diff mbox series

[PATCHi,V2] cpufreq: optimize cpufreq_notify_transition()

Message ID c0a3082eee2d2a819a13c9e03926e9e3e8692b97.1525944574.git.viresh.kumar@linaro.org
State Accepted
Commit 20b5324d8353d66e68e8c40031e438c247cf2d65
Headers show
Series [PATCHi,V2] cpufreq: optimize cpufreq_notify_transition() | expand

Commit Message

Viresh Kumar May 10, 2018, 9:30 a.m. UTC
cpufreq_notify_transition() calls __cpufreq_notify_transition() for each
CPU of a policy. There is a lot of code in __cpufreq_notify_transition()
though which isn't required to be executed for each CPU, like checking
about disabled cpufreq or irqs, adjusting jiffies, updating cpufreq
stats and some debug print messages.

This commit merges __cpufreq_notify_transition() into
cpufreq_notify_transition() and modifies cpufreq_notify_transition() to
execute minimum amount of code for each CPU.

Also fix the kerneldoc for cpufreq_notify_transition() while at it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

---
V2:
- Fixed kerneldoc comment over cpufreq_notify_transition().
- Add more details to the commit log.

 drivers/cpufreq/cpufreq.c | 63 ++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 31 deletions(-)

-- 
2.15.0.194.g9af6a3dea062

Comments

Rafael J. Wysocki May 17, 2018, 10:34 a.m. UTC | #1
On Thursday, May 10, 2018 11:30:29 AM CEST Viresh Kumar wrote:
> cpufreq_notify_transition() calls __cpufreq_notify_transition() for each

> CPU of a policy. There is a lot of code in __cpufreq_notify_transition()

> though which isn't required to be executed for each CPU, like checking

> about disabled cpufreq or irqs, adjusting jiffies, updating cpufreq

> stats and some debug print messages.

> 

> This commit merges __cpufreq_notify_transition() into

> cpufreq_notify_transition() and modifies cpufreq_notify_transition() to

> execute minimum amount of code for each CPU.

> 

> Also fix the kerneldoc for cpufreq_notify_transition() while at it.

> 

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

> V2:

> - Fixed kerneldoc comment over cpufreq_notify_transition().

> - Add more details to the commit log.

> 

>  drivers/cpufreq/cpufreq.c | 63 ++++++++++++++++++++++++-----------------------

>  1 file changed, 32 insertions(+), 31 deletions(-)

> 

> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c

> index 075d18f6ba7a..b79c5324767c 100644

> --- a/drivers/cpufreq/cpufreq.c

> +++ b/drivers/cpufreq/cpufreq.c

> @@ -300,8 +300,19 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)

>  #endif

>  }

>  

> -static void __cpufreq_notify_transition(struct cpufreq_policy *policy,

> -		struct cpufreq_freqs *freqs, unsigned int state)

> +/**

> + * cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.

> + * @policy: cpufreq policy to enable fast frequency switching for.

> + * @freqs: contain details of the frequency update.

> + * @state: set to CPUFREQ_PRECHANGE or CPUFREQ_POSTCHANGE.

> + *

> + * This function calls the transition notifiers and the "adjust_jiffies"

> + * function. It is called twice on all CPU frequency changes that have

> + * external effects.

> + */

> +static void cpufreq_notify_transition(struct cpufreq_policy *policy,

> +				      struct cpufreq_freqs *freqs,

> +				      unsigned int state)

>  {

>  	BUG_ON(irqs_disabled());

>  

> @@ -313,54 +324,44 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,

>  		 state, freqs->new);

>  

>  	switch (state) {

> -

>  	case CPUFREQ_PRECHANGE:

> -		/* detect if the driver reported a value as "old frequency"

> +		/*

> +		 * Detect if the driver reported a value as "old frequency"

>  		 * which is not equal to what the cpufreq core thinks is

>  		 * "old frequency".

>  		 */

>  		if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {

> -			if ((policy) && (policy->cpu == freqs->cpu) &&

> -			    (policy->cur) && (policy->cur != freqs->old)) {

> +			if (policy->cur && (policy->cur != freqs->old)) {

>  				pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",

>  					 freqs->old, policy->cur);

>  				freqs->old = policy->cur;

>  			}

>  		}

> -		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,

> -				CPUFREQ_PRECHANGE, freqs);

> +

> +		for_each_cpu(freqs->cpu, policy->cpus) {

> +			srcu_notifier_call_chain(&cpufreq_transition_notifier_list,

> +						 CPUFREQ_PRECHANGE, freqs);

> +		}

> +

>  		adjust_jiffies(CPUFREQ_PRECHANGE, freqs);

>  		break;

>  

>  	case CPUFREQ_POSTCHANGE:

>  		adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);

> -		pr_debug("FREQ: %lu - CPU: %lu\n",

> -			 (unsigned long)freqs->new, (unsigned long)freqs->cpu);

