summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-08-22 13:47:33 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2017-09-06 19:00:53 +0100
commite56ab79711b3fb248bf165d1601acd25a2b7529d (patch)
tree84a98307d74144724ef204dbf44008736f154eec /lib
parent406bb36aae33f574da522bc4effbf028d5ebca9b (diff)
igt/pm_rpm: Use libc 'ftw' rather than opencoding our own filetree walk
By using ftw, we avoid the issue of having to handle directory recursion ourselves and can focus on the test of checking the reading a sysfs/debugfs does not break runtime suspend. In the process, disregard errors when opening the individual files as they may fail for other reasons. v2: Bracket the file open/close with the wait_for_suspended() tests. Whilst the fd is open, it may be keeping the device awake, e.g. i915_forcewake_user. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Tested-by: Jari Tahvanainen <jari.tahvanainen@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_debugfs.c50
-rw-r--r--lib/igt_debugfs.h1
-rw-r--r--lib/igt_sysfs.c41
-rw-r--r--lib/igt_sysfs.h1
4 files changed, 68 insertions, 25 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 63183e57..1e8c8cc3 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -127,38 +127,38 @@ const char *igt_debugfs_mount(void)
}
/**
- * igt_debugfs_dir:
+ * igt_debugfs_path:
* @device: fd of the device
+ * @path: buffer to store path
+ * @pathlen: len of @path buffer.
*
- * This opens the debugfs directory corresponding to device for use
- * with igt_sysfs_get() and related functions.
+ * This finds the debugfs directory corresponding to @device.
*
* Returns:
- * The directory fd, or -1 on failure.
+ * The directory path, or NULL on failure.
*/
-int igt_debugfs_dir(int device)
+char *igt_debugfs_path(int device, char *path, int pathlen)
{
struct stat st;
const char *debugfs_root;
- char path[200];
int idx;
if (fstat(device, &st)) {
igt_debug("Couldn't stat FD for DRM device: %s\n", strerror(errno));
- return -1;
+ return NULL;
}
if (!S_ISCHR(st.st_mode)) {
igt_debug("FD for DRM device not a char device!\n");
- return -1;
+ return NULL;
}
debugfs_root = igt_debugfs_mount();
idx = minor(st.st_rdev);
- snprintf(path, sizeof(path), "%s/dri/%d/name", debugfs_root, idx);
+ snprintf(path, pathlen, "%s/dri/%d/name", debugfs_root, idx);
if (stat(path, &st))
- return -1;
+ return NULL;
if (idx >= 64) {
int file, name_len, cmp_len;
@@ -166,17 +166,17 @@ int igt_debugfs_dir(int device)
file = open(path, O_RDONLY);
if (file < 0)
- return -1;
+ return NULL;
name_len = read(file, name, sizeof(name));
close(file);
for (idx = 0; idx < 16; idx++) {
- snprintf(path, sizeof(path), "%s/dri/%d/name",
+ snprintf(path, pathlen, "%s/dri/%d/name",
debugfs_root, idx);
file = open(path, O_RDONLY);
if (file < 0)
- return -1;
+ return NULL;
cmp_len = read(file, cmp, sizeof(cmp));
close(file);
@@ -186,10 +186,30 @@ int igt_debugfs_dir(int device)
}
if (idx == 16)
- return -1;
+ return NULL;
}
- snprintf(path, sizeof(path), "%s/dri/%d", debugfs_root, idx);
+ snprintf(path, pathlen, "%s/dri/%d", debugfs_root, idx);
+ return path;
+}
+
+/**
+ * igt_debugfs_dir:
+ * @device: fd of the device
+ *
+ * This opens the debugfs directory corresponding to device for use
+ * with igt_sysfs_get() and related functions.
+ *
+ * Returns:
+ * The directory fd, or -1 on failure.
+ */
+int igt_debugfs_dir(int device)
+{
+ char path[200];
+
+ if (!igt_debugfs_path(device, path, sizeof(path)))
+ return -1;
+
igt_debug("Opening debugfs directory '%s'\n", path);
return open(path, O_RDONLY);
}
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index f1a76406..4fa49d21 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -32,6 +32,7 @@
enum pipe;
const char *igt_debugfs_mount(void);
+char *igt_debugfs_path(int device, char *path, int pathlen);
int igt_debugfs_dir(int device);
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 9227e374..f7853ca0 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -86,26 +86,26 @@ static int writeN(int fd, const char *buf, int len)
}
/**
- * igt_sysfs_open:
+ * igt_sysfs_path:
* @device: fd of the device (or -1 to default to Intel)
+ * @path: buffer to fill with the sysfs path to the device
+ * @pathlen: length of @path buffer
* @idx: optional pointer to store the card index of the opened device
*
- * This opens the sysfs directory corresponding to device for use
- * with igt_sysfs_set() and igt_sysfs_get().
+ * This finds the sysfs directory corresponding to @device.
*
* Returns:
- * The directory fd, or -1 on failure.
+ * The directory path, or NULL on failure.
*/
-int igt_sysfs_open(int device, int *idx)
+char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
{
- char path[80];
struct stat st;
if (device != -1 && (fstat(device, &st) || !S_ISCHR(st.st_mode)))
- return -1;
+ return NULL;
for (int n = 0; n < 16; n++) {
- int len = sprintf(path, "/sys/class/drm/card%d", n);
+ int len = snprintf(path, pathlen, "/sys/class/drm/card%d", n);
if (device != -1) {
FILE *file;
int ret, maj, min;
@@ -132,10 +132,31 @@ int igt_sysfs_open(int device, int *idx)
path[len] = '\0';
if (idx)
*idx = n;
- return open(path, O_RDONLY);
+ return path;
}
- return -1;
+ return NULL;
+}
+
+/**
+ * igt_sysfs_open:
+ * @device: fd of the device (or -1 to default to Intel)
+ * @idx: optional pointer to store the card index of the opened device
+ *
+ * This opens the sysfs directory corresponding to device for use
+ * with igt_sysfs_set() and igt_sysfs_get().
+ *
+ * Returns:
+ * The directory fd, or -1 on failure.
+ */
+int igt_sysfs_open(int device, int *idx)
+{
+ char path[80];
+
+ if (!igt_sysfs_path(device, path, sizeof(path), idx))
+ return -1;
+
+ return open(path, O_RDONLY);
}
/**
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index d666438a..3ee89b0f 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -27,6 +27,7 @@
#include <stdbool.h>
+char *igt_sysfs_path(int device, char *path, int pathlen, int *idx);
int igt_sysfs_open(int device, int *idx);
int igt_sysfs_open_parameters(int device);
bool igt_sysfs_set_parameter(int device,