From: Daniel Vetter Date: Tue, 10 Jan 2012 13:59:58 +0000 (+0100) Subject: lib/drmtest: extract gem_set_tiling X-Git-Tag: 1.2~68 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa67b22e426f26f8a8d7fe35221fe2a6ceb5d3db;p=profile%2Fextras%2Fintel-gpu-tools.git lib/drmtest: extract gem_set_tiling Way too much copy-pasting going on here. Also fix a compiler warnings in gem_stress while fixup things up. Signed-off-by: Daniel Vetter --- diff --git a/lib/drmtest.c b/lib/drmtest.c index fc40ad1..dc655c4 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -1,5 +1,5 @@ /* - * Copyright © 2007 Intel Corporation + * Copyright © 2007, 2011 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,16 +22,21 @@ * * Authors: * Eric Anholt + * Daniel Vetter * */ #include #include #include +#include #include "drmtest.h" #include "i915_drm.h" #include "intel_chipset.h" +/* This file contains a bunch of wrapper functions to directly use gem ioctls. + * Mostly useful to write kernel tests. */ + static int is_intel(int fd) { @@ -110,3 +115,22 @@ int drm_open_any_master(void) fprintf(stderr, "Couldn't find an un-controlled DRM device\n"); abort(); } + +void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride) +{ + struct drm_i915_gem_set_tiling st; + int ret; + + memset(&st, 0, sizeof(st)); + do { + st.handle = handle; + st.tiling_mode = tiling; + st.stride = tiling ? stride : 0; + + ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &st); + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); + assert(ret == 0); + assert(st.tiling_mode == tiling); +} + + diff --git a/lib/drmtest.h b/lib/drmtest.h index afa0df4..02138dc 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -35,3 +35,6 @@ int drm_open_any(void); int drm_open_any_master(void); + + +void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride); diff --git a/tests/gem_gtt_speed.c b/tests/gem_gtt_speed.c index 1a159a9..a406a24 100644 --- a/tests/gem_gtt_speed.c +++ b/tests/gem_gtt_speed.c @@ -98,20 +98,6 @@ static int gem_read(int fd, return drmIoctl(fd, DRM_IOCTL_I915_GEM_PREAD, &pread); } -static void gem_set_tiling(int fd, uint32_t handle, int tiling) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = 512; - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); -} - static void gem_close(int fd, uint32_t handle) { struct drm_gem_close close; @@ -165,7 +151,7 @@ int main(int argc, char **argv) if (tiling != I915_TILING_NONE) { printf("\nSetting tiling mode to %s\n", tiling == I915_TILING_X ? "X" : "Y"); - gem_set_tiling(fd, handle, tiling); + gem_set_tiling(fd, handle, tiling, 512); } if (tiling == I915_TILING_NONE) { diff --git a/tests/gem_stress.c b/tests/gem_stress.c index ecf3a0d..64dca6c 100644 --- a/tests/gem_stress.c +++ b/tests/gem_stress.c @@ -188,14 +188,14 @@ void keep_gpu_busy(void) busy_bo, 0, 4096, 0, 128); } -static void set_to_cpu_domain(struct scratch_buf *buf, int write) +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 (write) + if (writing) set_domain.write_domain = I915_GEM_DOMAIN_CPU; else set_domain.write_domain = 0; @@ -522,32 +522,6 @@ static void exchange_buf(void *array, unsigned i, unsigned j) } -/* libdrm is too clever and prevents us from changing tiling of buffers already - * used in relocations. */ -static void set_tiling(drm_intel_bo *bo, unsigned *tiling, unsigned stride) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - memset(&set_tiling, 0, sizeof(set_tiling)); - do { - /* set_tiling is slightly broken and overwrites the - * input on the error path, so we have to open code - * drmIoctl. - */ - set_tiling.handle = bo->handle; - set_tiling.tiling_mode = *tiling; - set_tiling.stride = tiling ? stride : 0; - - ret = ioctl(drm_fd, - DRM_IOCTL_I915_GEM_SET_TILING, - &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - assert(ret != -1); - - *tiling = set_tiling.tiling_mode; -} - static void init_set(unsigned set) { long int r; @@ -591,9 +565,9 @@ static void init_set(unsigned set) sanitize_stride(&buffers[set][i]); - set_tiling(buffers[set][i].bo, - &buffers[set][i].tiling, - buffers[set][i].stride); + gem_set_tiling(drm_fd, buffers[set][i].bo->handle, + buffers[set][i].tiling, + buffers[set][i].stride); if (options.trace_tile != -1 && i == options.trace_tile/options.tiles_per_buf) printf("changing buffer %i containing tile %i: tiling %i, stride %i\n", i, @@ -857,11 +831,8 @@ static void init(void) batch = intel_batchbuffer_alloc(bufmgr, devid); busy_bo = drm_intel_bo_alloc(bufmgr, "tiled bo", BUSY_BUF_SIZE, 4096); - if (options.forced_tiling >= 0) { - tmp = options.forced_tiling; - set_tiling(busy_bo, &tmp, 4096); - assert(tmp == options.forced_tiling); - } + if (options.forced_tiling >= 0) + gem_set_tiling(drm_fd, busy_bo->handle, options.forced_tiling, 4096); for (i = 0; i < num_buffers; i++) { init_buffer(&buffers[0][i], options.scratch_buf_size); diff --git a/tests/gem_tiled_pread.c b/tests/gem_tiled_pread.c index e2b2b64..b25759d 100644 --- a/tests/gem_tiled_pread.c +++ b/tests/gem_tiled_pread.c @@ -104,21 +104,6 @@ gem_read(int fd, uint32_t handle, int offset, int length, void *buf) } static void -gem_set_tiling(int fd, uint32_t handle, int tiling) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = WIDTH * sizeof(uint32_t); - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); -} - -static void gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle) { struct drm_i915_gem_get_tiling get_tiling; @@ -142,7 +127,7 @@ create_bo(int fd) int i; handle = gem_create(fd, sizeof(linear)); - gem_set_tiling(fd, handle, I915_TILING_X); + gem_set_tiling(fd, handle, I915_TILING_X, WIDTH * sizeof(uint32_t)); /* Fill the BO with dwords starting at start_val */ data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE); diff --git a/tests/gem_tiled_pread_pwrite.c b/tests/gem_tiled_pread_pwrite.c index c6f124f..b10eaa4 100644 --- a/tests/gem_tiled_pread_pwrite.c +++ b/tests/gem_tiled_pread_pwrite.c @@ -123,21 +123,6 @@ gem_read(int fd, uint32_t handle, int offset, int length, void *buf) } static void -gem_set_tiling(int fd, uint32_t handle, int tiling) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = WIDTH * sizeof(uint32_t); - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); -} - -static void gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle) { struct drm_i915_gem_get_tiling get_tiling; @@ -161,7 +146,7 @@ create_bo_and_fill(int fd) int i; handle = gem_create(fd, sizeof(linear)); - gem_set_tiling(fd, handle, current_tiling_mode); + gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t)); /* Fill the BO with dwords starting at start_val */ data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE); @@ -178,7 +163,7 @@ create_bo(int fd) uint32_t handle; handle = gem_create(fd, sizeof(linear)); - gem_set_tiling(fd, handle, current_tiling_mode); + gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t)); return handle; } diff --git a/tests/gen3_mixed_blits.c b/tests/gen3_mixed_blits.c index 997a7b7..1ebc773 100644 --- a/tests/gen3_mixed_blits.c +++ b/tests/gen3_mixed_blits.c @@ -484,22 +484,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot) return ptr; } -static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = stride; - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - assert(ret == 0); - assert(set_tiling.tiling_mode == tiling); -} - static uint32_t create_bo(int fd, uint32_t val, int tiling) { diff --git a/tests/gen3_render_mixed_blits.c b/tests/gen3_render_mixed_blits.c index 8439e06..72a4b0a 100644 --- a/tests/gen3_render_mixed_blits.c +++ b/tests/gen3_render_mixed_blits.c @@ -373,22 +373,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot) return ptr; } -static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = stride; - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - assert(ret == 0); - assert(set_tiling.tiling_mode == tiling); -} - static uint32_t create_bo(int fd, uint32_t val, int tiling) { diff --git a/tests/gen3_render_tiledx_blits.c b/tests/gen3_render_tiledx_blits.c index a6c72a6..1636027 100644 --- a/tests/gen3_render_tiledx_blits.c +++ b/tests/gen3_render_tiledx_blits.c @@ -360,22 +360,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot) return ptr; } -static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = stride; - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - assert(ret == 0); - assert(set_tiling.tiling_mode == tiling); -} - static uint32_t create_bo(int fd, uint32_t val) { diff --git a/tests/gen3_render_tiledy_blits.c b/tests/gen3_render_tiledy_blits.c index 11c00c2..a29d555 100644 --- a/tests/gen3_render_tiledy_blits.c +++ b/tests/gen3_render_tiledy_blits.c @@ -360,22 +360,6 @@ static void *gem_mmap(int fd, uint32_t handle, int size, int prot) return ptr; } -static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride) -{ - struct drm_i915_gem_set_tiling set_tiling; - int ret; - - do { - set_tiling.handle = handle; - set_tiling.tiling_mode = tiling; - set_tiling.stride = stride; - - ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - assert(ret == 0); - assert(set_tiling.tiling_mode == tiling); -} - static uint32_t create_bo(int fd, uint32_t val) {