Team LiB
Previous Section Next Section

Time

Never assume the frequency of the timer interrupt or the number of jiffies per second. Instead, always use HZ to scale your units of time correctly. This is very important because not only can the timer frequency differ among the various architectures, but it can also change on a given architecture from one kernel release to the next.

For example, HZ is 1000 on the x86 platforms. That is, the timer interrupt occurs 1000 times per second, or every millisecond. Before 2.6, however, HZ was 100 on x86. On other architectures, the value differs: Alpha has HZ equal to 1024 and ARM has it equal to 100.

Never simply compare jiffies to a number such as 1000 and assume that always means the same thing. To scale time appropriately, multiply or divide by HZ. For example:

HZ            /* one second */
(2*HZ)        /* two seconds */
(HZ/2)        /* half a second */
(HZ/100)      /* 10 ms */
(2*HZ/100)    /* 20 ms */

HZ is defined in <asm/param.h>. The subject is discussed further in Chapter 10, "Timers and Time Management."

    Team LiB
    Previous Section Next Section