[igt-dev] [PATCH i-g-t v2] lib/hang_ctx: Make use of dummyload library to create recursive batch

Antonio Argenziano antonio.argenziano at intel.com
Tue Jul 10 15:31:55 UTC 2018


An hanging batch is nothing more than a spinning batch that never gets
stopped, so re-use the routines implemented in dummyload.c.

v2:
	- Let caller decide spin loop size (Chris)
	- Now builds with meson.

Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/igt_gt.c                 | 65 +++++++++-----------------------------------
 lib/igt_gt.h                 |  3 +-
 lib/meson.build              |  1 +
 tests/gem_concurrent_all.c   |  6 ++--
 tests/gem_ctx_exec.c         |  2 +-
 tests/gem_mmap_gtt.c         |  2 +-
 tests/gem_pread_after_blit.c |  2 +-
 tests/gem_reloc_vs_gpu.c     |  2 +-
 tests/gem_ringfill.c         |  2 +-
 tests/gem_shrink.c           |  2 +-
 tests/kms_flip.c             |  2 +-
 tests/kms_vblank.c           |  2 +-
 12 files changed, 27 insertions(+), 64 deletions(-)

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 4569fd36..4ca4beef 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -40,6 +40,7 @@
 #include "ioctl_wrappers.h"
 #include "intel_reg.h"
 #include "intel_chipset.h"
+#include "igt_dummyload.h"
 
 /**
  * SECTION:igt_gt
@@ -264,14 +265,10 @@ igt_hang_t igt_hang_ctx(int fd,
 			unsigned flags,
 			uint64_t *offset)
 {
-	struct drm_i915_gem_relocation_entry reloc;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 exec;
+	igt_spin_t *spinning_batch;
+	struct igt_spin_factory opts = {};
 	struct drm_i915_gem_context_param param;
-	uint32_t b[16];
 	unsigned ban;
-	unsigned len;
-	int gen;
 
 	igt_require_hang_ring(fd, ring);
 
@@ -295,58 +292,22 @@ igt_hang_t igt_hang_ctx(int fd,
 	if ((flags & HANG_ALLOW_BAN) == 0)
 		context_set_ban(fd, ctx, 0);
 
-	memset(&reloc, 0, sizeof(reloc));
-	memset(&exec, 0, sizeof(exec));
-	memset(&execbuf, 0, sizeof(execbuf));
-
-	exec.handle = gem_create(fd, 4096);
-	exec.relocation_count = 1;
-	exec.relocs_ptr = to_user_pointer(&reloc);
-
-	memset(b, 0xc5, sizeof(b));
-
-	len = 0;
-	gen = intel_gen(intel_get_drm_devid(fd));
-	if (gen >= 8) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8 | 1;
-		b[len++] = 0;
-		b[len++] = 0;
-	} else if (gen >= 6) {
-		b[len++] = MI_BATCH_BUFFER_START | 1 << 8;
-		b[len++] = 0;
-	} else {
-		b[len++] = MI_BATCH_BUFFER_START | 2 << 6;
-		b[len] = 0;
-		if (gen < 4) {
-			b[len] |= 1;
-			reloc.delta = 1;
-		}
-		len++;
-	}
-	b[len++] = MI_BATCH_BUFFER_END;
-	b[len] = MI_NOOP;
-	gem_write(fd, exec.handle, 0, b, sizeof(b));
-
-	reloc.offset = sizeof(uint32_t);
-	reloc.target_handle = exec.handle;
-	reloc.read_domains = I915_GEM_DOMAIN_COMMAND;
-
-	execbuf.buffers_ptr = to_user_pointer(&exec);
-	execbuf.buffer_count = 1;
-	execbuf.flags = ring;
-	i915_execbuffer2_set_context_id(execbuf, ctx);
-	gem_execbuf(fd, &execbuf);
+	opts.ctx = ctx;
+	opts.engine = ring;
+	opts.flags |= (flags & HANG_SPIN_FAST) ? IGT_SPIN_FAST : 0; /* hangs faster */
+	spinning_batch = igt_spin_batch_factory(fd, &opts);
 
 	if (offset)
-		*offset = exec.offset;
+		*offset = (*spinning_batch).obj[1].offset; /* The batch is the last object */
 
