TIMECOUNTERS(4)
π TIMECOUNTERS π
ok so bestie, welcome to timecounters(4) β it's a page from the Kernel Interfaces Manual, section 4, and it's literally all about how your kernel keeps track of time. sit down, grab a boba, we're doing this π§β¨
β¨ SYNOPSIS β¨
so the kernel uses a bunch of different time-related devices, right? like:
- real time clocks β these track real world time, mostly when the system is down π
- time counters β these do the tracking when the system is running π
- event timers β these generate interrupts at a specified time or periodically, to run different time-based events β°
and this whole page? it's about the second one. time counters. the main character. periodt π
πΈ DESCRIPTION πΈ
Time counters are the lowest level of time tracking in the kernel. no cap. they give you monotonically increasing timestamps with known width and update frequency. that's the vibe.
but bestie, listen β they can overflow, they can drift, etc. so in raw form they can only be used in very limited performance-critical places, like the process scheduler. it's giving "don't touch this unless you know what you're doing" π
more usable time gets created by scaling the values read from the selected time counter and combining it with some offset, regularly updated by tc_windup() on hardclock() invocation. iconic behaviour honestly.
Different platforms provide different kinds of timer hardware. and the whole goal of the time counters subsystem is to provide a unified way to access that hardware. slay π¦
Each driver implementing time counters registers them with the subsystem. and you can literally see the list of present time counters via 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, explained π
The output nodes are defined as follows:
kern.timecounter.tc.X.maskβ it's a bitmask, defining valid counter bits πkern.timecounter.tc.X.counterβ it's a present counter value βkern.timecounter.tc.X.frequencyβ it's a counter update frequency π₯kern.timecounter.tc.X.qualityβ it's 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 time management code of the kernel automatically switches to a higher-quality time counter when it registers β unless the kern.timecounter.hardware sysctl has been used to choose a specific device. so like, it picks for you, but you can override it if you're feeling spicy π
β οΈ ok serious moment bestie: there is no way to unregister a time counter once it has registered with the kernel. none. zero. nope. 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. that's just how it is π
π SEE ALSO π
that's the whole page bestie, you ate it, go forth and understand your kernel's clock vibe β¨π«Ά
Debian β August 12, 2015 β TIMECOUNTERS(4) π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2011 Alexander Motin <mav@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms