Skip to content

Commit d9dc887

Browse files
captain5050acmel
authored andcommitted
perf pmu-events: Remove now unused event and metric variables
Previous changes separated the uses of pmu_event and pmu_metric, however, both structures contained all the variables of event and metric. This change removes the event variables from metric and the metric variables from event. Note, this change removes the setting of evsel's metric_name/expr as these fields are no longer part of struct pmu_event. The metric remains but is no longer implicitly requested when the event is. This impacts a few Intel uncore events, however, as the ScaleUnit is shared by the event and the metric this utility is questionable. Also the MetricNames look broken (contain spaces) in some cases and when trying to use the functionality with '-e' the metrics fail but regular metrics with '-M' work. For example, on SkylakeX '-M' works: ``` $ perf stat -M LLC_MISSES.PCIE_WRITE -a sleep 1 Performance counter stats for 'system wide': 0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 # 57896.0 Bytes LLC_MISSES.PCIE_WRITE (49.84%) 7,174 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 (49.85%) 0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 (50.16%) 63 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 (50.15%) 1.004576381 seconds time elapsed ``` whilst the event '-e' version is broken even with --group/-g (fwiw, we should also remove -g [1]): ``` $ perf stat -g -e LLC_MISSES.PCIE_WRITE -g -a sleep 1 Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Performance counter stats for 'system wide': 27,316 Bytes LLC_MISSES.PCIE_WRITE 1.004505469 seconds time elapsed ``` The code also carries warnings where the user is supposed to select events for metrics [2] but given the lack of use of such a feature, let's clean the code and just remove. [1] https://lore.kernel.org/lkml/20220707195610.303254-1-irogers@google.com/ [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/stat-shadow.c?id=01b8957b738f42f96a130079bc951b3cc78c5b8a#n425 Reviewed-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Kajol Jain <kjain@linux.ibm.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Caleb Biggers <caleb.biggers@intel.com> Cc: Florian Fischer <florian.fischer@muhq.space> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Kang Minchul <tegongkang@gmail.com> Cc: Kim Phillips <kim.phillips@amd.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Perry Taylor <perry.taylor@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Rob Herring <robh@kernel.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Stephane Eranian <eranian@google.com> Cc: Will Deacon <will@kernel.org> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Link: https://lore.kernel.org/r/20230126233645.200509-7-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 96d2a74 commit d9dc887

File tree

9 files changed

+36
-134
lines changed

9 files changed

+36
-134
lines changed

tools/perf/builtin-list.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
9999
const char *scale_unit __maybe_unused,
100100
bool deprecated, const char *event_type_desc,
101101
const char *desc, const char *long_desc,
102-
const char *encoding_desc,
103-
const char *metric_name, const char *metric_expr)
102+
const char *encoding_desc)
104103
{
105104
struct print_state *print_state = ps;
106105
int pos;
@@ -159,10 +158,6 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
159158
if (print_state->detailed && encoding_desc) {
160159
printf("%*s", 8, "");
161160
wordwrap(encoding_desc, 8, pager_get_columns(), 0);
162-
if (metric_name)
163-
printf(" MetricName: %s", metric_name);
164-
if (metric_expr)
165-
printf(" MetricExpr: %s", metric_expr);
166161
putchar('\n');
167162
}
168163
}
@@ -308,8 +303,7 @@ static void json_print_event(void *ps, const char *pmu_name, const char *topic,
308303
const char *scale_unit,
309304
bool deprecated, const char *event_type_desc,
310305
const char *desc, const char *long_desc,
311-
const char *encoding_desc,
312-
const char *metric_name, const char *metric_expr)
306+
const char *encoding_desc)
313307
{
314308
struct json_print_state *print_state = ps;
315309
bool need_sep = false;
@@ -366,16 +360,6 @@ static void json_print_event(void *ps, const char *pmu_name, const char *topic,
366360
encoding_desc);
367361
need_sep = true;
368362
}
369-
if (metric_name) {
370-
fix_escape_printf(&buf, "%s\t\"MetricName\": \"%S\"", need_sep ? ",\n" : "",
371-
metric_name);
372-
need_sep = true;
373-
}
374-
if (metric_expr) {
375-
fix_escape_printf(&buf, "%s\t\"MetricExpr\": \"%S\"", need_sep ? ",\n" : "",
376-
metric_expr);
377-
need_sep = true;
378-
}
379363
printf("%s}", need_sep ? "\n" : "");
380364
strbuf_release(&buf);
381365
}

