[Intel-gfx] [PATCH i-g-t] i915/gem_exec_fence: Replace open-coded recursive batch with igt_spin_t

Chris Wilson chris at chris-wilson.co.uk
Wed May 22 19:45:16 UTC 2019


The only detail of note here was that we were creating a fence from the
recursive batch, now supported by igt_spin_t (thanks Tvrtko).

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Matthew Auld <matthew.auld at intel.com>
Reviewed-by: Matthew Auld <matthew.auld at intel.com>
---
 lib/igt_core.c              |  1 +
 lib/igt_dummyload.c         |  5 +++
 lib/igt_dummyload.h         |  1 +
 tests/i915/gem_exec_fence.c | 77 ++++++++-----------------------------
 4 files changed, 22 insertions(+), 62 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index d5d4fce26..3ae11cef0 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1731,6 +1731,7 @@ bool __igt_fork(void)
 		exit_handler_count = 0;
 		reset_helper_process_list();
 		oom_adjust_for_doom();
+		igt_unclone_spins();
 
 		return true;
 	default:
diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 1e11ccd3d..d1521f9a0 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -464,6 +464,11 @@ void igt_terminate_spins(void)
 	pthread_mutex_unlock(&list_lock);
 }
 
+void igt_unclone_spins(void)
+{
+	igt_list_init(&spin_list);
+}
+
 static uint32_t plug_vgem_handle(struct igt_cork *cork, int fd)
 {
 	struct vgem_bo bo;
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index 61a9f2fcf..b9eca3519 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -92,6 +92,7 @@ static inline void igt_spin_busywait_until_started(igt_spin_t *spin)
 }
 
 void igt_terminate_spins(void);
+void igt_unclone_spins(void);
 
 enum igt_cork_type {
 	CORK_SYNC_FD = 1,
diff --git a/tests/i915/gem_exec_fence.c b/tests/i915/gem_exec_fence.c
index 8120f8b56..0befb54f8 100644
--- a/tests/i915/gem_exec_fence.c
+++ b/tests/i915/gem_exec_fence.c
@@ -317,68 +317,22 @@ static void test_fence_busy_all(int fd, unsigned flags)
 
 static void test_fence_await(int fd, unsigned ring, unsigned flags)
 {
-	const int gen = intel_gen(intel_get_drm_devid(fd));
-	struct drm_i915_gem_exec_object2 obj;
-	struct drm_i915_gem_relocation_entry reloc;
-	struct drm_i915_gem_execbuffer2 execbuf;
 	uint32_t scratch = gem_create(fd, 4096);
-	uint32_t *batch, *out;
+	igt_spin_t *spin;
 	unsigned engine;
-	int fence, i;
+	uint32_t *out;
+	int i;
 
 	igt_require(gem_can_store_dword(fd, 0));
 
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(&obj);
-	execbuf.buffer_count = 1;
-	execbuf.flags = ring | LOCAL_EXEC_FENCE_OUT;
-
-	memset(&obj, 0, sizeof(obj));
-	obj.handle = gem_create(fd, 4096);
-
-	obj.relocs_ptr = to_user_pointer(&reloc);
-	obj.relocation_count = 1;
-	memset(&reloc, 0, sizeof(reloc));
-
 	out = gem_mmap__wc(fd, scratch, 0, 4096, PROT_WRITE);
-	gem_set_domain(fd, obj.handle,
-			I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
-
-	batch = gem_mmap__wc(fd, obj.handle, 0, 4096, PROT_WRITE);
-	gem_set_domain(fd, obj.handle,
+	gem_set_domain(fd, scratch,
 			I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 
-	reloc.target_handle = obj.handle; /* recurse */
-	reloc.presumed_offset = 0;
-	reloc.offset = sizeof(uint32_t);
-	reloc.delta = 0;
-	reloc.read_domains = I915_GEM_DOMAIN_COMMAND;
-	reloc.write_domain = 0;
-
-	i = 0;
-	batch[i] = MI_BATCH_BUFFER_START;
-	if (gen >= 8) {
-		batch[i] |= 1 << 8 | 1;
-		batch[++i] = 0;
-		batch[++i] = 0;
-	} else if (gen >= 6) {
-		batch[i] |= 1 << 8;
-		batch[++i] = 0;
-	} else {
-		batch[i] |= 2 << 6;
-		batch[++i] = 0;
-		if (gen < 4) {
-			batch[i] |= 1;
-			reloc.delta = 1;
-		}
-	}
-	i++;
-
-	execbuf.rsvd2 = -1;
-	gem_execbuf_wr(fd, &execbuf);
-	gem_close(fd, obj.handle);
-	fence = execbuf.rsvd2 >> 32;
-	igt_assert(fence != -1);
+	spin = igt_spin_new(fd,
+			    .engine = ring,
+			    .flags = IGT_SPIN_FENCE_OUT);
+	igt_assert(spin->out_fence != -1);
 
 	i = 0;
 	for_each_physical_engine(fd, engine) {
@@ -386,27 +340,24 @@ static void test_fence_await(int fd, unsigned ring, unsigned flags)
 			continue;
 
 		if (flags & NONBLOCK) {
-			store(fd, engine, fence, scratch, i);
+			store(fd, engine, spin->out_fence, scratch, i);
 		} else {
 			igt_fork(child, 1)
-				store(fd, engine, fence, scratch, i);
+				store(fd, engine, spin->out_fence, scratch, i);
 		}
 
 		i++;
 	}
-	close(fence);
 
 	sleep(1);
 
 	/* Check for invalidly completing the task early */
+	igt_assert(fence_busy(spin->out_fence));
 	for (int n = 0; n < i; n++)
 		igt_assert_eq_u32(out[n], 0);
 
-	if ((flags & HANG) == 0) {
-		*batch = MI_BATCH_BUFFER_END;
-		__sync_synchronize();
-	}
-	munmap(batch, 4096);
+	if ((flags & HANG) == 0)
+		igt_spin_end(spin);
 
 	igt_waitchildren();
 
@@ -414,6 +365,8 @@ static void test_fence_await(int fd, unsigned ring, unsigned flags)
 	while (i--)
 		igt_assert_eq_u32(out[i], i);
 	munmap(out, 4096);
+
+	igt_spin_free(fd, spin);
 	gem_close(fd, scratch);
 }
 
-- 
2.20.1



More information about the Intel-gfx mailing list