mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Juri Lelli <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Valentin Schneider <vschneid@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Mel Gorman <mgorman@suse.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 5/6] sched/fair: Rename cfs_rq::avg_load to cfs_rq::sum_weight
Date: Tue, 2 Dec 2025 11:27:17 +0100	[thread overview]
Message-ID: <20251202102717.GB2556898@noisy.programming.kicks-ass.net> (raw)
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 <mingo@kernel.org>

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
> 

  reply	other threads:[~2025-12-02 10:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-01  6:46 [PATCH 0/6] sched: Misc cleanups Ingo Molnar
2025-12-01  6:46 ` [PATCH 1/6] sched/fair: Join two #ifdef CONFIG_CFS_BANDWIDTH blocks Ingo Molnar
2025-12-04  5:53   ` Shrikanth Hegde
2025-12-06 10:48     ` Ingo Molnar
2025-12-14  7:46   ` [tip: sched/core] sched/fair: Join two #ifdef CONFIG_FAIR_GROUP_SCHED blocks tip-bot2 for Ingo Molnar
2025-12-15  7:59   ` tip-bot2 for Ingo Molnar
2025-12-01  6:46 ` [PATCH 2/6] sched/fair: Clean up comments in 'struct cfs_rq' Ingo Molnar
2025-12-14  7:46   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-12-15  7:59   ` tip-bot2 for Ingo Molnar
2025-12-01  6:46 ` [PATCH 3/6] sched/fair: Separate se->vlag from se->vprot Ingo Molnar
2025-12-01  8:06   ` [PATCH 3/6 v2] " Ingo Molnar
2025-12-14  7:46   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-12-15  7:59   ` tip-bot2 for Ingo Molnar
2025-12-01  6:46 ` [PATCH 4/6] sched/fair: Rename avg_vruntime() to cfs_avg_vruntime() Ingo Molnar
2025-12-02 10:24   ` Peter Zijlstra
2025-12-02 15:15     ` Ingo Molnar
2025-12-01  6:46 ` [PATCH 5/6] sched/fair: Rename cfs_rq::avg_load to cfs_rq::sum_weight Ingo Molnar
2025-12-02 10:27   ` Peter Zijlstra [this message]
2025-12-02 15:57     ` Ingo Molnar
2025-12-14  7:46   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-12-15  7:59   ` tip-bot2 for Ingo Molnar
2025-12-01  6:46 ` [PATCH 6/6] sched/fair: Rename cfs_rq::avg_vruntime to ::sum_w_vruntime, and helper functions Ingo Molnar
2025-12-02 10:35   ` Peter Zijlstra
2025-12-02 15:19     ` Ingo Molnar
2025-12-14  7:46   ` [tip: sched/core] " tip-bot2 for Ingo Molnar
2025-12-15  7:59   ` tip-bot2 for Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251202102717.GB2556898@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sshegde@linux.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®