tools/perf/pmu-events/jevents.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
'metric_constraint', 'metric_expr', 'long_desc'
3838
]
3939

40+
# Attributes that are in pmu_metric rather than pmu_event.
41+
_json_metric_attributes = [
42+
'metric_name', 'metric_group', 'metric_constraint', 'metric_expr', 'desc',
43+
'long_desc', 'unit', 'compat', 'aggr_mode'
44+
]
4045

4146
def removesuffix(s: str, suffix: str) -> str:
4247
"""Remove the suffix from a string
@@ -569,21 +574,28 @@ def print_system_mapping_table() -> None:
569574
\tconst char *p = &big_c_string[offset];
570575
""")
571576
for attr in _json_event_attributes:
572-
_args.output_file.write(f"""
577+
if attr in _json_metric_attributes and 'metric_' in attr:
578+
_args.output_file.write(f'\n\t/* Skip {attr} */\n')
579+
else:
580+
_args.output_file.write(f"""
573581
\tpe->{attr} = (*p == '\\0' ? NULL : p);
574582
""")
575583
if attr == _json_event_attributes[-1]:
576584
continue
577585
_args.output_file.write('\twhile (*p++);')
578586
_args.output_file.write("""}
579-
static void decompress_metric(int offset, struct pmu_metric *pe)
587+
588+
static void decompress_metric(int offset, struct pmu_metric *pm)
580589
{
581590
\tconst char *p = &big_c_string[offset];
582591
""")
583592
for attr in _json_event_attributes:
584-
_args.output_file.write(f"""
585-
\tpe->{attr} = (*p == '\\0' ? NULL : p);
593+
if attr in _json_metric_attributes:
594+
_args.output_file.write(f"""
595+
\tpm->{attr} = (*p == '\\0' ? NULL : p);
586596
""")
597+
else:
598+
_args.output_file.write(f'\n\t/* Skip {attr} */\n')
587599
if attr == _json_event_attributes[-1]:
588600
continue
589601
_args.output_file.write('\twhile (*p++);')

tools/perf/pmu-events/pmu-events.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,19 @@ struct pmu_event {
2323
const char *unit;
2424
const char *perpkg;
2525
const char *aggr_mode;
26-
const char *metric_expr;
27-
const char *metric_name;
28-
const char *metric_group;
2926
const char *deprecated;
30-
const char *metric_constraint;
3127
};
3228

3329
struct pmu_metric {
34-
const char *name;
35-
const char *compat;
36-
const char *event;
37-
const char *desc;
38-
const char *topic;
39-
const char *long_desc;
40-
const char *pmu;
41-
const char *unit;
42-
const char *perpkg;
43-
const char *aggr_mode;
44-
const char *metric_expr;
4530
const char *metric_name;
4631
const char *metric_group;
47-
const char *deprecated;
32+
const char *metric_expr;
33+
const char *unit;
34+
const char *compat;
35+
const char *aggr_mode;
4836
const char *metric_constraint;
37+
const char *desc;
38+
const char *long_desc;
4939
};
5040

5141
struct pmu_events_table;

tools/perf/tests/pmu-events.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -337,36 +337,12 @@ static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event
337337
return -1;
338338
}
339339

