两个证据表明,Linux 交换器任务(空闲)在禁用预谋的情况下运行:
1:使用INIT_PREEMPT_COUNT初始化的抢占计数对象,值为“1”,表示禁用抢占。
#define INIT_THREAD_INFO(tsk) \
{ \
.task = &tsk, \
.flags = 0, \
.preempt_count = INIT_PREEMPT_COUNT, \
.addr_limit = KERNEL_DS, \
}
2.从irqsoff的ftrace中,preempt-depth设置为1,表示禁止抢占。
# tracer: irqsoff
#
# irqsoff latency trace v1.1.5 on 4.15.10+
# --------------------------------------------------------------------
# latency: 3464 us, #4/4, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
# -----------------
# | task: swapper/2-0 (uid:0 nice:0 policy:0 rt_prio:0)
# -----------------
# => started at: rcu_idle_exit
# => ended at: rcu_idle_exit
#
#
# _------=> CPU#
# / _-----=> irqs-off
# | / _----=> need-resched
# || / _---=> hardirq/softirq
# ||| / _--=> preempt-depth
# |||| / delay
# cmd pid ||||| time | caller
# \ / ||||| \ | /
<idle>-0 2dn.1 927us#: rcu_idle_exit
<idle>-0 2dn.1 3067us!: rcu_idle_exit
<idle>-0 2dn.1 3645us#: trace_hardirqs_on <-rcu_idle_exit
<idle>-0 2dn.1 5713us : <stack trace>
那么,为什么要这样设计呢?