Skip to content

Commit e9387ba

Browse files
captain5050namhyung
authored andcommitted
perf evsel: Add evsel__open_per_cpu_and_thread
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>
1 parent cd63c22 commit e9387ba

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

tools/perf/util/evsel.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,17 +2761,32 @@ void evsel__close(struct evsel *evsel)
27612761
perf_evsel__free_id(&evsel->core);
27622762
}
27632763

2764-
int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx)
2764+
int evsel__open_per_cpu_and_thread(struct evsel *evsel,
2765+
struct perf_cpu_map *cpus, int cpu_map_idx,
2766+
struct perf_thread_map *threads)
27652767
{
27662768
if (cpu_map_idx == -1)
2767-
return evsel__open_cpu(evsel, cpus, NULL, 0, perf_cpu_map__nr(cpus));
2769+
return evsel__open_cpu(evsel, cpus, threads, 0, perf_cpu_map__nr(cpus));
27682770

2769-
return evsel__open_cpu(evsel, cpus, NULL, cpu_map_idx, cpu_map_idx + 1);
2771+
return evsel__open_cpu(evsel, cpus, threads, cpu_map_idx, cpu_map_idx + 1);
2772+
}
2773+
2774+
int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx)
2775+
{
2776+
struct perf_thread_map *threads = thread_map__new_by_tid(-1);
2777+
int ret = evsel__open_per_cpu_and_thread(evsel, cpus, cpu_map_idx, threads);
2778+
2779+
perf_thread_map__put(threads);
2780+
return ret;
27702781
}
27712782

27722783
int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads)
27732784
{
2774-
return evsel__open(evsel, NULL, threads);
2785+
struct perf_cpu_map *cpus = perf_cpu_map__new_any_cpu();
2786+
int ret = evsel__open_per_cpu_and_thread(evsel, cpus, -1, threads);
2787+
2788+
perf_cpu_map__put(cpus);
2789+
return ret;
27752790
}
27762791

27772792
static int perf_evsel__parse_id_sample(const struct evsel *evsel,

tools/perf/util/evsel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ int evsel__enable(struct evsel *evsel);
351351
int evsel__disable(struct evsel *evsel);
352352
int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx);
353353

354+
int evsel__open_per_cpu_and_thread(struct evsel *evsel,
355+
struct perf_cpu_map *cpus, int cpu_map_idx,
356+
struct perf_thread_map *threads);
354357
int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx);
355358
int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads);
356359
int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,

0 commit comments

Comments
 (0)