From: Peter Zijlstra Date: Wed, 27 May 2026 07:58:02 +0000 (+0200) Subject: sched/proxy: Only return migrate when needed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7918cf3693614c9f96bc9e43daff6fc72c01b81a;p=thirdparty%2Flinux.git sched/proxy: Only return migrate when needed 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) Link: https://patch.msgid.link/20260527082916.GP3126523%40noisy.programming.kicks-ass.net --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 8b7eb126c254d..b007b65d9c88f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -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);