From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751796AbdG1GBq (ORCPT ); Fri, 28 Jul 2017 02:01:46 -0400 Received: from cmta20.telus.net ([209.171.16.93]:47213 "EHLO cmta20.telus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751778AbdG1GBo (ORCPT ); Fri, 28 Jul 2017 02:01:44 -0400 X-Authority-Analysis: v=2.2 cv=Pe4Qvmpd c=1 sm=1 tr=0 a=zJWegnE7BH9C0Gl4FFgQyA==:117 a=zJWegnE7BH9C0Gl4FFgQyA==:17 a=Pyq9K9CWowscuQLKlpiwfMBGOR0=:19 a=kj9zAlcOel0A:10 a=QyXUC8HyAAAA:8 a=aatUQebYAAAA:8 a=DEiIhCQrTjOTv3MwrR0A:9 a=CjuIK1q_8ugA:10 a=7715FyvI7WU-l6oqrZBK:22 From: "Doug Smythies" To: "'Rafael J. Wysocki'" Cc: "'Len Brown'" , , , , , , "'Len Brown'" , , References: <1498281114-3868-1-git-send-email-lenb@kernel.org> <006201d30595$e0a23870$a1e6a950$@net> at1wdL9D9BxRWat21ddU41 In-Reply-To: at1wdL9D9BxRWat21ddU41 Subject: RE: [PATCH] cpufreq: x86: Make scaling_cur_freq behave more as expected Date: Thu, 27 Jul 2017 23:01:39 -0700 Message-ID: <001901d30766$fc66a3c0$f533eb40$@net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdMHN3dMT65AUHKkRtqiYgoO/1sdvwALZvqA Content-Language: en-ca X-CMAE-Envelope: MS4wfM3iwOwVTg4HD8dq8Qi1wwvxQP6Y5l1tmi/1z7tMNpH3jU89Mp53QmfTHAKxg4HHCDGvw4oVyL+IJl1k9jApjOhHlC37Yj3Ya0wv9RQ6fri+F9cb4qyi h8HgMDjHnmzX2KWlDohbRsZe1bal45LJgjxeoHFKfGfK4iQScpVEU6oySvCnWhov1ksgUK0S7f4qtTYAAPHhcfc8TfyT6imEvvIB3aJoo6yOHWcKcz0Zxzvr omYOeCtI9nrOYQ2+XOW9CPY5wUpMaOSkzDL6qZqt6lc5tG4BHs3WaH6hInm/WeLDejHWTdT0JHrVuCSTlUlCtHCrf95L40Cow1Dl0Im3mUaCF62gfip74djh bQTSJncOyn3uCy3mE2XDBkdtZ20lQzYr+n4hoWcZ23Ybj3mmY8HlU9joD/JQtAke1UhKy5HcanLeWrmxL49MbqLaUpREi4Yc8htDYSKbici2ImQV8os= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017.07.27 17:13 Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > 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 > Signed-off-by: Rafael J. Wysocki > --- > 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