[RFC PATCH v6 18/25] sched/rt: Update task's RT runqueue when switching scheduling class

From: Yuri Andriaccio

Date: Mon Jun 08 2026 - 08:23:46 EST


Signed-off-by: Yuri Andriaccio <yurand2000@xxxxxxxxx>
---
kernel/sched/rt.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index a32b1f68e645..fc7af6bda3f8 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1897,6 +1897,25 @@ void __init init_sched_rt_class(void)
}
}

+#ifdef CONFIG_RT_GROUP_SCHED
+static void switching_to_rt(struct rq *rq, struct task_struct *p)
+{
+ struct task_group *tg = p->sched_task_group;
+ int cpu = rq->cpu;
+
+ if (tg == &root_task_group)
+ return;
+
+ guard(raw_spinlock_irqsave)(dl_bw_lock_of_tg(tg));
+ if (!rt_group_sched_enabled())
+ tg = &root_task_group;
+
+ p->rt.rt_rq = dl_bandwidth_read(tg)->active_context->rt_rq[cpu];
+}
+#else
+static void switching_to_rt(struct rq *rq, struct task_struct *p) {}
+#endif
+
/*
* When switching a task to RT, we may overload the runqueue
* with RT tasks. In this case we try to push them off to
@@ -2095,6 +2114,7 @@ DEFINE_SCHED_CLASS(rt) = {

.get_rr_interval = get_rr_interval_rt,

+ .switching_to = switching_to_rt,
.switched_to = switched_to_rt,
.prio_changed = prio_changed_rt,

--
2.54.0