CONFIG_PREEMPT 和 CONFIG_PREEMPT_VOLUNTARY的区别

在kernel/kernel/Kconfig.preempt中定义了两种抢占策略,PREEMPT_VOLUNTARY和PREEMPT
其中PREEMPT_VOLUNTARY 适用于有桌面的环境,而PREEMPT 则可以用于桌面或者嵌入式,其调度延迟是毫秒级别的。详细说明如下:
config PREEMPT_VOLUNTARY
    bool "Voluntary Kernel Preemption (Desktop)"
    help
      This option reduces the latency of the kernel by adding more
      "explicit preemption points" to the kernel code. These new
      preemption points have been selected to reduce the maximum
      latency of rescheduling, providing faster application reactions,
      at the cost of slightly lower throughput.

      This allows reaction to interactive events by allowing a
      low priority process to voluntarily preempt itself even if it
      is in kernel mode executing a system call. This allows
      applications to run more 'smoothly' even when the system is
      under load.

      Select this if you are building a kernel for a desktop system.

config PREEMPT
    bool "Preemptible Kernel (Low-Latency Desktop)"
    select PREEMPT_COUNT
    select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
    help
      This option reduces the latency of the kernel by making
      all kernel code (that is not executing in a critical section)
      preemptible.  This allows reaction to interactive events by
      permitting a low priority process to be preempted involuntarily
      even if it is in kernel mode executing a system call and would
      otherwise not be about to reach a natural preemption point.
      This allows applications to run more 'smoothly' even when the
      system is under load, at the cost of slightly lower throughput
      and a slight runtime overhead to kernel code.

      Select this if you are building a kernel for a desktop or
      embedded system with latency requirements in the milliseconds

从code中看主要影响下面这两个函数
static inline void crypto_yield(u32 flags)
{
#if !defined(CONFIG_PREEMPT) || defined(CONFIG_PREEMPT_VOLUNTARY)
    if (flags & CRYPTO_TFM_REQ_MAY_SLEEP)
        cond_resched();
#endif
}
在crypto_yield 中如果定义了CONFIG_PREEMPT_VOLUNTARY 就调度,而CONFIG_PREEMPT 则是不调度的,继续留在原来的task中

#ifdef CONFIG_PREEMPT_VOLUNTARY
extern int _cond_resched(void);
# define might_resched() _cond_resched()
#else
# define might_resched() do { } while (0)
#endif
如果code中调用might_resched的话,就发生调度。

从code中看CONFIG_PREEMPT_VOLUNTARY 就是会比 CONFIG_PREEMPT 的调度延迟少一点。
对于内存管理延迟,从延迟的来源处理过程出发提出解决方案 ,根据前文我们发现可以从内核的抢占性出发进行优化,提出 解决方案如下 (1)启用完全抢占内核(Preemptible Kernel)打补丁(如PREEMPT_ RT)修改内核为完全可抢占模式,允许在内核任意位置被高优先级任务 抢占。 启用完全抢占内核(Preemptible Kernel)是提升系统响应能力的关键技 术手段。通过为Linux内核打上实时补丁(如PREEMPT_RT),可以将标准 内核修改为完全可抢占模式。这种模式下,内核在执行过程中几乎任意位 置(除极少数不可中断的原子上下文,如中断处理、自旋锁保护区域等) 都可以被更高优先级的任务立即抢占。这种机制显著降低了任务调度延迟 ,使得高优先级任务能够获得毫秒级甚至微秒级的响应速度。 PREEMPT_RT补丁通过重构内核锁机制、将自旋锁替换为可睡眠的互斥锁、 将中断处理线程化等技术手段,大幅增加了内核的可抢占点。相比标准 Linux内核的三种抢占模式(无抢占、自愿抢占完全抢占),经过 PREEMPT_RT补丁修改后的内核实现了真正的全内核范围抢占。这种改进特 别适用于工业控制、自动驾驶、高频交易等对延迟敏感的领域,在这些场 景中,即使是几十微秒的延迟差异也可能导致严重后果 (2)配置抢占模式 通过内核编译选项调整抢占策略: CONFIG_PREEMPT_NONE:无主动抢占,吞吐量优先。 CONFIG_PREEMPT_VOLUNTARY:插入主动让步点,平衡吞吐与延迟。 CONFIG_PREEMPT:允许内核抢占,适用于桌面实时性需求。
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值