Linux: config: NO_HZ; CONFIG_NO_HZ_FULL;nohz

318 篇文章 ¥69.90 ¥99.00
本文介绍了Linux中的NO_HZ配置,包括NO_HZ和NO_HZ_FULL,它们旨在减少不必要的tick中断以节省能源。当CPU空闲或运行单一任务时,系统尝试关闭tick。依赖于特定的内核参数和配置,如SMP和IRQ_WORK。NO_HZ_FULL允许在用户态和内核态切换时动态调整tick,但可能导致一些过渡开销。通过nohz_full和nohz启动参数进行配置,适用于低负载场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考

https://www.kernel.org/doc/html/latest/timers/no_hz.html
https://access.redhat.com/articles/3720611
https://access.redhat.com/articles/4200151
https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html
https://wxdublin.gitbooks.io/deep-into-linux-and-beyond/content/idle_scheduling_class.html

config NO_HZ

布尔值,这是一个旧的动态tick空闲的配置。这个dynticks需要了解具体的概念,这里不介绍。
依赖!ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTS
描述:This is the old config entry that enables dynticks idle. We keep it around for a little while to enforce backward compatibility with older config files.
这个配置的存在完全是为了兼容之前老的配置文件。

timer_interrupt() 是 Linux 内核中的一个定时器中断处理函数,它主要用于处理内核中的各种定时器事件,包括时钟中断、定时器任务等。 源码如下: ```c void __irqentry timer_interrupt(struct pt_regs *regs) { ... update_process_times(user_mode(regs)); profile_tick(CPU_PROFILING, user_mode(regs), regs); if (user_mode(regs)) return; irq_enter(); #ifdef CONFIG_NO_HZ_COMMON /* * The tick broadcast device is disabled after the first * CPU goes offlined, see tick_nohz_enable. */ if (tick_nohz_tick_stopped()) goto out; #endif tick_check_idle(TICK_NMI_SAFE); /* * Tickless idle is in progress. */ if (idle_cpu(smp_processor_id())) { watchdog_touch(); smp_idle_check(); goto out; } /* * Check if we need to do anything at all: */ if (!tick_check_oneshot_broadcast(tick_nohz_full_cpu_idle())) { if (tick_check_oneshot() && !tick_check_broadcast_expired() && !tick_broadcast_oneshot_active()) { tick_program_event(tick_oneshot_broadcast, oneshot_timer.expires); goto out; } if (tick_check_broadcast_spurious()) goto out; if (tick_check_cpu_dead(cpu) || tick_check_new_device(cpu)) goto out; tick_check_replacement(cpu); } /* * Re-enable periodic tick if it is stopped and there are no * oneshot or broadcast events pending: */ if (tick_check_periodic() && !tick_check_oneshot_active() && !tick_check_broadcast_active()) tick_program_event(tick_periodic, tick_next_period); out: irq_exit(); ... } ``` 该函数的主要流程如下: 1. 调用 update_process_times() 和 profile_tick() 更新进程的时间信息和性能分析信息。 2. 判断是否是用户态,如果是则直接返回。 3. 调用 irq_enter() 进入中断上下文。 4. 检查 tickless idle 是否正在进行,如果是,则直接返回。 5. 检查是否正在进行 idle,如果是,则调用 watchdog_touch() 和 smp_idle_check(),并直接返回。 6. 检查是否需要进行任何操作。 7. 如果需要,检查是否需要启动一次性定时器事件。 8. 如果需要,检查是否需要启动广播定时器事件。 9. 如果需要,检查是否需要停止定时器,并重新启动。 10. 调用 irq_exit() 退出中断上下文。 总的来说,timer_interrupt() 函数主要用于检查和处理各种定时器事件,以保证内核的正常运行。这些事件包括一次性定时器、广播定时器、周期性定时器等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mzhan017

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值