Re: [PATCH] perf stat: Fix crash on arm64

From: Ian Rogers

Date: Thu Feb 05 2026 - 13:22:42 EST


On Thu, Feb 5, 2026 at 9:52 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> On Thu, Feb 05, 2026 at 05:39:18PM +0000, Leo Yan wrote:
>
> > > > The sorting function introduced by commit a745c0831c15c ("perf stat:
> > > > Sort default events/metrics") compares events based on their individual
> > > > properties. This can cause events from different groups to be
> > > > interleaved, resulting in group members appearing before their leaders
> > > > in the sorted evlist.
> > >
> > > Hi, sorry for the issue. I can see what you're saying but why is this
> > > an arm64 issue? The legacy Default metrics are common to all
> > > architectures:
> > > https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/pmu-events/arch/common/common/metrics.json?h=perf-tools-next
> >
> > Since you are mentioning common metrics, I found the common metrics does
> > not work on Arm64 platform (I built with NO_JEVENTS=1 or enabled jevnts
> > but both don't work).
> >
> > The latest perf will have no any output if the CPU type is missed in
> > json and rallback to common metrics. The failure path is:
> >
> > add_default_events()
> > metricgroup__parse_groups()
> > pmu_metrics_table__find() => return NULL
> >

The return is correct but the early return is wrong, the metric code
was updated to always consider the default table and skip a NULL
table:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/metricgroup.c?h=perf-tools-next#n430
I'll send a patch for the early return.

> > In my case, pmu_metrics_table__find() always return NULL, as a result,
> > `perf stat sleep 1` directly bail out without any output.
> >
> > I expect Breno's env might have the corresponding CPU json files, this
> > is possible different from my test machine.
>
> On my local env, I need a fix:
>
> diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c
> index e4d00f6b2b5d..f74acc206856 100644
> --- a/tools/perf/pmu-events/empty-pmu-events.c
> +++ b/tools/perf/pmu-events/empty-pmu-events.c
> @@ -3237,14 +3237,6 @@ const struct pmu_events_table *perf_pmu__default_core_events_table(void)
> return NULL;
> }
>
> -const struct pmu_metrics_table *pmu_metrics_table__find(void)
> -{
> - struct perf_cpu cpu = {-1};
> - const struct pmu_events_map *map = map_for_cpu(cpu);
> -
> - return map ? &map->metric_table : NULL;
> -}
> -
> const struct pmu_metrics_table *pmu_metrics_table__default(void)
> {
> int i = 0;
> @@ -3261,6 +3253,17 @@ const struct pmu_metrics_table *pmu_metrics_table__default(void)
> return NULL;
> }
>
> +const struct pmu_metrics_table *pmu_metrics_table__find(void)
> +{
> + struct perf_cpu cpu = {-1};
> + const struct pmu_events_map *map = map_for_cpu(cpu);
> +
> + if (map)
> + return &map->metric_table;
> +
> + return pmu_metrics_table__default();
> +}
> +
>
> I have no deep understanding for jevents, seems to me, Breno's issue is
> a different one from me. Please kindly confirm.

I think it is a different issue, they have metrics while you don't.
Your report does highlight we're missing a NO_JEVENTS=1 build-test,
but the build is working for me. I'll send out two patches for these
issues.

Thanks,
Ian

> Thanks,
> Leo