mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kayra Cizmeci <kayracizmeci@gmail.com>
To: Tim Douglas <me@timdoug.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Vincent Guittot <vincent.guittot@linaro.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	 Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	 linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] sched/fair: Fix removal of load and runnable sums on 32-bit
Date: Tue, 1 Dec 2026 22:16:42 +0300	[thread overview]
Message-ID: <aw8LmNqVCR5tb0aG@scheduler.schedules> (raw)
In-Reply-To: <20261201164320.96708-1-me@timdoug.com>

On Tue, Dec 01, 2026 at 11:43:20AM -0500, Tim Douglas wrote:
> Since commit 089d84203ad4 ("sched/fair: Fold the sched_avg update"),
> update_cfs_rq_load_avg() drains cfs_rq->removed with -r*divider as the
> sum delta, where r is an unsigned long. On 32-bit, the product is a
> 32-bit unsigned value, which add_positive() zero-extends to the s64
> delta for load_sum and runnable_sum. For 0 < r*divider < 2^32, the
> resulting delta is 2^32 too large. (The u32 util_sum update is
> unaffected.)

Ah. I hate this stuff :/. It requires a lot of blank staring to the
screen...

> 
> For runnable_sum, that excess corresponds to about 90000 units of
> runnable_avg before decay, which saturates cpu_util_cfs_boost() and
> causes schedutil to select the highest CPU frequency on a mostly idle
> system. Seen on an Allwinner R16 (Cortex-A7) with runnable_avg up to
> 342000 and at most three runnable tasks. With the fix, the highest
> runnable_avg in 73000 samples under the same workload was 1828, and
> schedutil scaled with load as expected.
> 
> Make r an s64 so that the delta is computed in 64 bits.
> 
> Fixes: 089d84203ad4 ("sched/fair: Fold the sched_avg update")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tim Douglas <me@timdoug.com>
> ---
>  kernel/sched/fair.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 8a55571b9..74d4f9ced 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5814,7 +5814,7 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
>  	int decayed = 0;
>  
>  	if (cfs_rq->removed.nr) {
> -		unsigned long r;
> +		s64 r;
>  		u32 divider = get_pelt_divider(&cfs_rq->avg);
>  
>  		raw_spin_lock(&cfs_rq->removed.lock);
> -- 
> 2.56.1
> 

Sweet.

So the problem is that r is a unsigned long (u32) number that we try to
do: x + (-r). But x is 64 bits, so normally if r was 64 bits too, (-r)
would be just correct. But if r is bigger than 0 and we are on 32 bits,
things go like wrong-wrong-bam-boom-quiet.

Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>

(I'm holding myself from making more jokes, I think drinking 3 shots of
espresso in a span of 1 hour makes me want to make more jokes.)


Cheers!


Kayra

      reply	other threads:[~2026-12-01 19:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:43 Tim Douglas
2026-12-01 19:16 ` Kayra Cizmeci [this message]

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=aw8LmNqVCR5tb0aG@scheduler.schedules \
    --to=kayracizmeci@gmail.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@timdoug.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.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®