diff mbox series

[RFC,v3,2/6] sched/cpufreq: Attach perf domain to sugov policy

Message ID 20191011134500.235736-3-douglas.raillard@arm.com (mailing list archive)
State RFC, archived
Headers show
Series sched/cpufreq: Make schedutil energy aware | expand

Commit Message

Douglas RAILLARD Oct. 11, 2019, 1:44 p.m. UTC
Attach an Energy Model perf_domain to each sugov_policy to prepare the
ground for energy-aware schedutil.

Signed-off-by: Douglas RAILLARD <douglas.raillard@arm.com>
---
 kernel/sched/cpufreq_schedutil.c | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Dietmar Eggemann Oct. 17, 2019, 8:57 a.m. UTC | #1
On 11/10/2019 15:44, Douglas RAILLARD wrote:

[...]

> @@ -66,6 +70,38 @@ static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);
>  
>  /************************ Governor internals ***********************/
>  
> +#ifdef CONFIG_ENERGY_MODEL
> +static void sugov_policy_attach_pd(struct sugov_policy *sg_policy)
> +{
> +	struct em_perf_domain *pd;
> +	struct cpufreq_policy *policy = sg_policy->policy;

Shouldn't always order local variable declarations from longest to
shortest line?

> +
> +	sg_policy->pd = NULL;
> +	pd = em_cpu_get(policy->cpu);
> +	if (!pd)
> +		return;
> +
> +	if (cpumask_equal(policy->related_cpus, to_cpumask(pd->cpus)))
> +		sg_policy->pd = pd;
> +	else
> +		pr_warn("%s: Not all CPUs in schedutil policy %u share the same perf domain, no perf domain for that policy will be registered\n",
> +			__func__, policy->cpu);

Maybe {} because of 2 lines?

> +}
> +
> +static struct em_perf_domain *sugov_policy_get_pd(
> +						struct sugov_policy *sg_policy)


Maybe this way? This format is already used in this file.

static struct em_perf_domain *
sugov_policy_get_pd(struct sugov_policy *sg_policy)


> +{
> +	return sg_policy->pd;
> +}
> +#else /* CONFIG_ENERGY_MODEL */
> +static void sugov_policy_attach_pd(struct sugov_policy *sg_policy) {}
> +static struct em_perf_domain *sugov_policy_get_pd(
> +						struct sugov_policy *sg_policy)
> +{
> +	return NULL;
> +}
> +#endif /* CONFIG_ENERGY_MODEL */
> +
>  static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
>  {
>  	s64 delta_ns;
> @@ -859,6 +895,9 @@ static int sugov_start(struct cpufreq_policy *policy)
>  							sugov_update_shared :
>  							sugov_update_single);
>  	}
> +
> +	sugov_policy_attach_pd(sg_policy);
> +
>  	return 0;
>  }

A sugov_policy_detach_pd() called from sugov_stop() (doing for instance
the g_policy->pd = NULL) is not needed?
Douglas RAILLARD Oct. 17, 2019, 10:22 a.m. UTC | #2
Hi Dietmar,

On 10/17/19 9:57 AM, Dietmar Eggemann wrote:
> On 11/10/2019 15:44, Douglas RAILLARD wrote:
> 
> [...]
> 
>> @@ -66,6 +70,38 @@ static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);
>>   
>>   /************************ Governor internals ***********************/
>>   
>> +#ifdef CONFIG_ENERGY_MODEL
>> +static void sugov_policy_attach_pd(struct sugov_policy *sg_policy)
>> +{
>> +	struct em_perf_domain *pd;
>> +	struct cpufreq_policy *policy = sg_policy->policy;
> 
> Shouldn't always order local variable declarations from longest to
> shortest line?

Can't find any reference to that rule in the coding style, although I'm happy to change order
if that's deemed useful.

> 
>> +
>> +	sg_policy->pd = NULL;
>> +	pd = em_cpu_get(policy->cpu);
>> +	if (!pd)
>> +		return;
>> +
>> +	if (cpumask_equal(policy->related_cpus, to_cpumask(pd->cpus)))
>> +		sg_policy->pd = pd;
>> +	else
>> +		pr_warn("%s: Not all CPUs in schedutil policy %u share the same perf domain, no perf domain for that policy will be registered\n",
>> +			__func__, policy->cpu);
> 
> Maybe {} because of 2 lines?

+1

>> +}
>> +
>> +static struct em_perf_domain *sugov_policy_get_pd(
>> +						struct sugov_policy *sg_policy)
> 
> 
> Maybe this way? This format is already used in this file.
> 
> static struct em_perf_domain *
> sugov_policy_get_pd(struct sugov_policy *sg_policy)
> 

