[igt-dev] [i-g-t] i915/perf: Correct the logic of finding i915 pmu event path
Terrence Xu
terrence.xu at intel.com
Fri Apr 10 10:20:46 UTC 2020
Hardcoded i915 PMU event path /sys/bus/event_source/devices/i915
isn't always correct when vGPU isn't on BDF 0:2.0 in virtualization
environment.
e.g. It will show as sys/bus/event_source/devices/i915-0000:00:03.0
when vGPU is on BDF 0:3.0.
Refine the path name so that intel_gpu_top can find the correct adapter.
Signed-off-by: Terrence Xu <terrence.xu at intel.com>
---
lib/igt_perf.c | 15 ++++++++++++++-
tools/intel_gpu_top.c | 16 +++++++++++++++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/lib/igt_perf.c b/lib/igt_perf.c
index 418c1c188..3531209b3 100644
--- a/lib/igt_perf.c
+++ b/lib/igt_perf.c
@@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <sys/sysinfo.h>
#include <sys/sysmacros.h>
+#include <dirent.h>
#include "igt_perf.h"
@@ -75,11 +76,23 @@ uint64_t i915_perf_type_id(int i915)
uint64_t igt_perf_type_id(const char *device)
{
char buf[64];
+ char dev[64];
ssize_t ret;
int fd;
+ DIR *dir;
+ struct dirent *dent;
+
+ dir = opendir("/sys/bus/event_source/devices/");
+
+ while ((dent = readdir(dir))) {
+ if (!(strncmp(dent->d_name, device, strlen(device)))) {
+ strcpy(dev, dent->d_name);
+ break;
+ }
+ }
snprintf(buf, sizeof(buf),
- "/sys/bus/event_source/devices/%s/type", device);
+ "/sys/bus/event_source/devices/%s/type", dev);
fd = open(buf, O_RDONLY);
if (fd < 0)
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 8197482dd..065c40bba 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -170,11 +170,13 @@ static int engine_cmp(const void *__a, const void *__b)
static struct engines *discover_engines(void)
{
- const char *sysfs_root = "/sys/devices/i915/events";
+ const char *sysfs_root = "/sys/bus/event_source/devices/";
struct engines *engines;
struct dirent *dent;
int ret = 0;
DIR *d;
+ char dev[64];
+ char eve[64];
engines = malloc(sizeof(struct engines));
if (!engines)
@@ -184,7 +186,19 @@ static struct engines *discover_engines(void)
engines->num_engines = 0;
+
d = opendir(sysfs_root);
+ while ((dent = readdir(d))) {
+
+ if (!(strncmp(dent->d_name, "i915", 4))) {
+ strcpy(dev, dent->d_name);
+ break;
+ }
+ }
+
+ sprintf(eve, "%s%s/events", sysfs_root, dev);
+
+ d = opendir(eve);
if (!d)
return NULL;
--
2.17.1
More information about the igt-dev
mailing list