Linux kernel sched_唤醒粒度、sched_最小粒度和sched_RR
“我的”框中的以下值:Linux kernel sched_唤醒粒度、sched_最小粒度和sched_RR,linux-kernel,scheduler,Linux Kernel,Scheduler,“我的”框中的以下值: 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 kerne
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_,我在谷歌上搜索了一下,得到了解释:
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_粒度只会影响sched_其他任务,
SCHED_FIFO和SCHED_RR不应处于睡眠模式,因此无需“唤醒”,
我说的对吗
对于sched_min_粒度,解释如下:
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_粒度值=10000000,因此为0.01秒,
这意味着每个SCHED_OTHER在被抢占之前都有0.01秒的时间片运行,除非它被阻塞套接字或睡眠或其他方式阻塞,这意味着如果我在core 1中有3个任务,例如,2个任务带有SCHED_RR,第三个任务带有SCHED_OTHER,第三个任务只是运行一个无止境的循环,没有阻塞socket recv,也没有屈服,所以一旦第三个任务得到cpu并运行,它将运行0.01秒
然后切换出上下文,即使下一个任务是SCHED_RR的优先级,
这是对sched_min_粒度使用的正确理解
编辑:
描述:
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循环,而不会阻塞
时间片还没完成 具有较高调度级别“优先级”的任务将优先于具有较低优先级调度级别的所有任务,而不管是否有超时。看一下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);
}
对于_,每个_类将按以下顺序返回类:停止、截止日期、rt、公平、空闲。当尝试抢占与抢占任务具有相同调度类的任务时,循环将停止
所以对于你的问题,答案是肯定的,“rt”任务将先于“公平”任务