STRUCT TIMECOUNTER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ 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 that timecounter_read has seen πŸ‘€
  • nsec β€” a continuously increasing count, just going up and up, main character energy ⭐
  • mask β€” the bit mask used for maintaining the frac field πŸŽ€
  • 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:


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