Skip to contentSkip to conversation

lib: add igt_get_stop_rings and igt_set_stop_rings

PATCH New Mika Kuoppala 1 participant 4 messages Mar 28, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 lib: add igt_get_stop_rings and igt_set_stop_rings

Multiple tests are introducing hangs by fidding with i915_ring_stop debugfs entry.

---
 lib/drmtest.c     |   16 ++++++++
 lib/igt_debugfs.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_debugfs.h |   33 ++++++++++++++++
 3 files changed, 157 insertions(+)
lib/drmtest.c +16 -0
index b1bf589..2c9cf62 100644
@@ -88,6 +88,18 @@ is_intel(int fd)
 	return IS_INTEL(devid);
 }
 
+static void check_stop_rings(void)
+{
+	enum stop_ring_flags flags;
+	flags = igt_get_stop_rings();
+	igt_warn_on_f(flags != 0,
+		      "i915_ring_stop flags on exit 0x%x, can't quiescent gpu cleanly\n",
+		      flags);
+
+	if (flags)
+		igt_set_stop_rings(STOP_RING_NONE);
+}
+
 #define LOCAL_I915_EXEC_VEBOX	(4 << 0)
 /**
  * gem_quiescent_gpu:
@@ -108,6 +120,8 @@ void gem_quiescent_gpu(int fd)
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 gem_exec[1];
 
+	check_stop_rings();
+
 	handle = gem_create(fd, 4096);
 	gem_write(fd, handle, 0, batch, sizeof(batch));
 
@@ -252,6 +266,7 @@ static void quiescent_gpu_at_exit(int sig)
 	if (at_exit_drm_fd < 0)
 		return;
 
+	check_stop_rings();
 	gem_quiescent_gpu(at_exit_drm_fd);
 	close(at_exit_drm_fd);
 	at_exit_drm_fd = -1;
@@ -262,6 +277,7 @@ static void quiescent_gpu_at_exit_render(int sig)
 	if (at_exit_drm_render_fd < 0)
 		return;
 
+	check_stop_rings();
 	gem_quiescent_gpu(at_exit_drm_render_fd);
 	close(at_exit_drm_render_fd);
 	at_exit_drm_render_fd = -1;
lib/igt_debugfs.c +108 -0

120 lines not on this page · raw message

lib/igt_debugfs.h +33 -0
index 3312a8b..bcd7f76 100644
@@ -143,4 +143,37 @@ void igt_enable_prefault(void);
 
 int igt_open_forcewake_handle(void);
 
+/**
+ * stop_ring_flags:
+ *
+ * @STOP_RING_NONE: Can be used to clear the pending stop (warning: hang might
+ * be declared already). Returned by igt_get_stop_rings() if there is
+ * no currently stopped rings.
+ * @STOP_RING_RENDER: Render ring
+ * @STOP_RING_BSD: Video encoding/decoding ring
+ * @STOP_RING_BLT: Blitter ring
+ * @STOP_RING_VEBOX: Video enchanment ring
+ * @STOP_RING_ALL: All rings
+ * @STOP_RING_ALLOW_ERRORS: Driver will not omit expected DRM_ERRORS
+ * @STOP_RING_ALLOW_BAN: Driver will use context ban policy
+ * @STOP_RING_DEFAULT: STOP_RING_ALL | STOP_RING_ALLOW_ERRORS
+ * Enumeration of all supported flags for igt_set_stop_rings().
+ *
+ */
+enum stop_ring_flags {
+	STOP_RING_NONE = 0x00,
+	STOP_RING_RENDER = (1 << 0),
+	STOP_RING_BSD = (1 << 1),
+	STOP_RING_BLT = (1 << 2),
+	STOP_RING_VEBOX = (1 << 3),
+	STOP_RING_ALL = 0xff,
+	STOP_RING_ALLOW_ERRORS = (1 << 30),
+	STOP_RING_ALLOW_BAN = (1 << 31),
+	STOP_RING_DEFAULTS = STOP_RING_ALL | STOP_RING_ALLOW_ERRORS,
+};
+
+enum stop_ring_flags igt_to_stop_ring_flag(int ring);
+void igt_set_stop_rings(enum stop_ring_flags flags);
+enum stop_ring_flags igt_get_stop_rings(void);
+
 #endif /* __IGT_DEBUGFS_H__ */
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/4 tests: use lib igt_[get|set]_stop_rings()

