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

From: Vincent Guittot

Date: Tue Nov 17 2026 - 11:09:25 EST


On Tue, 17 Nov 2026 at 17:05, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> 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.

Yeah it seems that arm64 has optimized div with an early exit when the
dividend is null so it would be better to always do the div

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