From 9fc5f4c48b20875337b7a1eddd274f191edd504d Mon Sep 17 00:00:00 2001 From: Mily <128398851+milyth@users.noreply.github.com> Date: Sun, 23 Jul 2023 15:51:00 -0300 Subject: init: Request SCHED_RR using CAP_SYS_NICE and add Python to nix dev shell (#2690) * nix: add python3 to devShell * init: request SCHED_RR scheduling policy * init: checks if host supports reseting scheduler on fork * init: make gainRealTime more compatible with other OSes * init: remove linux-only code --- src/init/initHelpers.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/init/initHelpers.cpp') diff --git a/src/init/initHelpers.cpp b/src/init/initHelpers.cpp index dc51650a..2666ed0b 100644 --- a/src/init/initHelpers.cpp +++ b/src/init/initHelpers.cpp @@ -3,3 +3,19 @@ bool Init::isSudo() { return getuid() != geteuid() || !geteuid(); } + +void Init::gainRealTime() { + const int minPrio = sched_get_priority_min(SCHED_RR); + const struct sched_param param = {.sched_priority = minPrio}; + + if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m)) { + Debug::log(WARN, "Failed to change process scheduling strategy"); + return; + } + + pthread_atfork(NULL, NULL, []() { + const struct sched_param param = {.sched_priority = 0}; + if (pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m)) + Debug::log(WARN, "Failed to reset process scheduling strategy"); + }); +} \ No newline at end of file -- cgit v1.2.3