From 673e6b220a34fb7600cbf272bc46a4ac1ca08905 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Tue, 10 Jan 2012 16:05:34 +0100 Subject: [PATCH] lib/drmtest: extract gem_set_domain and gem_sync gem_sync just does a gtt sync by using set_domain(GTT, GTT). Signed-Off-by: Daniel Vetter --- lib/drmtest.c | 19 +++++++++++++++++++ lib/drmtest.h | 3 +++ tests/gem_exec_blt.c | 11 ----------- tests/gem_exec_faulting_reloc.c | 11 ----------- tests/gem_exec_nop.c | 11 ----------- tests/gem_fence_thrash.c | 8 +------- tests/gem_gtt_speed.c | 11 ----------- tests/gem_mmap_gtt.c | 10 +--------- tests/gem_stress.c | 16 ++-------------- tests/gem_vmap_blits.c | 10 +--------- 10 files changed, 27 insertions(+), 83 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index d526f38..376e4ac 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -169,3 +169,22 @@ void gem_read(int fd, uint32_t handle, uint32_t offset, void *buf, uint32_t leng assert(ret == 0); } +void gem_set_domain(int fd, uint32_t handle, + uint32_t read_domains, uint32_t write_domain) +{ + struct drm_i915_gem_set_domain set_domain; + int ret; + + set_domain.handle = handle; + set_domain.read_domains = read_domains; + set_domain.write_domain = write_domain; + + ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); + assert(ret == 0); +} + +void gem_sync(int fd, uint32_t handle) +{ + gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); +} + diff --git a/lib/drmtest.h b/lib/drmtest.h index 299570f..794e08b 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -41,3 +41,6 @@ void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride); void gem_close(int fd, uint32_t handle); void gem_write(int fd, uint32_t handle, uint32_t offset, const void *buf, uint32_t size); void gem_read(int fd, uint32_t handle, uint32_t offset, void *buf, uint32_t size); +void gem_set_domain(int fd, uint32_t handle, + uint32_t read_domains, uint32_t write_domain); +void gem_sync(int fd, uint32_t handle); diff --git a/tests/gem_exec_blt.c b/tests/gem_exec_blt.c index 415b882..91f7d21 100644 --- a/tests/gem_exec_blt.c +++ b/tests/gem_exec_blt.c @@ -137,17 +137,6 @@ static int gem_linear_blt(uint32_t *batch, return (b+2 - batch) * sizeof(uint32_t); } -static void gem_sync(int fd, uint32_t handle) -{ - struct drm_i915_gem_set_domain set_domain; - - set_domain.handle = handle; - set_domain.read_domains = I915_GEM_DOMAIN_GTT; - set_domain.write_domain = I915_GEM_DOMAIN_GTT; - - drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); -} - static int gem_exec(int fd, struct drm_i915_gem_execbuffer2 *execbuf, int loops) { int ret = 0; diff --git a/tests/gem_exec_faulting_reloc.c b/tests/gem_exec_faulting_reloc.c index d584e64..013ee79 100644 --- a/tests/gem_exec_faulting_reloc.c +++ b/tests/gem_exec_faulting_reloc.c @@ -162,17 +162,6 @@ static int gem_linear_blt(uint32_t *batch, return (b+2 - batch) * sizeof(uint32_t); } -static void gem_sync(int fd, uint32_t handle) -{ - struct drm_i915_gem_set_domain set_domain; - - set_domain.handle = handle; - set_domain.read_domains = I915_GEM_DOMAIN_GTT; - set_domain.write_domain = I915_GEM_DOMAIN_GTT; - - drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); -} - static void gem_exec(int fd, struct drm_i915_gem_execbuffer2 *execbuf) { int ret; diff --git a/tests/gem_exec_nop.c b/tests/gem_exec_nop.c index b6c361e..d13756b 100644 --- a/tests/gem_exec_nop.c +++ b/tests/gem_exec_nop.c @@ -55,17 +55,6 @@ static uint32_t gem_create(int fd, int size) return create.handle; } -static void gem_sync(int fd, uint32_t handle) -{ - struct drm_i915_gem_set_domain set_domain; - - set_domain.handle = handle; - set_domain.read_domains = I915_GEM_DOMAIN_GTT; - set_domain.write_domain = I915_GEM_DOMAIN_GTT; - - drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); -} - static double elapsed(const struct timeval *start, const struct timeval *end, int loop) diff --git a/tests/gem_fence_thrash.c b/tests/gem_fence_thrash.c index 7b67936..2065ac6 100644 --- a/tests/gem_fence_thrash.c +++ b/tests/gem_fence_thrash.c @@ -58,7 +58,6 @@ bo_create (int fd) { struct drm_i915_gem_create create; struct drm_i915_gem_set_tiling tiling; - struct drm_i915_gem_set_domain domain; struct drm_i915_gem_mmap_gtt mmap_arg; void *ptr; int handle; @@ -88,12 +87,7 @@ bo_create (int fd) assert (ptr != MAP_FAILED); /* XXX: mmap_gtt pulls the bo into the GTT read domain. */ - memset(&domain, 0, sizeof(domain)); - domain.handle = handle; - domain.read_domains = I915_GEM_DOMAIN_GTT; - domain.write_domain = I915_GEM_DOMAIN_GTT; - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &domain); - assert (ret == 0); + gem_sync(fd, handle); return ptr; } diff --git a/tests/gem_gtt_speed.c b/tests/gem_gtt_speed.c index 8e3750d..3f5bd0b 100644 --- a/tests/gem_gtt_speed.c +++ b/tests/gem_gtt_speed.c @@ -79,17 +79,6 @@ static double elapsed(const struct timeval *start, return (1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop; } -static void gem_sync(int fd, uint32_t handle) -{ - struct drm_i915_gem_set_domain set_domain; - - set_domain.handle = handle; - set_domain.read_domains = I915_GEM_DOMAIN_GTT; - set_domain.write_domain = I915_GEM_DOMAIN_GTT; - - drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); -} - int main(int argc, char **argv) { struct timeval start, end; diff --git a/tests/gem_mmap_gtt.c b/tests/gem_mmap_gtt.c index f817f14..e813587 100644 --- a/tests/gem_mmap_gtt.c +++ b/tests/gem_mmap_gtt.c @@ -57,15 +57,7 @@ static uint32_t gem_create(int fd, int size) static void set_domain(int fd, uint32_t handle) { - struct drm_i915_gem_set_domain set_domain; - int ret; - - set_domain.handle = handle; - set_domain.read_domains = I915_GEM_DOMAIN_GTT; - set_domain.write_domain = I915_GEM_DOMAIN_GTT; - - ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); - assert(ret == 0); + gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); } static void * diff --git a/tests/gem_stress.c b/tests/gem_stress.c index 64dca6c..f72bd13 100644 --- a/tests/gem_stress.c +++ b/tests/gem_stress.c @@ -190,20 +190,8 @@ void keep_gpu_busy(void) static void set_to_cpu_domain(struct scratch_buf *buf, int writing) { - struct drm_i915_gem_set_domain set_domain; - int ret; - - set_domain.handle = buf->bo->handle; - set_domain.read_domains = I915_GEM_DOMAIN_CPU; - if (writing) - set_domain.write_domain = I915_GEM_DOMAIN_CPU; - else - set_domain.write_domain = 0; - - ret = drmIoctl(drm_fd, - DRM_IOCTL_I915_GEM_SET_DOMAIN, - &set_domain); - assert(ret == 0); + gem_set_domain(drm_fd, buf->bo->handle, I915_GEM_DOMAIN_CPU, + writing ? I915_GEM_DOMAIN_CPU : 0); } static unsigned int copyfunc_seq = 0; diff --git a/tests/gem_vmap_blits.c b/tests/gem_vmap_blits.c index a6655a4..9c0a91f 100644 --- a/tests/gem_vmap_blits.c +++ b/tests/gem_vmap_blits.c @@ -96,15 +96,7 @@ static uint32_t gem_vmap(int fd, void *ptr, int size, int read_only) static void gem_vmap_sync(int fd, uint32_t handle) { - struct drm_i915_gem_set_domain set_domain; - int ret; - - set_domain.handle = handle; - set_domain.read_domains = I915_GEM_DOMAIN_CPU; - set_domain.write_domain = I915_GEM_DOMAIN_CPU; - - ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); - assert(ret == 0); + gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); } static uint64_t -- 2.7.4