[PATCH] sched/rt: Push RT tasks when preempted by a deadline task

From: yangsonghua

Date: Tue Jun 23 2026 - 23:05:03 EST


Commit 704069649b5b ("sched/core: Rework sched_class::wakeup_preempt()
and rq_modified_*()") made wakeup_preempt_rt() callable for cross-class
wakeups, leaving a "XXX If we're preempted by DL, queue a push?" comment
with no implementation.

When a SCHED_DEADLINE task preempts a running SCHED_FIFO/SCHED_RR task,
the RT class's put_prev_task_rt() is the natural place to trigger a push:
at that point the preempted task is (conditionally) added to
pushable_tasks, and we have 'next' available to identify the reason for
preemption.

The earlier wakeup_preempt_rt() call site is too early: the running RT
task has not yet been added to pushable_tasks, so rt_queue_push_tasks()
would be a no-op for the common single-RT-task-per-CPU case.

Fix this by adding a dl_task(next) check in put_prev_task_rt(). This is
intentionally placed outside and after the enqueue_pushable_task()
condition, so that a push is triggered even when the preempted RT task is
pinned (nr_cpus_allowed == 1) or blocked (proxy-exec): in those cases
there may be other migratable RT tasks already sitting in pushable_tasks.

The task_is_blocked() early-return is folded into the
enqueue_pushable_task() condition to avoid inadvertently suppressing the
new push logic.

Note: this does not cover the DL-server case where a fair-class task
running under DL bandwidth budget displaces an RT task; that is a
separate concern.

Signed-off-by: yangsonghua <yangsonghua@xxxxxxxxxxx>
---
kernel/sched/rt.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index e474c31d8fe6..299ce6c9699c 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1627,7 +1627,8 @@ static void wakeup_preempt_rt(struct rq *rq, struct task_struct *p, int flags)
struct task_struct *donor = rq->donor;

/*
- * XXX If we're preempted by DL, queue a push?
+ * If we're preempted by a higher-priority class (e.g. deadline),
+ * nothing to do here for the RT class itself.
*/
if (p->sched_class != &rt_sched_class)
return;
@@ -1736,14 +1737,24 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p, struct task_s

update_rt_rq_load_avg(rq_clock_pelt(rq), rq, 1);

- if (task_is_blocked(p))
- return;
/*
* The previous task needs to be made eligible for pushing
- * if it is still active
+ * if it is still active and migratable.
*/
- if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
+ if (!task_is_blocked(p) && on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
enqueue_pushable_task(rq, p);
+
+ /*
+ * When a deadline task takes over this CPU, try to push any queued
+ * RT tasks to CPUs running lower-priority work. This is independent
+ * of whether p itself is pushable: even if p is pinned or blocked,
+ * there may be other migratable RT tasks already in pushable_tasks.
+ *
+ * rt_queue_push_tasks() guards on has_pushable_tasks() internally,
+ * so this is a no-op if nothing is queued.
+ */
+ if (dl_task(next))
+ rt_queue_push_tasks(rq);
}

/* Only try algorithms three times */
--
2.34.1