From 6f93020d0be493bdee934b496c4a4469f3d73672 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sun, 10 Jun 2018 09:36:21 +0200 Subject: [PATCH] scheduler: Apply renice configuration to clients This commit applies the configured nice value to the client. It accepts values from 1 to 20, the negated value is applied as a nice value. Negation was chosen due to limits of the configuration parser. Since low priority values (0 to 19) make no sense in the scope of GameMode, this is a safe approach. Signed-off-by: Kai Krakow --- daemon/gamemode.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon/gamemode.c b/daemon/gamemode.c index 0012e44..9a8380d 100644 --- a/daemon/gamemode.c +++ b/daemon/gamemode.c @@ -57,7 +57,7 @@ POSSIBILITY OF SUCH DAMAGE. /* Priority to renice the process to. */ -#define NICE_PRIORITY -4 +#define NICE_DEFAULT_PRIORITY -4 /** * The GameModeClient encapsulates the remote connection, providing a list @@ -180,12 +180,24 @@ static void game_mode_apply_scheduler(GameModeContext *self, pid_t client) { LOG_MSG("Setting scheduling policies...\n"); + /* + * read configuration "renice" (1..20) + */ + long int renice = 0; + config_get_renice_value(self->config, &renice); + if ((renice < 1) || (renice > 20)) { + LOG_ERROR("Renice value [%ld] defaulted to [%d].\n", renice, -NICE_DEFAULT_PRIORITY); + renice = NICE_DEFAULT_PRIORITY; + } else { + renice = -renice; + } + /* * don't adjust priority if it was already adjusted */ if (getpriority(PRIO_PROCESS, (id_t)client) != 0) { LOG_ERROR("Client [%d] already reniced, ignoring.\n", client); - } else if (setpriority(PRIO_PROCESS, (id_t)client, NICE_PRIORITY)) { + } else if (setpriority(PRIO_PROCESS, (id_t)client, (int)renice)) { LOG_ERROR("Renicing client [%d] failed with error %d, ignoring.\n", client, errno); }