Re: [PATCH] x86: Calculate MHz using APERF/MPERF for cpuinfo and scaling_cur_freq

From: Peter Zijlstra
Date: Fri Apr 01 2016 - 04:16:48 EST


On Fri, Apr 01, 2016 at 12:37:00AM -0400, Len Brown wrote:
> From: Len Brown <len.brown@xxxxxxxxx>
>
> For x86 processors with APERF/MPERF and TSC,
> return meaningful and consistent MHz in
> /proc/cpuinfo and
> /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
>
> MHz is computed like so:
>
> MHz = base_MHz * delta_APERF / delta_MPERF
>
> MHz is the average frequency of the busy processor
> over a measurement interval. The interval is
> defined to be the time between successive reads
> of the frequency on that processor, whether from
> /proc/cpuinfo or from sysfs cpufreq/scaling_cur_freq.
> As with previous methods of calculating MHz,
> idle time is excluded.

Is this really a semantic you want to pin down?

Since we're looking at doing something like:

lkml.kernel.org/r/20160303162829.GB6375@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

We could also just return cpu_khz * whatever fraction we store there,
knowing it is something recent.