Skip to content

Commit

Permalink
sched: Optimize migration_cpu_stop()
Browse files Browse the repository at this point in the history
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: 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
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Mar 6, 2021
1 parent 58b1a45 commit 3f1bc11
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f1bc11

Please sign in to comment.