From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FC9C30EF96 for ; Tue, 2 Dec 2025 10:27:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764671245; cv=none; b=HvXJp3leVyDHFvYHPFPjsORGN7Fn3sDSzNmNTqN4YxPcMXotm6061tVpsGRTT0XG5MXI65DSNYIMVd5JRBMEbpLxrsAG6c1ltc29inKkNE8ZAyhQiZ79x3HYI34jyj8D8TS5ct08SpjpPBE5VeQBL808oo+2yXZ0QwUE7A+vnCc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764671245; c=relaxed/simple; bh=qtoob+g7Qc2eVKzpLm/Vo9raIV7iU5Jk9bJvbJGUN74=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a3GO62pvGMqwA1bS+Jp037RU20l9Xr2tP/vYLLbOjwtic7Etig1cjru4X7yOVJ3jljoNqRHvzB+L6vQuNBXYAw9GPk7cIyKoUK80GFbRvaEGuIRgKok1SwYQP62FzSSuCE4kyBemq108ujAlVSAgju5/rxj72/xEYPiFgqcRjE8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=gkjg8vsL; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="gkjg8vsL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=scxKQ+BRqlhb9Ks1O9W6GttARhgPKjGJMDSdOa2ijDU=; b=gkjg8vsL/tO+PGpmYeYJS3eAP3 26vkq1eyln0l4BVj863bBmY0Lo9nGAIGDi/NXMV4ilM6/ozdYASaFbFfPz9Zy4tI6zms+pZO1yt8R r0JvRusZ9x6BMJbLGiQ2u1j/m42YQKgJSx3+f7BuSgaGSXG4N/OAj6W3/SHqU4E1luJRk9Pdp63p9 0uyrKxjHSfAArKyjmr8j1MlFBTtfHg8qGsvxzwzIT7pmDgNeNVwzZo/n6YdAS3Yr/STUpBcJ6Eb1N TwW7K0ouwZo/pa3AvlL0hX+ogpoTGZDyKUOI4ulIXPyfxuJb0bOKgjHG8R9zE6/TSLPTyyIjxnJWb 6IcJo+eA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vQMjm-000000007Wp-0ylW; Tue, 02 Dec 2025 09:31:58 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2B66C3005E0; Tue, 02 Dec 2025 11:27:18 +0100 (CET) Date: Tue, 2 Dec 2025 11:27:17 +0100 From: Peter Zijlstra To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Juri Lelli , Dietmar Eggemann , Valentin Schneider , Vincent Guittot , Shrikanth Hegde , Linus Torvalds , Mel Gorman , Steven Rostedt , Thomas Gleixner Subject: Re: [PATCH 5/6] sched/fair: Rename cfs_rq::avg_load to cfs_rq::sum_weight Message-ID: <20251202102717.GB2556898@noisy.programming.kicks-ass.net> References: <20251201064647.1851919-1-mingo@kernel.org> <20251201064647.1851919-6-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251201064647.1851919-6-mingo@kernel.org> On Mon, Dec 01, 2025 at 07:46:46AM +0100, Ingo Molnar wrote: > The ::avg_load field is a long-standing misnomer: it says it's an > 'average load', but in reality it's the momentary sum of the load > of all currently runnable tasks. We'd have to also perform a > division by nr_running (or use time-decay) to arrive at any sort > of average value. > > This is clear from comments about the math of fair scheduling: > > * \Sum w_i := cfs_rq->avg_load > > The sum of all weights is ... the sum of all weights, not > the average of all weights. > > To make it doubly confusing, there's also an ::avg_load > in the load-balancing struct sg_lb_stats, which *is* a > true average. > > The second part of the field's name is a minor misnomer > as well: it says 'load', and it is indeed a load_weight > structure as it shares code with the load-balancer - but > it's only in an SMP load-balancing context where > load = weight, in the fair scheduling context the primary > purpose is the weighting of different nice levels. > > So rename the field to ::sum_weight instead, which makes > the terminology of the EEVDF math match up with our > implementation of it: > > * \Sum w_i := cfs_rq->sum_weight > > Signed-off-by: Ingo Molnar Bah, this is going to be a pain rebasing for me, but yes, these variables are poorly named. 'sum_weight' is a better name. > --- > kernel/sched/fair.c | 16 ++++++++-------- > kernel/sched/sched.h | 2 +- > 2 files changed, 9 insertions(+), 9 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 3d6d551168aa..2ffd52a2e7a0 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -608,7 +608,7 @@ static inline s64 entity_key(struct cfs_rq *cfs_rq, struct sched_entity *se) > * > * v0 := cfs_rq->zero_vruntime > * \Sum (v_i - v0) * w_i := cfs_rq->avg_vruntime > - * \Sum w_i := cfs_rq->avg_load > + * \Sum w_i := cfs_rq->sum_weight > * > * Since zero_vruntime closely tracks the per-task service, these > * deltas: (v_i - v), will be in the order of the maximal (virtual) lag > @@ -625,7 +625,7 @@ avg_vruntime_add(struct cfs_rq *cfs_rq, struct sched_entity *se) > s64 key = entity_key(cfs_rq, se); > > cfs_rq->avg_vruntime += key * weight; > - cfs_rq->avg_load += weight; > + cfs_rq->sum_weight += weight; > } > > static void > @@ -635,16 +635,16 @@ avg_vruntime_sub(struct cfs_rq *cfs_rq, struct sched_entity *se) > s64 key = entity_key(cfs_rq, se); > > cfs_rq->avg_vruntime -= key * weight; > - cfs_rq->avg_load -= weight; > + cfs_rq->sum_weight -= weight; > } > > static inline > void avg_vruntime_update(struct cfs_rq *cfs_rq, s64 delta) > { > /* > - * v' = v + d ==> avg_vruntime' = avg_runtime - d*avg_load > + * v' = v + d ==> avg_vruntime' = avg_runtime - d*sum_weight > */ > - cfs_rq->avg_vruntime -= cfs_rq->avg_load * delta; > + cfs_rq->avg_vruntime -= cfs_rq->sum_weight * delta; > } > > /* > @@ -655,7 +655,7 @@ u64 cfs_avg_vruntime(struct cfs_rq *cfs_rq) > { > struct sched_entity *curr = cfs_rq->curr; > s64 avg = cfs_rq->avg_vruntime; > - long load = cfs_rq->avg_load; > + long load = cfs_rq->sum_weight; > > if (curr && curr->on_rq) { > unsigned long weight = scale_load_down(curr->load.weight); > @@ -723,7 +723,7 @@ static int vruntime_eligible(struct cfs_rq *cfs_rq, u64 vruntime) > { > struct sched_entity *curr = cfs_rq->curr; > s64 avg = cfs_rq->avg_vruntime; > - long load = cfs_rq->avg_load; > + long load = cfs_rq->sum_weight; > > if (curr && curr->on_rq) { > unsigned long weight = scale_load_down(curr->load.weight); > @@ -5172,7 +5172,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) > * > * vl_i = (W + w_i)*vl'_i / W > */ > - load = cfs_rq->avg_load; > + load = cfs_rq->sum_weight; > if (curr && curr->on_rq) > load += scale_load_down(curr->load.weight); > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 47f7b6df634c..54994d93958a 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -679,7 +679,7 @@ struct cfs_rq { > unsigned int h_nr_idle; /* SCHED_IDLE */ > > s64 avg_vruntime; > - u64 avg_load; > + u64 sum_weight; > > u64 zero_vruntime; > #ifdef CONFIG_SCHED_CORE > -- > 2.51.0 >