NOHZ = On如何影响linux内核中的do_timer

在一个简单的实验中,我设置NOHZ = OFF,并使用printk打印do_timer函数被调用的频率.它在我的机器上每10ms调用一次.

但是如果NOHZ = ON,那么do_timer被调用的方式有很多抖动.大多数时候,它每10毫秒都会被调用,但有时它完全错过了最后期限.

我已经研究了do_timer和NOHZ. do_timer是负责更新jiffies值的功能,同时也负责进程的循环调度.

NOHZ功能关闭系统上的高保真定时器.

我无法理解的是高分辨率定时器如何影响do_timer?即使高分辨率硬件处于睡眠状态,持续时钟也能够每10ms执行一次do_timer.其次,如果do_timer在执行时不执行,那意味着某些进程在理想情况下不会得到分时.很多谷歌搜索确实显示,对于许多人来说,当NOHZ = OFF时,许多应用程序开始工作得更好.

要长篇小说,NOHZ = ON如何影响do_timer?
为什么do_timer错过了最后期限?

首先让我们明白什么是无节点内核(NOHZ = On或CONFIG_NO_HZ),从2.6.17开始将其引入 Linux内核的动机是什么

http://www.lesswatts.org/projects/tickless/index.php,

Traditionally, the Linux kernel used a periodic timer for each CPU.
This timer did a variety of things, such as process accounting,
scheduler load balancing, and maintaining per-CPU timer events. Older
Linux kernels used a timer with a frequency of 100Hz (100 timer events
per second or one event every 10ms), while newer kernels use 250Hz
(250 events per second or one event every 4ms) or 1000Hz (1000 events
per second or one event every 1ms).

This periodic timer event is often called “the timer tick”. The timer
tick is simple in its design, but has a significant drawback: the
timer tick happens periodically, irrespective of the processor state,
whether it’s idle or busy. If the processor is idle, it has to wake up
from its power saving sleep state every 1, 4, or 10 milliseconds. This
costs quite a bit of energy, consuming battery life in laptops and
causing unnecessary power consumption in servers.

With “tickless idle”, the Linux kernel has eliminated this periodic
timer tick when the CPU is idle. This allows the CPU to remain in
power saving states for a longer period of time, reducing the overall
system power consumption.

因此,降低功耗是无内核的主要动力之一.但是,随着时间的流逝,大部分时间,性能下降了功耗.对于台式机来说,性能是非常重要的,因此您可以看到,对于大多数人来说,NOHZ = OFF功能非常好.

在Ingo Molnar自己的话

The tickless kernel feature (CONFIG_NO_HZ) enables ‘on-demand’ timer
interrupts: if there is no timer to be expired for say 1.5 seconds
when the system goes idle, then the system will stay totally idle for
1.5 seconds. This should bring cooler CPUs and power savings: on our (x86) testboxes we have measured the effective IRQ rate to go from HZ
to 1-2 timer interrupts per second.

现在,让我们尝试回答你的问题 –

What I am unable to understand is how can hi-res timers affect the
do_timer ?

如果系统支持高精度定时器,则大多数系统上的定时器中断可能比通常的10ms更频繁.即这些定时器试图通过利用系统功能和更快地触发定时器中断来使系统更加灵敏,比如说每100us一次.所以使用NOHZ选项,这些定时器被冷却,因此do_timer的执行次数就会降低

Even if hi-res hardware is in sleep state the persistent clock is more
than capable to execute do_timer every 10ms

是的,有能力但NOHZ的意图恰恰相反.防止频繁的定时器中断!

Secondly if do_timer is not executing when it should that means some
processes are not getting their timeshare when they should ideally be
getting it

正如caf在评论中指出的那样,NOHZ不会导致进程得到更少的安排,因为它只在CPU空闲时才启动 – 换句话说,当没有进程可调度时.只有进程会计资料将在延迟的时间完成.

Why does do_timer miss it’s deadlines ?

详细说明,这是NOHZ的设计

我建议你通过tick-sched.c内核源码作为起点.搜索CONFIG_NO_HZ,并尝试了解为NOHZ功能添加的新功能

这是测试Impact of a Tickless Kernel的一个测试

相关文章
相关标签/搜索