Skip to content

Commit 7f1b11b

Browse files
committed
tools/power/turbostat: Fallback to an MSR read for EPB
Commit 6d6501d ("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: 6d6501d ("tools/power/turbostat: Read energy_perf_bias from sysfs") Reported-by: Artem Bityutskiy <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Tested-by: Artem Bityutskiy <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 8acf417 commit 7f1b11b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,12 +1834,15 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp)
18341834
int get_epb(int cpu)
18351835
{
18361836
char path[128 + PATH_BYTES];
1837+
unsigned long long msr;
18371838
int ret, epb = -1;
18381839
FILE *fp;
18391840

18401841
sprintf(path, "/sys/devices/system/cpu/cpu%d/power/energy_perf_bias", cpu);
18411842

1842-
fp = fopen_or_die(path, "r");
1843+
fp = fopen(path, "r");
1844+
if (!fp)
1845+
goto msr_fallback;
18431846

18441847
ret = fscanf(fp, "%d", &epb);
18451848
if (ret != 1)
@@ -1848,6 +1851,11 @@ int get_epb(int cpu)
18481851
fclose(fp);
18491852

18501853
return epb;
1854+
1855+
msr_fallback:
1856+
get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr);
1857+
1858+
return msr & 0xf;
18511859
}
18521860

18531861
void get_apic_id(struct thread_data *t)

0 commit comments

Comments
 (0)