Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/common-gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct GameModeGPUInfo {
long nv_core; /* Nvidia core clock */
long nv_mem; /* Nvidia mem clock */
long nv_powermizer_mode; /* NV Powermizer Mode */
long nv_per_profile_editable; /* Allows per profile editable offsets */

char amd_performance_level[GPU_VALUE_MAX]; /* The AMD performance level set to */
};
Expand Down
7 changes: 6 additions & 1 deletion daemon/gamemode-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct GameModeConfig {
long nv_core_clock_mhz_offset;
long nv_mem_clock_mhz_offset;
long nv_powermizer_mode;
long nv_per_profile_editable;
char amd_performance_level[CONFIG_VALUE_MAX];

char cpu_park_cores[CONFIG_VALUE_MAX];
Expand Down Expand Up @@ -308,6 +309,8 @@ static int inih_handler(void *user, const char *section, const char *name, const
valid = get_long_value(name, value, &self->values.nv_mem_clock_mhz_offset);
} else if (strcmp(name, "nv_powermizer_mode") == 0) {
valid = get_long_value(name, value, &self->values.nv_powermizer_mode);
} else if (strcmp(name, "nv_per_profile_editable") == 0) {
valid = get_long_value(name, value, &self->values.nv_per_profile_editable);
} else if (strcmp(name, "amd_performance_level") == 0) {
valid = get_string_value(value, self->values.amd_performance_level);
}
Expand Down Expand Up @@ -387,6 +390,7 @@ static void load_config_files(GameModeConfig *self)
self->values.reaper_frequency = DEFAULT_REAPER_FREQ;
self->values.gpu_device = 0;
self->values.nv_powermizer_mode = -1;
self->values.nv_per_profile_editable = 1; /* Defaults to editable profiles */
self->values.nv_core_clock_mhz_offset = -1;
self->values.nv_mem_clock_mhz_offset = -1;
self->values.script_timeout = 10; /* Default to 10 seconds for scripts */
Expand Down Expand Up @@ -479,7 +483,7 @@ GameModeConfig *config_create(void)
}

/*
* Initialise the config
* Initialize the config
*/
void config_init(GameModeConfig *self)
{
Expand Down Expand Up @@ -827,6 +831,7 @@ DEFINE_CONFIG_GET(gpu_device)
DEFINE_CONFIG_GET(nv_core_clock_mhz_offset)
DEFINE_CONFIG_GET(nv_mem_clock_mhz_offset)
DEFINE_CONFIG_GET(nv_powermizer_mode)
DEFINE_CONFIG_GET(nv_per_profile_editable)

void config_get_amd_performance_level(GameModeConfig *self, char value[CONFIG_VALUE_MAX])
{
Expand Down
1 change: 1 addition & 0 deletions daemon/gamemode-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ 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);
long config_get_nv_powermizer_mode(GameModeConfig *self);
long config_get_nv_per_profile_editable(GameModeConfig *self);
void config_get_amd_performance_level(GameModeConfig *self, char value[CONFIG_VALUE_MAX]);

/*
Expand Down
9 changes: 8 additions & 1 deletion daemon/gamemode-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
new_info->nv_core = config_get_nv_core_clock_mhz_offset(config);
new_info->nv_mem = config_get_nv_mem_clock_mhz_offset(config);
new_info->nv_powermizer_mode = config_get_nv_powermizer_mode(config);
new_info->nv_per_profile_editable = config_get_nv_per_profile_editable(config);

/* Reject values over some guessed values
* If a user wants to go into very unsafe levels they can recompile
Expand Down Expand Up @@ -164,6 +165,8 @@ int game_mode_apply_gpu(const GameModeGPUInfo *info)
snprintf(nv_mem, 8, "%ld", info->nv_mem);
char nv_powermizer_mode[4];
snprintf(nv_powermizer_mode, 4, "%ld", info->nv_powermizer_mode);
char nv_per_profile_editable[4];
snprintf(nv_per_profile_editable, 4, "%ld", info->nv_per_profile_editable);

// Set up our command line to pass to gpuclockctl
const char *const exec_args[] = {
Expand All @@ -174,6 +177,7 @@ int game_mode_apply_gpu(const GameModeGPUInfo *info)
info->vendor == Vendor_NVIDIA ? nv_core : info->amd_performance_level,
info->vendor == Vendor_NVIDIA ? nv_mem : NULL, /* Only use this if Nvidia */
info->vendor == Vendor_NVIDIA ? nv_powermizer_mode : NULL, /* Only use this if Nvidia */
info->vendor == Vendor_NVIDIA ? nv_per_profile_editable : NULL, /* Only use this if Nvidia */
NULL,
};

Expand All @@ -192,14 +196,17 @@ int game_mode_get_gpu(GameModeGPUInfo *info)

/* Generate the input strings */
char device[4];
char profile_editable[4];
snprintf(device, 4, "%ld", info->device);
snprintf(profile_editable, 4, "%ld", info->nv_per_profile_editable);

// Set up our command line to pass to gpuclockctl
// This doesn't need pkexec as get does not need elevated perms
const char *const exec_args[] = {
LIBEXECDIR "/gpuclockctl",
device,
"get",
profile_editable, //TODO:refactor
NULL,
};

Expand Down Expand Up @@ -228,4 +235,4 @@ int game_mode_get_gpu(GameModeGPUInfo *info)
}

return 0;
}
}
4 changes: 4 additions & 0 deletions example/gamemode.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ disable_splitlock=1
;nv_core_clock_mhz_offset=0
;nv_mem_clock_mhz_offset=0

; Whether the GPU supports per-profile editable options for core and memory clock offsets.
; NOTE: if thi is set to 0 (AllPerformanceLevels) then nv_powermizer_mode must be set to 0
;nv_per_profile_editable = 1

; AMD specific settings
; Requires a relatively up to date AMDGPU kernel module
; See: https://dri.freedesktop.org/docs/drm/gpu/amdgpu.html#gpu-power-thermal-controls-and-monitoring
Expand Down
Loading
Loading