mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 23:57:22 +02:00
Refactor config functions that can return their full value to do so
This pattern got a little out of hand, and was only meant for variable length values like strings
This commit is contained in:
parent
d17d682082
commit
b7dff4265c
@ -438,9 +438,11 @@ bool config_get_client_blacklisted(GameModeConfig *self, const char *client)
|
|||||||
/*
|
/*
|
||||||
* Gets the reaper frequency
|
* Gets the reaper frequency
|
||||||
*/
|
*/
|
||||||
void config_get_reaper_thread_frequency(GameModeConfig *self, long *value)
|
long config_get_reaper_thread_frequency(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->reaper_frequency, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->reaper_frequency, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -498,24 +500,28 @@ void config_get_soft_realtime(GameModeConfig *self, char softrealtime[CONFIG_VAL
|
|||||||
/*
|
/*
|
||||||
* Get the renice value
|
* Get the renice value
|
||||||
*/
|
*/
|
||||||
void config_get_renice_value(GameModeConfig *self, long *value)
|
long config_get_renice_value(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->renice, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->renice, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the ioprio value
|
* Get the ioprio value
|
||||||
*/
|
*/
|
||||||
void config_get_ioprio_value(GameModeConfig *self, int *value)
|
long config_get_ioprio_value(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
|
long value = 0;
|
||||||
char ioprio_value[CONFIG_VALUE_MAX] = { 0 };
|
char ioprio_value[CONFIG_VALUE_MAX] = { 0 };
|
||||||
memcpy_locked_config(self, ioprio_value, &self->ioprio, sizeof(self->ioprio));
|
memcpy_locked_config(self, ioprio_value, &self->ioprio, sizeof(self->ioprio));
|
||||||
if (0 == strncmp(ioprio_value, "off", sizeof(self->ioprio)))
|
if (0 == strncmp(ioprio_value, "off", sizeof(self->ioprio)))
|
||||||
*value = IOPRIO_DONT_SET;
|
value = IOPRIO_DONT_SET;
|
||||||
else if (0 == strncmp(ioprio_value, "default", sizeof(self->ioprio)))
|
else if (0 == strncmp(ioprio_value, "default", sizeof(self->ioprio)))
|
||||||
*value = IOPRIO_RESET_DEFAULT;
|
value = IOPRIO_RESET_DEFAULT;
|
||||||
else
|
else
|
||||||
*value = atoi(ioprio_value);
|
value = atoi(ioprio_value);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -529,36 +535,51 @@ void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_
|
|||||||
sizeof(self->apply_gpu_optimisations));
|
sizeof(self->apply_gpu_optimisations));
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_get_gpu_vendor(GameModeConfig *self, long *value)
|
long config_get_gpu_vendor(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->gpu_vendor, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->gpu_vendor, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_get_gpu_device(GameModeConfig *self, long *value)
|
long config_get_gpu_device(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->gpu_device, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->gpu_device, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_get_nv_core_clock_mhz_offset(GameModeConfig *self, long *value)
|
long config_get_nv_core_clock_mhz_offset(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->nv_core_clock_mhz_offset, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->nv_core_clock_mhz_offset, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_get_nv_mem_clock_mhz_offset(GameModeConfig *self, long *value)
|
long config_get_nv_mem_clock_mhz_offset(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->nv_mem_clock_mhz_offset, sizeof(long));
|
long value = 0;
|
||||||
}
|
memcpy_locked_config(self, &value, &self->nv_mem_clock_mhz_offset, sizeof(long));
|
||||||
void config_get_nv_perf_level(GameModeConfig *self, long *value)
|
return value;
|
||||||
{
|
|
||||||
memcpy_locked_config(self, value, &self->nv_perf_level, sizeof(long));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_get_amd_core_clock_percentage(GameModeConfig *self, long *value)
|
long config_get_nv_perf_level(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->amd_core_clock_percentage, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->nv_perf_level, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_get_amd_mem_clock_percentage(GameModeConfig *self, long *value)
|
long config_get_amd_core_clock_percentage(GameModeConfig *self)
|
||||||
{
|
{
|
||||||
memcpy_locked_config(self, value, &self->amd_mem_clock_percentage, sizeof(long));
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->amd_core_clock_percentage, sizeof(long));
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
long config_get_amd_mem_clock_percentage(GameModeConfig *self)
|
||||||
|
{
|
||||||
|
long value = 0;
|
||||||
|
memcpy_locked_config(self, &value, &self->amd_mem_clock_percentage, sizeof(long));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ bool config_get_client_blacklisted(GameModeConfig *self, const char *client);
|
|||||||
/*
|
/*
|
||||||
* Get the frequency (in seconds) for the reaper thread
|
* Get the frequency (in seconds) for the reaper thread
|
||||||
*/
|
*/
|
||||||
void config_get_reaper_thread_frequency(GameModeConfig *self, long *value);
|
long config_get_reaper_thread_frequency(GameModeConfig *self);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get whether we want to inhibit the screensaver (defaults to true)
|
* Get whether we want to inhibit the screensaver (defaults to true)
|
||||||
@ -123,21 +123,21 @@ void config_get_soft_realtime(GameModeConfig *self, char softrealtime[CONFIG_VAL
|
|||||||
/*
|
/*
|
||||||
* Get the renice value
|
* Get the renice value
|
||||||
*/
|
*/
|
||||||
void config_get_renice_value(GameModeConfig *self, long *value);
|
long config_get_renice_value(GameModeConfig *self);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the ioprio value
|
* Get the ioprio value
|
||||||
*/
|
*/
|
||||||
void config_get_ioprio_value(GameModeConfig *self, int *value);
|
long config_get_ioprio_value(GameModeConfig *self);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get various config info for gpu optimisations
|
* Get various config info for gpu optimisations
|
||||||
*/
|
*/
|
||||||
void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_VALUE_MAX]);
|
void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_VALUE_MAX]);
|
||||||
void config_get_gpu_vendor(GameModeConfig *self, long *value);
|
long config_get_gpu_vendor(GameModeConfig *self);
|
||||||
void config_get_gpu_device(GameModeConfig *self, long *value);
|
long config_get_gpu_device(GameModeConfig *self);
|
||||||
void config_get_nv_core_clock_mhz_offset(GameModeConfig *self, long *value);
|
long config_get_nv_core_clock_mhz_offset(GameModeConfig *self);
|
||||||
void config_get_nv_mem_clock_mhz_offset(GameModeConfig *self, long *value);
|
long config_get_nv_mem_clock_mhz_offset(GameModeConfig *self);
|
||||||
void config_get_nv_perf_level(GameModeConfig *self, long *value);
|
long config_get_nv_perf_level(GameModeConfig *self);
|
||||||
void config_get_amd_core_clock_percentage(GameModeConfig *self, long *value);
|
long config_get_amd_core_clock_percentage(GameModeConfig *self);
|
||||||
void config_get_amd_mem_clock_percentage(GameModeConfig *self, long *value);
|
long config_get_amd_mem_clock_percentage(GameModeConfig *self);
|
||||||
|
@ -71,8 +71,8 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
|
|||||||
memset(new_info, 0, sizeof(GameModeGPUInfo));
|
memset(new_info, 0, sizeof(GameModeGPUInfo));
|
||||||
|
|
||||||
/* Get the config parameters */
|
/* Get the config parameters */
|
||||||
config_get_gpu_vendor(config, &new_info->vendor);
|
new_info->vendor = config_get_gpu_vendor(config);
|
||||||
config_get_gpu_device(config, &new_info->device);
|
new_info->device = config_get_gpu_device(config);
|
||||||
|
|
||||||
/* verify device ID */
|
/* verify device ID */
|
||||||
if (new_info->device == -1) {
|
if (new_info->device == -1) {
|
||||||
@ -100,8 +100,8 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
|
|||||||
/* Load the config based on GPU and also verify the values are sane */
|
/* Load the config based on GPU and also verify the values are sane */
|
||||||
switch (new_info->vendor) {
|
switch (new_info->vendor) {
|
||||||
case Vendor_NVIDIA:
|
case Vendor_NVIDIA:
|
||||||
config_get_nv_core_clock_mhz_offset(config, &new_info->core);
|
new_info->core = config_get_nv_core_clock_mhz_offset(config);
|
||||||
config_get_nv_mem_clock_mhz_offset(config, &new_info->mem);
|
new_info->mem = config_get_nv_mem_clock_mhz_offset(config);
|
||||||
|
|
||||||
/* Reject values over some guessed values
|
/* Reject values over some guessed values
|
||||||
* If a user wants to go into very unsafe levels they can recompile
|
* If a user wants to go into very unsafe levels they can recompile
|
||||||
@ -122,7 +122,7 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Sanity check the performance level value as well */
|
/* Sanity check the performance level value as well */
|
||||||
config_get_nv_perf_level(config, &new_info->nv_perf_level);
|
new_info->nv_perf_level = config_get_nv_perf_level(config);
|
||||||
if (new_info->nv_perf_level < 0 || new_info->nv_perf_level > 16) {
|
if (new_info->nv_perf_level < 0 || new_info->nv_perf_level > 16) {
|
||||||
LOG_ERROR(
|
LOG_ERROR(
|
||||||
"NVIDIA Performance level value likely invalid (%ld), will not apply "
|
"NVIDIA Performance level value likely invalid (%ld), will not apply "
|
||||||
@ -134,8 +134,8 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case Vendor_AMD:
|
case Vendor_AMD:
|
||||||
config_get_amd_core_clock_percentage(config, &new_info->core);
|
new_info->core = config_get_amd_core_clock_percentage(config);
|
||||||
config_get_amd_mem_clock_percentage(config, &new_info->mem);
|
new_info->mem = config_get_amd_mem_clock_percentage(config);
|
||||||
|
|
||||||
/* Reject values over 20%
|
/* Reject values over 20%
|
||||||
* If a user wants to go into very unsafe levels they can recompile
|
* If a user wants to go into very unsafe levels they can recompile
|
||||||
|
@ -102,8 +102,7 @@ void game_mode_apply_ioprio(const GameModeContext *self, const pid_t client)
|
|||||||
/*
|
/*
|
||||||
* read configuration "ioprio" (0..7)
|
* read configuration "ioprio" (0..7)
|
||||||
*/
|
*/
|
||||||
int ioprio = 0;
|
int ioprio = (int)config_get_ioprio_value(config);
|
||||||
config_get_ioprio_value(config, &ioprio);
|
|
||||||
if (IOPRIO_RESET_DEFAULT == ioprio) {
|
if (IOPRIO_RESET_DEFAULT == ioprio) {
|
||||||
LOG_MSG("IO priority will be reset to default behavior (based on CPU priority).\n");
|
LOG_MSG("IO priority will be reset to default behavior (based on CPU priority).\n");
|
||||||
ioprio = 0;
|
ioprio = 0;
|
||||||
|
@ -66,8 +66,7 @@ void game_mode_apply_renice(const GameModeContext *self, const pid_t client)
|
|||||||
/*
|
/*
|
||||||
* read configuration "renice" (1..20)
|
* read configuration "renice" (1..20)
|
||||||
*/
|
*/
|
||||||
long int renice = 0;
|
long int renice = config_get_renice_value(config);
|
||||||
config_get_renice_value(config, &renice);
|
|
||||||
if ((renice < 1) || (renice > 20)) {
|
if ((renice < 1) || (renice > 20)) {
|
||||||
LOG_ONCE(ERROR, "Configured renice value '%ld' is invalid, will not renice.\n", renice);
|
LOG_ONCE(ERROR, "Configured renice value '%ld' is invalid, will not renice.\n", renice);
|
||||||
return;
|
return;
|
||||||
|
@ -549,8 +549,7 @@ static void *game_mode_context_reaper(void *userdata)
|
|||||||
/* Stack, not allocated, won't disappear. */
|
/* Stack, not allocated, won't disappear. */
|
||||||
GameModeContext *self = userdata;
|
GameModeContext *self = userdata;
|
||||||
|
|
||||||
long reaper_interval = 0.0f;
|
long reaper_interval = config_get_reaper_thread_frequency(self->config);
|
||||||
config_get_reaper_thread_frequency(self->config, &reaper_interval);
|
|
||||||
|
|
||||||
struct timespec ts = { 0, 0 };
|
struct timespec ts = { 0, 0 };
|
||||||
ts.tv_sec = time(NULL) + reaper_interval;
|
ts.tv_sec = time(NULL) + reaper_interval;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user