Skip to content

Enable/Disable high resolution timers in Linux

homepage-banner

Background knowledge

The objective of the high resolution timers project is to implement the POSIX 1003.1b Section 14 (Clocks and Timers) API in Linux. This includes support for high resolution timers - that is, timers with accuracy better than 1 jiffy.

Currently, timers in a few Linux distribution are only supported at a resolution of 1 jiffy. The length of a jiffy is dependent on the value of HZ in the Linux kernel.

# grep CONFIG_HZ /boot/config-$(uname -r)
# CONFIG_HZ_PERIODIC is not set
CONFIG_HZ_250=y
CONFIG_HZ=250

Higher resolution timers are needed to config and allow the system to wake up and process data at more accurate intervals.

Check timer and highres config

if highres is enabled, the following output should be seen, and the minimal time resolution is around 1 nano second.

cat /proc/cmdline |grep highres

# cat /proc/timer_list |grep handler
 event_handler:  tick_handle_oneshot_broadcast
 event_handler:  hrtimer_interrupt

# cat /proc/timer_list |grep resolution |uniq
  .resolution: 1 nsecs

if highres is forbidden, might get the following, and the minimal time resolution is around milliseconds.

# cat /proc/cmdline |grep highres
  highres=off

# cat /proc/timer_list |grep handler
 event_handler:  tick_handle_oneshot_broadcast
 event_handler:  tick_nohz_handler

# cat /proc/timer_list |grep resolution |uniq 
  .resolution: 4000000 nsecs

Enable highres on kernel config

add the following line into grub config, /etc/default/grub or /etc/default/grub.d/0x-yy.cfg

GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT highres=off"

and update grub, then reboot

update-grub
reboot

Reference

  • https://docs.kernel.org/timers/hrtimers.html
  • https://www.kernel.org/doc/html/latest/timers/highres.html
  • https://elinux.org/High_Resolution_Timers
  • https://elinux.org/Kernel_Timer_Systems
Leave a message