sched_wakeup_granularity_ns , sched_min_granularity_ns 和 SCHED_RR

sched_wakeup_granularity_ns , sched_min_granularity_ns and SCHED_RR

我的盒子中的以下值:

sysctl -A | grep "sched" | grep -v "domain"

kernel.sched_autogroup_enabled = 0
kernel.sched_cfs_bandwidth_slice_us = 5000
kernel.sched_child_runs_first = 0
kernel.sched_latency_ns = 18000000
kernel.sched_migration_cost_ns = 5000000
kernel.sched_min_granularity_ns = 10000000
kernel.sched_nr_migrate = 32
kernel.sched_rr_timeslice_ms = 100
kernel.sched_rt_period_us = 1000000
kernel.sched_rt_runtime_us = 950000
kernel.sched_shares_window_ns = 10000000
kernel.sched_time_avg_ms = 1000
kernel.sched_tunable_scaling = 1
kernel.sched_wakeup_granularity_ns = 3000000

表示一秒后,0.95秒为SCHED_FIFO或SCHED_RR, 只有 0.05 保留给 SCHED_OTHER ,我很好奇的是
sched_wakeup_granularity_ns ,我用谷歌搜索并得到了解释:

Ability of tasks being woken to preempt the current task. 
The smaller the value, the easier it is for the task to force the preemption

我认为sched_wakeup_granularity_ns只影响SCHED_OTHER任务, SCHED_FIFO 和 SCHED_RR 不应该处于睡眠模式,所以不需要 "wakeup", 我说得对吗?!

对于sched_min_granularity_ns,解释是:

Minimum preemption granularity for processor-bound tasks. 
Tasks are guaranteed to run for this minimum time before they are preempted

我想知道,虽然 SCHED_RR 任务可以有 95% 的 cpu 时间,但是 因为 sched_min_granularity_ns 值 = 10000000,所以是 0.01 秒, 这意味着每个 SCHED_OTHER 在被抢占之前获得 运行 的 0.01 秒时间片,除非它被阻塞套接字或睡眠或其他阻塞,这意味着如果我在核心 1 中有 3 个任务,例如,2 个任务使用 SCHED_RR ,第三个任务使用 SCHED_OTHER ,第三个任务只是 运行 一个无限循环,没有阻塞套接字 recv 并且没有 yield ,所以一旦第三个任务获得 cpu和 运行 ,它将 运行 0.01 秒 然后上下文切换,即使下一个任务优先于 SCHED_RR , 这是对 sched_min_granularity_ns 用法的正确理解 ?!

编辑:

http://lists.pdxlinux.org/pipermail/plug/2006-February/045495.html

描述:

No SCHED_OTHER process may be preempted by another SCHED_OTHER process.
However a SCHED_RR or SCHED_FIFO process will preempt SCHED_OTHER
process before their time slice is done. So a SCHED_RR process
should wake up from a sleep with fairly good accuracy.

意味着SCHED_RR任务可以抢占无限的while循环而不会阻塞甚至 时间片没有完成?!

具有较高调度 class "priority" 的任务将抢占具有较低优先级调度 class 的所有任务,而不管任何超时。看看下面来自 kernel/sched/core.c 的片段:

void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
{
    const struct sched_class *class;

    if (p->sched_class == rq->curr->sched_class) {
        rq->curr->sched_class->check_preempt_curr(rq, p, flags);
    } else {
        for_each_class(class) {
            if (class == rq->curr->sched_class)
                break;
            if (class == p->sched_class) {
                resched_curr(rq);
                break;
            }
        }
    }

    /*
     * A queue event has occurred, and we're going to schedule.  In
     * this case, we can save a useless back to back clock update.
     */
    if (task_on_rq_queued(rq->curr) && test_tsk_need_resched(rq->curr))
        rq_clock_skip_update(rq, true);
}

for_each_class 将 return class 的顺序为:停止、截止日期、rt、公平、空闲。当尝试抢占与抢占任务具有相同调度 class 的任务时,循环将停止。

所以对于你的问题,答案是肯定的,"rt" 任务将抢占 "fair" 任务。