sched/rt: Fix schedulable check with rt_group_sched=0 and cleanups
v2 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 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: 9702969978695d9a699a1f34771580cdbb153b33
change-id: 20260119-sched-rert_groups-431e2d5d1c57
Best regards,
Signature · 1 line
Michal Koutný <[email protected]>
PATCH v2 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.
This fix is immaterial with CONFIG_RT_GROUP_SCHED=n.
--- kernel/sched/rt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/rt.c +2 -3
@@ -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.52.0
PATCH v2 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
@@ -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.52.0
PATCH v2 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
@@ -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 *buffif (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.52.0
Quoted 4 lines · Michal Koutný
The crux is the first commit which fixes how sysctl kernel.sched_rt_runtime_us changes are validated with
CONFIG_RT_GROUP_SCHEDbut rt_group_sched=0. The rest are cleanups that occurred to me.
Ping