Linux HZ checker

22 01 2008

HZ defined how many ticks the internal timer interrupt in 1sec, which means the number of jiffies count in 1 sec.

Different architecture/machine may have different HZ value, you can check using this script from the timer interrupt:

#!/bin/sh
while [ 1 ]; do
A=`cat /proc/interrupts | grep timer | cut -d ‘:’ -f 2 |sed -e ‘s/[^0-9]//g’`
sleep 1
B=`cat /proc/interrupts | grep timer | cut -d ‘:’ -f 2 |sed -e ‘s/[^0-9]//g’`
C=$(($B-$A));
echo “HZ:$C”
done

it is around 250 in my desktop running 2.6, but 100 in my mips 2.4 embedded board.

Sometimes we may need to know the time in seconds from jiffies in kernel.

time(sec) = jiffies/HZ;


Actions

Information

5 responses

10 03 2009
Lincoln

The script wouldn’t work for me. So I used awk instead of cut. It might be a little simpler also.

#!/bin/sh
while [ 1 ]; do
A=`cat /proc/interrupts | grep timer | awk ‘{ print $2 }’`
sleep 1
B=`cat /proc/interrupts | grep timer | awk ‘{ print $2 }’`
C=$(($B-$A));
echo “HZ:$C”
done

5 06 2010
Jules Simon

Rule #1 of shell scripting: cat is NEVER necessary unless it’s actually used for concatenating. If you’re doing cat xxxxx | zzzz, you’re doint it wrong.

#37: Don’t pipe grep into awk. Awk can do regular expressions.

Try this instead:

i=/proc/interrupts;s=’/l timer/{print $2}’;echo $((-`awk “$s”<$i;sleep 1`+`awk "$s"<$i`))

18 09 2012
How to check HZ in the terminal? - feed99

[…] have seen this https://kaasxxx.wordpress.com/2008/01/22/linux-hz-checker/ But the script seems not to work. Does anyway know an easy way to chech “HZ” in the […]

3 01 2019
linux - Comment vérifier HZ dans le terminal?

[…] vu cette https://kaasxxx.wordpress.com/2008/01/22/linux-hz-checker/ Mais le script ne semble pas fonctionner. Fait quand même connaître un moyen facile de vérifier […]

31 03 2022
How to check HZ in the terminal? - ErrorsFixing

[…] have seen this https://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 […]

Leave a comment