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.
This commit is contained in:
kleines Filmröllchen 2022-07-24 18:05:44 +02:00 committed by Linus Groh
parent bbe40ae632
commit 259bfe05b1

View file

@ -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;
}