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