Skip to content

Commit 3f1bc11

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Optimize migration_cpu_stop()
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]
1 parent 58b1a45 commit 3f1bc11

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
@@ -1936,14 +1936,25 @@ static int migration_cpu_stop(void *data)
19361936
complete = true;
19371937
}
19381938

1939-
if (dest_cpu < 0)
1939+
if (dest_cpu < 0) {
1940+
if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask))
1941+
goto out;
1942+
19401943
dest_cpu = cpumask_any_distribute(&p->cpus_mask);
1944+
}
19411945

19421946
if (task_on_rq_queued(p))
19431947
rq = __migrate_task(rq, &rf, p, dest_cpu);
19441948
else
19451949
p->wake_cpu = dest_cpu;
19461950

1951+
/*
1952+
* XXX __migrate_task() can fail, at which point we might end
1953+
* up running on a dodgy CPU, AFAICT this can only happen
1954+
* during CPU hotplug, at which point we'll get pushed out
1955+
* anyway, so it's probably not a big deal.
1956+
*/
1957+
19471958
} else if (pending) {
19481959
/*
19491960
* This happens when we get migrated between migrate_enable()'s

0 commit comments

Comments
 (0)