psched_ratecfg_precompute__(9)
π¦ 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 ofmultβ Multiplier for reciprocal divisionshiftβ 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 π
- Kernel file
./net/sched/sch_generic.c netif_carrier_on(9)netif_carrier_off(9)netif_carrier_event(9)dev_deactivate_many(9)
okay bye bestie π«Ά β source/version: ./net/sched, dated October 2026, and this whole page is psched_ratecfg_precompute__(9) πβ¨
π¦ 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