diff options
author | Borislav Petkov <bp@suse.de> | 2021-01-28 22:28:56 +0300 |
---|---|---|
committer | Borislav Petkov <bp@suse.de> | 2021-02-03 13:58:19 +0300 |
commit | 7f1b11ba3564a391169420d98162987a12d0795d (patch) | |
tree | 3b2563f7b5e3e8edaf41a7cc7d015f82fbb5a1ed /tools/power/x86 | |
parent | 8acf417805a5f5c69e9ff66f14cab022c2755161 (diff) | |
download | linux-7f1b11ba3564a391169420d98162987a12d0795d.tar.xz |
tools/power/turbostat: Fallback to an MSR read for EPB
Commit
6d6501d912a9 ("tools/power/turbostat: Read energy_perf_bias from sysfs")
converted turbostat to read the energy_perf_bias value from sysfs.
However, older kernels which do not have that file yet, would fail. For
those, fall back to the MSR reading.
Fixes: 6d6501d912a9 ("tools/power/turbostat: Read energy_perf_bias from sysfs")
Reported-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Tested-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Link: https://lkml.kernel.org/r/20210127132444.981120-1-dedekind1@gmail.com
Diffstat (limited to 'tools/power/x86')
-rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 389ea5209a83..a7c4f0772e53 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1834,12 +1834,15 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) int get_epb(int cpu) { char path[128 + PATH_BYTES]; + unsigned long long msr; int ret, epb = -1; FILE *fp; sprintf(path, "/sys/devices/system/cpu/cpu%d/power/energy_perf_bias", cpu); - fp = fopen_or_die(path, "r"); + fp = fopen(path, "r"); + if (!fp) + goto msr_fallback; ret = fscanf(fp, "%d", &epb); if (ret != 1) @@ -1848,6 +1851,11 @@ int get_epb(int cpu) fclose(fp); return epb; + +msr_fallback: + get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr); + + return msr & 0xf; } void get_apic_id(struct thread_data *t) |