]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf evsel: Add evsel__open_per_cpu_and_thread
authorIan Rogers <irogers@google.com>
Sat, 19 Jul 2025 03:05:13 +0000 (20:05 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 24 Jul 2025 20:41:35 +0000 (13:41 -0700)
Add evsel__open_per_cpu_and_thread that combines the operation of
evsel__open_per_cpu and evsel__open_per_thread so that an event
without the "any" cpumask can be opened with its cpumask and with
threads it specifies. Change the implementation of evsel__open_per_cpu
and evsel__open_per_thread to use evsel__open_per_cpu_and_thread to
make the implementation of those functions clearer.

Reviewed-by: Thomas Falcon <thomas.falcon@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250719030517.1990983-12-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index af2b26c6456ae18078a270a5697e542674f9a8c7..ae11df1e79020b6076bf719153f8e879af741abf 100644 (file)
@@ -2761,17 +2761,32 @@ void evsel__close(struct evsel *evsel)
        perf_evsel__free_id(&evsel->core);
 }
 
-int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx)
+int evsel__open_per_cpu_and_thread(struct evsel *evsel,
+                                  struct perf_cpu_map *cpus, int cpu_map_idx,
+                                  struct perf_thread_map *threads)
 {
        if (cpu_map_idx == -1)
-               return evsel__open_cpu(evsel, cpus, NULL, 0, perf_cpu_map__nr(cpus));
+               return evsel__open_cpu(evsel, cpus, threads, 0, perf_cpu_map__nr(cpus));
 
-       return evsel__open_cpu(evsel, cpus, NULL, cpu_map_idx, cpu_map_idx + 1);
+       return evsel__open_cpu(evsel, cpus, threads, cpu_map_idx, cpu_map_idx + 1);
+}
+
+int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx)
+{
+       struct perf_thread_map *threads = thread_map__new_by_tid(-1);
+       int ret = evsel__open_per_cpu_and_thread(evsel, cpus, cpu_map_idx, threads);
+
+       perf_thread_map__put(threads);
+       return ret;
 }
 
 int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads)
 {
-       return evsel__open(evsel, NULL, threads);
+       struct perf_cpu_map *cpus = perf_cpu_map__new_any_cpu();
+       int ret = evsel__open_per_cpu_and_thread(evsel, cpus, -1, threads);
+
+       perf_cpu_map__put(cpus);
+       return ret;
 }
 
 static int perf_evsel__parse_id_sample(const struct evsel *evsel,
index cefa8e64c0d5eba6128909dbab688fcbf74404ef..8e79eb6d41b3de1325b1848468d8f6a208c0b0b1 100644 (file)
@@ -351,6 +351,9 @@ int evsel__enable(struct evsel *evsel);
 int evsel__disable(struct evsel *evsel);
 int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx);
 
+int evsel__open_per_cpu_and_thread(struct evsel *evsel,
+                                  struct perf_cpu_map *cpus, int cpu_map_idx,
+                                  struct perf_thread_map *threads);
 int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx);
 int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads);
 int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,