Linux 如何在终端查看HZ?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12480486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:23:36  来源:igfitidea点击:

How to check HZ in the terminal?

linuxclock

提问by Hao Shen

I have seen this http://kaasxxx.wordpress.com/2008/01/22/linux-hz-checker/But the script seems not to work. Does anyway know an easy way to check "HZ" in the terminal in Linux?

我见过这个http://kaasxxx.wordpress.com/2008/01/22/linux-hz-checker/但脚本似乎不起作用。无论如何知道在Linux终端中检查“HZ”的简单方法吗?

采纳答案by Andy Ross

There's no uniform answer to this questions, as in some cases your kernel may be compiled "tickless" and not use a regular timer interrupt at all. But if you're on a traditional kernel and a traditional distro, you can find the current kernel's .configfile under /boot with something like grep 'CONFIG_HZ=' /boot/config-$(uname -r).

这个问题没有统一的答案,因为在某些情况下,您的内核可能被编译为“无滴答”并且根本不使用常规定时器中断。但是,如果您使用的是传统内核和传统发行版,则可以.config在 /boot 下找到当前内核的文件,其中包含类似grep 'CONFIG_HZ=' /boot/config-$(uname -r).

回答by user3387542

There are many different approaches to get a hint on what your settings are. On some single-core systems this trick is handy:

有许多不同的方法可以提示您的设置是什么。在一些单核系统上,这个技巧很方便:

/ # cat /proc/interrupts | grep -i time; sleep 10; cat /proc/interrupts | grep time
 16:   10404858      INTC  68 Level     gp_timer
 16:   10514798      INTC  68 Level     gp_timer

It shows you the amount of ticks there were during the 10 sec. sleep. Here about 100'000. Divide by 10 gives about 10'000 HZ.

它会向您显示 10 秒内的滴答数。睡觉。这里大约100'000。除以 10 得到大约 10'000 HZ。

This might get confusing on multicore systems, as it will be a per core list.

这在多核系统上可能会令人困惑,因为它将是每个核心的列表。

Another option will be to check if you can get a hand on the original kernel config. It would be stored in

另一种选择是检查您是否可以使用原始内核配置。它将被存储在

/proc/config.gz

Unpack it and open the file. Search for parts that look similar to

解压并打开文件。搜索看起来相似的零件

CONFIG_HZ_FIXED=0
# CONFIG_HZ_100 is not set
# CONFIG_HZ_200 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
# CONFIG_HZ_500 is not set
# CONFIG_HZ_1000 is not set
CONFIG_HZ_10000=y
CONFIG_HZ=10000
CONFIG_SCHED_HRTICK=y

Just to warn you; 10'000 is way off normal settings. Experimental setup.

只是为了警告你;10'000 与正常设置相差甚远。实验装置。

回答by reichhart

UPDATE: Edited answer according to scai's comment.

更新:根据 scai 的评论编辑答案。

In Bash the "HZ" calculation would look like e.g.

在 Bash 中,“HZ”计算看起来像

$ awk '{print/'$(tail -n 1 /proc/uptime|cut -d. -f1)"}" /proc/self/stat
100

Means: Take the 22nd value of uptime and divide it by the start time of the "self" process.

意思是:取uptime的第22个值除以“self”进程的开始时间。

This delivers just the USER_HZ variable which is always 100 and not kernel's CONFIG_HZ variable.

这仅提供始终为 100 的 USER_HZ 变量,而不是内核的 CONFIG_HZ 变量。

Note: In ancient times there was only oneHZ variable. I guess that "#define USER_HZ 100" was introduced with the split. And I guess also that in terminal/shell usage you are requiring USER_HZ and not CONFIG_HZ.

注:古代只有一个HZ变量。我猜“#define USER_HZ 100”是在拆分中引入的。而且我猜在终端/外壳使用中,您需要 USER_HZ 而不是 CONFIG_HZ

回答by slm

The value of HZ can be determined like so:

HZ 的值可以这样确定:

$ getconf CLK_TCK
100

Any of the compile time options of the running kernel can be gleamed using getconf. Keep in mind that HZ is configurable:

运行内核的任何编译时选项都可以使用getconf. 请记住,HZ 是可配置的:

$ man 7 time

The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100 giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the common video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

The times(2) system call is a special case. It reports times with a granularity defined by the kernel constant USER_HZ. User-space applications can determine thecvalue of this constant using sysconf(_SC_CLK_TCK).

$人7次

HZ 的值因内核版本和硬件平台而异。在 i386 上,情况如下:在 2.4.x 及以下的内核上,HZ 为 100,给出 0.01 秒的 jiffy 值;从 2.6.0 开始,HZ 被提高到 1000,给出 0.001 秒的瞬间。从内核 2.6.13 开始,HZ 值是内核配置参数,可以是 100、250(默认值)或 1000,产生的 jiffies 值分别为 0.01、0.004 或 0.001 秒。从内核 2.6.20 开始,可以使用更多频率:300,这是一个平均分配常见视频帧速率(PAL,25 HZ;NTSC,30 HZ)的数字。

times(2) 系统调用是一个特例。它以内核常量 USER_HZ 定义的粒度报告时间。用户空间应用程序可以使用 sysconf(_SC_CLK_TCK) 确定该常量的 cvalue。

As is typically the case you may need to trim the _SC_bit off of the variable name shown in the man pages when inquiring about it using getconf.

通常情况下,您可能需要_SC_在使用getconf.

回答by thodnev

What you're looking for is inside the configuration of the running kernel /proc/config.gz(if it is enabled, on most systems it is).

您正在寻找的是正在运行的内核的配置内部/proc/config.gz(如果已启用,则在大多数系统上都是如此)。

So you may check the resulting tick rate using:

因此,您可以使用以下方法检查生成的滴答率:

zcat /proc/config.gz | grep CONFIG_HZ