[PATCH] sched: Fix RT task setup failures by disabling rt_bandwidth for cgroup v2

fangqiurong posted 1 patch 4 days, 19 hours ago
There is a newer version of this series
kernel/sched/sched.h | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] sched: Fix RT task setup failures by disabling rt_bandwidth for cgroup v2
Posted by fangqiurong 4 days, 19 hours ago
When CONFIG_RT_GROUP_SCHED is enabled, RT tasks cannot be created in non-root
cgroups under cgroup v2 because rt_runtime defaults to 0, causing
sched_setscheduler() to fail with -EPERM.

The cgroup v2 design makes per-cgroup RT bandwidth control impractical,
as non-root groups have no meaningful RT runtime allocation. In this
configuration, rt_bandwidth only serves as a starvation prevention mechanism
for CFS tasks, which is no longer necessary in modern schedulers.

This fix disables rt_bandwidth checks when using cgroup v2 with
CONFIG_RT_GROUP_SCHED, allowing RT tasks to be created normally while relying
on the scheduler's inherent fairness mechanisms instead of artificial bandwidth
limitations.

Signed-off-by: fangqiurong <fangqiurong@kylinos.cn>
---
 kernel/sched/sched.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index adfb6e340..f7290b80d 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -814,6 +814,12 @@ struct scx_rq {
 
 static inline int rt_bandwidth_enabled(void)
 {
+#ifdef CONFIG_RT_GROUP_SCHED
+	/* Disable rt_bandwidth for cgroup v2 */
+	if (root_task_group.css.cgroup &&
+	    root_task_group.css.cgroup->root == &cgrp_dfl_root)
+		return 0;
+#endif
 	return sysctl_sched_rt_runtime >= 0;
 }
 
-- 
2.25.1