Skip to content

Commit d7f21df

Browse files
captain5050acmel
authored andcommitted
perf print-events: Print legacy cache events for each PMU
Mirroring parse_events_add_cache, list the legacy name alongside its alias with the PMU. Remove the now unnecessary hybrid logic. Note, the alias output removes the event type descriptor, so: L1-dcache-loads [Hardware cache event] becomes: L1-dcache-loads OR cpu/L1-dcache-loads/ Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Kan Liang <kan.liang@linux.intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ahmad Yasin <ahmad.yasin@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Caleb Biggers <caleb.biggers@intel.com> Cc: Edward Baker <edward.baker@intel.com> Cc: Florian Fischer <florian.fischer@muhq.space> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kang Minchul <tegongkang@gmail.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> 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: Samantha Alt <samantha.alt@intel.com> Cc: Stephane Eranian <eranian@google.com> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Weilin Wang <weilin.wang@intel.com> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: Yang Jihong <yangjihong1@huawei.com> Link: https://lore.kernel.org/r/20230502223851.2234828-26-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 2bdf4d7 commit d7f21df

File tree

3 files changed

+43
-48
lines changed

3 files changed

+43
-48
lines changed

tools/perf/util/parse-events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static int config_attr(struct perf_event_attr *attr,
414414
* contain hyphens and the longest name
415415
* should always be selected.
416416
*/
417-
static int parse_events__decode_legacy_cache(const char *name, int pmu_type, __u64 *config)
417+
int parse_events__decode_legacy_cache(const char *name, int pmu_type, __u64 *config)
418418
{
419419
int len, cache_type = -1, cache_op = -1, cache_result = -1;
420420
const char *name_end = &name[strlen(name) + 1];

tools/perf/util/parse-events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ int parse_events_add_tool(struct parse_events_state *parse_state,
173173
int parse_events_add_cache(struct list_head *list, int *idx, const char *name,
174174
struct parse_events_error *error,
175175
struct list_head *head_config);
176+
int parse_events__decode_legacy_cache(const char *name, int pmu_type, __u64 *config);
176177
int parse_events_add_breakpoint(struct list_head *list, int *idx,
177178
u64 addr, char *type, u64 len);
178179
int parse_events_add_pmu(struct parse_events_state *parse_state,

tools/perf/util/print-events.c

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -230,56 +230,50 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
230230

231231
int print_hwcache_events(const struct print_callbacks *print_cb, void *print_state)
232232
{
233+
struct perf_pmu *pmu = NULL;
233234
const char *event_type_descriptor = event_type_descriptors[PERF_TYPE_HW_CACHE];
234235

235-
for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
236-
for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
237-
/* skip invalid cache type */
238-
if (!evsel__is_cache_op_valid(type, op))
239-
continue;
240-
241-
for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) {
242-
struct perf_pmu *pmu = NULL;
243-
char name[64];
244-
245-
__evsel__hw_cache_type_op_res_name(type, op, res,
246-
name, sizeof(name));
247-
if (!perf_pmu__has_hybrid()) {
248-
if (is_event_supported(PERF_TYPE_HW_CACHE,
249-
type | (op << 8) | (res << 16))) {
250-
print_cb->print_event(print_state,
251-
"cache",
252-
/*pmu_name=*/NULL,
253-
name,
254-
/*event_alias=*/NULL,
255-
/*scale_unit=*/NULL,
256-
/*deprecated=*/false,
257-
event_type_descriptor,
258-
/*desc=*/NULL,
259-
/*long_desc=*/NULL,
260-
/*encoding_desc=*/NULL);
261-
}
236+
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
237+
/*
238+
* Skip uncore PMUs for performance. PERF_TYPE_HW_CACHE type
239+
* attributes can accept software PMUs in the extended type, so
240+
* also skip.
241+
*/
242+
if (pmu->is_uncore || pmu->type == PERF_TYPE_SOFTWARE)
243+
continue;
244+
245+
for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
246+
for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
247+
/* skip invalid cache type */
248+
if (!evsel__is_cache_op_valid(type, op))
262249
continue;
263-
}
264-
perf_pmu__for_each_hybrid_pmu(pmu) {
265-
if (is_event_supported(PERF_TYPE_HW_CACHE,
266-
type | (op << 8) | (res << 16) |
267-
((__u64)pmu->type << PERF_PMU_TYPE_SHIFT))) {
268-
char new_name[128];
269-
snprintf(new_name, sizeof(new_name),
270-
"%s/%s/", pmu->name, name);
271-
print_cb->print_event(print_state,
272-
"cache",
273-
pmu->name,
274-
name,
275-
new_name,
276-
/*scale_unit=*/NULL,
277-
/*deprecated=*/false,
278-
event_type_descriptor,
279-
/*desc=*/NULL,
280-
/*long_desc=*/NULL,
281-
/*encoding_desc=*/NULL);
282-
}
250+
251+
for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) {
252+
char name[64];
253+
char alias_name[128];
254+
__u64 config;
255+
int ret;
256+
257+
__evsel__hw_cache_type_op_res_name(type, op, res,
258+
name, sizeof(name));
259+
260+
ret = parse_events__decode_legacy_cache(name, pmu->type,
261+
&config);
262+
if (ret || !is_event_supported(PERF_TYPE_HW_CACHE, config))
263+
continue;
264+
snprintf(alias_name, sizeof(alias_name), "%s/%s/",
265+
pmu->name, name);
266+
print_cb->print_event(print_state,
267+
"cache",
268+
pmu->name,
269+
name,
270+
alias_name,
271+
/*scale_unit=*/NULL,
272+
/*deprecated=*/false,
273+
event_type_descriptor,
274+
/*desc=*/NULL,
275+
/*long_desc=*/NULL,
276+
/*encoding_desc=*/NULL);
283277
}
284278
}
285279
}

0 commit comments

Comments
 (0)