我正在学习Linux内核,并试图弄清楚循环调度算法的工作原理。在kernel\sched_rt.c
文件中,有一个名为task_tick_rt
的方法,定义如下:
static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
{
update_curr_rt(rq);
watchdog(rq, p);
/*
* RR tasks need a special form of timeslice management.
* FIFO tasks have no timeslices.
*/
if (p->policy != SCHED_RR)
return;
if (--p->rt.time_slice)
return;
p->rt.time_slice = DEF_TIMESLICE;
/*
* Requeue to the end of queue if we are not the only element
* on the queue:
*/
if (p->rt.run_list.prev != p->rt.run_list.next) {
requeue_task_rt(rq, p, 0);
set_tsk_need_resched(p);
}
除了有一个无用的queued
参数之外,我不明白这段代码试图通过if(--p->rt.time_slice)
检查达到什么目的。我不理解为什么任务列表指针p
被减1,换句话说,为什么该方法要检查前一个任务而不是当前任务?如有任何疑问,请解释清楚。
SCHED_FIFO
和SCHED_RR
。然而,查看http://lxr.missinglinkelectronics.com/#linux+v3.10/kernel/sched/rt.c#L1 sched/rt.c,我无法弄清楚sched_class如何协助选择使用哪种策略。 - newprint