Skip to contentSkip to conversation

sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups

PATCH Applied Michal Koutný 2 participants 7 messages Mar 23 – Apr 8 Scheduler

lore
Share & tools
lore
#0 lore raw

v3 cover sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups

The crux is the first commit which fixes how sysctl kernel.sched_rt_runtime_us changes are validated with CONFIG_RT_GROUP_SCHED but rt_group_sched=0. The rest are cleanups that occurred to me.

---
Changes in v3:
- More details to patch's 1/3 message
- Rebased on current torvalds/master
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Prateek's ifdef/locks suggestion
- Rebased on current torvalds/master
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Michal Koutný (3):
sched/rt: Skip group schedulable check with rt_group_sched=0 sched/rt: Move group schedulability check to sched_rt_global_validate() sched/rt: Cleanup global RT bandwidth functions

 kernel/sched/rt.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)

---
base-commit: c369299895a591d96745d6492d4888259b004a9e
change-id: 20260119-sched-rert_groups-431e2d5d1c57

Best regards,

Signature · 1 line
Michal Koutný <[email protected]>
#1 lore raw

PATCH v3 1/3 sched/rt: Skip group schedulable check with rt_group_sched=0

The warning from the commit 87f1fb77d87a6 ("sched: Add RT_GROUP WARN checks for non-root task_groups") is wrong -- it assumes that only task_groups with rt_rq are traversed, however, the schedulability check would iterate all task_groups even when rt_group_sched=0 is disabled at boot time but some non-root task_groups exist.

The schedulability check is supposed to validate:
a) that children don't overcommit its parent,
b) no RT task group overcommits global RT limit.
but with rt_group_sched=0 there is no (non-trivial) hierarchy of RT groups, therefore skip the validation altogether. Otherwise, writes to the global sched_rt_runtime_us knob will be rejected with incorrect validation error.

This fix is immaterial with CONFIG_RT_GROUP_SCHED=n.

Fixes 87f1fb77d87a6 ("sched: Add RT_GROUP WARN checks for non-root task_groups")
---
 kernel/sched/rt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/rt.c +2 -3
index f69e1f16d9238..37e6ce3604fd7 100644
@@ -2676,9 +2676,6 @@ static int tg_rt_schedulable(struct task_group *tg, void *data)
 	    tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg))
 		return -EBUSY;
 
-	if (WARN_ON(!rt_group_sched_enabled() && tg != &root_task_group))
-		return -EBUSY;
-
 	total = to_ratio(period, runtime);
 
 	/*
@@ -2822,6 +2819,8 @@ long sched_group_rt_period(struct task_group *tg)
 static int sched_rt_global_constraints(void)
 {
 	int ret = 0;
+	if (!rt_group_sched_enabled())
+		return ret;
 
 	mutex_lock(&rt_constraints_mutex);
 	ret = __rt_schedulable(NULL, 0, 0);
Signature · 1 line
2.53.0
merge bot Applied
#2 lore raw

[tip: sched/core] sched/rt: Skip group schedulable check with rt_group_sched=0

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     8b016dcec9365675be81d26be88f2c09cf983bd4
Gitweb:        https://git.kernel.org/tip/8b016dcec9365675be81d26be88f2c09cf983bd4
Author:        Michal Koutný <[email protected]>
AuthorDate:    Mon, 23 Mar 2026 13:39:37 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 08 Apr 2026 13:11:44 +02:00

sched/rt: Skip group schedulable check with rt_group_sched=0

The warning from the commit 87f1fb77d87a6 ("sched: Add RT_GROUP WARN checks for non-root task_groups") is wrong -- it assumes that only task_groups with rt_rq are traversed, however, the schedulability check would iterate all task_groups even when rt_group_sched=0 is disabled at boot time but some non-root task_groups exist.

The schedulability check is supposed to validate:
a) that children don't overcommit its parent,
b) no RT task group overcommits global RT limit.
but with rt_group_sched=0 there is no (non-trivial) hierarchy of RT groups, therefore skip the validation altogether. Otherwise, writes to the global sched_rt_runtime_us knob will be rejected with incorrect validation error.

This fix is immaterial with CONFIG_RT_GROUP_SCHED=n.

Fixes 87f1fb77d87a6 ("sched: Add RT_GROUP WARN checks for non-root task_groups")
---
 kernel/sched/rt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/rt.c +2 -3
index a48e867..893e54d 100644
@@ -2690,9 +2690,6 @@ static int tg_rt_schedulable(struct task_group *tg, void *data)
 	    tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg))
 		return -EBUSY;
 
-	if (WARN_ON(!rt_group_sched_enabled() && tg != &root_task_group))
-		return -EBUSY;
-
 	total = to_ratio(period, runtime);
 
 	/*
@@ -2836,6 +2833,8 @@ long sched_group_rt_period(struct task_group *tg)
 static int sched_rt_global_constraints(void)
 {
 	int ret = 0;
+	if (!rt_group_sched_enabled())
+		return ret;
 
 	mutex_lock(&rt_constraints_mutex);
 	ret = __rt_schedulable(NULL, 0, 0);
#3 lore raw

PATCH v3 2/3 sched/rt: Move group schedulability check to sched_rt_global_validate()

In reply to Michal Koutný

The sched_rt_global_constraints() function is a remnant that used to set up global RT throttling but that is no more since commit 5f6bd380c7bdb ("sched/rt: Remove default bandwidth control") and the function ended up only doing schedulability check.
Move the check into the validation function where it fits better. (The order of validations sched_dl_global_validate() and sched_rt_global_validate() shouldn't matter.)

---
 kernel/sched/rt.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
kernel/sched/rt.c +8 -9
index 37e6ce3604fd7..d3b6483fc3e7a 100644
@@ -2818,15 +2818,7 @@ long sched_group_rt_period(struct task_group *tg)
 #ifdef CONFIG_SYSCTL
 static int sched_rt_global_constraints(void)
 {
-	int ret = 0;
-	if (!rt_group_sched_enabled())
-		return ret;
-
-	mutex_lock(&rt_constraints_mutex);
-	ret = __rt_schedulable(NULL, 0, 0);
-	mutex_unlock(&rt_constraints_mutex);
-
-	return ret;
+	return 0;
 }
 #endif /* CONFIG_SYSCTL */
 
