The Passage of Time
The kernel keeps track of the flow of time. It provides services to sleep wait for long periods and busy wait for short periods, can schedule events to run at a future time, and can do periodic work with microsecond precision. Here’s a look at kernel time.
Saturday, October 15th, 2005
Many features of the Linux kernel are critically dependent on the passage of time. The Linux kernel makes use of different timers provided by hardware to provide time-dependent services such as busy wait and sleep wait. The kernel also facilitates scheduling for functions that desire to run after some specified time has elapsed.
In this month’s “Gearheads” column, let’s explore the the semantics of kernel variables like jiffies, HZ, loops_per_jiffy, and xtime, learn how to measure execution times using the Pentium Time Stamp Counter (TSC), and use the Real-Time Clock (RTC) to perform periodic work from an application with microsecond precision.
Of HZ and Jiffies
System timers interrupt the processor, or pop, at programmable frequencies. This frequency, or the number of timer ticks per second, is contained in the kernel variable HZ. Choosing a value for HZ is a trade-off: a large HZ value results in finer timer granularity and better resolution. However, high values of HZ also result in larger overhead, since more cycles are spent executing the timer interrupt handler.
The value of HZ is architecture-dependent. On x86 systems,the 2.4 kernels set HZ to 100, but with 2.6, this value was changed to 1000. On ARM-based platforms, 2.6 kernels use a HZ value of 100.