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>
This commit is contained in:
Ian Rogers 2025-07-18 20:05:13 -07:00 committed by Namhyung Kim
parent cd63c22168
commit e9387ba569
2 changed files with 22 additions and 4 deletions

View 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,

View 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,