Browse Source

Convert "apply_gpu_optimisations" to a string with a special key

Marc Di Luzio 6 years ago
parent
commit
6b268e8349
4 changed files with 21 additions and 11 deletions
  1. 9 6
      daemon/daemon_config.c
  2. 1 1
      daemon/daemon_config.h
  3. 10 3
      daemon/gamemode-gpu.c
  4. 1 1
      example/gamemode.ini

+ 9 - 6
daemon/daemon_config.c

@@ -76,7 +76,7 @@ struct GameModeConfig {
 
 	long reaper_frequency;
 
-	long apply_gpu_optimisations;
+	char apply_gpu_optimisations[CONFIG_VALUE_MAX];
 	long gpu_vendor;
 	long gpu_device;
 	long nv_core_clock_mhz_offset;
@@ -204,7 +204,7 @@ static int inih_handler(void *user, const char *section, const char *name, const
 	} else if (strcmp(section, "gpu") == 0) {
 		/* GPU subsection */
 		if (strcmp(name, "apply_gpu_optimisations") == 0) {
-			valid = get_long_value(name, value, &self->apply_gpu_optimisations);
+			valid = get_string_value(value, self->apply_gpu_optimisations);
 		} else if (strcmp(name, "gpu_vendor") == 0) {
 			valid = get_long_value_hex(name, value, &self->gpu_vendor);
 		} else if (strcmp(name, "gpu_device") == 0) {
@@ -276,10 +276,10 @@ static void load_config_files(GameModeConfig *self)
 	memset(self->defaultgov, 0, sizeof(self->defaultgov));
 	memset(self->desiredgov, 0, sizeof(self->desiredgov));
 	memset(self->softrealtime, 0, sizeof(self->softrealtime));
+	memset(self->apply_gpu_optimisations, 0, sizeof(self->apply_gpu_optimisations));
+	self->inhibit_screensaver = 1; /* Defaults to on */
 	self->renice = 4; /* default value of 4 */
 	self->reaper_frequency = DEFAULT_REAPER_FREQ;
-	self->inhibit_screensaver = 1; /* Defaults to on */
-	self->apply_gpu_optimisations = 0;
 	self->gpu_vendor = 0;
 	self->gpu_device = -1; /* 0 is a valid device ID so use -1 to indicate no value */
 	self->nv_core_clock_mhz_offset = 0;
@@ -517,9 +517,12 @@ void config_get_ioprio_value(GameModeConfig *self, int *value)
 /*
  * Get various config info for gpu optimisations
  */
-void config_get_apply_gpu_optimisations(GameModeConfig *self, long *value)
+void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_VALUE_MAX])
 {
-	memcpy_locked_config(self, value, &self->apply_gpu_optimisations, sizeof(long));
+	memcpy_locked_config(self,
+	                     value,
+	                     &self->apply_gpu_optimisations,
+	                     sizeof(self->apply_gpu_optimisations));
 }
 
 void config_get_gpu_vendor(GameModeConfig *self, long *value)

+ 1 - 1
daemon/daemon_config.h

@@ -133,7 +133,7 @@ void config_get_ioprio_value(GameModeConfig *self, int *value);
 /*
  * Get various config info for gpu optimisations
  */
-void config_get_apply_gpu_optimisations(GameModeConfig *self, long *value);
+void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_VALUE_MAX]);
 void config_get_gpu_vendor(GameModeConfig *self, long *value);
 void config_get_gpu_device(GameModeConfig *self, long *value);
 void config_get_nv_core_clock_mhz_offset(GameModeConfig *self, long *value);

+ 10 - 3
daemon/gamemode-gpu.c

@@ -58,10 +58,17 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
 		FATAL_ERROR("Invalid GameModeGPUInfo passed to %s", __func__);
 
 	/* Early out if we have this feature turned off */
-	long apply = 0;
-	config_get_apply_gpu_optimisations(config, &apply);
-	if (apply == 0)
+	char apply[CONFIG_VALUE_MAX];
+	config_get_apply_gpu_optimisations(config, apply);
+	if (strlen(apply) == 0) {
 		return 0;
+	} else if (strncmp(apply, "accept-responsibility", CONFIG_VALUE_MAX) != 0) {
+		LOG_ERROR(
+		    "apply_gpu_optimisations set to value other than \"accept-responsibility\" (%s), will "
+		    "not apply GPU optimisations!\n",
+		    apply);
+		return -1;
+	}
 
 	/* Create the context */
 	GameModeGPUInfo *new_info = malloc(sizeof(GameModeGPUInfo));

+ 1 - 1
example/gamemode.ini

@@ -40,7 +40,7 @@ inhibit_screensaver=1
 ; Any damage to hardware incurred due to this feature is your responsibility and yours alone
 ; It is also highly recommended you try these settings out first manually to find the sweet spots
 
-; Setting this to 1 will allow gamemode to attempt to apply GPU optimisations such as overclocks
+; Setting this to the keyphrase "accept-responsibility" will allow gamemode to apply GPU optimisations such as overclocks
 ;apply_gpu_optimisations=0
 
 ; Set these to specify which vendor and device ID you want apply optimisations to