mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] sched/rt: Restore the PUSH_IPI fallback for migration disabled next_task
@ 2026-11-23 19:21 Josh Lafleur via B4 Relay
  2026-11-23 19:21 ` [PATCH 1/2] sched/rt: Allow queued stopper targets past the pushable-head check Josh Lafleur via B4 Relay
  2026-11-23 19:21 ` [PATCH 2/2] sched/rt: Restore pinned candidates for PUSH_IPI balancing Josh Lafleur via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Josh Lafleur via B4 Relay @ 2026-11-23 19:21 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Gauri Patwardhan, Phil Auld,
	Harshit Agarwal, Jon Kohler, Seiji Nishikawa
  Cc: Rahul Chunduru, linux-kernel, Josh Lafleur (Zipline)

A migrate-disabled RT task will remain on the pushable list though fail
migration.

The PUSH_IPI path originally used the non-migrateable condition to
request a stopper push of the running task, allowing the pinned task to
run. The head check added by 690e47d1403e can reject the stopper target
after the source rq lock is dropped; dae5c0292080 then prevented the
PUSH_IPI path from selecting the pinned candidate at all to reduce stopper
handler load, however this is still at the cost of increased rt latency
when there are other available cores which may run both the current and
next tasks of a rq.

Patch 1 allows a queued stopper target through the head recheck while
retaining the ordinary push validation.

Patch 2 selects pinned candidates only for the PUSH_IPI path. Ordinary
pushes continue to skip them and can reach movable tasks behind them.
One caveat with this change which would be good to address is that it
(seems?) feasible for a Task A running on core N with task B queued
behind it and of lower priority to attempt pushing task A onto a cpu
running task C (prioritized in-between the A,B) which would be roughly
a short windowed priority inversion of task C. I have posited a third
change to precheck the push_rt_task() codepath which would ensure the
next_task is of higher priority than the remote rq->curr, however this
is up for discussion. I can see how we would want to avoid cascaded
load-balancing sequences even after the recent improvements to the IPI
balancer, but this problem should technically still exist because the
remote rq can concurrently re-shuffle during the push->handler
sequence.

I was able to reproduce the failing migration with a set of 4 tasks
which are runnable on 3 cores in addition to 1 per-cpu high frequency
periodic. The periodic runs at multiple kHz to stress a higher->lower
priority transition to kick off cross core IPI balancing. The A, B,
high priority, and busy worker are all ~wake aligned operating at 50Hz
(arbitrary number for this test case). The A and B tasks content on an
rt mutex in a non-migrateable section for 10% of its runtime whereas
the other 90% is spent running busy work. The A, B, and Busy tasks
have 5ms of work to complete whereas the high priority task has 1ms.
The periodic runs at 4kHz and does ~25us of work.

The intended sequence is that the A, B, and High priority tasks start
~algined on cpu such that one of the victim tasks goes non-preemptible
and blocks on the acquired mutex. This then allows the busy worker to
step on cpu for its 5ms runtime. In ~1% of runtimes, we would see the
worst case completion time of the victim be over 10ms with high IPI
interrupt rates due to failed migration. After this changeset, we
reduced rt completion latency by ~40% due it no longer being stuck in
the runqueue, in addition to the reduced IPI rates.

Note: Codex assisted in the creation of a test module and for
post-processing ftrace/test application data.

The original testing was conducted on a PREEMPT_RT LTS without
dae5c0292080. The fixed scheduler saw a reduction of 10/1200 missed
deadlines to 0/1200 missed deadlines. It also saw a reduction in the
max IPI per period going from 190->64. Following this testing, we
applied dae5c0292080 and saw roughly the same deadline misses (15
total), though roughly comparable improvements to IPI hard irq rates.
Max completion times for A, B were still over 10ms with just the
dae5c0292080 patch applied. This is expected as that change didn't
intend to resolve the balancing storms, only mitigate the failed
handler load.

Completion Time Analysis

 Worker           Unfixed mean ± SD     Fixed mean ± SD    Maximum, unfixed → fixed
━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━━━━━━━━━
 A                 5.088 ± 0.264 ms    5.937 ± 0.303 ms           10.546 → 6.065 ms
───────────────  ───────────────────  ──────────────────  ──────────────────────────
 B                 5.982 ± 0.485 ms    5.096 ± 0.179 ms           10.549 → 6.069 ms
───────────────  ───────────────────  ──────────────────  ──────────────────────────
 High priority     1.037 ± 0.021 ms    1.036 ± 0.002 ms            1.541 → 1.064 ms
