Linux – the hardware which the linux kernel uses for timer interrupt

interruptlinuxlinux-kernelprocessscheduling

I am reading about jiffies which will be updated for every timer interrupt. The frequency of the timer interrupt is determined by compile time constant HZ.

We have lot of hardware devices present on X86.
1. RTC
2. Programmable interrupt timer
3. Local APIC
4. Time Stamp Counter
5. HPET

Which is the device used by the Linux Kernel for incrementing the jiffie value.

Robert Love book says 'Programmable Interrupt Timer'. Is it still valid.

 cat /sys/devices/system/clocksource/clocksource0/available_clocksource 
tsc hpet acpi_pm 

# cat /sys/devices/system/clocksource/clocksource0/current_clocksource 
tsc

Is the above sys file giving that information?

Best Answer

I suspect you were reading this or something very similar (https://elinux.org/Kernel_Timer_Systems):

Timer Wheel, Jiffies and HZ (or, the way it was)

The original kernel timer system (called the "timer wheel) was based on incrementing a kernel-internal value (jiffies) every timer interrupt. The timer interrupt becomes the default scheduling quantum, and all other timers are based on jiffies. The timer interrupt rate (and jiffy increment rate) is defined by a compile-time constant called HZ. Different platforms use different values for HZ. Historically, the kernel used 100 as the value for HZ, yielding a jiffy interval of 10 ms. With 2.4, the HZ value for i386 was changed to 1000, yeilding a jiffy interval of 1 ms. Recently (2.6.13) the kernel changed HZ for i386 to 250. (1000 was deemed too high).

So it seems you are asking "what timer times a jiffy?"

By process of elimination: RTC, newer Local APIC, and TSC don't support fixed frequency interrupts. As quoted below HPET seems to superseed PIT.

So the most likely answer is the HPET. These are based on a counter triggered by a quartz crystal, usually on the south bridge. In this case jiffys are timed by a single HPET comparator in periodic mode that generates interrupt.

However it is possible for linux to still use a PIT or other timer (see https://en.wikipedia.org/wiki/High_Precision_Event_Timer) :

Use and compatibility

Operating systems designed before HPET existed cannot use HPET, so they use other timer facilities. Newer operating systems tend to be able to use either. Some hardware has both. Indeed, most current southbridge chips have legacy-supporting instances of PIT, PIC, Advanced Programmable Interrupt Controller (APIC) and RTC devices incorporated into their silicon whether or not they are used by the operating system, which helps very modern PCs run older operating systems.

Connection between PIT and PET

The Programmable Interrupt Timer is an active timer that interrupts the normal execution of code. It seems to have been superseded by the HPET:

The Programmable Interval Timer (PIT) is an essential component of modern computers, especially in a multi-tasking environment. The PIT chip can be made β€’ by setting various register values β€’ to count up or down, at certain rates, and to trigger interrupts at certain times. The timer can be set into a cyclic mode, so that when it triggers it automatically starts counting again, or it can be set into a one-time-only countdown mode.

On newer hardware, a HPET (High Precision Event Timer), which is an evolution of the PIT concept, is likely to be available.

Related Question