实时进程RT的调度策略RR - Time Slice

Time Slice 目前只用于RR策略.
默认的时间片长度是100 毫秒

/*
 * These are the 'tuning knobs' of the scheduler:
 *
 * default timeslice is 100 msecs (used only for SCHED_RR tasks).
 * Timeslices get refilled after they expire.
 */
#define DEF_TIMESLICE       (100 * HZ / 1000)

当处理Tick 的周期调度任务时

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)?// 如果不等于RR的话直接返回.
        return;

    if (--p->rt.time_slice)// 时间片减去1单位
        return;

    p->rt.time_slice = DEF_TIMESLICE;//(100 * HZ / 1000)

    /*
     * 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);// 如果当前进程不是RQ上面的唯一进程时,重新加到队列尾部.
        set_tsk_need_resched(p);//设置重新需要调度标志位.
    }
}

把task 放到队列尾部.

/*
 * Put task to the end of the run list without the overhead of dequeue
 * followed by enqueue.
 */
static void
requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head)
{
    if (on_rt_rq(rt_se)) {
        struct rt_prio_array *array = &rt_rq->active;
        struct list_head *queue = array->queue + rt_se_prio(rt_se);

        if (head)
            list_move(&rt_se->run_list, queue);
        else
            list_move_tail(&rt_se->run_list, queue);
    }
}

猜你喜欢

转载自blog.csdn.net/yuzaipiaofei/article/details/78089219