NOHZ=ON 如何影响 Linux 内核中的 do_timer()? [英] How NOHZ=ON affects do_timer() in Linux kernel?

查看:23
本文介绍了NOHZ=ON 如何影响 Linux 内核中的 do_timer()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In a simple experiment I set NOHZ=OFF and used printk() to print how often the do_timer() function gets called. It gets called every 10 ms on my machine.

然而,如果NOHZ=ON 那么do_timer() 被调用的方式会有很多抖动.大多数情况下,它确实每 10 毫秒被调用一次,但有时它会完全错过最后期限.

However if NOHZ=ON then there is a lot of jitter in the way do_timer() gets called. Most of the times it does get called every 10 ms but there are times when it completely misses the deadlines.

我研究了 do_timer() 和 NOHZ.do_timer() 是负责更新jiffies 值的函数,也负责进程的循环调度.

I have researched about both do_timer() and NOHZ. do_timer() is the function responsible for updating jiffies value and is also responsible for the round robin scheduling of the processes.

NOHZ 功能会关闭系统上的高分辨率计时器.

NOHZ feature switches off the hi-res timers on the system.

我无法理解的是高分辨率计时器如何影响 do_timer()?即使高分辨率硬件处于睡眠状态,持久时钟也足以每 10 毫秒执行一次 do_timer().其次,如果 do_timer() 没有在它应该执行的时候执行,这意味着某些进程没有在理想情况下获得它们的分时度假.许多谷歌搜索确实表明,对于许多人来说,当 NOHZ=OFF 时,许多应用程序开始工作得更好.

What I am unable to understand is how can hi-res timers affect the do_timer()? Even if hi-res hardware is in sleep state the persistent clock is more than capable to execute do_timer() every 10 ms. 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. A lot of googling does show that for many people many applications start working much better when NOHZ=OFF.

长话短说,NOHZ=ON 如何影响 do_timer()?
为什么 do_timer() 错过了截止日期?

To make long story short, how does NOHZ=ON affect do_timer()?
Why does do_timer() miss its deadlines?

推荐答案

首先让我们了解什么是 tickless kernel ( NOHZ=OnCONFIG_NO_HZ set ) 以及将其从 2.6.17

First lets understand what is a tickless kernel ( NOHZ=On or CONFIG_NO_HZ set ) and what was the motivation of introducing it into the Linux Kernel from 2.6.17

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

传统上,Linux 内核为每个 CPU 使用一个周期性计时器.这个计时器做了很多事情,比如进程记账,调度程序负载平衡,并维护每个 CPU 的计时器事件.年长的Linux 内核使用频率为 100Hz 的定时器(100 个定时器事件每秒或每 10 毫秒一个事件),而较新的内核使用 250Hz(每秒 250 个事件或每 4ms 一个事件)或 1000Hz(1000 个事件每秒或每 1 毫秒一个事件).

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).

这个周期性的定时器事件通常被称为定时器滴答".计时器tick 的设计很简单,但有一个明显的缺点:无论处理器状态如何,定时器滴答都会定期发生,不管是闲的还是忙的.如果处理器空闲,它必须唤醒每 1、4 或 10 毫秒从其省电睡眠状态开始.这消耗相当多的能源,消耗笔记本电脑的电池寿命和造成服务器不必要的功耗.

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.

通过tickless idle",Linux 内核消除了这种周期性CPU空闲时定时器滴答.这允许 CPU 保持在更长时间的省电状态,降低整体系统功耗.

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 运行良好.

So reducing power consumption was one of the main motivations of the tickless kernel. But as it goes, most of the times, Performance takes a hit with decreased power consumption. For desktop computers, performance is of utmost concern and hence you see that for most of them NOHZ=OFF works pretty well.

Ingo Molnar 自己的话

In Ingo Molnar's own words

无滴答内核功能 (CONFIG_NO_HZ) 启用按需"计时器中断:如果没有计时器到期,例如 1.5 秒当系统空闲时,系统将保持完全空闲状态1.5 秒.这应该会带来更凉爽的 CPU 和节能:在我们的 (x86) 测试盒上,我们测量了从 HZ 开始的有效 IRQ 速率到每秒 1-2 次定时器中断.

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.

现在,让我们尝试回答您的疑问-

Now, lets try to answer your queries-

我无法理解的是高分辨率计时器如何影响do_timer ?

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

如果系统支持高分辨率计时器,则在大多数系统上,计时器中断可能比通常的 10ms 更频繁地发生.即这些计时器试图通过利用系统功能和更快地触发计时器中断来使系统响应更快,例如每 100us.因此,使用 NOHZ 选项,这些计时器会冷却下来,因此 do_timer

If a system supports high-res timers, timer interrupts can occur more frequently than the usual 10ms on most systems. i.e these timers try to make the system more responsive by leveraging the system capabilities and by firing timer interrupts even faster, say every 100us. So with NOHZ option, these timers are cooled down and hence the lower execution of do_timer

即使高分辨率硬件处于睡眠状态,持久时钟也更多能够每 10 毫秒执行一次 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的意图恰恰相反.防止定时器频繁中断!

Yes it is capable. But the intention of NOHZ is exactly the opposite. To prevent frequent timer interrupts!

其次,如果 do_timer 在它应该执行的时候没有执行,这意味着一些流程在理想情况下没有得到他们的分时度假得到它

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 空闲时启动 - 换句话说,当没有进程可调度时.只有流程会计的东西会延迟完成.

As caf noted in the comments, NOHZ does not cause processes to get scheduled less often, because it only kicks in when the CPU is idle - in other words, when no processes are schedulable. Only the process accounting stuff will be done at a delayed time.

为什么 do_timer 会错过截止日期?

Why does do_timer miss it's deadlines ?

正如所阐述的,这是NOHZ

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

I suggest you go through the tick-sched.c kernel sources as a starting point. Search for CONFIG_NO_HZ and try understanding the new functionality added for the NOHZ feature

这里进行了一项测试来衡量 一个 Tickless 内核

Here is one test performed to measure the Impact of a Tickless Kernel

这篇关于NOHZ=ON 如何影响 Linux 内核中的 do_timer()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