on gem_reset_stats, kms_flip and pm_rps.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=75876

---
 tests/gem_reset_stats.c |   55 +++++++++++++++++------------------------------
 tests/kms_flip.c        |   36 ++++++-------------------------
 tests/pm_rps.c          |   35 ++----------------------------
 3 files changed, 28 insertions(+), 98 deletions(-)
tests/gem_reset_stats.c +20 -35
index 3e7460f..9581703 100644
@@ -242,38 +242,10 @@ static int exec_valid(int fd, int ctx)
 	return exec_valid_ring(fd, ctx, current_ring->exec);
 }
 
-static void stop_rings(const int mask)
-{
-	int fd;
-	char buf[80];
-
-	igt_assert((mask & ~((1 << NUM_RINGS) - 1)) == 0);
-	igt_assert(snprintf(buf, sizeof(buf), "0x%02x", mask) == 4);
-	fd = igt_debugfs_open("i915_ring_stop", O_WRONLY);
-	igt_assert(fd >= 0);
-
-	igt_assert(write(fd, buf, 4) == 4);
-	close(fd);
-}
-
 #define BUFSIZE (4 * 1024)
 #define ITEMS   (BUFSIZE >> 2)
 
-static int ring_to_mask(int ring)
-{
-	for (unsigned i = 0; i < NUM_RINGS; i++) {
-		const struct target_ring *r = &rings[i];
-
-		if (r->exec == ring)
-			return (1 << i);
-	}
-
-	igt_assert(0);
-
-	return -1;
-}
-
-static int inject_hang_ring(int fd, int ctx, int ring)
+static int inject_hang_ring(int fd, int ctx, int ring, bool ignore_ban_error)
 {
 	struct drm_i915_gem_execbuffer2 execbuf;
 	struct drm_i915_gem_exec_object2 exec;
@@ -281,6 +253,7 @@ static int inject_hang_ring(int fd, int ctx, int ring)
 	uint32_t *buf;
 	int roff, i;
 	unsigned cmd_len = 2;
+	enum stop_ring_flags flags;
 
 	srandom(time(NULL));
 
@@ -362,14 +335,26 @@ static int inject_hang_ring(int fd, int ctx, int ring)
 
 	free(buf);
 
-	stop_rings(ring_to_mask(ring));
+	flags = igt_to_stop_ring_flag(ring);
+
+	flags |= STOP_RING_ALLOW_BAN;
+
+	if (!ignore_ban_error)
+		flags |= STOP_RING_ALLOW_ERRORS;
+
+	igt_set_stop_rings(flags);
 
 	return exec.handle;
 }
 
 static int inject_hang(int fd, int ctx)
 {
-	return inject_hang_ring(fd, ctx, current_ring->exec);
+	return inject_hang_ring(fd, ctx, current_ring->exec, false);
+}
+
+static int inject_hang_no_ban_error(int fd, int ctx)
+{
+	return inject_hang_ring(fd, ctx, current_ring->exec, true);
 }
 
 static int _assert_reset_status(int fd, int ctx, int status)
@@ -551,7 +536,7 @@ static void test_ban(void)
 	assert_reset_status(fd_bad, 0, RS_NO_ERROR);
 	assert_reset_status(fd_good, 0, RS_NO_ERROR);
 
-	h2 = inject_hang(fd_bad, 0);
+	h2 = inject_hang_no_ban_error(fd_bad, 0);
 	igt_assert(h2 >= 0);
 	active_count++;
 	/* Second hang will be pending for this */
