From: Terrence Xu <terrence.xu@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: colin.xu@intel.com, zhenyu.z.wang@intel.com, gordon.jin@intel.com
Subject: [igt-dev] [i-g-t] i915/perf: Correct the logic of finding i915 pmu event path
Date: Fri, 10 Apr 2020 18:20:46 +0800 [thread overview]
Message-ID: <20200410102046.6428-1-terrence.xu@intel.com> (raw)
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@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2020-04-10 10:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-10 10:20 Terrence Xu [this message]
2020-04-10 10:31 ` [igt-dev] [i-g-t] i915/perf: Correct the logic of finding i915 pmu event path Chris Wilson
2020-04-10 12:32 ` Xu, Terrence
2020-04-14 12:05 ` Tvrtko Ursulin
2020-04-10 11:10 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200410102046.6428-1-terrence.xu@intel.com \
--to=terrence.xu@intel.com \
--cc=colin.xu@intel.com \
--cc=gordon.jin@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=zhenyu.z.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox