summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2021-02-24 13:21:35 +0300
committerIngo Molnar <mingo@kernel.org>2021-03-06 14:40:21 +0300
commit3f1bc119cd7fc987c8ed25ffb717f99403bb308c (patch)
tree8ee04aee094a12ea4ad9b83523cfb76f4dd0a2b3 /kernel
parent58b1a45086b5f80f2b2842aa7ed0da51a64a302b (diff)
downloadlinux-3f1bc119cd7fc987c8ed25ffb717f99403bb308c.tar.xz
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
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/core.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 84b657f05625..ac05afbd982e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1936,14 +1936,25 @@ static int migration_cpu_stop(void *data)
complete = true;
}
- if (dest_cpu < 0)
+ if (dest_cpu < 0) {
+ if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask))
+ goto out;
+
dest_cpu = cpumask_any_distribute(&p->cpus_mask);
+ }
if (task_on_rq_queued(p))
rq = __migrate_task(rq, &rf, p, dest_cpu);
else
p->wake_cpu = dest_cpu;
+ /*
+ * XXX __migrate_task() can fail, at which point we might end
+ * up running on a dodgy CPU, AFAICT this can only happen
+ * during CPU hotplug, at which point we'll get pushed out
+ * anyway, so it's probably not a big deal.
+ */
+
} else if (pending) {
/*
* This happens when we get migrated between migrate_enable()'s