[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250106-perf_evsel_get_id-v3-1-44eca9194f1e@rivosinc.com>
Date: Mon, 06 Jan 2025 19:39:47 -0800
From: Charlie Jenkins <charlie@...osinc.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>, Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>
Cc: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Charlie Jenkins <charlie@...osinc.com>
Subject: [PATCH v3] libperf: Add perf_evsel__id() function
Introduce perf_evsel__id() to collect the id of an evsel. This allows
applications to determine the allocated id of an evsel for each fd. The
"ids" argument is expected to be an array the size of the number of open
fd's for the evsel. This will allow applications to link the id
returned by PERF_SAMPLE_ID to the event being sampled.
Signed-off-by: Charlie Jenkins <charlie@...osinc.com>
---
Changes in v3:
- Replace id argument with array of pointers. IDs is indexed by
[cpu][thread].
- Add error handling
- Use uint64_t instead of __u64 for consistency
- Link to v2: https://lore.kernel.org/r/20240909-perf_evsel_get_id-v2-1-b26eae02f606@rivosinc.com
Changes in v2:
- Replaced id argument with array of ids for perf_evsel__id() to support
the id for each fd.
- Link to v1: https://lore.kernel.org/r/20240823-perf_evsel_get_id-v1-1-0ffa204c4164@rivosinc.com
---
tools/lib/perf/Documentation/libperf.txt | 2 ++
tools/lib/perf/evsel.c | 23 +++++++++++++++++++++++
tools/lib/perf/include/perf/evsel.h | 1 +
3 files changed, 26 insertions(+)
diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
index 59aabdd3cabff19c9a4835d9d20a74c6087d9a06..0133547394c296ee3ab7467ebe5c9a48707bad1d 100644
--- a/tools/lib/perf/Documentation/libperf.txt
+++ b/tools/lib/perf/Documentation/libperf.txt
@@ -93,6 +93,8 @@ SYNOPSIS
void perf_evlist__enable(struct perf_evlist *evlist);
void perf_evlist__disable(struct perf_evlist *evlist);
+ void perf_evsel__id(struct perf_evsel *evsel, u64 *ids[]);
+
#define perf_evlist__for_each_evsel(evlist, pos)
void perf_evlist__set_maps(struct perf_evlist *evlist,
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index c475319e2e410d31d072d81afb9e6277b16ef1f1..7c84ecaa6c87977edc9c70e960e985ffc975fcbf 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -486,6 +486,29 @@ int perf_evsel__disable(struct perf_evsel *evsel)
return err;
}
+static int perf_evsel__get_id(struct perf_evsel *evsel, int cpu_map_idx, int thread, u64 *id)
+{
+ return perf_evsel__ioctl(evsel, PERF_EVENT_IOC_ID, id, cpu_map_idx, thread);
+}
+
+int perf_evsel__id(struct perf_evsel *evsel, u64 *ids[])
+{
+ struct perf_thread_map *threads = perf_evsel__threads(evsel);
+ struct perf_cpu_map *cpus = perf_evsel__cpus(evsel);
+ int x, y, err;
+
+ for (x = 0; x < perf_cpu_map__nr(cpus); x++) {
+ for (y = 0; y < perf_thread_map__nr(threads); y++) {
+ err = perf_evsel__get_id(evsel, x, y, &ids[x][y]);
+
+ if (err)
+ return err;
+ }
+ }
+
+ return 0;
+}
+
int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
{
int err = 0, i;
diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
index 6f92204075c244bc623b26dc2c97fa4c835a4228..2bb9d6406e405b4ee29b8b13d64dd40b78edb501 100644
--- a/tools/lib/perf/include/perf/evsel.h
+++ b/tools/lib/perf/include/perf/evsel.h
@@ -41,6 +41,7 @@ LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx
LIBPERF_API int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread);
LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
+LIBPERF_API int perf_evsel__id(struct perf_evsel *evsel, uint64_t *ids[]);
LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
---
base-commit: ed60738a9b7ede4a4ae797d90be7fde3e10a36c7
change-id: 20240822-perf_evsel_get_id-f7e11f15504b
--
- Charlie
Powered by blists - more mailing lists