[PATCH v5 10/14] sched/deadline: Add support to remove DLserver's bandwidth contribution

Joel Fernandes
2025-06-20T20:33:07Z

From: Andrea Righi <arighi@nvidia.com>

During switching from sched_ext to FAIR tasks and vice-versa, we need
support for removing the bandwidth contribution of either DL server. Add
support for the same.

Co-developed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
kernel/sched/deadline.c | 31 +++++++++++++++++++++++++++++++
kernel/sched/sched.h | 1 +
2 files changed, 32 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index c61752c2e052..50d938856b3d 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1742,6 +1742,12 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio
dl_rq_change_utilization(rq, dl_se, new_bw);
}

+ /* Clear these so that the dl_server is reinitialized */
+ if (new_bw == 0) {
+ dl_se->dl_defer = 0;
+ dl_se->dl_server = 0;
+ }
+
dl_se->dl_runtime = runtime;
dl_se->dl_deadline = period;
dl_se->dl_period = period;
@@ -1755,6 +1761,31 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio
return retval;
}

+/**
+ * dl_server_remove_params - Remove bandwidth reservation for a DL server
+ * @dl_se: The DL server entity to remove bandwidth for
+ *
+ * This function removes the bandwidth reservation for a DL server entity,
+ * cleaning up all bandwidth accounting and server state.
+ *
+ * Returns: 0 on success, negative error code on failure
+ */
+int dl_server_remove_params(struct sched_dl_entity *dl_se)
+{
+ if (!dl_se->dl_server)
+ return 0; /* Already disabled */
+
+ /*
+ * First dequeue if still queued. It should not be queued since
+ * we call this only after the last dl_server_stop().
+ */
+ if (WARN_ON_ONCE(on_dl_rq(dl_se)))
+ dequeue_dl_entity(dl_se, DEQUEUE_SLEEP);
+
+ /* Remove bandwidth reservation */
+ return dl_server_apply_params(dl_se, 0, dl_se->dl_period, false);
+}
+
/*
* Update the current task's runtime statistics (provided it is still
* a -deadline task and has not been removed from the dl_rq).
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 576b69cee6b1..13dc32a6346a 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -393,6 +393,7 @@ extern void ext_server_init(struct rq *rq);
extern void __dl_server_attach_root(struct sched_dl_entity *dl_se, struct rq *rq);
extern int dl_server_apply_params(struct sched_dl_entity *dl_se,
u64 runtime, u64 period, bool init);
+extern int dl_server_remove_params(struct sched_dl_entity *dl_se);

static inline bool dl_server_active(struct sched_dl_entity *dl_se)
{
--
2.43.0