clocks_calc_mult_shift(9)
π 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 themultvariable π«Άshiftβ a pointer to theshiftvariable β¨fromβ the frequency you're converting fromtoβ the frequency you're converting tomaxsecβ 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:
clocksource_mark_unstable(9)clocksource_suspend_select(9)clocksource_start_suspend_timing(9)clocksource_stop_suspend_timing(9)clocksource_suspend(9)clocksource_resume(9)clocksource_touch_watchdog(9)clocksource_max_adjustment(9)clocks_calc_max_nsecs(9)clocksource_update_max_deferment(9)clocksource_select(9)__clocksource_update_freq_scale(9)__clocksource_register_scale(9)clocksource_unregister(9)current_clocksource_show(9)current_clocksource_store(9)unbind_clocksource_store(9)available_clocksource_show(9)boot_override_clocksource(9)boot_override_clock(9)
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
- 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