@@ -561,7 +546,7 @@ static void test_ban(void)
 	h7 = exec_valid(fd_good, 0);
 
         while (retry--) {
-                h3 = inject_hang(fd_bad, 0);
+                h3 = inject_hang_no_ban_error(fd_bad, 0);
                 igt_assert(h3 >= 0);
                 gem_sync(fd_bad, h3);
 		active_count++;
@@ -643,7 +628,7 @@ static void test_ban_ctx(void)
 	assert_reset_status(fd, ctx_good, RS_NO_ERROR);
 	assert_reset_status(fd, ctx_bad, RS_NO_ERROR);
 
-	h2 = inject_hang(fd, ctx_bad);
+	h2 = inject_hang_no_ban_error(fd, ctx_bad);
 	igt_assert(h2 >= 0);
 	active_count++;
 	/* Second hang will be pending for this */
@@ -653,7 +638,7 @@ static void test_ban_ctx(void)
 	h7 = exec_valid(fd, ctx_good);
 
         while (retry--) {
-                h3 = inject_hang(fd, ctx_bad);
+                h3 = inject_hang_no_ban_error(fd, ctx_bad);
                 igt_assert(h3 >= 0);
                 gem_sync(fd, h3);
 		active_count++;
tests/kms_flip.c +6 -30
index a3a7be2..24bbc0b 100644
@@ -44,6 +44,7 @@
 #include "intel_batchbuffer.h"
 #include "igt_kms.h"
 #include "igt_aux.h"
+#include "igt_debugfs.h"
 
 #define TEST_DPMS		(1 << 0)
 #define TEST_WITH_DUMMY_BCS	(1 << 1)
@@ -692,35 +693,17 @@ static void set_y_tiling(struct test_output *o, int fb_idx)
 
 static void stop_rings(bool stop)
 {
-	static const char dfs_base[] = "/sys/kernel/debug/dri";
-	static const char dfs_entry[] = "i915_ring_stop";
-	static const char stop_data[] = "0xf";
-	static const char run_data[] = "0x0";
-	char fname[FILENAME_MAX];
-	int card_index = drm_get_card();
-	int fd;
-
-	snprintf(fname, FILENAME_MAX, "%s/%i/%s",
-		 dfs_base, card_index, dfs_entry);
-
-	fd = open(fname, O_WRONLY);
-	igt_assert(fd >= 0);
-
 	if (stop)
-		igt_assert(write(fd, stop_data, sizeof(stop_data)) == sizeof(stop_data));
+		igt_set_stop_rings(STOP_RING_DEFAULTS);
 	else
-		igt_assert(write(fd, run_data, sizeof(run_data)) == sizeof(run_data));
-
-	close(fd);
+		igt_set_stop_rings(STOP_RING_NONE);
 }
 
 static void eat_error_state(void)
 {
 	static const char dfs_base[] = "/sys/kernel/debug/dri";
 	static const char dfs_entry_error[] = "i915_error_state";
-	static const char dfs_entry_stop[] = "i915_ring_stop";
 	static const char data[] = "";
-	static char tmp[128];
 	char fname[FILENAME_MAX];
 	int card_index = drm_get_card();
 	int fd;
@@ -739,16 +722,9 @@ static void eat_error_state(void)
 
 	/* and check whether stop_rings is not reset, i.e. the hang has indeed
 	 * happened */
-	snprintf(fname, FILENAME_MAX, "%s/%i/%s",
-		 dfs_base, card_index, dfs_entry_stop);
-
-	fd = open(fname, O_RDONLY);
-	igt_assert(fd >= 0);
-
-	igt_assert(read(fd, tmp, sizeof tmp) > 0);
-
-	igt_assert_f(atoi(tmp) == 0,
-		     "no gpu hang detected, stop_rings is still %s\n", tmp);
+	igt_assert_f(igt_get_stop_rings() == STOP_RING_NONE,
+		     "no gpu hang detected, stop_rings is still 0x%x\n",
+		     igt_get_stop_rings());
 
 	close(fd);
 }
tests/pm_rps.c +2 -33
index 09ae349..c1156a5 100644
@@ -306,37 +306,6 @@ static void load_helper_deinit(void)
 		drm_intel_bufmgr_destroy(lh.bufmgr);
 }
 
-static void stop_rings(void)
-{
-	int fd;
-	static const char data[] = "0xf";
-
-	fd = igt_debugfs_open("i915_ring_stop", O_WRONLY);
-	igt_assert(fd >= 0);
-
-	igt_debug("injecting ring stop\n");
-	igt_assert(write(fd, data, sizeof(data)) == sizeof(data));
-
-	close(fd);
-}
-
-static bool rings_stopped(void)
-{
-	int fd;
-	static char buf[128];
-	unsigned long long val;
-
-	fd = igt_debugfs_open("i915_ring_stop", O_RDONLY);
-	igt_assert(fd >= 0);
-
-	igt_assert(read(fd, buf, sizeof(buf)) > 0);
-	close(fd);
-
-	sscanf(buf, "%llx", &val);
-
-	return (bool)val;
-}
-
 static void min_max_config(void (*check)(void))
 {
 	int fmid = (origfreqs[RPn] + origfreqs[RP0]) / 2;
@@ -499,8 +468,8 @@ static void reset(void)
 	stabilize_check(pre_freqs);
 
 	igt_debug("Stop rings...\n");
-	stop_rings();
-	while (rings_stopped())
+	igt_set_stop_rings(STOP_RING_DEFAULTS);
+	while (igt_get_stop_rings())
 		usleep(1000 * 100);
 	igt_debug("Ring stop cleared\n");
 
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 3/4 lib/drmtest: don't dup quiescent fd

In reply to Mika Kuoppala

If we dup the fd, we are in mercy of the context banning of the test application. Better to have our own to guarantee that gem_quiescent_gpu won't find itself banned on exit.

---
 lib/drmtest.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/drmtest.c +2 -2
index 2c9cf62..bd72e49 100644
@@ -302,7 +302,7 @@ int drm_open_any(void)
 		return fd;
 
 	gem_quiescent_gpu(fd);
-	at_exit_drm_fd = dup(fd);
+	at_exit_drm_fd = __drm_open_any();
 	igt_install_exit_handler(quiescent_gpu_at_exit);
 
 	return fd;
@@ -328,7 +328,7 @@ int drm_open_any_render(void)
 	if (__sync_fetch_and_add(&open_count, 1))
 		return fd;
 
-	at_exit_drm_render_fd = dup(fd);
+	at_exit_drm_render_fd = __drm_open_any();
 	gem_quiescent_gpu(fd);
 	igt_install_exit_handler(quiescent_gpu_at_exit_render);
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 4/4 tests/gem_reset_stats: check gpu state before each subtest

In reply to Mika Kuoppala

Some tests, namely the close pending variety, tries to carefully drop all handles to gpu when hang is intruduced, to expose bugs in reset handling without any clients.

Add guards after and before tests to really know if the gpu is still alive as the particular test might report success and then gpu dies few seconds after.

---
 tests/gem_reset_stats.c |   66 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 21 deletions(-)
tests/gem_reset_stats.c +45 -21
index 9581703..f402d97 100644
@@ -1057,16 +1057,41 @@ static bool gem_has_reset_stats(int fd)
 	return false;
 }
 
-#define RING_HAS_CONTEXTS (current_ring->contexts(current_ring))
-#define RUN_CTX_TEST(...) do { igt_skip_on(RING_HAS_CONTEXTS == false); __VA_ARGS__; } while (0)
+static void check_gpu_ok(void)
+{
+	int retry_count = 30;
+	enum stop_ring_flags flags;
+	int fd;
+
+	igt_debug("checking gpu state\n");
+
+	while (retry_count--) {
+		flags = igt_get_stop_rings();
+		if (flags == 0)
+			break;
+
+		igt_debug("waiting previous hang to clear\n");
+		sleep(1);
+	}
+
+	igt_assert(flags == 0);
+
+	fd = drm_open_any();
+	gem_quiescent_gpu(fd);
+	close(fd);
+}
 
-static int fd;
+#define RING_HAS_CONTEXTS (current_ring->contexts(current_ring))
+#define RUN_TEST(...) do { check_gpu_ok(); __VA_ARGS__; check_gpu_ok(); } while (0)
+#define RUN_CTX_TEST(...) do { igt_skip_on(RING_HAS_CONTEXTS == false); RUN_TEST(__VA_ARGS__); } while (0)
 
 igt_main
 {
 	igt_skip_on_simulation();
 
 	igt_fixture {
+		int fd;
+
 		bool has_reset_stats;
 		fd = drm_open_any();
 		devid = intel_get_drm_devid(fd);
@@ -1074,6 +1099,8 @@ igt_main
 		hw_contexts = gem_has_hw_contexts(fd);
 		has_reset_stats = gem_has_reset_stats(fd);
 
+		close(fd);
+
 		igt_require_f(has_reset_stats,
 			      "No reset stats ioctl support. Too old kernel?\n");
 	}
@@ -1087,8 +1114,11 @@ igt_main
 		current_ring = &rings[i];
 		name = current_ring->name;
 
-		igt_fixture
+		igt_fixture {
+			int fd = drm_open_any();
 			gem_require_ring(fd, current_ring->exec);
+			close(fd);
+		}
 
 		igt_fixture
 			igt_require_f(intel_gen(devid) >= 4,
@@ -1098,19 +1128,19 @@ igt_main
 			RUN_CTX_TEST(test_params_ctx());
 
 		igt_subtest_f("reset-stats-%s", name)
-			test_rs(4, 1, 0);
+			RUN_TEST(test_rs(4, 1, 0));
 
 		igt_subtest_f("reset-stats-ctx-%s", name)
 			RUN_CTX_TEST(test_rs_ctx(4, 4, 1, 2));
 
 		igt_subtest_f("ban-%s", name)
-			test_ban();
+			RUN_TEST(test_ban());
 
 		igt_subtest_f("ban-ctx-%s", name)
 			RUN_CTX_TEST(test_ban_ctx());
 
 		igt_subtest_f("reset-count-%s", name)
-			test_reset_count(false);
+			RUN_TEST(test_reset_count(false));
 
 		igt_subtest_f("reset-count-ctx-%s", name)
 			RUN_CTX_TEST(test_reset_count(true));
@@ -1118,22 +1148,16 @@ igt_main
 		igt_subtest_f("unrelated-ctx-%s", name)
 			RUN_CTX_TEST(test_unrelated_ctx());
 
-		igt_subtest_f("close-pending-%s", name) {
-			test_close_pending();
-			gem_quiescent_gpu(fd);
-		}
+		igt_subtest_f("close-pending-%s", name)
+			RUN_TEST(test_close_pending());
 
-		igt_subtest_f("close-pending-ctx-%s", name) {
+		igt_subtest_f("close-pending-ctx-%s", name)
 			RUN_CTX_TEST(test_close_pending_ctx());
-			gem_quiescent_gpu(fd);
-		}
 
-		igt_subtest_f("close-pending-fork-%s", name) {
-			test_close_pending_fork(true);
-			test_close_pending_fork(false);
-		}
-	}
+		igt_subtest_f("close-pending-fork-%s", name)
+			RUN_TEST(test_close_pending_fork(false));
 
-	igt_fixture
-		close(fd);
+		igt_subtest_f("close-pending-fork-reverse-%s", name)
+			RUN_TEST(test_close_pending_fork(true));
+	}
 }
Signature · 1 line
1.7.9.5