diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2016-02-23 17:45:49 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2016-02-23 18:03:46 +0000 |
commit | f27d295fe3a1ca005dfa0fbfd81d6808b1f5ca47 (patch) | |
tree | eef0a41794f920cdba7023c2d8c12202844e1c08 | |
parent | babcf40f29d9e9cce5d0739b1784eb94fe91bd26 (diff) |
lib: Move gem_wait() to ioctl-wrappers
We intend to use gem_wait() in more tests than gem_wait.c, so move the
simple ioctl wrapper into the core.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | lib/ioctl_wrappers.c | 44 | ||||
-rw-r--r-- | lib/ioctl_wrappers.h | 1 | ||||
-rw-r--r-- | tests/gem_wait.c | 29 |
3 files changed, 41 insertions, 33 deletions
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index de56e42d..40712606 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -370,28 +370,52 @@ void gem_set_domain(int fd, uint32_t handle, } /** - * gem_sync: + * __gem_wait: * @fd: open i915 drm file descriptor * @handle: gem buffer object handle + * @timeout_ns: [in] time to wait, [out] remaining time (in nanoseconds) * - * This functions waits for outstanding rendering to complete. + * This functions waits for outstanding rendering to complete, upto + * the timeout_ns. If no timeout_ns is provided, the wait is indefinite and + * only returns upon an error or when the rendering is complete. */ -void gem_sync(int fd, uint32_t handle) +int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns) { struct drm_i915_gem_wait wait; + int ret; memset(&wait, 0, sizeof(wait)); wait.bo_handle = handle; - wait.timeout_ns =-1; - if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait) == 0) { - errno = 0; - return; - } + wait.timeout_ns = timeout_ns ? *timeout_ns : -1; + wait.flags = 0; + + ret = 0; + if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait)) + ret = -errno; + + if (timeout_ns) + *timeout_ns = wait.timeout_ns; + + return ret; +} - gem_set_domain(fd, handle, - I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); +/** + * gem_sync: + * @fd: open i915 drm file descriptor + * @handle: gem buffer object handle + * + * This functions waits for outstanding rendering to complete. + */ +void gem_sync(int fd, uint32_t handle) +{ + if (gem_wait(fd, handle, NULL)) + gem_set_domain(fd, handle, + I915_GEM_DOMAIN_GTT, + I915_GEM_DOMAIN_GTT); + errno = 0; } + bool gem_create__has_stolen_support(int fd) { static int has_stolen_support = -1; diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 4683ff5f..dc0827a1 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -55,6 +55,7 @@ void gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint6 void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length); void gem_set_domain(int fd, uint32_t handle, uint32_t read_domains, uint32_t write_domain); +int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns); void gem_sync(int fd, uint32_t handle); bool gem_create__has_stolen_support(int fd); uint32_t __gem_create_stolen(int fd, uint64_t size); diff --git a/tests/gem_wait.c b/tests/gem_wait.c index ecf0dcf3..461efdbd 100644 --- a/tests/gem_wait.c +++ b/tests/gem_wait.c @@ -64,23 +64,6 @@ do_time_diff(struct timespec *end, struct timespec *start) return ret; } -static int -gem_bo_wait_timeout(int fd, uint32_t handle, int64_t *timeout_ns) -{ - struct drm_i915_gem_wait wait; - int ret; - - igt_assert(timeout_ns); - - wait.bo_handle = handle; - wait.timeout_ns = *timeout_ns; - wait.flags = 0; - ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait); - *timeout_ns = wait.timeout_ns; - - return ret ? -errno : 0; -} - static void blt_color_fill(struct intel_batchbuffer *batch, drm_intel_bo *buf, const unsigned int pages) @@ -122,7 +105,7 @@ static void render_timeout(int fd) dst = drm_intel_bo_alloc(bufmgr, "dst", BUF_SIZE, 4096); dst2 = drm_intel_bo_alloc(bufmgr, "dst2", BUF_SIZE, 4096); - igt_skip_on_f(gem_bo_wait_timeout(fd, dst->handle, &timeout) == -EINVAL, + igt_skip_on_f(gem_wait(fd, dst->handle, &timeout) == -EINVAL, "kernel doesn't support wait_timeout, skipping test\n"); timeout = ENOUGH_WORK_IN_SECONDS * NSEC_PER_SEC; @@ -169,7 +152,7 @@ static void render_timeout(int fd) intel_batchbuffer_flush(batch); igt_assert(gem_bo_busy(fd, dst2->handle) == true); - igt_assert_eq(gem_bo_wait_timeout(fd, dst2->handle, &timeout), 0); + igt_assert_eq(gem_wait(fd, dst2->handle, &timeout), 0); igt_assert(gem_bo_busy(fd, dst2->handle) == false); igt_assert_neq(timeout, 0); if (timeout == (ENOUGH_WORK_IN_SECONDS * NSEC_PER_SEC)) @@ -179,7 +162,7 @@ static void render_timeout(int fd) /* check that polling with timeout=0 works. */ timeout = 0; - igt_assert_eq(gem_bo_wait_timeout(fd, dst2->handle, &timeout), 0); + igt_assert_eq(gem_wait(fd, dst2->handle, &timeout), 0); igt_assert_eq(timeout, 0); /* Now check that we correctly time out, twice the auto-tune load should @@ -190,14 +173,14 @@ static void render_timeout(int fd) intel_batchbuffer_flush(batch); - ret = gem_bo_wait_timeout(fd, dst2->handle, &timeout); + ret = gem_wait(fd, dst2->handle, &timeout); igt_assert_eq(ret, -ETIME); igt_assert_eq(timeout, 0); igt_assert(gem_bo_busy(fd, dst2->handle) == true); /* check that polling with timeout=0 works. */ timeout = 0; - igt_assert_eq(gem_bo_wait_timeout(fd, dst2->handle, &timeout), -ETIME); + igt_assert_eq(gem_wait(fd, dst2->handle, &timeout), -ETIME); igt_assert_eq(timeout, 0); @@ -208,7 +191,7 @@ static void render_timeout(int fd) intel_batchbuffer_flush(batch); - igt_assert_eq(gem_bo_wait_timeout(fd, dst2->handle, &negative_timeout), 0); + igt_assert_eq(gem_wait(fd, dst2->handle, &negative_timeout), 0); igt_assert_eq(negative_timeout, -1); /* infinity always remains */ igt_assert(gem_bo_busy(fd, dst2->handle) == false); |