How to check HZ in the terminal?

萝らか妹 提交于 2019-11-30 08:32:17

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 .config file under /boot with something like grep 'CONFIG_HZ=' /boot/config-$(uname -r).

The value of HZ can be determined like so:

$ 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:

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

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.

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.

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.

UPDATE: Edited answer according to scai's comment.

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

$ awk '{print$22/'$(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.

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

Note: In ancient times there was only one HZ 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.

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

So you may check the resulting tick rate using:

zcat /proc/config.gz | grep CONFIG_HZ
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!