───────────────  ───────────────────  ──────────────────  ──────────────────────────
 Busy              5.133 ± 0.293 ms    5.130 ± 0.289 ms            6.057 → 6.056 ms

I did note that per test run, results seem quasi dependent on the way tasks
tend to land on cpus in the first scheduler run which is why I believe
the A and B workers are non-deterministically the victim though we can
see the worst case completion time significantly improve across the tests.

I believe this is also similar to discussions in [1,2] (among many others
when going through the lore) though I believe it addresses the root cause
of the failed migration storms leading to increased RT latency.

Note: The seperate items relating to the DL scheduler in related issues
and the original changes is out of scope of this change-set.

[1] https://lore.kernel.org/all/20261113160655.2909479-1-mgorman@techsingularity.net/
[2] https://lore.kernel.org/all/178833372384.3717435.9283330313829938009.tip-bot2@tip-bot2/

Signed-off-by: Josh Lafleur (Zipline) <josh.lafleur@outlook.com>
---
Josh Lafleur (Zipline) (2):
      sched/rt: Allow queued stopper targets past the pushable-head check
      sched/rt: Restore pinned candidates for PUSH_IPI balancing

 kernel/sched/rt.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261123-migrate-on-ipi-510b41db851a

Best regards,
--  
Josh Lafleur (Zipline) <josh.lafleur@outlook.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] sched/rt: Allow queued stopper targets past the pushable-head check
  2026-11-23 19:21 [PATCH 0/2] sched/rt: Restore the PUSH_IPI fallback for migration disabled next_task Josh Lafleur via B4 Relay
@ 2026-11-23 19:21 ` Josh Lafleur via B4 Relay
  2026-11-23 19:21 ` [PATCH 2/2] sched/rt: Restore pinned candidates for PUSH_IPI balancing Josh Lafleur via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Josh Lafleur via B4 Relay @ 2026-11-23 19:21 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Gauri Patwardhan, Phil Auld,
	Harshit Agarwal, Jon Kohler, Seiji Nishikawa
  Cc: Rahul Chunduru, linux-kernel, Josh Lafleur (Zipline)

From: "Josh Lafleur (Zipline)" <josh.lafleur@outlook.com>

Commit a7c81556ec4d ("sched: Fix migrate_disable() vs rt/dl
balancing") added a stopper push when RT balancing cannot push a
migrate-disabled task which moves the running task so the pinned
task can run locally. The PUSH_IPI path can request the same fallback
when it selects a pinned push candidate.

Commit 690e47d1403e ("sched/rt: Fix race in push_rt_task") added a
pushable-head check after find_lock_lowest_rq() drops and reacquires
the source rq lock. That check protects ordinary pushes, but can
reject a queued stopper target when another task remains ahead of it
in the pushable list. The stopper then gives up without moving the
task. Since we know in the stopper push case the rq is actively
owning the last running task and the rq is push_busy, we can be
confident that it will not be migrated between the push_rt_task()
and subsequent stopper handler.

Allow a queued stopper target that is still on the source rq to pass
the head comparison. Keep the migration-disable and affinity checks,
and retain the head comparison for ordinary pushes. This also makes
the PUSH_IPI fallback usable when pinned candidates are selected by
the following patch.

Fixes: 690e47d1403e ("sched/rt: Fix race in push_rt_task")
---
 kernel/sched/rt.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 1535046a23ffa..54a6533cffe07 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1923,19 +1923,26 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
 
 		/* if the prio of this runqueue changed, try again */
 		if (double_lock_balance(rq, lowest_rq)) {
+			bool stopper_push = rq->push_busy &&
+					    (rq->curr == rq->stop) &&
+					    (task_rq(task) == rq) &&
+					    task_on_rq_queued(task);
+
 			/*
 			 * We had to unlock the run queue. In
 			 * the mean time, task could have
 			 * migrated already or had its affinity changed,
 			 * therefore check if the task is still at the
-			 * head of the pushable tasks list.
+			 * head of the pushable tasks list. A queued stopper
+			 * target need not be at the head of that list.
 			 * It is possible the task was scheduled, set
 			 * "migrate_disabled" and then got preempted, so we must
 			 * check the task migration disable flag here too.
 			 */
 			if (unlikely(is_migration_disabled(task) ||
 				     !cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) ||
-				     task != pick_next_pushable_task(rq))) {
+				     (task != pick_next_pushable_task(rq) &&
+				      !stopper_push))) {
 
 				double_unlock_balance(rq, lowest_rq);
 				lowest_rq = NULL;

-- 
2.53.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] sched/rt: Restore pinned candidates for PUSH_IPI balancing
  2026-11-23 19:21 [PATCH 0/2] sched/rt: Restore the PUSH_IPI fallback for migration disabled next_task Josh Lafleur via B4 Relay
  2026-11-23 19:21 ` [PATCH 1/2] sched/rt: Allow queued stopper targets past the pushable-head check Josh Lafleur via B4 Relay
@ 2026-11-23 19:21 ` Josh Lafleur via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Josh Lafleur via B4 Relay @ 2026-11-23 19:21 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Gauri Patwardhan, Phil Auld,
	Harshit Agarwal, Jon Kohler, Seiji Nishikawa
  Cc: Rahul Chunduru, linux-kernel, Josh Lafleur (Zipline)

