Skip to content

Commit d6809c2

Browse files
WerkovPeter Zijlstra
authored andcommitted
sched: Do not construct nor expose RT_GROUP_SCHED structures if disabled
Thanks to kernel cmdline being available early, before any cgroup hierarchy exists, we can achieve the RT_GROUP_SCHED boottime disabling goal by simply skipping any creation (and destruction) of RT_GROUP data and its exposure via RT attributes. We can do this thanks to previously placed runtime guards that would redirect all operations to root_task_group's data when RT_GROUP_SCHED disabled. Signed-off-by: Michal Koutný <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 277e090 commit d6809c2

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

kernel/sched/core.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9867,18 +9867,6 @@ static struct cftype cpu_legacy_files[] = {
98679867
.seq_show = cpu_cfs_local_stat_show,
98689868
},
98699869
#endif
9870-
#ifdef CONFIG_RT_GROUP_SCHED
9871-
{
9872-
.name = "rt_runtime_us",
9873-
.read_s64 = cpu_rt_runtime_read,
9874-
.write_s64 = cpu_rt_runtime_write,
9875-
},
9876-
{
9877-
.name = "rt_period_us",
9878-
.read_u64 = cpu_rt_period_read_uint,
9879-
.write_u64 = cpu_rt_period_write_uint,
9880-
},
9881-
#endif
98829870
#ifdef CONFIG_UCLAMP_TASK_GROUP
98839871
{
98849872
.name = "uclamp.min",
@@ -9897,6 +9885,20 @@ static struct cftype cpu_legacy_files[] = {
98979885
};
98989886

98999887
#ifdef CONFIG_RT_GROUP_SCHED
9888+
static struct cftype rt_group_files[] = {
9889+
{
9890+
.name = "rt_runtime_us",
9891+
.read_s64 = cpu_rt_runtime_read,
9892+
.write_s64 = cpu_rt_runtime_write,
9893+
},
9894+
{
9895+
.name = "rt_period_us",
9896+
.read_u64 = cpu_rt_period_read_uint,
9897+
.write_u64 = cpu_rt_period_write_uint,
9898+
},
9899+
{ } /* Terminate */
9900+
};
9901+
99009902
# ifdef CONFIG_RT_GROUP_SCHED_DEFAULT_DISABLED
99019903
DEFINE_STATIC_KEY_FALSE(rt_group_sched);
99029904
# else
@@ -9919,6 +9921,16 @@ static int __init setup_rt_group_sched(char *str)
99199921
return 1;
99209922
}
99219923
__setup("rt_group_sched=", setup_rt_group_sched);
9924+
9925+
static int __init cpu_rt_group_init(void)
9926+
{
9927+
if (!rt_group_sched_enabled())
9928+
return 0;
9929+
9930+
WARN_ON(cgroup_add_legacy_cftypes(&cpu_cgrp_subsys, rt_group_files));
9931+
return 0;
9932+
}
9933+
subsys_initcall(cpu_rt_group_init);
99229934
#endif /* CONFIG_RT_GROUP_SCHED */
99239935

99249936
static int cpu_extra_stat_show(struct seq_file *sf,

kernel/sched/rt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ static inline struct rq *rq_of_rt_se(struct sched_rt_entity *rt_se)
193193

194194
void unregister_rt_sched_group(struct task_group *tg)
195195
{
196+
if (!rt_group_sched_enabled())
197+
return;
198+
196199
if (tg->rt_se)
197200
destroy_rt_bandwidth(&tg->rt_bandwidth);
198201
}
@@ -201,6 +204,9 @@ void free_rt_sched_group(struct task_group *tg)
201204
{
202205
int i;
203206

207+
if (!rt_group_sched_enabled())
208+
return;
209+
204210
for_each_possible_cpu(i) {
205211
if (tg->rt_rq)
206212
kfree(tg->rt_rq[i]);
@@ -245,6 +251,9 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
245251
struct sched_rt_entity *rt_se;
246252
int i;
247253

254+
if (!rt_group_sched_enabled())
255+
return 1;
256+
248257
tg->rt_rq = kcalloc(nr_cpu_ids, sizeof(rt_rq), GFP_KERNEL);
249258
if (!tg->rt_rq)
250259
goto err;

0 commit comments

Comments
 (0)