summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-07-24 18:05:44 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-27 11:30:19 +0100
commit259bfe05b1fc991a9993c53af97b068c4efc6abc (patch)
tree27dba0ca4afa653a22239d08cd965d597249f005
parentbbe40ae6328d894b17ff974604b609b5ad0c5747 (diff)
downloadserenity-259bfe05b1fc991a9993c53af97b068c4efc6abc.zip
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.
-rw-r--r--Kernel/Syscalls/sched.cpp9
1 files changed, 8 insertions, 1 deletions
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<FlatPtr> Process::sys$scheduler_set_parameters(Userspace<Syscall::SC_sch
if (!credentials->is_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;
}