STRUCT TIMECOUNTER(9)
π¦ struct timecounter(9) π¦
okay bestie, welcome to the Kernel API Manual β¨ β yes this is that kernel, and yes this page is literally about the little struct that keeps your nanoseconds from going full chaos mode π
π« NAME π«
struct timecounter β it's the layer that sits right above a &struct cyclecounter and counts nanoseconds, periodt π
It holds all the state that timecounter_read() needs so it can detect cycle counter wrap around. You set it up with timecounter_init(). It's also the thing that converts cycle counts into the matching nanosecond counts via timecounter_cyc2time() π₯
And ngl, the fine print matters here:
- you (the user of this code, bestie, not us π) are responsible for initializing the underlying cycle counter hardware
- you are responsible for the locking issues
- you are responsible for reading the time more often than the cycle counter wraps around π
The good news? The nanosecond counter will only wrap around after ~585 years β so like, not your problem, not your era ππ
πΈ SYNOPSIS πΈ
struct timecounter {
struct cyclecounter *cc;
u64 cycle_last;
u64 nsec;
u64 mask;
u64 frac;
};
π«Ά Members π«Ά
ccβ the cycle counter this instance is using, its ride-or-die πcycle_lastβ the most recent cycle counter value thattimecounter_readhas seen πnsecβ a continuously increasing count, just going up and up, main character energy βmaskβ the bit mask used for maintaining thefracfield πfracβ the accumulated fractional nanoseconds, the little leftovers we refuse to throw away π
π§ SEE ALSO π§
Kernel file ./include/linux/timecounter.h, plus the whole squad:
struct cyclecounter(9)cyclecounter_cyc2ns(9)timecounter_adjtime(9)timecounter_init(9)timecounter_read(9)timecounter_cyc2time(9)
and that's the whole vibe check, bestie π this page came out of ./include/linux and it's dated October 2026 β screenshot it, frame it, it's iconic β¨π
π¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms