Skip to content

Commit 8002019

Browse files
captain5050namhyung
authored andcommitted
perf parse-events: Make X modifier more respectful of groups
Events with an X modifier were reordered within a group, for example slots was made the leader in: ``` $ perf record -e '{cpu/mem-stores/ppu,cpu/slots/uX}' -- sleep 1 ``` Fix by making `dont_regroup` evsels always use their index for sorting. Make the cur_leader, when fixing the groups, be that of `dont_regroup` evsel so that the `dont_regroup` evsel doesn't become a leader. On a tigerlake this patch corrects this and meets expectations in: ``` $ perf stat -e '{cpu/mem-stores/,cpu/slots/uX}' -a -- sleep 0.1 Performance counter stats for 'system wide': 83,458,652 cpu/mem-stores/ 2,720,854,880 cpu/slots/uX 0.103780587 seconds time elapsed $ perf stat -e 'slots,slots:X' -a -- sleep 0.1 Performance counter stats for 'system wide': 732,042,247 slots (48.96%) 643,288,155 slots:X (51.04%) 0.102731018 seconds time elapsed ``` Closes: https://lore.kernel.org/lkml/18f20d38-070c-4e17-bc90-cf7102e1e53d@linux.intel.com/ Fixes: 035c178 ("perf parse-events: Add 'X' modifier to exclude an event from being regrouped") Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent ad83f3b commit 8002019

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/perf/util/parse-events.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,14 +1973,18 @@ static int evlist__cmp(void *_fg_idx, const struct list_head *l, const struct li
19731973
* event's index is used. An index may be forced for events that
19741974
* must be in the same group, namely Intel topdown events.
19751975
*/
1976-
if (*force_grouped_idx != -1 && arch_evsel__must_be_in_group(lhs)) {
1976+
if (lhs->dont_regroup) {
1977+
lhs_sort_idx = lhs_core->idx;
1978+
} else if (*force_grouped_idx != -1 && arch_evsel__must_be_in_group(lhs)) {
19771979
lhs_sort_idx = *force_grouped_idx;
19781980
} else {
19791981
bool lhs_has_group = lhs_core->leader != lhs_core || lhs_core->nr_members > 1;
19801982

19811983
lhs_sort_idx = lhs_has_group ? lhs_core->leader->idx : lhs_core->idx;
19821984
}
1983-
if (*force_grouped_idx != -1 && arch_evsel__must_be_in_group(rhs)) {
1985+
if (rhs->dont_regroup) {
1986+
rhs_sort_idx = rhs_core->idx;
1987+
} else if (*force_grouped_idx != -1 && arch_evsel__must_be_in_group(rhs)) {
19841988
rhs_sort_idx = *force_grouped_idx;
19851989
} else {
19861990
bool rhs_has_group = rhs_core->leader != rhs_core || rhs_core->nr_members > 1;
@@ -2078,10 +2082,10 @@ static int parse_events__sort_events_and_fix_groups(struct list_head *list)
20782082
*/
20792083
idx = 0;
20802084
list_for_each_entry(pos, list, core.node) {
2081-
const struct evsel *pos_leader = evsel__leader(pos);
2085+
struct evsel *pos_leader = evsel__leader(pos);
20822086
const char *pos_pmu_name = pos->group_pmu_name;
20832087
const char *cur_leader_pmu_name;
2084-
bool pos_force_grouped = force_grouped_idx != -1 &&
2088+
bool pos_force_grouped = force_grouped_idx != -1 && !pos->dont_regroup &&
20852089
arch_evsel__must_be_in_group(pos);
20862090

20872091
/* Reset index and nr_members. */
@@ -2095,8 +2099,8 @@ static int parse_events__sort_events_and_fix_groups(struct list_head *list)
20952099
* groups can't span PMUs.
20962100
*/
20972101
if (!cur_leader || pos->dont_regroup) {
2098-
cur_leader = pos;
2099-
cur_leaders_grp = &pos->core;
2102+
cur_leader = pos->dont_regroup ? pos_leader : pos;
2103+
cur_leaders_grp = &cur_leader->core;
21002104
if (pos_force_grouped)
21012105
force_grouped_leader = pos;
21022106
}

0 commit comments

Comments
 (0)