Understading Linux Kernel Scheduler

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);

    /*
     * 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);
    }

}

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.

+4
source share
1 answer

c http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence

-> , ++, :

if (--(p->rt.time_slice))

, , , .


queued , . , , task_tick_rt(). - .task_tick rt_sched_class struct sched_class: http://lxr.free-electrons.com/source/kernel/sched/rt.c#L1991

, , struct sched_class, ​​ . , , CFS ( ) struct sched_class, fair_sched_class: http://lxr.free-electrons.com/source/kernel/sched/fair.c#L6179

.task_tick CFS task_tick_fair(): http://lxr.free-electrons.com/source/kernel/sched/fair.c#L5785

task_tick_fair() queued. , .task_tick ( ), queued 0 1. , task_tick_rt() , queued , struct sched_class .

, struct sched_class . queued , Round Robin .

+7

All Articles