Commit e9387ba5 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

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: default avatarThomas Falcon <thomas.falcon@intel.com>
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarJames Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250719030517.1990983-12-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent cd63c221
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -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,
+3 −0
Original line number Diff line number Diff line
@@ -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,