Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 6d337eab041d ("sched: Fix migrate_disable() vs set_cpus_allowed_ptr()")
Cc: stable@kernel.org
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Link: https://lkml.kernel.org/r/20210224131355.569238629@infradead.org

authored by

Peter Zijlstra and committed by
Ingo Molnar
3f1bc119 58b1a450

+12 -1
+12 -1
kernel/sched/core.c
··· 1936 1936 complete = true; 1937 1937 } 1938 1938 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 + 1940 1943 dest_cpu = cpumask_any_distribute(&p->cpus_mask); 1944 + } 1941 1945 1942 1946 if (task_on_rq_queued(p)) 1943 1947 rq = __migrate_task(rq, &rf, p, dest_cpu); 1944 1948 else 1945 1949 p->wake_cpu = dest_cpu; 1950 + 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 + */ 1946 1957 1947 1958 } else if (pending) { 1948 1959 /*