Browse Source

Disable softrealtime (SCHED_ISO) and renice by default

SCHED_ISO is not supported by upstream kernels, so don't try to use this by
default since for most users it will result in an error log that trying to
set the scheduling policy fails.

Without extra system configuration, we will also not have permission to renice
processes by default, so out of the box doing this will fail as well.

Users that wish to use these features can enable them from the config once
they have configured their system appropriately.
Alex Smith 6 years ago
parent
commit
2ab46df4c3
4 changed files with 17 additions and 18 deletions
  1. 3 3
      README.md
  2. 0 1
      daemon/daemon_config.c
  3. 6 7
      daemon/gamemode-sched.c
  4. 8 7
      example/gamemode.ini

+ 3 - 3
README.md

@@ -94,15 +94,15 @@ The file parsing uses [inih](https://github.com/benhoyt/inih).
 ## Features
 
 ### Scheduling
-GameMode can leverage support for soft real time mode if the running kernel supports `SCHED_ISO`. This adjusts the scheduling of the game to real time without sacrificing system stability by starving other processes.
+GameMode can leverage support for soft real time mode if the running kernel supports `SCHED_ISO`, controlled by the `softrealtime` option. This adjusts the scheduling of the game to real time without sacrificing system stability by starving other processes.
 
-GameMode adjusts the nice priority of games to -4 by default to give it a slight IO and CPU priority over other background processes. This only works if your user is permitted to adjust priorities within the limits configured by PAM. GameMode can be configured to take care of it by passing `with-pam-group=group` to the build options where `group` is a group your user needs to be part of.
+GameMode can adjust the nice priority of games to give them a slight IO and CPU priority over other background processes, controlled by the `renice` option. This only works if your user is permitted to adjust priorities within the limits configured by PAM. GameMode can be configured to take care of it by passing `with-pam-group=group` to the build options where `group` is a group your user needs to be part of.
 For more information, see `/etc/security/limits.conf`.
 
 Please take note that some games may actually run seemingly slower with `SCHED_ISO` if the game makes use of busy looping while interacting with the graphic driver. The same may happen if you apply too strong nice values. This effect is called priority inversion: Due to the high priority given to busy loops, there may be too few resources left for the graphics driver. Thus, sane defaults were chosen to not expose this effect on most systems. Part of this default is a heuristic which automatically turns off `SCHED_ISO` if GameMode detects three or less CPU cores. Your experience may change based on using GL threaded optimizations, CPU core binding (taskset), the graphic driver, or different CPU architectures. If you experience bad input latency or inconsistent FPS, try switching these configurations on or off first and report back. `SCHED_ISO` comes with a protection against this effect by falling back to normal scheduling as soon as the `SCHED_ISO` process uses more than 70% avarage across all CPU cores. This default value can be adjusted outside of the scope of GameMode (it's in `/proc/sys/kernel/iso_cpu`). This value also protects against compromising system stability, do not set it to 100% as this would turn the game into a full real time process, thus potentially starving all other OS components from CPU resources.
 
 ### IO priority
-GameMode can adjust the io priority of games to benefit from reduced lag and latency when a game has to load assets on demand.
+GameMode can adjust the I/O priority of games to benefit from reduced lag and latency when a game has to load assets on demand. This is done by default.
 
 ### For those with overclocked CPUs
 If you have an AMD CPU and have disabled Cool'n'Quiet, or you have an Intel CPU and have disabled SpeedStep, then GameMode's governor settings will not work, as your CPU is not running with a governor. You are already getting maximum performance.

+ 0 - 1
daemon/daemon_config.c

@@ -326,7 +326,6 @@ static void load_config_files(GameModeConfig *self)
 
 	/* Set some non-zero defaults */
 	self->values.inhibit_screensaver = 1; /* Defaults to on */
-	self->values.renice = 4;              /* default value of 4 */
 	self->values.reaper_frequency = DEFAULT_REAPER_FREQ;
 	self->values.gpu_device = -1; /* 0 is a valid device ID so use -1 to indicate no value */
 	self->values.nv_powermizer_mode = -1;

+ 6 - 7
daemon/gamemode-sched.c

@@ -67,7 +67,9 @@ void game_mode_apply_renice(const GameModeContext *self, const pid_t client)
 	 * read configuration "renice" (1..20)
 	 */
 	long int renice = config_get_renice_value(config);
-	if ((renice < 1) || (renice > 20)) {
+	if (renice == 0) {
+		return;
+	} else if ((renice < 1) || (renice > 20)) {
 		LOG_ONCE(ERROR, "Configured renice value '%ld' is invalid, will not renice.\n", renice);
 		return;
 	} else {
@@ -105,12 +107,13 @@ void game_mode_apply_scheduling(const GameModeContext *self, const pid_t client)
 	 * priority inversion problems with the graphics driver thus running
 	 * slower as a result, so enable only with more than 3 cores.
 	 */
-	bool enable_softrealtime = (strcmp(softrealtime, "on") == 0) || (get_nprocs() > 3);
+	bool enable_softrealtime = (strcmp(softrealtime, "on") == 0) ||
+							   ((strcmp(softrealtime, "auto") == 0) && (get_nprocs() > 3));
 
 	/*
 	 * Actually apply the scheduler policy if not explicitly turned off
 	 */
-	if (!(strcmp(softrealtime, "off") == 0) && (enable_softrealtime)) {
+	if (enable_softrealtime) {
 		const struct sched_param p = { .sched_priority = 0 };
 		if (sched_setscheduler(client, SCHED_ISO | SCHED_RESET_ON_FORK, &p)) {
 			const char *hint = "";
@@ -139,9 +142,5 @@ void game_mode_apply_scheduling(const GameModeContext *self, const pid_t client)
 			    strerror(errno),
 			    hint);
 		}
-	} else {
-		LOG_ERROR("Skipped setting client [%d] into SCHED_ISO mode: softrealtime setting is '%s'\n",
-		          client,
-		          softrealtime);
 	}
 }

+ 8 - 7
example/gamemode.ini

@@ -7,19 +7,20 @@ desiredgov=performance
 ; The default governer is used when leaving GameMode instead of restoring the original value
 defaultgov=powersave
 
-; By default, GameMode changes the scheduler policy to SCHED_ISO with 4 or more CPU cores,
-; force enable or disable with "on" or "off"
-softrealtime=auto
+; GameMode can change the scheduler policy to SCHED_ISO on kernels which support it (currently
+; not supported by upstream kernels). Can be set to "auto", "on" or "off". "auto" will enable
+; with 4 or more CPU cores. "on" will always enable. Defaults to "off".
+;softrealtime=off
 
-; By default, GameMode renices the client to -4, you can put any value between 1 and 20 here,
-; the value will be negated and applied as a nice value
-renice = 4
+; GameMode can renice game processes. You can put any value between 1 and 20 here, the value
+; will be negated and applied as a nice value.
+;renice=4
 
 ; By default, GameMode adjusts the iopriority of clients to BE/0, you can put any value
 ; between 0 and 7 here (with 0 being highest priority), or one of the special values
 ; "off" (to disable) or "reset" (to restore Linux default behavior based on CPU priority),
 ; currently, only the best-effort class is supported thus you cannot set it here
-ioprio = 0
+ioprio=0
 
 ; Sets whether gamemode will inhibit the screensaver when active
 ; Defaults to 1