Re: [PATCH v2] sched/pelt: Skip redundant decay and divisions when sched_avg is zero

From: Peter Zijlstra

Date: Tue Nov 17 2026 - 11:05:37 EST


On Tue, Nov 17, 2026 at 04:46:56PM +0100, Peter Zijlstra wrote:
> On Tue, Nov 17, 2026 at 12:50:01PM +0000, Chris Wiseman wrote:
>
> > + sa->load_avg = sa->load_sum ? div_u64(load * sa->load_sum, divider) : 0;
> > + sa->runnable_avg = sa->runnable_sum ?
> > + div_u64(sa->runnable_sum, divider) : 0;
> > + WRITE_ONCE(sa->util_avg,
> > + sa->util_sum ? sa->util_sum / divider : 0);
>
> This is micro-architectural.
>
> Gemini is trying to sell me:
>
> IDIV latency (32/64) Branch mispredict
>
> Apple P-core (M4 tested): 7 13-15
> AMD Zen[45]: 10-13 / 15-20 15-20
> Intel Golven Cove+: 12-16 17-22
>
> So on these architectures it is more expensive to mispredict than to
> just do the division.

That same Gemini thing is also telling me most modern uarch should have
an early out when dividing 0 (making it cheaper still). OTOH it also
noted that if the prediction rate is near 100% the conditional might
win out because of reduced port contention.

As per obvious, if your uarch sucks at divisions its most always going
to be a win.