340-
if (!is_same(e1->metric_expr, e2->metric_expr)) {
341-
pr_debug2("testing event e1 %s: mismatched metric_expr, %s vs %s\n",
342-
e1->name, e1->metric_expr, e2->metric_expr);
343-
return -1;
344-
}
345-
346-
if (!is_same(e1->metric_name, e2->metric_name)) {
347-
pr_debug2("testing event e1 %s: mismatched metric_name, %s vs %s\n",
348-
e1->name, e1->metric_name, e2->metric_name);
349-
return -1;
350-
}
351-
352-
if (!is_same(e1->metric_group, e2->metric_group)) {
353-
pr_debug2("testing event e1 %s: mismatched metric_group, %s vs %s\n",
354-
e1->name, e1->metric_group, e2->metric_group);
355-
return -1;
356-
}
357-
358340
if (!is_same(e1->deprecated, e2->deprecated)) {
359341
pr_debug2("testing event e1 %s: mismatched deprecated, %s vs %s\n",
360342
e1->name, e1->deprecated, e2->deprecated);
361343
return -1;
362344
}
363345

364-
if (!is_same(e1->metric_constraint, e2->metric_constraint)) {
365-
pr_debug2("testing event e1 %s: mismatched metric_constant, %s vs %s\n",
366-
e1->name, e1->metric_constraint, e2->metric_constraint);
367-
return -1;
368-
}
369-
370346
return 0;
371347
}
372348

@@ -432,9 +408,6 @@ static int test__pmu_event_table_core_callback(const struct pmu_event *pe,
432408
struct perf_pmu_test_event const **test_event_table;
433409
bool found = false;
434410

435-
if (!pe->name)
436-
return 0;
437-
438411
if (pe->pmu)
439412
test_event_table = &uncore_events[0];
440413
else

tools/perf/util/parse-events.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,6 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
15701570
evsel->scale = info.scale;
15711571
evsel->per_pkg = info.per_pkg;
15721572
evsel->snapshot = info.snapshot;
1573-
evsel->metric_expr = info.metric_expr;
1574-
evsel->metric_name = info.metric_name;
15751573
return 0;
15761574
}
15771575

tools/perf/util/pmu.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,6 @@ static void perf_pmu_update_alias(struct perf_pmu_alias *old,
280280
perf_pmu_assign_str(old->name, "long_desc", &old->long_desc,
281281
&newalias->long_desc);
282282
perf_pmu_assign_str(old->name, "topic", &old->topic, &newalias->topic);
283-
perf_pmu_assign_str(old->name, "metric_expr", &old->metric_expr,
284-
&newalias->metric_expr);
285-
perf_pmu_assign_str(old->name, "metric_name", &old->metric_name,
286-
&newalias->metric_name);
287283
perf_pmu_assign_str(old->name, "value", &old->str, &newalias->str);
288284
old->scale = newalias->scale;
289285
old->per_pkg = newalias->per_pkg;
@@ -299,8 +295,6 @@ void perf_pmu_free_alias(struct perf_pmu_alias *newalias)
299295
zfree(&newalias->long_desc);
300296
zfree(&newalias->topic);
301297
zfree(&newalias->str);
302-
zfree(&newalias->metric_expr);
303-
zfree(&newalias->metric_name);
304298
zfree(&newalias->pmu_name);
305299
parse_events_terms__purge(&newalias->terms);
306300
free(newalias);
@@ -337,16 +331,13 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
337331
int num;
338332
char newval[256];
339333
char *long_desc = NULL, *topic = NULL, *unit = NULL, *perpkg = NULL,
340-
*metric_expr = NULL, *metric_name = NULL, *deprecated = NULL,
341-
*pmu_name = NULL;
334+
*deprecated = NULL, *pmu_name = NULL;
342335

343336
if (pe) {
344337
long_desc = (char *)pe->long_desc;
345338
topic = (char *)pe->topic;
346339
unit = (char *)pe->unit;
347340
perpkg = (char *)pe->perpkg;
348-
metric_expr = (char *)pe->metric_expr;
349-
metric_name = (char *)pe->metric_name;
350341
deprecated = (char *)pe->deprecated;
351342
pmu_name = (char *)pe->pmu;
352343
}
@@ -401,8 +392,6 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
401392
perf_pmu__parse_snapshot(alias, dir, name);
402393
}
403394

