Преглед на файлове

Add defaultgov and desiredgov config settings

	Allows users to choose which governor settings they want.

	Should provide some future compatibility for other governor settings.
Marc Di Luzio преди 6 години
родител
ревизия
5ebc77a0f1
променени са 4 файла, в които са добавени 32 реда и са изтрити 2 реда
  1. 10 0
      daemon/daemon_config.h
  2. 12 2
      daemon/gamemode.c
  3. 5 0
      data/gamemoded.1
  4. 5 0
      example/gamemode.ini

+ 10 - 0
daemon/daemon_config.h

@@ -93,3 +93,13 @@ void config_get_gamemode_start_scripts(GameModeConfig *self,
  */
 void config_get_gamemode_end_scripts(GameModeConfig *self,
                                      char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX]);
+
+/*
+ * Get the chosen default governor
+ */
+void config_get_default_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX]);
+
+/*
+ * Get the chosen desired governor
+ */
+void config_get_desired_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX]);

+ 12 - 2
daemon/gamemode.c

@@ -184,8 +184,13 @@ static void game_mode_context_enter(GameModeContext *self)
 		self->initial_cpu_mode[sizeof(self->initial_cpu_mode) - 1] = '\0';
 		LOG_MSG("governor was initially set to [%s]\n", initial_state);
 
+		/* Choose the desired governor */
+		char desired[CONFIG_VALUE_MAX] = { 0 };
+		config_get_desired_governor(self->config, desired);
+		const char *desiredGov = desired[0] != '\0' ? desired : "performance";
+
 		/* set the governor to performance */
-		if (!set_governors("performance")) {
+		if (!set_governors(desiredGov)) {
 			/* if the set fails, clear the initial mode so we don't try and reset it back and fail
 			 * again, presumably */
 			memset(self->initial_cpu_mode, 0, sizeof(self->initial_cpu_mode));
@@ -206,7 +211,12 @@ static void game_mode_context_leave(GameModeContext *self)
 
 	/* Reset the governer state back to initial */
 	if (self->initial_cpu_mode[0] != '\0') {
-		set_governors(self->initial_cpu_mode);
+		/* Choose the governor to reset to, using the config to override */
+		char defaultgov[CONFIG_VALUE_MAX] = { 0 };
+		config_get_default_governor(self->config, defaultgov);
+		const char *gov_mode = defaultgov[0] != '\0' ? defaultgov : self->initial_cpu_mode;
+
+		set_governors(gov_mode);
 		memset(self->initial_cpu_mode, 0, sizeof(self->initial_cpu_mode));
 	}
 

+ 5 - 0
data/gamemoded.1

@@ -97,6 +97,11 @@ Behaviour of the config file can be explained by presenting a commented example:
 ; The reaper thread will check every 10 seconds for exited clients
 reaper_freq=10
 
+; The desired governor is used when entering GameMode instead of "performance"
+desiredgov=performance
+; The default governer is used when leaving GameMode instead of restoring the original value
+defaultgov=powersave
+
 [filter]
 ; If "whitelist" entry has a value(s)
 ; gamemode will reject anything not in the whitelist

+ 5 - 0
example/gamemode.ini

@@ -2,6 +2,11 @@
 ; The reaper thread will check every 10 seconds for exited clients
 reaper_freq=10
 
+; The desired governor is used when entering GameMode instead of "performance"
+desiredgov=performance
+; The default governer is used when leaving GameMode instead of restoring the original value
+defaultgov=powersave
+
 [filter]
 ; If "whitelist" entry has a value(s)
 ; gamemode will reject anything not in the whitelist