Skip to content

Commit b2b9d3a

Browse files
Agustin Vega-Friasacmel
authored andcommitted
perf pmu: Support wildcards on pmu name in dynamic pmu events
Starting on v4.12 event parsing code for dynamic pmu events already supports prefix-based matching of multiple pmus when creating dynamic events. E.g., in a system with the following dynamic pmus: mypmu_0 mypmu_1 mypmu_2 mypmu_4 passing mypmu/<config>/ as an event spec will result in the creation of the event in all of the pmus. This change expands this matching through the use of fnmatch so glob-like expressions can be used to create events in multiple pmus. E.g., in the system described above if a user only wants to create the event in mypmu_0 and mypmu_1, mypmu_[01]/<config>/ can be passed. Signed-off-by: Agustin Vega-Frias <agustinv@codeaurora.org> Acked-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: linux-arm-kernel@lists.infradead.org Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Timur Tabi <timur@codeaurora.org> Change-Id: Icb25653fc5d5239c20f3bffdfdf4ab4c9c9bb20b Link: http://lkml.kernel.org/r/1520454947-16977-1-git-send-email-agustinv@codeaurora.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ea66536 commit b2b9d3a

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

tools/perf/Documentation/perf-list.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ on the first memory controller on socket 0 of a Intel Xeon system
141141

142142
Each memory controller has its own PMU. Measuring the complete system
143143
bandwidth would require specifying all imc PMUs (see perf list output),
144-
and adding the values together.
144+
and adding the values together. To simplify creation of multiple events,
145+
prefix and glob matching is supported in the PMU name, and the prefix
146+
'uncore_' is also ignored when performing the match. So the command above
147+
can be expanded to all memory controllers by using the syntaxes:
148+
149+
perf stat -C 0 -a imc/cas_count_read/,imc/cas_count_write/ -I 1000 ...
150+
perf stat -C 0 -a *imc*/cas_count_read/,*imc*/cas_count_write/ -I 1000 ...
145151

146152
This example measures the combined core power every second
147153

tools/perf/Documentation/perf-stat.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ report::
4949
parameters are defined by corresponding entries in
5050
/sys/bus/event_source/devices/<pmu>/format/*
5151

52+
Note that the last two syntaxes support prefix and glob matching in
53+
the PMU name to simplify creation of events accross multiple instances
54+
of the same type of PMU in large systems (e.g. memory controller PMUs).
55+
Multiple PMU instances are typical for uncore PMUs, so the prefix
56+
'uncore_' is also ignored when performing this match.
57+
58+
5259
-i::
5360
--no-inherit::
5461
child tasks do not inherit counters
@@ -260,6 +267,12 @@ taskset.
260267
--no-merge::
261268
Do not merge results from same PMUs.
262269

270+
When multiple events are created from a single event alias, stat will,
271+
by default, aggregate the event counts and show the result in a single
272+
row. This option disables that behavior and shows the individual events
273+
and counts. Aliases are listed immediately after the Kernel PMU events
274+
by perf list.
275+
263276
--smi-cost::
264277
Measure SMI cost if msr/aperf/ and msr/smi/ events are supported.
265278

tools/perf/util/parse-events.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bpf_source [^,{}]+\.c[a-zA-Z0-9._]*
175175
num_dec [0-9]+
176176
num_hex 0x[a-fA-F0-9]+
177177
num_raw_hex [a-fA-F0-9]+
178-
name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
178+
name [a-zA-Z_*?\[\]][a-zA-Z0-9_*?.\[\]]*
179179
name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*
180180
drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
181181
/* If you add a modifier you need to update check_modifier() */

tools/perf/util/parse-events.y

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define YYDEBUG 1
1010

11+
#include <fnmatch.h>
1112
#include <linux/compiler.h>
1213
#include <linux/list.h>
1314
#include <linux/types.h>
@@ -234,21 +235,30 @@ PE_NAME opt_event_config
234235
if (parse_events_add_pmu(_parse_state, list, $1, $2)) {
235236
struct perf_pmu *pmu = NULL;
236237
int ok = 0;
238+
char *pattern;
239+
240+
if (asprintf(&pattern, "%s*", $1) < 0)
241+
YYABORT;
237242

238243
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
239244
char *name = pmu->name;
240245

241246
if (!strncmp(name, "uncore_", 7) &&
242247
strncmp($1, "uncore_", 7))
243248
name += 7;
244-
if (!strncmp($1, name, strlen($1))) {
245-
if (parse_events_copy_term_list(orig_terms, &terms))
249+
if (!fnmatch(pattern, name, 0)) {
250+
if (parse_events_copy_term_list(orig_terms, &terms)) {
251+
free(pattern);
246252
YYABORT;
253+
}
247254
if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms))
248255
ok++;
249256
parse_events_terms__delete(terms);
250257
}
251258
}
259+
260+
free(pattern);
261+
252262
if (!ok)
253263
YYABORT;
254264
}

0 commit comments

Comments
 (0)