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>

authored by Patryk Wlazlyn and committed by Len Brown 7c6fee25 1af5baed

+7 -3
+7 -3
tools/power/x86/turbostat/turbostat.c
··· 2113 int probe_msr(int cpu, off_t offset) 2114 { 2115 ssize_t retval; 2116 - unsigned long long dummy; 2117 2118 assert(!no_msr); 2119 2120 - retval = pread(get_msr_fd(cpu), &dummy, sizeof(dummy), offset); 2121 2122 - if (retval != sizeof(dummy)) 2123 return 1; 2124 2125 return 0;
··· 2113 int probe_msr(int cpu, off_t offset) 2114 { 2115 ssize_t retval; 2116 + unsigned long long value; 2117 2118 assert(!no_msr); 2119 2120 + retval = pread(get_msr_fd(cpu), &value, sizeof(value), offset); 2121 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) 2127 return 1; 2128 2129 return 0;