Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1698486
| From | "Doug Smythies" <dsmythies@telus.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | RE: [PATCH] cpufreq: x86: Make scaling_cur_freq behave more as expected |
| Date | 2017-07-28 08:10 +0200 |
| Message-ID | <u86Df-8nH-3@gated-at.bofh.it> (permalink) |
| References | <tVLEd-3Fl-3@gated-at.bofh.it> <u7gOm-s4-17@gated-at.bofh.it> <u86Df-8nH-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 2017.07.27 17:13 Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> After commit f8475cef9008 "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
> aperfmperf_snapshot_khz() call which may be stale. However, the
> interface is expected to return meaningful values on every read,
> including the first one.
>
> To address this problem 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) and
> adjust aperfmperf_snapshot_khz() for that.
>
> Fixes: f8475cef9008 "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 | 36 +++++++++++++++++++++++++++++-------
> 1 file changed, 29 insertions(+), 7 deletions(-)
>
> Index: linux-pm/arch/x86/kernel/cpu/aperfmperf.c
...[deleted the rest]...
This proposed patch would be good. However, I can only try it maybe by Sunday.
I think the maximum time span means that this code:
/*
* if (cpu_khz * aperf_delta) fits into ULLONG_MAX, then
* khz = (cpu_khz * aperf_delta) / mperf_delta
*/
if (div64_u64(ULLONG_MAX, cpu_khz) > aperf_delta)
s->khz = div64_u64((cpu_khz * aperf_delta), mperf_delta);
else /* khz = aperf_delta / (mperf_delta / cpu_khz) */
s->khz = div64_u64(aperf_delta,
div64_u64(mperf_delta, cpu_khz));
Could be reduced to this:
s->khz = div64_u64((cpu_khz * aperf_delta), mperf_delta);
Because it could never overflow anymore.
... Doug
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
RE: [PATCH 2/4 v2] x86: use common aperfmperf_khz_on_cpu() to calculate KHz using APERF/MPERF "Doug Smythies" <dsmythies@telus.net> - 2017-07-26 00:50 +0200
Re: [PATCH 2/4 v2] x86: use common aperfmperf_khz_on_cpu() to calculate KHz using APERF/MPERF Len Brown <lenb@kernel.org> - 2017-07-26 19:30 +0200
[PATCH] cpufreq: x86: Make scaling_cur_freq behave more as expected "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-07-28 02:30 +0200
[PATCH v2] cpufreq: x86: Make scaling_cur_freq behave more as expected "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-07-28 15:00 +0200
RE: [PATCH] cpufreq: x86: Make scaling_cur_freq behave more as expected "Doug Smythies" <dsmythies@telus.net> - 2017-07-28 08:10 +0200
Re: [PATCH] cpufreq: x86: Make scaling_cur_freq behave more as expected "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2017-07-28 14:40 +0200
csiph-web