mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/3] sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups
@ 2026-03-23 12:39 Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 1/3] sched/rt: Skip group schedulable check with rt_group_sched=0 Michal Koutný
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Michal Koutný @ 2026-03-23 12:39 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: linux-kernel, K Prateek Nayak, Michal Koutný

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.

Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
Changes in v3:
- More details to patch's 1/3 message
- Rebased on current torvalds/master
- Link to v2: https://lore.kernel.org/r/20260217-sched-rert_groups-v2-0-5cf969b60032@suse.com

Changes in v2:
- Prateek's ifdef/locks suggestion
- Rebased on current torvalds/master
- Link to v1: https://lore.kernel.org/r/20260119-sched-rert_groups-v1-0-80c1e5269910@suse.com

---
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,
-- 
Michal Koutný <mkoutny@suse.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/3] sched/rt: Skip group schedulable check with rt_group_sched=0
  2026-03-23 12:39 [PATCH v3 0/3] sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups Michal Koutný
@ 2026-03-23 12:39 ` Michal Koutný
  2026-04-08 11:20   ` [tip: sched/core] " tip-bot2 for Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 2/3] sched/rt: Move group schedulability check to sched_rt_global_validate() Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 3/3] sched/rt: Cleanup global RT bandwidth functions Michal Koutný
  2 siblings, 1 reply; 7+ messages in thread
From: Michal Koutný @ 2026-03-23 12:39 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: linux-kernel, K Prateek Nayak, Michal Koutný

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")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 kernel/sched/rt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index f69e1f16d9238..37e6ce3604fd7 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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);

-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 2/3] sched/rt: Move group schedulability check to sched_rt_global_validate()
  2026-03-23 12:39 [PATCH v3 0/3] sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 1/3] sched/rt: Skip group schedulable check with rt_group_sched=0 Michal Koutný
@ 2026-03-23 12:39 ` Michal Koutný
  2026-04-08 11:20   ` [tip: sched/core] " tip-bot2 for Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 3/3] sched/rt: Cleanup global RT bandwidth functions Michal Koutný
  2 siblings, 1 reply; 7+ messages in thread
From: Michal Koutný @ 2026-03-23 12:39 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: linux-kernel, K Prateek Nayak, 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.)

Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 kernel/sched/rt.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 37e6ce3604fd7..d3b6483fc3e7a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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;
 }
 

-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 3/3] sched/rt: Cleanup global RT bandwidth functions
  2026-03-23 12:39 [PATCH v3 0/3] sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 1/3] sched/rt: Skip group schedulable check with rt_group_sched=0 Michal Koutný
  2026-03-23 12:39 ` [PATCH v3 2/3] sched/rt: Move group schedulability check to sched_rt_global_validate() Michal Koutný
@ 2026-03-23 12:39 ` Michal Koutný
  2026-04-08 11:20   ` [tip: sched/core] " tip-bot2 for Michal Koutný
  2 siblings, 1 reply; 7+ messages in thread
From: Michal Koutný @ 2026-03-23 12:39 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: linux-kernel, K Prateek Nayak, 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.

Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 kernel/sched/rt.c | 24 ------------------------
 1 file changed, 24 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index d3b6483fc3e7a..87ed7268fd547 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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) {

-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: sched/core] sched/rt: Cleanup global RT bandwidth functions
  2026-03-23 12:39 ` [PATCH v3 3/3] sched/rt: Cleanup global RT bandwidth functions Michal Koutný
@ 2026-04-08 11:20   ` tip-bot2 for Michal Koutný
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Michal Koutný @ 2026-04-08 11:20 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: mkoutny, Peter Zijlstra (Intel), x86, linux-kernel

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ý <mkoutny@suse.com>
AuthorDate:    Mon, 23 Mar 2026 13:39:39 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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.

Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260323-sched-rert_groups-v3-3-1e7d5ed6b249@suse.com
---
 kernel/sched/rt.c | 24 ------------------------
 1 file changed, 24 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index e16d8f1..4ee8faf 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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) {

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: sched/core] sched/rt: Move group schedulability check to sched_rt_global_validate()
  2026-03-23 12:39 ` [PATCH v3 2/3] sched/rt: Move group schedulability check to sched_rt_global_validate() Michal Koutný
@ 2026-04-08 11:20   ` tip-bot2 for Michal Koutný
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Michal Koutný @ 2026-04-08 11:20 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: mkoutny, Peter Zijlstra (Intel), x86, linux-kernel

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ý <mkoutny@suse.com>
AuthorDate:    Mon, 23 Mar 2026 13:39:38 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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.)

Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260323-sched-rert_groups-v3-2-1e7d5ed6b249@suse.com
---
 kernel/sched/rt.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 893e54d..e16d8f1 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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;
 }
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: sched/core] sched/rt: Skip group schedulable check with rt_group_sched=0
  2026-03-23 12:39 ` [PATCH v3 1/3] sched/rt: Skip group schedulable check with rt_group_sched=0 Michal Koutný
@ 2026-04-08 11:20   ` tip-bot2 for Michal Koutný
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Michal Koutný @ 2026-04-08 11:20 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: mkoutny, Peter Zijlstra (Intel), x86, linux-kernel

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ý <mkoutny@suse.com>
AuthorDate:    Mon, 23 Mar 2026 13:39:37 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260323-sched-rert_groups-v3-1-1e7d5ed6b249@suse.com
---
 kernel/sched/rt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index a48e867..893e54d 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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);

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-08 11:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-23 12:39 [PATCH v3 0/3] sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups Michal Koutný
2026-03-23 12:39 ` [PATCH v3 1/3] sched/rt: Skip group schedulable check with rt_group_sched=0 Michal Koutný
2026-04-08 11:20   ` [tip: sched/core] " tip-bot2 for Michal Koutný
2026-03-23 12:39 ` [PATCH v3 2/3] sched/rt: Move group schedulability check to sched_rt_global_validate() Michal Koutný
2026-04-08 11:20   ` [tip: sched/core] " tip-bot2 for Michal Koutný
2026-03-23 12:39 ` [PATCH v3 3/3] sched/rt: Cleanup global RT bandwidth functions Michal Koutný
2026-04-08 11:20   ` [tip: sched/core] " tip-bot2 for Michal Koutný

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®