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) <peterz@infradead.org>
Link: https://patch.msgid.link/20260527082916.GP3126523%40noisy.programming.kicks-ass.net
This commit is contained in:
Peter Zijlstra
2026-05-27 09:58:02 +02:00
parent 708024b575
commit 7918cf3693

View 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);