diff mbox series

[v2,1/3] cpufreq: CPPC: Add cppc_cpufreq_search_cpu_data

Message ID 20220407081620.1662192-2-pierre.gondois@arm.com (mailing list archive)
State New, archived
Headers show
Series Enable EAS for CPPC/ACPI based systems | expand

Commit Message

Pierre Gondois April 7, 2022, 8:16 a.m. UTC
From: Pierre Gondois <Pierre.Gondois@arm.com>

cppc_cpufreq_get_cpu_data() allocates a new struct cppc_cpudata
for the input CPU at each call.

To search the struct associated with a cpu without allocating
a new one, add cppc_cpufreq_search_cpu_data().
Also add an early prototype.

This will be used in a later patch, when generating artificial
performance states to register an artificial Energy Model in the
cppc_cpufreq driver and enable the Energy Aware Scheduler for ACPI
based systems.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
 drivers/cpufreq/cppc_cpufreq.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Viresh Kumar April 11, 2022, 3:10 a.m. UTC | #1
On 07-04-22, 10:16, Pierre Gondois wrote:
> From: Pierre Gondois <Pierre.Gondois@arm.com>
> 
> cppc_cpufreq_get_cpu_data() allocates a new struct cppc_cpudata
> for the input CPU at each call.
> 
> To search the struct associated with a cpu without allocating
> a new one, add cppc_cpufreq_search_cpu_data().
> Also add an early prototype.
> 
> This will be used in a later patch, when generating artificial
> performance states to register an artificial Energy Model in the
> cppc_cpufreq driver and enable the Energy Aware Scheduler for ACPI
> based systems.
> 
> Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
> ---
>  drivers/cpufreq/cppc_cpufreq.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
> index 82d370ae6a4a..ffcd9704add2 100644
> --- a/drivers/cpufreq/cppc_cpufreq.c
> +++ b/drivers/cpufreq/cppc_cpufreq.c
> @@ -41,6 +41,8 @@
>   */
>  static LIST_HEAD(cpu_data_list);
>  
> +static struct cppc_cpudata *cppc_cpufreq_search_cpu_data(unsigned int cpu);
> +
>  static bool boost_supported;
>  
>  struct cppc_workaround_oem_info {
> @@ -479,6 +481,19 @@ static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy)
>  	policy->driver_data = NULL;
>  }
>  
> +static struct cppc_cpudata *
> +cppc_cpufreq_search_cpu_data(unsigned int cpu)
> +{
> +	struct cppc_cpudata *iter, *tmp;
> +
> +	list_for_each_entry_safe(iter, tmp, &cpu_data_list, node) {
> +		if (cpumask_test_cpu(cpu, iter->shared_cpu_map))
> +			return iter;
> +	}
> +
> +	return NULL;
> +}

Did you miss this in cppc_cpufreq_cpu_init() ?

	policy->driver_data = cpu_data;

The data is saved inside the policy and it shouldn't be difficult to
fetch it from there, instead of going through the list.
Pierre Gondois April 11, 2022, 10:34 a.m. UTC | #2
On 4/11/22 05:10, Viresh Kumar wrote:
> On 07-04-22, 10:16, Pierre Gondois wrote:
>> From: Pierre Gondois <Pierre.Gondois@arm.com>
>>
>> cppc_cpufreq_get_cpu_data() allocates a new struct cppc_cpudata
>> for the input CPU at each call.
>>
>> To search the struct associated with a cpu without allocating
>> a new one, add cppc_cpufreq_search_cpu_data().
>> Also add an early prototype.
>>
>> This will be used in a later patch, when generating artificial
>> performance states to register an artificial Energy Model in the
>> cppc_cpufreq driver and enable the Energy Aware Scheduler for ACPI
>> based systems.
>>
>> Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
>> ---
>>   drivers/cpufreq/cppc_cpufreq.c | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
>>
>> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
>> index 82d370ae6a4a..ffcd9704add2 100644
>> --- a/drivers/cpufreq/cppc_cpufreq.c
>> +++ b/drivers/cpufreq/cppc_cpufreq.c
>> @@ -41,6 +41,8 @@
>>    */
>>   static LIST_HEAD(cpu_data_list);
>>   
>> +static struct cppc_cpudata *cppc_cpufreq_search_cpu_data(unsigned int cpu);
>> +
>>   static bool boost_supported;
>>   
>>   struct cppc_workaround_oem_info {
>> @@ -479,6 +481,19 @@ static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy)
>>   	policy->driver_data = NULL;
>>   }
>>   
>> +static struct cppc_cpudata *
>> +cppc_cpufreq_search_cpu_data(unsigned int cpu)
>> +{
>> +	struct cppc_cpudata *iter, *tmp;
>> +
>> +	list_for_each_entry_safe(iter, tmp, &cpu_data_list, node) {
>> +		if (cpumask_test_cpu(cpu, iter->shared_cpu_map))
>> +			return iter;
>> +	}
>> +
>> +	return NULL;
>> +}
> 
> Did you miss this in cppc_cpufreq_cpu_init() ?
> 
> 	policy->driver_data = cpu_data;
> 
> The data is saved inside the policy and it shouldn't be difficult to
> fetch it from there, instead of going through the list.
> 

A previous (internal) implementation required this function,
but this is not necessary anymore indeed. I will drop this patch,
Thanks for the review,
Pierre
diff mbox series

Patch

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 82d370ae6a4a..ffcd9704add2 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -41,6 +41,8 @@ 
  */
 static LIST_HEAD(cpu_data_list);
 
+static struct cppc_cpudata *cppc_cpufreq_search_cpu_data(unsigned int cpu);
+
 static bool boost_supported;
 
 struct cppc_workaround_oem_info {
@@ -479,6 +481,19 @@  static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy)
 	policy->driver_data = NULL;
 }
 
+static struct cppc_cpudata *
+cppc_cpufreq_search_cpu_data(unsigned int cpu)
+{
+	struct cppc_cpudata *iter, *tmp;
+
+	list_for_each_entry_safe(iter, tmp, &cpu_data_list, node) {
+		if (cpumask_test_cpu(cpu, iter->shared_cpu_map))
+			return iter;
+	}
+
+	return NULL;
+}
+
 static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
 {
 	unsigned int cpu = policy->cpu;