tools/power turbostat: Allow probing RAPL with platform_features->rapl_msrs cleared

platform_features->rapl_msrs describes the RAPL MSRs supported. While
RAPL Perf counters can be exposed from different kernel backend drivers,
e.g. RAPL MSR I/F driver, or RAPL TPMI I/F driver.

Thus, turbostat should first blindly probe all the available RAPL Perf
counters, and falls back to the RAPL MSR counters if they are listed in
platform_features->rapl_msrs.

With this, platforms that don't have RAPL MSRs can clear the
platform_features->rapl_msrs bits and use RAPL Perf counters only.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

authored by Zhang Rui and committed by Len Brown ff3d019e 03623379

+23 -24
+23 -24
tools/power/x86/turbostat/turbostat.c
··· 2245 return 1; 2246 } 2247 2248 - int add_rapl_msr_counter(int cpu, off_t offset, int index) 2249 { 2250 int ret; 2251 2252 - ret = add_msr_counter(cpu, offset); 2253 if (ret < 0) 2254 return -1; 2255 2256 - switch (index) { 2257 case RAPL_RCI_INDEX_ENERGY_PKG: 2258 case RAPL_RCI_INDEX_ENERGY_CORES: 2259 case RAPL_RCI_INDEX_DRAM: ··· 2671 if (DO_BIC(BIC_SYS_LPI)) 2672 outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : "")); 2673 2674 - if (platform->rapl_msrs && !rapl_joules) { 2675 if (DO_BIC(BIC_PkgWatt)) 2676 outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); 2677 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) ··· 2684 outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); 2685 if (DO_BIC(BIC_RAM__)) 2686 outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); 2687 - } else if (platform->rapl_msrs && rapl_joules) { 2688 if (DO_BIC(BIC_Pkg_J)) 2689 outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); 2690 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) ··· 7991 7992 struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[next_domain]; 7993 7994 - /* Check if the counter is enabled and accessible */ 7995 - if (platform->rapl_msrs & cai->feature_mask) { 7996 7997 - /* Use perf API for this counter */ 7998 - if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) { 7999 - rci->source[cai->rci_index] = COUNTER_SOURCE_PERF; 8000 - rci->scale[cai->rci_index] = scale * cai->compat_scale; 8001 - rci->unit[cai->rci_index] = unit; 8002 - rci->flags[cai->rci_index] = cai->flags; 8003 - 8004 - /* Use MSR for this counter */ 8005 - } else if (add_rapl_msr_counter(cpu, cai->msr, cai->rci_index) >= 0) { 8006 - rci->source[cai->rci_index] = COUNTER_SOURCE_MSR; 8007 - rci->msr[cai->rci_index] = cai->msr; 8008 - rci->msr_mask[cai->rci_index] = cai->msr_mask; 8009 - rci->msr_shift[cai->rci_index] = cai->msr_shift; 8010 - rci->unit[cai->rci_index] = RAPL_UNIT_JOULES; 8011 - rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale; 8012 - rci->flags[cai->rci_index] = cai->flags; 8013 - } 8014 } 8015 8016 if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE)
··· 2245 return 1; 2246 } 2247 2248 + int add_rapl_msr_counter(int cpu, const struct rapl_counter_arch_info *cai) 2249 { 2250 int ret; 2251 2252 + if (!(platform->rapl_msrs & cai->feature_mask)) 2253 + return -1; 2254 + 2255 + ret = add_msr_counter(cpu, cai->msr); 2256 if (ret < 0) 2257 return -1; 2258 2259 + switch (cai->rci_index) { 2260 case RAPL_RCI_INDEX_ENERGY_PKG: 2261 case RAPL_RCI_INDEX_ENERGY_CORES: 2262 case RAPL_RCI_INDEX_DRAM: ··· 2668 if (DO_BIC(BIC_SYS_LPI)) 2669 outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : "")); 2670 2671 + if (!rapl_joules) { 2672 if (DO_BIC(BIC_PkgWatt)) 2673 outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); 2674 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) ··· 2681 outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); 2682 if (DO_BIC(BIC_RAM__)) 2683 outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); 2684 + } else { 2685 if (DO_BIC(BIC_Pkg_J)) 2686 outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); 2687 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) ··· 7988 7989 struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[next_domain]; 7990 7991 + /* Use perf API for this counter */ 7992 + if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) { 7993 + rci->source[cai->rci_index] = COUNTER_SOURCE_PERF; 7994 + rci->scale[cai->rci_index] = scale * cai->compat_scale; 7995 + rci->unit[cai->rci_index] = unit; 7996 + rci->flags[cai->rci_index] = cai->flags; 7997 7998 + /* Use MSR for this counter */ 7999 + } else if (add_rapl_msr_counter(cpu, cai) >= 0) { 8000 + rci->source[cai->rci_index] = COUNTER_SOURCE_MSR; 8001 + rci->msr[cai->rci_index] = cai->msr; 8002 + rci->msr_mask[cai->rci_index] = cai->msr_mask; 8003 + rci->msr_shift[cai->rci_index] = cai->msr_shift; 8004 + rci->unit[cai->rci_index] = RAPL_UNIT_JOULES; 8005 + rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale; 8006 + rci->flags[cai->rci_index] = cai->flags; 8007 } 8008 8009 if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE)