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 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 30 | /** @file gem_concurrent.c |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 31 | * |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 32 | * This is a test of pread/pwrite/mmap behavior when writing to active |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 33 | * buffers. |
| 34 | * |
| 35 | * Based on gem_gtt_concurrent_blt. |
| 36 | */ |
| 37 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 38 | #include "igt.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 39 | #include <stdlib.h> |
| 40 | #include <stdio.h> |
| 41 | #include <string.h> |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 42 | #include <fcntl.h> |
| 43 | #include <inttypes.h> |
| 44 | #include <errno.h> |
| 45 | #include <sys/stat.h> |
| 46 | #include <sys/time.h> |
Chris Wilson | 99431a4 | 2013-08-14 11:03:34 +0100 | [diff] [blame] | 47 | #include <sys/wait.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 48 | |
| 49 | #include <drm.h> |
| 50 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 51 | #include "intel_bufmgr.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 52 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 53 | IGT_TEST_DESCRIPTION("Test of pread/pwrite/mmap behavior when writing to active" |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 54 | " buffers."); |
| 55 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 56 | int fd, devid, gen; |
| 57 | struct intel_batchbuffer *batch; |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 58 | int all; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 59 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 60 | static void |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 61 | nop_release_bo(drm_intel_bo *bo) |
| 62 | { |
| 63 | drm_intel_bo_unreference(bo); |
| 64 | } |
| 65 | |
| 66 | static void |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 67 | 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] | 68 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 69 | int size = width * height, i; |
| 70 | uint32_t *tmp; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 71 | |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 72 | tmp = malloc(4*size); |
| 73 | if (tmp) { |
| 74 | for (i = 0; i < size; i++) |
| 75 | tmp[i] = val; |
| 76 | drm_intel_bo_subdata(bo, 0, 4*size, tmp); |
| 77 | free(tmp); |
| 78 | } else { |
| 79 | for (i = 0; i < size; i++) |
| 80 | drm_intel_bo_subdata(bo, 4*i, 4, &val); |
| 81 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 85 | prw_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 86 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 87 | int size = width * height, i; |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 88 | uint32_t *vaddr; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 89 | |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 90 | do_or_die(drm_intel_bo_map(tmp, true)); |
| 91 | do_or_die(drm_intel_bo_get_subdata(bo, 0, 4*size, tmp->virtual)); |
| 92 | vaddr = tmp->virtual; |
| 93 | for (i = 0; i < size; i++) |
| 94 | igt_assert_eq_u32(vaddr[i], val); |
| 95 | drm_intel_bo_unmap(tmp); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 99 | unmapped_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 100 | { |
| 101 | drm_intel_bo *bo; |
| 102 | |
| 103 | bo = drm_intel_bo_alloc(bufmgr, "bo", 4*width*height, 0); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 104 | igt_assert(bo); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 105 | |
| 106 | return bo; |
| 107 | } |
| 108 | |
Chris Wilson | 46ec33e | 2015-10-20 14:40:50 +0100 | [diff] [blame] | 109 | static drm_intel_bo * |
| 110 | snoop_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 111 | { |
| 112 | drm_intel_bo *bo; |
| 113 | |
| 114 | igt_skip_on(gem_has_llc(fd)); |
| 115 | |
| 116 | bo = unmapped_create_bo(bufmgr, width, height); |
| 117 | gem_set_caching(fd, bo->handle, I915_CACHING_CACHED); |
| 118 | drm_intel_bo_disable_reuse(bo); |
| 119 | |
| 120 | return bo; |
| 121 | } |
| 122 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 123 | static void |
| 124 | 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] | 125 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 126 | uint32_t *vaddr = bo->virtual; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 127 | int size = width * height; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 128 | |
| 129 | drm_intel_gem_bo_start_gtt_access(bo, true); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 130 | while (size--) |
| 131 | *vaddr++ = val; |
| 132 | } |
| 133 | |
| 134 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 135 | gtt_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 136 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 137 | uint32_t *vaddr = bo->virtual; |
| 138 | int y; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 139 | |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 140 | /* GTT access is slow. So we just compare a few points */ |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 141 | drm_intel_gem_bo_start_gtt_access(bo, false); |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 142 | for (y = 0; y < height; y++) |
| 143 | igt_assert_eq_u32(vaddr[y*width+y], val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 147 | map_bo(drm_intel_bo *bo) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 148 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 149 | /* gtt map doesn't have a write parameter, so just keep the mapping |
| 150 | * around (to avoid the set_domain with the gtt write domain set) and |
| 151 | * manually tell the kernel when we start access the gtt. */ |
| 152 | do_or_die(drm_intel_gem_bo_map_gtt(bo)); |
| 153 | |
| 154 | return bo; |
| 155 | } |
| 156 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 157 | static drm_intel_bo * |
| 158 | tile_bo(drm_intel_bo *bo, int width) |
| 159 | { |
| 160 | uint32_t tiling = I915_TILING_X; |
| 161 | uint32_t stride = width * 4; |
| 162 | |
| 163 | do_or_die(drm_intel_bo_set_tiling(bo, &tiling, stride)); |
| 164 | |
| 165 | return bo; |
| 166 | } |
| 167 | |
| 168 | static drm_intel_bo * |
| 169 | gtt_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 170 | { |
| 171 | return map_bo(unmapped_create_bo(bufmgr, width, height)); |
| 172 | } |
| 173 | |
| 174 | static drm_intel_bo * |
| 175 | gttX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 176 | { |
| 177 | return tile_bo(gtt_create_bo(bufmgr, width, height), width); |
| 178 | } |
| 179 | |
| 180 | static drm_intel_bo * |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 181 | wc_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 182 | { |
| 183 | drm_intel_bo *bo; |
| 184 | |
Daniel Vetter | a3e34ce | 2015-02-06 11:05:28 +0100 | [diff] [blame] | 185 | gem_require_mmap_wc(fd); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 186 | |
| 187 | bo = unmapped_create_bo(bufmgr, width, height); |
Ville Syrjälä | b8a77dd | 2015-10-09 18:29:28 +0300 | [diff] [blame] | 188 | bo->virtual = __gem_mmap__wc(fd, bo->handle, 0, bo->size, PROT_READ | PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 189 | return bo; |
| 190 | } |
| 191 | |
| 192 | static void |
| 193 | wc_release_bo(drm_intel_bo *bo) |
| 194 | { |
| 195 | munmap(bo->virtual, bo->size); |
| 196 | bo->virtual = NULL; |
| 197 | |
| 198 | nop_release_bo(bo); |
| 199 | } |
| 200 | |
| 201 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 202 | gpu_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 203 | { |
| 204 | return unmapped_create_bo(bufmgr, width, height); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | static drm_intel_bo * |
| 209 | gpuX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 210 | { |
| 211 | return tile_bo(gpu_create_bo(bufmgr, width, height), width); |
| 212 | } |
| 213 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 214 | static void |
| 215 | cpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 216 | { |
| 217 | int size = width * height; |
| 218 | uint32_t *vaddr; |
| 219 | |
| 220 | do_or_die(drm_intel_bo_map(bo, true)); |
| 221 | vaddr = bo->virtual; |
| 222 | while (size--) |
| 223 | *vaddr++ = val; |
| 224 | drm_intel_bo_unmap(bo); |
| 225 | } |
| 226 | |
| 227 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 228 | cpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 229 | { |
| 230 | int size = width * height; |
| 231 | uint32_t *vaddr; |
| 232 | |
| 233 | do_or_die(drm_intel_bo_map(bo, false)); |
| 234 | vaddr = bo->virtual; |
| 235 | while (size--) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 236 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 237 | drm_intel_bo_unmap(bo); |
| 238 | } |
| 239 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 240 | static void |
| 241 | gpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 242 | { |
| 243 | struct drm_i915_gem_relocation_entry reloc[1]; |
| 244 | struct drm_i915_gem_exec_object2 gem_exec[2]; |
| 245 | struct drm_i915_gem_execbuffer2 execbuf; |
| 246 | struct drm_i915_gem_pwrite gem_pwrite; |
| 247 | struct drm_i915_gem_create create; |
| 248 | uint32_t buf[10], *b; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 249 | uint32_t tiling, swizzle; |
| 250 | |
| 251 | drm_intel_bo_get_tiling(bo, &tiling, &swizzle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 252 | |
| 253 | memset(reloc, 0, sizeof(reloc)); |
| 254 | memset(gem_exec, 0, sizeof(gem_exec)); |
| 255 | memset(&execbuf, 0, sizeof(execbuf)); |
| 256 | |
| 257 | b = buf; |
| 258 | *b++ = XY_COLOR_BLT_CMD_NOLEN | |
| 259 | ((gen >= 8) ? 5 : 4) | |
| 260 | COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 261 | if (gen >= 4 && tiling) { |
| 262 | b[-1] |= XY_COLOR_BLT_TILED; |
| 263 | *b = width; |
| 264 | } else |
| 265 | *b = width << 2; |
| 266 | *b++ |= 0xf0 << 16 | 1 << 25 | 1 << 24; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 267 | *b++ = 0; |
| 268 | *b++ = height << 16 | width; |
| 269 | reloc[0].offset = (b - buf) * sizeof(uint32_t); |
| 270 | reloc[0].target_handle = bo->handle; |
| 271 | reloc[0].read_domains = I915_GEM_DOMAIN_RENDER; |
| 272 | reloc[0].write_domain = I915_GEM_DOMAIN_RENDER; |
| 273 | *b++ = 0; |
| 274 | if (gen >= 8) |
| 275 | *b++ = 0; |
| 276 | *b++ = val; |
| 277 | *b++ = MI_BATCH_BUFFER_END; |
| 278 | if ((b - buf) & 1) |
| 279 | *b++ = 0; |
| 280 | |
| 281 | gem_exec[0].handle = bo->handle; |
| 282 | gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE; |
| 283 | |
| 284 | create.handle = 0; |
| 285 | create.size = 4096; |
| 286 | drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); |
| 287 | gem_exec[1].handle = create.handle; |
| 288 | gem_exec[1].relocation_count = 1; |
| 289 | gem_exec[1].relocs_ptr = (uintptr_t)reloc; |
| 290 | |
| 291 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 292 | execbuf.buffer_count = 2; |
| 293 | execbuf.batch_len = (b - buf) * sizeof(buf[0]); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 294 | if (gen >= 6) |
| 295 | execbuf.flags = I915_EXEC_BLT; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 296 | |
| 297 | gem_pwrite.handle = gem_exec[1].handle; |
| 298 | gem_pwrite.offset = 0; |
| 299 | gem_pwrite.size = execbuf.batch_len; |
| 300 | gem_pwrite.data_ptr = (uintptr_t)buf; |
Daniel Stone | de7ccdd | 2015-10-01 14:16:48 +0100 | [diff] [blame] | 301 | do_ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite); |
| 302 | do_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 303 | |
| 304 | drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &create.handle); |
| 305 | } |
| 306 | |
| 307 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 308 | gpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 309 | { |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 310 | intel_blt_copy(batch, |
| 311 | bo, 0, 0, 4*width, |
| 312 | tmp, 0, 0, 4*width, |
| 313 | width, height, 32); |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 314 | cpu_cmp_bo(tmp, val, width, height, NULL); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 317 | const struct access_mode { |
| 318 | const char *name; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 319 | void (*set_bo)(drm_intel_bo *bo, uint32_t val, int w, int h); |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 320 | void (*cmp_bo)(drm_intel_bo *bo, uint32_t val, int w, int h, drm_intel_bo *tmp); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 321 | drm_intel_bo *(*create_bo)(drm_intel_bufmgr *bufmgr, int width, int height); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 322 | void (*release_bo)(drm_intel_bo *bo); |
| 323 | } access_modes[] = { |
| 324 | { |
| 325 | .name = "prw", |
| 326 | .set_bo = prw_set_bo, |
| 327 | .cmp_bo = prw_cmp_bo, |
| 328 | .create_bo = unmapped_create_bo, |
| 329 | .release_bo = nop_release_bo, |
| 330 | }, |
| 331 | { |
| 332 | .name = "cpu", |
| 333 | .set_bo = cpu_set_bo, |
| 334 | .cmp_bo = cpu_cmp_bo, |
| 335 | .create_bo = unmapped_create_bo, |
| 336 | .release_bo = nop_release_bo, |
| 337 | }, |
| 338 | { |
Chris Wilson | 46ec33e | 2015-10-20 14:40:50 +0100 | [diff] [blame] | 339 | .name = "snoop", |
| 340 | .set_bo = cpu_set_bo, |
| 341 | .cmp_bo = cpu_cmp_bo, |
| 342 | .create_bo = snoop_create_bo, |
| 343 | .release_bo = nop_release_bo, |
| 344 | }, |
| 345 | { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 346 | .name = "gtt", |
| 347 | .set_bo = gtt_set_bo, |
| 348 | .cmp_bo = gtt_cmp_bo, |
| 349 | .create_bo = gtt_create_bo, |
| 350 | .release_bo = nop_release_bo, |
| 351 | }, |
| 352 | { |
| 353 | .name = "gttX", |
| 354 | .set_bo = gtt_set_bo, |
| 355 | .cmp_bo = gtt_cmp_bo, |
| 356 | .create_bo = gttX_create_bo, |
| 357 | .release_bo = nop_release_bo, |
| 358 | }, |
| 359 | { |
| 360 | .name = "wc", |
| 361 | .set_bo = gtt_set_bo, |
| 362 | .cmp_bo = gtt_cmp_bo, |
| 363 | .create_bo = wc_create_bo, |
| 364 | .release_bo = wc_release_bo, |
| 365 | }, |
| 366 | { |
| 367 | .name = "gpu", |
| 368 | .set_bo = gpu_set_bo, |
| 369 | .cmp_bo = gpu_cmp_bo, |
| 370 | .create_bo = gpu_create_bo, |
| 371 | .release_bo = nop_release_bo, |
| 372 | }, |
| 373 | { |
| 374 | .name = "gpuX", |
| 375 | .set_bo = gpu_set_bo, |
| 376 | .cmp_bo = gpu_cmp_bo, |
| 377 | .create_bo = gpuX_create_bo, |
| 378 | .release_bo = nop_release_bo, |
| 379 | }, |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 380 | }; |
| 381 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 382 | int num_buffers; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 383 | const int width = 512, height = 512; |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 384 | igt_render_copyfunc_t rendercopy; |
| 385 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 386 | struct buffers { |
| 387 | const struct access_mode *mode; |
| 388 | drm_intel_bufmgr *bufmgr; |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 389 | drm_intel_bo **src, **dst; |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 390 | drm_intel_bo *dummy, *spare; |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 391 | int count; |
| 392 | }; |
| 393 | |
| 394 | static void *buffers_init(struct buffers *data, |
| 395 | const struct access_mode *mode, |
| 396 | int _fd) |
| 397 | { |
| 398 | data->mode = mode; |
| 399 | data->count = 0; |
| 400 | |
| 401 | data->bufmgr = drm_intel_bufmgr_gem_init(_fd, 4096); |
| 402 | igt_assert(data->bufmgr); |
| 403 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 404 | data->src = malloc(2*sizeof(drm_intel_bo *)*num_buffers); |
| 405 | igt_assert(data->src); |
| 406 | data->dst = data->src + num_buffers; |
| 407 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 408 | drm_intel_bufmgr_gem_enable_reuse(data->bufmgr); |
| 409 | return intel_batchbuffer_alloc(data->bufmgr, devid); |
| 410 | } |
| 411 | |
| 412 | static void buffers_destroy(struct buffers *data) |
| 413 | { |
| 414 | if (data->count == 0) |
| 415 | return; |
| 416 | |
| 417 | for (int i = 0; i < data->count; i++) { |
| 418 | data->mode->release_bo(data->src[i]); |
| 419 | data->mode->release_bo(data->dst[i]); |
| 420 | } |
| 421 | data->mode->release_bo(data->dummy); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 422 | data->mode->release_bo(data->spare); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 423 | data->count = 0; |
| 424 | } |
| 425 | |
| 426 | static void buffers_create(struct buffers *data, |
| 427 | int count) |
| 428 | { |
| 429 | igt_assert(data->bufmgr); |
| 430 | |
| 431 | buffers_destroy(data); |
| 432 | |
| 433 | for (int i = 0; i < count; i++) { |
| 434 | data->src[i] = |
| 435 | data->mode->create_bo(data->bufmgr, width, height); |
| 436 | data->dst[i] = |
| 437 | data->mode->create_bo(data->bufmgr, width, height); |
| 438 | } |
| 439 | data->dummy = data->mode->create_bo(data->bufmgr, width, height); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 440 | data->spare = data->mode->create_bo(data->bufmgr, width, height); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 441 | data->count = count; |
| 442 | } |
| 443 | |
| 444 | static void buffers_fini(struct buffers *data) |
| 445 | { |
| 446 | if (data->bufmgr == NULL) |
| 447 | return; |
| 448 | |
| 449 | buffers_destroy(data); |
| 450 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 451 | free(data->src); |
| 452 | data->src = NULL; |
| 453 | data->dst = NULL; |
| 454 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 455 | intel_batchbuffer_free(batch); |
| 456 | drm_intel_bufmgr_destroy(data->bufmgr); |
| 457 | data->bufmgr = NULL; |
| 458 | } |
| 459 | |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 460 | typedef void (*do_copy)(drm_intel_bo *dst, drm_intel_bo *src); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 461 | typedef struct igt_hang_ring (*do_hang)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 462 | |
| 463 | static void render_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 464 | { |
| 465 | struct igt_buf d = { |
| 466 | .bo = dst, |
| 467 | .size = width * height * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 468 | .num_tiles = width * height * 4, |
| 469 | .stride = width * 4, |
| 470 | }, s = { |
| 471 | .bo = src, |
| 472 | .size = width * height * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 473 | .num_tiles = width * height * 4, |
| 474 | .stride = width * 4, |
| 475 | }; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 476 | uint32_t swizzle; |
| 477 | |
| 478 | drm_intel_bo_get_tiling(dst, &d.tiling, &swizzle); |
| 479 | drm_intel_bo_get_tiling(src, &s.tiling, &swizzle); |
| 480 | |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 481 | rendercopy(batch, NULL, |
| 482 | &s, 0, 0, |
| 483 | width, height, |
| 484 | &d, 0, 0); |
| 485 | } |
| 486 | |
| 487 | static void blt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 488 | { |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 489 | intel_blt_copy(batch, |
| 490 | src, 0, 0, 4*width, |
| 491 | dst, 0, 0, 4*width, |
| 492 | width, height, 32); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 493 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 494 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 495 | static void cpu_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 496 | { |
| 497 | const int size = width * height * sizeof(uint32_t); |
| 498 | void *d, *s; |
| 499 | |
| 500 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0); |
| 501 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 502 | s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ); |
| 503 | d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 504 | |
| 505 | memcpy(d, s, size); |
| 506 | |
| 507 | munmap(d, size); |
| 508 | munmap(s, size); |
| 509 | } |
| 510 | |
| 511 | static void gtt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 512 | { |
| 513 | const int size = width * height * sizeof(uint32_t); |
| 514 | void *d, *s; |
| 515 | |
| 516 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 517 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 518 | |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 519 | s = gem_mmap__gtt(fd, src->handle, size, PROT_READ); |
| 520 | d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 521 | |
| 522 | memcpy(d, s, size); |
| 523 | |
| 524 | munmap(d, size); |
| 525 | munmap(s, size); |
| 526 | } |
| 527 | |
| 528 | static void wc_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 529 | { |
| 530 | const int size = width * height * sizeof(uint32_t); |
| 531 | void *d, *s; |
| 532 | |
| 533 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 534 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 535 | |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 536 | s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ); |
| 537 | d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 538 | |
| 539 | memcpy(d, s, size); |
| 540 | |
| 541 | munmap(d, size); |
| 542 | munmap(s, size); |
| 543 | } |
| 544 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 545 | static struct igt_hang_ring no_hang(void) |
| 546 | { |
| 547 | return (struct igt_hang_ring){0, 0}; |
| 548 | } |
| 549 | |
| 550 | static struct igt_hang_ring bcs_hang(void) |
| 551 | { |
Daniel Vetter | 3cd45de | 2015-02-10 17:46:43 +0100 | [diff] [blame] | 552 | return igt_hang_ring(fd, I915_EXEC_BLT); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static struct igt_hang_ring rcs_hang(void) |
| 556 | { |
Daniel Vetter | 3cd45de | 2015-02-10 17:46:43 +0100 | [diff] [blame] | 557 | return igt_hang_ring(fd, I915_EXEC_RENDER); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static void hang_require(void) |
| 561 | { |
Daniel Vetter | c66b242 | 2015-02-06 10:49:20 +0100 | [diff] [blame] | 562 | igt_require_hang_ring(fd, -1); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 565 | static void check_gpu(void) |
| 566 | { |
| 567 | unsigned missed_irq = 0; |
| 568 | FILE *file; |
| 569 | |
| 570 | gem_quiescent_gpu(fd); |
| 571 | |
| 572 | file = igt_debugfs_fopen("i915_ring_missed_irq", "r"); |
| 573 | if (file) { |
| 574 | fscanf(file, "%x", &missed_irq); |
| 575 | fclose(file); |
| 576 | } |
| 577 | file = igt_debugfs_fopen("i915_ring_missed_irq", "w"); |
| 578 | if (file) { |
| 579 | fwrite("0\n", 1, 2, file); |
| 580 | fclose(file); |
| 581 | } |
| 582 | igt_assert_eq(missed_irq, 0); |
| 583 | } |
| 584 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame^] | 585 | static void do_basic0(struct buffers *buffers, |
| 586 | do_copy do_copy_func, |
| 587 | do_hang do_hang_func) |
| 588 | { |
| 589 | gem_quiescent_gpu(fd); |
| 590 | |
| 591 | buffers->mode->set_bo(buffers->src[0], 0xdeadbeef, width, height); |
| 592 | for (int i = 0; i < buffers->count; i++) { |
| 593 | struct igt_hang_ring hang = do_hang_func(); |
| 594 | |
| 595 | do_copy_func(buffers->dst[i], buffers->src[0]); |
| 596 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef, width, height, buffers->dummy); |
| 597 | |
| 598 | igt_post_hang_ring(fd, hang); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | static void do_basic1(struct buffers *buffers, |
| 603 | do_copy do_copy_func, |
| 604 | do_hang do_hang_func) |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 605 | { |
| 606 | gem_quiescent_gpu(fd); |
| 607 | |
| 608 | for (int i = 0; i < buffers->count; i++) { |
| 609 | struct igt_hang_ring hang = do_hang_func(); |
| 610 | |
| 611 | buffers->mode->set_bo(buffers->src[i], i, width, height); |
| 612 | buffers->mode->set_bo(buffers->dst[i], ~i, width, height); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame^] | 613 | |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 614 | do_copy_func(buffers->dst[i], buffers->src[i]); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame^] | 615 | usleep(0); /* let someone else claim the mutex */ |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 616 | buffers->mode->cmp_bo(buffers->dst[i], i, width, height, buffers->dummy); |
| 617 | |
| 618 | igt_post_hang_ring(fd, hang); |
| 619 | } |
| 620 | } |
| 621 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame^] | 622 | static void do_basicN(struct buffers *buffers, |
| 623 | do_copy do_copy_func, |
| 624 | do_hang do_hang_func) |
| 625 | { |
| 626 | struct igt_hang_ring hang; |
| 627 | |
| 628 | gem_quiescent_gpu(fd); |
| 629 | |
| 630 | for (int i = 0; i < buffers->count; i++) { |
| 631 | buffers->mode->set_bo(buffers->src[i], i, width, height); |
| 632 | buffers->mode->set_bo(buffers->dst[i], ~i, width, height); |
| 633 | } |
| 634 | |
| 635 | hang = do_hang_func(); |
| 636 | |
| 637 | for (int i = 0; i < buffers->count; i++) { |
| 638 | do_copy_func(buffers->dst[i], buffers->src[i]); |
| 639 | usleep(0); /* let someone else claim the mutex */ |
| 640 | } |
| 641 | |
| 642 | for (int i = 0; i < buffers->count; i++) |
| 643 | buffers->mode->cmp_bo(buffers->dst[i], i, width, height, buffers->dummy); |
| 644 | |
| 645 | igt_post_hang_ring(fd, hang); |
| 646 | } |
| 647 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 648 | static void do_overwrite_source(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 649 | do_copy do_copy_func, |
| 650 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 651 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 652 | struct igt_hang_ring hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 653 | int i; |
| 654 | |
| 655 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 656 | for (i = 0; i < buffers->count; i++) { |
| 657 | buffers->mode->set_bo(buffers->src[i], i, width, height); |
| 658 | buffers->mode->set_bo(buffers->dst[i], ~i, width, height); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 659 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 660 | for (i = 0; i < buffers->count; i++) |
| 661 | do_copy_func(buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 662 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 663 | for (i = buffers->count; i--; ) |
| 664 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef, width, height); |
| 665 | for (i = 0; i < buffers->count; i++) |
| 666 | buffers->mode->cmp_bo(buffers->dst[i], i, width, height, buffers->dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 667 | igt_post_hang_ring(fd, hang); |
| 668 | } |
| 669 | |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 670 | static void do_overwrite_source_read(struct buffers *buffers, |
| 671 | do_copy do_copy_func, |
| 672 | do_hang do_hang_func, |
| 673 | int do_rcs) |
| 674 | { |
| 675 | const int half = buffers->count/2; |
| 676 | struct igt_hang_ring hang; |
| 677 | int i; |
| 678 | |
| 679 | gem_quiescent_gpu(fd); |
| 680 | for (i = 0; i < half; i++) { |
| 681 | buffers->mode->set_bo(buffers->src[i], i, width, height); |
| 682 | buffers->mode->set_bo(buffers->dst[i], ~i, width, height); |
| 683 | buffers->mode->set_bo(buffers->dst[i+half], ~i, width, height); |
| 684 | } |
| 685 | for (i = 0; i < half; i++) { |
| 686 | do_copy_func(buffers->dst[i], buffers->src[i]); |
| 687 | if (do_rcs) |
| 688 | render_copy_bo(buffers->dst[i+half], buffers->src[i]); |
| 689 | else |
| 690 | blt_copy_bo(buffers->dst[i+half], buffers->src[i]); |
| 691 | } |
| 692 | hang = do_hang_func(); |
| 693 | for (i = half; i--; ) |
| 694 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef, width, height); |
| 695 | for (i = 0; i < half; i++) { |
| 696 | buffers->mode->cmp_bo(buffers->dst[i], i, width, height, buffers->dummy); |
| 697 | buffers->mode->cmp_bo(buffers->dst[i+half], i, width, height, buffers->dummy); |
| 698 | } |
| 699 | igt_post_hang_ring(fd, hang); |
| 700 | } |
| 701 | |
| 702 | static void do_overwrite_source_read_bcs(struct buffers *buffers, |
| 703 | do_copy do_copy_func, |
| 704 | do_hang do_hang_func) |
| 705 | { |
| 706 | do_overwrite_source_read(buffers, do_copy_func, do_hang_func, 0); |
| 707 | } |
| 708 | |
| 709 | static void do_overwrite_source_read_rcs(struct buffers *buffers, |
| 710 | do_copy do_copy_func, |
| 711 | do_hang do_hang_func) |
| 712 | { |
| 713 | do_overwrite_source_read(buffers, do_copy_func, do_hang_func, 1); |
| 714 | } |
| 715 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 716 | static void do_overwrite_source__rev(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 717 | do_copy do_copy_func, |
| 718 | do_hang do_hang_func) |
| 719 | { |
| 720 | struct igt_hang_ring hang; |
| 721 | int i; |
| 722 | |
| 723 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 724 | for (i = 0; i < buffers->count; i++) { |
| 725 | buffers->mode->set_bo(buffers->src[i], i, width, height); |
| 726 | buffers->mode->set_bo(buffers->dst[i], ~i, width, height); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 727 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 728 | for (i = 0; i < buffers->count; i++) |
| 729 | do_copy_func(buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 730 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 731 | for (i = 0; i < buffers->count; i++) |
| 732 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef, width, height); |
| 733 | for (i = buffers->count; i--; ) |
| 734 | buffers->mode->cmp_bo(buffers->dst[i], i, width, height, buffers->dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 735 | igt_post_hang_ring(fd, hang); |
| 736 | } |
| 737 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 738 | static void do_overwrite_source__one(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 739 | do_copy do_copy_func, |
| 740 | do_hang do_hang_func) |
| 741 | { |
| 742 | struct igt_hang_ring hang; |
| 743 | |
| 744 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 745 | buffers->mode->set_bo(buffers->src[0], 0, width, height); |
| 746 | buffers->mode->set_bo(buffers->dst[0], ~0, width, height); |
| 747 | do_copy_func(buffers->dst[0], buffers->src[0]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 748 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 749 | buffers->mode->set_bo(buffers->src[0], 0xdeadbeef, width, height); |
| 750 | buffers->mode->cmp_bo(buffers->dst[0], 0, width, height, buffers->dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 751 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 752 | } |
| 753 | |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 754 | static void do_intermix(struct buffers *buffers, |
| 755 | do_copy do_copy_func, |
| 756 | do_hang do_hang_func, |
| 757 | int do_rcs) |
| 758 | { |
| 759 | const int half = buffers->count/2; |
| 760 | struct igt_hang_ring hang; |
| 761 | int i; |
| 762 | |
| 763 | gem_quiescent_gpu(fd); |
| 764 | for (i = 0; i < buffers->count; i++) { |
| 765 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef^~i, width, height); |
| 766 | buffers->mode->set_bo(buffers->dst[i], i, width, height); |
| 767 | } |
| 768 | for (i = 0; i < half; i++) { |
| 769 | if (do_rcs == 1 || (do_rcs == -1 && i & 1)) |
| 770 | render_copy_bo(buffers->dst[i], buffers->src[i]); |
| 771 | else |
| 772 | blt_copy_bo(buffers->dst[i], buffers->src[i]); |
| 773 | |
| 774 | do_copy_func(buffers->dst[i+half], buffers->src[i]); |
| 775 | |
| 776 | if (do_rcs == 1 || (do_rcs == -1 && (i & 1) == 0)) |
| 777 | render_copy_bo(buffers->dst[i], buffers->dst[i+half]); |
| 778 | else |
| 779 | blt_copy_bo(buffers->dst[i], buffers->dst[i+half]); |
| 780 | |
| 781 | do_copy_func(buffers->dst[i+half], buffers->src[i+half]); |
| 782 | } |
| 783 | hang = do_hang_func(); |
| 784 | for (i = 0; i < 2*half; i++) |
| 785 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef^~i, width, height, buffers->dummy); |
| 786 | igt_post_hang_ring(fd, hang); |
| 787 | } |
| 788 | |
| 789 | static void do_intermix_rcs(struct buffers *buffers, |
| 790 | do_copy do_copy_func, |
| 791 | do_hang do_hang_func) |
| 792 | { |
| 793 | do_intermix(buffers, do_copy_func, do_hang_func, 1); |
| 794 | } |
| 795 | |
| 796 | static void do_intermix_bcs(struct buffers *buffers, |
| 797 | do_copy do_copy_func, |
| 798 | do_hang do_hang_func) |
| 799 | { |
| 800 | do_intermix(buffers, do_copy_func, do_hang_func, 0); |
| 801 | } |
| 802 | |
| 803 | static void do_intermix_both(struct buffers *buffers, |
| 804 | do_copy do_copy_func, |
| 805 | do_hang do_hang_func) |
| 806 | { |
| 807 | do_intermix(buffers, do_copy_func, do_hang_func, -1); |
| 808 | } |
| 809 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 810 | static void do_early_read(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 811 | do_copy do_copy_func, |
| 812 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 813 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 814 | struct igt_hang_ring hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 815 | int i; |
| 816 | |
| 817 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 818 | for (i = buffers->count; i--; ) |
| 819 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef, width, height); |
| 820 | for (i = 0; i < buffers->count; i++) |
| 821 | do_copy_func(buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 822 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 823 | for (i = buffers->count; i--; ) |
| 824 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef, width, height, buffers->dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 825 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 826 | } |
| 827 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 828 | static void do_read_read_bcs(struct buffers *buffers, |
| 829 | do_copy do_copy_func, |
| 830 | do_hang do_hang_func) |
| 831 | { |
| 832 | struct igt_hang_ring hang; |
| 833 | int i; |
| 834 | |
| 835 | gem_quiescent_gpu(fd); |
| 836 | for (i = buffers->count; i--; ) |
| 837 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef ^ i, width, height); |
| 838 | for (i = 0; i < buffers->count; i++) { |
| 839 | do_copy_func(buffers->dst[i], buffers->src[i]); |
| 840 | blt_copy_bo(buffers->spare, buffers->src[i]); |
| 841 | } |
| 842 | cpu_cmp_bo(buffers->spare, 0xdeadbeef^(buffers->count-1), width, height, NULL); |
| 843 | hang = do_hang_func(); |
| 844 | for (i = buffers->count; i--; ) |
| 845 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef ^ i, width, height, buffers->dummy); |
| 846 | igt_post_hang_ring(fd, hang); |
| 847 | } |
| 848 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 849 | static void do_write_read_bcs(struct buffers *buffers, |
| 850 | do_copy do_copy_func, |
| 851 | do_hang do_hang_func) |
| 852 | { |
| 853 | struct igt_hang_ring hang; |
| 854 | int i; |
| 855 | |
| 856 | gem_quiescent_gpu(fd); |
| 857 | for (i = buffers->count; i--; ) |
| 858 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef ^ i, width, height); |
| 859 | for (i = 0; i < buffers->count; i++) { |
| 860 | blt_copy_bo(buffers->spare, buffers->src[i]); |
| 861 | do_copy_func(buffers->dst[i], buffers->spare); |
| 862 | } |
| 863 | hang = do_hang_func(); |
| 864 | for (i = buffers->count; i--; ) |
| 865 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef ^ i, width, height, buffers->dummy); |
| 866 | igt_post_hang_ring(fd, hang); |
| 867 | } |
| 868 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 869 | static void do_read_read_rcs(struct buffers *buffers, |
| 870 | do_copy do_copy_func, |
| 871 | do_hang do_hang_func) |
| 872 | { |
| 873 | struct igt_hang_ring hang; |
| 874 | int i; |
| 875 | |
| 876 | gem_quiescent_gpu(fd); |
| 877 | for (i = buffers->count; i--; ) |
| 878 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef ^ i, width, height); |
| 879 | for (i = 0; i < buffers->count; i++) { |
| 880 | do_copy_func(buffers->dst[i], buffers->src[i]); |
| 881 | render_copy_bo(buffers->spare, buffers->src[i]); |
| 882 | } |
| 883 | cpu_cmp_bo(buffers->spare, 0xdeadbeef^(buffers->count-1), width, height, NULL); |
| 884 | hang = do_hang_func(); |
| 885 | for (i = buffers->count; i--; ) |
| 886 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef ^ i, width, height, buffers->dummy); |
| 887 | igt_post_hang_ring(fd, hang); |
| 888 | } |
| 889 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 890 | static void do_write_read_rcs(struct buffers *buffers, |
| 891 | do_copy do_copy_func, |
| 892 | do_hang do_hang_func) |
| 893 | { |
| 894 | struct igt_hang_ring hang; |
| 895 | int i; |
| 896 | |
| 897 | gem_quiescent_gpu(fd); |
| 898 | for (i = buffers->count; i--; ) |
| 899 | buffers->mode->set_bo(buffers->src[i], 0xdeadbeef ^ i, width, height); |
| 900 | for (i = 0; i < buffers->count; i++) { |
| 901 | render_copy_bo(buffers->spare, buffers->src[i]); |
| 902 | do_copy_func(buffers->dst[i], buffers->spare); |
| 903 | } |
| 904 | hang = do_hang_func(); |
| 905 | for (i = buffers->count; i--; ) |
| 906 | buffers->mode->cmp_bo(buffers->dst[i], 0xdeadbeef ^ i, width, height, buffers->dummy); |
| 907 | igt_post_hang_ring(fd, hang); |
| 908 | } |
| 909 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 910 | static void do_gpu_read_after_write(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 911 | do_copy do_copy_func, |
| 912 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 913 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 914 | struct igt_hang_ring hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 915 | int i; |
| 916 | |
| 917 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 918 | for (i = buffers->count; i--; ) |
| 919 | buffers->mode->set_bo(buffers->src[i], 0xabcdabcd, width, height); |
| 920 | for (i = 0; i < buffers->count; i++) |
| 921 | do_copy_func(buffers->dst[i], buffers->src[i]); |
| 922 | for (i = buffers->count; i--; ) |
| 923 | do_copy_func(buffers->dummy, buffers->dst[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 924 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 925 | for (i = buffers->count; i--; ) |
| 926 | buffers->mode->cmp_bo(buffers->dst[i], 0xabcdabcd, width, height, buffers->dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 927 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 930 | typedef void (*do_test)(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 931 | do_copy do_copy_func, |
| 932 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 933 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 934 | typedef void (*run_wrap)(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 935 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 936 | do_copy do_copy_func, |
| 937 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 938 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 939 | static void run_single(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 940 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 941 | do_copy do_copy_func, |
| 942 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 943 | { |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 944 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 945 | check_gpu(); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 946 | } |
| 947 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 948 | static void run_interruptible(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 949 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 950 | do_copy do_copy_func, |
| 951 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 952 | { |
| 953 | int loop; |
| 954 | |
| 955 | for (loop = 0; loop < 10; loop++) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 956 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 957 | check_gpu(); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 960 | static void __run_forked(struct buffers *buffers, |
| 961 | int num_children, int loops, |
| 962 | do_test do_test_func, |
| 963 | do_copy do_copy_func, |
| 964 | do_hang do_hang_func) |
| 965 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 966 | { |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 967 | const int old_num_buffers = num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 968 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 969 | num_buffers /= num_children; |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 970 | num_buffers += 2; |
| 971 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 972 | igt_fork(child, num_children) { |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 973 | /* recreate process local variables */ |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 974 | buffers->count = 0; |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 975 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 976 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 977 | batch = buffers_init(buffers, buffers->mode, fd); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 978 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 979 | buffers_create(buffers, num_buffers); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 980 | for (int loop = 0; loop < loops; loop++) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 981 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 982 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 983 | buffers_fini(buffers); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 984 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 985 | |
| 986 | igt_waitchildren(); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 987 | check_gpu(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 988 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 989 | num_buffers = old_num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 990 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 991 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 992 | static void run_forked(struct buffers *buffers, |
| 993 | do_test do_test_func, |
| 994 | do_copy do_copy_func, |
| 995 | do_hang do_hang_func) |
| 996 | { |
| 997 | __run_forked(buffers, sysconf(_SC_NPROCESSORS_ONLN), 10, |
| 998 | do_test_func, do_copy_func, do_hang_func); |
| 999 | } |
| 1000 | |
| 1001 | static void run_bomb(struct buffers *buffers, |
| 1002 | do_test do_test_func, |
| 1003 | do_copy do_copy_func, |
| 1004 | do_hang do_hang_func) |
| 1005 | { |
| 1006 | __run_forked(buffers, 8*sysconf(_SC_NPROCESSORS_ONLN), 10, |
| 1007 | do_test_func, do_copy_func, do_hang_func); |
| 1008 | } |
| 1009 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1010 | static void bit17_require(void) |
| 1011 | { |
| 1012 | struct drm_i915_gem_get_tiling2 { |
| 1013 | uint32_t handle; |
| 1014 | uint32_t tiling_mode; |
| 1015 | uint32_t swizzle_mode; |
| 1016 | uint32_t phys_swizzle_mode; |
| 1017 | } arg; |
| 1018 | #define DRM_IOCTL_I915_GEM_GET_TILING2 DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling2) |
| 1019 | |
| 1020 | memset(&arg, 0, sizeof(arg)); |
| 1021 | arg.handle = gem_create(fd, 4096); |
| 1022 | gem_set_tiling(fd, arg.handle, I915_TILING_X, 512); |
| 1023 | |
Daniel Stone | de7ccdd | 2015-10-01 14:16:48 +0100 | [diff] [blame] | 1024 | do_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING2, &arg); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1025 | gem_close(fd, arg.handle); |
| 1026 | igt_require(arg.phys_swizzle_mode == arg.swizzle_mode); |
| 1027 | } |
| 1028 | |
| 1029 | static void cpu_require(void) |
| 1030 | { |
| 1031 | bit17_require(); |
| 1032 | } |
| 1033 | |
| 1034 | static void gtt_require(void) |
| 1035 | { |
| 1036 | } |
| 1037 | |
| 1038 | static void wc_require(void) |
| 1039 | { |
| 1040 | bit17_require(); |
Daniel Vetter | a3e34ce | 2015-02-06 11:05:28 +0100 | [diff] [blame] | 1041 | gem_require_mmap_wc(fd); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1042 | } |
| 1043 | |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1044 | static void bcs_require(void) |
| 1045 | { |
| 1046 | } |
| 1047 | |
| 1048 | static void rcs_require(void) |
| 1049 | { |
| 1050 | igt_require(rendercopy); |
| 1051 | } |
| 1052 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1053 | static void no_require(void) |
| 1054 | { |
| 1055 | } |
| 1056 | |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1057 | static void |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1058 | run_basic_modes(const char *prefix, |
| 1059 | const struct access_mode *mode, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1060 | const char *suffix, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1061 | run_wrap run_wrap_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1062 | { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1063 | const struct { |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1064 | const char *prefix; |
| 1065 | do_copy copy; |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1066 | void (*require)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1067 | } pipelines[] = { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1068 | { "cpu", cpu_copy_bo, cpu_require }, |
| 1069 | { "gtt", gtt_copy_bo, gtt_require }, |
| 1070 | { "wc", wc_copy_bo, wc_require }, |
Daniel Vetter | 3e9b4e3 | 2015-02-06 23:10:26 +0100 | [diff] [blame] | 1071 | { "blt", blt_copy_bo, bcs_require }, |
| 1072 | { "render", render_copy_bo, rcs_require }, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1073 | { NULL, NULL } |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1074 | }, *pskip = pipelines + 3, *p; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1075 | const struct { |
| 1076 | const char *suffix; |
| 1077 | do_hang hang; |
| 1078 | void (*require)(void); |
| 1079 | } hangs[] = { |
| 1080 | { "", no_hang, no_require }, |
Daniel Vetter | fbcc7ba | 2015-01-22 09:43:10 +0100 | [diff] [blame] | 1081 | { "-hang-blt", bcs_hang, hang_require }, |
| 1082 | { "-hang-render", rcs_hang, hang_require }, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1083 | { NULL, NULL }, |
| 1084 | }, *h; |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1085 | struct buffers buffers; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1086 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1087 | for (h = hangs; h->suffix; h++) { |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1088 | if (!all && *h->suffix) |
| 1089 | continue; |
| 1090 | |
| 1091 | for (p = all ? pipelines : pskip; p->prefix; p++) { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1092 | igt_fixture { |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1093 | batch = buffers_init(&buffers, mode, fd); |
Daniel Vetter | 6011508 | 2015-01-22 10:01:28 +0100 | [diff] [blame] | 1094 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1095 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame^] | 1096 | igt_subtest_f("%s-%s-%s-sanitycheck0%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 1097 | h->require(); |
| 1098 | p->require(); |
| 1099 | buffers_create(&buffers, num_buffers); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame^] | 1100 | run_wrap_func(&buffers, do_basic0, |
| 1101 | p->copy, h->hang); |
| 1102 | } |
| 1103 | |
| 1104 | igt_subtest_f("%s-%s-%s-sanitycheck1%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1105 | h->require(); |
| 1106 | p->require(); |
| 1107 | buffers_create(&buffers, num_buffers); |
| 1108 | run_wrap_func(&buffers, do_basic1, |
| 1109 | p->copy, h->hang); |
| 1110 | } |
| 1111 | |
| 1112 | igt_subtest_f("%s-%s-%s-sanitycheckN%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1113 | h->require(); |
| 1114 | p->require(); |
| 1115 | buffers_create(&buffers, num_buffers); |
| 1116 | run_wrap_func(&buffers, do_basicN, |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 1117 | p->copy, h->hang); |
| 1118 | } |
| 1119 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1120 | /* try to overwrite the source values */ |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1121 | igt_subtest_f("%s-%s-%s-overwrite-source-one%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1122 | h->require(); |
| 1123 | p->require(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1124 | buffers_create(&buffers, num_buffers); |
| 1125 | run_wrap_func(&buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1126 | do_overwrite_source__one, |
| 1127 | p->copy, h->hang); |
| 1128 | } |
| 1129 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1130 | igt_subtest_f("%s-%s-%s-overwrite-source%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1131 | h->require(); |
| 1132 | p->require(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1133 | buffers_create(&buffers, num_buffers); |
| 1134 | run_wrap_func(&buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1135 | do_overwrite_source, |
| 1136 | p->copy, h->hang); |
| 1137 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1138 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1139 | igt_subtest_f("%s-%s-%s-overwrite-source-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1140 | h->require(); |
| 1141 | p->require(); |
| 1142 | buffers_create(&buffers, num_buffers); |
| 1143 | run_wrap_func(&buffers, |
| 1144 | do_overwrite_source_read_bcs, |
| 1145 | p->copy, h->hang); |
| 1146 | } |
| 1147 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1148 | igt_subtest_f("%s-%s-%s-overwrite-source-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1149 | h->require(); |
| 1150 | p->require(); |
| 1151 | igt_require(rendercopy); |
| 1152 | buffers_create(&buffers, num_buffers); |
| 1153 | run_wrap_func(&buffers, |
| 1154 | do_overwrite_source_read_rcs, |
| 1155 | p->copy, h->hang); |
| 1156 | } |
| 1157 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1158 | igt_subtest_f("%s-%s-%s-overwrite-source-rev%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1159 | h->require(); |
| 1160 | p->require(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1161 | buffers_create(&buffers, num_buffers); |
| 1162 | run_wrap_func(&buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1163 | do_overwrite_source__rev, |
| 1164 | p->copy, h->hang); |
| 1165 | } |
| 1166 | |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1167 | /* try to intermix copies with GPU copies*/ |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1168 | igt_subtest_f("%s-%s-%s-intermix-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1169 | h->require(); |
| 1170 | p->require(); |
| 1171 | igt_require(rendercopy); |
| 1172 | buffers_create(&buffers, num_buffers); |
| 1173 | run_wrap_func(&buffers, |
| 1174 | do_intermix_rcs, |
| 1175 | p->copy, h->hang); |
| 1176 | } |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1177 | igt_subtest_f("%s-%s-%s-intermix-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1178 | h->require(); |
| 1179 | p->require(); |
| 1180 | igt_require(rendercopy); |
| 1181 | buffers_create(&buffers, num_buffers); |
| 1182 | run_wrap_func(&buffers, |
| 1183 | do_intermix_bcs, |
| 1184 | p->copy, h->hang); |
| 1185 | } |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1186 | igt_subtest_f("%s-%s-%s-intermix-both%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1187 | h->require(); |
| 1188 | p->require(); |
| 1189 | igt_require(rendercopy); |
| 1190 | buffers_create(&buffers, num_buffers); |
| 1191 | run_wrap_func(&buffers, |
| 1192 | do_intermix_both, |
| 1193 | p->copy, h->hang); |
| 1194 | } |
| 1195 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1196 | /* try to read the results before the copy completes */ |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1197 | igt_subtest_f("%s-%s-%s-early-read%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1198 | h->require(); |
| 1199 | p->require(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1200 | buffers_create(&buffers, num_buffers); |
| 1201 | run_wrap_func(&buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1202 | do_early_read, |
| 1203 | p->copy, h->hang); |
| 1204 | } |
| 1205 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1206 | /* concurrent reads */ |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1207 | igt_subtest_f("%s-%s-%s-read-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1208 | h->require(); |
| 1209 | p->require(); |
| 1210 | buffers_create(&buffers, num_buffers); |
| 1211 | run_wrap_func(&buffers, |
| 1212 | do_read_read_bcs, |
| 1213 | p->copy, h->hang); |
| 1214 | } |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1215 | igt_subtest_f("%s-%s-%s-read-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1216 | h->require(); |
| 1217 | p->require(); |
| 1218 | igt_require(rendercopy); |
| 1219 | buffers_create(&buffers, num_buffers); |
| 1220 | run_wrap_func(&buffers, |
| 1221 | do_read_read_rcs, |
| 1222 | p->copy, h->hang); |
| 1223 | } |
| 1224 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1225 | /* split copying between rings */ |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1226 | igt_subtest_f("%s-%s-%s-write-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1227 | h->require(); |
| 1228 | p->require(); |
| 1229 | buffers_create(&buffers, num_buffers); |
| 1230 | run_wrap_func(&buffers, |
| 1231 | do_write_read_bcs, |
| 1232 | p->copy, h->hang); |
| 1233 | } |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1234 | igt_subtest_f("%s-%s-%s-write-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1235 | h->require(); |
| 1236 | p->require(); |
| 1237 | igt_require(rendercopy); |
| 1238 | buffers_create(&buffers, num_buffers); |
| 1239 | run_wrap_func(&buffers, |
| 1240 | do_write_read_rcs, |
| 1241 | p->copy, h->hang); |
| 1242 | } |
| 1243 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1244 | /* and finally try to trick the kernel into loosing the pending write */ |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1245 | igt_subtest_f("%s-%s-%s-gpu-read-after-write%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1246 | h->require(); |
| 1247 | p->require(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1248 | buffers_create(&buffers, num_buffers); |
| 1249 | run_wrap_func(&buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1250 | do_gpu_read_after_write, |
| 1251 | p->copy, h->hang); |
| 1252 | } |
| 1253 | |
| 1254 | igt_fixture { |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1255 | buffers_fini(&buffers); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1256 | } |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1257 | } |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1258 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1259 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1260 | |
| 1261 | static void |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1262 | run_modes(const char *style, const struct access_mode *mode) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1263 | { |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1264 | igt_debug("%s: using 2x%d buffers, each 1MiB\n", style, num_buffers); |
| 1265 | intel_require_memory(2*num_buffers, 1024*1024, CHECK_RAM); |
| 1266 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1267 | if (all) { |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1268 | run_basic_modes(style, mode, "", run_single); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1269 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1270 | igt_fork_signal_helper(); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1271 | run_basic_modes(style, mode, "-interruptible", run_interruptible); |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1272 | igt_stop_signal_helper(); |
| 1273 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1274 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1275 | igt_fork_signal_helper(); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1276 | run_basic_modes(style, mode, "-forked", run_forked); |
| 1277 | run_basic_modes(style, mode, "-bomb", run_bomb); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1278 | igt_stop_signal_helper(); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 1281 | igt_main |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1282 | { |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1283 | int i; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1284 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1285 | igt_skip_on_simulation(); |
| 1286 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1287 | if (strstr(igt_test_name(), "all")) |
| 1288 | all = true; |
| 1289 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 1290 | igt_fixture { |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 1291 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1292 | devid = intel_get_drm_devid(fd); |
| 1293 | gen = intel_gen(devid); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1294 | rendercopy = igt_get_render_copyfunc(devid); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1295 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1296 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1297 | igt_fixture { |
| 1298 | num_buffers = gem_mappable_aperture_size() / (1024 * 1024) / 4; |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 1299 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1300 | |
| 1301 | for (i = 0; i < ARRAY_SIZE(access_modes); i++) |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1302 | run_modes("small", &access_modes[i]); |
| 1303 | |
| 1304 | igt_fixture { |
| 1305 | num_buffers = gem_mappable_aperture_size() / (1024 * 1024); |
| 1306 | } |
| 1307 | |
| 1308 | for (i = 0; i < ARRAY_SIZE(access_modes); i++) |
| 1309 | run_modes("thrash", &access_modes[i]); |
| 1310 | |
| 1311 | igt_fixture { |
| 1312 | num_buffers = gem_aperture_size(fd) / (1024 * 1024); |
| 1313 | } |
| 1314 | |
| 1315 | for (i = 0; i < ARRAY_SIZE(access_modes); i++) |
| 1316 | run_modes("full", &access_modes[i]); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1317 | } |