I also prefer this kind of non-indented form that always stays indented across renames :)

>> +{
>> +	return sg_policy->pd;
>> +}
>> +#else /* CONFIG_ENERGY_MODEL */
>> +static void sugov_policy_attach_pd(struct sugov_policy *sg_policy) {}
>> +static struct em_perf_domain *sugov_policy_get_pd(
>> +						struct sugov_policy *sg_policy)
>> +{
>> +	return NULL;
>> +}
>> +#endif /* CONFIG_ENERGY_MODEL */
>> +
>>   static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
>>   {
>>   	s64 delta_ns;
>> @@ -859,6 +895,9 @@ static int sugov_start(struct cpufreq_policy *policy)
>>   							sugov_update_shared :
>>   							sugov_update_single);
>>   	}
>> +
>> +	sugov_policy_attach_pd(sg_policy);
>> +
>>   	return 0;
>>   }
> 
> A sugov_policy_detach_pd() called from sugov_stop() (doing for instance
> the g_policy->pd = NULL) is not needed?

 From what I could see, sugov_stop() will always be followed by sugov_start() before
it's used again, so that does not seem more risky than not de-initializing sg_cpu's
for example.
diff mbox series

Patch

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index ba9e8309eec7..9abda58827c0 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -42,6 +42,10 @@  struct sugov_policy {
 
 	bool			limits_changed;
 	bool			need_freq_update;
+
+#ifdef CONFIG_ENERGY_MODEL
+	struct em_perf_domain *pd;
+#endif
 };
 
 struct sugov_cpu {
@@ -66,6 +70,38 @@  static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);
 
 /************************ Governor internals ***********************/
 
+#ifdef CONFIG_ENERGY_MODEL
+static void sugov_policy_attach_pd(struct sugov_policy *sg_policy)
+{
+	struct em_perf_domain *pd;
+	struct cpufreq_policy *policy = sg_policy->policy;
+
+	sg_policy->pd = NULL;
+	pd = em_cpu_get(policy->cpu);
+	if (!pd)
+		return;
+
+	if (cpumask_equal(policy->related_cpus, to_cpumask(pd->cpus)))
+		sg_policy->pd = pd;
+	else
+		pr_warn("%s: Not all CPUs in schedutil policy %u share the same perf domain, no perf domain for that policy will be registered\n",
+			__func__, policy->cpu);
+}
+
+static struct em_perf_domain *sugov_policy_get_pd(
+						struct sugov_policy *sg_policy)
+{
+	return sg_policy->pd;
+}
+#else /* CONFIG_ENERGY_MODEL */
+static void sugov_policy_attach_pd(struct sugov_policy *sg_policy) {}
+static struct em_perf_domain *sugov_policy_get_pd(
+						struct sugov_policy *sg_policy)
+{
+	return NULL;
+}
+#endif /* CONFIG_ENERGY_MODEL */
+
 static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
 {
 	s64 delta_ns;
@@ -859,6 +895,9 @@  static int sugov_start(struct cpufreq_policy *policy)
 							sugov_update_shared :
 							sugov_update_single);
 	}
+
+	sugov_policy_attach_pd(sg_policy);
+
 	return 0;
 }