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

查看:390
本文介绍了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=ONdo_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个计时器事件 每秒或一个事件每10ms),而较新的内核使用250Hz (每秒250个事件,或每4ms一个事件)或1000Hz(1000个事件 每秒或每1ms发生一次事件).

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

此定期计时器事件通常称为计时器滴答".计时器 勾号在设计上很简单,但有一个明显的缺点: 计时器滴答声是周期性发生的,与处理器状态无关, 无论是闲置还是忙碌.如果处理器空闲,则必须唤醒 从每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.

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

这是一项旨在测量影响的测试不滴答的内核

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

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