@@ -2858,6 +2850,13 @@ static int sched_rt_global_validate(void)
 			NSEC_PER_USEC > max_rt_runtime)))
 		return -EINVAL;
 
+#ifdef CONFIG_RT_GROUP_SCHED
+	if (!rt_group_sched_enabled())
+		return 0;
+
+	scoped_guard(mutex, &rt_constraints_mutex)
+		return __rt_schedulable(NULL, 0, 0);
+#endif
 	return 0;
 }
 
Signature · 1 line
2.53.0
merge bot Applied
#4 lore raw

[tip: sched/core] sched/rt: Move group schedulability check to sched_rt_global_validate()

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     4f70a0456d090303d5a6c915dd7d9db9da56cb16
Gitweb:        https://git.kernel.org/tip/4f70a0456d090303d5a6c915dd7d9db9da56cb16
Author:        Michal Koutný <[email protected]>
AuthorDate:    Mon, 23 Mar 2026 13:39:38 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 08 Apr 2026 13:11:44 +02:00

sched/rt: Move group schedulability check to sched_rt_global_validate()

The sched_rt_global_constraints() function is a remnant that used to set up global RT throttling but that is no more since commit 5f6bd380c7bdb ("sched/rt: Remove default bandwidth control") and the function ended up only doing schedulability check.
Move the check into the validation function where it fits better. (The order of validations sched_dl_global_validate() and sched_rt_global_validate() shouldn't matter.)

---
 kernel/sched/rt.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
kernel/sched/rt.c +8 -9
index 893e54d..e16d8f1 100644
@@ -2832,15 +2832,7 @@ long sched_group_rt_period(struct task_group *tg)
 #ifdef CONFIG_SYSCTL
 static int sched_rt_global_constraints(void)
 {
-	int ret = 0;
-	if (!rt_group_sched_enabled())
-		return ret;
-
-	mutex_lock(&rt_constraints_mutex);
-	ret = __rt_schedulable(NULL, 0, 0);
-	mutex_unlock(&rt_constraints_mutex);
-
-	return ret;
+	return 0;
 }
 #endif /* CONFIG_SYSCTL */
 
@@ -2872,6 +2864,13 @@ static int sched_rt_global_validate(void)
 			NSEC_PER_USEC > max_rt_runtime)))
 		return -EINVAL;
 
+#ifdef CONFIG_RT_GROUP_SCHED
+	if (!rt_group_sched_enabled())
+		return 0;
+
+	scoped_guard(mutex, &rt_constraints_mutex)
+		return __rt_schedulable(NULL, 0, 0);
+#endif
 	return 0;
 }
 
