[PATCH] sched/rt: Remove unreachable migration-disabled push path

Shubhang Kaushik (Ampere) posted 1 patch an hour ago
kernel/sched/rt.c | 48 +++---------------------------------------------
1 file changed, 3 insertions(+), 45 deletions(-)
[PATCH] sched/rt: Remove unreachable migration-disabled push path
Posted by Shubhang Kaushik (Ampere) an hour ago
push_rt_task() selects next_task with pick_next_pushable_task().
That helper does not return migration-disabled tasks.

The relevant path is:

    push_rt_task()
      next_task = pick_next_pushable_task()
      is_migration_disabled(next_task)
      find_lock_lowest_rq(next_task)

Before the migration-disabled check, rq->lock is held, so the selected
queued task cannot run and change its migration-disabled state.

find_lock_lowest_rq() can temporarily drop rq->lock. If that happens,
it rechecks is_migration_disabled(task) after reacquiring the locks and
rejects the task if it changed state. push_rt_task() then consults
pick_next_pushable_task() again; it either exits or retries only a task
returned by that helper.

The migration-disabled branch in push_rt_task() is therefore
unreachable. Remove it along with the @pull argument, which exists only
for that branch.

This does not change the migration-disabled handling in pull_rt_task(),
which uses pick_highest_pushable_task() and retains its existing
donor-push recovery.

Signed-off-by: Shubhang Kaushik (Ampere) <sh@gentwo.org>
---
Tested on 80-core SMP, non-SMT Ampere Altra system:

  - Built and booted with CONFIG_IRQ_WORK=y.
  - Ran repeated SCHED_FIFO affinity changes among CPUs 78 and 79 with
    RT_PUSH_IPI enabled and disabled; both runs completed and cleaned
    up all worker tasks.
  - With RT_PUSH_IPI enabled, function tracing confirmed repeated
    execution of rto_push_irq_work_func() via irq_work_single().
---
 kernel/sched/rt.c | 48 +++---------------------------------------------
 1 file changed, 3 insertions(+), 45 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 85303add726df4c2da846c427aab2d627fca9589..f85edc6f896c72d2251b5eb59ee7ffd0e23934f5 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1957,7 +1957,7 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
  * running task can migrate over to a CPU that is running a task
  * of lesser priority.
  */
-static int push_rt_task(struct rq *rq, bool pull)
+static int push_rt_task(struct rq *rq)
 {
 	struct task_struct *next_task;
 	struct rq *lowest_rq;
@@ -1981,48 +1981,6 @@ static int push_rt_task(struct rq *rq, bool pull)
 		return 0;
 	}
 
-	if (is_migration_disabled(next_task)) {
-		struct task_struct *push_task = NULL;
-		int cpu;
-
-		if (!pull || rq->push_busy)
-			return 0;
-
-		/*
-		 * Invoking find_lowest_rq() on anything but an RT task doesn't
-		 * make sense. Per the above priority check, curr has to
-		 * be of higher priority than next_task, so no need to
-		 * reschedule when bailing out.
-		 *
-		 * Note that the stoppers are masqueraded as SCHED_FIFO
-		 * (cf. sched_set_stop_task()), so we can't rely on rt_task().
-		 */
-		if (rq->donor->sched_class != &rt_sched_class)
-			return 0;
-
-		cpu = find_lowest_rq(rq->curr);
-		if (cpu == -1 || cpu == rq->cpu)
-			return 0;
-
-		/*
-		 * Given we found a CPU with lower priority than @next_task,
-		 * therefore it should be running. However we cannot migrate it
-		 * to this other CPU, instead attempt to push the current
-		 * running task on this CPU away.
-		 */
-		push_task = get_push_task(rq);
-		if (push_task) {
-			preempt_disable();
-			raw_spin_rq_unlock(rq);
-			stop_one_cpu_nowait(rq->cpu, push_cpu_stop,
-					    push_task, &rq->push_work);
-			preempt_enable();
-			raw_spin_rq_lock(rq);
-		}
-
-		return 0;
-	}
-
 	if (WARN_ON(next_task == rq->curr))
 		return 0;
 
@@ -2078,7 +2036,7 @@ static int push_rt_task(struct rq *rq, bool pull)
 static void push_rt_tasks(struct rq *rq)
 {
 	/* push_rt_task will return true if it moved an RT */
-	while (push_rt_task(rq, false))
+	while (push_rt_task(rq))
 		;
 }
 
@@ -2236,7 +2194,7 @@ void rto_push_irq_work_func(struct irq_work *work)
 	 */
 	if (has_pushable_tasks(rq)) {
 		raw_spin_rq_lock(rq);
-		while (push_rt_task(rq, true))
+		while (push_rt_task(rq))
 			;
 		raw_spin_rq_unlock(rq);
 	}

---
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
change-id: 20261014-sched-rt-dead-md-push-c88b47c3e2f0

Best regards,
-- 
Shubhang Kaushik (Ampere) <sh@gentwo.org>