[PATCH v3] sched: Simplify __sched_init runtime checks

Chun-Hung Tseng posted 1 patch 4 years, 3 months ago
kernel/sched/core.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
[PATCH v3] sched: Simplify __sched_init runtime checks
Posted by Chun-Hung Tseng 4 years, 3 months ago
Improve runtime checks in __sched_init(void) by replacing if conditional
checks with preprocessor directives.

Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
---
 kernel/sched/core.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9745613d531c..003e8677f6ba 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9317,28 +9317,29 @@ void __init sched_init(void)
 #ifdef CONFIG_RT_GROUP_SCHED
 	ptr += 2 * nr_cpu_ids * sizeof(void **);
 #endif
-	if (ptr) {
-		ptr = (unsigned long)kzalloc(ptr, GFP_NOWAIT);
+
+#if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
+	ptr = (unsigned long)kzalloc(ptr, GFP_NOWAIT);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-		root_task_group.se = (struct sched_entity **)ptr;
-		ptr += nr_cpu_ids * sizeof(void **);
+	root_task_group.se = (struct sched_entity **)ptr;
+	ptr += nr_cpu_ids * sizeof(void **);
 
-		root_task_group.cfs_rq = (struct cfs_rq **)ptr;
-		ptr += nr_cpu_ids * sizeof(void **);
+	root_task_group.cfs_rq = (struct cfs_rq **)ptr;
+	ptr += nr_cpu_ids * sizeof(void **);
 
-		root_task_group.shares = ROOT_TASK_GROUP_LOAD;
-		init_cfs_bandwidth(&root_task_group.cfs_bandwidth);
+	root_task_group.shares = ROOT_TASK_GROUP_LOAD;
+	init_cfs_bandwidth(&root_task_group.cfs_bandwidth);
 #endif /* CONFIG_FAIR_GROUP_SCHED */
 #ifdef CONFIG_RT_GROUP_SCHED
-		root_task_group.rt_se = (struct sched_rt_entity **)ptr;
-		ptr += nr_cpu_ids * sizeof(void **);
-
-		root_task_group.rt_rq = (struct rt_rq **)ptr;
-		ptr += nr_cpu_ids * sizeof(void **);
+	root_task_group.rt_se = (struct sched_rt_entity **)ptr;
+	ptr += nr_cpu_ids * sizeof(void **);
 
+	root_task_group.rt_rq = (struct rt_rq **)ptr;
+	ptr += nr_cpu_ids * sizeof(void **);
 #endif /* CONFIG_RT_GROUP_SCHED */
-	}
+#endif /* CONFIG_FAIR_GROUP_SCHED || CONFIG_RT_GROUP_SCHED */
+
 #ifdef CONFIG_CPUMASK_OFFSTACK
 	for_each_possible_cpu(i) {
 		per_cpu(load_balance_mask, i) = (cpumask_var_t)kzalloc_node(
-- 
2.35.1
Re: [PATCH v3] sched: Simplify __sched_init runtime checks
Posted by Henry Tseng 4 years, 1 month ago
A friendly ping on this patch!

On Thu, Mar 3, 2022 at 2:19 PM Chun-Hung Tseng <henrybear327@gmail.com> wrote:
>
> Improve runtime checks in __sched_init(void) by replacing if conditional
> checks with preprocessor directives.
>
> Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
> ---
>  kernel/sched/core.c | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 9745613d531c..003e8677f6ba 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -9317,28 +9317,29 @@ void __init sched_init(void)
>  #ifdef CONFIG_RT_GROUP_SCHED
>         ptr += 2 * nr_cpu_ids * sizeof(void **);
>  #endif
> -       if (ptr) {
> -               ptr = (unsigned long)kzalloc(ptr, GFP_NOWAIT);
> +
> +#if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
> +       ptr = (unsigned long)kzalloc(ptr, GFP_NOWAIT);
>
>  #ifdef CONFIG_FAIR_GROUP_SCHED
> -               root_task_group.se = (struct sched_entity **)ptr;
> -               ptr += nr_cpu_ids * sizeof(void **);
> +       root_task_group.se = (struct sched_entity **)ptr;
> +       ptr += nr_cpu_ids * sizeof(void **);
>
> -               root_task_group.cfs_rq = (struct cfs_rq **)ptr;
> -               ptr += nr_cpu_ids * sizeof(void **);
> +       root_task_group.cfs_rq = (struct cfs_rq **)ptr;
> +       ptr += nr_cpu_ids * sizeof(void **);
>
> -               root_task_group.shares = ROOT_TASK_GROUP_LOAD;
> -               init_cfs_bandwidth(&root_task_group.cfs_bandwidth);
> +       root_task_group.shares = ROOT_TASK_GROUP_LOAD;
> +       init_cfs_bandwidth(&root_task_group.cfs_bandwidth);
>  #endif /* CONFIG_FAIR_GROUP_SCHED */
>  #ifdef CONFIG_RT_GROUP_SCHED
> -               root_task_group.rt_se = (struct sched_rt_entity **)ptr;
> -               ptr += nr_cpu_ids * sizeof(void **);
> -
> -               root_task_group.rt_rq = (struct rt_rq **)ptr;
> -               ptr += nr_cpu_ids * sizeof(void **);
> +       root_task_group.rt_se = (struct sched_rt_entity **)ptr;
> +       ptr += nr_cpu_ids * sizeof(void **);
>
> +       root_task_group.rt_rq = (struct rt_rq **)ptr;
> +       ptr += nr_cpu_ids * sizeof(void **);
>  #endif /* CONFIG_RT_GROUP_SCHED */
> -       }
> +#endif /* CONFIG_FAIR_GROUP_SCHED || CONFIG_RT_GROUP_SCHED */
> +
>  #ifdef CONFIG_CPUMASK_OFFSTACK
>         for_each_possible_cpu(i) {
>                 per_cpu(load_balance_mask, i) = (cpumask_var_t)kzalloc_node(
> --
> 2.35.1
>


-- 
Best wishes,
Henry