diff mbox series

cpufreq: schedutil: Merge initialization code of sg_cpu in single loop

Message ID 20230908031604.2262422-1-liaochang1@huawei.com (mailing list archive)
State Mainlined, archived
Headers show
Series cpufreq: schedutil: Merge initialization code of sg_cpu in single loop | expand

Commit Message

Liao, Chang Sept. 8, 2023, 3:16 a.m. UTC
The initialization code of the per-cpu sg_cpu struct is currently split
into two for-loop blocks. This can be simplified by merging the two
blocks into a single loop. This will make the code more maintainable.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 kernel/sched/cpufreq_schedutil.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Viresh Kumar Sept. 27, 2023, 8:55 a.m. UTC | #1
On 08-09-23, 03:16, Liao Chang wrote:
> The initialization code of the per-cpu sg_cpu struct is currently split
> into two for-loop blocks. This can be simplified by merging the two
> blocks into a single loop. This will make the code more maintainable.
> 
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
>  kernel/sched/cpufreq_schedutil.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 4492608b7d7f..f3a95def49cc 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -767,14 +767,6 @@ static int sugov_start(struct cpufreq_policy *policy)
>  
>  	sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
>  
> -	for_each_cpu(cpu, policy->cpus) {
> -		struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
> -
> -		memset(sg_cpu, 0, sizeof(*sg_cpu));
> -		sg_cpu->cpu			= cpu;
> -		sg_cpu->sg_policy		= sg_policy;
> -	}
> -
>  	if (policy_is_shared(policy))
>  		uu = sugov_update_shared;
>  	else if (policy->fast_switch_enabled && cpufreq_driver_has_adjust_perf())
> @@ -785,6 +777,9 @@ static int sugov_start(struct cpufreq_policy *policy)
>  	for_each_cpu(cpu, policy->cpus) {
>  		struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
>  
> +		memset(sg_cpu, 0, sizeof(*sg_cpu));
> +		sg_cpu->cpu = cpu;
> +		sg_cpu->sg_policy = sg_policy;
>  		cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util, uu);
>  	}
>  	return 0;

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Rafael J. Wysocki Oct. 6, 2023, 7:52 p.m. UTC | #2
On Wed, Sep 27, 2023 at 10:55 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 08-09-23, 03:16, Liao Chang wrote:
> > The initialization code of the per-cpu sg_cpu struct is currently split
> > into two for-loop blocks. This can be simplified by merging the two
> > blocks into a single loop. This will make the code more maintainable.
> >
> > Signed-off-by: Liao Chang <liaochang1@huawei.com>
> > ---
> >  kernel/sched/cpufreq_schedutil.c | 11 +++--------
> >  1 file changed, 3 insertions(+), 8 deletions(-)
> >
> > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> > index 4492608b7d7f..f3a95def49cc 100644
> > --- a/kernel/sched/cpufreq_schedutil.c
> > +++ b/kernel/sched/cpufreq_schedutil.c
> > @@ -767,14 +767,6 @@ static int sugov_start(struct cpufreq_policy *policy)
> >
> >       sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
> >
> > -     for_each_cpu(cpu, policy->cpus) {
> > -             struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
> > -
> > -             memset(sg_cpu, 0, sizeof(*sg_cpu));
> > -             sg_cpu->cpu                     = cpu;
> > -             sg_cpu->sg_policy               = sg_policy;
> > -     }
> > -
> >       if (policy_is_shared(policy))
> >               uu = sugov_update_shared;
> >       else if (policy->fast_switch_enabled && cpufreq_driver_has_adjust_perf())
> > @@ -785,6 +777,9 @@ static int sugov_start(struct cpufreq_policy *policy)
> >       for_each_cpu(cpu, policy->cpus) {
> >               struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
> >
> > +             memset(sg_cpu, 0, sizeof(*sg_cpu));
> > +             sg_cpu->cpu = cpu;
> > +             sg_cpu->sg_policy = sg_policy;
> >               cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util, uu);
> >       }
> >       return 0;
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Applied as 6.7 material, thanks!
diff mbox series

Patch

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 4492608b7d7f..f3a95def49cc 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -767,14 +767,6 @@  static int sugov_start(struct cpufreq_policy *policy)
 
 	sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS);
 
-	for_each_cpu(cpu, policy->cpus) {
-		struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
-
-		memset(sg_cpu, 0, sizeof(*sg_cpu));
-		sg_cpu->cpu			= cpu;
-		sg_cpu->sg_policy		= sg_policy;
-	}
-
 	if (policy_is_shared(policy))
 		uu = sugov_update_shared;
 	else if (policy->fast_switch_enabled && cpufreq_driver_has_adjust_perf())
@@ -785,6 +777,9 @@  static int sugov_start(struct cpufreq_policy *policy)
 	for_each_cpu(cpu, policy->cpus) {
 		struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
 
+		memset(sg_cpu, 0, sizeof(*sg_cpu));
+		sg_cpu->cpu = cpu;
+		sg_cpu->sg_policy = sg_policy;
 		cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util, uu);
 	}
 	return 0;