From: "Josh Lafleur (Zipline)" <josh.lafleur@outlook.com>

Commit a7c81556ec4d ("sched: Fix migrate_disable() vs rt/dl
balancing") added a PUSH_IPI fallback for a migrate-disabled RT
candidate. It runs the stopper to move the running task so that the
pinned task can run on its current CPU.

Commit dae5c0292080 ("sched/rt,dl: Skip migrate-disabled tasks when
picking a push candidate") made the RT picker skip pinned candidates.
This avoids futile ordinary pushes, but also prevents the push-IPI
path from reaching that fallback.

Select migrate-disabled candidates on the PUSH_IPI path, while
continuing to skip them on ordinary pushes. An ordinary push can
therefore still reach a movable task behind a pinned one. Use the
same selection mode when retrying after a failed destination search;
the head recheck for ordinary candidates continues to skip pinned
tasks.

The preceding patch allows the stopper target to pass the head
recheck after the source rq lock is reacquired.

Fixes: dae5c0292080 ("sched/rt,dl: Skip migrate-disabled tasks when picking a push candidate")
---
 kernel/sched/rt.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 54a6533cffe07..bb0d125889bd1 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1866,7 +1866,7 @@ static int find_lowest_rq(struct task_struct *task)
 	return -1;
 }
 
-static struct task_struct *pick_next_pushable_task(struct rq *rq)
+static struct task_struct *pick_next_pushable_task(struct rq *rq, bool pull)
 {
 	struct plist_head *head = &rq->rt.pushable_tasks;
 	struct task_struct *i, *p = NULL;
@@ -1875,8 +1875,9 @@ static struct task_struct *pick_next_pushable_task(struct rq *rq)
 		return NULL;
 
 	plist_for_each_entry(i, head, pushable_tasks) {
-		/* skip tasks that cannot be migrated */
-		if (!task_on_cpu(rq, i) && !is_migration_disabled(i)) {
+		/* Only the push-IPI path can push the current task instead. */
+		if (!task_on_cpu(rq, i) &&
+		    (pull || !is_migration_disabled(i))) {
 			p = i;
 			break;
 		}
@@ -1941,7 +1942,7 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
 			 */
 			if (unlikely(is_migration_disabled(task) ||
 				     !cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) ||
-				     (task != pick_next_pushable_task(rq) &&
+				     (task != pick_next_pushable_task(rq, false) &&
 				      !stopper_push))) {
 
 				double_unlock_balance(rq, lowest_rq);
@@ -1976,7 +1977,7 @@ static int push_rt_task(struct rq *rq, bool pull)
 	if (!rq->rt.overloaded)
 		return 0;
 
-	next_task = pick_next_pushable_task(rq);
+	next_task = pick_next_pushable_task(rq, pull);
 	if (!next_task)
 		return 0;
 
@@ -2051,7 +2052,7 @@ static int push_rt_task(struct rq *rq, bool pull)
 		 * run-queue and is also still the next task eligible for
 		 * pushing.
 		 */
-		task = pick_next_pushable_task(rq);
+		task = pick_next_pushable_task(rq, pull);
 		if (task == next_task) {
 			/*
 			 * The task hasn't migrated, and is still the next

-- 
2.53.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-23 19:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 19:21 [PATCH 0/2] sched/rt: Restore the PUSH_IPI fallback for migration disabled next_task Josh Lafleur via B4 Relay
2026-11-23 19:21 ` [PATCH 1/2] sched/rt: Allow queued stopper targets past the pushable-head check Josh Lafleur via B4 Relay
2026-11-23 19:21 ` [PATCH 2/2] sched/rt: Restore pinned candidates for PUSH_IPI balancing Josh Lafleur via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®