From 0847d3b4526e45b947e5b8861fe4857411656127 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 16 Feb 2019 12:22:47 +0000 Subject: [PATCH 1/5] Remove the vendor config value in prep for it to be auto-detected --- daemon/daemon_config.c | 4 ---- daemon/daemon_config.h | 1 - daemon/gamemode-gpu.c | 9 +++++---- daemon/gamemode-tests.c | 7 +++---- example/gamemode.ini | 4 +--- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/daemon/daemon_config.c b/daemon/daemon_config.c index db2d3ff..e0265d6 100644 --- a/daemon/daemon_config.c +++ b/daemon/daemon_config.c @@ -87,7 +87,6 @@ struct GameModeConfig { long reaper_frequency; char apply_gpu_optimisations[CONFIG_VALUE_MAX]; - long gpu_vendor; long gpu_device; long nv_core_clock_mhz_offset; long nv_mem_clock_mhz_offset; @@ -231,8 +230,6 @@ static int inih_handler(void *user, const char *section, const char *name, const /* GPU subsection */ if (strcmp(name, "apply_gpu_optimisations") == 0) { valid = get_string_value(value, self->values.apply_gpu_optimisations); - } else if (strcmp(name, "gpu_vendor") == 0) { - valid = get_long_value_hex(name, value, &self->values.gpu_vendor); } else if (strcmp(name, "gpu_device") == 0) { valid = get_long_value(name, value, &self->values.gpu_device); } else if (strcmp(name, "nv_core_clock_mhz_offset") == 0) { @@ -556,7 +553,6 @@ void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_ } /* Define the getters for GPU values */ -DEFINE_CONFIG_GET(gpu_vendor) DEFINE_CONFIG_GET(gpu_device) DEFINE_CONFIG_GET(nv_core_clock_mhz_offset) DEFINE_CONFIG_GET(nv_mem_clock_mhz_offset) diff --git a/daemon/daemon_config.h b/daemon/daemon_config.h index 01acd9d..921b5f9 100644 --- a/daemon/daemon_config.h +++ b/daemon/daemon_config.h @@ -134,7 +134,6 @@ long config_get_ioprio_value(GameModeConfig *self); * Get various config info for gpu optimisations */ void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_VALUE_MAX]); -long config_get_gpu_vendor(GameModeConfig *self); long config_get_gpu_device(GameModeConfig *self); long config_get_nv_core_clock_mhz_offset(GameModeConfig *self); long config_get_nv_mem_clock_mhz_offset(GameModeConfig *self); diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index ecc01a2..21b341c 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -71,9 +71,11 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) memset(new_info, 0, sizeof(GameModeGPUInfo)); /* Get the config parameters */ - new_info->vendor = config_get_gpu_vendor(config); new_info->device = config_get_gpu_device(config); + /* TODO fill in GPU vendor */ + new_info->vendor = 0; + /* verify device ID */ if (new_info->device == -1) { LOG_ERROR( @@ -86,10 +88,9 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) /* verify GPU vendor */ if (!GPUVendorValid(new_info->vendor)) { LOG_ERROR( - "Invalid gpu_vendor value (0x%04x) set in configuration, will not apply " - "optimisations!\n", + "Unknown vendor value (0x%04x) found, cannot apply optimisations!\n", (unsigned int)new_info->vendor); - LOG_ERROR("Possible values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n", + LOG_ERROR("Known values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n", Vendor_NVIDIA, Vendor_AMD, Vendor_Intel); diff --git a/daemon/gamemode-tests.c b/daemon/gamemode-tests.c index a5d36bc..89c1291 100644 --- a/daemon/gamemode-tests.c +++ b/daemon/gamemode-tests.c @@ -421,16 +421,15 @@ int run_gpu_optimisation_tests(struct GameModeConfig *config) /* Get current GPU values */ GameModeGPUInfo gpuinfo; gpuinfo.device = config_get_gpu_device(config); - gpuinfo.vendor = config_get_gpu_vendor(config); - - if (gpuinfo.vendor == Vendor_NVIDIA) - gpuinfo.nv_perf_level = config_get_nv_perf_level(config); if (game_mode_get_gpu(&gpuinfo) != 0) { LOG_ERROR("Could not get current GPU info, see above!\n"); return -1; } + if (gpuinfo.vendor == Vendor_NVIDIA) + gpuinfo.nv_perf_level = config_get_nv_perf_level(config); + /* Store the original values */ long original_core = gpuinfo.core; long original_mem = gpuinfo.mem; diff --git a/example/gamemode.ini b/example/gamemode.ini index da101e4..bfb826a 100644 --- a/example/gamemode.ini +++ b/example/gamemode.ini @@ -43,9 +43,7 @@ inhibit_screensaver=1 ; Setting this to the keyphrase "accept-responsibility" will allow gamemode to apply GPU optimisations such as overclocks ;apply_gpu_optimisations=0 -; You must set these to tell gamemode the Vendor of your graphics card, as well it's device number on the system (usually 0) -; Vendor must be one of 0x10de (NVIDIA), 0x1002 (AMD) or 0x8086 (Intel) -;gpu_vendor=0x0000 +; The device number on the system (usually 0) ;gpu_device=0 ; Nvidia specific settings (these are Mhz offsets from the baseline, ie. 0 applies no change) From 91deffb6b4544bfa9207f829519c15f569ec36ed Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 16 Feb 2019 12:34:23 +0000 Subject: [PATCH 2/5] Fill in the GPU vendor automatically --- daemon/gamemode-gpu.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index 21b341c..2ae3374 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -73,9 +73,6 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) /* Get the config parameters */ new_info->device = config_get_gpu_device(config); - /* TODO fill in GPU vendor */ - new_info->vendor = 0; - /* verify device ID */ if (new_info->device == -1) { LOG_ERROR( @@ -85,11 +82,29 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) return -1; } + /* Fill in GPU vendor */ + char path[64] = { 0 }; + if (snprintf(path, 64, "/sys/class/drm/card%ld/device/vendor", new_info->device) < 0) { + LOG_ERROR("snprintf failed, will not apply gpu optimisations!\n"); + return -1; + } + FILE *vendor = fopen(path, "r"); + if (!vendor) { + LOG_ERROR("Couldn't open vendor file at %s, will not apply gpu optimisations!\n", path); + return -1; + } + char buff[64]; + if (fgets(buff, 64, vendor) != NULL) { + new_info->vendor = strtol(buff, NULL, 0); + } else { + LOG_ERROR("Coudn't read contents of file %s, will not apply optimisations!\n", path); + return -1; + } + /* verify GPU vendor */ if (!GPUVendorValid(new_info->vendor)) { - LOG_ERROR( - "Unknown vendor value (0x%04x) found, cannot apply optimisations!\n", - (unsigned int)new_info->vendor); + LOG_ERROR("Unknown vendor value (0x%04x) found, cannot apply optimisations!\n", + (unsigned int)new_info->vendor); LOG_ERROR("Known values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n", Vendor_NVIDIA, Vendor_AMD, From ebe525d04ea42bf9fda01c21d56b9a6512947af7 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 19 Feb 2019 19:36:36 +0000 Subject: [PATCH 3/5] Fix up testing now that we detect the vendor --- daemon/gamemode-tests.c | 61 ++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/daemon/gamemode-tests.c b/daemon/gamemode-tests.c index 89c1291..fe90613 100644 --- a/daemon/gamemode-tests.c +++ b/daemon/gamemode-tests.c @@ -419,81 +419,68 @@ int run_gpu_optimisation_tests(struct GameModeConfig *config) } /* Get current GPU values */ - GameModeGPUInfo gpuinfo; - gpuinfo.device = config_get_gpu_device(config); + GameModeGPUInfo *gpuinfo; + game_mode_initialise_gpu(config, &gpuinfo); - if (game_mode_get_gpu(&gpuinfo) != 0) { - LOG_ERROR("Could not get current GPU info, see above!\n"); + if (!gpuinfo) { + LOG_ERROR("Failed to initialise gpuinfo!\n"); return -1; } - if (gpuinfo.vendor == Vendor_NVIDIA) - gpuinfo.nv_perf_level = config_get_nv_perf_level(config); - - /* Store the original values */ - long original_core = gpuinfo.core; - long original_mem = gpuinfo.mem; - /* Grab the expected values */ - long expected_core = 0; - long expected_mem = 0; - switch (gpuinfo.vendor) { - case Vendor_NVIDIA: - expected_core = config_get_nv_core_clock_mhz_offset(config); - expected_mem = config_get_nv_mem_clock_mhz_offset(config); - break; - case Vendor_AMD: - expected_core = config_get_amd_core_clock_percentage(config); - expected_mem = config_get_amd_mem_clock_percentage(config); - break; - default: - LOG_ERROR("Configured for unsupported GPU vendor 0x%04x!\n", (unsigned int)gpuinfo.vendor); - return -1; - } + long expected_core = gpuinfo->core; + long expected_mem = gpuinfo->mem; + + /* Get current stats */ + game_mode_get_gpu(gpuinfo); + long original_core = gpuinfo->core; + long original_mem = gpuinfo->mem; LOG_MSG("Configured with vendor:0x%04x device:%ld core:%ld mem:%ld (nv_perf_level:%ld)\n", - (unsigned int)gpuinfo.vendor, - gpuinfo.device, + (unsigned int)gpuinfo->vendor, + gpuinfo->device, expected_core, expected_mem, - gpuinfo.nv_perf_level); + gpuinfo->nv_perf_level); /* Start gamemode and check the new values */ gamemode_request_start(); - if (game_mode_get_gpu(&gpuinfo) != 0) { + if (game_mode_get_gpu(gpuinfo) != 0) { LOG_ERROR("Could not get current GPU info, see above!\n"); gamemode_request_end(); + game_mode_free_gpu(&gpuinfo); return -1; } - if (gpuinfo.core != expected_core || gpuinfo.mem != expected_mem) { + if (gpuinfo->core != expected_core || gpuinfo->mem != expected_mem) { LOG_ERROR( "Current GPU clocks during gamemode do not match requested values!\n" "\tcore - expected:%ld was:%ld | mem - expected:%ld was:%ld\n", expected_core, - gpuinfo.core, + gpuinfo->core, expected_mem, - gpuinfo.mem); + gpuinfo->mem); gpustatus = -1; } /* End gamemode and check the values have returned */ gamemode_request_end(); - if (game_mode_get_gpu(&gpuinfo) != 0) { + if (game_mode_get_gpu(gpuinfo) != 0) { LOG_ERROR("Could not get current GPU info, see above!\n"); + game_mode_free_gpu(&gpuinfo); return -1; } - if (gpuinfo.core != original_core || gpuinfo.mem != original_mem) { + if (gpuinfo->core != original_core || gpuinfo->mem != original_mem) { LOG_ERROR( "Current GPU clocks after gamemode do not matcch original values!\n" "\tcore - original:%ld was:%ld | mem - original:%ld was:%ld\n", original_core, - gpuinfo.core, + gpuinfo->core, original_mem, - gpuinfo.mem); + gpuinfo->mem); gpustatus = -1; } From de390be93d68e5386ee08e6e4d55d4aef31fa396 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Thu, 21 Feb 2019 17:29:11 +0000 Subject: [PATCH 4/5] Add unused to now unused hex function --- daemon/daemon_config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daemon/daemon_config.c b/daemon/daemon_config.c index e0265d6..77a964a 100644 --- a/daemon/daemon_config.c +++ b/daemon/daemon_config.c @@ -152,7 +152,8 @@ static bool get_long_value(const char *value_name, const char *value, long *outp /* * Get a long value from a hex string */ -static bool get_long_value_hex(const char *value_name, const char *value, long *output) +__attribute__((unused)) static bool get_long_value_hex(const char *value_name, const char *value, + long *output) { char *end = NULL; long config_value = strtol(value, &end, 16); From a5543880f3402cf1507d473408e8cfc79778e50f Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Fri, 1 Mar 2019 18:13:58 +0000 Subject: [PATCH 5/5] Clarify ini file description As requested in #105 --- example/gamemode.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/gamemode.ini b/example/gamemode.ini index bfb826a..58aad32 100644 --- a/example/gamemode.ini +++ b/example/gamemode.ini @@ -43,7 +43,7 @@ inhibit_screensaver=1 ; Setting this to the keyphrase "accept-responsibility" will allow gamemode to apply GPU optimisations such as overclocks ;apply_gpu_optimisations=0 -; The device number on the system (usually 0) +; The DRM device number on the system (usually 0), ie. the number in /sys/class/drm/card0/ ;gpu_device=0 ; Nvidia specific settings (these are Mhz offsets from the baseline, ie. 0 applies no change)