降低Linux内核计时器频率 [英] Lowering linux kernel timer frequency

查看:739
本文介绍了降低Linux内核计时器频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我以Gentoo的身份运行虚拟机时,我发现tick_periodic函数会产生相当大的开销. (此函数在每个计时器中断上运行.)此函数使用write_seqlocks更新全局jiffy,这会导致开销.

When I run my Virtual Machine with Gentoo as guest, I have found that there is considerable overhead coming from tick_periodic function. (This is the function which runs on every timer interrupt.) This function updates a global jiffy using write_seqlocks which leads to the overhead.

这是我的内核配置文件中的HZ以及相关内容的一小部分.

Here's a grep of HZ and relevant stuff in my kernel config file.

sharan013@sitmac4:~$ cat /boot/config | egrep 'HZ|TIME'

# CONFIG_RCU_FAST_NO_HZ is not set
CONFIG_NO_HZ=y
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000
# CONFIG_MACHZ_WDT is not set
CONFIG_TIMERFD=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_X86_CYCLONE_TIMER=y
CONFIG_HPET_TIMER=y

很显然,它已将配置设置为1000,但是当我执行sysconf(_SC_CLK_TCK)时,我得到100作为我的计时器频率.那么我的系统的计时器频率是多少?

Clearly it has set the configuration to 1000, but when I do sysconf(_SC_CLK_TCK), I get 100 as my timer frequency. So what is my system's timer frequency?

我想做的是将频率降低到100,如果可能的话甚至更低.尽管这可能会影响poll/select和调度程序时间片的交互性和精度,但我准备为减少计时器中断而牺牲这些东西,因为这会加快VM的速度.

What I want to do is to bring the frequency down to 100, even lower if possible. Although it might effect the interactivity and precision of poll/select and schedulers time slice, I am ready to sacrifice these things for lesser timer interrupt as it will speed up VM.

当我试图找出必须要做的事情时,我在某个地方读取了可以通过更改配置文件来读取的内容,否则,我看到在引导参数上添加divider = 10即可完成工作,否则读取我读到,如果即使不增加计时器频率也可以将CONFIG_HIGH_RES_TIMERS设置为可实现低等待时间的计时器,则不需要任何操作,而对于无滴答系统CONFIG_NO_HZ,也可以这样做.

When I tried to find out what has to be done I read in some place that you can do so by changing in the configuration file, else where I read that adding divider=10 to the boot parameter does the job, else where I read that none of it is needed if you can set the CONFIG_HIGH_RES_TIMERS to acheive low-latency timers even without increasing the timer frequency and the same is possible with a tickless system CONFIG_NO_HZ.

我对什么是正确的方法感到非常困惑.

I am extermely confused about what is the right approach.

我想要做的就是将计时器中断降低到尽可能低的水平.

All I want is to bring down the timer interrupt to as low as possible.

我能知道正确的方法吗?

Can I know the right way of doing this?

推荐答案

别担心!您的困惑不过是期望而已. Linux计时器中断非常令人困惑,并且有着悠久而令人兴奋的历史.

Don't worry! Your confusion is nothing but expected. Linux timer interrupts are very confusing and have had a long and quite exciting history.

CLK_TCK

Linux没有sysconf系统调用,而glibc仅返回常数100.对不起.

Linux has no sysconf system call and glibc is just returning the constant value 100. Sorry.

HZ <-您可能想要的

HZ <-- what you probably want

在配置内核时,您可以选择100Hz,250Hz,300Hz或1000Hz的定时器频率.所有这些都受支持,尽管默认值为1000Hz,但它并不总是最好的.

When configuring your kernel you can choose a timer frequency of either 100Hz, 250Hz, 300Hz or 1000Hz. All of these are supported, and although 1000Hz is the default it's not always the best.

人们通常会在评估延迟(台式机或Web服务器)时选择较高的值,而在评估吞吐量(HPC)时选择较低的值.

People will generally choose a high value when they value latency (a desktop or a webserver) and a low value when they value throughput (HPC).

CONFIG_HIGH_RES_TIMERS

这与计时器中断无关,它只是一种允许您使用更高分辨率计时器的机制.这基本上意味着select之类的呼叫超时可以比1/HZ秒更准确.

This has nothing to do with timer interrupts, it's just a mechanism that allows you to have higher resolution timers. This basically means that timeouts on calls like select can be more accurate than 1/HZ seconds.

除法器

此命令行选项是Red Hat提供的补丁.您可能可以使用它(如果您使用的是Red Hat或CentOS),但是我会小心.这会导致很多错误,您可能应该使用不同的Hz值重新编译.

This command line option is a patch provided by Red Hat. You can probably use this (if you're using Red Hat or CentOS), but I'd be careful. It's caused lots of bugs and you should probably just recompile with a different Hz value.

CONFIG_NO_HZ

这实际上并没有做什么用,这是为了节省功率,这意味着当什么都不执行时,滴答声将停止(或至少变得不那么频繁).这可能已经在您的内核上启用了.至少有一个任务可以运行时,它没有任何区别.

This really doesn't do much, it's for power saving and it means that the ticks will stop (or at least become less frequent) when nothing is executing. This is probably already enabled on your kernel. It doesn't make any difference when at least one task is runnable.

Frederic Weisbecker实际上有一个待处理的补丁程序,可以将其推广到仅运行单个任务的情况,但是距离还很遥远.

Frederic Weisbecker actually has a patch pending which generalizes this to cases where only a single task is running, but it's a little way off yet.

这篇关于降低Linux内核计时器频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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