Understading the Linux Kernel Scheduler

孤街醉人 提交于 2019-12-03 16:33:00

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!