Skip to content

Commit 035c178

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Add 'X' modifier to exclude an event from being regrouped
The function parse_events__sort_events_and_fix_groups is needed to fix uncore events like: ``` $ perf stat -e '{data_read,data_write}' ... ``` so that the multiple uncore PMUs have a group each of data_read and data_write events. The same function will perform architecture sorting and group fixing, in particular for Intel topdown/perf-metric events. Grouping multiple perf metric events together causes perf_event_open to fail as the group can only support one. This means command lines like: ``` $ perf stat -e 'slots,slots' ... ``` fail as the slots events are forced into a group together to try to satisfy the perf-metric event constraints. As the user may know better than parse_events__sort_events_and_fix_groups add a 'X' modifier to skip its regrouping behavior. This allows the following to succeed rather than fail on the second slots event being opened: ``` $ perf stat -e 'slots,slots:X' -a sleep 1 Performance counter stats for 'system wide': 6,834,154,071 cpu_core/slots/ (50.13%) 5,548,629,453 cpu_core/slots/X (49.87%) 1.002634606 seconds time elapsed ``` Closes: https://lore.kernel.org/lkml/[email protected]/ Reported-by: Dapeng Mi <[email protected]> Reported-by: Xudong Hao <[email protected]> Reviewed-by: Dapeng Mi <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Tested-by: Dapeng Mi <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Falcon <[email protected]> Cc: Yoshihiro Furudera <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9eac561 commit 035c178

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

tools/perf/Documentation/perf-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ counted. The following modifiers exist:
7373
e - group or event are exclusive and do not share the PMU
7474
b - use BPF aggregration (see perf stat --bpf-counters)
7575
R - retire latency value of the event
76+
X - don't regroup the event to match PMUs
7677

7778
The 'p' modifier can be used for specifying how precise the instruction
7879
address should be. The 'p' modifier can be specified multiple times:

tools/perf/util/evsel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct evsel {
8989
bool use_config_name;
9090
bool skippable;
9191
bool retire_lat;
92+
bool dont_regroup;
9293
int bpf_fd;
9394
struct bpf_object *bpf_obj;
9495
struct list_head config_terms;

tools/perf/util/parse-events.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,8 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
18961896
evsel->bpf_counter = true;
18971897
if (mod.retire_lat)
18981898
evsel->retire_lat = true;
1899+
if (mod.dont_regroup)
1900+
evsel->dont_regroup = true;
18991901
}
19001902
return 0;
19011903
}
@@ -2192,13 +2194,12 @@ static int parse_events__sort_events_and_fix_groups(struct list_head *list)
21922194
* Set the group leader respecting the given groupings and that
21932195
* groups can't span PMUs.
21942196
*/
2195-
if (!cur_leader) {
2197+
if (!cur_leader || pos->dont_regroup) {
21962198
cur_leader = pos;
21972199
cur_leaders_grp = &pos->core;
21982200
if (pos_force_grouped)
21992201
force_grouped_leader = pos;
22002202
}
2201-
22022203
cur_leader_pmu_name = cur_leader->group_pmu_name;
22032204
if (strcmp(cur_leader_pmu_name, pos_pmu_name)) {
22042205
/* PMU changed so the group/leader must change. */

tools/perf/util/parse-events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ struct parse_events_modifier {
216216
bool guest : 1; /* 'G' */
217217
bool host : 1; /* 'H' */
218218
bool retire_lat : 1; /* 'R' */
219+
bool dont_regroup : 1; /* 'X' */
219220
};
220221

221222
int parse_events__modifier_event(struct parse_events_state *parse_state, void *loc,

tools/perf/util/parse-events.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static int modifiers(struct parse_events_state *parse_state, yyscan_t scanner)
206206
CASE('e', exclusive);
207207
CASE('b', bpf);
208208
CASE('R', retire_lat);
209+
CASE('X', dont_regroup);
209210
default:
210211
return PE_ERROR;
211212
}
@@ -251,10 +252,10 @@ term_name {name_start}[a-zA-Z0-9_*?.\[\]!\-:]*
251252
quoted_name [\']{name_start}[a-zA-Z0-9_*?.\[\]!\-:,\.=]*[\']
252253
drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
253254
/*
254-
* If you add a modifier you need to update check_modifier().
255+
* If you add a modifier you need to update modifiers().
255256
* Also, the letters in modifier_event must not be in modifier_bp.
256257
*/
257-
modifier_event [ukhpPGHSDIWebR]{1,16}
258+
modifier_event [ukhpPGHSDIWebRX]{1,17}
258259
modifier_bp [rwx]{1,3}
259260
lc_type (L1-dcache|l1-d|l1d|L1-data|L1-icache|l1-i|l1i|L1-instruction|LLC|L2|dTLB|d-tlb|Data-TLB|iTLB|i-tlb|Instruction-TLB|branch|branches|bpu|btb|bpc|node)
260261
lc_op_result (load|loads|read|store|stores|write|prefetch|prefetches|speculative-read|speculative-load|refs|Reference|ops|access|misses|miss)

0 commit comments

Comments
 (0)