From: Christian Loehle <christian.loehle@arm.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Qais Yousef <qyousef@layalina.io>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
John Stultz <jstultz@google.com>,
linux-kernel@vger.kernel.org,
Kayra Cizmeci <kayracizmeci@gmail.com>, Wei Wang <wvw@google.com>
Subject: Re: [PATCH v6 1/3] sched/uclamp: Fix race condition leading to imbalanced uclamp_rq
Date: Wed, 25 Nov 2026 19:10:04 +0000 [thread overview]
Message-ID: <3be9a901-ee11-4aa5-b891-889d3bde2221@arm.com> (raw)
In-Reply-To: <CAKfTPtAxbSMg2NkNP4t5Edsb2DUkpEOKntno90rPvPwkphpETQ@mail.gmail.com>
On 11/25/26 17:15, Vincent Guittot wrote:
> On Wed, 25 Nov 2026 at 10:13, Christian Loehle <christian.loehle@arm.com> wrote:
>>
>> On 11/23/26 18:15, Christian Loehle wrote:
>>> On 11/23/26 17:23, Vincent Guittot wrote:
>>>> On Mon, 23 Nov 2026 at 15:38, Christian Loehle <christian.loehle@arm.com> wrote:
>>>>>
>>>>> On 11/21/26 04:15, Qais Yousef wrote:
>>>>>> Static keys are not guaranteed to be enabled atomically across CPUs. Or
>>>>>> across callsites on the same CPUs. Which means when sched_uclamp_used is
>>>>>> enabled, some CPUs/callsites will return true for uclamp_is_used() while
>>>>>> others won't, leading to asymmetric uclamp_rq_{inc, dec}_id. If we
>>>>>> decrement without increment this is safe as documented in the code. But
>>>>>> an increment without a decrement is a problem and will leave the
>>>>>> uclamp_rq in a corrupt state.
>>>>>
>>>>> So if we only need decrement to work then we can rely on
>>>>> p's uclamp_se.active and decrement regardless of uclamp_is_used() and call it
>>>>> a day?
>>>>
>>>> The static key prevents overhead for those who don't use uclamp. It's
>>>> a default rule for features like numa, cache aware, eas, uclamp etc to
>>>> not impact those who don't use it.
>>>> I'm afraid that the executing uclamp_rq_dec up to
>>>> p->uclamp[clamp_id].active will not be free of overhead
>>>
>>> I get why the static branch is there, but as long as p->uclamp[clamp_id].active
>>> never changes from 0, like when uclamp is never used, the check should be virtually
>>> free on any half-decent branch predictor.
>>> Also in any case the enqueue path ought to be the expensive part for uclamp.
>>>
>>> I can come back with some numbers though, including the original netperf that
>>> introduced the static key.
>>
>> So I compared mainline, my dequeue-only fix and a version where uclamp_is_used()
>> always returns true (i.e. no static branch optimisation at all).
>> A MeteorLake, Xeon and Orion, all compared to mainline as a base:
>
> I did a quick test on my favorite dragon rb5 with perf sched pipe -T ,
> perf cpufreq gov and only WFI:
> - on big, the diff is -0.7% (+/- 0.30%)
> - on medium it's -1.85% (+/- 0.20%)
> - and on little it's -6.53% (+/- 0.15%)
>
Looks in line with my results on Orion I'd say,
FWIW here's the diff I'm proposing on top, proper will follow once I've completed the
full results, but if you wanna have a go already and (hopefully) convince yourself:
----------->8------------
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3c141aaae6a7..850088eeda5f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1900,8 +1900,12 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
/*
* Static-key updates are not atomic across callsites. An enqueue may
* have accounted this task before this callsite observes the key enabled.
- * Let uclamp_rq_dec_id() use uc_se->active to match that accounting.
+ * Check the task's accounting state instead. Both clamps are updated
+ * under the rq lock, so either active flag is sufficient here.
*/
+ if (!p->uclamp[UCLAMP_MIN].active)
+ return;
+
if (unlikely(!p->sched_class->uclamp_enabled))
return;
(END)
next prev parent reply other threads:[~2026-11-25 19:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 4:15 [PATCH v6 0/3] Fix uclamp race against non atomic static key enable Qais Yousef
2026-11-21 4:15 ` [PATCH v6 1/3] sched/uclamp: Fix race condition leading to imbalanced uclamp_rq Qais Yousef
2026-11-23 14:38 ` Christian Loehle
2026-11-23 17:23 ` Vincent Guittot
2026-11-23 18:15 ` Christian Loehle
2026-11-24 9:25 ` Vincent Guittot
2026-11-25 9:13 ` Christian Loehle
2026-11-25 17:15 ` Vincent Guittot
2026-11-25 19:10 ` Christian Loehle [this message]
2026-11-24 7:40 ` Qais Yousef
2026-11-24 8:13 ` Qais Yousef
2026-11-24 9:36 ` Vincent Guittot
2026-11-21 4:15 ` [PATCH v6 2/3] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Qais Yousef
2026-11-21 4:15 ` [PATCH v6 3/3] sched/uclamp: Move uclamp_rq_{inc, dec}() from core.c Qais Yousef
2026-11-22 17:22 ` [PATCH v6 0/3] Fix uclamp race against non atomic static key enable Qais Yousef
2026-11-23 9:19 ` Christian Loehle
2026-11-24 7:21 ` Qais Yousef
2026-11-24 7:35 ` Christian Loehle
2026-11-24 7:54 ` Qais Yousef
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=3be9a901-ee11-4aa5-b891-889d3bde2221@arm.com \
--to=christian.loehle@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=jstultz@google.com \
--cc=kayracizmeci@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=qyousef@layalina.io \
--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®