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:
parent
bbe40ae632
commit
259bfe05b1
Notes:
sideshowbarker
2024-07-17 05:23:40 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/259bfe05b1 Pull-request: https://github.com/SerenityOS/serenity/pull/14672 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/timschumi
1 changed files with 8 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue