Skip to content

Commit 3a6c51e

Browse files
Jiri Olsaacmel
authored andcommitted
perf parser: Add support to specify rXXX event with pmu
The current rXXXX event specification creates event under PERF_TYPE_RAW pmu type. This change allows to use rXXXX within pmu syntax, so it's type is used via the following syntax: -e 'cpu/r3c/' -e 'cpum_cf/r0/' The XXXX number goes directly to perf_event_attr::config the same way as in '-e rXXXX' event. The perf_event_attr::type is filled with pmu type. Committer testing: So, lets see what goes in perf_event_attr::config for, say, the 'instructions' PERF_TYPE_HARDWARE (0) event, first we should look at how to encode this event as a PERF_TYPE_RAW event for this specific CPU, an AMD Ryzen 5: # cat /sys/devices/cpu/events/instructions event=0xc0 # Then try with it _and_ the instruction, just to see that they are close enough: # perf stat -e rc0,instructions sleep 1 Performance counter stats for 'sleep 1': 919,794 rc0 919,898 instructions 1.000754579 seconds time elapsed 0.000715000 seconds user 0.000000000 seconds sys # Now we should try, before this patch, the PMU event encoding: # perf stat -e cpu/rc0/ sleep 1 event syntax error: 'cpu/rc0/' \___ unknown term valid terms: event,edge,inv,umask,cmask,config,config1,config2,name,period,percore # Now with this patch, the three ways of specifying the 'instructions' CPU counter are accepted: # perf stat -e cpu/rc0/,rc0,instructions sleep 1 Performance counter stats for 'sleep 1': 892,948 cpu/rc0/ 893,052 rc0 893,156 instructions 1.000931819 seconds time elapsed 0.000916000 seconds user 0.000000000 seconds sys # Requested-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Thomas Richter <tmricht@linux.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Link: http://lore.kernel.org/lkml/20200416221405.437788-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e9cfa47 commit 3a6c51e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

tools/perf/Documentation/perf-list.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ raw encoding of 0x1A8 can be used:
115115
perf stat -e r1a8 -a sleep 1
116116
perf record -e r1a8 ...
117117

118+
It's also possible to use pmu syntax:
119+
120+
perf record -e r1a8 -a sleep 1
121+
perf record -e cpu/r1a8/ ...
122+
118123
You should refer to the processor specific documentation for getting these
119124
details. Some of them are referenced in the SEE ALSO section below.
120125

tools/perf/tests/parse-events.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,16 @@ static int test__checkevent_complex_name(struct evlist *evlist)
13561356
return 0;
13571357
}
13581358

1359+
static int test__checkevent_raw_pmu(struct evlist *evlist)
1360+
{
1361+
struct evsel *evsel = evlist__first(evlist);
1362+
1363+
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1364+
TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1365+
TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1366+
return 0;
1367+
}
1368+
13591369
static int test__sym_event_slash(struct evlist *evlist)
13601370
{
13611371
struct evsel *evsel = evlist__first(evlist);
@@ -1750,7 +1760,12 @@ static struct evlist_test test__events_pmu[] = {
17501760
.name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
17511761
.check = test__checkevent_complex_name,
17521762
.id = 3,
1753-
}
1763+
},
1764+
{
1765+
.name = "software/r1a/",
1766+
.check = test__checkevent_raw_pmu,
1767+
.id = 4,
1768+
},
17541769
};
17551770

17561771
struct terms_test {

tools/perf/util/parse-events.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
286286
percore { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_PERCORE); }
287287
aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); }
288288
aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE); }
289+
r{num_raw_hex} { return raw(yyscanner); }
289290
, { return ','; }
290291
"/" { BEGIN(INITIAL); return '/'; }
291292
{name_minus} { return str(yyscanner, PE_NAME); }

tools/perf/util/parse-events.y

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,15 @@ event_term
706706
}
707707

708708
event_term:
709+
PE_RAW
710+
{
711+
struct parse_events_term *term;
712+
713+
ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_CONFIG,
714+
NULL, $1, false, &@1, NULL));
715+
$$ = term;
716+
}
717+
|
709718
PE_NAME '=' PE_NAME
710719
{
711720
struct parse_events_term *term;

0 commit comments

Comments
 (0)