【发布时间】:2013-10-20 01:39:54
【问题描述】:
我正在研究 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,换句话说,为什么方法检查上一个任务 而不是当前的?对此的任何澄清表示赞赏。
【问题讨论】:
标签: c linux linux-kernel scheduler