lscpu: read MHZ from /sys/.../cpufreq/scaling_cur_freq
This is more portable and provides more stable results than /proc/cpuinfo. Fixes: https://github.com/karelzak/util-linux/pull/1317 Co-Author: Thomas Weißschuh Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
0b538002da
commit
f2d08d4ddc
|
@ -546,6 +546,16 @@ static int read_mhz(struct lscpu_cxt *cxt, struct lscpu_cpu *cpu)
|
|||
if (ul_path_readf_s32(sys, &mhz, "cpu%d/cpufreq/cpuinfo_min_freq", num) == 0)
|
||||
cpu->mhz_min_freq = (float) mhz / 1000;
|
||||
|
||||
/* The default current-frequency value comes is from /proc/cpuinfo (if
|
||||
* available). This /proc value is usually based on MSR registers
|
||||
* (APERF/APERF) and it changes pretty often. It seems better to read
|
||||
* frequency from cpufreq subsystem that provides the current frequency
|
||||
* for the current policy. There is also cpuinfo_cur_freq in sysfs, but
|
||||
* it's not always available.
|
||||
*/
|
||||
if (ul_path_readf_s32(sys, &mhz, "cpu%d/cpufreq/scaling_cur_freq", num) == 0)
|
||||
cpu->mhz_cur_freq = (float) mhz / 1000;
|
||||
|
||||
if (cpu->type && (cpu->mhz_min_freq || cpu->mhz_max_freq))
|
||||
cpu->type->has_freq = 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue