All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch
@ 2017-12-01 22:43 Chris Wilson
  2017-12-01 23:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Chris Wilson @ 2017-12-01 22:43 UTC (permalink / raw)
  To: intel-gfx

In CI, we were observing situations where the busy blt would complete
before the very next instruction (in userspace) to assert that it was
busy. This is entirely possible if the process was scheduled away and
slept for longer than the arbitrary batch. Instead replace arbitrariness
with a precise infinity.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103829
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/gem_busy.c | 248 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 151 insertions(+), 97 deletions(-)

diff --git a/tests/gem_busy.c b/tests/gem_busy.c
index 2b88270b..4d8cd9c6 100644
--- a/tests/gem_busy.c
+++ b/tests/gem_busy.c
@@ -21,10 +21,16 @@
  * IN THE SOFTWARE.
  */
 
+#include <sched.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+
 #include "igt.h"
 #include "igt_rand.h"
+#include "igt_vgem.h"
 
 #define LOCAL_EXEC_NO_RELOC (1<<11)
+#define PAGE_ALIGN(x) ALIGN(x, 4096)
 
 /* Exercise the busy-ioctl, ensuring the ABI is never broken */
 IGT_TEST_DESCRIPTION("Basic check of busy-ioctl ABI.");
@@ -59,80 +65,6 @@ static void __gem_busy(int fd,
 	*read = busy.busy >> 16;
 }
 