#5 lore raw

PATCH v3 3/3 sched/rt: Cleanup global RT bandwidth functions

In reply to Michal Koutný

The commit 5f6bd380c7bdb ("sched/rt: Remove default bandwidth control") and followup changes made a few of the functions unnecessary, drop them for simplicity.

---
 kernel/sched/rt.c | 24 ------------------------
 1 file changed, 24 deletions(-)
kernel/sched/rt.c +0 -24
index d3b6483fc3e7a..87ed7268fd547 100644
@@ -2815,13 +2815,6 @@ long sched_group_rt_period(struct task_group *tg)
 	return rt_period_us;
 }
 
-#ifdef CONFIG_SYSCTL
-static int sched_rt_global_constraints(void)
-{
-	return 0;
-}
-#endif /* CONFIG_SYSCTL */
-
 int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk)
 {
 	/* Don't accept real-time tasks when there is no way for them to run */
@@ -2831,14 +2824,6 @@ int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk)
 	return 1;
 }
 
-#else /* !CONFIG_RT_GROUP_SCHED: */
-
-#ifdef CONFIG_SYSCTL
-static int sched_rt_global_constraints(void)
-{
-	return 0;
-}
-#endif /* CONFIG_SYSCTL */
 #endif /* !CONFIG_RT_GROUP_SCHED */
 
 #ifdef CONFIG_SYSCTL
@@ -2860,10 +2845,6 @@ static int sched_rt_global_validate(void)
 	return 0;
 }
 
-static void sched_rt_do_global(void)
-{
-}
-
 static int sched_rt_handler(const struct ctl_table *table, int write, void *buffer,
 		size_t *lenp, loff_t *ppos)
 {
@@ -2887,11 +2868,6 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buff
 		if (ret)
 			goto undo;
 
-		ret = sched_rt_global_constraints();
-		if (ret)
-			goto undo;
-
-		sched_rt_do_global();
 		sched_dl_do_global();
 	}
 	if (0) {
Signature · 1 line
2.53.0
merge bot Applied
#6 lore raw

[tip: sched/core] sched/rt: Cleanup global RT bandwidth functions

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     985215804dcbf02ab675977e770708e3f084e9fc
Gitweb:        https://git.kernel.org/tip/985215804dcbf02ab675977e770708e3f084e9fc
Author:        Michal Koutný <[email protected]>
AuthorDate:    Mon, 23 Mar 2026 13:39:39 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 08 Apr 2026 13:11:44 +02:00

sched/rt: Cleanup global RT bandwidth functions

The commit 5f6bd380c7bdb ("sched/rt: Remove default bandwidth control") and followup changes made a few of the functions unnecessary, drop them for simplicity.

---
 kernel/sched/rt.c | 24 ------------------------
 1 file changed, 24 deletions(-)
kernel/sched/rt.c +0 -24
index e16d8f1..4ee8faf 100644
@@ -2829,13 +2829,6 @@ long sched_group_rt_period(struct task_group *tg)
 	return rt_period_us;
 }
 
-#ifdef CONFIG_SYSCTL
-static int sched_rt_global_constraints(void)
-{
-	return 0;
-}
-#endif /* CONFIG_SYSCTL */
-
 int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk)
 {
 	/* Don't accept real-time tasks when there is no way for them to run */
@@ -2845,14 +2838,6 @@ int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk)
 	return 1;
 }
 
-#else /* !CONFIG_RT_GROUP_SCHED: */
-
-#ifdef CONFIG_SYSCTL
-static int sched_rt_global_constraints(void)
-{
-	return 0;
-}
-#endif /* CONFIG_SYSCTL */
 #endif /* !CONFIG_RT_GROUP_SCHED */
 
 #ifdef CONFIG_SYSCTL
@@ -2874,10 +2859,6 @@ static int sched_rt_global_validate(void)
 	return 0;
 }
 
-static void sched_rt_do_global(void)
-{
-}
-
 static int sched_rt_handler(const struct ctl_table *table, int write, void *buffer,
 		size_t *lenp, loff_t *ppos)
 {
@@ -2901,11 +2882,6 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buff
 		if (ret)
 			goto undo;
 
-		ret = sched_rt_global_constraints();
-		if (ret)
-			goto undo;
-
-		sched_rt_do_global();
 		sched_dl_do_global();
 	}
 	if (0) {