-	return (igt_hang_t){ exec.handle, ctx, ban, flags };
+	return (igt_hang_t){ (*spinning_batch).obj[1].handle, ctx, ban, flags };
 }
 
 /**
  * igt_hang_ring:
  * @fd: open i915 drm file descriptor
  * @ring: execbuf ring flag
+ * @flags: set of flags to control execution
  *
  * This helper function injects a hanging batch into @ring. It returns a
  * #igt_hang_t structure which must be passed to igt_post_hang_ring() for
@@ -355,9 +316,9 @@ igt_hang_t igt_hang_ctx(int fd,
  * Returns:
  * Structure with helper internal state for igt_post_hang_ring().
  */
-igt_hang_t igt_hang_ring(int fd, int ring)
+igt_hang_t igt_hang_ring(int fd, int ring, unsigned flags)
 {
-	return igt_hang_ctx(fd, 0, ring, 0, NULL);
+	return igt_hang_ctx(fd, 0, ring, flags, NULL);
 }
 
 /**
@@ -425,7 +386,7 @@ hang_helper_process(pid_t pid, int fd)
 			exit(0);
 
 		igt_post_hang_ring(fd,
-				   igt_hang_ring(fd, I915_EXEC_DEFAULT));
+				   igt_hang_ring(fd, I915_EXEC_DEFAULT, 0));
 
 		sleep(1);
 	}
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index d44b7552..12a83a1b 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -50,8 +50,9 @@ igt_hang_t igt_hang_ctx(int fd,
 			uint64_t *offset);
 #define HANG_ALLOW_BAN 1
 #define HANG_ALLOW_CAPTURE 2
+#define HANG_SPIN_FAST 3
 
-igt_hang_t igt_hang_ring(int fd, int ring);
+igt_hang_t igt_hang_ring(int fd, int ring, unsigned flags);
 void igt_post_hang_ring(int fd, igt_hang_t arg);
 
 void igt_force_gpu_reset(int fd);
diff --git a/lib/meson.build b/lib/meson.build
index 1a355414..045f4a13 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -134,6 +134,7 @@ lib_igt_chipset = declare_dependency(link_with : lin_igt_chipset_build,
 
 lib_igt_perf_build = static_library('igt_perf',
 	['igt_perf.c'],
+    dependencies: [libdrm],
 	include_directories : inc)
 
 lib_igt_perf = declare_dependency(link_with : lib_igt_perf_build,
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 3a1097ba..d327f78a 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -936,12 +936,12 @@ static igt_hang_t no_hang(void)
 
 static igt_hang_t bcs_hang(void)
 {
-	return igt_hang_ring(fd, I915_EXEC_BLT);
+	return igt_hang_ring(fd, I915_EXEC_BLT, 0);
 }
 
 static igt_hang_t rcs_hang(void)
 {
-	return igt_hang_ring(fd, I915_EXEC_RENDER);
+	return igt_hang_ring(fd, I915_EXEC_RENDER, 0);
 }
 
 static igt_hang_t all_hang(void)
@@ -961,7 +961,7 @@ static igt_hang_t all_hang(void)
 	execbuf.buffer_count = 1;
 
 	for_each_physical_engine(fd, engine) {
-		hang = igt_hang_ring(fd, engine);
+		hang = igt_hang_ring(fd, engine, 0);
 
 		execbuf.flags = engine;
 		__gem_execbuf(fd, &execbuf);
diff --git a/tests/gem_ctx_exec.c b/tests/gem_ctx_exec.c
index 1f8ed64d..8b126b38 100644
--- a/tests/gem_ctx_exec.c
+++ b/tests/gem_ctx_exec.c
@@ -195,7 +195,7 @@ igt_main
 		 * the last context is leaked at every reset.
 		 */
 		for (i = 0; i < 20; i++) {
-			igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER);
+			igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER, 0);
 			igt_assert(exec(fd, handle, I915_EXEC_RENDER, 0) == 0);
 			igt_assert(exec(fd, handle, I915_EXEC_RENDER, ctx_id) == 0);
 			igt_post_hang_ring(fd, hang);
diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c
index fd60b8ff..43797f73 100644
--- a/tests/gem_mmap_gtt.c
+++ b/tests/gem_mmap_gtt.c
@@ -382,7 +382,7 @@ test_hang(int fd)
 		gem_close(fd, handle);
 	}
 
-	hang = igt_hang_ring(fd, I915_EXEC_RENDER);
+	hang = igt_hang_ring(fd, I915_EXEC_RENDER, 0);
 
 	do {
 		for (i = 0; i < OBJECT_SIZE / 64; i++) {
diff --git a/tests/gem_pread_after_blit.c b/tests/gem_pread_after_blit.c
index 6ef3ca20..1763ea6e 100644
--- a/tests/gem_pread_after_blit.c
+++ b/tests/gem_pread_after_blit.c
@@ -127,7 +127,7 @@ static igt_hang_t no_hang(int fd)
 
 static igt_hang_t bcs_hang(int fd)
 {
-	return igt_hang_ring(fd, batch->gen >= 6 ? I915_EXEC_BLT : I915_EXEC_DEFAULT);
+	return igt_hang_ring(fd, batch->gen >= 6 ? I915_EXEC_BLT : I915_EXEC_DEFAULT, 0);
 }
 
 static void do_test(int fd, int cache_level,
diff --git a/tests/gem_reloc_vs_gpu.c b/tests/gem_reloc_vs_gpu.c
index d421e434..c589ea63 100644
--- a/tests/gem_reloc_vs_gpu.c
+++ b/tests/gem_reloc_vs_gpu.c
@@ -190,7 +190,7 @@ static igt_hang_t no_hang(int fd)
 
 static igt_hang_t bcs_hang(int fd)
 {
-	return igt_hang_ring(fd, I915_EXEC_BLT);
+	return igt_hang_ring(fd, I915_EXEC_BLT, 0);
 }
 
 static void do_test(int fd, bool faulting_reloc,
diff --git a/tests/gem_ringfill.c b/tests/gem_ringfill.c
index c728e1cd..ceaee8c8 100644
--- a/tests/gem_ringfill.c
+++ b/tests/gem_ringfill.c
@@ -188,7 +188,7 @@ static void run_test(int fd, unsigned ring, unsigned flags, unsigned timeout)
 
 	memset(&hang, 0, sizeof(hang));
 	if (flags & HANG)
-		hang = igt_hang_ring(fd, ring & ~(3<<13));
+		hang = igt_hang_ring(fd, ring & ~(3<<13), 0);
 
 	if (flags & (CHILD | FORKED | BOMB)) {
 		int nchild;
diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 929e0426..94b833f5 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -208,7 +208,7 @@ static void hang(int fd, uint64_t alloc)
 		gem_execbuf(fd, &execbuf);
 	}
 
-	gem_close(fd, igt_hang_ring(fd, 0).handle);
+	gem_close(fd, igt_hang_ring(fd, 0, 0).handle);
 	for (int i = 0; i <= count; i++)
 		gem_madvise(fd, obj[i].handle, I915_MADV_DONTNEED);
 	munmap(obj, obj_size);
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index 3d6fe948..290bdd30 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -616,7 +616,7 @@ static void set_y_tiling(struct test_output *o, int fb_idx)
 
 static igt_hang_t hang_gpu(int fd)
 {
-	return igt_hang_ring(fd, I915_EXEC_DEFAULT);
+	return igt_hang_ring(fd, I915_EXEC_DEFAULT, 0);
 }
 
 static void unhang_gpu(int fd, igt_hang_t hang)
diff --git a/tests/kms_vblank.c b/tests/kms_vblank.c
index 2bee49de..676231f9 100644
--- a/tests/kms_vblank.c
+++ b/tests/kms_vblank.c
@@ -128,7 +128,7 @@ static void run_test(data_t *data, void (*testfunc)(data_t *, int, int))
 		 igt_output_name(output));
 
 	if (!(data->flags & NOHANG))
-		hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
+		hang = igt_hang_ring(fd, I915_EXEC_DEFAULT, 0);
 
 	if (data->flags & BUSY) {
 		union drm_wait_vblank vbl;
-- 
2.16.2



More information about the igt-dev mailing list