summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2012-01-11 17:19:53 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2012-01-11 17:19:53 +0100
commit9f8766030463bc0c75506d990831b853f19d7725 (patch)
tree0395b705d328d27a197aba3968b014a66944a370
parent7a54bfa772d6823a20152c15fe18726e9222a4e9 (diff)
lib/drmtest: add gpu quiescent helper
Some tests are higly timing dependent and others carelessly leave active buffers behind. So add a helper to quiescent the gpu and call it unconditionally when opening an fd in a vain attempt to make all this race-condition hitting more scientifically sound. Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--lib/drmtest.c46
-rw-r--r--lib/drmtest.h1
2 files changed, 46 insertions, 1 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index bfb36a86..a64aa6aa 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -55,6 +55,48 @@ is_intel(int fd)
return IS_INTEL(devid);
}
+/* Ensure the gpu is idle by launching a nop execbuf and stalling for it. */
+void gem_quiescent_gpu(int fd)
+{
+#define MI_BATCH_BUFFER_END (0xA<<23)
+ uint32_t batch[2] = {MI_BATCH_BUFFER_END, 0};
+ uint32_t handle;
+ struct drm_i915_gem_execbuffer2 execbuf;
+ struct drm_i915_gem_exec_object2 gem_exec[1];
+ int ret = 0;
+
+ handle = gem_create(fd, 4096);
+ gem_write(fd, handle, 0, batch, sizeof(batch));
+
+ gem_exec[0].handle = handle;
+ gem_exec[0].relocation_count = 0;
+ gem_exec[0].relocs_ptr = 0;
+ gem_exec[0].alignment = 0;
+ gem_exec[0].offset = 0;
+ gem_exec[0].flags = 0;
+ gem_exec[0].rsvd1 = 0;
+ gem_exec[0].rsvd2 = 0;
+
+ execbuf.buffers_ptr = (uintptr_t)gem_exec;
+ execbuf.buffer_count = 1;
+ execbuf.batch_start_offset = 0;
+ execbuf.batch_len = 8;
+ execbuf.cliprects_ptr = 0;
+ execbuf.num_cliprects = 0;
+ execbuf.DR1 = 0;
+ execbuf.DR4 = 0;
+ execbuf.flags = 0;
+ execbuf.rsvd1 = 0;
+ execbuf.rsvd2 = 0;
+
+ ret = drmIoctl(fd,
+ DRM_IOCTL_I915_GEM_EXECBUFFER2,
+ &execbuf);
+ assert(ret == 0);
+
+ gem_sync(fd, handle);
+}
+
/** Open the first DRM device we can find, searching up to 16 device nodes */
int drm_open_any(void)
{
@@ -67,8 +109,10 @@ int drm_open_any(void)
if (fd == -1)
continue;
- if (is_intel(fd))
+ if (is_intel(fd)) {
+ gem_quiescent_gpu(fd);
return fd;
+ }
close(fd);
}
diff --git a/lib/drmtest.h b/lib/drmtest.h
index a10a0521..4af98002 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -36,6 +36,7 @@
int drm_open_any(void);
int drm_open_any_master(void);
+void gem_quiescent_gpu(int fd);
void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride);
void gem_close(int fd, uint32_t handle);