* [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates
@ 2026-11-27 8:35 Christian Loehle
2026-11-27 8:35 ` [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue Christian Loehle
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Christian Loehle @ 2026-11-27 8:35 UTC (permalink / raw)
To: mingo, peterz, vincent.guittot
Cc: qyousef, christian.loehle, dietmar.eggemann, rostedt, jstultz,
kayracizmeci, wvw, linux-kernel
Static-key updates can let enqueue account a task before dequeue observes
uclamp as enabled. Patch 1 checks the task's effective UCLAMP_MIN active
flag on dequeue, so accounted clamps are released regardless of static-key
update progress. The early check keeps the unused dequeue path short, and
enqueue retains its static key.
Patch 2 picks up Qais's idle-flag wrapper cleanup from v7 [1].
The measurements below are for patch 1 on v7.4-rc4, before adding patch 2
and rebasing. Each cell gives fix / always-on percentage changes versus
unfixed, with CONFIG_UCLAMP_TASK=y throughout. The unfixed and fixed
kernels keep the uclamp key disabled while always-on performs accounting.
Nine fresh boots per variant, 20 measured repetitions per boot. Changes
are geometric means of paired boot-median ratios.
Positive time/latency is slower, positive throughput is faster.
Workload / metric │ i7-13700K: fix / always-on │ Xeon: fix / always-on │ Orion: fix / always-on
────────────────────────────────┼────────────────────────────┼───────────────────────┼────────────────────────
messaging-processes / seconds │ (-0.06%) / (+0.09%) │ (-0.40%) / (-0.21%) │ -0.38% / (-0.31%)
messaging-threads / seconds │ (-0.19%) / (+0.05%) │ -0.86% / -1.77% │ (+0.10%) / (+0.11%)
pipe-processes / usec_per_op │ (+0.18%) / +1.56% │ (-0.002%) / +2.41% │ -1.17% / +1.19%
pipe-threads / usec_per_op │ -0.78% / +0.88% │ (+0.01%) / +2.91% │ (-1.61%) / (+0.53%)
schbench-256k / rps │ (+0.002%) / (-0.04%) │ (+0.004%) / -0.05% │ (-0.20%) / (+0.03%)
schbench-256k / wakeup_p99_us │ (+0.42%) / (+0.51%) │ (+2.33%) / +10.62% │ (-1.44%) / (-0.37%)
schbench-4096k / rps │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%)
schbench-4096k / wakeup_p99_us │ +32.68% / (+12.93%) │ (-10.66%) / (+2.71%) │ (+3.03%) / -6.99%
tcp-stream-1024 / Mbps │ (-0.24%) / -0.69% │ -0.61% / +1.07% │ +0.36% / (-0.52%)
tcp-stream-16384 / Mbps │ (-0.03%) / -0.29% │ -0.57% / +0.23% │ (+1.04%) / (-0.82%)
tcp-stream-64 / Mbps │ (+3.05%) / +18.60% │ (+0.12%) / +23.54% │ +2.50% / +2.09%
tcp_rr / transactions_per_sec │ (-0.57%) / -1.68% │ -0.66% / -1.33% │ (+0.10%) / -1.58%
udp-stream-1024 / rx_Mbps │ (+0.19%) / (+0.17%) │ (-0.41%) / (+0.32%) │ -1.58% / (-0.63%)
udp-stream-128 / rx_Mbps │ (-0.82%) / (-0.15%) │ (-0.38%) / +1.54% │ -1.31% / -0.69%
udp-stream-16384 / rx_Mbps │ (-0.31%) / (-0.49%) │ -0.35% / +0.30% │ -1.52% / +0.61%
udp-stream-2048 / rx_Mbps │ (+0.02%) / (+0.06%) │ (-0.24%) / (-0.09%) │ -1.18% / (-0.74%)
udp-stream-256 / rx_Mbps │ (+0.33%) / (+0.29%) │ -0.72% / +1.56% │ -1.76% / -0.86%
udp-stream-3312 / rx_Mbps │ (+0.38%) / (-0.07%) │ (-0.04%) / (+0.14%) │ -1.18% / (-0.54%)
udp-stream-4096 / rx_Mbps │ (-0.06%) / (+0.22%) │ (-0.24%) / (+0.08%) │ -1.31% / (-0.66%)
udp-stream-64 / rx_Mbps │ (-0.18%) / (-0.17%) │ -0.57% / +1.20% │ -1.51% / -1.45%
udp-stream-64-pinned / rx_Mbps │ (-0.94%) / (+0.90%) │ (-0.28%) / +1.63% │ -1.21% / (-0.30%)
udp-stream-8192 / rx_Mbps │ (-0.25%) / -0.39% │ -1.54% / -1.01% │ -0.96% / (+0.15%)
udp_rr / transactions_per_sec │ (-0.72%) / -1.69% │ -0.94% / -1.55% │ +0.44% / -1.84%
Separately, paired log-ratio t-tests with Holm correction across the 69
fix-versus-unfixed comparisons retained only significant regression:
Xeon UDP_STREAM 8 KiB throughput −1.54%.
[1] https://lore.kernel.org/r/20261126012836.15205-3-qyousef@layalina.io
Christian Loehle (1):
sched/uclamp: Always account active clamps on dequeue
Qais Yousef (1):
sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
kernel/sched/core.c | 27 +++++++++++++--------------
kernel/sched/sched.h | 10 ++++++++++
2 files changed, 23 insertions(+), 14 deletions(-)
base-commit: 029fd68a263364583b6f9b34d22761acf0a3940c
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue
2026-11-27 8:35 [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Christian Loehle
@ 2026-11-27 8:35 ` Christian Loehle
2026-11-27 10:18 ` Kayra Cizmeci
2026-11-27 8:35 ` [PATCH 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Christian Loehle
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Christian Loehle @ 2026-11-27 8:35 UTC (permalink / raw)
To: mingo, peterz, vincent.guittot
Cc: qyousef, christian.loehle, dietmar.eggemann, rostedt, jstultz,
kayracizmeci, wvw, linux-kernel
Enabling sched_uclamp_used does not update all static-key callsites
atomically. An enqueue can observe the key enabled and increment a
task's uclamp buckets while a subsequent dequeue still observes it
disabled and skips the decrement. This leaves stale bucket references
and active bits, which can keep the runqueue clamps elevated after the
task sleeps or migrates.
Replace the static-key check in uclamp_rq_dec() with a check of the
task's effective UCLAMP_MIN active flag. This records whether the task
contributed to the runqueue accounting, so an accounted task releases
its references regardless of static-key update progress.
Enqueue and dequeue update both effective clamps under rq->lock.
Updates to an already active clamp complete their decrement and
increment under the same lock, so dequeue cannot observe their
temporary inactive state. At entry to uclamp_rq_dec(), either active
flag therefore suffices to determine whether the task has accounting
to release.
Keep the static key on enqueue, so unused uclamp still skips enqueue
accounting. On dequeue, the early active check returns before the
scheduling-class and delayed-task checks or either per-ID helper call.
Limiting the change to dequeue retains the enqueue benefit of the
static key and reduces the unused dequeue path to an active-state
check.
Reported-by: Wei Wang <wvw@google.com>
Closes: https://lore.kernel.org/all/CANDhNCqyXsZ6G77z+9s=rTO6BZifRG9+hVxMTah+tAv6pB6h3w@mail.gmail.com/
Suggested-by: Wei Wang <wvw@google.com>
Fixes: 46609ce22703 ("sched/uclamp: Protect uclamp fast path code with static key")
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
kernel/sched/core.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c9890ed35df7..05b092147c6f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1617,8 +1617,7 @@ static struct uclamp_se uclamp_default[UCLAMP_CNT];
/*
* This static key is used to reduce the uclamp overhead in the fast path. It
- * primarily disables the call to uclamp_rq_{inc, dec}() in
- * enqueue/dequeue_task().
+ * disables uclamp_rq_inc() accounting in enqueue_task().
*
* This allows users to continue to enable uclamp in their kernel config with
* minimum uclamp overhead in the fast path.
@@ -1918,12 +1917,12 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
enum uclamp_id clamp_id;
/*
- * Avoid any overhead until uclamp is actually used by the userspace.
- *
- * The condition is constructed such that a NOP is generated when
- * sched_uclamp_used is disabled.
+ * Static-key updates are not atomic across callsites. An enqueue may
+ * have accounted this task before this callsite observes the key enabled.
+ * Check the task's accounting state instead. Both clamps are updated
+ * under the rq lock, so either active flag is sufficient here.
*/
- if (!uclamp_is_used())
+ if (!p->uclamp[UCLAMP_MIN].active)
return;
if (unlikely(!p->sched_class->uclamp_enabled))
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
2026-11-27 8:35 [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Christian Loehle
2026-11-27 8:35 ` [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue Christian Loehle
@ 2026-11-27 8:35 ` Christian Loehle
2026-11-27 9:40 ` [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Peter Zijlstra
2026-11-27 9:49 ` Vincent Guittot
3 siblings, 0 replies; 7+ messages in thread
From: Christian Loehle @ 2026-11-27 8:35 UTC (permalink / raw)
To: mingo, peterz, vincent.guittot
Cc: qyousef, christian.loehle, dietmar.eggemann, rostedt, jstultz,
kayracizmeci, wvw, linux-kernel
From: Qais Yousef <qyousef@layalina.io>
We already have uclamp_rq_is_idle(), but it wasn't used everywhere.
Replace open coding with the function and add new wrapper to set and
clear the flag which enhances readability.
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
Signed-off-by: Qais Yousef <qyousef@layalina.io>
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
kernel/sched/core.c | 14 +++++++-------
kernel/sched/sched.h | 10 ++++++++++
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 05b092147c6f..8c4cd507eca9 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1644,7 +1644,7 @@ uclamp_idle_value(struct rq *rq, enum uclamp_id clamp_id,
* max-clamp.
*/
if (clamp_id == UCLAMP_MAX) {
- rq->uclamp_flags |= UCLAMP_FLAG_IDLE;
+ uclamp_rq_set_idle(rq);
return clamp_value;
}
@@ -1655,7 +1655,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id,
unsigned int clamp_value)
{
/* Reset max-clamp retention only on idle exit */
- if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE))
+ if (!uclamp_rq_is_idle(rq))
return;
uclamp_rq_set(rq, clamp_id, clamp_value);
@@ -1908,8 +1908,8 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p, int flags
uclamp_rq_inc_id(rq, p, clamp_id);
/* Reset clamp idle holding when there is one RUNNABLE task */
- if (rq->uclamp_flags & UCLAMP_FLAG_IDLE)
- rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
+ if (uclamp_rq_is_idle(rq))
+ uclamp_rq_clear_idle(rq);
}
static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
@@ -1948,8 +1948,8 @@ static inline void uclamp_rq_reinc_id(struct rq *rq, struct task_struct *p,
* Make sure to clear the idle flag if we've transiently reached 0
* active tasks on rq.
*/
- if (clamp_id == UCLAMP_MAX && (rq->uclamp_flags & UCLAMP_FLAG_IDLE))
- rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
+ if (clamp_id == UCLAMP_MAX && uclamp_rq_is_idle(rq))
+ uclamp_rq_clear_idle(rq);
}
static inline void
@@ -2140,7 +2140,7 @@ static void __init init_uclamp_rq(struct rq *rq)
};
}
- rq->uclamp_flags = UCLAMP_FLAG_IDLE;
+ uclamp_rq_set_idle(rq);
}
static void __init init_uclamp(void)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 804c70317637..982d47fbe9b7 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3799,6 +3799,16 @@ static inline void uclamp_rq_set(struct rq *rq, enum uclamp_id clamp_id,
WRITE_ONCE(rq->uclamp[clamp_id].value, value);
}
+static inline void uclamp_rq_set_idle(struct rq *rq)
+{
+ rq->uclamp_flags |= UCLAMP_FLAG_IDLE;
+}
+
+static inline void uclamp_rq_clear_idle(struct rq *rq)
+{
+ rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
+}
+
static inline bool uclamp_rq_is_idle(struct rq *rq)
{
return rq->uclamp_flags & UCLAMP_FLAG_IDLE;
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates
2026-11-27 8:35 [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Christian Loehle
2026-11-27 8:35 ` [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue Christian Loehle
2026-11-27 8:35 ` [PATCH 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Christian Loehle
@ 2026-11-27 9:40 ` Peter Zijlstra
2026-11-27 9:47 ` Christian Loehle
2026-11-27 9:49 ` Vincent Guittot
3 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2026-11-27 9:40 UTC (permalink / raw)
To: Christian Loehle
Cc: mingo, vincent.guittot, qyousef, dietmar.eggemann, rostedt,
jstultz, kayracizmeci, wvw, linux-kernel
On Fri, Nov 27, 2026 at 08:35:40AM +0000, Christian Loehle wrote:
> Static-key updates can let enqueue account a task before dequeue observes
> uclamp as enabled. Patch 1 checks the task's effective UCLAMP_MIN active
> flag on dequeue, so accounted clamps are released regardless of static-key
> update progress. The early check keeps the unused dequeue path short, and
> enqueue retains its static key.
>
> Patch 2 picks up Qais's idle-flag wrapper cleanup from v7 [1].
>
> The measurements below are for patch 1 on v7.4-rc4, before adding patch 2
> and rebasing. Each cell gives fix / always-on percentage changes versus
> unfixed, with CONFIG_UCLAMP_TASK=y throughout. The unfixed and fixed
> kernels keep the uclamp key disabled while always-on performs accounting.
>
> Nine fresh boots per variant, 20 measured repetitions per boot. Changes
> are geometric means of paired boot-median ratios.
> Positive time/latency is slower, positive throughput is faster.
>
> Workload / metric │ i7-13700K: fix / always-on │ Xeon: fix / always-on │ Orion: fix / always-on
> ────────────────────────────────┼────────────────────────────┼───────────────────────┼────────────────────────
> messaging-processes / seconds │ (-0.06%) / (+0.09%) │ (-0.40%) / (-0.21%) │ -0.38% / (-0.31%)
> messaging-threads / seconds │ (-0.19%) / (+0.05%) │ -0.86% / -1.77% │ (+0.10%) / (+0.11%)
> pipe-processes / usec_per_op │ (+0.18%) / +1.56% │ (-0.002%) / +2.41% │ -1.17% / +1.19%
> pipe-threads / usec_per_op │ -0.78% / +0.88% │ (+0.01%) / +2.91% │ (-1.61%) / (+0.53%)
> schbench-256k / rps │ (+0.002%) / (-0.04%) │ (+0.004%) / -0.05% │ (-0.20%) / (+0.03%)
> schbench-256k / wakeup_p99_us │ (+0.42%) / (+0.51%) │ (+2.33%) / +10.62% │ (-1.44%) / (-0.37%)
> schbench-4096k / rps │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%)
> schbench-4096k / wakeup_p99_us │ +32.68% / (+12.93%) │ (-10.66%) / (+2.71%) │ (+3.03%) / -6.99%
> tcp-stream-1024 / Mbps │ (-0.24%) / -0.69% │ -0.61% / +1.07% │ +0.36% / (-0.52%)
> tcp-stream-16384 / Mbps │ (-0.03%) / -0.29% │ -0.57% / +0.23% │ (+1.04%) / (-0.82%)
> tcp-stream-64 / Mbps │ (+3.05%) / +18.60% │ (+0.12%) / +23.54% │ +2.50% / +2.09%
> tcp_rr / transactions_per_sec │ (-0.57%) / -1.68% │ -0.66% / -1.33% │ (+0.10%) / -1.58%
> udp-stream-1024 / rx_Mbps │ (+0.19%) / (+0.17%) │ (-0.41%) / (+0.32%) │ -1.58% / (-0.63%)
> udp-stream-128 / rx_Mbps │ (-0.82%) / (-0.15%) │ (-0.38%) / +1.54% │ -1.31% / -0.69%
> udp-stream-16384 / rx_Mbps │ (-0.31%) / (-0.49%) │ -0.35% / +0.30% │ -1.52% / +0.61%
> udp-stream-2048 / rx_Mbps │ (+0.02%) / (+0.06%) │ (-0.24%) / (-0.09%) │ -1.18% / (-0.74%)
> udp-stream-256 / rx_Mbps │ (+0.33%) / (+0.29%) │ -0.72% / +1.56% │ -1.76% / -0.86%
> udp-stream-3312 / rx_Mbps │ (+0.38%) / (-0.07%) │ (-0.04%) / (+0.14%) │ -1.18% / (-0.54%)
> udp-stream-4096 / rx_Mbps │ (-0.06%) / (+0.22%) │ (-0.24%) / (+0.08%) │ -1.31% / (-0.66%)
> udp-stream-64 / rx_Mbps │ (-0.18%) / (-0.17%) │ -0.57% / +1.20% │ -1.51% / -1.45%
> udp-stream-64-pinned / rx_Mbps │ (-0.94%) / (+0.90%) │ (-0.28%) / +1.63% │ -1.21% / (-0.30%)
> udp-stream-8192 / rx_Mbps │ (-0.25%) / -0.39% │ -1.54% / -1.01% │ -0.96% / (+0.15%)
> udp_rr / transactions_per_sec │ (-0.72%) / -1.69% │ -0.94% / -1.55% │ +0.44% / -1.84%
>
> Separately, paired log-ratio t-tests with Holm correction across the 69
> fix-versus-unfixed comparisons retained only significant regression:
> Xeon UDP_STREAM 8 KiB throughput −1.54%.
>
> [1] https://lore.kernel.org/r/20261126012836.15205-3-qyousef@layalina.io
>
> Christian Loehle (1):
> sched/uclamp: Always account active clamps on dequeue
>
> Qais Yousef (1):
> sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
>
> kernel/sched/core.c | 27 +++++++++++++--------------
> kernel/sched/sched.h | 10 ++++++++++
> 2 files changed, 23 insertions(+), 14 deletions(-)
>
So we're going to do this first and then Qais can work on issues still
plaguing his approach? Is that the thinking?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates
2026-11-27 9:40 ` [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Peter Zijlstra
@ 2026-11-27 9:47 ` Christian Loehle
0 siblings, 0 replies; 7+ messages in thread
From: Christian Loehle @ 2026-11-27 9:47 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mingo, vincent.guittot, qyousef, dietmar.eggemann, rostedt,
jstultz, kayracizmeci, wvw, linux-kernel
On 11/27/26 09:40, Peter Zijlstra wrote:
> On Fri, Nov 27, 2026 at 08:35:40AM +0000, Christian Loehle wrote:
>> Static-key updates can let enqueue account a task before dequeue observes
>> uclamp as enabled. Patch 1 checks the task's effective UCLAMP_MIN active
>> flag on dequeue, so accounted clamps are released regardless of static-key
>> update progress. The early check keeps the unused dequeue path short, and
>> enqueue retains its static key.
>>
>> Patch 2 picks up Qais's idle-flag wrapper cleanup from v7 [1].
>>
>> The measurements below are for patch 1 on v7.4-rc4, before adding patch 2
>> and rebasing. Each cell gives fix / always-on percentage changes versus
>> unfixed, with CONFIG_UCLAMP_TASK=y throughout. The unfixed and fixed
>> kernels keep the uclamp key disabled while always-on performs accounting.
>>
>> Nine fresh boots per variant, 20 measured repetitions per boot. Changes
>> are geometric means of paired boot-median ratios.
>> Positive time/latency is slower, positive throughput is faster.
>>
>> Workload / metric │ i7-13700K: fix / always-on │ Xeon: fix / always-on │ Orion: fix / always-on
>> ────────────────────────────────┼────────────────────────────┼───────────────────────┼────────────────────────
>> messaging-processes / seconds │ (-0.06%) / (+0.09%) │ (-0.40%) / (-0.21%) │ -0.38% / (-0.31%)
>> messaging-threads / seconds │ (-0.19%) / (+0.05%) │ -0.86% / -1.77% │ (+0.10%) / (+0.11%)
>> pipe-processes / usec_per_op │ (+0.18%) / +1.56% │ (-0.002%) / +2.41% │ -1.17% / +1.19%
>> pipe-threads / usec_per_op │ -0.78% / +0.88% │ (+0.01%) / +2.91% │ (-1.61%) / (+0.53%)
>> schbench-256k / rps │ (+0.002%) / (-0.04%) │ (+0.004%) / -0.05% │ (-0.20%) / (+0.03%)
>> schbench-256k / wakeup_p99_us │ (+0.42%) / (+0.51%) │ (+2.33%) / +10.62% │ (-1.44%) / (-0.37%)
>> schbench-4096k / rps │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%)
>> schbench-4096k / wakeup_p99_us │ +32.68% / (+12.93%) │ (-10.66%) / (+2.71%) │ (+3.03%) / -6.99%
>> tcp-stream-1024 / Mbps │ (-0.24%) / -0.69% │ -0.61% / +1.07% │ +0.36% / (-0.52%)
>> tcp-stream-16384 / Mbps │ (-0.03%) / -0.29% │ -0.57% / +0.23% │ (+1.04%) / (-0.82%)
>> tcp-stream-64 / Mbps │ (+3.05%) / +18.60% │ (+0.12%) / +23.54% │ +2.50% / +2.09%
>> tcp_rr / transactions_per_sec │ (-0.57%) / -1.68% │ -0.66% / -1.33% │ (+0.10%) / -1.58%
>> udp-stream-1024 / rx_Mbps │ (+0.19%) / (+0.17%) │ (-0.41%) / (+0.32%) │ -1.58% / (-0.63%)
>> udp-stream-128 / rx_Mbps │ (-0.82%) / (-0.15%) │ (-0.38%) / +1.54% │ -1.31% / -0.69%
>> udp-stream-16384 / rx_Mbps │ (-0.31%) / (-0.49%) │ -0.35% / +0.30% │ -1.52% / +0.61%
>> udp-stream-2048 / rx_Mbps │ (+0.02%) / (+0.06%) │ (-0.24%) / (-0.09%) │ -1.18% / (-0.74%)
>> udp-stream-256 / rx_Mbps │ (+0.33%) / (+0.29%) │ -0.72% / +1.56% │ -1.76% / -0.86%
>> udp-stream-3312 / rx_Mbps │ (+0.38%) / (-0.07%) │ (-0.04%) / (+0.14%) │ -1.18% / (-0.54%)
>> udp-stream-4096 / rx_Mbps │ (-0.06%) / (+0.22%) │ (-0.24%) / (+0.08%) │ -1.31% / (-0.66%)
>> udp-stream-64 / rx_Mbps │ (-0.18%) / (-0.17%) │ -0.57% / +1.20% │ -1.51% / -1.45%
>> udp-stream-64-pinned / rx_Mbps │ (-0.94%) / (+0.90%) │ (-0.28%) / +1.63% │ -1.21% / (-0.30%)
>> udp-stream-8192 / rx_Mbps │ (-0.25%) / -0.39% │ -1.54% / -1.01% │ -0.96% / (+0.15%)
>> udp_rr / transactions_per_sec │ (-0.72%) / -1.69% │ -0.94% / -1.55% │ +0.44% / -1.84%
>>
>> Separately, paired log-ratio t-tests with Holm correction across the 69
>> fix-versus-unfixed comparisons retained only significant regression:
>> Xeon UDP_STREAM 8 KiB throughput −1.54%.
>>
>> [1] https://lore.kernel.org/r/20261126012836.15205-3-qyousef@layalina.io
>>
>> Christian Loehle (1):
>> sched/uclamp: Always account active clamps on dequeue
>>
>> Qais Yousef (1):
>> sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
>>
>> kernel/sched/core.c | 27 +++++++++++++--------------
>> kernel/sched/sched.h | 10 ++++++++++
>> 2 files changed, 23 insertions(+), 14 deletions(-)
>>
>
> So we're going to do this first and then Qais can work on issues still
> plaguing his approach? Is that the thinking?
If we're happy with this, then I don't see anything that still needs fixing?
I guess we can miss an enqueue transiently still, but given how rare this
case is I would say not to care, anyway that is self-healing at the next
enqueue-dequeue pair.
The important issue was not seeing the static branch at dequeue, while it
was enabled on the corresponding enqueue, this patch completely plumbs that,
with the cost of no longer having the static branch on the dequeue path.
The numbers indicate that this is probably okay.
Or did you mean Qais' patch 3?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates
2026-11-27 8:35 [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Christian Loehle
` (2 preceding siblings ...)
2026-11-27 9:40 ` [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Peter Zijlstra
@ 2026-11-27 9:49 ` Vincent Guittot
3 siblings, 0 replies; 7+ messages in thread
From: Vincent Guittot @ 2026-11-27 9:49 UTC (permalink / raw)
To: Christian Loehle
Cc: mingo, peterz, qyousef, dietmar.eggemann, rostedt, jstultz,
kayracizmeci, wvw, linux-kernel
On Fri, 27 Nov 2026 at 09:35, Christian Loehle <christian.loehle@arm.com> wrote:
>
> Static-key updates can let enqueue account a task before dequeue observes
> uclamp as enabled. Patch 1 checks the task's effective UCLAMP_MIN active
> flag on dequeue, so accounted clamps are released regardless of static-key
> update progress. The early check keeps the unused dequeue path short, and
> enqueue retains its static key.
>
> Patch 2 picks up Qais's idle-flag wrapper cleanup from v7 [1].
>
> The measurements below are for patch 1 on v7.4-rc4, before adding patch 2
> and rebasing. Each cell gives fix / always-on percentage changes versus
> unfixed, with CONFIG_UCLAMP_TASK=y throughout. The unfixed and fixed
> kernels keep the uclamp key disabled while always-on performs accounting.
>
> Nine fresh boots per variant, 20 measured repetitions per boot. Changes
> are geometric means of paired boot-median ratios.
> Positive time/latency is slower, positive throughput is faster.
>
> Workload / metric │ i7-13700K: fix / always-on │ Xeon: fix / always-on │ Orion: fix / always-on
> ────────────────────────────────┼────────────────────────────┼───────────────────────┼────────────────────────
> messaging-processes / seconds │ (-0.06%) / (+0.09%) │ (-0.40%) / (-0.21%) │ -0.38% / (-0.31%)
> messaging-threads / seconds │ (-0.19%) / (+0.05%) │ -0.86% / -1.77% │ (+0.10%) / (+0.11%)
> pipe-processes / usec_per_op │ (+0.18%) / +1.56% │ (-0.002%) / +2.41% │ -1.17% / +1.19%
> pipe-threads / usec_per_op │ -0.78% / +0.88% │ (+0.01%) / +2.91% │ (-1.61%) / (+0.53%)
> schbench-256k / rps │ (+0.002%) / (-0.04%) │ (+0.004%) / -0.05% │ (-0.20%) / (+0.03%)
> schbench-256k / wakeup_p99_us │ (+0.42%) / (+0.51%) │ (+2.33%) / +10.62% │ (-1.44%) / (-0.37%)
> schbench-4096k / rps │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%) │ (+0.00%) / (+0.00%)
> schbench-4096k / wakeup_p99_us │ +32.68% / (+12.93%) │ (-10.66%) / (+2.71%) │ (+3.03%) / -6.99%
> tcp-stream-1024 / Mbps │ (-0.24%) / -0.69% │ -0.61% / +1.07% │ +0.36% / (-0.52%)
> tcp-stream-16384 / Mbps │ (-0.03%) / -0.29% │ -0.57% / +0.23% │ (+1.04%) / (-0.82%)
> tcp-stream-64 / Mbps │ (+3.05%) / +18.60% │ (+0.12%) / +23.54% │ +2.50% / +2.09%
> tcp_rr / transactions_per_sec │ (-0.57%) / -1.68% │ -0.66% / -1.33% │ (+0.10%) / -1.58%
> udp-stream-1024 / rx_Mbps │ (+0.19%) / (+0.17%) │ (-0.41%) / (+0.32%) │ -1.58% / (-0.63%)
> udp-stream-128 / rx_Mbps │ (-0.82%) / (-0.15%) │ (-0.38%) / +1.54% │ -1.31% / -0.69%
> udp-stream-16384 / rx_Mbps │ (-0.31%) / (-0.49%) │ -0.35% / +0.30% │ -1.52% / +0.61%
> udp-stream-2048 / rx_Mbps │ (+0.02%) / (+0.06%) │ (-0.24%) / (-0.09%) │ -1.18% / (-0.74%)
> udp-stream-256 / rx_Mbps │ (+0.33%) / (+0.29%) │ -0.72% / +1.56% │ -1.76% / -0.86%
> udp-stream-3312 / rx_Mbps │ (+0.38%) / (-0.07%) │ (-0.04%) / (+0.14%) │ -1.18% / (-0.54%)
> udp-stream-4096 / rx_Mbps │ (-0.06%) / (+0.22%) │ (-0.24%) / (+0.08%) │ -1.31% / (-0.66%)
> udp-stream-64 / rx_Mbps │ (-0.18%) / (-0.17%) │ -0.57% / +1.20% │ -1.51% / -1.45%
> udp-stream-64-pinned / rx_Mbps │ (-0.94%) / (+0.90%) │ (-0.28%) / +1.63% │ -1.21% / (-0.30%)
> udp-stream-8192 / rx_Mbps │ (-0.25%) / -0.39% │ -1.54% / -1.01% │ -0.96% / (+0.15%)
> udp_rr / transactions_per_sec │ (-0.72%) / -1.69% │ -0.94% / -1.55% │ +0.44% / -1.84%
>
I rerun the test on my dragon rb5 with patch 1and perf sched pipe -T,
perf cpufreq gov and only WFI:
- on big, the diff is -0.68% (+/- 0.32%)
- on medium it's -1.35% (+/- 0.58%)
- and on little it's -3.99% (+/- 0.56%)
That being said, I don't have a better solution so far ... So although
I always favor putting this kind of feature behind a static key to
avoid penalizing non-users, if others are fine with it, the solution
is okay with me too
> Separately, paired log-ratio t-tests with Holm correction across the 69
> fix-versus-unfixed comparisons retained only significant regression:
> Xeon UDP_STREAM 8 KiB throughput −1.54%.
>
> [1] https://lore.kernel.org/r/20261126012836.15205-3-qyousef@layalina.io
>
> Christian Loehle (1):
> sched/uclamp: Always account active clamps on dequeue
>
> Qais Yousef (1):
> sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
>
> kernel/sched/core.c | 27 +++++++++++++--------------
> kernel/sched/sched.h | 10 ++++++++++
> 2 files changed, 23 insertions(+), 14 deletions(-)
>
>
> base-commit: 029fd68a263364583b6f9b34d22761acf0a3940c
> --
> 2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue
2026-11-27 8:35 ` [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue Christian Loehle
@ 2026-11-27 10:18 ` Kayra Cizmeci
0 siblings, 0 replies; 7+ messages in thread
From: Kayra Cizmeci @ 2026-11-27 10:18 UTC (permalink / raw)
To: Christian Loehle
Cc: mingo, peterz, vincent.guittot, qyousef, dietmar.eggemann,
rostedt, jstultz, wvw, linux-kernel
Hi Christian,
On Fri, Nov 27, 2026 at 08:35:41AM +0000, Christian Loehle wrote:
> Enabling sched_uclamp_used does not update all static-key callsites
> atomically. An enqueue can observe the key enabled and increment a
> task's uclamp buckets while a subsequent dequeue still observes it
> disabled and skips the decrement. This leaves stale bucket references
> and active bits, which can keep the runqueue clamps elevated after the
> task sleeps or migrates.
>
> Replace the static-key check in uclamp_rq_dec() with a check of the
> task's effective UCLAMP_MIN active flag. This records whether the task
> contributed to the runqueue accounting, so an accounted task releases
> its references regardless of static-key update progress.
>
> Enqueue and dequeue update both effective clamps under rq->lock.
> Updates to an already active clamp complete their decrement and
> increment under the same lock, so dequeue cannot observe their
> temporary inactive state. At entry to uclamp_rq_dec(), either active
> flag therefore suffices to determine whether the task has accounting
> to release.
>
> Keep the static key on enqueue, so unused uclamp still skips enqueue
> accounting. On dequeue, the early active check returns before the
> scheduling-class and delayed-task checks or either per-ID helper call.
> Limiting the change to dequeue retains the enqueue benefit of the
> static key and reduces the unused dequeue path to an active-state
> check.
>
> Reported-by: Wei Wang <wvw@google.com>
> Closes: https://lore.kernel.org/all/CANDhNCqyXsZ6G77z+9s=rTO6BZifRG9+hVxMTah+tAv6pB6h3w@mail.gmail.com/
> Suggested-by: Wei Wang <wvw@google.com>
> Fixes: 46609ce22703 ("sched/uclamp: Protect uclamp fast path code with static key")
> Signed-off-by: Christian Loehle <christian.loehle@arm.com>
> ---
> kernel/sched/core.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index c9890ed35df7..05b092147c6f 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1617,8 +1617,7 @@ static struct uclamp_se uclamp_default[UCLAMP_CNT];
>
> /*
> * This static key is used to reduce the uclamp overhead in the fast path. It
> - * primarily disables the call to uclamp_rq_{inc, dec}() in
> - * enqueue/dequeue_task().
> + * disables uclamp_rq_inc() accounting in enqueue_task().
> *
> * This allows users to continue to enable uclamp in their kernel config with
> * minimum uclamp overhead in the fast path.
> @@ -1918,12 +1917,12 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
> enum uclamp_id clamp_id;
>
> /*
> - * Avoid any overhead until uclamp is actually used by the userspace.
> - *
> - * The condition is constructed such that a NOP is generated when
> - * sched_uclamp_used is disabled.
> + * Static-key updates are not atomic across callsites. An enqueue may
> + * have accounted this task before this callsite observes the key enabled.
> + * Check the task's accounting state instead. Both clamps are updated
> + * under the rq lock, so either active flag is sufficient here.
> */
> - if (!uclamp_is_used())
> + if (!p->uclamp[UCLAMP_MIN].active)
> return;
>
> if (unlikely(!p->sched_class->uclamp_enabled))
> --
> 2.34.1
>
Yeah well...
Hope I was following this issue from the start. Now reviewing is a bit
messy.
Although, I can't really see any *cleaner* way to fix this. And the code
looks correct. Since this active thing gets set in uclamp_rq_inc_id(),
when we increase the bucket thingie.
BTW, a little nit: right now uclamp_rq_dec_id() checks active too, but
with above that is always true since we check it before we enter.
The only other call site uclamp_rq_reinc_id() checks it too.
So removing it would be sweet. Just a nit tho :-).
Hope I'm not missing something.
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
Cheers,
Kayra
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-27 10:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 8:35 [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Christian Loehle
2026-11-27 8:35 ` [PATCH 1/2] sched/uclamp: Always account active clamps on dequeue Christian Loehle
2026-11-27 10:18 ` Kayra Cizmeci
2026-11-27 8:35 ` [PATCH 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Christian Loehle
2026-11-27 9:40 ` [RESEND][PATCH 0/2] sched/uclamp: Fix dequeue accounting across static-key updates Peter Zijlstra
2026-11-27 9:47 ` Christian Loehle
2026-11-27 9:49 ` Vincent Guittot
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®