]> git.baikalelectronics.ru Git - kernel.git/commit
cpufreq: x86: Make scaling_cur_freq behave more as expected
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 28 Jul 2017 12:45:03 +0000 (14:45 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sun, 30 Jul 2017 12:26:51 +0000 (14:26 +0200)
commit1d43e9b7a3834aefb776fe607f519fb23124d7c6
tree4b0c96b189ce8a66b7ded6301480a99489b2e9d2
parent14d22ef8941bd2289e511668715c5e0ef97018bd
cpufreq: x86: Make scaling_cur_freq behave more as expected

After commit 5a70c7cddb75 "x86: use common aperfmperf_khz_on_cpu() to
calculate KHz using APERF/MPERF" the scaling_cur_freq policy attribute
in sysfs only behaves as expected on x86 with APERF/MPERF registers
available when it is read from at least twice in a row.  The value
returned by the first read may not be meaningful, because the
computations in there use cached values from the previous iteration
of aperfmperf_snapshot_khz() which may be stale.

To prevent that from happening, modify arch_freq_get_on_cpu() to
call aperfmperf_snapshot_khz() twice, with a short delay between
these calls, if the previous invocation of aperfmperf_snapshot_khz()
was too far back in the past (specifically, more that 1s ago).

Also, as pointed out by Doug Smythies, aperf_delta is limited now
and the multiplication of it by cpu_khz won't overflow, so simplify
the s->khz computations too.

Fixes: 5a70c7cddb75 "x86: use common aperfmperf_khz_on_cpu() to calculate KHz using APERF/MPERF"
Reported-by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
arch/x86/kernel/cpu/aperfmperf.c