[igt-dev] [PATCH i-g-t v3 04/11] tests/gem_exec_fence: use new common functions

Antonio Argenziano antonio.argenziano at intel.com
Fri Feb 16 00:43:03 UTC 2018


From: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>

With intel_measure_ring_size and igt_cork added as common utilities we
can use them instead of the local copy of those utilities

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>

Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/gem_exec_fence.c | 107 ++++++-------------------------------------------
 1 file changed, 12 insertions(+), 95 deletions(-)

diff --git a/tests/gem_exec_fence.c b/tests/gem_exec_fence.c
index 8dd758aa..04a89afe 100644
--- a/tests/gem_exec_fence.c
+++ b/tests/gem_exec_fence.c
@@ -25,6 +25,7 @@
 #include "igt_sysfs.h"
 #include "igt_vgem.h"
 #include "sw_sync.h"
+#include "i915/gem_ring.h"
 
 #include <sys/ioctl.h>
 #include <sys/poll.h>
@@ -321,36 +322,6 @@ static void resubmit(int fd, uint32_t handle, unsigned int ring, int count)
 		gem_execbuf(fd, &execbuf);
 }
 
-struct cork {
-	int device;
-	uint32_t handle;
-	uint32_t fence;
-};
-
-static void plug(int fd, struct cork *c)
-{
-	struct vgem_bo bo;
-	int dmabuf;
-
-	c->device = drm_open_driver(DRIVER_VGEM);
-
-	bo.width = bo.height = 1;
-	bo.bpp = 4;
-	vgem_create(c->device, &bo);
-	c->fence = vgem_fence_attach(c->device, &bo, VGEM_FENCE_WRITE);
-
-	dmabuf = prime_handle_to_fd(c->device, bo.handle);
-	c->handle = prime_fd_to_handle(fd, dmabuf);
-	close(dmabuf);
-}
-
-static void unplug(int fd, struct cork *c)
-{
-	vgem_fence_signal(c->device, c->fence);
-	gem_close(fd, c->handle);
-	close(c->device);
-}
-
 static void alarm_handler(int sig)
 {
 }
@@ -367,62 +338,6 @@ static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
 	return err;
 }
 
-static unsigned int measure_ring_size(int fd)
-{
-	struct sigaction sa = { .sa_handler = alarm_handler };
-	struct drm_i915_gem_exec_object2 obj[2];
-	struct drm_i915_gem_execbuffer2 execbuf;
-	const uint32_t bbe = MI_BATCH_BUFFER_END;
-	unsigned int count, last;
-	struct itimerval itv;
-	struct cork c;
-
-	memset(obj, 0, sizeof(obj));
-	obj[1].handle = gem_create(fd, 4096);
-	gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe));
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(&obj[1]);
-	execbuf.buffer_count = 1;
-	gem_execbuf(fd, &execbuf);
-	gem_sync(fd, obj[1].handle);
-
-	plug(fd, &c);
-	obj[0].handle = c.handle;
-
-	execbuf.buffers_ptr = to_user_pointer(obj);
-	execbuf.buffer_count = 2;
-
-	sigaction(SIGALRM, &sa, NULL);
-	itv.it_interval.tv_sec = 0;
-	itv.it_interval.tv_usec = 100;
-	itv.it_value.tv_sec = 0;
-	itv.it_value.tv_usec = 1000;
-	setitimer(ITIMER_REAL, &itv, NULL);
-
-	last = -1;
-	count = 0;
-	do {
-		if (__execbuf(fd, &execbuf) == 0) {
-			count++;
-			continue;
-		}
-
-		if (last == count)
-			break;
-
-		last = count;
-	} while (1);
-
-	memset(&itv, 0, sizeof(itv));
-	setitimer(ITIMER_REAL, &itv, NULL);
-
-	unplug(fd, &c);
-	gem_close(fd, obj[1].handle);
-
-	return count;
-}
-
 static void test_parallel(int fd, unsigned int master)
 {
 	const int SCRATCH = 0;
@@ -437,15 +352,16 @@ static void test_parallel(int fd, unsigned int master)
 	uint32_t batch[16];
 	igt_spin_t *spin;
 	unsigned engine;
-	struct cork c;
+	struct igt_cork_vgem c;
+	uint32_t plug;
 	int i, x = 0;
 
-	plug(fd, &c);
+	plug = igt_cork_plug(fd, VGEM_BO, &c);
 
 	/* Fill the queue with many requests so that the next one has to
 	 * wait before it can be executed by the hardware.
 	 */
-	spin = igt_spin_batch_new(fd, 0, master, c.handle);
+	spin = igt_spin_batch_new(fd, 0, master, plug);
 	resubmit(fd, spin->handle, master, 16);
 
 	/* Now queue the master request and its secondaries */
@@ -566,7 +482,8 @@ static void test_parallel(int fd, unsigned int master)
 	}
 
 	/* Unblock the master */
-	unplug(fd, &c);
+	igt_cork_unplug(VGEM_BO, &c);
+	gem_close(fd, plug);
 	igt_spin_batch_end(spin);
 
 	/* Wait for all secondaries to complete. If we used a regular fence
@@ -692,7 +609,7 @@ static void test_long_history(int fd, long ring_size, unsigned flags)
 	unsigned int nengine, n, s;
 	unsigned long limit;
 	int all_fences;
-	struct cork c;
+	struct igt_cork_vgem c;
 
 	limit = -1;
 	if (!gem_uses_full_ppgtt(fd))
@@ -727,8 +644,7 @@ static void test_long_history(int fd, long ring_size, unsigned flags)
 	execbuf.buffers_ptr = to_user_pointer(obj);
 	execbuf.buffer_count = 2;
 
-	plug(fd, &c);
-	obj[0].handle = c.handle;
+	obj[0].handle = igt_cork_plug(fd, VGEM_BO, &c);
 
 	igt_until_timeout(5) {
 		execbuf.rsvd1 = gem_context_create(fd);
@@ -756,7 +672,7 @@ static void test_long_history(int fd, long ring_size, unsigned flags)
 		if (!--limit)
 			break;
 	}
-	unplug(fd, &c);
+	igt_cork_unplug(VGEM_BO, &c);
 
 	igt_info("History depth = %d\n", sync_fence_count(all_fences));
 
@@ -780,6 +696,7 @@ static void test_long_history(int fd, long ring_size, unsigned flags)
 
 	gem_sync(fd, obj[1].handle);
 	gem_close(fd, obj[1].handle);
+	gem_close(fd, obj[0].handle);
 }
 
 static void test_fence_flip(int i915)
@@ -1630,7 +1547,7 @@ igt_main
 		long ring_size = 0;
 
 		igt_fixture {
-			ring_size = measure_ring_size(i915) - 1;
+			ring_size = intel_measure_ring_size(i915, 0, false) - 1;
 			igt_info("Ring size: %ld batches\n", ring_size);
 			igt_require(ring_size);
 
-- 
2.14.2



More information about the igt-dev mailing list