Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH v2] perf pmu: Use available core PMU for raw events
@ 2025-05-07 21:59 Namhyung Kim
  2025-05-08 15:11 ` Ian Rogers
  0 siblings, 1 reply; 2+ messages in thread
From: Namhyung Kim @ 2025-05-07 21:59 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 similarly.

On x86, PERF_TYPE_RAW should match with the existing cpu PMU.  But on
ARM, there's no PMU with the matching type so it'll pick the first core
PMU for it.

Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/pmus.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index b99292de76693dbb..3bbd26fec78a10e2 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;
-- 
2.49.0.987.g0cc8ee98dc-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] perf pmu: Use available core PMU for raw events
  2025-05-07 21:59 [PATCH v2] perf pmu: Use available core PMU for raw events Namhyung Kim
@ 2025-05-08 15:11 ` Ian Rogers
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Rogers @ 2025-05-08 15:11 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 Wed, May 7, 2025 at 2:59 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 similarly.
>
> On x86, PERF_TYPE_RAW should match with the existing cpu PMU.  But on
> ARM, there's no PMU with the matching type so it'll pick the first core
> PMU for it.
>
> Suggested-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/pmus.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> index b99292de76693dbb..3bbd26fec78a10e2 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;
> --
> 2.49.0.987.g0cc8ee98dc-goog
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-08 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-07 21:59 [PATCH v2] perf pmu: Use available core PMU for raw events Namhyung Kim
2025-05-08 15:11 ` Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox