diff mbox series

[v2] cpufreq: schedutil: Call sugov_update_next_freq() before check to fast_switch_enabled

Message ID 20210224063927.1298-1-zbestahu@gmail.com (mailing list archive)
State Awaiting Upstream
Delegated to: Rafael Wysocki
Headers show
Series [v2] cpufreq: schedutil: Call sugov_update_next_freq() before check to fast_switch_enabled | expand

Commit Message

Yue Hu Feb. 24, 2021, 6:39 a.m. UTC
From: Yue Hu <huyue2@yulong.com>

Note that sugov_update_next_freq() may return false, that means the
caller sugov_fast_switch() will do nothing except fast switch check.

Similarly, sugov_deferred_update() also has unnecessary operations
of raw_spin_{lock,unlock} in sugov_update_single_freq() for that case.

So, let's call sugov_update_next_freq() before the fast switch check
to avoid unnecessary behaviors above. Accordingly, update interface
definition to sugov_deferred_update() and remove sugov_fast_switch()
since we will call cpufreq_driver_fast_switch() directly instead.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
v2: remove sugov_fast_switch() and call cpufreq_driver_fast_switch()
    directly instead, also update minor log message.

 kernel/sched/cpufreq_schedutil.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

Comments

Viresh Kumar Feb. 24, 2021, 6:47 a.m. UTC | #1
On 24-02-21, 14:39, Yue Hu wrote:
> From: Yue Hu <huyue2@yulong.com>
> 
> Note that sugov_update_next_freq() may return false, that means the
> caller sugov_fast_switch() will do nothing except fast switch check.
> 
> Similarly, sugov_deferred_update() also has unnecessary operations
> of raw_spin_{lock,unlock} in sugov_update_single_freq() for that case.
> 
> So, let's call sugov_update_next_freq() before the fast switch check
> to avoid unnecessary behaviors above. Accordingly, update interface
> definition to sugov_deferred_update() and remove sugov_fast_switch()
> since we will call cpufreq_driver_fast_switch() directly instead.
> 
> Signed-off-by: Yue Hu <huyue2@yulong.com>
> ---
> v2: remove sugov_fast_switch() and call cpufreq_driver_fast_switch()
>     directly instead, also update minor log message.
> 
>  kernel/sched/cpufreq_schedutil.c | 29 ++++++++++++-----------------
>  1 file changed, 12 insertions(+), 17 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Yue Hu March 10, 2021, 11:20 a.m. UTC | #2
Hi Rafael,

Please also review the patch.
I'm not sure if you have reviewed or not.

Thank you!

On Wed, 24 Feb 2021 12:17:27 +0530
Viresh Kumar <viresh.kumar@linaro.org> wrote:

> On 24-02-21, 14:39, Yue Hu wrote:
> > From: Yue Hu <huyue2@yulong.com>
> > 
> > Note that sugov_update_next_freq() may return false, that means the
> > caller sugov_fast_switch() will do nothing except fast switch check.
> > 
> > Similarly, sugov_deferred_update() also has unnecessary operations
> > of raw_spin_{lock,unlock} in sugov_update_single_freq() for that case.
> > 
> > So, let's call sugov_update_next_freq() before the fast switch check
> > to avoid unnecessary behaviors above. Accordingly, update interface
> > definition to sugov_deferred_update() and remove sugov_fast_switch()
> > since we will call cpufreq_driver_fast_switch() directly instead.
> > 
> > Signed-off-by: Yue Hu <huyue2@yulong.com>
> > ---
> > v2: remove sugov_fast_switch() and call cpufreq_driver_fast_switch()
> >     directly instead, also update minor log message.
> > 
> >  kernel/sched/cpufreq_schedutil.c | 29 ++++++++++++-----------------
> >  1 file changed, 12 insertions(+), 17 deletions(-)  
> 
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
diff mbox series

Patch

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 41e498b..65fe2c8 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -114,19 +114,8 @@  static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time,
 	return true;
 }
 
-static void sugov_fast_switch(struct sugov_policy *sg_policy, u64 time,
-			      unsigned int next_freq)
+static void sugov_deferred_update(struct sugov_policy *sg_policy)
 {
-	if (sugov_update_next_freq(sg_policy, time, next_freq))
-		cpufreq_driver_fast_switch(sg_policy->policy, next_freq);
-}
-
-static void sugov_deferred_update(struct sugov_policy *sg_policy, u64 time,
-				  unsigned int next_freq)
-{
-	if (!sugov_update_next_freq(sg_policy, time, next_freq))
-		return;
-
 	if (!sg_policy->work_in_progress) {
 		sg_policy->work_in_progress = true;
 		irq_work_queue(&sg_policy->irq_work);
@@ -368,16 +357,19 @@  static void sugov_update_single_freq(struct update_util_data *hook, u64 time,
 		sg_policy->cached_raw_freq = cached_freq;
 	}
 
+	if (!sugov_update_next_freq(sg_policy, time, next_f))
+		return;
+
 	/*
 	 * This code runs under rq->lock for the target CPU, so it won't run
 	 * concurrently on two different CPUs for the same target and it is not
 	 * necessary to acquire the lock in the fast switch case.
 	 */
 	if (sg_policy->policy->fast_switch_enabled) {
-		sugov_fast_switch(sg_policy, time, next_f);
+		cpufreq_driver_fast_switch(sg_policy->policy, next_f);
 	} else {
 		raw_spin_lock(&sg_policy->update_lock);
-		sugov_deferred_update(sg_policy, time, next_f);
+		sugov_deferred_update(sg_policy);
 		raw_spin_unlock(&sg_policy->update_lock);
 	}
 }
@@ -456,12 +448,15 @@  static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
 	if (sugov_should_update_freq(sg_policy, time)) {
 		next_f = sugov_next_freq_shared(sg_cpu, time);
 
+		if (!sugov_update_next_freq(sg_policy, time, next_f))
+			goto unlock;
+
 		if (sg_policy->policy->fast_switch_enabled)
-			sugov_fast_switch(sg_policy, time, next_f);
+			cpufreq_driver_fast_switch(sg_policy->policy, next_f);
 		else
-			sugov_deferred_update(sg_policy, time, next_f);
+			sugov_deferred_update(sg_policy);
 	}
-
+unlock:
 	raw_spin_unlock(&sg_policy->update_lock);
 }