Re: [PATCH 0/4] sched: Various reweight_entity() fixes
From: Peter Zijlstra
Date: Tue Feb 10 2026 - 05:29:58 EST
On Tue, Feb 10, 2026 at 10:46:28AM +0530, K Prateek Nayak wrote:
> Hello Peter,
>
> On 2/9/2026 9:17 PM, Peter Zijlstra wrote:
> > I ended up with the below; and I've already pushed out a fresh
> > queue/sched/core. Could you please test again?
>
> I haven't seen any "sum_shifts" turning non-zero on the overnight runs,
> even with the larger workloads, so feel free to include:
>
> Tested-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Awesome, thanks!
>
> The overall patch looks good. I only have couple of cosmetic nits
> inlined below:
>
> [..snip..]
>
> > u64 avg_vruntime(struct cfs_rq *cfs_rq)
> > {
> > struct sched_entity *curr = cfs_rq->curr;
> > - s64 avg = cfs_rq->sum_w_vruntime;
> > - long load = cfs_rq->sum_weight;
> > + s64 delta = 0, runtime = cfs_rq->sum_w_vruntime;
>
> nit.
>
> "runtime" is only ever used in "weight" != 0 case so perhaps it can be
> moved there to preserve the reverse x-mas (or this whole line can be
> moved up top).
Indeed!
> > + long weight = cfs_rq->sum_weight;
> >
> > - if (curr && curr->on_rq) {
> > - unsigned long weight = scale_load_down(curr->load.weight);
> > + if (curr && !curr->on_rq)
> > + curr = NULL;
> >
> > - avg += entity_key(cfs_rq, curr) * weight;
> > - load += weight;
> > - }
> > + if (weight) {
> > + if (curr) {
> > + unsigned long w = scale_load_down(curr->load.weight);
> > +
> > + runtime += entity_key(cfs_rq, curr) * w;
> > + weight += w;
> > + }
> >
> > - if (load) {
> > /* sign flips effective floor / ceiling */
> > - if (avg < 0)
> > - avg -= (load - 1);
> > - avg = div_s64(avg, load);
> > + if (runtime < 0)
> > + runtime -= (weight - 1);
> > +
> > + delta = div_s64(runtime, weight);
> > +
>
> nit. Is this empty line necessary?
Not really, but somehow I always find myself ending a block with an
empty line when there's an else statement following.
I'll get rid of it :-)