* [PATCH] perf pmu: Consider raw events as legacy events
@ 2025-05-06 22:23 Namhyung Kim
2025-05-07 15:42 ` Ian Rogers
0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2025-05-06 22:23 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang
Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users
When it finds a matching pmu for a legacy event, it should look for
core pmus. The raw events also refers to core events so it should be
handled together.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/pmus.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index b99292de76693dbb..0134321fc520b1fc 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -726,7 +726,8 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
pmu = perf_pmus__find_by_type(evsel->core.attr.type);
legacy_core_type =
evsel->core.attr.type == PERF_TYPE_HARDWARE ||
- evsel->core.attr.type == PERF_TYPE_HW_CACHE;
+ evsel->core.attr.type == PERF_TYPE_HW_CACHE ||
+ evsel->core.attr.type == PERF_TYPE_RAW;
if (!pmu && legacy_core_type) {
if (perf_pmus__supports_extended_type()) {
u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
--
2.49.0.987.g0cc8ee98dc-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf pmu: Consider raw events as legacy events
2025-05-06 22:23 [PATCH] perf pmu: Consider raw events as legacy events Namhyung Kim
@ 2025-05-07 15:42 ` Ian Rogers
2025-05-07 21:50 ` Namhyung Kim
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2025-05-07 15:42 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Kan Liang, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Tue, May 6, 2025 at 3:23 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> When it finds a matching pmu for a legacy event, it should look for
> core pmus. The raw events also refers to core events so it should be
> handled together.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/pmus.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> index b99292de76693dbb..0134321fc520b1fc 100644
> --- a/tools/perf/util/pmus.c
> +++ b/tools/perf/util/pmus.c
> @@ -726,7 +726,8 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
> pmu = perf_pmus__find_by_type(evsel->core.attr.type);
> legacy_core_type =
> evsel->core.attr.type == PERF_TYPE_HARDWARE ||
> - evsel->core.attr.type == PERF_TYPE_HW_CACHE;
> + evsel->core.attr.type == PERF_TYPE_HW_CACHE ||
> + evsel->core.attr.type == PERF_TYPE_RAW;
I don't think this is right. The PERF_TYPE_RAW isn't a legacy type as
we map sysfs/json names to the format encoding. More than this, the
extended type information will not be present for a raw type and so
this change could cause an invalid PMU to be looked up on
hybrid/BIG.little systems. On x86 the cpu or cpu_core PMU will have
type PERF_TYPE_RAW (4). As is common ARM decided to do things
differently, meaning there is no type 4 to a PMU mapping. I think we
need a change like:
```
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index b99292de7669..6632209c6664 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -727,14 +727,21 @@ struct perf_pmu *evsel__find_pmu(const struct
evsel *evsel)
legacy_core_type =
evsel->core.attr.type == PERF_TYPE_HARDWARE ||
evsel->core.attr.type == PERF_TYPE_HW_CACHE;
- if (!pmu && legacy_core_type) {
- if (perf_pmus__supports_extended_type()) {
- u32 type = evsel->core.attr.config >>
PERF_PMU_TYPE_SHIFT;
+ if (!pmu && legacy_core_type && perf_pmus__supports_extended_type()) {
+ u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
- pmu = perf_pmus__find_by_type(type);
- } else {
- pmu = perf_pmus__find_core_pmu();
- }
+ pmu = perf_pmus__find_by_type(type);
+ }
+ if (!pmu && (legacy_core_type || evsel->core.attr.type ==
PERF_TYPE_RAW)) {
+ /*
+ * For legacy events, if there was no extended type info then
+ * assume the PMU is the first core PMU.
+ *
+ * On architectures like ARM there is no sysfs PMU with type
+ * PERF_TYPE_RAW, assume the RAW events are going to be handled
+ * by the first core PMU.
+ */
+ pmu = perf_pmus__find_core_pmu();
}
((struct evsel *)evsel)->pmu = pmu;
return pmu;
```
which handles both the case that the extended type was missing on
hybrid/BIG.little and the ARM raw type problem.
Thanks,
Ian
> if (!pmu && legacy_core_type) {
> if (perf_pmus__supports_extended_type()) {
> u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
> --
> 2.49.0.987.g0cc8ee98dc-goog
>
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] perf pmu: Consider raw events as legacy events
2025-05-07 15:42 ` Ian Rogers
@ 2025-05-07 21:50 ` Namhyung Kim
0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-05-07 21:50 UTC (permalink / raw)
To: Ian Rogers
Cc: Arnaldo Carvalho de Melo, Kan Liang, Jiri Olsa, Adrian Hunter,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Hi Ian,
On Wed, May 07, 2025 at 08:42:27AM -0700, Ian Rogers wrote:
> On Tue, May 6, 2025 at 3:23 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > When it finds a matching pmu for a legacy event, it should look for
> > core pmus. The raw events also refers to core events so it should be
> > handled together.
> >
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > ---
> > tools/perf/util/pmus.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> > index b99292de76693dbb..0134321fc520b1fc 100644
> > --- a/tools/perf/util/pmus.c
> > +++ b/tools/perf/util/pmus.c
> > @@ -726,7 +726,8 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
> > pmu = perf_pmus__find_by_type(evsel->core.attr.type);
> > legacy_core_type =
> > evsel->core.attr.type == PERF_TYPE_HARDWARE ||
> > - evsel->core.attr.type == PERF_TYPE_HW_CACHE;
> > + evsel->core.attr.type == PERF_TYPE_HW_CACHE ||
> > + evsel->core.attr.type == PERF_TYPE_RAW;
>
> I don't think this is right. The PERF_TYPE_RAW isn't a legacy type as
> we map sysfs/json names to the format encoding. More than this, the
> extended type information will not be present for a raw type and so
> this change could cause an invalid PMU to be looked up on
> hybrid/BIG.little systems. On x86 the cpu or cpu_core PMU will have
> type PERF_TYPE_RAW (4). As is common ARM decided to do things
> differently, meaning there is no type 4 to a PMU mapping. I think we
> need a change like:
> ```
> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> index b99292de7669..6632209c6664 100644
> --- a/tools/perf/util/pmus.c
> +++ b/tools/perf/util/pmus.c
> @@ -727,14 +727,21 @@ struct perf_pmu *evsel__find_pmu(const struct
> evsel *evsel)
> legacy_core_type =
> evsel->core.attr.type == PERF_TYPE_HARDWARE ||
> evsel->core.attr.type == PERF_TYPE_HW_CACHE;
> - if (!pmu && legacy_core_type) {
> - if (perf_pmus__supports_extended_type()) {
> - u32 type = evsel->core.attr.config >>
> PERF_PMU_TYPE_SHIFT;
> + if (!pmu && legacy_core_type && perf_pmus__supports_extended_type()) {
> + u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
>
> - pmu = perf_pmus__find_by_type(type);
> - } else {
> - pmu = perf_pmus__find_core_pmu();
> - }
> + pmu = perf_pmus__find_by_type(type);
> + }
> + if (!pmu && (legacy_core_type || evsel->core.attr.type ==
> PERF_TYPE_RAW)) {
> + /*
> + * For legacy events, if there was no extended type info then
> + * assume the PMU is the first core PMU.
> + *
> + * On architectures like ARM there is no sysfs PMU with type
> + * PERF_TYPE_RAW, assume the RAW events are going to be handled
> + * by the first core PMU.
> + */
> + pmu = perf_pmus__find_core_pmu();
> }
> ((struct evsel *)evsel)->pmu = pmu;
> return pmu;
> ```
> which handles both the case that the extended type was missing on
> hybrid/BIG.little and the ARM raw type problem.
Looks good to me. Thanks for the suggestion!
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-07 21:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 22:23 [PATCH] perf pmu: Consider raw events as legacy events Namhyung Kim
2025-05-07 15:42 ` Ian Rogers
2025-05-07 21:50 ` Namhyung Kim
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.