Course contentsShow
← Linux
Lesson 1813 of 1,81915. Kernel Concepts for Systems AdministratorsFree lesson

Timer interrupts and Jiffies

You will measure time precision within the kernel and understand system clock drift.

In this lesson, you will learn how the Linux kernel tracks the passage of time using the heartbeat of the CPU known as the "jiffy" and the inherent limitations of measuring sub-millisecond events.

The Heartbeat of the Kernel: Jiffies

At the core of Linux timekeeping is a global variable called jiffies. Every time the system timer interrupt fires, the kernel increments this counter. If your kernel is configured with a HZ value of 1000, the timer interrupt fires 1000 times per second, meaning one jiffy is exactly 1 millisecond.

Because this relies on hardware timer interrupts, the resolution is tied directly to the frequency of that interrupt. If you need to measure an event that happens faster than the interval between two jiffies, you cannot use them; the counter will simply not have changed between the start and end of your event.

Measuring Precision and Drift

While jiffies are excellent for long-term scheduling (e.g., "do this task every 5 seconds"), they are susceptible to two main issues:

  1. Resolution Limits: Because jiffies only increment on timer interrupts, your measurement resolution is fixed at 1/HZ. Any event duration occurring between interrupts is effectively "lost" or rounded.
  2. Clock Drift: System clocks are not perfect. The local hardware oscillator may run slightly faster or slower than "true" time. While the kernel uses NTP (Network Time Protocol) to adjust the rate at which it increments time to sync with external references, the jiffies counter remains a coarse software approximation of time.

To inspect your system's current frequency, check the kernel configuration:

grep CONFIG_HZ /boot/config-$(uname -r)

If you are performing high-precision measurements, you must move beyond the standard jiffies and utilize high-resolution timers (hrtimers) or CPU-specific hardware counters (like rdtsc), as jiffies is designed for task scheduling and system uptime, not microsecond-accurate benchmarking.

Key Takeaway: Jiffies provide a reliable, low-overhead heartbeat for kernel tasks, but their precision is strictly capped by the HZ frequency and they are fundamentally unsuitable for sub-millisecond performance profiling.