Question

I wanted to know how much time "1ms sleep" takes.

Ran this quest in kernel module:

rdtscl(aj);
msleep(1);
rdtscl(b);
printk(KERN_INFO "Difference = %lu", (b-a));// Number of clock cycles consumed

Output i got:

Difference = 13479219

Output for cat /proc/cpuinfo

cpu MHz : 1197.000

With that, I calculated the delay, which i got 11.26 milli second.

Why am i not getting it around 1 ms ?

UPDATE:

The Processor frequency in cat /proc/cpuinfo sholud be got from the following line:

model name  : Intel(R) Core(TM) i3 CPU         540  @ 3.07GHz

=> the Processor frequency is 3.07 GHz. Dont know what is the meaning of this line "cpu MHz : 1197.000" though.

Thanks

Was it helpful?

Solution

The process resolution depends on the HZ value configured on the system that you had run the test code. The HZ value can be 100 or 1000, if its 100 then the scheduler will wake up only once in 10 ms. Mostly in desktop systems, in the recent distributions, it will be set to 1000. (You can check in the config file in /boot in Fedora). The scheduler will schedule only based on that, so if the scheduler wakes up once in every 10 ms, then there is no way of getting resolutions lesser than 10 ms. Or you need to use HR timers in the kernel.

kernel-3.4.5 (u3-1 *)$ cat /boot/config-3.6.10-4.fc18.x86_64 | grep HZ
CONFIG_NO_HZ=y
# CONFIG_RCU_FAST_NO_HZ is not set
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000

If you really want the delay but without sleeping, then you can use mdelay, which will just loop for the specified amount of time and return.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top