> -		trace_cpu_frequency(freqs->new, freqs->cpu);

> +		pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new,

> +			 cpumask_pr_args(policy->cpus));

> +

> +		for_each_cpu(freqs->cpu, policy->cpus) {

> +			trace_cpu_frequency(freqs->new, freqs->cpu);

> +			srcu_notifier_call_chain(&cpufreq_transition_notifier_list,

> +						 CPUFREQ_POSTCHANGE, freqs);

> +		}

> +

>  		cpufreq_stats_record_transition(policy, freqs->new);

> -		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,

> -				CPUFREQ_POSTCHANGE, freqs);

> -		if (likely(policy) && likely(policy->cpu == freqs->cpu))

> -			policy->cur = freqs->new;

> -		break;

> +		policy->cur = freqs->new;

>  	}

>  }

>  

> -/**

> - * cpufreq_notify_transition - call notifier chain and adjust_jiffies

> - * on frequency transition.

> - *

> - * This function calls the transition notifiers and the "adjust_jiffies"

> - * function. It is called twice on all CPU frequency changes that have

> - * external effects.

> - */

> -static void cpufreq_notify_transition(struct cpufreq_policy *policy,

> -		struct cpufreq_freqs *freqs, unsigned int state)

> -{

> -	for_each_cpu(freqs->cpu, policy->cpus)

> -		__cpufreq_notify_transition(policy, freqs, state);

> -}

> -

>  /* Do post notifications when there are chances that transition has failed */

>  static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,

>  		struct cpufreq_freqs *freqs, int transition_failed)

> 


Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 075d18f6ba7a..b79c5324767c 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -300,8 +300,19 @@  static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
 #endif
 }
 
-static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
-		struct cpufreq_freqs *freqs, unsigned int state)
+/**
+ * cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.
+ * @policy: cpufreq policy to enable fast frequency switching for.
+ * @freqs: contain details of the frequency update.
+ * @state: set to CPUFREQ_PRECHANGE or CPUFREQ_POSTCHANGE.
+ *
+ * This function calls the transition notifiers and the "adjust_jiffies"
+ * function. It is called twice on all CPU frequency changes that have
+ * external effects.
+ */
+static void cpufreq_notify_transition(struct cpufreq_policy *policy,
+				      struct cpufreq_freqs *freqs,
+				      unsigned int state)
 {
 	BUG_ON(irqs_disabled());
 
@@ -313,54 +324,44 @@  static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
 		 state, freqs->new);
 
 	switch (state) {
-
 	case CPUFREQ_PRECHANGE:
-		/* detect if the driver reported a value as "old frequency"
+		/*
+		 * Detect if the driver reported a value as "old frequency"
 		 * which is not equal to what the cpufreq core thinks is
 		 * "old frequency".
 		 */
 		if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
-			if ((policy) && (policy->cpu == freqs->cpu) &&
-			    (policy->cur) && (policy->cur != freqs->old)) {
+			if (policy->cur && (policy->cur != freqs->old)) {
 				pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
 					 freqs->old, policy->cur);
 				freqs->old = policy->cur;
 			}
 		}
-		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
-				CPUFREQ_PRECHANGE, freqs);
+
+		for_each_cpu(freqs->cpu, policy->cpus) {
+			srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
+						 CPUFREQ_PRECHANGE, freqs);
+		}
+
 		adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
 		break;
 
 	case CPUFREQ_POSTCHANGE:
 		adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
-		pr_debug("FREQ: %lu - CPU: %lu\n",
-			 (unsigned long)freqs->new, (unsigned long)freqs->cpu);
-		trace_cpu_frequency(freqs->new, freqs->cpu);
+		pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new,
+			 cpumask_pr_args(policy->cpus));
+
+		for_each_cpu(freqs->cpu, policy->cpus) {
+			trace_cpu_frequency(freqs->new, freqs->cpu);
+			srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
+						 CPUFREQ_POSTCHANGE, freqs);
+		}
+
 		cpufreq_stats_record_transition(policy, freqs->new);
-		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
-				CPUFREQ_POSTCHANGE, freqs);
-		if (likely(policy) && likely(policy->cpu == freqs->cpu))
-			policy->cur = freqs->new;
-		break;
+		policy->cur = freqs->new;
 	}
 }
 
-/**
- * cpufreq_notify_transition - call notifier chain and adjust_jiffies
- * on frequency transition.
- *
- * This function calls the transition notifiers and the "adjust_jiffies"
- * function. It is called twice on all CPU frequency changes that have
- * external effects.
- */
-static void cpufreq_notify_transition(struct cpufreq_policy *policy,
-		struct cpufreq_freqs *freqs, unsigned int state)
-{
-	for_each_cpu(freqs->cpu, policy->cpus)
-		__cpufreq_notify_transition(policy, freqs, state);
-}
-
 /* Do post notifications when there are chances that transition has failed */
 static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
 		struct cpufreq_freqs *freqs, int transition_failed)