clocks_calc_mult_shift(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… clocks_calc_mult_shift(9) β€” a kernel API manual moment

Ok so bestie, buckle up, because this one lives in the Kernel API Manual and it's lowkey the math behind every clock in your kernel πŸ•°οΈβœ¨


✨ NAME ✨

clocks_calc_mult_shift β€” literally the function that calculates mult/shift factors for scaled math of clocks πŸŽ€


🌸 SYNOPSIS 🌸

void clocks_calc_mult_shift (u32 *mult , u32 *shift , u32 from , u32 to
, u32 maxsec );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • mult β€” a pointer to the mult variable 🫢
  • shift β€” a pointer to the shift variable ✨
  • from β€” the frequency you're converting from
  • to β€” the frequency you're converting to
  • maxsec β€” the guaranteed runtime conversion range, in seconds ⏳

πŸ’– DESCRIPTION πŸ’–

So what this function actually does: it evaluates the shift/mult pair for the scaled math operations of clocksources and clockevents. Iconic. No cap. πŸ‘‘

to and from are frequency values in HZ, bestie. For clock sources, to is NSEC_PER_SEC == 1GHz and from is the counter frequency. For clock events it's the other way around β€” to is the counter frequency and from is NSEC_PER_SEC. Swap queen πŸ”„πŸ’…

The maxsec conversion range argument controls the time frame in seconds which must be covered by the runtime conversion with the calculated mult and shift factors. This guarantees that no 64bit overflow happens when the input value of the conversion is multiplied with the calculated mult factor. So like, it's your safety net, fr fr πŸ›Ÿ

Heads up though: larger ranges may reduce the conversion accuracy by choosing smaller mult and shift factors. Not me trading precision for range 😭 it's giving tradeoff.

πŸ”₯ SEE ALSO πŸ”₯

Kernel file ./kernel/time/clocksource.c:


Ok that's the whole page, bestie, you ate that πŸ’œβœ¨ This one's from ./kernel/time, dated October 2026, and it's the clocks_calc_mult_shift(9) page β€” go forth and scale your math responsibly πŸ§šβ€β™€οΈπŸŽ€

πŸ“¦ where this page comes from