[igt-dev] [PATCH i-g-t] tests/gem_exec_basic: Quiesce GPU before returning from test

Chris Wilson chris at chris-wilson.co.uk
Mon Jun 11 21:06:56 UTC 2018


Quoting Antonio Argenziano (2018-06-11 21:58:36)
> All subtests send a workload to the engines and then return without
> waiting on it, while this is not a problem because the test targets the
> API, it makes the hang detector pointless since the driver will declare
> an hang long after the test has completed.
> 
> Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  tests/gem_exec_basic.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/gem_exec_basic.c b/tests/gem_exec_basic.c
> index 2f057ef0..473c2e8e 100644
> --- a/tests/gem_exec_basic.c
> +++ b/tests/gem_exec_basic.c
> @@ -42,7 +42,9 @@ static void noop(int fd, unsigned ring)
>         execbuf.buffer_count = 1;
>         execbuf.flags = ring;
>         gem_execbuf(fd, &execbuf);
> +
>         gem_close(fd, exec.handle);
> +       gem_quiescent_gpu(fd);
>  }
>  
>  static void readonly(int fd, unsigned ring)
> @@ -66,8 +68,10 @@ static void readonly(int fd, unsigned ring)
>         igt_assert(mprotect(execbuf, 4096, PROT_READ) == 0);
>  
>         gem_execbuf(fd, execbuf);
> +
>         munmap(execbuf, 4096);
>         gem_close(fd, exec.handle);
> +       gem_quiescent_gpu(fd);
>  }
>  
>  static void gtt(int fd, unsigned ring)
> @@ -94,9 +98,11 @@ static void gtt(int fd, unsigned ring)
>         execbuf->flags = ring;
>  
>         gem_execbuf(fd, execbuf);
> -       gem_close(fd, exec->handle);
>  
> +       gem_close(fd, exec->handle);
>         munmap(execbuf, 4096);
> +
> +       gem_quiescent_gpu(fd);
>  }

As you are there, maybe
diff --git a/tests/gem_exec_basic.c b/tests/gem_exec_basic.c
index 2f057ef..b1b9081 100644
--- a/tests/gem_exec_basic.c
+++ b/tests/gem_exec_basic.c
@@ -25,37 +25,51 @@
 
 IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl rings.");
 
+static uint32_t batch_create(int fd)
+{
+       const uint32_t bbe = MI_BATCH_BUFFER_END;
+       uint32_t handle;
+
+       handle = gem_create(fd, 4096);
+       gem_write(fd, handle, 0, &bbe, sizeof(bbe));
+
+       return handle;
+}
+
+static void batch_fini(int fd, uint32_t handle)
+{
+       gem_sync(fd, handle); /* catch any GPU hang */
+       gem_close(fd, handle);
+}
+
 static void noop(int fd, unsigned ring)
 {
-       uint32_t bbe = MI_BATCH_BUFFER_END;
        struct drm_i915_gem_execbuffer2 execbuf;
        struct drm_i915_gem_exec_object2 exec;
 
        gem_require_ring(fd, ring);
 
        memset(&exec, 0, sizeof(exec));
-       exec.handle = gem_create(fd, 4096);
-       gem_write(fd, exec.handle, 0, &bbe, sizeof(bbe));
+       exec.handle = batch_create(fd);
 
        memset(&execbuf, 0, sizeof(execbuf));
        execbuf.buffers_ptr = to_user_pointer(&exec);
        execbuf.buffer_count = 1;
        execbuf.flags = ring;
        gem_execbuf(fd, &execbuf);
-       gem_close(fd, exec.handle);
+
+       batch_fini(fd, exec.handle);
 }
 
 static void readonly(int fd, unsigned ring)
 {
-       uint32_t bbe = MI_BATCH_BUFFER_END;
        struct drm_i915_gem_execbuffer2 *execbuf;
        struct drm_i915_gem_exec_object2 exec;
 
        gem_require_ring(fd, ring);
 
        memset(&exec, 0, sizeof(exec));
-       exec.handle = gem_create(fd, 4096);
-       gem_write(fd, exec.handle, 0, &bbe, sizeof(bbe));
+       exec.handle = batch_create(fd);
 
        execbuf = mmap(NULL, 4096, PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
        igt_assert(execbuf != NULL);
@@ -67,12 +81,12 @@ static void readonly(int fd, unsigned ring)
 
        gem_execbuf(fd, execbuf);
        munmap(execbuf, 4096);
-       gem_close(fd, exec.handle);
+
+       batch_fini(fd, exec.handle);
 }
 
 static void gtt(int fd, unsigned ring)
 {
-       uint32_t bbe = MI_BATCH_BUFFER_END;
        struct drm_i915_gem_execbuffer2 *execbuf;
        struct drm_i915_gem_exec_object2 *exec;
        uint32_t handle;
@@ -86,15 +100,15 @@ static void gtt(int fd, unsigned ring)
        exec = (struct drm_i915_gem_exec_object2 *)(execbuf + 1);
        gem_close(fd, handle);
 
-       exec->handle = gem_create(fd, 4096);
-       gem_write(fd, exec->handle, 0, &bbe, sizeof(bbe));
+       exec->handle = batch_create(fd);
 
        execbuf->buffers_ptr = to_user_pointer(exec);
        execbuf->buffer_count = 1;
        execbuf->flags = ring;
 
        gem_execbuf(fd, execbuf);
-       gem_close(fd, exec->handle);
+
+       batch_fini(fd, exec->handle);
 
        munmap(execbuf, 4096);
 }



More information about the igt-dev mailing list