Skip to content

Commit 73ed3c9

Browse files
Patryk Wlazlynlenb
authored andcommitted
tools/power turbostat: Replace enum rapl_source and cstate_source with counter_source
Reuse the enum. It means the same thing in both cases. Signed-off-by: Patryk Wlazlyn <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent c81c8ee commit 73ed3c9

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ enum counter_scope { SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE };
8686
enum counter_type { COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC, COUNTER_K2M };
8787
enum counter_format { FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT, FORMAT_AVERAGE };
8888
enum amperf_source { AMPERF_SOURCE_PERF, AMPERF_SOURCE_MSR };
89-
enum rapl_source { RAPL_SOURCE_NONE, RAPL_SOURCE_PERF, RAPL_SOURCE_MSR };
90-
enum cstate_source { CSTATE_SOURCE_NONE, CSTATE_SOURCE_PERF, CSTATE_SOURCE_MSR };
89+
enum counter_source { COUNTER_SOURCE_NONE, COUNTER_SOURCE_PERF, COUNTER_SOURCE_MSR };
9190

9291
struct sysfs_path {
9392
char path[PATH_BYTES];
@@ -1081,7 +1080,7 @@ enum rapl_unit {
10811080

10821081
struct rapl_counter_info_t {
10831082
unsigned long long data[NUM_RAPL_COUNTERS];
1084-
enum rapl_source source[NUM_RAPL_COUNTERS];
1083+
enum counter_source source[NUM_RAPL_COUNTERS];
10851084
unsigned long long flags[NUM_RAPL_COUNTERS];
10861085
double scale[NUM_RAPL_COUNTERS];
10871086
enum rapl_unit unit[NUM_RAPL_COUNTERS];
@@ -1243,7 +1242,7 @@ enum ccstate_rci_index {
12431242

12441243
struct cstate_counter_info_t {
12451244
unsigned long long data[NUM_CSTATE_COUNTERS];
1246-
enum cstate_source source[NUM_CSTATE_COUNTERS];
1245+
enum counter_source source[NUM_CSTATE_COUNTERS];
12471246
unsigned long long msr[NUM_CSTATE_COUNTERS];
12481247
int fd_perf_core;
12491248
int fd_perf_pkg;
@@ -3601,7 +3600,7 @@ size_t rapl_counter_info_count_perf(const struct rapl_counter_info_t *rci)
36013600
size_t ret = 0;
36023601

36033602
for (int i = 0; i < NUM_RAPL_COUNTERS; ++i)
3604-
if (rci->source[i] == RAPL_SOURCE_PERF)
3603+
if (rci->source[i] == COUNTER_SOURCE_PERF)
36053604
++ret;
36063605

36073606
return ret;
@@ -3612,7 +3611,7 @@ static size_t cstate_counter_info_count_perf(const struct cstate_counter_info_t
36123611
size_t ret = 0;
36133612

36143613
for (int i = 0; i < NUM_CSTATE_COUNTERS; ++i)
3615-
if (cci->source[i] == CSTATE_SOURCE_PERF)
3614+
if (cci->source[i] == COUNTER_SOURCE_PERF)
36163615
++ret;
36173616

36183617
return ret;
@@ -3653,10 +3652,10 @@ int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct
36533652

36543653
for (unsigned int i = 0, pi = 1; i < NUM_RAPL_COUNTERS; ++i) {
36553654
switch (rci->source[i]) {
3656-
case RAPL_SOURCE_NONE:
3655+
case COUNTER_SOURCE_NONE:
36573656
break;
36583657

3659-
case RAPL_SOURCE_PERF:
3658+
case COUNTER_SOURCE_PERF:
36603659
assert(pi < ARRAY_SIZE(perf_data));
36613660
assert(rci->fd_perf != -1);
36623661

@@ -3669,7 +3668,7 @@ int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct
36693668
++pi;
36703669
break;
36713670

3672-
case RAPL_SOURCE_MSR:
3671+
case COUNTER_SOURCE_MSR:
36733672
if (debug)
36743673
fprintf(stderr, "Reading rapl counter via msr at %u\n", i);
36753674

@@ -3791,10 +3790,10 @@ int get_cstate_counters(unsigned int cpu, struct thread_data *t, struct core_dat
37913790

37923791
for (unsigned int i = 0, pi = 0; i < NUM_CSTATE_COUNTERS; ++i) {
37933792
switch (cci->source[i]) {
3794-
case CSTATE_SOURCE_NONE:
3793+
case COUNTER_SOURCE_NONE:
37953794
break;
37963795

3797-
case CSTATE_SOURCE_PERF:
3796+
case COUNTER_SOURCE_PERF:
37983797
assert(pi < ARRAY_SIZE(perf_data));
37993798
assert(cci->fd_perf_core != -1 || cci->fd_perf_pkg != -1);
38003799

@@ -3807,7 +3806,7 @@ int get_cstate_counters(unsigned int cpu, struct thread_data *t, struct core_dat
38073806
++pi;
38083807
break;
38093808

3810-
case CSTATE_SOURCE_MSR:
3809+
case COUNTER_SOURCE_MSR:
38113810
assert(!no_msr);
38123811
if (get_msr(cpu, cci->msr[i], &cci->data[i]))
38133812
return -13 - i;
@@ -3828,7 +3827,7 @@ int get_cstate_counters(unsigned int cpu, struct thread_data *t, struct core_dat
38283827
* when invoked for the thread sibling.
38293828
*/
38303829
#define PERF_COUNTER_WRITE_DATA(out_counter, index) do { \
3831-
if (cci->source[index] != CSTATE_SOURCE_NONE) \
3830+
if (cci->source[index] != COUNTER_SOURCE_NONE) \
38323831
out_counter = cci->data[index]; \
38333832
} while (0)
38343833

@@ -6894,7 +6893,7 @@ void rapl_perf_init(void)
68946893
rci->fd_perf = -1;
68956894
for (size_t i = 0; i < NUM_RAPL_COUNTERS; ++i) {
68966895
rci->data[i] = 0;
6897-
rci->source[i] = RAPL_SOURCE_NONE;
6896+
rci->source[i] = COUNTER_SOURCE_NONE;
68986897
}
68996898
}
69006899

@@ -6936,14 +6935,14 @@ void rapl_perf_init(void)
69366935
/* Use perf API for this counter */
69376936
if (!no_perf && cai->perf_name
69386937
&& add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) {
6939-
rci->source[cai->rci_index] = RAPL_SOURCE_PERF;
6938+
rci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
69406939
rci->scale[cai->rci_index] = scale * cai->compat_scale;
69416940
rci->unit[cai->rci_index] = unit;
69426941
rci->flags[cai->rci_index] = cai->flags;
69436942

69446943
/* Use MSR for this counter */
69456944
} else if (!no_msr && cai->msr && probe_msr(cpu, cai->msr) == 0) {
6946-
rci->source[cai->rci_index] = RAPL_SOURCE_MSR;
6945+
rci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
69476946
rci->msr[cai->rci_index] = cai->msr;
69486947
rci->msr_mask[cai->rci_index] = cai->msr_mask;
69496948
rci->msr_shift[cai->rci_index] = cai->msr_shift;
@@ -6953,7 +6952,7 @@ void rapl_perf_init(void)
69536952
}
69546953
}
69556954

6956-
if (rci->source[cai->rci_index] != RAPL_SOURCE_NONE)
6955+
if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE)
69576956
has_counter = 1;
69586957
}
69596958

@@ -7146,17 +7145,17 @@ void cstate_perf_init_(bool soft_c1)
71467145
/* Use perf API for this counter */
71477146
if (!no_perf && cai->perf_name && add_cstate_perf_counter(cpu, cci, cai) != -1) {
71487147

7149-
cci->source[cai->rci_index] = CSTATE_SOURCE_PERF;
7148+
cci->source[cai->rci_index] = COUNTER_SOURCE_PERF;
71507149

71517150
/* User MSR for this counter */
71527151
} else if (!no_msr && cai->msr && pkg_cstate_limit >= cai->pkg_cstate_limit
71537152
&& probe_msr(cpu, cai->msr) == 0) {
7154-
cci->source[cai->rci_index] = CSTATE_SOURCE_MSR;
7153+
cci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
71557154
cci->msr[cai->rci_index] = cai->msr;
71567155
}
71577156
}
71587157

7159-
if (cci->source[cai->rci_index] != CSTATE_SOURCE_NONE) {
7158+
if (cci->source[cai->rci_index] != COUNTER_SOURCE_NONE) {
71607159
has_counter = true;
71617160
cores_visited[core_id] = true;
71627161
pkg_visited[pkg_id] = true;

0 commit comments

Comments
 (0)