summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-03-24 18:11:08 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2017-03-24 18:12:23 +0000
commit58de785468782f29e6eb1d32d47b55b3d234dfcf (patch)
treeea862ef365385096817e1ae7b636fab440d03e4f
parent137360f75a42042198cf00d35a54cc68660d8c90 (diff)
Improve utilisation of igt_debugfs_dir()
As we can export igt_debugfs_dir() to cache the path to our debugfs directory, encourage a few more users to take advantage. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--lib/igt_debugfs.c57
-rw-r--r--lib/igt_debugfs.h7
-rw-r--r--lib/igt_gt.c43
-rw-r--r--tests/drv_missed_irq.c81
-rw-r--r--tests/gem_exec_whisper.c17
5 files changed, 79 insertions, 126 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 77769e0b..bd9ea3f0 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -131,7 +131,17 @@ const char *igt_debugfs_mount(void)
return "/sys/kernel/debug";
}
-static int __igt_debugfs_dir(int device)
+/**
+ * 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)
{
struct stat st;
const char *debugfs_root;
@@ -204,7 +214,7 @@ int igt_debugfs_open(int device, const char *filename, int mode)
{
int dir;
- dir = __igt_debugfs_dir(device);
+ dir = igt_debugfs_dir(device);
if (dir < 0)
return dir;
@@ -226,13 +236,17 @@ FILE *igt_debugfs_fopen(int device,
const char *filename,
const char *mode)
{
+ FILE *file;
int fd;
fd = igt_debugfs_open(device, filename, O_RDWR);
if (fd < 0)
return NULL;
- return fdopen(fd, mode);
+ file = fdopen(fd, mode);
+ close(fd);
+
+ return file;
}
/**
@@ -250,7 +264,7 @@ void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size)
int dir;
int len;
- dir = __igt_debugfs_dir(fd);
+ dir = igt_debugfs_dir(fd);
len = igt_sysfs_read(dir, filename, buf, buf_size - 1);
if (len < 0)
len = 0;
@@ -278,7 +292,7 @@ bool igt_debugfs_search(int fd, const char *filename, const char *substring)
igt_assert(file);
while (getline(&line, &n, file) >= 0) {
- matched = (strstr(line, substring) != NULL);
+ matched = strstr(line, substring) != NULL;
if (matched)
break;
}
@@ -419,7 +433,7 @@ static void igt_pipe_crc_reset(int drm_fd)
int fdir;
int fd;
- fdir = __igt_debugfs_dir(drm_fd);
+ fdir = igt_debugfs_dir(drm_fd);
if (fdir < 0)
return;
@@ -949,7 +963,7 @@ bool igt_drop_caches_has(int drm_fd, uint64_t val)
int dir;
mask = 0;
- dir = __igt_debugfs_dir(drm_fd);
+ dir = igt_debugfs_dir(drm_fd);
igt_sysfs_scanf(dir, "i915_gem_drop_caches", "0x%" PRIx64, &mask);
close(dir);
@@ -1043,7 +1057,7 @@ static int get_object_count(int fd)
igt_drop_caches_set(fd, DROP_RETIRE | DROP_ACTIVE | DROP_FREED);
- dir = __igt_debugfs_dir(fd);
+ dir = igt_debugfs_dir(fd);
scanned = igt_sysfs_scanf(dir, "i915_gem_objects",
"%i objects", &ret);
igt_assert_eq(scanned, 1);
@@ -1094,33 +1108,6 @@ int igt_get_stable_obj_count(int driver)
return obj_count;
}
-
-/* Non-i915 specific debugfs API */
-
-/**
- * igt_debugfs_dir:
- * @device: fd of the device (or -1 to default to Intel)
- *
- * 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)
-{
- struct stat st;
- char path[256];
-
- if (fstat(device, &st) || !S_ISCHR(st.st_mode))
- return -1;
-
- sprintf(path, "%s/dri/%d",
- igt_debugfs_mount(), (int)(st.st_rdev & 0xff));
- igt_debug("Opening debugfs dir %s\n", path);
- return open(path, O_RDONLY);
-}
-
void igt_debugfs_dump(int device, const char *filename)
{
char *contents;
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index ff396564..cdad562d 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -33,9 +33,10 @@ enum pipe;
const char *igt_debugfs_mount(void);
+int igt_debugfs_dir(int device);
+
int igt_debugfs_open(int fd, const char *filename, int mode);
-FILE *igt_debugfs_fopen(int fd, const char *filename,
- const char *mode);
+FILE *igt_debugfs_fopen(int fd, const char *filename, const char *mode);
void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size);
bool igt_debugfs_search(int fd, const char *filename, const char *substring);
@@ -203,8 +204,6 @@ void igt_enable_prefault(void);
* gem buffer objects
*/
int igt_get_stable_obj_count(int driver);
-
-int igt_debugfs_dir(int device);
void igt_debugfs_dump(int device, const char *filename);
#endif /* __IGT_DEBUGFS_H__ */
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index cc680862..976b0061 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -362,25 +362,16 @@ void igt_post_hang_ring(int fd, igt_hang_t arg)
*/
void igt_force_gpu_reset(int drm_fd)
{
- FILE *file;
- int fd, ret, wedged;
+ int dir, wedged;
igt_debug("Triggering GPU reset\n");
- fd = igt_debugfs_open(drm_fd, "i915_wedged", O_RDWR);
- igt_require(fd >= 0);
-
- ret = write(fd, "-1\n", 3);
- close(fd);
-
- igt_assert_eq(ret, 3);
+ dir = igt_debugfs_dir(drm_fd);
- file = igt_debugfs_fopen(drm_fd, "i915_wedged", "r");
- igt_assert(file);
+ igt_sysfs_set(dir, "i915_wedged", "-1");
+ igt_sysfs_scanf(dir, "i915_wedged", "%d", &wedged);
- wedged = 1;
- igt_ignore_warn(fscanf(file, "%d", &wedged));
- fclose(file);
+ close(dir);
igt_assert(!wedged);
}
@@ -538,23 +529,19 @@ void igt_clflush_range(void *addr, int size)
*/
unsigned intel_detect_and_clear_missed_interrupts(int fd)
{
- unsigned missed = 0;
- FILE *file;
+ unsigned missed;
+ int dir;
gem_quiescent_gpu(fd);
- file = igt_debugfs_fopen(fd, "i915_ring_missed_irq", "r");
- if (file) {
- igt_assert(fscanf(file, "%x", &missed) == 1);
- fclose(file);
- }
- if (missed) {
- file = igt_debugfs_fopen(fd, "i915_ring_missed_irq", "w");
- if (file) {
- fwrite("0\n", 1, 2, file);
- fclose(file);
- }
- }
+ dir = igt_debugfs_dir(fd);
+
+ missed = 0;
+ igt_assert(igt_sysfs_scanf(dir, "i915_ring_missed_irq", "%x", &missed) == 1);
+ if (missed)
+ igt_sysfs_set(dir, "i915_ring_missed_irq", "0");
+
+ close(dir);
errno = 0;
return missed;
diff --git a/tests/drv_missed_irq.c b/tests/drv_missed_irq.c
index 652cbc20..fb81f277 100644
--- a/tests/drv_missed_irq.c
+++ b/tests/drv_missed_irq.c
@@ -26,11 +26,11 @@
#include <sched.h>
#include "igt.h"
+#include "igt_debugfs.h"
+#include "igt_sysfs.h"
IGT_TEST_DESCRIPTION("Inject missed interrupts and make sure they are caught");
-static int drm_fd;
-
static void trigger_missed_interrupt(int fd, unsigned ring)
{
const int gen = intel_gen(intel_get_drm_devid(fd));
@@ -113,71 +113,49 @@ static void bind_to_cpu(int cpu)
igt_assert(sched_setscheduler(getpid(), SCHED_RR | SCHED_RESET_ON_FORK, &rt) == 0);
}
-static uint32_t engine_mask(void)
+static void enable_missed_irq(int dir)
{
- uint32_t mask;
- FILE *file;
-
- file = igt_debugfs_fopen(drm_fd, "i915_ring_test_irq", "w");
- fprintf(file, "0x%x", -1);
- fclose(file);
-
- mask = -1;
- file = igt_debugfs_fopen(drm_fd, "i915_ring_test_irq", "r");
- igt_ignore_warn(fscanf(file, "%x", &mask));
- fclose(file);
-
- file = igt_debugfs_fopen(drm_fd, "i915_ring_test_irq", "w");
- fprintf(file, "0");
- fclose(file);
-
- return mask;
+ igt_sysfs_printf(dir, "i915_ring_test_irq", "0x%x", -1);
}
-static void enable_missed_irq(void)
+static uint32_t disable_missed_irq(int dir)
{
- FILE *file;
-
- file = igt_debugfs_fopen(drm_fd, "i915_ring_test_irq", "w");
- fprintf(file, "0x%x", -1);
- fclose(file);
-}
-
-static uint32_t disable_missed_irq(void)
-{
- FILE *file;
uint32_t mask = 0;
- file = igt_debugfs_fopen(drm_fd, "i915_ring_test_irq", "r");
- igt_ignore_warn(fscanf(file, "%x", &mask));
- fclose(file);
-
- file = igt_debugfs_fopen(drm_fd, "i915_ring_test_irq", "w");
- fprintf(file, "0");
- fclose(file);
+ igt_sysfs_scanf(dir, "i915_ring_test_irq", "%x", &mask);
+ igt_sysfs_set(dir, "i915_ring_test_irq", "0");
return mask;
}
+static uint32_t engine_mask(int dir)
+{
+ enable_missed_irq(dir);
+ return disable_missed_irq(dir);
+}
+
igt_simple_main
{
const struct intel_execution_engine *e;
unsigned expect_rings;
unsigned missed_rings;
unsigned check_rings;
+ int debugfs, device;
igt_skip_on_simulation();
bind_to_cpu(0);
- drm_fd = drm_open_driver(DRIVER_INTEL);
- igt_require_gem(drm_fd);
- gem_require_mmap_wc(drm_fd);
- igt_fork_hang_detector(drm_fd);
+ device = drm_open_driver(DRIVER_INTEL);
+ igt_require_gem(device);
+ gem_require_mmap_wc(device);
+ igt_fork_hang_detector(device);
+
+ debugfs = igt_debugfs_dir(device);
- expect_rings = engine_mask();
+ expect_rings = engine_mask(debugfs);
igt_debug("Clearing rings %x\n", expect_rings);
- intel_detect_and_clear_missed_interrupts(drm_fd);
+ intel_detect_and_clear_missed_interrupts(device);
for (e = intel_execution_engines; e->name; e++) {
if (expect_rings == -1 && e->exec_id)
continue;
@@ -187,12 +165,12 @@ igt_simple_main
igt_debug("Clearing ring %s [%x]\n",
e->name, e->exec_id | e->flags);
- trigger_missed_interrupt(drm_fd, e->exec_id | e->flags);
+ trigger_missed_interrupt(device, e->exec_id | e->flags);
}
- igt_assert_eq(intel_detect_and_clear_missed_interrupts(drm_fd), 0);
+ igt_assert_eq(intel_detect_and_clear_missed_interrupts(device), 0);
igt_debug("Testing rings %x\n", expect_rings);
- enable_missed_irq();
+ enable_missed_irq(debugfs);
for (e = intel_execution_engines; e->name; e++) {
if (expect_rings == -1 && e->exec_id)
continue;
@@ -202,11 +180,11 @@ igt_simple_main
igt_debug("Executing on ring %s [%x]\n",
e->name, e->exec_id | e->flags);
- trigger_missed_interrupt(drm_fd, e->exec_id | e->flags);
+ trigger_missed_interrupt(device, e->exec_id | e->flags);
}
- missed_rings = intel_detect_and_clear_missed_interrupts(drm_fd);
+ missed_rings = intel_detect_and_clear_missed_interrupts(device);
- check_rings = disable_missed_irq();
+ check_rings = disable_missed_irq(debugfs);
igt_assert_eq_u32(check_rings, expect_rings);
if (expect_rings == -1)
@@ -214,6 +192,7 @@ igt_simple_main
else
igt_assert_eq_u32(missed_rings, expect_rings);
+ close(debugfs);
igt_stop_hang_detector();
- close(drm_fd);
+ close(device);
}
diff --git a/tests/gem_exec_whisper.c b/tests/gem_exec_whisper.c
index 53988103..dab3a247 100644
--- a/tests/gem_exec_whisper.c
+++ b/tests/gem_exec_whisper.c
@@ -29,6 +29,7 @@
#include "igt.h"
#include "igt_gt.h"
+#include "igt_debugfs.h"
#include "igt_sysfs.h"
#define LOCAL_I915_EXEC_NO_RELOC (1<<11)
@@ -41,16 +42,11 @@
#define VERIFY 0
-static void write_seqno(int fd, unsigned offset)
+static void write_seqno(int dir, unsigned offset)
{
uint32_t seqno = UINT32_MAX - offset;
- FILE *file;
- file = igt_debugfs_fopen(fd, "i915_next_seqno", "w");
- igt_assert(file);
-
- igt_assert(fprintf(file, "0x%x", seqno) > 0);
- fclose(file);
+ igt_sysfs_printf(dir, "i915_next_seqno", "0x%x", seqno);
igt_debug("next seqno set to: 0x%x\n", seqno);
}
@@ -217,6 +213,9 @@ static void whisper(int fd, unsigned engine, unsigned flags)
unsigned int reloc_interruptions = 0;
unsigned int eb_migrations = 0;
uint64_t old_offset;
+ int debugfs;
+
+ debugfs = igt_debugfs_dir(fd);
nengine = 0;
if (engine == -1) {
@@ -341,7 +340,7 @@ static void whisper(int fd, unsigned engine, unsigned flags)
uint64_t offset;
if (!(flags & FORKED))
- write_seqno(fd, pass);
+ write_seqno(debugfs, pass);
if (flags & HANG)
submit_hang(&hang, engines, nengine);
@@ -489,6 +488,8 @@ static void whisper(int fd, unsigned engine, unsigned flags)
fini_hang(&hang);
else
igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
+
+ close(debugfs);
}
static void print_welcome(int fd)