Tuesday, May 4, 2021

Linux: Difference between low resolution and high resolution kernel timers

 Low resolution timers

Low resolution timers in the kernel are implemented through the standard API:
* init_timer()
* add_timer()
* mod_timer()

These timers are called low resolution because they measure their time units in kernel jiffies.
All the logic for the low resolution timers is supported by <linux/timer.h>

Structure used to support the timers is struct timer_list { }.

High resolution timers
The new high resolution timers approach to kernel timers uses time units in nano-seconds. This consists of a very small list of timers maintained on a CPU which is sorted as a red-black tree. Though the insertion and deletion to this list is not as fast as that of the low res timers (as per the intended purpose), the list itself is small.  All the code needed for the high resolution timers is supported by <linux/ktime.h>

Time measured in nanoseconds is held by ktime_t. The structure used for hrtimers, is struct hrtimer {}.