Skip to content

Commit 1ab2e19

Browse files
zhang-ruilenb
authored andcommitted
tools/power turbostat: Introduce add_msr_counter()
probe_rapl_msr() is reused for probing RAPL MSR counters, cstate MSR counters and MPERF/APERF/SMI MSR counters, thus its name is misleading. Similar to add_perf_counter(), introduce add_msr_counter() to probe a counter via MSR. Introduce wrapper function add_rapl_msr_counter() at the same time to add extra check for Zero return value for specified RAPL counters. No functional change intended. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 3403e89 commit 1ab2e19

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,32 +2222,46 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr)
22222222
return 0;
22232223
}
22242224

2225-
int probe_rapl_msr(int cpu, off_t offset, int index)
2225+
int add_msr_counter(int cpu, off_t offset)
22262226
{
22272227
ssize_t retval;
22282228
unsigned long long value;
22292229

2230-
assert(!no_msr);
2230+
if (no_msr)
2231+
return -1;
22312232

22322233
retval = pread(get_msr_fd(cpu), &value, sizeof(value), offset);
22332234

22342235
/* if the read failed, the probe fails */
22352236
if (retval != sizeof(value))
2236-
return 1;
2237+
return -1;
2238+
2239+
if (value == 0)
2240+
return 0;
2241+
2242+
return 1;
2243+
}
2244+
2245+
int add_rapl_msr_counter(int cpu, off_t offset, int index)
2246+
{
2247+
int ret;
2248+
2249+
ret = add_msr_counter(cpu, offset);
2250+
if (ret < 0)
2251+
return -1;
22372252

2238-
/* If an Energy Status Counter MSR returns 0, the probe fails */
22392253
switch (index) {
22402254
case RAPL_RCI_INDEX_ENERGY_PKG:
22412255
case RAPL_RCI_INDEX_ENERGY_CORES:
22422256
case RAPL_RCI_INDEX_DRAM:
22432257
case RAPL_RCI_INDEX_GFX:
22442258
case RAPL_RCI_INDEX_ENERGY_PLATFORM:
2245-
if (value == 0)
2259+
if (ret == 0)
22462260
return 1;
22472261
}
22482262

22492263
/* PKG,DRAM_PERF_STATUS MSRs, can return any value */
2250-
return 0;
2264+
return 1;
22512265
}
22522266

22532267
/* Convert CPU ID to domain ID for given added perf counter. */
@@ -7980,7 +7994,7 @@ void rapl_perf_init(void)
79807994
rci->flags[cai->rci_index] = cai->flags;
79817995

79827996
/* Use MSR for this counter */
7983-
} else if (!no_msr && cai->msr && probe_rapl_msr(cpu, cai->msr, cai->rci_index) == 0) {
7997+
} else if (!no_msr && cai->msr && add_rapl_msr_counter(cpu, cai->msr, cai->rci_index) >= 0) {
79847998
rci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
79857999
rci->msr[cai->rci_index] = cai->msr;
79868000
rci->msr_mask[cai->rci_index] = cai->msr_mask;
@@ -8110,7 +8124,7 @@ void msr_perf_init_(void)
81108124
cai->present = true;
81118125

81128126
/* User MSR for this counter */
8113-
} else if (!no_msr && cai->msr && probe_rapl_msr(cpu, cai->msr, cai->rci_index) == 0) {
8127+
} else if (!no_msr && cai->msr && add_msr_counter(cpu, cai->msr) >= 0) {
81148128
cci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
81158129
cci->msr[cai->rci_index] = cai->msr;
81168130
cci->msr_mask[cai->rci_index] = cai->msr_mask;
@@ -8224,7 +8238,7 @@ void cstate_perf_init_(bool soft_c1)
82248238

82258239
/* User MSR for this counter */
82268240
} else if (!no_msr && cai->msr && pkg_cstate_limit >= cai->pkg_cstate_limit
8227-
&& probe_rapl_msr(cpu, cai->msr, cai->rci_index) == 0) {
8241+
&& add_msr_counter(cpu, cai->msr) >= 0) {
82288242
cci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
82298243
cci->msr[cai->rci_index] = cai->msr;
82308244
}

0 commit comments

Comments
 (0)