-static uint32_t busy_blt(int fd)
-{
-	const int gen = intel_gen(intel_get_drm_devid(fd));
-	const int has_64bit_reloc = gen >= 8;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 object[2];
-	struct drm_i915_gem_relocation_entry reloc[200], *r;
-	uint32_t *map;
-	int factor = 100;
-	int i = 0;
-
-	memset(object, 0, sizeof(object));
-	object[0].handle = gem_create(fd, 1024*1024);
-	object[1].handle = gem_create(fd, 4096);
-
-	r = memset(reloc, 0, sizeof(reloc));
-	map = gem_mmap__cpu(fd, object[1].handle, 0, 4096, PROT_WRITE);
-	gem_set_domain(fd, object[1].handle,
-		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
-
-#define COPY_BLT_CMD		(2<<29|0x53<<22|0x6)
-#define BLT_WRITE_ALPHA		(1<<21)
-#define BLT_WRITE_RGB		(1<<20)
-	while (factor--) {
-		/* XY_SRC_COPY */
-		map[i++] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		if (has_64bit_reloc)
-			map[i-1] += 2;
-		map[i++] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
-		map[i++] = 0;
-		map[i++] = 256 << 16 | 1024;
-
-		r->offset = i * sizeof(uint32_t);
-		r->target_handle = object[0].handle;
-		r->read_domains = I915_GEM_DOMAIN_RENDER;
-		r->write_domain = I915_GEM_DOMAIN_RENDER;
-		r++;
-		map[i++] = 0;
-		if (has_64bit_reloc)
-			map[i++] = 0;
-
-		map[i++] = 0;
-		map[i++] = 4096;
-
-		r->offset = i * sizeof(uint32_t);
-		r->target_handle = object[0].handle;
-		r->read_domains = I915_GEM_DOMAIN_RENDER;
-		r->write_domain = 0;
-		r++;
-		map[i++] = 0;
-		if (has_64bit_reloc)
-			map[i++] = 0;
-	}
-	map[i++] = MI_BATCH_BUFFER_END;
-	igt_assert(i <= 4096/sizeof(uint32_t));
-	igt_assert(r - reloc <= ARRAY_SIZE(reloc));
-	munmap(map, 4096);
-
-	object[1].relocs_ptr = to_user_pointer(reloc);
-	object[1].relocation_count = r - reloc;
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(object);
-	execbuf.buffer_count = 2;
-	if (gen >= 6)
-		execbuf.flags = I915_EXEC_BLT;
-	gem_execbuf(fd, &execbuf);
-	igt_assert(gem_bo_busy(fd, object[0].handle));
-
-	igt_debug("Created busy handle %d\n", object[0].handle);
-	gem_close(fd, object[1].handle);
-	return object[0].handle;
-}
-
 static bool exec_noop(int fd,
 		      uint32_t *handles,
 		      unsigned ring,
@@ -167,6 +99,7 @@ static bool still_busy(int fd, uint32_t handle)
 static void semaphore(int fd, unsigned ring, uint32_t flags)
 {
 	uint32_t bbe = MI_BATCH_BUFFER_END;
+	igt_spin_t *spin;
 	uint32_t handle[3];
 	uint32_t read, write;
 	uint32_t active;
@@ -179,7 +112,8 @@ static void semaphore(int fd, unsigned ring, uint32_t flags)
 	gem_write(fd, handle[BATCH], 0, &bbe, sizeof(bbe));
 
 	/* Create a long running batch which we can use to hog the GPU */
-	handle[BUSY] = busy_blt(fd);
+	handle[BUSY] = gem_create(fd, 4096);
+	spin = igt_spin_batch_new(fd, 0, ring, handle[BUSY]);
 
 	/* Queue a batch after the busy, it should block and remain "busy" */
 	igt_assert(exec_noop(fd, handle, ring | flags, false));
@@ -208,6 +142,7 @@ static void semaphore(int fd, unsigned ring, uint32_t flags)
 
 	/* Check that our long batch was long enough */
 	igt_assert(still_busy(fd, handle[BUSY]));
+	igt_spin_batch_free(fd, spin);
 
 	/* And make sure it becomes idle again */
 	gem_sync(fd, handle[TEST]);
@@ -364,47 +299,155 @@ static void xchg_u32(void *array, unsigned i, unsigned j)
 	u32[j] = tmp;
 }
 
+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(struct cork *c)
+{
+	vgem_fence_signal(c->device, c->fence);
+	close(c->device);
+}
+
+static void alarm_handler(int sig)
+{
+}
+
+static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
+{
+	return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+}
+
+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(&c);
+	gem_close(fd, obj[1].handle);
+	gem_quiescent_gpu(fd);
+
+	return count;
+}
+
 static void close_race(int fd)
 {
-#define N_HANDLES 4096
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	unsigned int nhandles = measure_ring_size(fd) / 2;
+	unsigned int nengine;
+	unsigned int engines[16];
+	igt_spin_t **spin;
 	uint32_t *handles;
 	unsigned long *control;
 	unsigned long count = 0;
 	int i;
 
-	intel_require_memory(N_HANDLES, 4096, CHECK_RAM);
+	intel_require_memory(nhandles, 4096, CHECK_RAM);
 
 	/* One thread spawning work and randomly closing fd.
 	 * One background thread per cpu checking busyness.
 	 */
 
+	nengine = 0;
+	for_each_engine(fd, i)
+		engines[nengine++] = i;
+	igt_require(nengine);
+
 	control = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(control != MAP_FAILED);
 
-	handles = mmap(NULL, N_HANDLES*sizeof(*handles),
+	spin = calloc(nhandles, sizeof(*spin));
+	igt_assert(spin);
+
+	handles = mmap(NULL, PAGE_ALIGN(nhandles*sizeof(*handles)),
 		   PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(handles != MAP_FAILED);
 
-	for (i = 0; i < N_HANDLES; i++) {
-		handles[i] = gem_create(fd, 4096);
+	for (i = 0; i < nhandles; i++) {
+		spin[i] = igt_spin_batch_new(fd, 0,
+					     engines[rand() % nengine], 0);
+		handles[i] = spin[i]->handle;
 	}
 
 	igt_fork(child, ncpus) {
 		struct drm_i915_gem_busy busy;
-		uint32_t indirection[N_HANDLES];
+		uint32_t indirection[nhandles];
 
-		for (i = 0; i < N_HANDLES; i++)
+		for (i = 0; i < nhandles; i++)
 			indirection[i] = i;
 
 		hars_petruska_f54_1_random_perturb(child);
 
 		memset(&busy, 0, sizeof(busy));
 		do {
-			igt_permute_array(indirection, N_HANDLES, xchg_u32);
+			igt_permute_array(indirection, nhandles, xchg_u32);
 			__sync_synchronize();
-			for (i = 0; i < N_HANDLES; i++) {
-				busy.handle = indirection[handles[i]];
+			for (i = 0; i < nhandles; i++) {
+				busy.handle = handles[indirection[i]];
 				/* Check that the busy computation doesn't
 				 * explode in the face of random gem_close().
 				 */
@@ -414,17 +457,19 @@ static void close_race(int fd)
 		} while(*(volatile long *)control == 0);
 
 		igt_debug("child[%d]: count = %lu\n", child, count);
-		control[child] = count;
+		control[child + 1] = count;
 	}
 
 	igt_until_timeout(20) {
-		int j = rand() % N_HANDLES;
-
-		gem_close(fd, handles[j]);
-		__sync_synchronize();
-		handles[j] = busy_blt(fd);
-
-		count++;
+		for (i = 0; i < nhandles; i++) {
+			igt_spin_batch_free(fd, spin[i]);
+			spin[i] = igt_spin_batch_new(fd, 0,
+						     engines[rand() % nengine],
+						     0);
+			handles[i] = spin[i]->handle;
+			__sync_synchronize();
+		}
+		count += nhandles;
 	}
 	control[0] = 1;
 	igt_waitchildren();
@@ -432,12 +477,13 @@ static void close_race(int fd)
 	for (i = 0; i < ncpus; i++)
 		control[ncpus + 1] += control[i + 1];
 	igt_info("Total execs %lu, busy-ioctls %lu\n",
-		 count, control[ncpus + 1] * N_HANDLES);
+		 count, control[ncpus + 1] * nhandles);
 
-	for (i = 0; i < N_HANDLES; i++)
-		gem_close(fd, handles[i]);
+	for (i = 0; i < nhandles; i++)
+		igt_spin_batch_free(fd, spin[i]);
+	free(spin);
 
-	munmap(handles, N_HANDLES * sizeof(*handles));
+	munmap(handles, PAGE_ALIGN(nhandles * sizeof(*handles)));
 	munmap(control, 4096);
 
 	gem_quiescent_gpu(fd);
@@ -500,6 +546,12 @@ static void basic(int fd, unsigned ring, unsigned flags)
 	igt_spin_batch_free(fd, spin);
 }
 
+static void make_rr(void)
+{
+	struct sched_param rt = {.sched_priority = 99 };
+	igt_assert(sched_setscheduler(getpid(), SCHED_RR | SCHED_RESET_ON_FORK, &rt) == 0);
+}
+
 igt_main
 {
 	const struct intel_execution_engine *e;
@@ -509,6 +561,8 @@ igt_main
 		fd = drm_open_driver_master(DRIVER_INTEL);
 		igt_require_gem(fd);
 		igt_require(gem_can_store_dword(fd, 0));
+
+		make_rr();
 	}
 
 	igt_subtest_group {
-- 
2.15.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* ✗ Fi.CI.BAT: failure for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
@ 2017-12-01 23:03 ` Patchwork
  2017-12-01 23:29 ` [PATCH igt v2] " Chris Wilson
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Patchwork @ 2017-12-01 23:03 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch
URL   : https://patchwork.freedesktop.org/series/34780/
State : failure

== Summary ==

IGT patchset tested on top of latest successful build
476c4b462e0453c70ee81664c0227fdddc26cbd0 igt/gem_eio: Increase wakeup delay for in-flight-suspend

with latest DRM-Tip kernel build CI_DRM_3434
d872b1714457 drm-tip: 2017y-12m-01d-21h-08m-31s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                dmesg-fail -> DMESG-WARN (fi-elk-e7500) fdo#103989
Test gem_busy:
        Subgroup basic-hang-default:
                pass       -> INCOMPLETE (fi-bdw-gvtdvm)
                pass       -> INCOMPLETE (fi-skl-gvtdvm)
Test gem_exec_reloc:
        Subgroup basic-cpu-read-active:
                pass       -> FAIL       (fi-gdg-551) fdo#102582

fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989
fdo#102582 https://bugs.freedesktop.org/show_bug.cgi?id=102582

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:446s
fi-bdw-gvtdvm    total:11   pass:10   dwarn:0   dfail:0   fail:0   skip:0  
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:385s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:533s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:286s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:510s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:513s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:496s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:478s
fi-elk-e7500     total:224  pass:163  dwarn:15  dfail:0   fail:0   skip:45 
fi-gdg-551       total:288  pass:177  dwarn:1   dfail:0   fail:2   skip:108 time:278s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:545s
fi-hsw-4770r     total:288  pass:224  dwarn:0   dfail:0   fail:0   skip:64  time:259s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:396s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:489s
fi-ivb-3770      total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:447s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:486s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:528s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:478s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:538s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:601s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:460s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:552s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:564s
fi-skl-6700k     total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:519s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:500s
fi-skl-gvtdvm    total:11   pass:10   dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2520m     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:562s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:421s
Blacklisted hosts:
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:615s
fi-cnl-y         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:551s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_581/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH igt v2] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
  2017-12-01 23:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
@ 2017-12-01 23:29 ` Chris Wilson
  2017-12-02  0:22 ` ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2) Patchwork
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Chris Wilson @ 2017-12-01 23:29 UTC (permalink / raw)
  To: intel-gfx

In CI, we were observing situations where the busy blt would complete
before the very next instruction (in userspace) to assert that it was
busy. This is entirely possible if the process was scheduled away and
slept for longer than the arbitrary batch. Instead replace arbitrariness
with a precise infinity.

v2: Be respectful to UP!

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103829
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/gem_busy.c | 259 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 156 insertions(+), 103 deletions(-)

diff --git a/tests/gem_busy.c b/tests/gem_busy.c
index 2b88270b..3290b0d8 100644
--- a/tests/gem_busy.c
+++ b/tests/gem_busy.c
@@ -21,10 +21,16 @@
  * IN THE SOFTWARE.
  */
 
+#include <sched.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+
 #include "igt.h"
 #include "igt_rand.h"
+#include "igt_vgem.h"
 
 #define LOCAL_EXEC_NO_RELOC (1<<11)
+#define PAGE_ALIGN(x) ALIGN(x, 4096)
 
 /* Exercise the busy-ioctl, ensuring the ABI is never broken */
 IGT_TEST_DESCRIPTION("Basic check of busy-ioctl ABI.");
@@ -59,80 +65,6 @@ static void __gem_busy(int fd,
 	*read = busy.busy >> 16;
 }
 
-static uint32_t busy_blt(int fd)
-{
-	const int gen = intel_gen(intel_get_drm_devid(fd));
-	const int has_64bit_reloc = gen >= 8;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 object[2];
-	struct drm_i915_gem_relocation_entry reloc[200], *r;
-	uint32_t *map;
-	int factor = 100;
-	int i = 0;
-
-	memset(object, 0, sizeof(object));
-	object[0].handle = gem_create(fd, 1024*1024);
-	object[1].handle = gem_create(fd, 4096);
-
-	r = memset(reloc, 0, sizeof(reloc));
-	map = gem_mmap__cpu(fd, object[1].handle, 0, 4096, PROT_WRITE);
-	gem_set_domain(fd, object[1].handle,
-		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
-
-#define COPY_BLT_CMD		(2<<29|0x53<<22|0x6)
-#define BLT_WRITE_ALPHA		(1<<21)
-#define BLT_WRITE_RGB		(1<<20)
-	while (factor--) {
-		/* XY_SRC_COPY */
-		map[i++] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		if (has_64bit_reloc)
-			map[i-1] += 2;
-		map[i++] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
-		map[i++] = 0;
-		map[i++] = 256 << 16 | 1024;
-
-		r->offset = i * sizeof(uint32_t);
-		r->target_handle = object[0].handle;
-		r->read_domains = I915_GEM_DOMAIN_RENDER;
-		r->write_domain = I915_GEM_DOMAIN_RENDER;
-		r++;
-		map[i++] = 0;
-		if (has_64bit_reloc)
-			map[i++] = 0;
-
-		map[i++] = 0;
-		map[i++] = 4096;
-
-		r->offset = i * sizeof(uint32_t);
-		r->target_handle = object[0].handle;
-		r->read_domains = I915_GEM_DOMAIN_RENDER;
-		r->write_domain = 0;
-		r++;
-		map[i++] = 0;
-		if (has_64bit_reloc)
-			map[i++] = 0;
-	}
-	map[i++] = MI_BATCH_BUFFER_END;
-	igt_assert(i <= 4096/sizeof(uint32_t));
-	igt_assert(r - reloc <= ARRAY_SIZE(reloc));
-	munmap(map, 4096);
-
-	object[1].relocs_ptr = to_user_pointer(reloc);
-	object[1].relocation_count = r - reloc;
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(object);
-	execbuf.buffer_count = 2;
-	if (gen >= 6)
-		execbuf.flags = I915_EXEC_BLT;
-	gem_execbuf(fd, &execbuf);
-	igt_assert(gem_bo_busy(fd, object[0].handle));
-
-	igt_debug("Created busy handle %d\n", object[0].handle);
-	gem_close(fd, object[1].handle);
-	return object[0].handle;
-}
-
 static bool exec_noop(int fd,
 		      uint32_t *handles,
 		      unsigned ring,
@@ -167,6 +99,7 @@ static bool still_busy(int fd, uint32_t handle)
 static void semaphore(int fd, unsigned ring, uint32_t flags)
 {
 	uint32_t bbe = MI_BATCH_BUFFER_END;
+	igt_spin_t *spin;
 	uint32_t handle[3];
 	uint32_t read, write;
 	uint32_t active;
@@ -179,7 +112,8 @@ static void semaphore(int fd, unsigned ring, uint32_t flags)
 	gem_write(fd, handle[BATCH], 0, &bbe, sizeof(bbe));
 
 	/* Create a long running batch which we can use to hog the GPU */
-	handle[BUSY] = busy_blt(fd);
+	handle[BUSY] = gem_create(fd, 4096);
+	spin = igt_spin_batch_new(fd, 0, ring, handle[BUSY]);
 
 	/* Queue a batch after the busy, it should block and remain "busy" */
 	igt_assert(exec_noop(fd, handle, ring | flags, false));
@@ -208,6 +142,7 @@ static void semaphore(int fd, unsigned ring, uint32_t flags)
 
 	/* Check that our long batch was long enough */
 	igt_assert(still_busy(fd, handle[BUSY]));
+	igt_spin_batch_free(fd, spin);
 
 	/* And make sure it becomes idle again */
 	gem_sync(fd, handle[TEST]);
@@ -364,47 +299,156 @@ static void xchg_u32(void *array, unsigned i, unsigned j)
 	u32[j] = tmp;
 }
 
+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(struct cork *c)
+{
+	vgem_fence_signal(c->device, c->fence);
+	close(c->device);
+}
+
+static void alarm_handler(int sig)
+{
+}
+
+static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
+{
+	return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+}
+
+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(&c);
+	gem_close(fd, obj[1].handle);
+	gem_quiescent_gpu(fd);
+
+	return count;
+}
+
 static void close_race(int fd)
 {
-#define N_HANDLES 4096
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	unsigned int nhandles = measure_ring_size(fd) / 2;
+	unsigned int nengine;
+	unsigned int engines[16];
+	igt_spin_t **spin;
 	uint32_t *handles;
 	unsigned long *control;
-	unsigned long count = 0;
 	int i;
 
-	intel_require_memory(N_HANDLES, 4096, CHECK_RAM);
+	igt_require(ncpus > 1);
+	intel_require_memory(nhandles, 4096, CHECK_RAM);
 
 	/* One thread spawning work and randomly closing fd.
 	 * One background thread per cpu checking busyness.
 	 */
 
+	nengine = 0;
+	for_each_engine(fd, i)
+		engines[nengine++] = i;
+	igt_require(nengine);
+
 	control = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(control != MAP_FAILED);
 
-	handles = mmap(NULL, N_HANDLES*sizeof(*handles),
+	spin = calloc(nhandles, sizeof(*spin));
+	igt_assert(spin);
+
+	handles = mmap(NULL, PAGE_ALIGN(nhandles*sizeof(*handles)),
 		   PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(handles != MAP_FAILED);
 
-	for (i = 0; i < N_HANDLES; i++) {
-		handles[i] = gem_create(fd, 4096);
+	for (i = 0; i < nhandles; i++) {
+		spin[i] = igt_spin_batch_new(fd, 0,
+					     engines[rand() % nengine], 0);
+		handles[i] = spin[i]->handle;
 	}
 
-	igt_fork(child, ncpus) {
+	igt_fork(child, ncpus - 1) {
 		struct drm_i915_gem_busy busy;
-		uint32_t indirection[N_HANDLES];
+		uint32_t indirection[nhandles];
+		unsigned long count = 0;
 
-		for (i = 0; i < N_HANDLES; i++)
+		for (i = 0; i < nhandles; i++)
 			indirection[i] = i;
 
 		hars_petruska_f54_1_random_perturb(child);
 
 		memset(&busy, 0, sizeof(busy));
 		do {
-			igt_permute_array(indirection, N_HANDLES, xchg_u32);
+			igt_permute_array(indirection, nhandles, xchg_u32);
 			__sync_synchronize();
-			for (i = 0; i < N_HANDLES; i++) {
-				busy.handle = indirection[handles[i]];
+			for (i = 0; i < nhandles; i++) {
+				busy.handle = handles[indirection[i]];
 				/* Check that the busy computation doesn't
 				 * explode in the face of random gem_close().
 				 */
@@ -414,30 +458,39 @@ static void close_race(int fd)
 		} while(*(volatile long *)control == 0);
 
 		igt_debug("child[%d]: count = %lu\n", child, count);
-		control[child] = count;
+		control[child + 1] = count;
 	}
 
-	igt_until_timeout(20) {
-		int j = rand() % N_HANDLES;
-
-		gem_close(fd, handles[j]);
-		__sync_synchronize();
-		handles[j] = busy_blt(fd);
-
-		count++;
+	igt_fork(child, 1) {
+		struct sched_param rt = {.sched_priority = 99 };
+		unsigned long count = 0;
+
+		igt_assert(sched_setscheduler(getpid(), SCHED_RR, &rt) == 0);
+		igt_until_timeout(20) {
+			for (i = 0; i < nhandles; i++) {
+				igt_spin_batch_free(fd, spin[i]);
+				spin[i] = igt_spin_batch_new(fd, 0,
+							     engines[rand() % nengine],
+							     0);
+				handles[i] = spin[i]->handle;
+				__sync_synchronize();
+			}
+			count += nhandles;
+		}
+		control[0] = count;
 	}
-	control[0] = 1;
 	igt_waitchildren();
 
-	for (i = 0; i < ncpus; i++)
-		control[ncpus + 1] += control[i + 1];
+	for (i = 0; i < ncpus - 1; i++)
+		control[ncpus] += control[i + 1];
 	igt_info("Total execs %lu, busy-ioctls %lu\n",
-		 count, control[ncpus + 1] * N_HANDLES);
+		 control[0], control[ncpus] * nhandles);
 
-	for (i = 0; i < N_HANDLES; i++)
-		gem_close(fd, handles[i]);
+	for (i = 0; i < nhandles; i++)
+		igt_spin_batch_free(fd, spin[i]);
+	free(spin);
 
-	munmap(handles, N_HANDLES * sizeof(*handles));
+	munmap(handles, PAGE_ALIGN(nhandles * sizeof(*handles)));
 	munmap(control, 4096);
 
 	gem_quiescent_gpu(fd);
-- 
2.15.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2)
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
  2017-12-01 23:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
  2017-12-01 23:29 ` [PATCH igt v2] " Chris Wilson
@ 2017-12-02  0:22 ` Patchwork
  2017-12-02  1:44 ` ✗ Fi.CI.IGT: failure " Patchwork
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Patchwork @ 2017-12-02  0:22 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2)
URL   : https://patchwork.freedesktop.org/series/34780/
State : success

== Summary ==

IGT patchset tested on top of latest successful build
476c4b462e0453c70ee81664c0227fdddc26cbd0 igt/gem_eio: Increase wakeup delay for in-flight-suspend

with latest DRM-Tip kernel build CI_DRM_3435
5cac595012ce drm-tip: 2017y-12m-01d-23h-12m-37s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                pass       -> DMESG-WARN (fi-elk-e7500) fdo#103989 +1
Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-b:
                incomplete -> PASS       (fi-snb-2520m) fdo#103713

fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:440s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:448s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:385s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:527s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:282s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:510s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:511s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:491s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:483s
fi-elk-e7500     total:224  pass:163  dwarn:15  dfail:0   fail:0   skip:45 
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:543s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:373s
fi-hsw-4770r     total:288  pass:224  dwarn:0   dfail:0   fail:0   skip:64  time:268s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:394s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:495s
fi-ivb-3770      total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:451s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:490s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:528s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:477s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:531s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:598s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:456s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:547s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:568s
fi-skl-6700k     total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:524s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:503s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:449s
fi-snb-2520m     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:547s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:418s
Blacklisted hosts:
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:616s
fi-glk-dsi       total:287  pass:257  dwarn:0   dfail:0   fail:0   skip:29 

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_582/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* ✗ Fi.CI.IGT: failure for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2)
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
                   ` (2 preceding siblings ...)
  2017-12-02  0:22 ` ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2) Patchwork
@ 2017-12-02  1:44 ` Patchwork
  2017-12-02  8:47 ` [PATCH igt v3] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Patchwork @ 2017-12-02  1:44 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2)
URL   : https://patchwork.freedesktop.org/series/34780/
State : failure

== Summary ==

Test pm_rpm:
        Subgroup drm-resources-equal:
                pass       -> SKIP       (shard-hsw)
Test kms_draw_crc:
        Subgroup draw-method-xrgb8888-blt-xtiled:
                pass       -> SKIP       (shard-hsw)
Test drv_selftest:
        Subgroup mock_sanitycheck:
                dmesg-warn -> PASS       (shard-hsw) fdo#102707 +2
Test gem_userptr_blits:
        Subgroup map-fixed-invalidate-gup:
                pass       -> INCOMPLETE (shard-hsw)
Test gem_busy:
        Subgroup close-race:
                pass       -> INCOMPLETE (shard-snb) fdo#103829
                pass       -> FAIL       (shard-hsw)
Test kms_frontbuffer_tracking:
        Subgroup fbc-1p-offscren-pri-shrfb-draw-blt:
                pass       -> FAIL       (shard-snb) fdo#101623
Test gem_tiled_swapping:
        Subgroup non-threaded:
                incomplete -> PASS       (shard-hsw) fdo#104009

fdo#102707 https://bugs.freedesktop.org/show_bug.cgi?id=102707
fdo#103829 https://bugs.freedesktop.org/show_bug.cgi?id=103829
fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#104009 https://bugs.freedesktop.org/show_bug.cgi?id=104009

shard-hsw        total:2630 pass:1516 dwarn:1   dfail:0   fail:11  skip:1101 time:9314s
shard-snb        total:2591 pass:1274 dwarn:1   dfail:0   fail:12  skip:1303 time:7991s
Blacklisted hosts:
shard-apl        total:2663 pass:1691 dwarn:1   dfail:0   fail:22  skip:949 time:13810s
shard-kbl        total:2630 pass:1771 dwarn:12  dfail:3   fail:25  skip:818 time:10712s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_582/shards.html
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH igt v3] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
                   ` (3 preceding siblings ...)
  2017-12-02  1:44 ` ✗ Fi.CI.IGT: failure " Patchwork
@ 2017-12-02  8:47 ` Chris Wilson
  2017-12-04 14:20   ` Joonas Lahtinen
  2017-12-02  9:13 ` ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3) Patchwork
  2017-12-02 10:00 ` ✓ Fi.CI.IGT: " Patchwork
  6 siblings, 1 reply; 9+ messages in thread
From: Chris Wilson @ 2017-12-02  8:47 UTC (permalink / raw)
  To: intel-gfx

In CI, we were observing situations where the busy blt would complete
before the very next instruction (in userspace) to assert that it was
busy. This is entirely possible if the process was scheduled away and
slept for longer than the arbitrary batch. Instead replace arbitrariness
with a precise infinity.

v2: Be respectful to UP!
v3: Move spinbatch to owning process to avoid serialisation delays.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103829
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/gem_busy.c | 263 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 157 insertions(+), 106 deletions(-)

diff --git a/tests/gem_busy.c b/tests/gem_busy.c
index 2b88270b..4ba23241 100644
--- a/tests/gem_busy.c
+++ b/tests/gem_busy.c
@@ -21,10 +21,16 @@
  * IN THE SOFTWARE.
  */
 
+#include <sched.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+
 #include "igt.h"
 #include "igt_rand.h"
+#include "igt_vgem.h"
 
 #define LOCAL_EXEC_NO_RELOC (1<<11)
+#define PAGE_ALIGN(x) ALIGN(x, 4096)
 
 /* Exercise the busy-ioctl, ensuring the ABI is never broken */
 IGT_TEST_DESCRIPTION("Basic check of busy-ioctl ABI.");
@@ -59,80 +65,6 @@ static void __gem_busy(int fd,
 	*read = busy.busy >> 16;
 }
 
-static uint32_t busy_blt(int fd)
-{
-	const int gen = intel_gen(intel_get_drm_devid(fd));
-	const int has_64bit_reloc = gen >= 8;
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 object[2];
-	struct drm_i915_gem_relocation_entry reloc[200], *r;
-	uint32_t *map;
-	int factor = 100;
-	int i = 0;
-
-	memset(object, 0, sizeof(object));
-	object[0].handle = gem_create(fd, 1024*1024);
-	object[1].handle = gem_create(fd, 4096);
-
-	r = memset(reloc, 0, sizeof(reloc));
-	map = gem_mmap__cpu(fd, object[1].handle, 0, 4096, PROT_WRITE);
-	gem_set_domain(fd, object[1].handle,
-		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
-
-#define COPY_BLT_CMD		(2<<29|0x53<<22|0x6)
-#define BLT_WRITE_ALPHA		(1<<21)
-#define BLT_WRITE_RGB		(1<<20)
-	while (factor--) {
-		/* XY_SRC_COPY */
-		map[i++] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
-		if (has_64bit_reloc)
-			map[i-1] += 2;
-		map[i++] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
-		map[i++] = 0;
-		map[i++] = 256 << 16 | 1024;
-
-		r->offset = i * sizeof(uint32_t);
-		r->target_handle = object[0].handle;
-		r->read_domains = I915_GEM_DOMAIN_RENDER;
-		r->write_domain = I915_GEM_DOMAIN_RENDER;
-		r++;
-		map[i++] = 0;
-		if (has_64bit_reloc)
-			map[i++] = 0;
-
-		map[i++] = 0;
-		map[i++] = 4096;
-
-		r->offset = i * sizeof(uint32_t);
-		r->target_handle = object[0].handle;
-		r->read_domains = I915_GEM_DOMAIN_RENDER;
-		r->write_domain = 0;
-		r++;
-		map[i++] = 0;
-		if (has_64bit_reloc)
-			map[i++] = 0;
-	}
-	map[i++] = MI_BATCH_BUFFER_END;
-	igt_assert(i <= 4096/sizeof(uint32_t));
-	igt_assert(r - reloc <= ARRAY_SIZE(reloc));
-	munmap(map, 4096);
-
-	object[1].relocs_ptr = to_user_pointer(reloc);
-	object[1].relocation_count = r - reloc;
-
-	memset(&execbuf, 0, sizeof(execbuf));
-	execbuf.buffers_ptr = to_user_pointer(object);
-	execbuf.buffer_count = 2;
-	if (gen >= 6)
-		execbuf.flags = I915_EXEC_BLT;
-	gem_execbuf(fd, &execbuf);
-	igt_assert(gem_bo_busy(fd, object[0].handle));
-
-	igt_debug("Created busy handle %d\n", object[0].handle);
-	gem_close(fd, object[1].handle);
-	return object[0].handle;
-}
-
 static bool exec_noop(int fd,
 		      uint32_t *handles,
 		      unsigned ring,
@@ -167,6 +99,7 @@ static bool still_busy(int fd, uint32_t handle)
 static void semaphore(int fd, unsigned ring, uint32_t flags)
 {
 	uint32_t bbe = MI_BATCH_BUFFER_END;
+	igt_spin_t *spin;
 	uint32_t handle[3];
 	uint32_t read, write;
 	uint32_t active;
@@ -179,7 +112,8 @@ static void semaphore(int fd, unsigned ring, uint32_t flags)
 	gem_write(fd, handle[BATCH], 0, &bbe, sizeof(bbe));
 
 	/* Create a long running batch which we can use to hog the GPU */
-	handle[BUSY] = busy_blt(fd);
+	handle[BUSY] = gem_create(fd, 4096);
+	spin = igt_spin_batch_new(fd, 0, ring, handle[BUSY]);
 
 	/* Queue a batch after the busy, it should block and remain "busy" */
 	igt_assert(exec_noop(fd, handle, ring | flags, false));
@@ -208,6 +142,7 @@ static void semaphore(int fd, unsigned ring, uint32_t flags)
 
 	/* Check that our long batch was long enough */
 	igt_assert(still_busy(fd, handle[BUSY]));
+	igt_spin_batch_free(fd, spin);
 
 	/* And make sure it becomes idle again */
 	gem_sync(fd, handle[TEST]);
@@ -364,47 +299,146 @@ static void xchg_u32(void *array, unsigned i, unsigned j)
 	u32[j] = tmp;
 }
 
+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(struct cork *c)
+{
+	vgem_fence_signal(c->device, c->fence);
+	close(c->device);
+}
+
+static void alarm_handler(int sig)
+{
+}
+
+static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
+{
+	return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf);
+}
+
+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(&c);
+	gem_close(fd, obj[1].handle);
+	gem_quiescent_gpu(fd);
+
+	return count;
+}
+
 static void close_race(int fd)
 {
-#define N_HANDLES 4096
-	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
-	uint32_t *handles;
+	const unsigned int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	const unsigned int nhandles = measure_ring_size(fd) / 2;
+	unsigned int engines[16], nengine;
 	unsigned long *control;
-	unsigned long count = 0;
+	uint32_t *handles;
 	int i;
 
-	intel_require_memory(N_HANDLES, 4096, CHECK_RAM);
+	igt_require(ncpus > 1);
+	intel_require_memory(nhandles, 4096, CHECK_RAM);
 
-	/* One thread spawning work and randomly closing fd.
+	/*
+	 * One thread spawning work and randomly closing handles.
 	 * One background thread per cpu checking busyness.
 	 */
 
+	nengine = 0;
+	for_each_engine(fd, i)
+		engines[nengine++] = i;
+	igt_require(nengine);
+
 	control = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(control != MAP_FAILED);
 
-	handles = mmap(NULL, N_HANDLES*sizeof(*handles),
+	handles = mmap(NULL, PAGE_ALIGN(nhandles*sizeof(*handles)),
 		   PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(handles != MAP_FAILED);
 
-	for (i = 0; i < N_HANDLES; i++) {
-		handles[i] = gem_create(fd, 4096);
-	}
-
-	igt_fork(child, ncpus) {
+	igt_fork(child, ncpus - 1) {
 		struct drm_i915_gem_busy busy;
-		uint32_t indirection[N_HANDLES];
+		uint32_t indirection[nhandles];
+		unsigned long count = 0;
 
-		for (i = 0; i < N_HANDLES; i++)
+		for (i = 0; i < nhandles; i++)
 			indirection[i] = i;
 
 		hars_petruska_f54_1_random_perturb(child);
 
 		memset(&busy, 0, sizeof(busy));
 		do {
-			igt_permute_array(indirection, N_HANDLES, xchg_u32);
+			igt_permute_array(indirection, nhandles, xchg_u32);
 			__sync_synchronize();
-			for (i = 0; i < N_HANDLES; i++) {
-				busy.handle = indirection[handles[i]];
+			for (i = 0; i < nhandles; i++) {
+				busy.handle = handles[indirection[i]];
 				/* Check that the busy computation doesn't
 				 * explode in the face of random gem_close().
 				 */
@@ -414,30 +448,47 @@ static void close_race(int fd)
 		} while(*(volatile long *)control == 0);
 
 		igt_debug("child[%d]: count = %lu\n", child, count);
-		control[child] = count;
+		control[child + 1] = count;
 	}
 
-	igt_until_timeout(20) {
-		int j = rand() % N_HANDLES;
+	igt_fork(child, 1) {
+		struct sched_param rt = {.sched_priority = 99 };
+		igt_spin_t *spin[nhandles];
+		unsigned long count = 0;
+
+		igt_assert(sched_setscheduler(getpid(), SCHED_RR, &rt) == 0);
+
+		for (i = 0; i < nhandles; i++) {
+			spin[i] = igt_spin_batch_new(fd, 0,
+						     engines[rand() % nengine], 0);
+			handles[i] = spin[i]->handle;
+		}
 
-		gem_close(fd, handles[j]);
+		igt_until_timeout(20) {
+			for (i = 0; i < nhandles; i++) {
+				igt_spin_batch_free(fd, spin[i]);
+				spin[i] = igt_spin_batch_new(fd, 0,
+							     engines[rand() % nengine],
+							     0);
+				handles[i] = spin[i]->handle;
+				__sync_synchronize();
+			}
+			count += nhandles;
+		}
+		control[0] = count;
 		__sync_synchronize();
-		handles[j] = busy_blt(fd);
 
-		count++;
+		for (i = 0; i < nhandles; i++)
+			igt_spin_batch_free(fd, spin[i]);
 	}
-	control[0] = 1;
 	igt_waitchildren();
 
-	for (i = 0; i < ncpus; i++)
-		control[ncpus + 1] += control[i + 1];
+	for (i = 0; i < ncpus - 1; i++)
+		control[ncpus] += control[i + 1];
 	igt_info("Total execs %lu, busy-ioctls %lu\n",
-		 count, control[ncpus + 1] * N_HANDLES);
-
-	for (i = 0; i < N_HANDLES; i++)
-		gem_close(fd, handles[i]);
+		 control[0], control[ncpus] * nhandles);
 
-	munmap(handles, N_HANDLES * sizeof(*handles));
+	munmap(handles, PAGE_ALIGN(nhandles * sizeof(*handles)));
 	munmap(control, 4096);
 
 	gem_quiescent_gpu(fd);
-- 
2.15.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3)
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
                   ` (4 preceding siblings ...)
  2017-12-02  8:47 ` [PATCH igt v3] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
@ 2017-12-02  9:13 ` Patchwork
  2017-12-02 10:00 ` ✓ Fi.CI.IGT: " Patchwork
  6 siblings, 0 replies; 9+ messages in thread
From: Patchwork @ 2017-12-02  9:13 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3)
URL   : https://patchwork.freedesktop.org/series/34780/
State : success

== Summary ==

IGT patchset tested on top of latest successful build
476c4b462e0453c70ee81664c0227fdddc26cbd0 igt/gem_eio: Increase wakeup delay for in-flight-suspend

with latest DRM-Tip kernel build CI_DRM_3436
a0a650ed26d7 drm-tip: 2017y-12m-02d-01h-07m-05s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                dmesg-warn -> DMESG-FAIL (fi-elk-e7500) fdo#103989
Test gem_exec_reloc:
        Subgroup basic-gtt-active:
                pass       -> FAIL       (fi-gdg-551) fdo#102582 +6

fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989
fdo#102582 https://bugs.freedesktop.org/show_bug.cgi?id=102582

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:447s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:449s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:388s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:528s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:284s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:507s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:515s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:503s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:482s
fi-elk-e7500     total:224  pass:163  dwarn:14  dfail:1   fail:0   skip:45 
fi-gdg-551       total:288  pass:172  dwarn:1   dfail:0   fail:7   skip:108 time:269s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:540s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:378s
fi-hsw-4770r     total:288  pass:224  dwarn:0   dfail:0   fail:0   skip:64  time:262s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:397s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:483s
fi-ivb-3770      total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:450s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:490s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:530s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:479s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:535s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:594s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:449s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:543s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:568s
fi-skl-6700k     total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:526s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:503s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:446s
fi-snb-2520m     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:552s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:418s
Blacklisted hosts:
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:607s
fi-glk-dsi       total:48   pass:41   dwarn:0   dfail:0   fail:0   skip:6  

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_584/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* ✓ Fi.CI.IGT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3)
  2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
                   ` (5 preceding siblings ...)
  2017-12-02  9:13 ` ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3) Patchwork
@ 2017-12-02 10:00 ` Patchwork
  6 siblings, 0 replies; 9+ messages in thread
From: Patchwork @ 2017-12-02 10:00 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3)
URL   : https://patchwork.freedesktop.org/series/34780/
State : success

== Summary ==

Test kms_setmode:
        Subgroup basic:
                fail       -> PASS       (shard-hsw) fdo#99912
Test gem_tiled_swapping:
        Subgroup non-threaded:
                incomplete -> PASS       (shard-snb) fdo#104009 +1
Test perf:
        Subgroup blocking:
                pass       -> FAIL       (shard-hsw) fdo#102252
Test gem_busy:
        Subgroup close-race:
                fail       -> PASS       (shard-snb) fdo#103829
Test drv_module_reload:
        Subgroup basic-reload-inject:
                pass       -> DMESG-WARN (shard-snb) fdo#102707 +1
        Subgroup basic-reload:
                pass       -> DMESG-WARN (shard-snb) fdo#102848

fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
fdo#104009 https://bugs.freedesktop.org/show_bug.cgi?id=104009
fdo#102252 https://bugs.freedesktop.org/show_bug.cgi?id=102252
fdo#103829 https://bugs.freedesktop.org/show_bug.cgi?id=103829
fdo#102707 https://bugs.freedesktop.org/show_bug.cgi?id=102707
fdo#102848 https://bugs.freedesktop.org/show_bug.cgi?id=102848

shard-hsw        total:2540 pass:1467 dwarn:1   dfail:0   fail:10  skip:1061 time:9091s
shard-snb        total:2663 pass:1308 dwarn:3   dfail:0   fail:11  skip:1341 time:8186s
Blacklisted hosts:
shard-apl        total:2641 pass:1663 dwarn:2   dfail:0   fail:25  skip:949 time:13572s
shard-kbl        total:2596 pass:1768 dwarn:1   dfail:0   fail:25  skip:801 time:10697s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_584/shards.html
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH igt v3] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch
  2017-12-02  8:47 ` [PATCH igt v3] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
@ 2017-12-04 14:20   ` Joonas Lahtinen
  0 siblings, 0 replies; 9+ messages in thread
From: Joonas Lahtinen @ 2017-12-04 14:20 UTC (permalink / raw)
  To: Chris Wilson, intel-gfx

On Sat, 2017-12-02 at 08:47 +0000, Chris Wilson wrote:
> In CI, we were observing situations where the busy blt would complete
> before the very next instruction (in userspace) to assert that it was
> busy. This is entirely possible if the process was scheduled away and
> slept for longer than the arbitrary batch. Instead replace arbitrariness
> with a precise infinity.
> 
> v2: Be respectful to UP!
> v3: Move spinbatch to owning process to avoid serialisation delays.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103829
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

Even the variable names were good.

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-12-04 14:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-01 22:43 [PATCH igt] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
2017-12-01 23:03 ` ✗ Fi.CI.BAT: failure for " Patchwork
2017-12-01 23:29 ` [PATCH igt v2] " Chris Wilson
2017-12-02  0:22 ` ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev2) Patchwork
2017-12-02  1:44 ` ✗ Fi.CI.IGT: failure " Patchwork
2017-12-02  8:47 ` [PATCH igt v3] igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch Chris Wilson
2017-12-04 14:20   ` Joonas Lahtinen
2017-12-02  9:13 ` ✓ Fi.CI.BAT: success for igt/gem_busy: Replace arbitrary busy batch with indefinite spinbatch (rev3) Patchwork
2017-12-02 10:00 ` ✓ Fi.CI.IGT: " Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.