Skip to content

Commit ff3d019

Browse files
zhang-ruilenb
authored andcommitted
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 <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 0362337 commit ff3d019

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,15 +2245,18 @@ int add_msr_counter(int cpu, off_t offset)
22452245
return 1;
22462246
}
22472247

2248-
int add_rapl_msr_counter(int cpu, off_t offset, int index)
2248+
int add_rapl_msr_counter(int cpu, const struct rapl_counter_arch_info *cai)
22492249
{
22502250
int ret;
22512251

2252-
ret = add_msr_counter(cpu, offset);
2252+
if (!(platform->rapl_msrs & cai->feature_mask))
2253+
return -1;
2254+
2255+
ret = add_msr_counter(cpu, cai->msr);
22532256
if (ret < 0)
22542257
return -1;
22552258

2256-
switch (index) {
2259+
switch (cai->rci_index) {
22572260
case RAPL_RCI_INDEX_ENERGY_PKG:
22582261
case RAPL_RCI_INDEX_ENERGY_CORES:
22592262
case RAPL_RCI_INDEX_DRAM:
@@ -2668,7 +2671,7 @@ void print_header(char *delim)
26682671
if (DO_BIC(BIC_SYS_LPI))
26692672
outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : ""));
26702673

2671-
if (platform->rapl_msrs && !rapl_joules) {
2674+
if (!rapl_joules) {
26722675
if (DO_BIC(BIC_PkgWatt))
26732676
outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : ""));
26742677
if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl)
@@ -2681,7 +2684,7 @@ void print_header(char *delim)
26812684
outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : ""));
26822685
if (DO_BIC(BIC_RAM__))
26832686
outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : ""));
2684-
} else if (platform->rapl_msrs && rapl_joules) {
2687+
} else {
26852688
if (DO_BIC(BIC_Pkg_J))
26862689
outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : ""));
26872690
if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl)
@@ -7988,26 +7991,22 @@ void rapl_perf_init(void)
79887991

79897992
struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[next_domain];
79907993

7991-
/* Check if the counter is enabled and accessible */
7992-
if (platform->rapl_msrs & cai->feature_mask) {
7993-
7994-
/* Use perf API for this counter */
7995-
if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
7996-
rci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
7997-
rci->scale[cai->rci_index] = scale * cai->compat_scale;
7998-
rci->unit[cai->rci_index] = unit;
7999-
rci->flags[cai->rci_index] = cai->flags;
8000-
8001-
/* Use MSR for this counter */
8002-
} else if (add_rapl_msr_counter(cpu, cai->msr, cai->rci_index) >= 0) {
8003-
rci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
8004-
rci->msr[cai->rci_index] = cai->msr;
8005-
rci->msr_mask[cai->rci_index] = cai->msr_mask;
8006-
rci->msr_shift[cai->rci_index] = cai->msr_shift;
8007-
rci->unit[cai->rci_index] = RAPL_UNIT_JOULES;
8008-
rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale;
8009-
rci->flags[cai->rci_index] = cai->flags;
8010-
}
7994+
/* Use perf API for this counter */
7995+
if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
7996+
rci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
7997+
rci->scale[cai->rci_index] = scale * cai->compat_scale;
7998+
rci->unit[cai->rci_index] = unit;
7999+
rci->flags[cai->rci_index] = cai->flags;
8000+
8001+
/* Use MSR for this counter */
8002+
} else if (add_rapl_msr_counter(cpu, cai) >= 0) {
8003+
rci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
8004+
rci->msr[cai->rci_index] = cai->msr;
8005+
rci->msr_mask[cai->rci_index] = cai->msr_mask;
8006+
rci->msr_shift[cai->rci_index] = cai->msr_shift;
8007+
rci->unit[cai->rci_index] = RAPL_UNIT_JOULES;
8008+
rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale;
8009+
rci->flags[cai->rci_index] = cai->flags;
80118010
}
80128011

80138012
if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE)

0 commit comments

Comments
 (0)