Skip to content

Commit 7c6fee2

Browse files
Patryk Wlazlynlenb
authored andcommitted
tools/power turbostat: Check for non-zero value when MSR probing
For some MSRs, for example, the Platform Energy Counter (RAPL PSYS), it is required to additionally check for a non-zero value to confirm that it is present. From Intel SDM vol. 4: Platform Energy Counter (R/O) This MSR is valid only if both platform vendor hardware implementation and BIOS enablement support it. This MSR will read 0 if not valid. Signed-off-by: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 1af5bae commit 7c6fee2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,13 +2113,17 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr)
21132113
int probe_msr(int cpu, off_t offset)
21142114
{
21152115
ssize_t retval;
2116-
unsigned long long dummy;
2116+
unsigned long long value;
21172117

21182118
assert(!no_msr);
21192119

2120-
retval = pread(get_msr_fd(cpu), &dummy, sizeof(dummy), offset);
2120+
retval = pread(get_msr_fd(cpu), &value, sizeof(value), offset);
21212121

2122-
if (retval != sizeof(dummy))
2122+
/*
2123+
* Expect MSRs to accumulate some non-zero value since the system was powered on.
2124+
* Treat zero as a read failure.
2125+
*/
2126+
if (retval != sizeof(value) || value == 0)
21232127
return 1;
21242128

21252129
return 0;

0 commit comments

Comments
 (0)