[igt-dev] [PATCH i-g-t] lib/igt_perf: Support multiple GPUs
Robert M. Fosha
robert.m.fosha at intel.com
Fri Dec 27 16:23:12 UTC 2019
With discrete graphics system can have both integrated and discrete GPU
handled by i915.
Update path to PMU for non-integrated devices to include PCI device name
string to match driver implementation. Integrated devices keep legacy
path.
Signed-off-by: Robert M. Fosha <robert.m.fosha at intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
---
lib/igt_perf.c | 53 ++++++++++++++++++++++++++++++++++++++++++++---
tools/meson.build | 2 +-
2 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/lib/igt_perf.c b/lib/igt_perf.c
index e3dec2cc..f4a0036f 100644
--- a/lib/igt_perf.c
+++ b/lib/igt_perf.c
@@ -5,27 +5,74 @@
#include <string.h>
#include <errno.h>
#include <sys/sysinfo.h>
+#include <sys/stat.h>
#include "igt_perf.h"
+#include "drmtest.h"
+#include "igt_debugfs.h"
+
+static char *perf_event_sysfs_path(void)
+{
+ int drm_fd;
+ static const char unique[] = "unique=";
+ static const char prefix[] = "/sys/bus/event_source/devices/i915";
+ char path[100];
+ char buf[100];
+ char *busid;
+ struct stat st;
+
+ drm_fd = drm_open_driver(DRIVER_INTEL);
+ igt_debugfs_read(drm_fd, "name", buf);
+ close(drm_fd);
+
+ strtok(buf, "\n");
+
+ busid = strstr(buf, unique);
+ if (!busid || strlen(busid) <= strlen(unique))
+ goto err_path;
+
+ busid += strlen(unique);
+ snprintf(path, sizeof(path), "%s-%s/type", prefix, busid);
+ if (stat(path, &st) || !S_ISREG(st.st_mode))
+ goto err_path;
+
+ return strndup(path, sizeof(path));
+
+err_path:
+ snprintf(path, sizeof(path), "%s/type", prefix);
+ return strndup(path, sizeof(path));
+
+}
+
uint64_t i915_type_id(void)
{
+ char *type_path;
char buf[64];
ssize_t ret;
int fd;
- fd = open("/sys/bus/event_source/devices/i915/type", O_RDONLY);
+ type_path = perf_event_sysfs_path();
+ if (type_path == NULL)
+ goto err_type_id;
+
+ fd = open(type_path, O_RDONLY);
if (fd < 0)
- return 0;
+ goto err_type_id;
ret = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (ret < 1)
- return 0;
+ goto err_type_id;
buf[ret] = '\0';
+ free(type_path);
return strtoull(buf, NULL, 0);
+
+err_type_id:
+ free(type_path);
+ return 0;
}
static int
diff --git a/tools/meson.build b/tools/meson.build
index 74822a33..c71a3ed2 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -99,7 +99,7 @@ shared_library('intel_aubdump', 'aubdump.c',
executable('intel_gpu_top', 'intel_gpu_top.c',
install : true,
install_rpath : bindir_rpathdir,
- dependencies : lib_igt_perf)
+ dependencies : [ igt_deps, lib_igt_perf ])
executable('amd_hdmi_compliance', 'amd_hdmi_compliance.c',
dependencies : [tool_deps],
--
2.21.0.5.gaeb582a983
More information about the igt-dev
mailing list