psched_ratecfg_precompute__(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ psched_ratecfg_precompute__(9) πŸ’–

okay so welcome to the Kernel API Manual, bestie β€” this one is all about pre-computing reciprocal division values, and it’s lowkey iconic ✨


πŸ’… NAME πŸ’…

psched_ratecfg_precompute__ β€” Pre-compute values for reciprocal division


✨ SYNOPSIS ✨

void psched_ratecfg_precompute__ (u64 rate , u32 *mult , u8 *shift );

πŸŽ€ ARGUMENTS πŸŽ€

  • rate β€” Rate to compute reciprocal division values of
  • mult β€” Multiplier for reciprocal division
  • shift β€” Shift for reciprocal division

🌸 DESCRIPTION 🌸

The multiplier and shift for reciprocal division by rate are stored in mult and shift. That’s the whole vibe πŸ’«

The deal here is to replace a divide by a reciprocal one in the fast path β€” and a reciprocal divide is literally a multiply and a shift. Slay.

The normal formula would be:

time_in_ns = (NSEC_PER_SEC * len) / rate_bps

So we compute mult/shift to use instead:

time_in_ns = (len * mult) >> shift;

We try to get the highest possible mult value for accuracy, but we have to make sure no overflows will ever happen. No cap, overflow is not cute 😭πŸ”₯

Also: reciprocal_value is not used here β€” it doesn’t handle 64-bit values. Periodt.


πŸ‘‘ SEE ALSO πŸ‘‘


okay bye bestie 🫢 β€” source/version: ./net/sched, dated October 2026, and this whole page is psched_ratecfg_precompute__(9) πŸ’–βœ¨

πŸ“¦ where this page comes from