[Intel-gfx] [PATCH igt] igt/gem_eio: Use slow spinners to inject hangs

2018-02-07 Thread Chris Wilson
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104676
Signed-off-by: Chris Wilson 
---
 lib/igt_gt.c|  1 +
 tests/gem_eio.c | 77 +++--
 2 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index ad6e62053..f70fcb925 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -402,6 +402,7 @@ void igt_force_gpu_reset(int drm_fd)
igt_sysfs_scanf(dir, "i915_wedged", "%d", );
 
close(dir);
+   errno = 0;
 
igt_assert(!wedged);
 }
diff --git a/tests/gem_eio.c b/tests/gem_eio.c
index 16a89ecda..b36ade5e5 100644
--- a/tests/gem_eio.c
+++ b/tests/gem_eio.c
@@ -67,6 +67,8 @@ static void trigger_reset(int fd)
/* And just check the gpu is indeed running again */
igt_debug("Checking that the GPU recovered\n");
gem_test_engine(fd, -1);
+
+   gem_quiescent_gpu(fd);
 }
 
 static void wedge_gpu(int fd)
@@ -133,15 +135,17 @@ static void test_execbuf(int fd)
 
 static int __gem_wait(int fd, uint32_t handle, int64_t timeout)
 {
-   struct drm_i915_gem_wait wait;
-   int err = 0;
+   struct drm_i915_gem_wait wait = {
+   .bo_handle = handle,
+   .timeout_ns = timeout,
+   };
+   int err;
 
-   memset(, 0, sizeof(wait));
-   wait.bo_handle = handle;
-   wait.timeout_ns = timeout;
+   err = 0;
if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, ))
err = -errno;
 
+   errno = 0;
return err;
 }
 
@@ -182,11 +186,9 @@ static void test_suspend(int fd, int state)
 
 static void test_inflight(int fd)
 {
-   struct drm_i915_gem_execbuffer2 execbuf;
+   const uint32_t bbe = MI_BATCH_BUFFER_END;
struct drm_i915_gem_exec_object2 obj[2];
-   uint32_t bbe = MI_BATCH_BUFFER_END;
unsigned int engine;
-   int fence[64]; /* conservative estimate of ring size */
 
igt_require(gem_has_exec_fence(fd));
 
@@ -196,13 +198,17 @@ static void test_inflight(int fd)
gem_write(fd, obj[1].handle, 0, , sizeof(bbe));
 
for_each_engine(fd, engine) {
-   igt_hang_t hang;
+   struct drm_i915_gem_execbuffer2 execbuf;
+   igt_spin_t *hang;
+   int fence[64]; /* conservative estimate of ring size */
+
+   gem_quiescent_gpu(fd);
 
igt_debug("Starting %s on engine '%s'\n", __func__, e__->name);
igt_require(i915_reset_control(false));
 
-   hang = igt_hang_ring(fd, engine);
-   obj[0].handle = hang.handle;
+   hang = igt_spin_batch_new(fd, 0, engine, 0);
+   obj[0].handle = hang->handle;
 
memset(, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(obj);
@@ -215,14 +221,13 @@ static void test_inflight(int fd)
igt_assert(fence[n] != -1);
}
 
-   igt_post_hang_ring(fd, hang);
-
igt_assert_eq(__gem_wait(fd, obj[1].handle, -1), 0);
for (unsigned int n = 0; n < ARRAY_SIZE(fence); n++) {
igt_assert_eq(sync_fence_status(fence[n]), -EIO);
close(fence[n]);
}
 
+   igt_spin_batch_free(fd, hang);
igt_assert(i915_reset_control(true));
trigger_reset(fd);
}
@@ -234,7 +239,7 @@ static void test_inflight_suspend(int fd)
struct drm_i915_gem_exec_object2 obj[2];
uint32_t bbe = MI_BATCH_BUFFER_END;
int fence[64]; /* conservative estimate of ring size */
-   igt_hang_t hang;
+   igt_spin_t *hang;
 
igt_require(gem_has_exec_fence(fd));
igt_require(i915_reset_control(false));
@@ -244,8 +249,8 @@ static void test_inflight_suspend(int fd)
obj[1].handle = gem_create(fd, 4096);
gem_write(fd, obj[1].handle, 0, , sizeof(bbe));
 
-   hang = igt_hang_ring(fd, 0);
-   obj[0].handle = hang.handle;
+   hang = igt_spin_batch_new(fd, 0, 0, 0);
+   obj[0].handle = hang->handle;
 
memset(, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(obj);
@@ -261,26 +266,23 @@ static void test_inflight_suspend(int fd)
igt_set_autoresume_delay(30);
igt_system_suspend_autoresume(SUSPEND_STATE_MEM, SUSPEND_TEST_NONE);
 
-   igt_post_hang_ring(fd, hang);
-
igt_assert_eq(__gem_wait(fd, obj[1].handle, -1), 0);
for (unsigned int n = 0; n < ARRAY_SIZE(fence); n++) {
igt_assert_eq(sync_fence_status(fence[n]), -EIO);
close(fence[n]);
}
 
+   igt_spin_batch_free(fd, hang);
igt_assert(i915_reset_control(true));
trigger_reset(fd);
 }
 
 static void test_inflight_contexts(int fd)
 {
-   struct drm_i915_gem_execbuffer2 execbuf;
struct drm_i915_gem_exec_object2 obj[2];
-   uint32_t bbe = MI_BATCH_BUFFER_END;
+   const uint32_t 

[Intel-gfx] [PATCH igt] igt/gem_eio: Use slow spinners to inject hangs

2018-02-06 Thread Chris Wilson
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104676
Signed-off-by: Chris Wilson 
---
 lib/igt_gt.c|  1 +
 tests/gem_eio.c | 77 +++--
 2 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index ad6e62053..f70fcb925 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -402,6 +402,7 @@ void igt_force_gpu_reset(int drm_fd)
igt_sysfs_scanf(dir, "i915_wedged", "%d", );
 
close(dir);
+   errno = 0;
 
igt_assert(!wedged);
 }
diff --git a/tests/gem_eio.c b/tests/gem_eio.c
index c941f3564..0b563bd0d 100644
--- a/tests/gem_eio.c
+++ b/tests/gem_eio.c
@@ -69,6 +69,8 @@ static void trigger_reset(int fd)
/* And just check the gpu is indeed running again */
igt_debug("Checking that the GPU recovered\n");
gem_test_engine(fd, -1);
+
+   gem_quiescent_gpu(fd);
 }
 
 static void wedge_gpu(int fd)
@@ -135,15 +137,17 @@ static void test_execbuf(int fd)
 
 static int __gem_wait(int fd, uint32_t handle, int64_t timeout)
 {
-   struct drm_i915_gem_wait wait;
-   int err = 0;
+   struct drm_i915_gem_wait wait = {
+   .bo_handle = handle,
+   .timeout_ns = timeout,
+   };
+   int err;
 
-   memset(, 0, sizeof(wait));
-   wait.bo_handle = handle;
-   wait.timeout_ns = timeout;
+   err = 0;
if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, ))
err = -errno;
 
+   errno = 0;
return err;
 }
 
@@ -184,11 +188,9 @@ static void test_suspend(int fd, int state)
 
 static void test_inflight(int fd)
 {
-   struct drm_i915_gem_execbuffer2 execbuf;
+   const uint32_t bbe = MI_BATCH_BUFFER_END;
struct drm_i915_gem_exec_object2 obj[2];
-   uint32_t bbe = MI_BATCH_BUFFER_END;
unsigned int engine;
-   int fence[64]; /* conservative estimate of ring size */
 
igt_require(gem_has_exec_fence(fd));
 
@@ -198,13 +200,17 @@ static void test_inflight(int fd)
gem_write(fd, obj[1].handle, 0, , sizeof(bbe));
 
for_each_engine(fd, engine) {
-   igt_hang_t hang;
+   struct drm_i915_gem_execbuffer2 execbuf;
+   igt_spin_t *hang;
+   int fence[64]; /* conservative estimate of ring size */
+
+   gem_quiescent_gpu(fd);
 
igt_debug("Starting %s on engine '%s'\n", __func__, e__->name);
igt_require(i915_reset_control(false));
 
-   hang = igt_hang_ring(fd, engine);
-   obj[0].handle = hang.handle;
+   hang = igt_spin_batch_new(fd, 0, engine, 0);
+   obj[0].handle = hang->handle;
 
memset(, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(obj);
@@ -217,14 +223,13 @@ static void test_inflight(int fd)
igt_assert(fence[n] != -1);
}
 
-   igt_post_hang_ring(fd, hang);
-
igt_assert_eq(__gem_wait(fd, obj[1].handle, -1), 0);
for (unsigned int n = 0; n < ARRAY_SIZE(fence); n++) {
igt_assert_eq(sync_fence_status(fence[n]), -EIO);
close(fence[n]);
}
 
+   igt_spin_batch_free(fd, hang);
igt_assert(i915_reset_control(true));
trigger_reset(fd);
}
@@ -236,7 +241,7 @@ static void test_inflight_suspend(int fd)
struct drm_i915_gem_exec_object2 obj[2];
uint32_t bbe = MI_BATCH_BUFFER_END;
int fence[64]; /* conservative estimate of ring size */
-   igt_hang_t hang;
+   igt_spin_t *hang;
 
igt_require(gem_has_exec_fence(fd));
igt_require(i915_reset_control(false));
@@ -246,8 +251,8 @@ static void test_inflight_suspend(int fd)
obj[1].handle = gem_create(fd, 4096);
gem_write(fd, obj[1].handle, 0, , sizeof(bbe));
 
-   hang = igt_hang_ring(fd, 0);
-   obj[0].handle = hang.handle;
+   hang = igt_spin_batch_new(fd, 0, 0, 0);
+   obj[0].handle = hang->handle;
 
memset(, 0, sizeof(execbuf));
execbuf.buffers_ptr = to_user_pointer(obj);
@@ -263,14 +268,13 @@ static void test_inflight_suspend(int fd)
igt_set_autoresume_delay(30);
igt_system_suspend_autoresume(SUSPEND_STATE_MEM, SUSPEND_TEST_NONE);
 
-   igt_post_hang_ring(fd, hang);
-
igt_assert_eq(__gem_wait(fd, obj[1].handle, -1), 0);
for (unsigned int n = 0; n < ARRAY_SIZE(fence); n++) {
igt_assert_eq(sync_fence_status(fence[n]), -EIO);
close(fence[n]);
}
 
+   igt_spin_batch_free(fd, hang);
igt_assert(i915_reset_control(true));
trigger_reset(fd);
 }
@@ -288,12 +292,10 @@ static uint32_t __gem_context_create(int fd)
 
 static void test_inflight_contexts(int fd)
 {
-   struct drm_i915_gem_execbuffer2 execbuf;
struct drm_i915_gem_exec_object2 obj[2];
-