]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched: Add assert_balance_callbacks_empty helper
authorJohn Stultz <jstultz@google.com>
Tue, 24 Mar 2026 19:13:22 +0000 (19:13 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 3 Apr 2026 12:23:40 +0000 (14:23 +0200)
With proxy-exec utilizing pick-again logic, we can end up having
balance callbacks set by the preivous pick_next_task() call left
on the list.

So pull the warning out into a helper function, and make sure we
check it when we pick again.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://patch.msgid.link/20260324191337.1841376-8-jstultz@google.com
kernel/sched/core.c
kernel/sched/sched.h

index c997d516441dfcb3ff7e45ed13e46041d4d828f2..acb5894e7714eb63f98a735df19dde36021135f5 100644 (file)
@@ -6853,6 +6853,7 @@ static void __sched notrace __schedule(int sched_mode)
        }
 
 pick_again:
+       assert_balance_callbacks_empty(rq);
        next = pick_next_task(rq, rq->donor, &rf);
        rq->next_class = next->sched_class;
        if (sched_proxy_exec()) {
index b863bbda6de88c5055f499446925a0faf5639842..a2629d025c9094e01d66ff0bff66e9d1b6d43430 100644 (file)
@@ -1857,6 +1857,13 @@ static inline void scx_rq_clock_update(struct rq *rq, u64 clock) {}
 static inline void scx_rq_clock_invalidate(struct rq *rq) {}
 #endif /* !CONFIG_SCHED_CLASS_EXT */
 
+static inline void assert_balance_callbacks_empty(struct rq *rq)
+{
+       WARN_ON_ONCE(IS_ENABLED(CONFIG_PROVE_LOCKING) &&
+                    rq->balance_callback &&
+                    rq->balance_callback != &balance_push_callback);
+}
+
 /*
  * Lockdep annotation that avoids accidental unlocks; it's like a
  * sticky/continuous lockdep_assert_held().
@@ -1873,7 +1880,7 @@ static inline void rq_pin_lock(struct rq *rq, struct rq_flags *rf)
 
        rq->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
        rf->clock_update_flags = 0;
-       WARN_ON_ONCE(rq->balance_callback && rq->balance_callback != &balance_push_callback);
+       assert_balance_callbacks_empty(rq);
 }
 
 static inline void rq_unpin_lock(struct rq *rq, struct rq_flags *rf)