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" |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 52 | #include "igt_aux.h" |
| 53 | #include "igt_core.h" |
| 54 | #include "igt_gt.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 55 | #include "intel_bufmgr.h" |
| 56 | #include "intel_batchbuffer.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 57 | #include "intel_io.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 58 | #include "intel_chipset.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 59 | |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 60 | IGT_TEST_DESCRIPTION("Test of pread/pwrite behavior when writing to active" |
| 61 | " buffers."); |
| 62 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 63 | int fd, devid, gen; |
| 64 | struct intel_batchbuffer *batch; |
| 65 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 66 | static void |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 67 | nop_release_bo(drm_intel_bo *bo) |
| 68 | { |
| 69 | drm_intel_bo_unreference(bo); |
| 70 | } |
| 71 | |
| 72 | static void |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 73 | 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] | 74 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 75 | int size = width * height, i; |
| 76 | uint32_t *tmp; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 77 | |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 78 | tmp = malloc(4*size); |
| 79 | if (tmp) { |
| 80 | for (i = 0; i < size; i++) |
| 81 | tmp[i] = val; |
| 82 | drm_intel_bo_subdata(bo, 0, 4*size, tmp); |
| 83 | free(tmp); |
| 84 | } else { |
| 85 | for (i = 0; i < size; i++) |
| 86 | drm_intel_bo_subdata(bo, 4*i, 4, &val); |
| 87 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 91 | 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] | 92 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 93 | int size = width * height, i; |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 94 | uint32_t *vaddr; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 95 | |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 96 | do_or_die(drm_intel_bo_map(tmp, true)); |
| 97 | do_or_die(drm_intel_bo_get_subdata(bo, 0, 4*size, tmp->virtual)); |
| 98 | vaddr = tmp->virtual; |
| 99 | for (i = 0; i < size; i++) |
| 100 | igt_assert_eq_u32(vaddr[i], val); |
| 101 | drm_intel_bo_unmap(tmp); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 105 | unmapped_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 106 | { |
| 107 | drm_intel_bo *bo; |
| 108 | |
| 109 | bo = drm_intel_bo_alloc(bufmgr, "bo", 4*width*height, 0); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 110 | igt_assert(bo); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 111 | |
| 112 | return bo; |
| 113 | } |
| 114 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 115 | static void |
| 116 | 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] | 117 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 118 | uint32_t *vaddr = bo->virtual; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 119 | int size = width * height; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 120 | |
| 121 | drm_intel_gem_bo_start_gtt_access(bo, true); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 122 | while (size--) |
| 123 | *vaddr++ = val; |
| 124 | } |
| 125 | |
| 126 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 127 | 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] | 128 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 129 | uint32_t *vaddr = bo->virtual; |
| 130 | int y; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 131 | |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 132 | /* GTT access is slow. So we just compare a few points */ |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 133 | drm_intel_gem_bo_start_gtt_access(bo, false); |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 134 | for (y = 0; y < height; y++) |
| 135 | igt_assert_eq_u32(vaddr[y*width+y], val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 139 | map_bo(drm_intel_bo *bo) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 140 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 141 | /* gtt map doesn't have a write parameter, so just keep the mapping |
| 142 | * around (to avoid the set_domain with the gtt write domain set) and |
| 143 | * manually tell the kernel when we start access the gtt. */ |
| 144 | do_or_die(drm_intel_gem_bo_map_gtt(bo)); |
| 145 | |
| 146 | return bo; |
| 147 | } |
| 148 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 149 | static drm_intel_bo * |
| 150 | tile_bo(drm_intel_bo *bo, int width) |
| 151 | { |
| 152 | uint32_t tiling = I915_TILING_X; |
| 153 | uint32_t stride = width * 4; |
| 154 | |
| 155 | do_or_die(drm_intel_bo_set_tiling(bo, &tiling, stride)); |
| 156 | |
| 157 | return bo; |
| 158 | } |
| 159 | |
| 160 | static drm_intel_bo * |
| 161 | gtt_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 162 | { |
| 163 | return map_bo(unmapped_create_bo(bufmgr, width, height)); |
| 164 | } |
| 165 | |
| 166 | static drm_intel_bo * |
| 167 | gttX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 168 | { |
| 169 | return tile_bo(gtt_create_bo(bufmgr, width, height), width); |
| 170 | } |
| 171 | |
| 172 | static drm_intel_bo * |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 173 | wc_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 174 | { |
| 175 | drm_intel_bo *bo; |
| 176 | |
Daniel Vetter | a3e34ce | 2015-02-06 11:05:28 +0100 | [diff] [blame] | 177 | gem_require_mmap_wc(fd); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 178 | |
| 179 | bo = unmapped_create_bo(bufmgr, width, height); |
| 180 | bo->virtual = gem_mmap__wc(fd, bo->handle, 0, bo->size, PROT_READ | PROT_WRITE); |
| 181 | return bo; |
| 182 | } |
| 183 | |
| 184 | static void |
| 185 | wc_release_bo(drm_intel_bo *bo) |
| 186 | { |
| 187 | munmap(bo->virtual, bo->size); |
| 188 | bo->virtual = NULL; |
| 189 | |
| 190 | nop_release_bo(bo); |
| 191 | } |
| 192 | |
| 193 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 194 | gpu_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 195 | { |
| 196 | return unmapped_create_bo(bufmgr, width, height); |
| 197 | } |
| 198 | |
| 199 | |
| 200 | static drm_intel_bo * |
| 201 | gpuX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 202 | { |
| 203 | return tile_bo(gpu_create_bo(bufmgr, width, height), width); |
| 204 | } |
| 205 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 206 | static void |
| 207 | cpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 208 | { |
| 209 | int size = width * height; |
| 210 | uint32_t *vaddr; |
| 211 | |
| 212 | do_or_die(drm_intel_bo_map(bo, true)); |
| 213 | vaddr = bo->virtual; |
| 214 | while (size--) |
| 215 | *vaddr++ = val; |
| 216 | drm_intel_bo_unmap(bo); |
| 217 | } |
| 218 | |
| 219 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 220 | 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] | 221 | { |
| 222 | int size = width * height; |
| 223 | uint32_t *vaddr; |
| 224 | |
| 225 | do_or_die(drm_intel_bo_map(bo, false)); |
| 226 | vaddr = bo->virtual; |
| 227 | while (size--) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 228 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 229 | drm_intel_bo_unmap(bo); |
| 230 | } |
| 231 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 232 | static void |
| 233 | gpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
| 234 | { |
| 235 | struct drm_i915_gem_relocation_entry reloc[1]; |
| 236 | struct drm_i915_gem_exec_object2 gem_exec[2]; |
| 237 | struct drm_i915_gem_execbuffer2 execbuf; |
| 238 | struct drm_i915_gem_pwrite gem_pwrite; |
| 239 | struct drm_i915_gem_create create; |
| 240 | uint32_t buf[10], *b; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 241 | uint32_t tiling, swizzle; |
| 242 | |
| 243 | drm_intel_bo_get_tiling(bo, &tiling, &swizzle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 244 | |
| 245 | memset(reloc, 0, sizeof(reloc)); |
| 246 | memset(gem_exec, 0, sizeof(gem_exec)); |
| 247 | memset(&execbuf, 0, sizeof(execbuf)); |
| 248 | |
| 249 | b = buf; |
| 250 | *b++ = XY_COLOR_BLT_CMD_NOLEN | |
| 251 | ((gen >= 8) ? 5 : 4) | |
| 252 | COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 253 | if (gen >= 4 && tiling) { |
| 254 | b[-1] |= XY_COLOR_BLT_TILED; |
| 255 | *b = width; |
| 256 | } else |
| 257 | *b = width << 2; |
| 258 | *b++ |= 0xf0 << 16 | 1 << 25 | 1 << 24; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 259 | *b++ = 0; |
| 260 | *b++ = height << 16 | width; |
| 261 | reloc[0].offset = (b - buf) * sizeof(uint32_t); |
| 262 | reloc[0].target_handle = bo->handle; |
| 263 | reloc[0].read_domains = I915_GEM_DOMAIN_RENDER; |
| 264 | reloc[0].write_domain = I915_GEM_DOMAIN_RENDER; |
| 265 | *b++ = 0; |
| 266 | if (gen >= 8) |
| 267 | *b++ = 0; |
| 268 | *b++ = val; |
| 269 | *b++ = MI_BATCH_BUFFER_END; |
| 270 | if ((b - buf) & 1) |
| 271 | *b++ = 0; |
| 272 | |
| 273 | gem_exec[0].handle = bo->handle; |
| 274 | gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE; |
| 275 | |
| 276 | create.handle = 0; |
| 277 | create.size = 4096; |
| 278 | drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create); |
| 279 | gem_exec[1].handle = create.handle; |
| 280 | gem_exec[1].relocation_count = 1; |
| 281 | gem_exec[1].relocs_ptr = (uintptr_t)reloc; |
| 282 | |
| 283 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 284 | execbuf.buffer_count = 2; |
| 285 | execbuf.batch_len = (b - buf) * sizeof(buf[0]); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 286 | if (gen >= 6) |
| 287 | execbuf.flags = I915_EXEC_BLT; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 288 | |
| 289 | gem_pwrite.handle = gem_exec[1].handle; |
| 290 | gem_pwrite.offset = 0; |
| 291 | gem_pwrite.size = execbuf.batch_len; |
| 292 | gem_pwrite.data_ptr = (uintptr_t)buf; |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 293 | do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite)); |
| 294 | do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 295 | |
| 296 | drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &create.handle); |
| 297 | } |
| 298 | |
| 299 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 300 | 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] | 301 | { |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 302 | intel_copy_bo(batch, tmp, bo, width*height*4); |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 303 | cpu_cmp_bo(tmp, val, width, height, NULL); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 306 | const struct access_mode { |
| 307 | const char *name; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 308 | 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] | 309 | 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] | 310 | 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] | 311 | void (*release_bo)(drm_intel_bo *bo); |
| 312 | } access_modes[] = { |
| 313 | { |
| 314 | .name = "prw", |
| 315 | .set_bo = prw_set_bo, |
| 316 | .cmp_bo = prw_cmp_bo, |
| 317 | .create_bo = unmapped_create_bo, |
| 318 | .release_bo = nop_release_bo, |
| 319 | }, |
| 320 | { |
| 321 | .name = "cpu", |
| 322 | .set_bo = cpu_set_bo, |
| 323 | .cmp_bo = cpu_cmp_bo, |
| 324 | .create_bo = unmapped_create_bo, |
| 325 | .release_bo = nop_release_bo, |
| 326 | }, |
| 327 | { |
| 328 | .name = "gtt", |
| 329 | .set_bo = gtt_set_bo, |
| 330 | .cmp_bo = gtt_cmp_bo, |
| 331 | .create_bo = gtt_create_bo, |
| 332 | .release_bo = nop_release_bo, |
| 333 | }, |
| 334 | { |
| 335 | .name = "gttX", |
| 336 | .set_bo = gtt_set_bo, |
| 337 | .cmp_bo = gtt_cmp_bo, |
| 338 | .create_bo = gttX_create_bo, |
| 339 | .release_bo = nop_release_bo, |
| 340 | }, |
| 341 | { |
| 342 | .name = "wc", |
| 343 | .set_bo = gtt_set_bo, |
| 344 | .cmp_bo = gtt_cmp_bo, |
| 345 | .create_bo = wc_create_bo, |
| 346 | .release_bo = wc_release_bo, |
| 347 | }, |
| 348 | { |
| 349 | .name = "gpu", |
| 350 | .set_bo = gpu_set_bo, |
| 351 | .cmp_bo = gpu_cmp_bo, |
| 352 | .create_bo = gpu_create_bo, |
| 353 | .release_bo = nop_release_bo, |
| 354 | }, |
| 355 | { |
| 356 | .name = "gpuX", |
| 357 | .set_bo = gpu_set_bo, |
| 358 | .cmp_bo = gpu_cmp_bo, |
| 359 | .create_bo = gpuX_create_bo, |
| 360 | .release_bo = nop_release_bo, |
| 361 | }, |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 362 | }; |
| 363 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 364 | #define MAX_NUM_BUFFERS 1024 |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 365 | int num_buffers = MAX_NUM_BUFFERS; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 366 | const int width = 512, height = 512; |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 367 | igt_render_copyfunc_t rendercopy; |
| 368 | |
| 369 | typedef void (*do_copy)(drm_intel_bo *dst, drm_intel_bo *src); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 370 | typedef struct igt_hang_ring (*do_hang)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 371 | |
| 372 | static void render_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 373 | { |
| 374 | struct igt_buf d = { |
| 375 | .bo = dst, |
| 376 | .size = width * height * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 377 | .num_tiles = width * height * 4, |
| 378 | .stride = width * 4, |
| 379 | }, s = { |
| 380 | .bo = src, |
| 381 | .size = width * height * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 382 | .num_tiles = width * height * 4, |
| 383 | .stride = width * 4, |
| 384 | }; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 385 | uint32_t swizzle; |
| 386 | |
| 387 | drm_intel_bo_get_tiling(dst, &d.tiling, &swizzle); |
| 388 | drm_intel_bo_get_tiling(src, &s.tiling, &swizzle); |
| 389 | |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 390 | rendercopy(batch, NULL, |
| 391 | &s, 0, 0, |
| 392 | width, height, |
| 393 | &d, 0, 0); |
| 394 | } |
| 395 | |
| 396 | static void blt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 397 | { |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 398 | intel_blt_copy(batch, |
| 399 | src, 0, 0, 4*width, |
| 400 | dst, 0, 0, 4*width, |
| 401 | width, height, 32); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 402 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 403 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 404 | static void cpu_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 405 | { |
| 406 | const int size = width * height * sizeof(uint32_t); |
| 407 | void *d, *s; |
| 408 | |
| 409 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0); |
| 410 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); |
| 411 | s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ); |
| 412 | igt_assert(s != NULL); |
| 413 | d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE); |
| 414 | igt_assert(d != NULL); |
| 415 | |
| 416 | memcpy(d, s, size); |
| 417 | |
| 418 | munmap(d, size); |
| 419 | munmap(s, size); |
| 420 | } |
| 421 | |
| 422 | static void gtt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 423 | { |
| 424 | const int size = width * height * sizeof(uint32_t); |
| 425 | void *d, *s; |
| 426 | |
| 427 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 428 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 429 | |
| 430 | s = gem_mmap__gtt(fd, src->handle, size, PROT_READ); |
| 431 | igt_assert(s != NULL); |
| 432 | d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE); |
| 433 | igt_assert(d != NULL); |
| 434 | |
| 435 | memcpy(d, s, size); |
| 436 | |
| 437 | munmap(d, size); |
| 438 | munmap(s, size); |
| 439 | } |
| 440 | |
| 441 | static void wc_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 442 | { |
| 443 | const int size = width * height * sizeof(uint32_t); |
| 444 | void *d, *s; |
| 445 | |
| 446 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 447 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 448 | |
| 449 | s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ); |
| 450 | igt_assert(s != NULL); |
| 451 | d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE); |
| 452 | igt_assert(d != NULL); |
| 453 | |
| 454 | memcpy(d, s, size); |
| 455 | |
| 456 | munmap(d, size); |
| 457 | munmap(s, size); |
| 458 | } |
| 459 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 460 | static struct igt_hang_ring no_hang(void) |
| 461 | { |
| 462 | return (struct igt_hang_ring){0, 0}; |
| 463 | } |
| 464 | |
| 465 | static struct igt_hang_ring bcs_hang(void) |
| 466 | { |
| 467 | return igt_hang_ring(fd, gen, I915_EXEC_BLT); |
| 468 | } |
| 469 | |
| 470 | static struct igt_hang_ring rcs_hang(void) |
| 471 | { |
| 472 | return igt_hang_ring(fd, gen, I915_EXEC_RENDER); |
| 473 | } |
| 474 | |
| 475 | static void hang_require(void) |
| 476 | { |
Daniel Vetter | c66b242 | 2015-02-06 10:49:20 +0100 | [diff] [blame] | 477 | igt_require_hang_ring(fd, -1); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 478 | } |
| 479 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 480 | static void do_overwrite_source(const struct access_mode *mode, |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 481 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 482 | drm_intel_bo *dummy, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 483 | do_copy do_copy_func, |
| 484 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 485 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 486 | struct igt_hang_ring hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 487 | int i; |
| 488 | |
| 489 | gem_quiescent_gpu(fd); |
| 490 | for (i = 0; i < num_buffers; i++) { |
| 491 | mode->set_bo(src[i], i, width, height); |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 492 | mode->set_bo(dst[i], ~i, width, height); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 493 | } |
| 494 | for (i = 0; i < num_buffers; i++) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 495 | do_copy_func(dst[i], src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 496 | hang = do_hang_func(); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 497 | for (i = num_buffers; i--; ) |
| 498 | mode->set_bo(src[i], 0xdeadbeef, width, height); |
| 499 | for (i = 0; i < num_buffers; i++) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 500 | mode->cmp_bo(dst[i], i, width, height, dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 501 | igt_post_hang_ring(fd, hang); |
| 502 | } |
| 503 | |
| 504 | static void do_overwrite_source__rev(const struct access_mode *mode, |
| 505 | drm_intel_bo **src, drm_intel_bo **dst, |
| 506 | drm_intel_bo *dummy, |
| 507 | do_copy do_copy_func, |
| 508 | do_hang do_hang_func) |
| 509 | { |
| 510 | struct igt_hang_ring hang; |
| 511 | int i; |
| 512 | |
| 513 | gem_quiescent_gpu(fd); |
| 514 | for (i = 0; i < num_buffers; i++) { |
| 515 | mode->set_bo(src[i], i, width, height); |
| 516 | mode->set_bo(dst[i], ~i, width, height); |
| 517 | } |
| 518 | for (i = 0; i < num_buffers; i++) |
| 519 | do_copy_func(dst[i], src[i]); |
| 520 | hang = do_hang_func(); |
| 521 | for (i = 0; i < num_buffers; i++) |
| 522 | mode->set_bo(src[i], 0xdeadbeef, width, height); |
| 523 | for (i = num_buffers; i--; ) |
| 524 | mode->cmp_bo(dst[i], i, width, height, dummy); |
| 525 | igt_post_hang_ring(fd, hang); |
| 526 | } |
| 527 | |
| 528 | static void do_overwrite_source__one(const struct access_mode *mode, |
| 529 | drm_intel_bo **src, drm_intel_bo **dst, |
| 530 | drm_intel_bo *dummy, |
| 531 | do_copy do_copy_func, |
| 532 | do_hang do_hang_func) |
| 533 | { |
| 534 | struct igt_hang_ring hang; |
| 535 | |
| 536 | gem_quiescent_gpu(fd); |
| 537 | mode->set_bo(src[0], 0, width, height); |
| 538 | mode->set_bo(dst[0], ~0, width, height); |
| 539 | do_copy_func(dst[0], src[0]); |
| 540 | hang = do_hang_func(); |
| 541 | mode->set_bo(src[0], 0xdeadbeef, width, height); |
| 542 | mode->cmp_bo(dst[0], 0, width, height, dummy); |
| 543 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 544 | } |
| 545 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 546 | static void do_early_read(const struct access_mode *mode, |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 547 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 548 | drm_intel_bo *dummy, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 549 | do_copy do_copy_func, |
| 550 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 551 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 552 | struct igt_hang_ring hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 553 | int i; |
| 554 | |
| 555 | gem_quiescent_gpu(fd); |
| 556 | for (i = num_buffers; i--; ) |
| 557 | mode->set_bo(src[i], 0xdeadbeef, width, height); |
| 558 | for (i = 0; i < num_buffers; i++) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 559 | do_copy_func(dst[i], src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 560 | hang = do_hang_func(); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 561 | for (i = num_buffers; i--; ) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 562 | mode->cmp_bo(dst[i], 0xdeadbeef, width, height, dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 563 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 564 | } |
| 565 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 566 | static void do_gpu_read_after_write(const struct access_mode *mode, |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 567 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 568 | drm_intel_bo *dummy, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 569 | do_copy do_copy_func, |
| 570 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 571 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 572 | struct igt_hang_ring hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 573 | int i; |
| 574 | |
| 575 | gem_quiescent_gpu(fd); |
| 576 | for (i = num_buffers; i--; ) |
| 577 | mode->set_bo(src[i], 0xabcdabcd, width, height); |
| 578 | for (i = 0; i < num_buffers; i++) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 579 | do_copy_func(dst[i], src[i]); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 580 | for (i = num_buffers; i--; ) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 581 | do_copy_func(dummy, dst[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 582 | hang = do_hang_func(); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 583 | for (i = num_buffers; i--; ) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 584 | mode->cmp_bo(dst[i], 0xabcdabcd, width, height, dummy); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 585 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 588 | typedef void (*do_test)(const struct access_mode *mode, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 589 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 590 | drm_intel_bo *dummy, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 591 | do_copy do_copy_func, |
| 592 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 593 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 594 | typedef void (*run_wrap)(const struct access_mode *mode, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 595 | drm_intel_bo **src, drm_intel_bo **dst, |
| 596 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 597 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 598 | do_copy do_copy_func, |
| 599 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 600 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 601 | static void run_single(const struct access_mode *mode, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 602 | drm_intel_bo **src, drm_intel_bo **dst, |
| 603 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 604 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 605 | do_copy do_copy_func, |
| 606 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 607 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 608 | do_test_func(mode, src, dst, dummy, do_copy_func, do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 609 | } |
| 610 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 611 | static void run_interruptible(const struct access_mode *mode, |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 612 | drm_intel_bo **src, drm_intel_bo **dst, |
| 613 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 614 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 615 | do_copy do_copy_func, |
| 616 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 617 | { |
| 618 | int loop; |
| 619 | |
| 620 | for (loop = 0; loop < 10; loop++) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 621 | do_test_func(mode, src, dst, dummy, do_copy_func, do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 622 | } |
| 623 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 624 | static void run_forked(const struct access_mode *mode, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 625 | drm_intel_bo **src, drm_intel_bo **dst, |
| 626 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 627 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 628 | do_copy do_copy_func, |
| 629 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 630 | { |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 631 | const int old_num_buffers = num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 632 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 633 | num_buffers /= 16; |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 634 | num_buffers += 2; |
| 635 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 636 | igt_fork(child, 16) { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 637 | drm_intel_bufmgr *bufmgr; |
| 638 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 639 | /* recreate process local variables */ |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 640 | fd = drm_open_any(); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 641 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 642 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 643 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 644 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 645 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 646 | for (int i = 0; i < num_buffers; i++) { |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 647 | src[i] = mode->create_bo(bufmgr, width, height); |
| 648 | dst[i] = mode->create_bo(bufmgr, width, height); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 649 | } |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 650 | dummy = mode->create_bo(bufmgr, width, height); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 651 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 652 | for (int loop = 0; loop < 10; loop++) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 653 | do_test_func(mode, src, dst, dummy, |
| 654 | do_copy_func, do_hang_func); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 655 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 656 | for (int i = 0; i < num_buffers; i++) { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 657 | mode->release_bo(src[i]); |
| 658 | mode->release_bo(dst[i]); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 659 | } |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 660 | mode->release_bo(dummy); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 661 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 662 | |
| 663 | igt_waitchildren(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 664 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 665 | num_buffers = old_num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 666 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 667 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 668 | static void bit17_require(void) |
| 669 | { |
| 670 | struct drm_i915_gem_get_tiling2 { |
| 671 | uint32_t handle; |
| 672 | uint32_t tiling_mode; |
| 673 | uint32_t swizzle_mode; |
| 674 | uint32_t phys_swizzle_mode; |
| 675 | } arg; |
| 676 | #define DRM_IOCTL_I915_GEM_GET_TILING2 DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling2) |
| 677 | |
| 678 | memset(&arg, 0, sizeof(arg)); |
| 679 | arg.handle = gem_create(fd, 4096); |
| 680 | gem_set_tiling(fd, arg.handle, I915_TILING_X, 512); |
| 681 | |
| 682 | do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_TILING2, &arg)); |
| 683 | gem_close(fd, arg.handle); |
| 684 | igt_require(arg.phys_swizzle_mode == arg.swizzle_mode); |
| 685 | } |
| 686 | |
| 687 | static void cpu_require(void) |
| 688 | { |
| 689 | bit17_require(); |
| 690 | } |
| 691 | |
| 692 | static void gtt_require(void) |
| 693 | { |
| 694 | } |
| 695 | |
| 696 | static void wc_require(void) |
| 697 | { |
| 698 | bit17_require(); |
Daniel Vetter | a3e34ce | 2015-02-06 11:05:28 +0100 | [diff] [blame] | 699 | gem_require_mmap_wc(fd); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 700 | } |
| 701 | |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 702 | static void bcs_require(void) |
| 703 | { |
| 704 | } |
| 705 | |
| 706 | static void rcs_require(void) |
| 707 | { |
| 708 | igt_require(rendercopy); |
| 709 | } |
| 710 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 711 | static void no_require(void) |
| 712 | { |
| 713 | } |
| 714 | |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 715 | static void |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 716 | run_basic_modes(const struct access_mode *mode, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 717 | const char *suffix, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 718 | run_wrap run_wrap_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 719 | { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 720 | const struct { |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 721 | const char *prefix; |
| 722 | do_copy copy; |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 723 | void (*require)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 724 | } pipelines[] = { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 725 | { "cpu", cpu_copy_bo, cpu_require }, |
| 726 | { "gtt", gtt_copy_bo, gtt_require }, |
| 727 | { "wc", wc_copy_bo, wc_require }, |
Daniel Vetter | 3e9b4e3 | 2015-02-06 23:10:26 +0100 | [diff] [blame^] | 728 | { "blt", blt_copy_bo, bcs_require }, |
| 729 | { "render", render_copy_bo, rcs_require }, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 730 | { NULL, NULL } |
| 731 | }, *p; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 732 | const struct { |
| 733 | const char *suffix; |
| 734 | do_hang hang; |
| 735 | void (*require)(void); |
| 736 | } hangs[] = { |
| 737 | { "", no_hang, no_require }, |
Daniel Vetter | fbcc7ba | 2015-01-22 09:43:10 +0100 | [diff] [blame] | 738 | { "-hang-blt", bcs_hang, hang_require }, |
| 739 | { "-hang-render", rcs_hang, hang_require }, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 740 | { NULL, NULL }, |
| 741 | }, *h; |
| 742 | drm_intel_bo *src[MAX_NUM_BUFFERS], *dst[MAX_NUM_BUFFERS], *dummy = NULL; |
| 743 | drm_intel_bufmgr *bufmgr; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 744 | |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 745 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 746 | for (h = hangs; h->suffix; h++) { |
| 747 | for (p = pipelines; p->prefix; p++) { |
| 748 | igt_fixture { |
| 749 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 750 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 751 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 752 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 753 | for (int i = 0; i < num_buffers; i++) { |
| 754 | src[i] = mode->create_bo(bufmgr, width, height); |
| 755 | dst[i] = mode->create_bo(bufmgr, width, height); |
| 756 | } |
| 757 | dummy = mode->create_bo(bufmgr, width, height); |
Daniel Vetter | 6011508 | 2015-01-22 10:01:28 +0100 | [diff] [blame] | 758 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 759 | |
| 760 | /* try to overwrite the source values */ |
| 761 | igt_subtest_f("%s-%s-overwrite-source-one%s%s", mode->name, p->prefix, suffix, h->suffix) { |
| 762 | h->require(); |
| 763 | p->require(); |
| 764 | run_wrap_func(mode, src, dst, dummy, |
| 765 | do_overwrite_source__one, |
| 766 | p->copy, h->hang); |
| 767 | } |
| 768 | |
| 769 | igt_subtest_f("%s-%s-overwrite-source%s%s", mode->name, p->prefix, suffix, h->suffix) { |
| 770 | h->require(); |
| 771 | p->require(); |
| 772 | run_wrap_func(mode, src, dst, dummy, |
| 773 | do_overwrite_source, |
| 774 | p->copy, h->hang); |
| 775 | } |
| 776 | igt_subtest_f("%s-%s-overwrite-source-rev%s%s", mode->name, p->prefix, suffix, h->suffix) { |
| 777 | h->require(); |
| 778 | p->require(); |
| 779 | run_wrap_func(mode, src, dst, dummy, |
| 780 | do_overwrite_source__rev, |
| 781 | p->copy, h->hang); |
| 782 | } |
| 783 | |
| 784 | /* try to read the results before the copy completes */ |
| 785 | igt_subtest_f("%s-%s-early-read%s%s", mode->name, p->prefix, suffix, h->suffix) { |
| 786 | h->require(); |
| 787 | p->require(); |
| 788 | run_wrap_func(mode, src, dst, dummy, |
| 789 | do_early_read, |
| 790 | p->copy, h->hang); |
| 791 | } |
| 792 | |
| 793 | /* and finally try to trick the kernel into loosing the pending write */ |
| 794 | igt_subtest_f("%s-%s-gpu-read-after-write%s%s", mode->name, p->prefix, suffix, h->suffix) { |
| 795 | h->require(); |
| 796 | p->require(); |
| 797 | run_wrap_func(mode, src, dst, dummy, |
| 798 | do_gpu_read_after_write, |
| 799 | p->copy, h->hang); |
| 800 | } |
| 801 | |
| 802 | igt_fixture { |
| 803 | for (int i = 0; i < num_buffers; i++) { |
| 804 | mode->release_bo(src[i]); |
| 805 | mode->release_bo(dst[i]); |
| 806 | } |
| 807 | mode->release_bo(dummy); |
| 808 | intel_batchbuffer_free(batch); |
| 809 | drm_intel_bufmgr_destroy(bufmgr); |
| 810 | } |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 811 | } |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 812 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 813 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 814 | |
| 815 | static void |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 816 | run_modes(const struct access_mode *mode) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 817 | { |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 818 | run_basic_modes(mode, "", run_single); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 819 | |
| 820 | igt_fork_signal_helper(); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 821 | run_basic_modes(mode, "-interruptible", run_interruptible); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 822 | igt_stop_signal_helper(); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 823 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 824 | igt_fork_signal_helper(); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 825 | run_basic_modes(mode, "-forked", run_forked); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 826 | igt_stop_signal_helper(); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 827 | } |
| 828 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 829 | igt_main |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 830 | { |
| 831 | int max, i; |
| 832 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 833 | igt_skip_on_simulation(); |
| 834 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 835 | igt_fixture { |
| 836 | fd = drm_open_any(); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 837 | devid = intel_get_drm_devid(fd); |
| 838 | gen = intel_gen(devid); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 839 | rendercopy = igt_get_render_copyfunc(devid); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 840 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 841 | max = gem_aperture_size (fd) / (1024 * 1024) / 2; |
| 842 | if (num_buffers > max) |
| 843 | num_buffers = max; |
Daniel Vetter | aee0dcb | 2013-12-03 16:32:52 +0100 | [diff] [blame] | 844 | |
| 845 | max = intel_get_total_ram_mb() * 3 / 4; |
| 846 | if (num_buffers > max) |
| 847 | num_buffers = max; |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 848 | num_buffers /= 2; |
Daniel Vetter | e624fa8 | 2014-05-14 00:36:04 +0200 | [diff] [blame] | 849 | igt_info("using 2x%d buffers, each 1MiB\n", num_buffers); |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 850 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 851 | |
| 852 | for (i = 0; i < ARRAY_SIZE(access_modes); i++) |
| 853 | run_modes(&access_modes[i]); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 854 | } |