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/ ) .
=)
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.
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.
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) .
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With