Skip to content

Commit 6d6501d

Browse files
committed
tools/power/turbostat: Read energy_perf_bias from sysfs
... instead of poking at the MSR directly. Signed-off-by: Borislav Petkov <[email protected]> Cc: Len Brown <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 8113ab2 commit 6d6501d

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,25 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp)
17211721
return 0;
17221722
}
17231723

1724+
int get_epb(int cpu)
1725+
{
1726+
char path[128 + PATH_BYTES];
1727+
int ret, epb = -1;
1728+
FILE *fp;
1729+
1730+
sprintf(path, "/sys/devices/system/cpu/cpu%d/power/energy_perf_bias", cpu);
1731+
1732+
fp = fopen_or_die(path, "r");
1733+
1734+
ret = fscanf(fp, "%d", &epb);
1735+
if (ret != 1)
1736+
err(1, "%s(%s)", __func__, path);
1737+
1738+
fclose(fp);
1739+
1740+
return epb;
1741+
}
1742+
17241743
void get_apic_id(struct thread_data *t)
17251744
{
17261745
unsigned int eax, ebx, ecx, edx;
@@ -3631,9 +3650,8 @@ dump_sysfs_pstate_config(void)
36313650
*/
36323651
int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p)
36333652
{
3634-
unsigned long long msr;
36353653
char *epb_string;
3636-
int cpu;
3654+
int cpu, epb;
36373655

36383656
if (!has_epb)
36393657
return 0;
@@ -3649,10 +3667,11 @@ int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p)
36493667
return -1;
36503668
}
36513669

3652-
if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr))
3670+
epb = get_epb(cpu);
3671+
if (epb < 0)
36533672
return 0;
36543673

3655-
switch (msr & 0xF) {
3674+
switch (epb) {
36563675
case ENERGY_PERF_BIAS_PERFORMANCE:
36573676
epb_string = "performance";
36583677
break;
@@ -3666,7 +3685,7 @@ int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p)
36663685
epb_string = "custom";
36673686
break;
36683687
}
3669-
fprintf(outf, "cpu%d: MSR_IA32_ENERGY_PERF_BIAS: 0x%08llx (%s)\n", cpu, msr, epb_string);
3688+
fprintf(outf, "cpu%d: EPB: %d (%s)\n", cpu, epb, epb_string);
36703689

36713690
return 0;
36723691
}

0 commit comments

Comments
 (0)