Reputation: 125
I am confused about how sched_setscheduler()
works in Linux.
My understanding is Linux uses CFS (SCHED_NORMAL)
internally for kernel processes scheduling. When user space starts a program (process), a clone()
call would be trigged to create a corresponding scheduling entity in kernel space.
So assume there are user process A and process B.
Process A calls sched_setscheduler(pid_A, SCHED_RR)
and spawns child processes A1, A2.
Process B calls sched_setscheduler(pid_B, SCHED_NORMAL)
and spawns child processes B1, B2.
How would Linux schedule process A and B in this case as they are using different scheduling policy? Does Linux still uses its internal default scheduling policy to choose between A and B, but leave A, A2, A1 compete each other using SCHED_RR
and B, B1, B2 with SCHED_NORMAL
?
Upvotes: 0
Views: 507
Reputation: 75555
The Linux kernel has a series of "scheduling classes" which are modules that decide what thread should run when a core goes idle.
Since SCHED_RR
is a real-time scheduling class, it will get to decide what to schedule onto an idle core before SCHED_NORMAL
does. That means that in some sense, A and its children have strict priority over B and its children.
However, I believe Linux reserves something like 5% CPU for non-realtime scheduling classes, so B and its children should not be starved of CPU.
Upvotes: 1