From b71791171e1559014879692b2f10f349dbe8602e Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Tue, 1 Mar 2022 10:41:41 -0800 Subject: [PATCH] sched/walt: do not perform unnecessary migrations It is possible that the fallback destination cpu is the same as the current cpu. In this case, this is an inappropriate migration request, causing a double lock unbalance error in walt_detach_task. Prevent this case by preventing a task that is not going to be migrated from being passed to __migrate_task, and instead detach the task and add it to the list to be added back later. Change-Id: I26f57bf52ca9a7bfe221d02d9ccb353d8c8d27ff Signed-off-by: Stephen Dickey --- kernel/sched/walt/walt_halt.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/kernel/sched/walt/walt_halt.c b/kernel/sched/walt/walt_halt.c index a8cf2ed2de8e..4b83f7e71d7c 100644 --- a/kernel/sched/walt/walt_halt.c +++ b/kernel/sched/walt/walt_halt.c @@ -146,13 +146,22 @@ static void migrate_tasks(struct rq *dead_rq, struct rq_flags *rf) /* Find suitable destination for @next */ dest_cpu = select_fallback_rq(dead_rq->cpu, next); - rq = __migrate_task(rq, rf, next, dest_cpu); - if (rq != dead_rq) { - rq_unlock(rq, rf); - rq = dead_rq; - *rf = orf; - rq_relock(rq, rf); + + if (cpu_of(rq) != dest_cpu) { + /* only perform a required migration */ + rq = __migrate_task(rq, rf, next, dest_cpu); + + if (rq != dead_rq) { + rq_unlock(rq, rf); + rq = dead_rq; + *rf = orf; + rq_relock(rq, rf); + } + } else { + detach_one_task_core(next, rq, &percpu_kthreads); + num_pinned_kthreads += 1; } + raw_spin_unlock(&next->pi_lock); }