perf tools: Ensure event leader stays at head of evlist after sorting
PATCH RESEND v2 1/1 perf tools: Ensure event leader stays at head of evlist after sorting
From: Ian Rogers <[email protected]>
For evlist of a certain event/metric, the HEAD should be the event leader. In some scenarios where uncore_xxx_0 does not exist, the event leader is not the first element after sorting. For example, on my test machine uncore_iio_0 does not exist, the event leader is uncore_iio_2.
However, in evlist__cmp, it was reordered based on the PMU name, which makes uncore_iio_1 the HEAD of evlist, breaking the following merge logic in evsel__merge_aliases.
The patch adds a loop at the end of parse_events__sort_events_and_fix_groups to make sure the first wildcard match is the earliest entry in the list, updating pointers accordingly without breaking reordering detection.
Tested on device lacks uncore_iio_0, and perf test looks good.
---
v2:
Adding missing Signed-off-by from Ian Rogers.
Renaming variable l to orig_leader.
v1: lore.kernel.org/[email protected]
tools/perf/util/parse-events.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
tools/perf/util/parse-events.c +27 -0
@@ -2251,6 +2251,33 @@ static int parse_events__sort_events_and_fix_groups(struct list_head *list) } last_event_was_forced_leader = (force_grouped_leader == pos); } + +/* +* Make sure the first wildcard match is the earliest entry in the list. +* Since list_sort might have reordered the aliases, the original leader +* might not be at the head of the list anymore. We find the first +* alias in the sorted list and make it the new leader, and redirect +* all other aliases to it. +*/ +list_for_each_entry (pos, list, core.node) { +struct evsel *orig_leader = pos->first_wildcard_match; + +if (!orig_leader) +continue ; + +if (orig_leader->first_wildcard_match) { +/* Original leader was redirected to a new leader */ + pos->first_wildcard_match = orig_leader->first_wildcard_match; + }else if (pos->core.idx < orig_leader->core.idx) { +/* +* We are earlier than the original leader in sorted order, +* and no earlier alias has claimed leadership yet. +*/ + orig_leader->first_wildcard_match = pos; + pos->first_wildcard_match =NULL ; + } + } +list_for_each_entry (pos, list, core.node) {struct evsel *pos_leader =evsel__leader (pos);
--
2.54.0.545.g6539524ca2-goog
Hello,
Quoted 16 lines · Chun-Tse Shao
From: Ian Rogers <[email protected]>
For evlist of a certain event/metric, the HEAD should be the event leader. In some scenarios where
uncore_xxx_0does not exist, the event leader is not the first element after sorting. For example, on my test machineuncore_iio_0does not exist, the event leader isuncore_iio_2.However, in
evlist__cmp, it was reordered based on the PMU name, which makesuncore_iio_1the HEAD of evlist, breaking the following merge logic inevsel__merge_aliases.The patch adds a loop at the end of
parse_events__sort_events_and_fix_groupsto make sure the first wildcard match is the earliest entry in the list, updating pointers accordingly without breaking reordering detection.
Quoted 4 lines
Tested on device lacks
uncore_iio_0, andperf testlooks good.Signed-off-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>
Thanks,
Namhyung
Quoted 51 lines
---
v2:
Adding missing Signed-off-by from Ian Rogers.
Renaming variableltoorig_leader.v1: lore.kernel.org/[email protected]
tools/perf/util/parse-events.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)tools/perf/util/parse-events.c +27
-1@@ -2251,6 +2251,33 @@ static int parse_events__sort_events_and_fix_groups(struct list_head *list) } last_event_was_forced_leader = (force_grouped_leader == pos); } + +/* +* Make sure the first wildcard match is the earliest entry in the list. +* Since list_sort might have reordered the aliases, the original leader +* might not be at the head of the list anymore. We find the first +* alias in the sorted list and make it the new leader, and redirect +* all other aliases to it. +*/ +list_for_each_entry (pos, list, core.node) { +struct evsel *orig_leader = pos->first_wildcard_match; + +if (!orig_leader) +continue ; + +if (orig_leader->first_wildcard_match) { +/* Original leader was redirected to a new leader */ + pos->first_wildcard_match = orig_leader->first_wildcard_match; + }else if (pos->core.idx < orig_leader->core.idx) { +/* +* We are earlier than the original leader in sorted order, +* and no earlier alias has claimed leadership yet. +*/ + orig_leader->first_wildcard_match = pos; + pos->first_wildcard_match =NULL ; + } + } +list_for_each_entry (pos, list, core.node) {struct evsel *pos_leader =evsel__leader (pos); --2.54.0.545.g6539524ca2-goog
Quoted 19 lines · Namhyung Kim
Hello,
Quoted 16 lines · Chun-Tse Shao
From: Ian Rogers <[email protected]>
For evlist of a certain event/metric, the HEAD should be the event leader. In some scenarios where
uncore_xxx_0does not exist, the event leader is not the first element after sorting. For example, on my test machineuncore_iio_0does not exist, the event leader isuncore_iio_2.However, in
evlist__cmp, it was reordered based on the PMU name, which makesuncore_iio_1the HEAD of evlist, breaking the following merge logic inevsel__merge_aliases.The patch adds a loop at the end of
parse_events__sort_events_and_fix_groupsto make sure the first wildcard match is the earliest entry in the list, updating pointers accordingly without breaking reordering detection.
Quoted 6 lines
Quoted 4 lines
Tested on device lacks
uncore_iio_0, andperf testlooks good.Signed-off-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>Acked-by Namhyung Kim <[email protected]>
Thanks, applied to perf-tools-next, for v7.2.
- Arnaldo