mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] sched/uclamp: Skip uclamp_rq_dec() for non-final dequeue of delayed tasks
@ 2025-07-01  9:34 Zihuan Zhang
  2025-07-01 10:49 ` Xuewen Yan
  2025-07-01 11:00 ` K Prateek Nayak
  0 siblings, 2 replies; 8+ messages in thread
From: Zihuan Zhang @ 2025-07-01  9:34 UTC (permalink / raw)
  To: xuewen.yan, vincent.guittot, mingo, peterz, juri.lelli
  Cc: rostedt, bsegall, mgorman, vschneid, hongyan.xia2, linux-kernel,
	ke.wang, di.shen, xuewen.yan94, kprateek.nayak, kuyo.chang,
	juju.sung, qyousef, Zihuan Zhang

Currently, uclamp_rq_inc() skips updating the clamp aggregation for
delayed tasks unless ENQUEUE_DELAYED is set, to ensure we only track the
real enqueue of a task that was previously marked as sched_delayed.

However, the corresponding uclamp_rq_dec() path only checks
sched_delayed, and misses the DEQUEUE_DELAYED flag. As a result, we may
skip dec for a delayed task that is now being truly dequeued, leading to
uclamp aggregation mismatch.

This patch makes uclamp_rq_dec() consistent with uclamp_rq_inc() by
checking both sched_delayed and DEQUEUE_DELAYED, ensuring correct
accounting symmetry.

Fixes: 90ca9410dab2 ("sched/uclamp: Align uclamp and util_est and call before freq update")
Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
---
 kernel/sched/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8988d38d46a3..99f1542cff7d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1781,7 +1781,7 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p, int flags
 		rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
 }
 
-static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
+static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p, int flags)
 {
 	enum uclamp_id clamp_id;
 
@@ -1797,7 +1797,8 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
 	if (unlikely(!p->sched_class->uclamp_enabled))
 		return;
 
-	if (p->se.sched_delayed)
+	/* Skip dec if this is a delayed task not being truly dequeued */
+	if (p->se.sched_delayed && !(flags & DEQUEUE_DELAYED))
 		return;
 
 	for_each_clamp_id(clamp_id)
@@ -2039,7 +2040,7 @@ static void __init init_uclamp(void)
 
 #else /* !CONFIG_UCLAMP_TASK */
 static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p, int flags) { }
-static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) { }
+static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p, int flags) { }
 static inline void uclamp_fork(struct task_struct *p) { }
 static inline void uclamp_post_fork(struct task_struct *p) { }
 static inline void init_uclamp(void) { }
@@ -2112,7 +2113,7 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
 	 * Must be before ->dequeue_task() because ->dequeue_task() can 'fail'
 	 * and mark the task ->sched_delayed.
 	 */
-	uclamp_rq_dec(rq, p);
+	uclamp_rq_dec(rq, p, flags);
 	return p->sched_class->dequeue_task(rq, p, flags);
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-03 12:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-01  9:34 [PATCH v1] sched/uclamp: Skip uclamp_rq_dec() for non-final dequeue of delayed tasks Zihuan Zhang
2025-07-01 10:49 ` Xuewen Yan
2025-07-02  0:48   ` Zihuan Zhang
2025-07-01 11:00 ` K Prateek Nayak
2025-07-02  0:53   ` Zihuan Zhang
2025-07-02  3:12     ` K Prateek Nayak
2025-07-03  9:03       ` Zihuan Zhang
2025-07-03 12:22     ` Christian Loehle

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®