TIMECOUNTERS(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

🌸 TIMECOUNTERS(4) β€” timecounters 🌸

okay so this is the TIMECOUNTERS(4) page from the Kernel Interfaces Manual, and it's all about the kernel time counters subsystem β€” literally the backbone of keeping time while your system is up. periodt. πŸ’–

πŸ’– NAME πŸ’–

timecounters β€” kernel time counters subsystem

✨ SYNOPSIS ✨

The kernel uses several types of time-related devices, such as: real time clocks, time counters and event timers. Real time clocks are responsible for tracking real world time, mostly when the system is down. Time counters are responsible for tracking purposes, when the system is running. Event timers are responsible for generating interrupts at a specified time or periodically, to run different time-based events. This page is about the second. πŸ•°οΈ

πŸ¦‹ DESCRIPTION πŸ¦‹

Time counters are the lowest level of time tracking in the kernel. They hand you monotonically increasing timestamps with a known width and update frequency. They can overflow, drift, etc., so in raw form they're only usable in very limited performance-critical spots, like the process scheduler. 😭

The more usable time you actually see gets made by scaling the values read from the selected time counter and combining that with some offset, which is regularly updated by tc_windup() when hardclock() is invoked. ✨

Different platforms bring different kinds of timer hardware to the table, and the whole goal of the time counters subsystem is to give you one unified way to access all of it. πŸ’…

Every driver that implements time counters registers them with the subsystem. You can peep the list of present time counters through the kern.timecounter sysctl(8) variable:

kern.timecounter.choice: TSC-low(-100) HPET(950) i8254(0) ACPI-fast(900) dummy(-1000000)
kern.timecounter.tc.ACPI-fast.mask: 16777215
kern.timecounter.tc.ACPI-fast.counter: 13467909
kern.timecounter.tc.ACPI-fast.frequency: 3579545
kern.timecounter.tc.ACPI-fast.quality: 900
kern.timecounter.tc.i8254.mask: 65535
kern.timecounter.tc.i8254.counter: 62692
kern.timecounter.tc.i8254.frequency: 1193182
kern.timecounter.tc.i8254.quality: 0
kern.timecounter.tc.HPET.mask: 4294967295
kern.timecounter.tc.HPET.counter: 3013495652
kern.timecounter.tc.HPET.frequency: 14318180
kern.timecounter.tc.HPET.quality: 950
kern.timecounter.tc.TSC-low.mask: 4294967295
kern.timecounter.tc.TSC-low.counter: 4067509463
kern.timecounter.tc.TSC-low.frequency: 11458556
kern.timecounter.tc.TSC-low.quality: -100

The output nodes are defined as follows:

  • kern.timecounter.tc.X.mask is a bitmask, defining valid counter bits,
  • kern.timecounter.tc.X.counter is a present counter value,
  • kern.timecounter.tc.X.frequency is a counter update frequency,
  • kern.timecounter.tc.X.quality is an integral value, defining the quality of this time counter compared to others. A negative value means this time counter is broken and should not be used. πŸ’€

The kernel's time management code automatically switches to a higher-quality time counter when one registers, unless you've used the kern.timecounter.hardware sysctl to pick a specific device. πŸ‘‘

⚠️ okay bestie, important warning: there is no way to unregister a time counter once it has registered with the kernel. If a dynamically loaded module contains a time counter, you will not be able to unload that module β€” even if the time counter it contains is not the one currently in use. 😭

πŸ¦‹ SEE ALSO πŸ¦‹


πŸ’– cute sign-off: this page is from Debian, dated August 12, 2015, and it's TIMECOUNTERS(4). bye bestie! πŸ’…βœ¨

πŸ“¦ where this page comes from