sched_wakeup_granularity_ns:调度唤醒粒度时间(纳秒) sched_min_granularity_ns:最小调度粒度时间(纳秒) SCHED_RR:循环调度策略,是一种实时优先级调度算法。

3
我的盒子里有以下数值:
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 不需要进入睡眠状态,因此无需“唤醒”, 我的理解正确吗?!

而对于 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 任务可以在时间片未完成的情况下抢占无限循环而不会阻塞?!

1个回答

2

具有更高调度类“优先级”的任务将抢占所有具有较低优先级调度类的任务,无论任何超时。请查看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将按照以下顺序返回类:stop,deadline,rt,fair,idle。当尝试抢占具有与抢占任务相同调度类的任务时,循环将停止。

因此,对于您的问题,答案是肯定的,“rt”任务将抢占“fair”任务。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接