Skip to content

Commit 0362337

Browse files
zhang-ruilenb
authored andcommitted
tools/power turbostat: Clean up add perf/msr counter logic
Increase the code readability by moving the no_perf/no_msr flag and the cai->perf_name/cai->msr sanity checks into the counter probe functions. No functional change. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 1ab2e19 commit 0362337

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,9 @@ int add_msr_counter(int cpu, off_t offset)
22302230
if (no_msr)
22312231
return -1;
22322232

2233+
if (!offset)
2234+
return -1;
2235+
22332236
retval = pread(get_msr_fd(cpu), &value, sizeof(value), offset);
22342237

22352238
/* if the read failed, the probe fails */
@@ -7875,6 +7878,9 @@ int add_rapl_perf_counter(int cpu, struct rapl_counter_info_t *rci, const struct
78757878
if (no_perf)
78767879
return -1;
78777880

7881+
if (!cai->perf_name)
7882+
return -1;
7883+
78787884
const double scale = read_perf_scale(cai->perf_subsys, cai->perf_name);
78797885

78807886
if (scale == 0.0)
@@ -7986,15 +7992,14 @@ void rapl_perf_init(void)
79867992
if (platform->rapl_msrs & cai->feature_mask) {
79877993

79887994
/* Use perf API for this counter */
7989-
if (!no_perf && cai->perf_name
7990-
&& add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
7995+
if (add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
79917996
rci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
79927997
rci->scale[cai->rci_index] = scale * cai->compat_scale;
79937998
rci->unit[cai->rci_index] = unit;
79947999
rci->flags[cai->rci_index] = cai->flags;
79958000

79968001
/* Use MSR for this counter */
7997-
} else if (!no_msr && cai->msr && add_rapl_msr_counter(cpu, cai->msr, cai->rci_index) >= 0) {
8002+
} else if (add_rapl_msr_counter(cpu, cai->msr, cai->rci_index) >= 0) {
79988003
rci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
79998004
rci->msr[cai->rci_index] = cai->msr;
80008005
rci->msr_mask[cai->rci_index] = cai->msr_mask;
@@ -8042,6 +8047,9 @@ int add_cstate_perf_counter(int cpu, struct cstate_counter_info_t *cci, const st
80428047
if (no_perf)
80438048
return -1;
80448049

8050+
if (!cai->perf_name)
8051+
return -1;
8052+
80458053
int *pfd_group = get_cstate_perf_group_fd(cci, cai->perf_subsys);
80468054

80478055
if (pfd_group == NULL)
@@ -8073,6 +8081,9 @@ int add_msr_perf_counter(int cpu, struct msr_counter_info_t *cci, const struct m
80738081
if (no_perf)
80748082
return -1;
80758083

8084+
if (!cai->perf_name)
8085+
return -1;
8086+
80768087
const unsigned int type = read_perf_type(cai->perf_subsys);
80778088
const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name);
80788089

@@ -8119,12 +8130,12 @@ void msr_perf_init_(void)
81198130

81208131
if (cai->needed) {
81218132
/* Use perf API for this counter */
8122-
if (!no_perf && cai->perf_name && add_msr_perf_counter(cpu, cci, cai) != -1) {
8133+
if (add_msr_perf_counter(cpu, cci, cai) != -1) {
81238134
cci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
81248135
cai->present = true;
81258136

81268137
/* User MSR for this counter */
8127-
} else if (!no_msr && cai->msr && add_msr_counter(cpu, cai->msr) >= 0) {
8138+
} else if (add_msr_counter(cpu, cai->msr) >= 0) {
81288139
cci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
81298140
cci->msr[cai->rci_index] = cai->msr;
81308141
cci->msr_mask[cai->rci_index] = cai->msr_mask;
@@ -8232,12 +8243,12 @@ void cstate_perf_init_(bool soft_c1)
82328243

82338244
if (counter_needed && counter_supported) {
82348245
/* Use perf API for this counter */
8235-
if (!no_perf && cai->perf_name && add_cstate_perf_counter(cpu, cci, cai) != -1) {
8246+
if (add_cstate_perf_counter(cpu, cci, cai) != -1) {
82368247

82378248
cci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
82388249

82398250
/* User MSR for this counter */
8240-
} else if (!no_msr && cai->msr && pkg_cstate_limit >= cai->pkg_cstate_limit
8251+
} else if (pkg_cstate_limit >= cai->pkg_cstate_limit
82418252
&& add_msr_counter(cpu, cai->msr) >= 0) {
82428253
cci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
82438254
cci->msr[cai->rci_index] = cai->msr;

0 commit comments

Comments
 (0)