]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf cs-etm: Make a helper to find the Coresight evsel
authorJames Clark <james.clark@linaro.org>
Wed, 14 Jan 2026 15:57:22 +0000 (15:57 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Jan 2026 02:16:01 +0000 (23:16 -0300)
This pattern occurs a few times and we'll add another one later, so add
a helper function for it.

Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/arch/arm/util/cs-etm.c

index c28208361d918a56597d1cbf957ede16fb73fd17..a49753f0d20ffbd7aefdcedb7288082498ec443d 100644 (file)
@@ -302,6 +302,19 @@ static int cs_etm_set_sink_attr(struct perf_pmu *pmu,
        return 0;
 }
 
+static struct evsel *cs_etm_get_evsel(struct evlist *evlist,
+                                     struct perf_pmu *cs_etm_pmu)
+{
+       struct evsel *evsel;
+
+       evlist__for_each_entry(evlist, evsel) {
+               if (evsel->core.attr.type == cs_etm_pmu->type)
+                       return evsel;
+       }
+
+       return NULL;
+}
+
 static int cs_etm_recording_options(struct auxtrace_record *itr,
                                    struct evlist *evlist,
                                    struct record_opts *opts)
@@ -473,29 +486,21 @@ out:
 
 static u64 cs_etm_get_config(struct auxtrace_record *itr)
 {
-       u64 config = 0;
        struct cs_etm_recording *ptr =
                        container_of(itr, struct cs_etm_recording, itr);
        struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
        struct evlist *evlist = ptr->evlist;
-       struct evsel *evsel;
+       struct evsel *evsel = cs_etm_get_evsel(evlist, cs_etm_pmu);
 
-       evlist__for_each_entry(evlist, evsel) {
-               if (evsel->core.attr.type == cs_etm_pmu->type) {
-                       /*
-                        * Variable perf_event_attr::config is assigned to
-                        * ETMv3/PTM.  The bit fields have been made to match
-                        * the ETMv3.5 ETRMCR register specification.  See the
-                        * PMU_FORMAT_ATTR() declarations in
-                        * drivers/hwtracing/coresight/coresight-perf.c for
-                        * details.
-                        */
-                       config = evsel->core.attr.config;
-                       break;
-               }
-       }
-
-       return config;
+       /*
+        * Variable perf_event_attr::config is assigned to
+        * ETMv3/PTM.  The bit fields have been made to match
+        * the ETMv3.5 ETRMCR register specification.  See the
+        * PMU_FORMAT_ATTR() declarations in
+        * drivers/hwtracing/coresight/coresight-perf.c for
+        * details.
+        */
+       return evsel ? evsel->core.attr.config : 0;
 }
 
 #ifndef BIT
@@ -829,12 +834,11 @@ static int cs_etm_snapshot_start(struct auxtrace_record *itr)
 {
        struct cs_etm_recording *ptr =
                        container_of(itr, struct cs_etm_recording, itr);
-       struct evsel *evsel;
+       struct evsel *evsel = cs_etm_get_evsel(ptr->evlist, ptr->cs_etm_pmu);
+
+       if (evsel)
+               return evsel__disable(evsel);
 
-       evlist__for_each_entry(ptr->evlist, evsel) {
-               if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
-                       return evsel__disable(evsel);
-       }
        return -EINVAL;
 }