STRUCT CYCLECOUNTER(9)
π struct cyclecounter(9) π
okay so this is from the Kernel API Manual (yes the actual kernel, bestie, we're in the big leagues now) and it's lowkey one of those pages that makes you feel smarter just reading it. let's get into it β¨
πΈ NAME πΈ
struct cyclecounter β hardware abstraction for a free running counter π
so basically it gives you completely state-free accessors to the underlying hardware. like, no state, none, she's just vibing and reading the raw thing for you π
but real talk β depending on which hardware it reads, the cycle counter may wrap around quickly. yes, that fast. so don't get comfy π«Ά
and the locking rules (if necessary, key phrase if necessary) have to be defined by the implementor and the user of specific instances of this API. not us, not the kernel, you. no cap. π₯
β¨ SYNOPSIS β¨
struct cyclecounter {
u64 (*read)(struct cyclecounter *cc);
u64 mask;
u32 mult;
u32 shift;
};
look at her. four little members. iconic. π
π¦ Members π¦
readβ returns the current cycle value. she reads. that's the whole job. main character energy honestly πmaskβ bitmask for two's complement subtraction of non-64-bit counters, see theCYCLECOUNTER_MASKhelper macro. so if your counter isn't a full 64 bits, this is how the subtraction math stays correct πmultβ cycle to nanosecond multiplier. multiplying, slay πshiftβ cycle to nanosecond divisor (power of two, don't forget that part, it matters π)
π SEE ALSO π
Kernel file ./include/linux/timecounter.h β plus her whole friend group:
struct timecounter(9)cyclecounter_cyc2ns(9)timecounter_adjtime(9)timecounter_init(9)timecounter_read(9)timecounter_cyc2time(9)
go read them, iykyk π§
heads up bestie: that wrap-around warning up in NAME is fr fr β this thing can flip over fast depending on the hardware, and the locking is your problem to define. not me, not the kernel. you. π
and that's the page!! sourced straight from ./include/linux, dated October 2026, filed under struct cyclecounter(9) π π¦ β
muah, go read your cycle counters responsibly π β¨π
π¦ 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