[PATCH v1 2/2] PM: EM: Slightly reduce em_check_capacity_update() overhead

Rafael J. Wysocki posted 1 patch 1 year ago
kernel/power/energy_model.c |    4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH v1 2/2] PM: EM: Slightly reduce em_check_capacity_update() overhead
Posted by Rafael J. Wysocki 1 year ago
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Every iteration of the loop over all possible CPUs in
em_check_capacity_update() causes get_cpu_device() to be called twice
for the same CPU, once indirectly via em_cpu_get() and once directly.

Get rid of the indirect get_cpu_device() call by moving the direct
invocation of it earlier and using em_pd_get() instead of em_cpu_get()
to get a pd pointer for the dev one returned by it.

This also exposes the fact that dev is needed to get a pd, so the code
becomes somewhat easier to follow after it.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 kernel/power/energy_model.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -774,7 +774,8 @@
 		}
 		cpufreq_cpu_put(policy);
 
-		pd = em_cpu_get(cpu);
+		dev = get_cpu_device(cpu);
+		pd = em_pd_get(dev);
 		if (!pd || em_is_artificial(pd))
 			continue;
 
@@ -798,7 +799,6 @@
 		pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n",
 			 cpu, cpu_capacity, em_max_perf);
 
-		dev = get_cpu_device(cpu);
 		em_adjust_new_capacity(dev, pd);
 	}
Re: [PATCH v1 2/2] PM: EM: Slightly reduce em_check_capacity_update() overhead
Posted by Lukasz Luba 12 months ago

On 1/27/25 13:38, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Every iteration of the loop over all possible CPUs in
> em_check_capacity_update() causes get_cpu_device() to be called twice
> for the same CPU, once indirectly via em_cpu_get() and once directly.
> 
> Get rid of the indirect get_cpu_device() call by moving the direct
> invocation of it earlier and using em_pd_get() instead of em_cpu_get()
> to get a pd pointer for the dev one returned by it.
> 
> This also exposes the fact that dev is needed to get a pd, so the code
> becomes somewhat easier to follow after it.
> 
> No functional impact.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   kernel/power/energy_model.c |    4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> --- a/kernel/power/energy_model.c
> +++ b/kernel/power/energy_model.c
> @@ -774,7 +774,8 @@
>   		}
>   		cpufreq_cpu_put(policy);
>   
> -		pd = em_cpu_get(cpu);
> +		dev = get_cpu_device(cpu);
> +		pd = em_pd_get(dev);
>   		if (!pd || em_is_artificial(pd))
>   			continue;
>   
> @@ -798,7 +799,6 @@
>   		pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n",
>   			 cpu, cpu_capacity, em_max_perf);
>   
> -		dev = get_cpu_device(cpu);
>   		em_adjust_new_capacity(dev, pd);
>   	}
>   
> 
> 
> 


LGTM

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>