Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine timer frequency in linux

I need to write a kernel module to calculate Linux Kernel Timer (Interrupt) Frequency .

somebody told me I need to use a timer in my module but I don't know how to do that clearly :(

My final goal is to write the result (the frequency) in some file ( for example in: /proc/osfreq/ ) .

=)

like image 684
Emadpres Avatar asked Nov 28 '12 08:11

Emadpres


People also ask

What is timer frequency Linux?

Linux timer interrupt frequency is an important parameter for near to real-time and multimedia applications running on Linux. The timer interrupt frequency directly impacts the capability of any near-to real time and multimedia application to process events at high frequencies.

What is kernel timer frequency?

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.

How do I know my kernel HZ?

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

What is HZ value Linux?

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


2 Answers

There are many ways to get the cpu's time frequency:

1. zcat /proc/config.gz |grep CONFIG_HZ

# CONFIG_HZ_100 is not set
CONFIG_HZ_250=y
# CONFIG_HZ_1000 is not set
CONFIG_HZ=250

means 250 Hz

2. cat /proc/interrupts |grep LOC; sleep 1;cat /proc/interrupts |grep LOC

LOC:   43986173   44089526   43986113   44089117
LOC:   43986424   44089777   43986364   44089368

means there are 4 logic CPUs, whose frequency is: 43986424 - 43986173 ~=250.

Also, you can get value of var cpu_khz in proc.c at kernel space.

like image 108
shiwenlu518 Avatar answered Nov 15 '22 08:11

shiwenlu518


You can just print the global variable HZ's value in the module using printk, and check the kernel log after loading the module using $dmesg, then you can find the value of HZ.

like image 43
harry Avatar answered Nov 15 '22 09:11

harry