Skip to contentSkip to conversation

perf evsel: Ignore the non-group case for branch counters

PATCH In review [email protected] 2 participants 3 messages Nov 9, 2023 – Nov 13, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf evsel: Ignore the non-group case for branch counters

From: Kan Liang <[email protected]>

The perf test 27: Sample parsing fails with the branch counters support introduced.

The branch counters feature requires all the events to belong to a group. There is no problem with the normal perf usage which usually initializes an evlist even for a single evsel.
But the perf test is special, which may not initialize an evlist. The Sample parsing test case is one of the examples. The existing code crashes with the !evsel->evlist.

Non-group means the evsel doesn't have branch counters support.

---
 tools/perf/util/evsel.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/evsel.c +4 -0
index 58a9b8c82790..7a6a2d1f96db 100644
@@ -2355,6 +2355,10 @@ static inline bool evsel__has_branch_counters(const struct evsel *evsel)
 {
 	struct evsel *cur, *leader = evsel__leader(evsel);
 
+	/* The branch counters feature only supports group */
+	if (!leader || !evsel->evlist)
+		return false;
+
 	evlist__for_each_entry(evsel->evlist, cur) {
 		if ((leader == evsel__leader(cur)) &&
 		    (cur->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS))
Signature · 1 line
2.35.1
reviewer
#1 lore raw
Quoted 6 lines · On Thu, Nov 9, 2023 at 8:41 AM <[email protected]> wrote:

From: Kan Liang <[email protected]>

The perf test 27: Sample parsing fails with the branch counters support introduced.

Quoted 8 lines

The branch counters feature requires all the events to belong to a group. There is no problem with the normal perf usage which usually initializes an evlist even for a single evsel.
But the perf test is special, which may not initialize an evlist. The Sample parsing test case is one of the examples. The existing code crashes with the !evsel->evlist.

Non-group means the evsel doesn't have branch counters support.

Thanks Kan, do we need to add this condition to
parse_events__sort_events_and_fix_groups?
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/parse-events.c#n2174

Ian

Quoted 25 lines
---
 tools/perf/util/evsel.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/evsel.c +4 -1
index 58a9b8c82790..7a6a2d1f96db 100644
@@ -2355,6 +2355,10 @@ static inline bool evsel__has_branch_counters(const struct evsel *evsel)
 {
        struct evsel *cur, *leader = evsel__leader(evsel);
 
+       /* The branch counters feature only supports group */
+       if (!leader || !evsel->evlist)
+               return false;
+
        evlist__for_each_entry(evsel->evlist, cur) {
                if ((leader == evsel__leader(cur)) &&
                    (cur->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS))
--

2.35.1

author
#2 lore raw
Quoted 14 lines · Ian Rogers
Quoted 13 lines · On Thu, Nov 9, 2023 at 8:41 AM <[email protected]> wrote:

From: Kan Liang <[email protected]>

The perf test 27: Sample parsing fails with the branch counters support introduced.

The branch counters feature requires all the events to belong to a group. There is no problem with the normal perf usage which usually initializes an evlist even for a single evsel.
But the perf test is special, which may not initialize an evlist. The Sample parsing test case is one of the examples. The existing code crashes with the !evsel->evlist.

Quoted 6 lines
Quoted 1 line

Non-group means the evsel doesn't have branch counters support.

Thanks Kan, do we need to add this condition to
parse_events__sort_events_and_fix_groups?
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/parse-events.c#n2174

I don't think so. The "non-group" here means the case that the evlist is not initialized. It should only happen with some perf test case.

In the parse_events__sort_events_and_fix_groups(), IIUC, the ungrouped event should mean a single event group. The feature works with the case. We don't need to add the condition.

BTW: Arnaldo should have already folded it with the original patch. We don't need the patch anymore.
https://lore.kernel.org/lkml/[email protected]/

Thanks,
Kan

Quoted 27 lines

Ian

Quoted 25 lines
---
 tools/perf/util/evsel.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/evsel.c +4 -1
index 58a9b8c82790..7a6a2d1f96db 100644
@@ -2355,6 +2355,10 @@ static inline bool evsel__has_branch_counters(const struct evsel *evsel)
 {
        struct evsel *cur, *leader = evsel__leader(evsel);
 
+       /* The branch counters feature only supports group */
+       if (!leader || !evsel->evlist)
+               return false;
+
        evlist__for_each_entry(evsel->evlist, cur) {
                if ((leader == evsel__leader(cur)) &&
                    (cur->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS))
--

2.35.1