404-
alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL;
405-
alias->metric_name = metric_name ? strdup(metric_name): NULL;
406395
alias->desc = desc ? strdup(desc) : NULL;
407396
alias->long_desc = long_desc ? strdup(long_desc) :
408397
desc ? strdup(desc) : NULL;
@@ -756,9 +745,6 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
756745
struct pmu_add_cpu_aliases_map_data *data = vdata;
757746
const char *pname = pe->pmu ? pe->pmu : data->cpu_name;
758747

759-
if (!pe->name)
760-
return 0;
761-
762748
if (data->pmu->is_uncore && pmu_uncore_alias_match(pname, data->name))
763749
goto new_alias;
764750

@@ -813,12 +799,6 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
813799
struct pmu_sys_event_iter_data *idata = data;
814800
struct perf_pmu *pmu = idata->pmu;
815801

816-
if (!pe->name) {
817-
if (pe->metric_group || pe->metric_name)
818-
return 0;
819-
return -EINVAL;
820-
}
821-
822802
if (!pe->compat || !pe->pmu)
823803
return 0;
824804

@@ -1400,8 +1380,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
14001380
info->unit = NULL;
14011381
info->scale = 0.0;
14021382
info->snapshot = false;
1403-
info->metric_expr = NULL;
1404-
info->metric_name = NULL;
14051383

14061384
list_for_each_entry_safe(term, h, head_terms, list) {
14071385
alias = pmu_find_alias(pmu, term);
@@ -1417,8 +1395,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
14171395

14181396
if (alias->per_pkg)
14191397
info->per_pkg = true;
1420-
info->metric_expr = alias->metric_expr;
1421-
info->metric_name = alias->metric_name;
14221398

14231399
list_del_init(&term->list);
14241400
parse_events_term__delete(term);
@@ -1634,8 +1610,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state)
16341610
for (j = 0; j < len; j++) {
16351611
const char *name, *alias = NULL, *scale_unit = NULL,
16361612
*desc = NULL, *long_desc = NULL,
1637-
*encoding_desc = NULL, *topic = NULL,
1638-
*metric_name = NULL, *metric_expr = NULL;
1613+
*encoding_desc = NULL, *topic = NULL;
16391614
bool deprecated = false;
16401615
size_t buf_used;
16411616

@@ -1673,8 +1648,6 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state)
16731648
buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used,
16741649
"%s/%s/", aliases[j].pmu->name,
16751650
aliases[j].event->str) + 1;
1676-
metric_name = aliases[j].event->metric_name;
1677-
metric_expr = aliases[j].event->metric_expr;
16781651
deprecated = aliases[j].event->deprecated;
16791652
}
16801653
print_cb->print_event(print_state,
@@ -1687,9 +1660,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state)
16871660
"Kernel PMU event",
16881661
desc,
16891662
long_desc,
1690-
encoding_desc,
1691-
metric_name,
1692-
metric_expr);
1663+
encoding_desc);
16931664
}
16941665
if (printed && pager_in_use())
16951666
printf("\n");

tools/perf/util/pmu.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ extern struct perf_pmu perf_pmu__fake;
132132

133133
struct perf_pmu_info {
134134
const char *unit;
135-
const char *metric_expr;
136-
const char *metric_name;
137135
double scale;
138136
bool per_pkg;
139137
bool snapshot;
@@ -187,13 +185,6 @@ struct perf_pmu_alias {
187185
* default.
188186
*/
189187
bool deprecated;
190-
/**
191-
* @metric_expr: A metric expression associated with an event. Doing
192-
* this makes little sense due to scale and unit applying to both.
193-
*/
194-
char *metric_expr;
195-
/** @metric_name: A name for the metric. unit applying to both. */
196-
char *metric_name;
197188
/** @pmu_name: The name copied from struct perf_pmu. */
198189
char *pmu_name;
199190
};

0 commit comments

Comments
 (0)