summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-08-23 15:51:21 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-08-23 15:53:01 +0100
commit9574cb1a3de0dfe45c59420e2cb9a74fc23baecc (patch)
treeaa474dcec21c0f00196394e6d78a4e97bd9bce06
parentfd88db77cccf5d8d9be133dfcb3cdc3ff3f219f3 (diff)
overlay: Search for right debugfs path
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--overlay/debugfs.c25
-rw-r--r--overlay/debugfs.h1
-rw-r--r--overlay/gem-objects.c7
-rw-r--r--overlay/gpu-freq.c7
-rw-r--r--overlay/gpu-perf.c4
-rw-r--r--overlay/power.c11
6 files changed, 43 insertions, 12 deletions
diff --git a/overlay/debugfs.c b/overlay/debugfs.c
index 644f434b..ccce2279 100644
--- a/overlay/debugfs.c
+++ b/overlay/debugfs.c
@@ -25,15 +25,25 @@
#include <sys/stat.h>
#include <sys/mount.h>
#include <errno.h>
+#include <stdio.h>
#include "debugfs.h"
+char debugfs_path[128];
+
int debugfs_init(void)
{
+ const char *path = "/sys/kernel/debug";
struct stat st;
+ int n;
+
+ if (stat("/debug/dri", &st) == 0) {
+ path = "/debug/dri";
+ goto find_minor;
+ }
if (stat("/sys/kernel/debug/dri", &st) == 0)
- return 0;
+ goto find_minor;
if (stat("/sys/kernel/debug", &st))
return errno;
@@ -41,5 +51,16 @@ int debugfs_init(void)
if (mount("debug", "/sys/kernel/debug", "debugfs", 0, 0))
return errno;
- return 0;
+find_minor:
+ for (n = 0; n < 16; n++) {
+ int len = sprintf(debugfs_path, "%s/dri/%d", path, n);
+ sprintf(debugfs_path + len, "/i915_error_state");
+ if (stat(debugfs_path, &st) == 0) {
+ debugfs_path[len] = '\0';
+ return 0;
+ }
+ }
+
+ debugfs_path[0] = '\0';
+ return ENOENT;
}
diff --git a/overlay/debugfs.h b/overlay/debugfs.h
index 476553c9..0e5ad95d 100644
--- a/overlay/debugfs.h
+++ b/overlay/debugfs.h
@@ -25,6 +25,7 @@
#ifndef DEBUGFS_H
#define DEBUGFS_H
+extern char debugfs_path[128];
int debugfs_init(void);
#endif /* DEBUGFS_H */
diff --git a/overlay/gem-objects.c b/overlay/gem-objects.c
index bf96a341..14427a73 100644
--- a/overlay/gem-objects.c
+++ b/overlay/gem-objects.c
@@ -30,6 +30,7 @@
#include <string.h>
#include "gem-objects.h"
+#include "debugfs.h"
/* /sys/kernel/debug/dri/0/i915_gem_objects:
* 46 objects, 20107264 bytes
@@ -52,7 +53,8 @@ int gem_objects_init(struct gem_objects *obj)
memset(obj, 0, sizeof(*obj));
- fd = open("/sys/kernel/debug/dri/0/i915_gem_objects", 0);
+ sprintf(buf, "%s/i915_gem_objects", debugfs_path);
+ fd = open(buf, 0);
if (fd < 0)
return errno;
len = read(fd, buf, sizeof(buf)-1);
@@ -97,7 +99,8 @@ int gem_objects_update(struct gem_objects *obj)
freed = obj->comm;
obj->comm = NULL;
- fd = open("/sys/kernel/debug/dri/0/i915_gem_objects", 0);
+ sprintf(buf, "%s/i915_gem_objects", debugfs_path);
+ fd = open(buf, 0);
if (fd < 0) {
ret = errno;
goto done;
diff --git a/overlay/gpu-freq.c b/overlay/gpu-freq.c
index 3cd69f9f..b34f66f2 100644
--- a/overlay/gpu-freq.c
+++ b/overlay/gpu-freq.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include "gpu-freq.h"
+#include "debugfs.h"
int gpu_freq_init(struct gpu_freq *gf)
{
@@ -37,7 +38,8 @@ int gpu_freq_init(struct gpu_freq *gf)
memset(gf, 0, sizeof(*gf));
- fd = open("/sys/kernel/debug/dri/0/i915_cur_delayinfo", 0);
+ sprintf(buf, "%s/i915_cur_delayinfo", debugfs_path);
+ fd = open(buf, 0);
if (fd < 0)
return gf->error = errno;
@@ -83,7 +85,8 @@ int gpu_freq_update(struct gpu_freq *gf)
if (gf->error)
return gf->error;
- fd = open("/sys/kernel/debug/dri/0/i915_cur_delayinfo", 0);
+ sprintf(buf, "%s/i915_cur_delayinfo", debugfs_path);
+ fd = open(buf, 0);
if (fd < 0)
return gf->error = errno;
diff --git a/overlay/gpu-perf.c b/overlay/gpu-perf.c
index b9ca11bd..61e447da 100644
--- a/overlay/gpu-perf.c
+++ b/overlay/gpu-perf.c
@@ -36,6 +36,7 @@
#include <errno.h>
#include "gpu-perf.h"
+#include "debugfs.h"
#if defined(__i386__)
#define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
@@ -45,7 +46,6 @@
#define rmb() asm volatile("lfence" ::: "memory")
#endif
-#define TRACING_EVENT_PATH "/sys/kernel/debug/tracing/events"
#define N_PAGES 32
struct sample_event {
@@ -85,7 +85,7 @@ static uint64_t tracepoint_id(const char *sys, const char *name)
char buf[1024];
int fd, n;
- snprintf(buf, sizeof(buf), "%s/%s/%s/id", TRACING_EVENT_PATH, sys, name);
+ snprintf(buf, sizeof(buf), "%s/tracing/events/%s/%s/id", debugfs_path, sys, name);
fd = open(buf, 0);
if (fd < 0)
return 0;
diff --git a/overlay/power.c b/overlay/power.c
index aecf54e8..e69b1a19 100644
--- a/overlay/power.c
+++ b/overlay/power.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include "power.h"
+#include "debugfs.h"
/* XXX Is this exposed through RAPL? */
@@ -41,7 +42,8 @@ int power_init(struct power *power)
memset(power, 0, sizeof(*power));
- fd = open("/sys/kernel/debug/dri/0/i915_energy_uJ", 0);
+ sprintf(buf, "%s/i915_energy_uJ", debugfs_path);
+ fd = open(buf, 0);
if (fd < 0)
return power->error = errno;
@@ -54,12 +56,13 @@ int power_init(struct power *power)
return 0;
}
-static uint64_t file_to_u64(const char *path)
+static uint64_t file_to_u64(const char *name)
{
char buf[4096];
int fd, len;
- fd = open(path, 0);
+ sprintf(buf, "%s/i915_energy_uJ", name);
+ fd = open(buf, 0);
if (fd < 0)
return 0;
@@ -93,7 +96,7 @@ int power_update(struct power *power)
if (power->error)
return power->error;
- s->energy = file_to_u64("/sys/kernel/debug/dri/0/i915_energy_uJ");
+ s->energy = file_to_u64("i915_energy_uJ");
s->timestamp = clock_ms_to_u64();
if (power->count == 1)
return EAGAIN;