From 259bfe05b1fc991a9993c53af97b068c4efc6abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sun, 24 Jul 2022 18:05:44 +0200 Subject: [PATCH] Kernel: Set priority of all threads within a process if requested This is intended to reflect the POSIX sched_setparam API, which has some cryptic language (https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_08_04_01 ) that as far as I can tell implies we should prioritize process scheduling policies over thread scheduling policies. Technically this means that a process must have its own sets of policies that are considered first by the scheduler, but it seems unlikely anyone relies on this behavior in practice. So we just override all thread's policies, making them (at least before calls to pthread_setschedparam) behave exactly like specified on the surface. --- Kernel/Syscalls/sched.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/sched.cpp b/Kernel/Syscalls/sched.cpp index a9351bb27b..f5db4eadbf 100644 --- a/Kernel/Syscalls/sched.cpp +++ b/Kernel/Syscalls/sched.cpp @@ -75,8 +75,15 @@ ErrorOr Process::sys$scheduler_set_parameters(Userspaceis_superuser() && credentials->euid() != peer_credentials->uid() && credentials->uid() != peer_credentials->uid()) return EPERM; - // FIXME: Only sets priority for main thread of process if mode == PROCESS peer->set_priority((u32)parameters.parameters.sched_priority); + // POSIX says that process scheduling parameters have precedence over thread scheduling parameters. + // We don't track them separately, so overwrite the thread scheduling settings manually for now. + if (parameters.mode == Syscall::SchedulerParametersMode::Process) { + peer->process().for_each_thread([&](auto& thread) { + thread.set_priority((u32)parameters.parameters.sched_priority); + }); + } + return 0; }