Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
How does the linux Kernel know when to increment jiffies? Is it based on the processor or the RTC or something else I may not know? I was wondering so I would know where to look when determining the accuracy of jiffies. I see Hz is defined as 250, which is common for all x86, but how does it exactly know when 4 ms have gone by?
Its based on the speed of your CPU. The kernel calculates jiffies, which are used to calculate BogoMIPS, which in turn are used to guess your CPU speed.
The kernel calculates jiffies, uses them to calculate bogomips, and uses that to guess the CPU speed. How does it calculate jiffies if it uses jiffies to guess the CPU speed?
When you boot the computer, you'll probably notice one of the lines reads
"Calibrating Delay Loop.... 3192.52 BogoMips"
The number isn't important and vary based upon the speed of processor. There is something called an internal delay loop. The goal is to see how many times this loop goes through between to timer ticks. I can't really explain it much better than this because I don't know much more than this myself. But the basic idea is a jiffy is used by the kernel to guess the CPU speed.
1.6G Pentium M = 3192.52 BogoMIPS = 6385059 Loop per jiffy
A jiffy is basicly just a unit of time. The more loops the kernel can complete in a "jiffY" the faster your processor is. But since humans work in terms of mhz and ghz, it goes through a series of calculations to convert that number to something more usuable.
Its called a BogoMIP because its a bogus calculation of how many millions of calculations you can do a second. Hence Bogo (bogus) MIPS(million instructions per second).
The 250 Hz is arch dependent. The x86 family processors send an interrupt every 4ms (I think this is where I was lost). Linux sees this interrupt and tries to see how many loops it can execute before the next interrupt, allowing us to calculate BogoMIPS per jiffy and then CPU speed. So at boot time, Linux has no clue of actual CPU speed, just the fact that it knows it's an x86 and will receive that interrupt every 250 Hz. So then, the 250 Hz (and consequently the jiffies value) accuracy is dependent on the CPU crystal?
Update: Now that I look through the kernel compile, I see there is an option in the config file for that value, 100, 250, or 1000 HZ. Now I am confused again, because obviously the processor is not sending a signal every 250 Hz if this is a custom value. Maybe it sends it at 1 kHz and the kernel steps down?
Update: Think I've figured it out (finally). The 8254 PIT (used by x86) is a set 1.193181818181.... MHz. A register in the PIT is programed with a value determined by the HZ variable and it is used to determine when to signal IRQ 0, which in turn updates jiffies! I beleive I read somewhere that the 8254 PIT has an accuracy of +/- 100 ppm.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.