Skip to content

Commit 6907852

Browse files
zhang-ruilenb
authored andcommitted
tools/power turbostat: Avoid probing the same perf counters
For the RAPL package energy status counter, Intel and AMD share the same perf_subsys and perf_name, but with different MSR addresses. Both rapl_counter_arch_infos[0] and rapl_counter_arch_infos[1] are introduced to describe this counter for different Vendors. As a result, the perf counter is probed twice, and causes a failure in in get_rapl_counters() because expected_read_size and actual_read_size don't match. Fix the problem by skipping the already probed counter. Note, this is not a perfect fix. For example, if different vendors/platforms use the same MSR value for different purpose, the code can be fooled when it probes a rapl_counter_arch_infos[] entry that does not belong to the running Vendor/Platform. In a long run, better to put rapl_counter_arch_infos[] into the platform_features so that this becomes Vendor/Platform specific. Signed-off-by: Zhang Rui <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent ff3d019 commit 6907852

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7991,6 +7991,21 @@ void rapl_perf_init(void)
79917991

79927992
struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[next_domain];
79937993

7994+
/*
7995+
* rapl_counter_arch_infos[] can have multiple entries describing the same
7996+
* counter, due to the difference from different platforms/Vendors.
7997+
* E.g. rapl_counter_arch_infos[0] and rapl_counter_arch_infos[1] share the
7998+
* same perf_subsys and perf_name, but with different MSR address.
7999+
* rapl_counter_arch_infos[0] is for Intel and rapl_counter_arch_infos[1]
8000+
* is for AMD.
8001+
* In this case, it is possible that multiple rapl_counter_arch_infos[]
8002+
* entries are probed just because their perf/msr is duplicate and valid.
8003+
*
8004+
* Thus need a check to avoid re-probe the same counters.
8005+
*/
8006+
if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE)
8007+
break;
8008+
79948009
/* Use perf API for this counter */
79958010
if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
79968011
rci->source[cai->rci_index] = COUNTER_SOURCE_PERF;

0 commit comments

Comments
 (0)