I am studying the Linux kernel and trying to figure out how Round Robin's scheduling algorithm works. There kernel\sched_rt.cis a method in the file called task_tick_rtlike this:
static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
{
update_curr_rt(rq);
watchdog(rq, p);
if (p->policy != SCHED_RR)
return;
if (--p->rt.time_slice)
return;
p->rt.time_slice = DEF_TIMESLICE;
if (p->rt.run_list.prev != p->rt.run_list.next) {
requeue_task_rt(rq, p, 0);
set_tsk_need_resched(p);
}
}
What I do not understand (besides the fact that there is a useless parameter queued) is what the code is trying to achieve through verification if (--p->rt.time_slice). I don’t understand why the task list pointer is preduced by 1, in other words, why does the method check the previous task instead of the current one? Any clarification on this subject is welcome.
source
share