I\'m studying the Linux Kernel and am trying to figure out how the Round Robin scheduling algorithm works. In the kernel\\sched_rt.c
file, there\'s a method called
Check out c operator precedence http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence
The ->
operator has a higher precedence than the prefix ++
, so this particular condition could be written:
if (--(p->rt.time_slice))
In other words, it is the timeslice which is being decremented, not the pointer.
The queued
parameter may appear useless here, but it has a reason to be there. Specifically notice where task_tick_rt()
is called from. Its only reference is when it is assigned to the .task_tick
function pointer in the rt_sched_class
instance of struct sched_class
:
http://lxr.free-electrons.com/source/kernel/sched/rt.c#L1991
So we see that each scheduling algorithm has its own struct sched_class
function vector which the kernel will call into for scheduling services. If we look at other algorithms, we see the CFS (Completely Fair Scheduling) algorithm also has its own instance of struct sched_class
, named fair_sched_class
:
http://lxr.free-electrons.com/source/kernel/sched/fair.c#L6179
The .task_tick
member in the CFS case points to task_tick_fair()
:
http://lxr.free-electrons.com/source/kernel/sched/fair.c#L5785
Note task_tick_fair()
does make use of the queued
parameter. So when the .task_tick
member is called into (here and here), a 0 or a 1 is passed in for the queued
parameter. So while task_tick_rt()
doesn't use it, the queued
parameter must still be their so the function pointer types in the struct sched_class
function vector all match up.
In short, the struct sched_class
function vector specifies the interface between scheduling algorithms and the rest of the kernel. The queued
parameter is there should a given algorithm choose to use it, but in the case of Round Robin, it is simply ignored.