* [PATCH] perf evsel: Ignore the non-group case for branch counters
@ 2023-11-09 16:40 kan.liang
2023-11-13 15:49 ` Ian Rogers
0 siblings, 1 reply; 3+ messages in thread
From: kan.liang @ 2023-11-09 16:40 UTC (permalink / raw)
To: acme, irogers, linux-kernel, linux-perf-users
Cc: peterz, mingo, jolsa, namhyung, adrian.hunter, tinghao.zhang,
Kan Liang, Arnaldo Carvalho de Melo
From: Kan Liang <kan.liang@linux.intel.com>
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.
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Closes: https://lore.kernel.org/lkml/ZUv+G+w5EvJgQS45@kernel.org/
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
tools/perf/util/evsel.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 58a9b8c82790..7a6a2d1f96db 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf evsel: Ignore the non-group case for branch counters
2023-11-09 16:40 [PATCH] perf evsel: Ignore the non-group case for branch counters kan.liang
@ 2023-11-13 15:49 ` Ian Rogers
2023-11-13 16:10 ` Liang, Kan
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2023-11-13 15:49 UTC (permalink / raw)
To: kan.liang
Cc: acme, linux-kernel, linux-perf-users, peterz, mingo, jolsa,
namhyung, adrian.hunter, tinghao.zhang, Arnaldo Carvalho de Melo
On Thu, Nov 9, 2023 at 8:41 AM <kan.liang@linux.intel.com> wrote:
>
> From: Kan Liang <kan.liang@linux.intel.com>
>
> 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.
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
> Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> Closes: https://lore.kernel.org/lkml/ZUv+G+w5EvJgQS45@kernel.org/
> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
> ---
> tools/perf/util/evsel.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 58a9b8c82790..7a6a2d1f96db 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -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
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] perf evsel: Ignore the non-group case for branch counters
2023-11-13 15:49 ` Ian Rogers
@ 2023-11-13 16:10 ` Liang, Kan
0 siblings, 0 replies; 3+ messages in thread
From: Liang, Kan @ 2023-11-13 16:10 UTC (permalink / raw)
To: Ian Rogers
Cc: acme, linux-kernel, linux-perf-users, peterz, mingo, jolsa,
namhyung, adrian.hunter, tinghao.zhang, Arnaldo Carvalho de Melo
On 2023-11-13 10:49 a.m., Ian Rogers wrote:
> On Thu, Nov 9, 2023 at 8:41 AM <kan.liang@linux.intel.com> wrote:
>>
>> From: Kan Liang <kan.liang@linux.intel.com>
>>
>> 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.
>
> 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/ZU0pGuUBJH+bF1yU@kernel.org/
Thanks,
Kan
> Ian
>
>> Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>> Closes: https://lore.kernel.org/lkml/ZUv+G+w5EvJgQS45@kernel.org/
>> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
>> ---
>> tools/perf/util/evsel.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
>> index 58a9b8c82790..7a6a2d1f96db 100644
>> --- a/tools/perf/util/evsel.c
>> +++ b/tools/perf/util/evsel.c
>> @@ -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
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-13 16:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-09 16:40 [PATCH] perf evsel: Ignore the non-group case for branch counters kan.liang
2023-11-13 15:49 ` Ian Rogers
2023-11-13 16:10 ` Liang, Kan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox