[PATCH i-g-t 1/3] lib/igt_perf: Add helper functions to read format entries
Riana Tauro
riana.tauro at intel.com
Wed Jan 15 07:30:38 UTC 2025
add helper functions to read format entries of pmu
Signed-off-by: Riana Tauro <riana.tauro at intel.com>
---
lib/igt_perf.c | 23 +++++++++++++++++++++++
lib/igt_perf.h | 1 +
2 files changed, 24 insertions(+)
diff --git a/lib/igt_perf.c b/lib/igt_perf.c
index 3866c6d77..7d2ff8969 100644
--- a/lib/igt_perf.c
+++ b/lib/igt_perf.c
@@ -129,6 +129,29 @@ uint64_t igt_perf_type_id(const char *device)
return strtoull(buf, NULL, 0);
}
+int igt_perf_format(const char *device, const char *name, char *buff, int buflen)
+{
+ char buf[NAME_MAX];
+ ssize_t ret;
+ int fd;
+
+ snprintf(buf, sizeof(buf),
+ "/sys/bus/event_source/devices/%s/format/%s", device, name);
+
+ fd = open(buf, O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ ret = read(fd, buff, buflen - 1);
+ close(fd);
+ if (ret < 1)
+ return -1;
+
+ buf[ret] = '\0';
+
+ return 0;
+}
+
int igt_perf_events_dir(int i915)
{
char buf[80];
diff --git a/lib/igt_perf.h b/lib/igt_perf.h
index 3d9ba2917..c9c6b27f7 100644
--- a/lib/igt_perf.h
+++ b/lib/igt_perf.h
@@ -57,6 +57,7 @@ uint64_t igt_perf_type_id(const char *device);
int igt_perf_events_dir(int i915);
int igt_perf_open(uint64_t type, uint64_t config);
int igt_perf_open_group(uint64_t type, uint64_t config, int group);
+int igt_perf_format(const char *device, const char *name, char *buff, int buflen);
const char *i915_perf_device(int i915, char *buf, int buflen);
uint64_t i915_perf_type_id(int i915);
--
2.47.1
More information about the igt-dev
mailing list