[RFC PATCH v5 10/29] sched/deadline: Add dl_init_tg

Yuri Andriaccio
2026-04-30T21:38:58Z

From: luca abeni <luca.abeni@santannapisa.it>

Add dl_init_tg to initialize and/or update a rt-cgroup dl_server and to
also account the allocated bandwidth. This function is currently unhooked
and will be later used to allocate bandwidth to rt-cgroups.

Add lock guard for raw_spin_rq_lock_irq for cleaner code.

Co-developed-by: Alessio Balsini <a.balsini@sssup.it>
Signed-off-by: Alessio Balsini <a.balsini@sssup.it>
Co-developed-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
Co-developed-by: Yuri Andriaccio <yurand2000@gmail.com>
Signed-off-by: Yuri Andriaccio <yurand2000@gmail.com>
Signed-off-by: luca abeni <luca.abeni@santannapisa.it>
---
kernel/sched/deadline.c | 31 +++++++++++++++++++++++++++++++
kernel/sched/sched.h | 5 +++++
2 files changed, 36 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 7c039d5f3c5d..5532ca4ad969 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -332,6 +332,37 @@ void cancel_inactive_timer(struct sched_dl_entity *dl_se)
cancel_dl_timer(dl_se, &dl_se->inactive_timer);
}

+#ifdef CONFIG_RT_GROUP_SCHED
+void dl_init_tg(struct sched_dl_entity *dl_se, u64 rt_runtime, u64 rt_period)
+{
+ struct rq *rq = container_of_const(dl_se->dl_rq, struct rq, dl);
+ int is_active;
+ u64 new_bw;
+
+ guard(raw_spin_rq_lock_irq)(rq);
+ is_active = dl_se->my_q->rt.rt_nr_running > 0;
+
+ update_rq_clock(rq);
+ dl_server_stop(dl_se);
+
+ new_bw = to_ratio(rt_period, rt_runtime);
+ dl_rq_change_utilization(rq, dl_se, new_bw);
+
+ dl_se->dl_runtime = rt_runtime;
+ dl_se->dl_deadline = rt_period;
+ dl_se->dl_period = rt_period;
+
+ dl_se->runtime = 0;
+ dl_se->deadline = 0;
+
+ dl_se->dl_bw = new_bw;
+ dl_se->dl_density = new_bw;
+
+ if (is_active)
+ dl_server_start(dl_se);
+}
+#endif
+
static void dl_change_utilization(struct task_struct *p, u64 new_bw)
{
WARN_ON_ONCE(p->dl.flags & SCHED_FLAG_SUGOV);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index e7e263d3cddb..ca69d2132061 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -423,6 +423,7 @@ extern void dl_server_init(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq,
struct rq *served_rq,
dl_server_pick_f pick_task);
extern void sched_init_dl_servers(void);
+extern void dl_init_tg(struct sched_dl_entity *dl_se, u64 rt_runtime, u64 rt_period);

extern void fair_server_init(struct rq *rq);
extern void ext_server_init(struct rq *rq);
@@ -2023,6 +2024,10 @@ static inline struct rq *_this_rq_lock_irq(struct rq_flags *rf) __acquires_ret
return rq;
}

+DEFINE_LOCK_GUARD_1(raw_spin_rq_lock_irq, struct rq,
+ raw_spin_rq_lock_irq(_T->lock),
+ raw_spin_rq_unlock_irq(_T->lock))
+
#ifdef CONFIG_NUMA

enum numa_topology_type {
--
2.53.0