[Intel-gfx] [PATCH 2/5] lib/igt_debugfs: Remove debugfs from igt_debugfs_open

Daniel Vetter daniel.vetter at ffwll.ch
Sun Mar 16 15:02:25 CET 2014


Also update the api docs a bit since the Returns: section was missing.

Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 lib/igt_debugfs.c       | 38 +++++++++++++++-----------------------
 lib/igt_debugfs.h       |  2 +-
 tests/gem_reset_stats.c |  6 +-----
 tests/pm_rps.c          |  8 ++------
 4 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 4a3384871717..2f9c7b117aa5 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -139,16 +139,21 @@ static igt_debugfs_t *__igt_debugfs_singleton(void)
 
 /**
  * igt_debugfs_open:
- * @debugfs: debugfs access structure
- * @filename: name of the debugfs node to open
  * @mode: mode bits as used by open()
  *
  * This opens a debugfs file as a Unix file descriptor. The filename should be
  * relative to the drm device's root, i.e without "drm/<minor>".
+ *
+ * Returns:
+ * The Unix file descriptor for the debugfs file or -1 if that didn't work out.
  */
-int igt_debugfs_open(igt_debugfs_t *debugfs, const char *filename, int mode)
+int igt_debugfs_open(const char *filename, int mode)
 {
 	char buf[1024];
+	igt_debugfs_t *debugfs = __igt_debugfs_singleton();
+
+	if (!debugfs)
+		return -1;
 
 	sprintf(buf, "%s/%s", debugfs->dri_path, filename);
 	return open(buf, mode);
@@ -297,11 +302,9 @@ static void igt_pipe_crc_pipe_off(int fd, enum pipe pipe)
 
 static void igt_pipe_crc_reset(void)
 {
-	igt_debugfs_t debugfs;
 	int fd;
 
-	igt_debugfs_init(&debugfs);
-	fd = igt_debugfs_open(&debugfs, "i915_display_crc_ctl", O_WRONLY);
+	fd = igt_debugfs_open("i915_display_crc_ctl", O_WRONLY);
 
 	igt_pipe_crc_pipe_off(fd, PIPE_A);
 	igt_pipe_crc_pipe_off(fd, PIPE_B);
@@ -364,12 +367,11 @@ igt_pipe_crc_new(igt_debugfs_t *debugfs, enum pipe pipe,
 
 	pipe_crc = calloc(1, sizeof(struct _igt_pipe_crc));
 
-	pipe_crc->ctl_fd = igt_debugfs_open(debugfs,
-					    "i915_display_crc_ctl", O_WRONLY);
+	pipe_crc->ctl_fd = igt_debugfs_open("i915_display_crc_ctl", O_WRONLY);
 	igt_assert(pipe_crc->ctl_fd != -1);
 
 	sprintf(buf, "i915_pipe_%c_crc", pipe_name(pipe));
-	pipe_crc->crc_fd = igt_debugfs_open(debugfs, buf, O_RDONLY);
+	pipe_crc->crc_fd = igt_debugfs_open(buf, O_RDONLY);
 	igt_assert(pipe_crc->crc_fd != -1);
 
 	pipe_crc->line_len = PIPE_CRC_LINE_LEN;
@@ -528,15 +530,13 @@ void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc)
  */
 void igt_drop_caches_set(uint64_t val)
 {
-	igt_debugfs_t debugfs;
 	int fd;
 	char data[19];
 	size_t nbytes;
 
 	sprintf(data, "0x%" PRIx64, val);
 
-	igt_debugfs_init(&debugfs);
-	fd = igt_debugfs_open(&debugfs, "i915_gem_drop_caches", O_WRONLY);
+	fd = igt_debugfs_open("i915_gem_drop_caches", O_WRONLY);
 
 	igt_assert(fd >= 0);
 	nbytes = write(fd, data, strlen(data) + 1);
@@ -606,18 +606,10 @@ void igt_enable_prefault(void)
  * This functions opens the debugfs forcewake file and so prevents the GT from
  * suspending. The reference is automatically dropped when the is closed.
  *
- * Returns: The file descriptor of the forcewake handle or -1 if that didn't
- * work out.
+ * Returns:
+ * The file descriptor of the forcewake handle or -1 if that didn't work out.
  */
 int igt_open_forcewake_handle(void)
 {
-	igt_debugfs_t debugfs;
-	int fd;
-
-	if (!__igt_debugfs_init(&debugfs))
-		return -1;
-
-	fd = igt_debugfs_open(&debugfs, "i915_forcewake_user", O_WRONLY);
-
-	return fd;
+	return igt_debugfs_open("i915_forcewake_user", O_WRONLY);
 }
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 5e153b175401..690f3dcaec41 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -42,7 +42,7 @@ typedef struct {
 } igt_debugfs_t;
 
 void igt_debugfs_init(igt_debugfs_t *debugfs);
-int igt_debugfs_open(igt_debugfs_t *debugfs, const char *filename, int mode);
+int igt_debugfs_open(const char *filename, int mode);
 FILE *igt_debugfs_fopen(igt_debugfs_t *debugfs, const char *filename,
 			const char *mode);
 
diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
index 71ba6dfe1659..3719f4070403 100644
--- a/tests/gem_reset_stats.c
+++ b/tests/gem_reset_stats.c
@@ -76,8 +76,6 @@ struct local_drm_i915_gem_context_destroy {
 #define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_gem_context_destroy)
 #define GET_RESET_STATS_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x32, struct local_drm_i915_reset_stats)
 
-static igt_debugfs_t dfs;
-
 #define LOCAL_I915_EXEC_VEBOX	(4 << 0)
 
 struct target_ring;
@@ -244,7 +242,7 @@ static void stop_rings(const int mask)
 
 	igt_assert((mask & ~((1 << NUM_RINGS) - 1)) == 0);
 	igt_assert(snprintf(buf, sizeof(buf), "0x%02x", mask) == 4);
-	fd = igt_debugfs_open(&dfs, "i915_ring_stop", O_WRONLY);
+	fd = igt_debugfs_open("i915_ring_stop", O_WRONLY);
 	igt_assert(fd >= 0);
 
 	igt_assert(write(fd, buf, 4) == 4);
@@ -1040,8 +1038,6 @@ igt_main
 		igt_skip_on_f(ret != 0 && (errno == ENODEV || errno == EINVAL),
 			      "Kernel is too old, or contexts not supported: %s\n",
 			      strerror(errno));
-
-		igt_debugfs_init(&dfs);
 	}
 
 	igt_subtest("params")
diff --git a/tests/pm_rps.c b/tests/pm_rps.c
index d964f2a7c10e..2f321840edcd 100644
--- a/tests/pm_rps.c
+++ b/tests/pm_rps.c
@@ -63,8 +63,6 @@ struct junk {
 	{ "cur", "r", NULL }, { "min", "rb+", NULL }, { "max", "rb+", NULL }, { "RP0", "r", NULL }, { "RP1", "r", NULL }, { "RPn", "r", NULL }, { NULL, NULL, NULL }
 };
 
-static igt_debugfs_t dfs;
-
 static int readval(FILE *filp)
 {
 	int val;
@@ -305,7 +303,7 @@ static void stop_rings(void)
 	int fd;
 	static const char data[] = "0xf";
 
-	fd = igt_debugfs_open(&dfs, "i915_ring_stop", O_WRONLY);
+	fd = igt_debugfs_open("i915_ring_stop", O_WRONLY);
 	igt_assert(fd >= 0);
 
 	igt_debug("injecting ring stop\n");
@@ -320,7 +318,7 @@ static bool rings_stopped(void)
 	static char buf[128];
 	unsigned long long val;
 
-	fd = igt_debugfs_open(&dfs, "i915_ring_stop", O_RDONLY);
+	fd = igt_debugfs_open("i915_ring_stop", O_RDONLY);
 	igt_assert(fd >= 0);
 
 	igt_assert(read(fd, buf, sizeof(buf)) > 0);
@@ -555,8 +553,6 @@ igt_main
 		igt_install_exit_handler(pm_rps_exit_handler);
 
 		load_helper_init();
-
-		igt_debugfs_init(&dfs);
 	}
 
 	igt_subtest("basic-api")
-- 
1.8.1.4




More information about the Intel-gfx mailing list