[PATCH] cpufreq: schedutil: Always trace frequency if it does not change

From: Rafael J. Wysocki
Date: Tue Mar 21 2017 - 21:02:34 EST


From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>

sugov_update_commit() calls trace_cpu_frequency() to record the
current CPU frequency if it has not changed in the fast switch case
to prevent utilities from getting confused (they may report that the
CPU is idle if the frequency has not been recorded for too long, for
example).

However, the same problem may occur for a cpufreq driver that doesn't
support fast frequency switching and implements the ->target callback
(that is, it doesn't use frequency tables), but trace_cpu_frequency()
is not called if frequency updates are skipped in that case.

For this reason, modify sugov_update_commit() to always call
trace_cpu_frequency() when the new frequency to be set is equal to
the one that was set previously and reorganize the code in there to
reduce duplication somewhat.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
kernel/sched/cpufreq_schedutil.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

Index: linux-pm/kernel/sched/cpufreq_schedutil.c
===================================================================
--- linux-pm.orig/kernel/sched/cpufreq_schedutil.c
+++ linux-pm/kernel/sched/cpufreq_schedutil.c
@@ -98,22 +98,22 @@ static void sugov_update_commit(struct s
{
struct cpufreq_policy *policy = sg_policy->policy;

+ if (sg_policy->next_freq == next_freq) {
+ trace_cpu_frequency(policy->cur, smp_processor_id());
+ return;
+ }
+
+ sg_policy->next_freq = next_freq;
+ sg_policy->last_freq_update_time = time;
+
if (policy->fast_switch_enabled) {
- if (sg_policy->next_freq == next_freq) {
- trace_cpu_frequency(policy->cur, smp_processor_id());
- return;
- }
- sg_policy->next_freq = next_freq;
- sg_policy->last_freq_update_time = time;
next_freq = cpufreq_driver_fast_switch(policy, next_freq);
if (next_freq == CPUFREQ_ENTRY_INVALID)
return;

policy->cur = next_freq;
trace_cpu_frequency(next_freq, smp_processor_id());
- } else if (sg_policy->next_freq != next_freq) {
- sg_policy->next_freq = next_freq;
- sg_policy->last_freq_update_time = time;
+ } else {
sg_policy->work_in_progress = true;
irq_work_queue(&sg_policy->irq_work);
}