lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 28 Jul 2017 14:26:56 +0200
From:   "Rafael J. Wysocki" <rjw@...ysocki.net>
To:     Doug Smythies <dsmythies@...us.net>
Cc:     'Len Brown' <lenb@...nel.org>, rafael@...nel.org,
        tglx@...utronix.de, srinivas.pandruvada@...ux.intel.com,
        peterz@...radead.org, linux-kernel@...r.kernel.org,
        'Len Brown' <len.brown@...el.com>, x86@...nel.org,
        linux-pm@...r.kernel.org
Subject: Re: [PATCH] cpufreq: x86: Make scaling_cur_freq behave more as expected

On Thursday, July 27, 2017 11:01:39 PM Doug Smythies wrote:
> On 2017.07.27 17:13 Rafael J. Wysocki wrote:
> 
> > From: Rafael J. Wysocki <rafael.j.wysocki@...el.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@...us.net>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@...el.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.

Right, that's a good point.

I'll send a v2 with this change included shortly.

Thanks,
Rafael

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