Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2009,2012,2013 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * Chris Wilson <chris@chris-wilson.co.uk> |
| 26 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 27 | * |
| 28 | */ |
| 29 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 30 | /** @file gem_concurrent_blit.c |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 31 | * |
| 32 | * This is a test of pread/pwrite behavior when writing to active |
| 33 | * buffers. |
| 34 | * |
| 35 | * Based on gem_gtt_concurrent_blt. |
| 36 | */ |
| 37 | |
| 38 | #include <stdlib.h> |
| 39 | #include <stdio.h> |
| 40 | #include <string.h> |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 41 | #include <fcntl.h> |
| 42 | #include <inttypes.h> |
| 43 | #include <errno.h> |
| 44 | #include <sys/stat.h> |
| 45 | #include <sys/time.h> |
Chris Wilson | 99431a4 | 2013-08-14 11:03:34 +0100 | [diff] [blame] | 46 | #include <sys/wait.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 47 | |
| 48 | #include <drm.h> |
| 49 | |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 50 | #include "ioctl_wrappers.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 51 | #include "drmtest.h" |
| 52 | #include "intel_bufmgr.h" |
| 53 | #include "intel_batchbuffer.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 54 | #include "intel_io.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 55 | #include "intel_chipset.h" |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 56 | #include "igt_aux.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 57 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 58 | int fd, devid, gen; |
| 59 | struct intel_batchbuffer *batch; |
| 60 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 61 | static void |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 62 | prw_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 63 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 64 | int size = width * height, i; |
| 65 | uint32_t *tmp; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 66 | |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 67 | tmp = malloc(4*size); |
| 68 | if (tmp) { |
| 69 | for (i = 0; i < size; i++) |
| 70 | tmp[i] = val; |
| 71 | drm_intel_bo_subdata(bo, 0, 4*size, tmp); |
| 72 | free(tmp); |
| 73 | } else { |
| 74 | for (i = 0; i < size; i++) |
| 75 | drm_intel_bo_subdata(bo, 4*i, 4, &val); |
| 76 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 80 | prw_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 81 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 82 | int size = width * height, i; |
| 83 | uint32_t *tmp; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 84 | |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 85 | tmp = malloc(4*size); |
| 86 | if (tmp) { |
| 87 | memset(tmp, 0, 4*size); |
| 88 | do_or_die(drm_intel_bo_get_subdata(bo, 0, 4*size, tmp)); |
| 89 | for (i = 0; i < size; i++) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 90 | igt_assert_eq_u32(tmp[i], val); |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 91 | free(tmp); |
| 92 | } else { |
| 93 | uint32_t t; |
| 94 | for (i = 0; i < size; i++) { |
| 95 | t = 0; |
| 96 | do_or_die(drm_intel_bo_get_subdata(bo, 4*i, 4, &t)); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 97 | igt_assert_eq_u32(t, val); |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static drm_intel_bo * |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 103 | unmapped_create_bo(drm_intel_bufmgr *bufmgr, uint32_t val, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 104 | { |
| 105 | drm_intel_bo *bo; |
| 106 | |
| 107 | bo = drm_intel_bo_alloc(bufmgr, "bo", 4*width*height, 0); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 108 | igt_assert(bo); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 109 | |
| 110 | return bo; |
| 111 | } |
| 112 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 113 | static void |
| 114 | gtt_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 115 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 116 | int size = width * height; |
| 117 | uint32_t *vaddr; |
| 118 | |
| 119 | drm_intel_gem_bo_start_gtt_access(bo, true); |
| 120 | vaddr = bo->virtual; |
| 121 | while (size--) |
| 122 | *vaddr++ = val; |
| 123 | } |
| 124 | |
| 125 | static void |
| 126 | gtt_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 127 | { |
| 128 | int size = width * height; |
| 129 | uint32_t *vaddr; |
| 130 | |
| 131 | drm_intel_gem_bo_start_gtt_access(bo, false); |
| 132 | vaddr = bo->virtual; |
| 133 | while (size--) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 134 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static drm_intel_bo * |
| 138 | gtt_create_bo(drm_intel_bufmgr *bufmgr, uint32_t val, int width, int height) |
| 139 | { |
| 140 | drm_intel_bo *bo; |
| 141 | |
| 142 | bo = drm_intel_bo_alloc(bufmgr, "bo", 4*width*height, 0); |
| 143 | igt_assert(bo); |
| 144 | |
| 145 | /* gtt map doesn't have a write parameter, so just keep the mapping |
| 146 | * around (to avoid the set_domain with the gtt write domain set) and |
| 147 | * manually tell the kernel when we start access the gtt. */ |
| 148 | do_or_die(drm_intel_gem_bo_map_gtt(bo)); |
| 149 | |
| 150 | return bo; |
| 151 | } |
| 152 | |
| 153 | static void |
| 154 | cpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 155 | { |
| 156 | int size = width * height; |
| 157 | uint32_t *vaddr; |
| 158 | |
| 159 | do_or_die(drm_intel_bo_map(bo, true)); |
| 160 | vaddr = bo->virtual; |
| 161 | while (size--) |
| 162 | *vaddr++ = val; |
| 163 | drm_intel_bo_unmap(bo); |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | cpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 168 | { |
| 169 | int size = width * height; |
| 170 | uint32_t *vaddr; |
| 171 | |
| 172 | do_or_die(drm_intel_bo_map(bo, false)); |
| 173 | vaddr = bo->virtual; |
| 174 | while (size--) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 175 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 176 | drm_intel_bo_unmap(bo); |
| 177 | } |
| 178 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 179 | static void |
| 180 | gpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 181 | { |
| 182 | struct drm_i915_gem_relocation_entry reloc[1]; |
| 183 | struct drm_i915_gem_exec_object2 gem_exec[2]; |
| 184 | struct drm_i915_gem_execbuffer2 execbuf; |
| 185 | struct drm_i915_gem_pwrite gem_pwrite; |
| 186 | struct drm_i915_gem_create create; |
| 187 | uint32_t buf[10], *b; |
| 188 | |
| 189 | memset(reloc, 0, sizeof(reloc)); |
| 190 | memset(gem_exec, 0, sizeof(gem_exec)); |
| 191 | memset(&execbuf, 0, sizeof(execbuf)); |
| 192 | |
| 193 | b = buf; |
| 194 | *b++ = XY_COLOR_BLT_CMD_NOLEN | |
| 195 | ((gen >= 8) ? 5 : 4) | |
| 196 | COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB; |
| 197 | *b++ = 0xf0 << 16 | 1 << 25 | 1 << 24 | width << 2; |
| 198 | *b++ = 0; |
| 199 | *b++ = height << 16 | width; |
| 200 | reloc[0].offset = (b - buf) * sizeof(uint32_t); |
| 201 | reloc[0].target_handle = bo->handle; |
| 202 | reloc[0].read_domains = I915_GEM_DOMAIN_RENDER; |
| 203 | reloc[0].write_domain = I915_GEM_DOMAIN_RENDER; |
| 204 | *b++ = 0; |
| 205 | if (gen >= 8) |
| 206 | *b++ = 0; |
| 207 | *b++ = val; |
| 208 | *b++ = MI_BATCH_BUFFER_END; |
| 209 | if ((b - buf) & 1) |
| 210 | *b++ = 0; |
| 211 | |
| 212 | gem_exec[0].handle = bo->handle; |
| 213 | gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE; |
| 214 | |
| 215 | create.handle = 0; |
| 216 | create.size = 4096; |
| 217 | drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); |
| 218 | gem_exec[1].handle = create.handle; |
| 219 | gem_exec[1].relocation_count = 1; |
| 220 | gem_exec[1].relocs_ptr = (uintptr_t)reloc; |
| 221 | |
| 222 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 223 | execbuf.buffer_count = 2; |
| 224 | execbuf.batch_len = (b - buf) * sizeof(buf[0]); |
| 225 | execbuf.flags = 1 << 11; |
| 226 | if (HAS_BLT_RING(devid)) |
| 227 | execbuf.flags |= I915_EXEC_BLT; |
| 228 | |
| 229 | gem_pwrite.handle = gem_exec[1].handle; |
| 230 | gem_pwrite.offset = 0; |
| 231 | gem_pwrite.size = execbuf.batch_len; |
| 232 | gem_pwrite.data_ptr = (uintptr_t)buf; |
| 233 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite) == 0) |
| 234 | drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf); |
| 235 | |
| 236 | drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &create.handle); |
| 237 | } |
| 238 | |
| 239 | static void |
| 240 | gpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 241 | { |
| 242 | dri_bo *tmp = drm_intel_bo_alloc(bo->bufmgr, "tmp", 4*width*height, 0); |
| 243 | intel_copy_bo(batch, tmp, bo, width*height*4); |
| 244 | cpu_cmp_bo(tmp, val, width, height); |
| 245 | drm_intel_bo_unreference(tmp); |
| 246 | } |
| 247 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 248 | struct access_mode { |
| 249 | void (*set_bo)(drm_intel_bo *bo, uint32_t val, int w, int h); |
| 250 | void (*cmp_bo)(drm_intel_bo *bo, uint32_t val, int w, int h); |
| 251 | drm_intel_bo *(*create_bo)(drm_intel_bufmgr *bufmgr, |
| 252 | uint32_t val, int width, int height); |
| 253 | const char *name; |
| 254 | }; |
| 255 | |
| 256 | struct access_mode access_modes[] = { |
| 257 | { .set_bo = prw_set_bo, .cmp_bo = prw_cmp_bo, |
| 258 | .create_bo = unmapped_create_bo, .name = "prw" }, |
| 259 | { .set_bo = cpu_set_bo, .cmp_bo = cpu_cmp_bo, |
| 260 | .create_bo = unmapped_create_bo, .name = "cpu" }, |
| 261 | { .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo, |
| 262 | .create_bo = gtt_create_bo, .name = "gtt" }, |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 263 | { .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo, |
| 264 | .create_bo = unmapped_create_bo, .name = "gpu" }, |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 265 | }; |
| 266 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 267 | #define MAX_NUM_BUFFERS 1024 |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 268 | int num_buffers = MAX_NUM_BUFFERS; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 269 | drm_intel_bufmgr *bufmgr; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 270 | int width = 512, height = 512; |
| 271 | |
| 272 | static void do_overwrite_source(struct access_mode *mode, |
| 273 | drm_intel_bo **src, drm_intel_bo **dst, |
| 274 | drm_intel_bo *dummy) |
| 275 | { |
| 276 | int i; |
| 277 | |
| 278 | gem_quiescent_gpu(fd); |
| 279 | for (i = 0; i < num_buffers; i++) { |
| 280 | mode->set_bo(src[i], i, width, height); |
| 281 | mode->set_bo(dst[i], i, width, height); |
| 282 | } |
| 283 | for (i = 0; i < num_buffers; i++) |
Daniel Vetter | eaccd44 | 2014-03-13 03:35:02 +0100 | [diff] [blame] | 284 | intel_copy_bo(batch, dst[i], src[i], width*height*4); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 285 | for (i = num_buffers; i--; ) |
| 286 | mode->set_bo(src[i], 0xdeadbeef, width, height); |
| 287 | for (i = 0; i < num_buffers; i++) |
| 288 | mode->cmp_bo(dst[i], i, width, height); |
| 289 | } |
| 290 | |
| 291 | static void do_early_read(struct access_mode *mode, |
| 292 | drm_intel_bo **src, drm_intel_bo **dst, |
| 293 | drm_intel_bo *dummy) |
| 294 | { |
| 295 | int i; |
| 296 | |
| 297 | gem_quiescent_gpu(fd); |
| 298 | for (i = num_buffers; i--; ) |
| 299 | mode->set_bo(src[i], 0xdeadbeef, width, height); |
| 300 | for (i = 0; i < num_buffers; i++) |
Daniel Vetter | eaccd44 | 2014-03-13 03:35:02 +0100 | [diff] [blame] | 301 | intel_copy_bo(batch, dst[i], src[i], width*height*4); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 302 | for (i = num_buffers; i--; ) |
| 303 | mode->cmp_bo(dst[i], 0xdeadbeef, width, height); |
| 304 | } |
| 305 | |
| 306 | static void do_gpu_read_after_write(struct access_mode *mode, |
| 307 | drm_intel_bo **src, drm_intel_bo **dst, |
| 308 | drm_intel_bo *dummy) |
| 309 | { |
| 310 | int i; |
| 311 | |
| 312 | gem_quiescent_gpu(fd); |
| 313 | for (i = num_buffers; i--; ) |
| 314 | mode->set_bo(src[i], 0xabcdabcd, width, height); |
| 315 | for (i = 0; i < num_buffers; i++) |
Daniel Vetter | eaccd44 | 2014-03-13 03:35:02 +0100 | [diff] [blame] | 316 | intel_copy_bo(batch, dst[i], src[i], width*height*4); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 317 | for (i = num_buffers; i--; ) |
Daniel Vetter | eaccd44 | 2014-03-13 03:35:02 +0100 | [diff] [blame] | 318 | intel_copy_bo(batch, dummy, dst[i], width*height*4); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 319 | for (i = num_buffers; i--; ) |
| 320 | mode->cmp_bo(dst[i], 0xabcdabcd, width, height); |
| 321 | } |
| 322 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 323 | typedef void (*do_test)(struct access_mode *mode, |
| 324 | drm_intel_bo **src, drm_intel_bo **dst, |
| 325 | drm_intel_bo *dummy); |
| 326 | |
| 327 | typedef void (*run_wrap)(struct access_mode *mode, |
| 328 | drm_intel_bo **src, drm_intel_bo **dst, |
| 329 | drm_intel_bo *dummy, |
| 330 | do_test do_test_func); |
| 331 | |
| 332 | static void run_single(struct access_mode *mode, |
| 333 | drm_intel_bo **src, drm_intel_bo **dst, |
| 334 | drm_intel_bo *dummy, |
| 335 | do_test do_test_func) |
| 336 | { |
| 337 | do_test_func(mode, src, dst, dummy); |
| 338 | } |
| 339 | |
| 340 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 341 | static void run_interruptible(struct access_mode *mode, |
| 342 | drm_intel_bo **src, drm_intel_bo **dst, |
| 343 | drm_intel_bo *dummy, |
| 344 | do_test do_test_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 345 | { |
| 346 | int loop; |
| 347 | |
| 348 | for (loop = 0; loop < 10; loop++) |
| 349 | do_test_func(mode, src, dst, dummy); |
| 350 | } |
| 351 | |
| 352 | static void run_forked(struct access_mode *mode, |
| 353 | drm_intel_bo **src, drm_intel_bo **dst, |
| 354 | drm_intel_bo *dummy, |
| 355 | do_test do_test_func) |
| 356 | { |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 357 | const int old_num_buffers = num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 358 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 359 | num_buffers /= 16; |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 360 | num_buffers += 2; |
| 361 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 362 | igt_fork(child, 16) { |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 363 | /* recreate process local variables */ |
| 364 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 365 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 366 | batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); |
| 367 | for (int i = 0; i < num_buffers; i++) { |
| 368 | src[i] = mode->create_bo(bufmgr, i, width, height); |
| 369 | dst[i] = mode->create_bo(bufmgr, ~i, width, height); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 370 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 371 | dummy = mode->create_bo(bufmgr, 0, width, height); |
| 372 | for (int loop = 0; loop < 10; loop++) |
| 373 | do_test_func(mode, src, dst, dummy); |
| 374 | /* as we borrow the fd, we need to reap our bo */ |
| 375 | for (int i = 0; i < num_buffers; i++) { |
| 376 | drm_intel_bo_unreference(src[i]); |
| 377 | drm_intel_bo_unreference(dst[i]); |
| 378 | } |
| 379 | drm_intel_bo_unreference(dummy); |
| 380 | intel_batchbuffer_free(batch); |
| 381 | drm_intel_bufmgr_destroy(bufmgr); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 382 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 383 | |
| 384 | igt_waitchildren(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 385 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 386 | num_buffers = old_num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 387 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 388 | |
| 389 | static void |
| 390 | run_basic_modes(struct access_mode *mode, |
| 391 | drm_intel_bo **src, drm_intel_bo **dst, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 392 | drm_intel_bo *dummy, const char *suffix, |
| 393 | run_wrap run_wrap_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 394 | { |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 395 | /* try to overwrite the source values */ |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 396 | igt_subtest_f("%s-overwrite-source%s", mode->name, suffix) |
| 397 | run_wrap_func(mode, src, dst, dummy, do_overwrite_source); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 398 | |
| 399 | /* try to read the results before the copy completes */ |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 400 | igt_subtest_f("%s-early-read%s", mode->name, suffix) |
| 401 | run_wrap_func(mode, src, dst, dummy, do_early_read); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 402 | |
| 403 | /* and finally try to trick the kernel into loosing the pending write */ |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 404 | igt_subtest_f("%s-gpu-read-after-write%s", mode->name, suffix) |
| 405 | run_wrap_func(mode, src, dst, dummy, do_gpu_read_after_write); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 406 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 407 | |
| 408 | static void |
| 409 | run_modes(struct access_mode *mode) |
| 410 | { |
Daniel Vetter | ad0f081 | 2013-08-26 20:41:00 +0200 | [diff] [blame] | 411 | drm_intel_bo *src[MAX_NUM_BUFFERS], *dst[MAX_NUM_BUFFERS], *dummy = NULL; |
| 412 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 413 | igt_fixture { |
Chris Wilson | 0d320fd | 2013-08-16 12:07:56 +0100 | [diff] [blame] | 414 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 415 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 416 | batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); |
| 417 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 418 | for (int i = 0; i < num_buffers; i++) { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 419 | src[i] = mode->create_bo(bufmgr, i, width, height); |
| 420 | dst[i] = mode->create_bo(bufmgr, ~i, width, height); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 421 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 422 | dummy = mode->create_bo(bufmgr, 0, width, height); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 423 | } |
| 424 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 425 | run_basic_modes(mode, src, dst, dummy, "", run_single); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 426 | |
| 427 | igt_fork_signal_helper(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 428 | run_basic_modes(mode, src, dst, dummy, "-interruptible", run_interruptible); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 429 | igt_stop_signal_helper(); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 430 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 431 | igt_fixture { |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 432 | for (int i = 0; i < num_buffers; i++) { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 433 | drm_intel_bo_unreference(src[i]); |
| 434 | drm_intel_bo_unreference(dst[i]); |
| 435 | } |
| 436 | drm_intel_bo_unreference(dummy); |
Chris Wilson | 0d320fd | 2013-08-16 12:07:56 +0100 | [diff] [blame] | 437 | intel_batchbuffer_free(batch); |
| 438 | drm_intel_bufmgr_destroy(bufmgr); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 439 | } |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 440 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 441 | igt_fork_signal_helper(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 442 | run_basic_modes(mode, src, dst, dummy, "-forked", run_forked); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 443 | igt_stop_signal_helper(); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 446 | igt_main |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 447 | { |
| 448 | int max, i; |
| 449 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 450 | igt_skip_on_simulation(); |
| 451 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 452 | igt_fixture { |
| 453 | fd = drm_open_any(); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame^] | 454 | devid = intel_get_drm_devid(fd); |
| 455 | gen = intel_gen(devid); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 456 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 457 | max = gem_aperture_size (fd) / (1024 * 1024) / 2; |
| 458 | if (num_buffers > max) |
| 459 | num_buffers = max; |
Daniel Vetter | aee0dcb | 2013-12-03 16:32:52 +0100 | [diff] [blame] | 460 | |
| 461 | max = intel_get_total_ram_mb() * 3 / 4; |
| 462 | if (num_buffers > max) |
| 463 | num_buffers = max; |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 464 | num_buffers /= 2; |
Daniel Vetter | e624fa8 | 2014-05-14 00:36:04 +0200 | [diff] [blame] | 465 | igt_info("using 2x%d buffers, each 1MiB\n", num_buffers); |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 466 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 467 | |
| 468 | for (i = 0; i < ARRAY_SIZE(access_modes); i++) |
| 469 | run_modes(&access_modes[i]); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 470 | } |