Skip to content

Commit 003be8c

Browse files
captain5050acmel
authored andcommitted
perf stat: Make cputype filter generic
Rather than limit the --cputype argument for "perf list" and "perf stat" to hybrid PMUs of just cpu_atom and cpu_core, allow any PMU. Note, that if cpu_atom isn't mounted but a filter of cpu_atom is requested, then this will now fail. As such a filter would never succeed, no events can come from that unmounted PMU, then this behavior could never have been useful and failing is clearer. 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-31-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 411ad22 commit 003be8c

File tree

6 files changed

+47
-35
lines changed

6 files changed

+47
-35
lines changed

tools/perf/builtin-list.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "builtin.h"
1212

1313
#include "util/print-events.h"
14+
#include "util/pmus.h"
1415
#include "util/pmu.h"
15-
#include "util/pmu-hybrid.h"
1616
#include "util/debug.h"
1717
#include "util/metricgroup.h"
1818
#include "util/string2.h"
@@ -429,7 +429,7 @@ int cmd_list(int argc, const char **argv)
429429
.print_event = default_print_event,
430430
.print_metric = default_print_metric,
431431
};
432-
const char *hybrid_name = NULL;
432+
const char *cputype = NULL;
433433
const char *unit_name = NULL;
434434
bool json = false;
435435
struct option list_options[] = {
@@ -443,8 +443,8 @@ int cmd_list(int argc, const char **argv)
443443
"Print information on the perf event names and expressions used internally by events."),
444444
OPT_BOOLEAN(0, "deprecated", &default_ps.deprecated,
445445
"Print deprecated events."),
446-
OPT_STRING(0, "cputype", &hybrid_name, "hybrid cpu type",
447-
"Limit PMU or metric printing to the given hybrid PMU (e.g. core or atom)."),
446+
OPT_STRING(0, "cputype", &cputype, "cpu type",
447+
"Limit PMU or metric printing to the given PMU (e.g. cpu, core or atom)."),
448448
OPT_STRING(0, "unit", &unit_name, "PMU name",
449449
"Limit PMU or metric printing to the specified PMU."),
450450
OPT_INCR(0, "debug", &verbose,
@@ -484,10 +484,15 @@ int cmd_list(int argc, const char **argv)
484484
assert(default_ps.visited_metrics);
485485
if (unit_name)
486486
default_ps.pmu_glob = strdup(unit_name);
487-
else if (hybrid_name) {
488-
default_ps.pmu_glob = perf_pmu__hybrid_type_to_pmu(hybrid_name);
489-
if (!default_ps.pmu_glob)
490-
pr_warning("WARNING: hybrid cputype is not supported!\n");
487+
else if (cputype) {
488+
const struct perf_pmu *pmu = perf_pmus__pmu_for_pmu_filter(cputype);
489+
490+
if (!pmu) {
491+
pr_err("ERROR: cputype is not supported!\n");
492+
ret = -1;
493+
goto out;
494+
}
495+
default_ps.pmu_glob = pmu->name;
491496
}
492497
}
493498
print_cb.print_start(ps);

tools/perf/builtin-stat.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "util/cgroup.h"
4545
#include <subcmd/parse-options.h>
4646
#include "util/parse-events.h"
47+
#include "util/pmus.h"
4748
#include "util/pmu.h"
4849
#include "util/event.h"
4950
#include "util/evlist.h"
@@ -69,7 +70,6 @@
6970
#include "util/pfm.h"
7071
#include "util/bpf_counter.h"
7172
#include "util/iostat.h"
72-
#include "util/pmu-hybrid.h"
7373
#include "util/util.h"
7474
#include "asm/bug.h"
7575

@@ -1089,22 +1089,24 @@ static int parse_stat_cgroups(const struct option *opt,
10891089
return parse_cgroups(opt, str, unset);
10901090
}
10911091

1092-
static int parse_hybrid_type(const struct option *opt,
1092+
static int parse_cputype(const struct option *opt,
10931093
const char *str,
10941094
int unset __maybe_unused)
10951095
{
1096+
const struct perf_pmu *pmu;
10961097
struct evlist *evlist = *(struct evlist **)opt->value;
10971098

10981099
if (!list_empty(&evlist->core.entries)) {
10991100
fprintf(stderr, "Must define cputype before events/metrics\n");
11001101
return -1;
11011102
}
11021103

1103-
parse_events_option_args.pmu_filter = perf_pmu__hybrid_type_to_pmu(str);
1104-
if (!parse_events_option_args.pmu_filter) {
1104+
pmu = perf_pmus__pmu_for_pmu_filter(str);
1105+
if (!pmu) {
11051106
fprintf(stderr, "--cputype %s is not supported!\n", str);
11061107
return -1;
11071108
}
1109+
parse_events_option_args.pmu_filter = pmu->name;
11081110

11091111
return 0;
11101112
}
@@ -1230,7 +1232,7 @@ static struct option stat_options[] = {
12301232
OPT_CALLBACK(0, "cputype", &evsel_list, "hybrid cpu type",
12311233
"Only enable events on applying cpu with this type "
12321234
"for hybrid platform (e.g. core or atom)",
1233-
parse_hybrid_type),
1235+
parse_cputype),
12341236
#ifdef HAVE_LIBPFM
12351237
OPT_CALLBACK(0, "pfm-events", &evsel_list, "event",
12361238
"libpfm4 event selector. use 'perf list' to list available events",

tools/perf/util/pmu-hybrid.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,3 @@ bool perf_pmu__is_hybrid(const char *name)
5050
{
5151
return perf_pmu__find_hybrid_pmu(name) != NULL;
5252
}
53-
54-
char *perf_pmu__hybrid_type_to_pmu(const char *type)
55-
{
56-
char *pmu_name = NULL;
57-
58-
if (asprintf(&pmu_name, "cpu_%s", type) < 0)
59-
return NULL;
60-
61-
if (perf_pmu__is_hybrid(pmu_name))
62-
return pmu_name;
63-
64-
/*
65-
* pmu may be not scanned, check the sysfs.
66-
*/
67-
if (perf_pmu__hybrid_mounted(pmu_name))
68-
return pmu_name;
69-
70-
free(pmu_name);
71-
return NULL;
72-
}

tools/perf/util/pmu-hybrid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ bool perf_pmu__hybrid_mounted(const char *name);
1717

1818
struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name);
1919
bool perf_pmu__is_hybrid(const char *name);
20-
char *perf_pmu__hybrid_type_to_pmu(const char *type);
2120

2221
static inline int perf_pmu__hybrid_pmu_num(void)
2322
{

tools/perf/util/pmus.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/list.h>
3-
#include <pmus.h>
3+
#include <string.h>
4+
#include "pmus.h"
5+
#include "pmu.h"
46

57
LIST_HEAD(pmus);
8+
9+
const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str)
10+
{
11+
struct perf_pmu *pmu = NULL;
12+
13+
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
14+
if (!strcmp(pmu->name, str))
15+
return pmu;
16+
/* Ignore "uncore_" prefix. */
17+
if (!strncmp(pmu->name, "uncore_", 7)) {
18+
if (!strcmp(pmu->name + 7, str))
19+
return pmu;
20+
}
21+
/* Ignore "cpu_" prefix on Intel hybrid PMUs. */
22+
if (!strncmp(pmu->name, "cpu_", 4)) {
23+
if (!strcmp(pmu->name + 4, str))
24+
return pmu;
25+
}
26+
}
27+
return NULL;
28+
}

tools/perf/util/pmus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#define __PMUS_H
44

55
extern struct list_head pmus;
6+
struct perf_pmu;
67

78
#define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list)
89

10+
const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str);
11+
912
#endif /* __PMUS_H */

0 commit comments

Comments
 (0)