From: Qais Yousef <qyousef@layalina.io>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Christian Loehle <christian.loehle@arm.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
John Stultz <jstultz@google.com>,
linux-kernel@vger.kernel.org, Wei Wang <wvw@google.com>
Subject: Re: [PATCH v2] sched/uclamp: Fix race condition leading to imbalanced uclamp_rq
Date: Wed, 28 Oct 2026 02:10:45 +0000 [thread overview]
Message-ID: <e4c97fa1-9d4e-4d1c-bcd2-af3d40dafa84@layalina.io> (raw)
In-Reply-To: <20261026115900.GG2668200@noisy.programming.kicks-ass.net>
On 10/26/26 11:59, Peter Zijlstra wrote:
> On Mon, Oct 26, 2026 at 11:24:31AM +0000, Qais Yousef wrote:
>> On 10/26/26 10:12, Peter Zijlstra wrote:
>>
>>>> +static inline bool __uclamp_is_imbalanced(struct rq *rq, enum uclamp_id clamp_id)
>>>> +{
>>>> + struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket;
>>>> + int bucket_id = UCLAMP_BUCKETS - 1;
>>>> +
>>>> + /*
>>>> + * On idle all bucket.tasks must be 0, or we have hit imbalance
>>>> + * problem.
>>>> + */
>>>> + for ( ; bucket_id >= 0; bucket_id--)
>>>> + if (bucket[bucket_id].tasks)
>>>> + return true;
>>>> +
>>>> + return false;
>>>> +}
>>>> +
>>>> +static inline bool uclamp_is_imbalanced(struct rq *rq)
>>>> +{
>>>> + enum uclamp_id clamp_id;
>>>> +
>>>> + for_each_clamp_id(clamp_id)
>>>> + if(__uclamp_is_imbalanced(rq, clamp_id))
>>>> + return true;
>>>> +
>>>> + return false;
>>>> +}
>>>
>>> Anyway; I was thinking, since we have a hole in struct uclamp_rq; and
>>> also uclamp_flags. Can we fold uclamp_flags into the hold, and also use
>>> UCLAMP_FLAG_IDLE to detect if we need this bucket scan at all?
>>
>> Actually maybe we can just check if the flag is not set then this means we
>> have a corruption without scanning the buckets. I didn't like the scan, but
>> seemed safer for a backport. Let me try that and update.
>>
>> I can fold the uclamp_flags into buckets, I don't think this will grow and I
>> do have a path to help us get rid off uclamp_rq (hopefully) in the future.
>>
>> Okay to do this as a separate follow up patch? Since this will go to LTS, I
>> think safer keep it minimalist and do the folding bit in a separate patch.
>
> Sure; I just noticed these separate things while trying to re acquaint
> myself with uclamp ;-)
I posted new version along with some clean up that makes this conversion
slightly easier, but didn't go all the way in as the flag being per
uclamp_id didn't make sense and if I moved it to uclamp_rq or
uclamp_bucket it meant we'll need to set and clear the two IDs which
didn't feel much better. We can discuss on the new series.
Turns out no need to scan too and can just check if the flag is not set
to detect the imbalance.
prev parent reply other threads:[~2026-10-28 2:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 16:26 Qais Yousef
2026-10-26 10:12 ` Peter Zijlstra
2026-10-26 11:24 ` Qais Yousef
2026-10-26 11:59 ` Peter Zijlstra
2026-10-28 2:10 ` Qais Yousef [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=e4c97fa1-9d4e-4d1c-bcd2-af3d40dafa84@layalina.io \
--to=qyousef@layalina.io \
--cc=christian.loehle@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=wvw@google.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®