How to check HZ in the terminal?

2019-02-06 06:35发布

问题:

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?

回答1:

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



回答2:

In my C programs I use the start time of a process and the uptime and more for some value calculations at runtime.

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.

EDIT:

Yes, user1530335, this is correct. Additional info about the stat file can be taken from the man page proc(5). Here the field "starttime" is described as "the time in jiffies the process started after system boot".

Yes, and mostly (Intel arch) it will be 100. Older rare "preempt" kernels sometimes had 1000 even on Intel. Other values could be:

/**
 * 10 S/390 (sometimes)
 * 20 User-mode Linux
 * 32 ia64 emulator
 * 64 StrongARM /Shark
 * 100 normal Linux
 * 128 MIPS, ARM
 * 1000 ARM
 * 1024 Alpha, ia64
 * 1200 Alpha
 */


回答3:

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.



回答4:

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.



标签: linux clock