]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched/proxy: Only return migrate when needed
authorPeter Zijlstra <peterz@infradead.org>
Wed, 27 May 2026 07:58:02 +0000 (09:58 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 2 Jun 2026 10:26:08 +0000 (12:26 +0200)
Current code will 'unconditionally' return migrate on PROXY_WAKING, even if the
task is (still) on the original CPU.

Check task_cpu(p) against p->waking_cpu, which per proxy_set_task_cpu()
preserves the original CPU the task was on. If they do not mis-match, there is
no need to go through the more expensive wakeup path.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260527082916.GP3126523%40noisy.programming.kicks-ass.net
kernel/sched/core.c

index 8b7eb126c254d803c04a1d3e4b7c690c3bddc91d..b007b65d9c88fc5078e72e1e09eb4ac18f1b0020 100644 (file)
@@ -3767,6 +3767,21 @@ static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p)
        if (!task_is_blocked(p))
                return false;
 
+       /*
+        * Typically per __set_task_cpu(), task_cpu(p) == p->wake_cpu.
+        *
+        * However, proxy_set_task_cpu() is such that it preserves the
+        * original cpu in p->wake_cpu while migrating p for proxy reasons
+        * (possibly outside of the allowed p->cpus_ptr).
+        *
+        * Furthermore, migration_cpu_stop() / __migrate_swap_task(), will
+        * only set p->wake_cpu when !p->on_rq, and since here p->on_rq, this
+        * will not apply. But if it did, this check is the safe way around
+        * and would migrate.
+        */
+       if (task_cpu(p) == p->wake_cpu)
+               return false;
+
        scoped_guard(raw_spinlock, &p->blocked_lock) {
                /* Task is waking up; clear any blocked_on relationship */
                __clear_task_blocked_on(p, NULL);