[PATCH v4 13/13] sched: Fixups to find_exec_ctx

From: John Stultz
Date: Thu Jun 01 2023 - 02:00:58 EST


find_exec_ctx() would sometimes cause the rt task pushing
to try to push tasks in the chain that ends in the rq->curr.

This caused lots of migration noise and effecively livelock
where tasks would get pushed off to other cpus, then
proxy-migrated back to the lockowner's cpu, over and over.

This kept other cpus constantly proxy-migrating away and
never actually selecting a task to run - effectively
hanging the system.

So this patch reworks some of the find_exec_ctx logic
so we stop when we hit rq->curr, and changes the logic
that was returning NULL when we came across
rq_selected(), as I'm not sure why we'd stop there.

Cc: Joel Fernandes <joelaf@xxxxxxxxxx>
Cc: Qais Yousef <qyousef@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Ben Segall <bsegall@xxxxxxxxxx>
Cc: Zimuzo Ezeozue <zezeozue@xxxxxxxxxx>
Cc: Youssef Esmat <youssefesmat@xxxxxxxxxx>
Cc: Mel Gorman <mgorman@xxxxxxx>
Cc: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
Cc: Waiman Long <longman@xxxxxxxxxx>
Cc: Boqun Feng <boqun.feng@xxxxxxxxx>
Cc: "Paul E . McKenney" <paulmck@xxxxxxxxxx>
Cc: kernel-team@xxxxxxxxxxx
Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
---
kernel/sched/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index e0e6c2feefd0..9cdabb79d450 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3881,7 +3881,15 @@ struct task_struct *find_exec_ctx(struct rq *rq, struct task_struct *p)
if (owner == exec_ctx)
break;

- if (!task_queued_on_rq(rq, owner) || task_current_selected(rq, owner)) {
+ /* If we get to current, that's the exec ctx! */
+ if (task_current(rq, owner))
+ return owner;
+
+ /*
+ * XXX This previously was checking task_current_selected()
+ * but that doesnt' make much sense to me. -jstultz
+ */
+ if (!task_queued_on_rq(rq, owner)) {
exec_ctx = NULL;
break;
}
--
2.41.0.rc0.172.g3f132b7071-goog