Skip to content

Commit 4444820

Browse files
Peter Zijlstrarostedt
authored andcommitted
sched: Optimize migration_cpu_stop()
commit 3f1bc11 upstream. When the purpose of migration_cpu_stop() is to migrate the task to 'any' valid CPU, don't migrate the task when it's already running on a valid CPU. Fixes: 6d337ea ("sched: Fix migrate_disable() vs set_cpus_allowed_ptr()") Cc: [email protected] Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Paul Gortmaker <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent c1ae80b commit 4444820

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

kernel/sched/core.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,14 +1972,25 @@ static int migration_cpu_stop(void *data)
19721972
complete = true;
19731973
}
19741974

1975-
if (dest_cpu < 0)
1975+
if (dest_cpu < 0) {
1976+
if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask))
1977+
goto out;
1978+
19761979
dest_cpu = cpumask_any_distribute(&p->cpus_mask);
1980+
}
19771981

19781982
if (task_on_rq_queued(p))
19791983
rq = __migrate_task(rq, &rf, p, dest_cpu);
19801984
else
19811985
p->wake_cpu = dest_cpu;
19821986

1987+
/*
1988+
* XXX __migrate_task() can fail, at which point we might end
1989+
* up running on a dodgy CPU, AFAICT this can only happen
1990+
* during CPU hotplug, at which point we'll get pushed out
1991+
* anyway, so it's probably not a big deal.
1992+
*/
1993+
19831994
} else if (pending) {
19841995
/*
19851996
* This happens when we get migrated between migrate_enable()'s

0 commit comments

Comments
 (0)