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" |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 39 | #include "igt_vgem.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 40 | #include <stdlib.h> |
| 41 | #include <stdio.h> |
| 42 | #include <string.h> |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 43 | #include <fcntl.h> |
| 44 | #include <inttypes.h> |
| 45 | #include <errno.h> |
Chris Wilson | 3d8af56 | 2016-03-20 10:49:54 +0000 | [diff] [blame] | 46 | #include <sys/resource.h> |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 47 | #include <sys/stat.h> |
| 48 | #include <sys/time.h> |
Chris Wilson | 99431a4 | 2013-08-14 11:03:34 +0100 | [diff] [blame] | 49 | #include <sys/wait.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 50 | |
| 51 | #include <drm.h> |
| 52 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 53 | #include "intel_bufmgr.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 54 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 55 | 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] | 56 | " buffers."); |
| 57 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 58 | int fd, devid, gen; |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 59 | int vgem_drv = -1; |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 60 | int all; |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 61 | int pass; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 62 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 63 | struct create { |
| 64 | const char *name; |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 65 | void (*require)(const struct create *, unsigned); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 66 | drm_intel_bo *(*create)(drm_intel_bufmgr *, uint64_t size); |
| 67 | }; |
| 68 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 69 | struct size { |
| 70 | const char *name; |
| 71 | int width, height; |
| 72 | }; |
| 73 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 74 | struct buffers { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 75 | const char *name; |
| 76 | const struct create *create; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 77 | const struct access_mode *mode; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 78 | const struct size *size; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 79 | drm_intel_bufmgr *bufmgr; |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 80 | struct intel_batchbuffer *batch; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 81 | drm_intel_bo **src, **dst; |
| 82 | drm_intel_bo *snoop, *spare; |
| 83 | uint32_t *tmp; |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 84 | int width, height, npixels, page_size; |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 85 | int count, num_buffers; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Chris Wilson | 571b876 | 2016-01-08 11:51:56 +0000 | [diff] [blame] | 88 | #define MIN_BUFFERS 3 |
| 89 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 90 | static void blt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src); |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 91 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 92 | static void |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 93 | nop_release_bo(drm_intel_bo *bo) |
| 94 | { |
| 95 | drm_intel_bo_unreference(bo); |
| 96 | } |
| 97 | |
| 98 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 99 | prw_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 100 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 101 | for (int i = 0; i < b->npixels; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 102 | b->tmp[i] = val; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 103 | drm_intel_bo_subdata(bo, 0, 4*b->npixels, b->tmp); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 107 | prw_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 108 | { |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 109 | uint32_t *vaddr; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 110 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 111 | vaddr = b->tmp; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 112 | do_or_die(drm_intel_bo_get_subdata(bo, 0, 4*b->npixels, vaddr)); |
| 113 | for (int i = 0; i < b->npixels; i++) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 114 | igt_assert_eq_u32(vaddr[i], val); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 117 | #define pixel(y, width) ((y)*(width) + (((y) + pass)%(width))) |
| 118 | |
| 119 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 120 | partial_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 121 | { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 122 | for (int y = 0; y < b->height; y++) |
| 123 | do_or_die(drm_intel_bo_subdata(bo, 4*pixel(y, b->width), 4, &val)); |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 127 | partial_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 128 | { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 129 | for (int y = 0; y < b->height; y++) { |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 130 | uint32_t buf; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 131 | do_or_die(drm_intel_bo_get_subdata(bo, 4*pixel(y, b->width), 4, &buf)); |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 132 | igt_assert_eq_u32(buf, val); |
| 133 | } |
| 134 | } |
| 135 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 136 | static drm_intel_bo * |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 137 | create_normal_bo(drm_intel_bufmgr *bufmgr, uint64_t size) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 138 | { |
| 139 | drm_intel_bo *bo; |
| 140 | |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 141 | bo = drm_intel_bo_alloc(bufmgr, "bo", size, 0); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 142 | igt_assert(bo); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 143 | |
| 144 | return bo; |
| 145 | } |
| 146 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 147 | static void can_create_normal(const struct create *create, unsigned count) |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 148 | { |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 151 | #if HAVE_CREATE_PRIVATE |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 152 | static drm_intel_bo * |
| 153 | create_private_bo(drm_intel_bufmgr *bufmgr, uint64_t size) |
| 154 | { |
| 155 | drm_intel_bo *bo; |
| 156 | uint32_t handle; |
| 157 | |
| 158 | /* XXX gem_create_with_flags(fd, size, I915_CREATE_PRIVATE); */ |
| 159 | |
| 160 | handle = gem_create(fd, size); |
| 161 | bo = gem_handle_to_libdrm_bo(bufmgr, fd, "stolen", handle); |
| 162 | gem_close(fd, handle); |
| 163 | |
| 164 | return bo; |
| 165 | } |
| 166 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 167 | static void can_create_private(const struct create *create, unsigned count) |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 168 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 169 | igt_require(0); |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 170 | } |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 171 | #endif |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 172 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 173 | #if HAVE_CREATE_STOLEN |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 174 | static drm_intel_bo * |
| 175 | create_stolen_bo(drm_intel_bufmgr *bufmgr, uint64_t size) |
| 176 | { |
| 177 | drm_intel_bo *bo; |
| 178 | uint32_t handle; |
| 179 | |
| 180 | /* XXX gem_create_with_flags(fd, size, I915_CREATE_STOLEN); */ |
| 181 | |
| 182 | handle = gem_create(fd, size); |
| 183 | bo = gem_handle_to_libdrm_bo(bufmgr, fd, "stolen", handle); |
| 184 | gem_close(fd, handle); |
| 185 | |
| 186 | return bo; |
| 187 | } |
| 188 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 189 | static void can_create_stolen(const struct create *create, unsigned count) |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 190 | { |
| 191 | /* XXX check num_buffers against available stolen */ |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 192 | igt_require(0); |
| 193 | } |
| 194 | #endif |
| 195 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 196 | static void create_cpu_require(const struct create *create, unsigned count) |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 197 | { |
| 198 | #if HAVE_CREATE_STOLEN |
| 199 | igt_require(create->create != create_stolen_bo); |
| 200 | #endif |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 204 | unmapped_create_bo(const struct buffers *b) |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 205 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 206 | return b->create->create(b->bufmgr, 4*b->npixels); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 209 | static void create_snoop_require(const struct create *create, unsigned count) |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 210 | { |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 211 | create_cpu_require(create, count); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 212 | igt_require(!gem_has_llc(fd)); |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 216 | snoop_create_bo(const struct buffers *b) |
Chris Wilson | 46ec33e | 2015-10-20 14:40:50 +0100 | [diff] [blame] | 217 | { |
| 218 | drm_intel_bo *bo; |
| 219 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 220 | bo = unmapped_create_bo(b); |
Chris Wilson | 46ec33e | 2015-10-20 14:40:50 +0100 | [diff] [blame] | 221 | gem_set_caching(fd, bo->handle, I915_CACHING_CACHED); |
| 222 | drm_intel_bo_disable_reuse(bo); |
| 223 | |
| 224 | return bo; |
| 225 | } |
| 226 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 227 | static void create_userptr_require(const struct create *create, unsigned count) |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 228 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 229 | static int has_userptr = -1; |
| 230 | if (has_userptr < 0) { |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 231 | struct drm_i915_gem_userptr arg; |
| 232 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 233 | has_userptr = 0; |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 234 | |
| 235 | memset(&arg, 0, sizeof(arg)); |
| 236 | arg.user_ptr = -4096ULL; |
| 237 | arg.user_size = 8192; |
| 238 | errno = 0; |
| 239 | drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &arg); |
| 240 | if (errno == EFAULT) { |
| 241 | igt_assert(posix_memalign((void **)&arg.user_ptr, |
| 242 | 4096, arg.user_size) == 0); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 243 | has_userptr = drmIoctl(fd, |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 244 | LOCAL_IOCTL_I915_GEM_USERPTR, |
| 245 | &arg) == 0; |
| 246 | free((void *)(uintptr_t)arg.user_ptr); |
| 247 | } |
| 248 | |
| 249 | } |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 250 | igt_require(has_userptr); |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 254 | userptr_create_bo(const struct buffers *b) |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 255 | { |
| 256 | struct local_i915_gem_userptr userptr; |
| 257 | drm_intel_bo *bo; |
Chris Wilson | d4a05bc | 2016-01-23 09:07:12 +0000 | [diff] [blame] | 258 | void *ptr; |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 259 | |
| 260 | memset(&userptr, 0, sizeof(userptr)); |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 261 | userptr.user_size = b->page_size; |
Chris Wilson | d4a05bc | 2016-01-23 09:07:12 +0000 | [diff] [blame] | 262 | |
| 263 | ptr = mmap(NULL, userptr.user_size, |
| 264 | PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); |
| 265 | igt_assert(ptr != (void *)-1); |
| 266 | userptr.user_ptr = (uintptr_t)ptr; |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 267 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 268 | #if 0 |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 269 | do_or_die(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &userptr)); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 270 | bo = gem_handle_to_libdrm_bo(b->bufmgr, fd, "userptr", userptr.handle); |
Chris Wilson | a64f31b | 2016-01-27 11:19:26 +0000 | [diff] [blame] | 271 | gem_close(fd, userptr.handle); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 272 | #else |
| 273 | bo = drm_intel_bo_alloc_userptr(b->bufmgr, "name", |
| 274 | ptr, I915_TILING_NONE, 0, |
| 275 | userptr.user_size, 0); |
| 276 | igt_assert(bo); |
| 277 | #endif |
| 278 | bo->virtual = (void *)(uintptr_t)userptr.user_ptr; |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 279 | |
| 280 | return bo; |
| 281 | } |
| 282 | |
| 283 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 284 | userptr_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 285 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 286 | int size = b->npixels; |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 287 | uint32_t *vaddr = bo->virtual; |
| 288 | |
| 289 | gem_set_domain(fd, bo->handle, |
| 290 | I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); |
| 291 | while (size--) |
| 292 | *vaddr++ = val; |
| 293 | } |
| 294 | |
| 295 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 296 | userptr_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 297 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 298 | int size = b->npixels; |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 299 | uint32_t *vaddr = bo->virtual; |
| 300 | |
| 301 | gem_set_domain(fd, bo->handle, |
| 302 | I915_GEM_DOMAIN_CPU, 0); |
| 303 | while (size--) |
| 304 | igt_assert_eq_u32(*vaddr++, val); |
| 305 | } |
| 306 | |
| 307 | static void |
| 308 | userptr_release_bo(drm_intel_bo *bo) |
| 309 | { |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 310 | igt_assert(bo->virtual); |
| 311 | |
Chris Wilson | d4a05bc | 2016-01-23 09:07:12 +0000 | [diff] [blame] | 312 | munmap(bo->virtual, bo->size); |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 313 | bo->virtual = NULL; |
| 314 | |
| 315 | drm_intel_bo_unreference(bo); |
| 316 | } |
| 317 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 318 | static void create_dmabuf_require(const struct create *create, unsigned count) |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 319 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 320 | static int has_dmabuf = -1; |
| 321 | if (has_dmabuf < 0) { |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 322 | struct drm_prime_handle args; |
| 323 | void *ptr; |
| 324 | |
| 325 | memset(&args, 0, sizeof(args)); |
| 326 | args.handle = gem_create(fd, 4096); |
| 327 | args.flags = DRM_RDWR; |
| 328 | args.fd = -1; |
| 329 | |
| 330 | drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); |
| 331 | gem_close(fd, args.handle); |
| 332 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 333 | has_dmabuf = 0; |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 334 | ptr = mmap(NULL, 4096, PROT_READ, MAP_SHARED, args.fd, 0); |
| 335 | if (ptr != MAP_FAILED) { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 336 | has_dmabuf = 1; |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 337 | munmap(ptr, 4096); |
| 338 | } |
| 339 | |
| 340 | close(args.fd); |
| 341 | } |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 342 | igt_require(has_dmabuf); |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 343 | intel_require_files(2*count); |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | struct dmabuf { |
| 347 | int fd; |
| 348 | void *map; |
| 349 | }; |
| 350 | |
| 351 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 352 | dmabuf_create_bo(const struct buffers *b) |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 353 | { |
| 354 | struct drm_prime_handle args; |
| 355 | drm_intel_bo *bo; |
| 356 | struct dmabuf *dmabuf; |
| 357 | int size; |
| 358 | |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 359 | size = b->page_size; |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 360 | |
| 361 | memset(&args, 0, sizeof(args)); |
| 362 | args.handle = gem_create(fd, size); |
| 363 | args.flags = DRM_RDWR; |
| 364 | args.fd = -1; |
| 365 | |
| 366 | do_ioctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); |
| 367 | gem_close(fd, args.handle); |
| 368 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 369 | bo = drm_intel_bo_gem_create_from_prime(b->bufmgr, args.fd, size); |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 370 | igt_assert(bo); |
| 371 | |
| 372 | dmabuf = malloc(sizeof(*dmabuf)); |
| 373 | igt_assert(dmabuf); |
| 374 | |
| 375 | dmabuf->fd = args.fd; |
| 376 | dmabuf->map = mmap(NULL, size, |
| 377 | PROT_READ | PROT_WRITE, MAP_SHARED, |
| 378 | dmabuf->fd, 0); |
| 379 | igt_assert(dmabuf->map != (void *)-1); |
| 380 | |
| 381 | bo->virtual = dmabuf; |
| 382 | |
| 383 | return bo; |
| 384 | } |
| 385 | |
| 386 | static void |
| 387 | dmabuf_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
| 388 | { |
| 389 | struct dmabuf *dmabuf = bo->virtual; |
Chris Wilson | c7f6ecc | 2016-09-25 09:09:02 +0100 | [diff] [blame^] | 390 | uint32_t *v = dmabuf->map; |
| 391 | int y; |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 392 | |
Chris Wilson | aed69b5 | 2016-02-25 21:43:01 +0000 | [diff] [blame] | 393 | prime_sync_start(dmabuf->fd, true); |
Chris Wilson | c7f6ecc | 2016-09-25 09:09:02 +0100 | [diff] [blame^] | 394 | for (y = 0; y < b->height; y++) |
| 395 | v[pixel(y, b->width)] = val; |
Chris Wilson | aed69b5 | 2016-02-25 21:43:01 +0000 | [diff] [blame] | 396 | prime_sync_end(dmabuf->fd, true); |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static void |
| 400 | dmabuf_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
| 401 | { |
| 402 | struct dmabuf *dmabuf = bo->virtual; |
Chris Wilson | c7f6ecc | 2016-09-25 09:09:02 +0100 | [diff] [blame^] | 403 | uint32_t *v = dmabuf->map; |
| 404 | int y; |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 405 | |
Chris Wilson | aed69b5 | 2016-02-25 21:43:01 +0000 | [diff] [blame] | 406 | prime_sync_start(dmabuf->fd, false); |
Chris Wilson | c7f6ecc | 2016-09-25 09:09:02 +0100 | [diff] [blame^] | 407 | for (y = 0; y < b->height; y++) |
| 408 | igt_assert_eq_u32(v[pixel(y, b->width)], val); |
Chris Wilson | aed69b5 | 2016-02-25 21:43:01 +0000 | [diff] [blame] | 409 | prime_sync_end(dmabuf->fd, false); |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void |
| 413 | dmabuf_release_bo(drm_intel_bo *bo) |
| 414 | { |
| 415 | struct dmabuf *dmabuf = bo->virtual; |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 416 | igt_assert(dmabuf); |
Chris Wilson | cf569c2 | 2016-02-25 17:58:24 +0000 | [diff] [blame] | 417 | |
| 418 | munmap(dmabuf->map, bo->size); |
| 419 | close(dmabuf->fd); |
| 420 | free(dmabuf); |
| 421 | |
| 422 | bo->virtual = NULL; |
| 423 | drm_intel_bo_unreference(bo); |
| 424 | } |
| 425 | |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 426 | static bool has_prime_export(int _fd) |
| 427 | { |
| 428 | uint64_t value; |
| 429 | |
| 430 | if (drmGetCap(_fd, DRM_CAP_PRIME, &value)) |
| 431 | return false; |
| 432 | |
| 433 | return value & DRM_PRIME_CAP_EXPORT; |
| 434 | } |
| 435 | |
| 436 | static void create_vgem_require(const struct create *create, unsigned count) |
| 437 | { |
| 438 | igt_require(vgem_drv != -1); |
| 439 | igt_require(has_prime_export(vgem_drv)); |
| 440 | create_dmabuf_require(create, count); |
| 441 | } |
| 442 | |
| 443 | static drm_intel_bo * |
| 444 | vgem_create_bo(const struct buffers *b) |
| 445 | { |
| 446 | struct drm_prime_handle args; |
| 447 | drm_intel_bo *bo; |
| 448 | struct vgem_bo vgem; |
| 449 | struct dmabuf *dmabuf; |
| 450 | |
| 451 | igt_assert(vgem_drv != -1); |
| 452 | |
| 453 | vgem.width = b->width; |
| 454 | vgem.height = b->height; |
| 455 | vgem.bpp = 32; |
| 456 | vgem_create(vgem_drv, &vgem); |
| 457 | |
| 458 | memset(&args, 0, sizeof(args)); |
| 459 | args.handle = vgem.handle; |
| 460 | args.flags = DRM_RDWR; |
| 461 | args.fd = -1; |
| 462 | |
| 463 | do_ioctl(vgem_drv, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); |
| 464 | gem_close(vgem_drv, args.handle); |
| 465 | igt_assert(args.fd != -1); |
| 466 | |
| 467 | bo = drm_intel_bo_gem_create_from_prime(b->bufmgr, args.fd, vgem.size); |
| 468 | igt_assert(bo); |
| 469 | |
| 470 | dmabuf = malloc(sizeof(*dmabuf)); |
| 471 | igt_assert(dmabuf); |
| 472 | |
| 473 | dmabuf->fd = args.fd; |
| 474 | dmabuf->map = mmap(NULL, vgem.size, |
| 475 | PROT_READ | PROT_WRITE, MAP_SHARED, |
| 476 | dmabuf->fd, 0); |
| 477 | igt_assert(dmabuf->map != (void *)-1); |
| 478 | |
| 479 | bo->virtual = dmabuf; |
| 480 | |
| 481 | return bo; |
| 482 | } |
| 483 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 484 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 485 | gtt_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 486 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 487 | uint32_t *vaddr = bo->virtual; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 488 | int size = b->npixels; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 489 | |
| 490 | drm_intel_gem_bo_start_gtt_access(bo, true); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 491 | while (size--) |
| 492 | *vaddr++ = val; |
| 493 | } |
| 494 | |
| 495 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 496 | gtt_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 497 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 498 | uint32_t *vaddr = bo->virtual; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 499 | |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 500 | /* GTT access is slow. So we just compare a few points */ |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 501 | drm_intel_gem_bo_start_gtt_access(bo, false); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 502 | for (int y = 0; y < b->height; y++) |
| 503 | igt_assert_eq_u32(vaddr[pixel(y, b->width)], val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 507 | map_bo(drm_intel_bo *bo) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 508 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 509 | /* gtt map doesn't have a write parameter, so just keep the mapping |
| 510 | * around (to avoid the set_domain with the gtt write domain set) and |
| 511 | * manually tell the kernel when we start access the gtt. */ |
| 512 | do_or_die(drm_intel_gem_bo_map_gtt(bo)); |
| 513 | |
| 514 | return bo; |
| 515 | } |
| 516 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 517 | static drm_intel_bo * |
| 518 | tile_bo(drm_intel_bo *bo, int width) |
| 519 | { |
| 520 | uint32_t tiling = I915_TILING_X; |
| 521 | uint32_t stride = width * 4; |
| 522 | |
| 523 | do_or_die(drm_intel_bo_set_tiling(bo, &tiling, stride)); |
| 524 | |
| 525 | return bo; |
| 526 | } |
| 527 | |
| 528 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 529 | gtt_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 530 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 531 | return map_bo(unmapped_create_bo(b)); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 535 | gttX_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 536 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 537 | return tile_bo(gtt_create_bo(b), b->width); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 540 | static void bit17_require(void) |
| 541 | { |
| 542 | static struct drm_i915_gem_get_tiling2 { |
| 543 | uint32_t handle; |
| 544 | uint32_t tiling_mode; |
| 545 | uint32_t swizzle_mode; |
| 546 | uint32_t phys_swizzle_mode; |
| 547 | } arg; |
| 548 | #define DRM_IOCTL_I915_GEM_GET_TILING2 DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling2) |
| 549 | |
| 550 | if (arg.handle == 0) { |
| 551 | arg.handle = gem_create(fd, 4096); |
| 552 | gem_set_tiling(fd, arg.handle, I915_TILING_X, 512); |
| 553 | |
| 554 | do_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING2, &arg); |
| 555 | gem_close(fd, arg.handle); |
| 556 | } |
| 557 | igt_require(arg.phys_swizzle_mode == arg.swizzle_mode); |
| 558 | } |
| 559 | |
| 560 | static void wc_require(void) |
| 561 | { |
| 562 | bit17_require(); |
| 563 | gem_require_mmap_wc(fd); |
| 564 | } |
| 565 | |
| 566 | static void |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 567 | wc_create_require(const struct create *create, unsigned count) |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 568 | { |
| 569 | wc_require(); |
| 570 | } |
| 571 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 572 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 573 | wc_create_bo(const struct buffers *b) |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 574 | { |
| 575 | drm_intel_bo *bo; |
| 576 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 577 | bo = unmapped_create_bo(b); |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 578 | 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] | 579 | return bo; |
| 580 | } |
| 581 | |
| 582 | static void |
| 583 | wc_release_bo(drm_intel_bo *bo) |
| 584 | { |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 585 | igt_assert(bo->virtual); |
| 586 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 587 | munmap(bo->virtual, bo->size); |
| 588 | bo->virtual = NULL; |
| 589 | |
| 590 | nop_release_bo(bo); |
| 591 | } |
| 592 | |
| 593 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 594 | gpu_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 595 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 596 | return unmapped_create_bo(b); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 599 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 600 | gpuX_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 601 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 602 | return tile_bo(gpu_create_bo(b), b->width); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 605 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 606 | cpu_set_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 607 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 608 | int size = b->npixels; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 609 | uint32_t *vaddr; |
| 610 | |
| 611 | do_or_die(drm_intel_bo_map(bo, true)); |
| 612 | vaddr = bo->virtual; |
| 613 | while (size--) |
| 614 | *vaddr++ = val; |
| 615 | drm_intel_bo_unmap(bo); |
| 616 | } |
| 617 | |
| 618 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 619 | cpu_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 620 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 621 | int size = b->npixels; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 622 | uint32_t *vaddr; |
| 623 | |
| 624 | do_or_die(drm_intel_bo_map(bo, false)); |
| 625 | vaddr = bo->virtual; |
| 626 | while (size--) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 627 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 628 | drm_intel_bo_unmap(bo); |
| 629 | } |
| 630 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 631 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 632 | gpu_set_bo(struct buffers *buffers, drm_intel_bo *bo, uint32_t val) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 633 | { |
| 634 | struct drm_i915_gem_relocation_entry reloc[1]; |
| 635 | struct drm_i915_gem_exec_object2 gem_exec[2]; |
| 636 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 637 | uint32_t buf[10], *b; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 638 | uint32_t tiling, swizzle; |
| 639 | |
| 640 | drm_intel_bo_get_tiling(bo, &tiling, &swizzle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 641 | |
| 642 | memset(reloc, 0, sizeof(reloc)); |
| 643 | memset(gem_exec, 0, sizeof(gem_exec)); |
| 644 | memset(&execbuf, 0, sizeof(execbuf)); |
| 645 | |
| 646 | b = buf; |
| 647 | *b++ = XY_COLOR_BLT_CMD_NOLEN | |
| 648 | ((gen >= 8) ? 5 : 4) | |
| 649 | COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 650 | if (gen >= 4 && tiling) { |
| 651 | b[-1] |= XY_COLOR_BLT_TILED; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 652 | *b = buffers->width; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 653 | } else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 654 | *b = buffers->width << 2; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 655 | *b++ |= 0xf0 << 16 | 1 << 25 | 1 << 24; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 656 | *b++ = 0; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 657 | *b++ = buffers->height << 16 | buffers->width; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 658 | reloc[0].offset = (b - buf) * sizeof(uint32_t); |
| 659 | reloc[0].target_handle = bo->handle; |
| 660 | reloc[0].read_domains = I915_GEM_DOMAIN_RENDER; |
| 661 | reloc[0].write_domain = I915_GEM_DOMAIN_RENDER; |
| 662 | *b++ = 0; |
| 663 | if (gen >= 8) |
| 664 | *b++ = 0; |
| 665 | *b++ = val; |
| 666 | *b++ = MI_BATCH_BUFFER_END; |
| 667 | if ((b - buf) & 1) |
| 668 | *b++ = 0; |
| 669 | |
| 670 | gem_exec[0].handle = bo->handle; |
| 671 | gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE; |
| 672 | |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 673 | gem_exec[1].handle = gem_create(fd, 4096); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 674 | gem_exec[1].relocation_count = 1; |
| 675 | gem_exec[1].relocs_ptr = (uintptr_t)reloc; |
| 676 | |
| 677 | execbuf.buffers_ptr = (uintptr_t)gem_exec; |
| 678 | execbuf.buffer_count = 2; |
| 679 | execbuf.batch_len = (b - buf) * sizeof(buf[0]); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 680 | if (gen >= 6) |
| 681 | execbuf.flags = I915_EXEC_BLT; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 682 | |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 683 | gem_write(fd, gem_exec[1].handle, 0, buf, execbuf.batch_len); |
| 684 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 685 | |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 686 | gem_close(fd, gem_exec[1].handle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 690 | gpu_cmp_bo(struct buffers *b, drm_intel_bo *bo, uint32_t val) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 691 | { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 692 | blt_copy_bo(b, b->snoop, bo); |
| 693 | cpu_cmp_bo(b, b->snoop, val); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 694 | } |
| 695 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 696 | struct access_mode { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 697 | const char *name; |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 698 | void (*require)(const struct create *, unsigned); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 699 | drm_intel_bo *(*create_bo)(const struct buffers *b); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 700 | void (*set_bo)(struct buffers *b, drm_intel_bo *bo, uint32_t val); |
| 701 | void (*cmp_bo)(struct buffers *b, drm_intel_bo *bo, uint32_t val); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 702 | void (*release_bo)(drm_intel_bo *bo); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 703 | }; |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 704 | igt_render_copyfunc_t rendercopy; |
| 705 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 706 | static int read_sysctl(const char *path) |
| 707 | { |
| 708 | FILE *file = fopen(path, "r"); |
| 709 | int max = 0; |
| 710 | if (file) { |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 711 | if (fscanf(file, "%d", &max) != 1) |
| 712 | max = 0; /* silence! */ |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 713 | fclose(file); |
| 714 | } |
| 715 | return max; |
| 716 | } |
| 717 | |
| 718 | static int write_sysctl(const char *path, int value) |
| 719 | { |
| 720 | FILE *file = fopen(path, "w"); |
| 721 | if (file) { |
| 722 | fprintf(file, "%d", value); |
| 723 | fclose(file); |
| 724 | } |
| 725 | return read_sysctl(path); |
| 726 | } |
| 727 | |
| 728 | static bool set_max_map_count(int num_buffers) |
| 729 | { |
| 730 | int max = read_sysctl("/proc/sys/vm/max_map_count"); |
| 731 | if (max < num_buffers + 1024) |
| 732 | max = write_sysctl("/proc/sys/vm/max_map_count", |
| 733 | num_buffers + 1024); |
| 734 | return max > num_buffers; |
| 735 | } |
| 736 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 737 | static void buffers_init(struct buffers *b, |
| 738 | const char *name, |
| 739 | const struct create *create, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 740 | const struct access_mode *mode, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 741 | const struct size *size, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 742 | int num_buffers, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 743 | int _fd, int enable_reuse) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 744 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 745 | memset(b, 0, sizeof(*b)); |
| 746 | b->name = name; |
| 747 | b->create = create; |
| 748 | b->mode = mode; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 749 | b->size = size; |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 750 | b->num_buffers = num_buffers; |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 751 | b->count = 0; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 752 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 753 | b->width = size->width; |
| 754 | b->height = size->height; |
| 755 | b->npixels = size->width * size->height; |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 756 | b->page_size = 4*b->npixels; |
| 757 | b->page_size = (b->page_size + 4095) & -4096; |
| 758 | b->tmp = malloc(b->page_size); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 759 | igt_assert(b->tmp); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 760 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 761 | b->bufmgr = drm_intel_bufmgr_gem_init(_fd, 4096); |
| 762 | igt_assert(b->bufmgr); |
| 763 | |
| 764 | b->src = malloc(2*sizeof(drm_intel_bo *)*num_buffers); |
| 765 | igt_assert(b->src); |
| 766 | b->dst = b->src + num_buffers; |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 767 | |
Chris Wilson | a1b47ef | 2016-01-27 19:44:16 +0000 | [diff] [blame] | 768 | if (enable_reuse) |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 769 | drm_intel_bufmgr_gem_enable_reuse(b->bufmgr); |
| 770 | b->batch = intel_batchbuffer_alloc(b->bufmgr, devid); |
| 771 | igt_assert(b->batch); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 774 | static void buffers_destroy(struct buffers *b) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 775 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 776 | int count = b->count; |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 777 | if (count == 0) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 778 | return; |
| 779 | |
Chris Wilson | c19b049 | 2016-03-20 11:13:30 +0000 | [diff] [blame] | 780 | /* Be safe so that we can clean up a partial creation */ |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 781 | b->count = 0; |
Chris Wilson | c19b049 | 2016-03-20 11:13:30 +0000 | [diff] [blame] | 782 | for (int i = 0; i < count; i++) { |
| 783 | if (b->src[i]) { |
| 784 | b->mode->release_bo(b->src[i]); |
| 785 | b->src[i] = NULL; |
| 786 | } else |
| 787 | break; |
| 788 | |
| 789 | if (b->dst[i]) { |
| 790 | b->mode->release_bo(b->dst[i]); |
| 791 | b->dst[i] = NULL; |
| 792 | } |
| 793 | } |
| 794 | if (b->snoop) { |
| 795 | nop_release_bo(b->snoop); |
| 796 | b->snoop = NULL; |
| 797 | } |
| 798 | if (b->spare) { |
| 799 | b->mode->release_bo(b->spare); |
| 800 | b->spare = NULL; |
| 801 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 804 | static void buffers_create(struct buffers *b) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 805 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 806 | int count = b->num_buffers; |
| 807 | igt_assert(b->bufmgr); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 808 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 809 | buffers_destroy(b); |
| 810 | igt_assert(b->count == 0); |
Chris Wilson | c19b049 | 2016-03-20 11:13:30 +0000 | [diff] [blame] | 811 | b->count = count; |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 812 | |
| 813 | for (int i = 0; i < count; i++) { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 814 | b->src[i] = b->mode->create_bo(b); |
| 815 | b->dst[i] = b->mode->create_bo(b); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 816 | } |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 817 | b->spare = b->mode->create_bo(b); |
| 818 | b->snoop = snoop_create_bo(b); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 821 | static void buffers_reset(struct buffers *b, bool enable_reuse) |
| 822 | { |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 823 | b->bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 824 | igt_assert(b->bufmgr); |
| 825 | |
| 826 | if (enable_reuse) |
| 827 | drm_intel_bufmgr_gem_enable_reuse(b->bufmgr); |
| 828 | b->batch = intel_batchbuffer_alloc(b->bufmgr, devid); |
| 829 | igt_assert(b->batch); |
| 830 | } |
| 831 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 832 | static void buffers_fini(struct buffers *b) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 833 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 834 | if (b->bufmgr == NULL) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 835 | return; |
| 836 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 837 | buffers_destroy(b); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 838 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 839 | free(b->tmp); |
| 840 | free(b->src); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 841 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 842 | intel_batchbuffer_free(b->batch); |
| 843 | drm_intel_bufmgr_destroy(b->bufmgr); |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 844 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 845 | memset(b, 0, sizeof(*b)); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 848 | typedef void (*do_copy)(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src); |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 849 | typedef igt_hang_t (*do_hang)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 850 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 851 | static void render_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 852 | { |
| 853 | struct igt_buf d = { |
| 854 | .bo = dst, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 855 | .size = b->npixels * 4, |
| 856 | .num_tiles = b->npixels * 4, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 857 | .stride = b->width * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 858 | }, s = { |
| 859 | .bo = src, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 860 | .size = b->npixels * 4, |
| 861 | .num_tiles = b->npixels * 4, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 862 | .stride = b->width * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 863 | }; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 864 | uint32_t swizzle; |
| 865 | |
| 866 | drm_intel_bo_get_tiling(dst, &d.tiling, &swizzle); |
| 867 | drm_intel_bo_get_tiling(src, &s.tiling, &swizzle); |
| 868 | |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 869 | rendercopy(b->batch, NULL, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 870 | &s, 0, 0, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 871 | b->width, b->height, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 872 | &d, 0, 0); |
| 873 | } |
| 874 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 875 | static void blt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 876 | { |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 877 | intel_blt_copy(b->batch, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 878 | src, 0, 0, 4*b->width, |
| 879 | dst, 0, 0, 4*b->width, |
| 880 | b->width, b->height, 32); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 881 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 882 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 883 | static void cpu_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src) |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 884 | { |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 885 | const int size = b->page_size; |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 886 | void *d, *s; |
| 887 | |
| 888 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0); |
| 889 | 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] | 890 | s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ); |
| 891 | d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 892 | |
| 893 | memcpy(d, s, size); |
| 894 | |
| 895 | munmap(d, size); |
| 896 | munmap(s, size); |
| 897 | } |
| 898 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 899 | static void gtt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src) |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 900 | { |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 901 | const int size = b->page_size; |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 902 | void *d, *s; |
| 903 | |
| 904 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 905 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 906 | |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 907 | s = gem_mmap__gtt(fd, src->handle, size, PROT_READ); |
| 908 | d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 909 | |
| 910 | memcpy(d, s, size); |
| 911 | |
| 912 | munmap(d, size); |
| 913 | munmap(s, size); |
| 914 | } |
| 915 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 916 | static void wc_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src) |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 917 | { |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 918 | const int size = b->page_size; |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 919 | void *d, *s; |
| 920 | |
| 921 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 922 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 923 | |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 924 | s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ); |
| 925 | d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 926 | |
| 927 | memcpy(d, s, size); |
| 928 | |
| 929 | munmap(d, size); |
| 930 | munmap(s, size); |
| 931 | } |
| 932 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 933 | static igt_hang_t no_hang(void) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 934 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 935 | return (igt_hang_t){0, 0}; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 938 | static igt_hang_t bcs_hang(void) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 939 | { |
Daniel Vetter | 3cd45de | 2015-02-10 17:46:43 +0100 | [diff] [blame] | 940 | return igt_hang_ring(fd, I915_EXEC_BLT); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 941 | } |
| 942 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 943 | static igt_hang_t rcs_hang(void) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 944 | { |
Daniel Vetter | 3cd45de | 2015-02-10 17:46:43 +0100 | [diff] [blame] | 945 | return igt_hang_ring(fd, I915_EXEC_RENDER); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 948 | static igt_hang_t all_hang(void) |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 949 | { |
| 950 | uint32_t bbe = MI_BATCH_BUFFER_END; |
| 951 | struct drm_i915_gem_execbuffer2 execbuf; |
| 952 | struct drm_i915_gem_exec_object2 obj; |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 953 | igt_hang_t hang; |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 954 | unsigned engine; |
| 955 | |
| 956 | memset(&obj, 0, sizeof(obj)); |
| 957 | obj.handle = gem_create(fd, 4096); |
| 958 | gem_write(fd, obj.handle, 0, &bbe, sizeof(&bbe)); |
| 959 | |
| 960 | memset(&execbuf, 0, sizeof(execbuf)); |
| 961 | execbuf.buffers_ptr = (uintptr_t)&obj; |
| 962 | execbuf.buffer_count = 1; |
| 963 | |
| 964 | for_each_engine(fd, engine) { |
| 965 | hang = igt_hang_ring(fd, engine); |
| 966 | |
| 967 | execbuf.flags = engine; |
| 968 | __gem_execbuf(fd, &execbuf); |
| 969 | |
| 970 | gem_close(fd, hang.handle); |
| 971 | } |
| 972 | |
| 973 | hang.handle = obj.handle; |
| 974 | return hang; |
| 975 | } |
| 976 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 977 | static void do_basic0(struct buffers *buffers, |
| 978 | do_copy do_copy_func, |
| 979 | do_hang do_hang_func) |
| 980 | { |
| 981 | gem_quiescent_gpu(fd); |
| 982 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 983 | buffers->mode->set_bo(buffers, buffers->src[0], 0xdeadbeef); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 984 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 985 | igt_hang_t hang = do_hang_func(); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 986 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 987 | do_copy_func(buffers, buffers->dst[i], buffers->src[0]); |
| 988 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 989 | |
| 990 | igt_post_hang_ring(fd, hang); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | static void do_basic1(struct buffers *buffers, |
| 995 | do_copy do_copy_func, |
| 996 | do_hang do_hang_func) |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 997 | { |
| 998 | gem_quiescent_gpu(fd); |
| 999 | |
| 1000 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1001 | igt_hang_t hang = do_hang_func(); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 1002 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1003 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1004 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1005 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1006 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1007 | usleep(0); /* let someone else claim the mutex */ |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1008 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 1009 | |
| 1010 | igt_post_hang_ring(fd, hang); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1014 | static void do_basicN(struct buffers *buffers, |
| 1015 | do_copy do_copy_func, |
| 1016 | do_hang do_hang_func) |
| 1017 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1018 | igt_hang_t hang; |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1019 | |
| 1020 | gem_quiescent_gpu(fd); |
| 1021 | |
| 1022 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1023 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1024 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | hang = do_hang_func(); |
| 1028 | |
| 1029 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1030 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1031 | usleep(0); /* let someone else claim the mutex */ |
| 1032 | } |
| 1033 | |
| 1034 | for (int i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1035 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1036 | |
| 1037 | igt_post_hang_ring(fd, hang); |
| 1038 | } |
| 1039 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1040 | static void do_overwrite_source(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1041 | do_copy do_copy_func, |
| 1042 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1043 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1044 | igt_hang_t hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1045 | int i; |
| 1046 | |
| 1047 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1048 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1049 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1050 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1051 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1052 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1053 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1054 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1055 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1056 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1057 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1058 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1059 | igt_post_hang_ring(fd, hang); |
| 1060 | } |
| 1061 | |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1062 | static void do_overwrite_source_read(struct buffers *buffers, |
| 1063 | do_copy do_copy_func, |
| 1064 | do_hang do_hang_func, |
| 1065 | int do_rcs) |
| 1066 | { |
| 1067 | const int half = buffers->count/2; |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1068 | igt_hang_t hang; |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1069 | int i; |
| 1070 | |
| 1071 | gem_quiescent_gpu(fd); |
| 1072 | for (i = 0; i < half; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1073 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1074 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
| 1075 | buffers->mode->set_bo(buffers, buffers->dst[i+half], ~i); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1076 | } |
| 1077 | for (i = 0; i < half; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1078 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1079 | if (do_rcs) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1080 | render_copy_bo(buffers, buffers->dst[i+half], buffers->src[i]); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1081 | else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1082 | blt_copy_bo(buffers, buffers->dst[i+half], buffers->src[i]); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1083 | } |
| 1084 | hang = do_hang_func(); |
| 1085 | for (i = half; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1086 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1087 | for (i = 0; i < half; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1088 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
| 1089 | buffers->mode->cmp_bo(buffers, buffers->dst[i+half], i); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1090 | } |
| 1091 | igt_post_hang_ring(fd, hang); |
| 1092 | } |
| 1093 | |
| 1094 | static void do_overwrite_source_read_bcs(struct buffers *buffers, |
| 1095 | do_copy do_copy_func, |
| 1096 | do_hang do_hang_func) |
| 1097 | { |
| 1098 | do_overwrite_source_read(buffers, do_copy_func, do_hang_func, 0); |
| 1099 | } |
| 1100 | |
| 1101 | static void do_overwrite_source_read_rcs(struct buffers *buffers, |
| 1102 | do_copy do_copy_func, |
| 1103 | do_hang do_hang_func) |
| 1104 | { |
| 1105 | do_overwrite_source_read(buffers, do_copy_func, do_hang_func, 1); |
| 1106 | } |
| 1107 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1108 | static void do_overwrite_source__rev(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1109 | do_copy do_copy_func, |
| 1110 | do_hang do_hang_func) |
| 1111 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1112 | igt_hang_t hang; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1113 | int i; |
| 1114 | |
| 1115 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1116 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1117 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1118 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1119 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1120 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1121 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1122 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1123 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1124 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1125 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1126 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1127 | igt_post_hang_ring(fd, hang); |
| 1128 | } |
| 1129 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1130 | static void do_overwrite_source__one(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1131 | do_copy do_copy_func, |
| 1132 | do_hang do_hang_func) |
| 1133 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1134 | igt_hang_t hang; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1135 | |
| 1136 | gem_quiescent_gpu(fd); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1137 | buffers->mode->set_bo(buffers, buffers->src[0], 0); |
| 1138 | buffers->mode->set_bo(buffers, buffers->dst[0], ~0); |
| 1139 | do_copy_func(buffers, buffers->dst[0], buffers->src[0]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1140 | hang = do_hang_func(); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1141 | buffers->mode->set_bo(buffers, buffers->src[0], 0xdeadbeef); |
| 1142 | buffers->mode->cmp_bo(buffers, buffers->dst[0], 0); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1143 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1144 | } |
| 1145 | |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1146 | static void do_intermix(struct buffers *buffers, |
| 1147 | do_copy do_copy_func, |
| 1148 | do_hang do_hang_func, |
| 1149 | int do_rcs) |
| 1150 | { |
| 1151 | const int half = buffers->count/2; |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1152 | igt_hang_t hang; |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1153 | int i; |
| 1154 | |
| 1155 | gem_quiescent_gpu(fd); |
| 1156 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1157 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef^~i); |
| 1158 | buffers->mode->set_bo(buffers, buffers->dst[i], i); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1159 | } |
| 1160 | for (i = 0; i < half; i++) { |
| 1161 | if (do_rcs == 1 || (do_rcs == -1 && i & 1)) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1162 | render_copy_bo(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1163 | else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1164 | blt_copy_bo(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1165 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1166 | do_copy_func(buffers, buffers->dst[i+half], buffers->src[i]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1167 | |
| 1168 | if (do_rcs == 1 || (do_rcs == -1 && (i & 1) == 0)) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1169 | render_copy_bo(buffers, buffers->dst[i], buffers->dst[i+half]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1170 | else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1171 | blt_copy_bo(buffers, buffers->dst[i], buffers->dst[i+half]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1172 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1173 | do_copy_func(buffers, buffers->dst[i+half], buffers->src[i+half]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1174 | } |
| 1175 | hang = do_hang_func(); |
| 1176 | for (i = 0; i < 2*half; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1177 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef^~i); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1178 | igt_post_hang_ring(fd, hang); |
| 1179 | } |
| 1180 | |
| 1181 | static void do_intermix_rcs(struct buffers *buffers, |
| 1182 | do_copy do_copy_func, |
| 1183 | do_hang do_hang_func) |
| 1184 | { |
| 1185 | do_intermix(buffers, do_copy_func, do_hang_func, 1); |
| 1186 | } |
| 1187 | |
| 1188 | static void do_intermix_bcs(struct buffers *buffers, |
| 1189 | do_copy do_copy_func, |
| 1190 | do_hang do_hang_func) |
| 1191 | { |
| 1192 | do_intermix(buffers, do_copy_func, do_hang_func, 0); |
| 1193 | } |
| 1194 | |
| 1195 | static void do_intermix_both(struct buffers *buffers, |
| 1196 | do_copy do_copy_func, |
| 1197 | do_hang do_hang_func) |
| 1198 | { |
| 1199 | do_intermix(buffers, do_copy_func, do_hang_func, -1); |
| 1200 | } |
| 1201 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1202 | static void do_early_read(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1203 | do_copy do_copy_func, |
| 1204 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1205 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1206 | igt_hang_t hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1207 | int i; |
| 1208 | |
| 1209 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1210 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1211 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1212 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1213 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1214 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1215 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1216 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1217 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1220 | static void do_read_read_bcs(struct buffers *buffers, |
| 1221 | do_copy do_copy_func, |
| 1222 | do_hang do_hang_func) |
| 1223 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1224 | igt_hang_t hang; |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1225 | int i; |
| 1226 | |
| 1227 | gem_quiescent_gpu(fd); |
| 1228 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1229 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1230 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1231 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
| 1232 | blt_copy_bo(buffers, buffers->spare, buffers->src[i]); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1233 | } |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1234 | buffers->mode->cmp_bo(buffers, buffers->spare, 0xdeadbeef^(buffers->count-1)); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1235 | hang = do_hang_func(); |
| 1236 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1237 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1238 | igt_post_hang_ring(fd, hang); |
| 1239 | } |
| 1240 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1241 | static void do_write_read_bcs(struct buffers *buffers, |
| 1242 | do_copy do_copy_func, |
| 1243 | do_hang do_hang_func) |
| 1244 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1245 | igt_hang_t hang; |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1246 | int i; |
| 1247 | |
| 1248 | gem_quiescent_gpu(fd); |
| 1249 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1250 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1251 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1252 | blt_copy_bo(buffers, buffers->spare, buffers->src[i]); |
| 1253 | do_copy_func(buffers, buffers->dst[i], buffers->spare); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1254 | } |
| 1255 | hang = do_hang_func(); |
| 1256 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1257 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1258 | igt_post_hang_ring(fd, hang); |
| 1259 | } |
| 1260 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1261 | static void do_read_read_rcs(struct buffers *buffers, |
| 1262 | do_copy do_copy_func, |
| 1263 | do_hang do_hang_func) |
| 1264 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1265 | igt_hang_t hang; |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1266 | int i; |
| 1267 | |
| 1268 | gem_quiescent_gpu(fd); |
| 1269 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1270 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1271 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1272 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
| 1273 | render_copy_bo(buffers, buffers->spare, buffers->src[i]); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1274 | } |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1275 | buffers->mode->cmp_bo(buffers, buffers->spare, 0xdeadbeef^(buffers->count-1)); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1276 | hang = do_hang_func(); |
| 1277 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1278 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1279 | igt_post_hang_ring(fd, hang); |
| 1280 | } |
| 1281 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1282 | static void do_write_read_rcs(struct buffers *buffers, |
| 1283 | do_copy do_copy_func, |
| 1284 | do_hang do_hang_func) |
| 1285 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1286 | igt_hang_t hang; |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1287 | int i; |
| 1288 | |
| 1289 | gem_quiescent_gpu(fd); |
| 1290 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1291 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1292 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1293 | render_copy_bo(buffers, buffers->spare, buffers->src[i]); |
| 1294 | do_copy_func(buffers, buffers->dst[i], buffers->spare); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1295 | } |
| 1296 | hang = do_hang_func(); |
| 1297 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1298 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1299 | igt_post_hang_ring(fd, hang); |
| 1300 | } |
| 1301 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1302 | static void do_gpu_read_after_write(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1303 | do_copy do_copy_func, |
| 1304 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1305 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1306 | igt_hang_t hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1307 | int i; |
| 1308 | |
| 1309 | gem_quiescent_gpu(fd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1310 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1311 | buffers->mode->set_bo(buffers, buffers->src[i], 0xabcdabcd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1312 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1313 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1314 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1315 | do_copy_func(buffers, buffers->spare, buffers->dst[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1316 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1317 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1318 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xabcdabcd); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1319 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1320 | } |
| 1321 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1322 | typedef void (*do_test)(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1323 | do_copy do_copy_func, |
| 1324 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1325 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1326 | typedef void (*run_wrap)(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1327 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1328 | do_copy do_copy_func, |
| 1329 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1330 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1331 | static void run_single(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1332 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1333 | do_copy do_copy_func, |
| 1334 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1335 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1336 | pass = 0; |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1337 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1338 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1341 | static void run_interruptible(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1342 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1343 | do_copy do_copy_func, |
| 1344 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1345 | { |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 1346 | pass = 0; |
Daniel Vetter | d7050f9 | 2016-05-11 17:06:28 +0200 | [diff] [blame] | 1347 | igt_while_interruptible(true) |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1348 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1349 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1350 | } |
| 1351 | |
Chris Wilson | 4645630 | 2016-01-22 19:29:07 +0000 | [diff] [blame] | 1352 | static void run_child(struct buffers *buffers, |
| 1353 | do_test do_test_func, |
| 1354 | do_copy do_copy_func, |
| 1355 | do_hang do_hang_func) |
| 1356 | |
| 1357 | { |
Chris Wilson | 69ecede | 2016-01-22 22:14:33 +0000 | [diff] [blame] | 1358 | /* We inherit the buffers from the parent, but the bufmgr/batch |
| 1359 | * needs to be local as the cache of reusable itself will be COWed, |
| 1360 | * leading to the child closing an object without the parent knowing. |
| 1361 | */ |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1362 | pass = 0; |
Chris Wilson | a1b47ef | 2016-01-27 19:44:16 +0000 | [diff] [blame] | 1363 | igt_fork(child, 1) |
Chris Wilson | 4645630 | 2016-01-22 19:29:07 +0000 | [diff] [blame] | 1364 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 4645630 | 2016-01-22 19:29:07 +0000 | [diff] [blame] | 1365 | igt_waitchildren(); |
| 1366 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
| 1367 | } |
| 1368 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1369 | static void __run_forked(struct buffers *buffers, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1370 | int num_children, int loops, bool interrupt, |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1371 | do_test do_test_func, |
| 1372 | do_copy do_copy_func, |
| 1373 | do_hang do_hang_func) |
| 1374 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1375 | { |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 1376 | /* purge the libdrm caches before cloing the process */ |
Chris Wilson | bca3ab2 | 2016-09-23 07:39:57 +0100 | [diff] [blame] | 1377 | buffers_destroy(buffers); |
| 1378 | intel_batchbuffer_free(buffers->batch); |
| 1379 | drm_intel_bufmgr_destroy(buffers->bufmgr); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1380 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1381 | igt_fork(child, num_children) { |
Chris Wilson | 459ff6b | 2016-04-20 07:49:02 +0100 | [diff] [blame] | 1382 | int num_buffers; |
| 1383 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 1384 | /* recreate process local variables */ |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 1385 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1386 | |
Chris Wilson | 459ff6b | 2016-04-20 07:49:02 +0100 | [diff] [blame] | 1387 | num_buffers = buffers->num_buffers / num_children; |
| 1388 | num_buffers += MIN_BUFFERS; |
| 1389 | if (num_buffers < buffers->num_buffers) |
| 1390 | buffers->num_buffers = num_buffers; |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 1391 | |
| 1392 | buffers_reset(buffers, true); |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 1393 | buffers_create(buffers); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 1394 | |
Daniel Vetter | d7050f9 | 2016-05-11 17:06:28 +0200 | [diff] [blame] | 1395 | igt_while_interruptible(interrupt) { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1396 | for (pass = 0; pass < loops; pass++) |
| 1397 | do_test_func(buffers, |
| 1398 | do_copy_func, |
| 1399 | do_hang_func); |
| 1400 | } |
| 1401 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 1402 | igt_waitchildren(); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1403 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Chris Wilson | bca3ab2 | 2016-09-23 07:39:57 +0100 | [diff] [blame] | 1404 | |
| 1405 | buffers_reset(buffers, true); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1406 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1407 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1408 | static void run_forked(struct buffers *buffers, |
| 1409 | do_test do_test_func, |
| 1410 | do_copy do_copy_func, |
| 1411 | do_hang do_hang_func) |
| 1412 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1413 | const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
| 1414 | __run_forked(buffers, ncpus, ncpus, false, |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1415 | do_test_func, do_copy_func, do_hang_func); |
| 1416 | } |
| 1417 | |
| 1418 | static void run_bomb(struct buffers *buffers, |
| 1419 | do_test do_test_func, |
| 1420 | do_copy do_copy_func, |
| 1421 | do_hang do_hang_func) |
| 1422 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1423 | const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
| 1424 | __run_forked(buffers, 8*ncpus, 2, true, |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1425 | do_test_func, do_copy_func, do_hang_func); |
| 1426 | } |
| 1427 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1428 | static void cpu_require(void) |
| 1429 | { |
| 1430 | bit17_require(); |
| 1431 | } |
| 1432 | |
| 1433 | static void gtt_require(void) |
| 1434 | { |
| 1435 | } |
| 1436 | |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1437 | static void bcs_require(void) |
| 1438 | { |
| 1439 | } |
| 1440 | |
| 1441 | static void rcs_require(void) |
| 1442 | { |
| 1443 | igt_require(rendercopy); |
| 1444 | } |
| 1445 | |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1446 | static void |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1447 | run_mode(const char *prefix, |
| 1448 | const struct create *create, |
| 1449 | const struct access_mode *mode, |
| 1450 | const struct size *size, |
| 1451 | const int num_buffers, |
| 1452 | const char *suffix, |
| 1453 | run_wrap run_wrap_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1454 | { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1455 | const struct { |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1456 | const char *prefix; |
| 1457 | do_copy copy; |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1458 | void (*require)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1459 | } pipelines[] = { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1460 | { "cpu", cpu_copy_bo, cpu_require }, |
| 1461 | { "gtt", gtt_copy_bo, gtt_require }, |
| 1462 | { "wc", wc_copy_bo, wc_require }, |
Daniel Vetter | 3e9b4e3 | 2015-02-06 23:10:26 +0100 | [diff] [blame] | 1463 | { "blt", blt_copy_bo, bcs_require }, |
| 1464 | { "render", render_copy_bo, rcs_require }, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1465 | { NULL, NULL } |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1466 | }, *pskip = pipelines + 3, *p; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1467 | const struct { |
| 1468 | const char *suffix; |
| 1469 | do_hang hang; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1470 | } hangs[] = { |
Chris Wilson | 92caf13 | 2015-12-16 09:23:56 +0000 | [diff] [blame] | 1471 | { "", no_hang }, |
| 1472 | { "-hang-blt", bcs_hang }, |
| 1473 | { "-hang-render", rcs_hang }, |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 1474 | { "-hang-all", all_hang }, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1475 | { NULL, NULL }, |
| 1476 | }, *h; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1477 | struct buffers buffers; |
| 1478 | |
| 1479 | igt_fixture |
| 1480 | buffers_init(&buffers, prefix, create, mode, |
| 1481 | size, num_buffers, |
| 1482 | fd, run_wrap_func != run_child); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1483 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1484 | for (h = hangs; h->suffix; h++) { |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1485 | if (!all && *h->suffix) |
| 1486 | continue; |
| 1487 | |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1488 | if (!*h->suffix) |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 1489 | igt_fixture |
| 1490 | igt_fork_hang_detector(fd); |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1491 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1492 | for (p = all ? pipelines : pskip; p->prefix; p++) { |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1493 | igt_subtest_group { |
| 1494 | igt_fixture p->require(); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1495 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1496 | igt_subtest_f("%s-%s-%s-sanitycheck0%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1497 | buffers_create(&buffers); |
| 1498 | run_wrap_func(&buffers, do_basic0, |
| 1499 | p->copy, h->hang); |
| 1500 | } |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1501 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1502 | igt_subtest_f("%s-%s-%s-sanitycheck1%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1503 | buffers_create(&buffers); |
| 1504 | run_wrap_func(&buffers, do_basic1, |
| 1505 | p->copy, h->hang); |
| 1506 | } |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1507 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1508 | igt_subtest_f("%s-%s-%s-sanitycheckN%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1509 | buffers_create(&buffers); |
| 1510 | run_wrap_func(&buffers, do_basicN, |
| 1511 | p->copy, h->hang); |
| 1512 | } |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 1513 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1514 | /* try to overwrite the source values */ |
| 1515 | igt_subtest_f("%s-%s-%s-overwrite-source-one%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1516 | buffers_create(&buffers); |
| 1517 | run_wrap_func(&buffers, |
| 1518 | do_overwrite_source__one, |
| 1519 | p->copy, h->hang); |
| 1520 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1521 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1522 | igt_subtest_f("%s-%s-%s-overwrite-source%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1523 | buffers_create(&buffers); |
| 1524 | run_wrap_func(&buffers, |
| 1525 | do_overwrite_source, |
| 1526 | p->copy, h->hang); |
| 1527 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1528 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1529 | igt_subtest_f("%s-%s-%s-overwrite-source-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1530 | buffers_create(&buffers); |
| 1531 | run_wrap_func(&buffers, |
| 1532 | do_overwrite_source_read_bcs, |
| 1533 | p->copy, h->hang); |
| 1534 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1535 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1536 | igt_subtest_f("%s-%s-%s-overwrite-source-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1537 | igt_require(rendercopy); |
| 1538 | buffers_create(&buffers); |
| 1539 | run_wrap_func(&buffers, |
| 1540 | do_overwrite_source_read_rcs, |
| 1541 | p->copy, h->hang); |
| 1542 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1543 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1544 | igt_subtest_f("%s-%s-%s-overwrite-source-rev%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1545 | buffers_create(&buffers); |
| 1546 | run_wrap_func(&buffers, |
| 1547 | do_overwrite_source__rev, |
| 1548 | p->copy, h->hang); |
| 1549 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1550 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1551 | /* try to intermix copies with GPU copies*/ |
| 1552 | igt_subtest_f("%s-%s-%s-intermix-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1553 | igt_require(rendercopy); |
| 1554 | buffers_create(&buffers); |
| 1555 | run_wrap_func(&buffers, |
| 1556 | do_intermix_rcs, |
| 1557 | p->copy, h->hang); |
| 1558 | } |
| 1559 | igt_subtest_f("%s-%s-%s-intermix-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1560 | igt_require(rendercopy); |
| 1561 | buffers_create(&buffers); |
| 1562 | run_wrap_func(&buffers, |
| 1563 | do_intermix_bcs, |
| 1564 | p->copy, h->hang); |
| 1565 | } |
| 1566 | igt_subtest_f("%s-%s-%s-intermix-both%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1567 | igt_require(rendercopy); |
| 1568 | buffers_create(&buffers); |
| 1569 | run_wrap_func(&buffers, |
| 1570 | do_intermix_both, |
| 1571 | p->copy, h->hang); |
| 1572 | } |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1573 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1574 | /* try to read the results before the copy completes */ |
| 1575 | igt_subtest_f("%s-%s-%s-early-read%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1576 | buffers_create(&buffers); |
| 1577 | run_wrap_func(&buffers, |
| 1578 | do_early_read, |
| 1579 | p->copy, h->hang); |
| 1580 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1581 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1582 | /* concurrent reads */ |
| 1583 | igt_subtest_f("%s-%s-%s-read-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1584 | buffers_create(&buffers); |
| 1585 | run_wrap_func(&buffers, |
| 1586 | do_read_read_bcs, |
| 1587 | p->copy, h->hang); |
| 1588 | } |
| 1589 | igt_subtest_f("%s-%s-%s-read-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1590 | igt_require(rendercopy); |
| 1591 | buffers_create(&buffers); |
| 1592 | run_wrap_func(&buffers, |
| 1593 | do_read_read_rcs, |
| 1594 | p->copy, h->hang); |
| 1595 | } |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1596 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1597 | /* split copying between rings */ |
| 1598 | igt_subtest_f("%s-%s-%s-write-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1599 | buffers_create(&buffers); |
| 1600 | run_wrap_func(&buffers, |
| 1601 | do_write_read_bcs, |
| 1602 | p->copy, h->hang); |
| 1603 | } |
| 1604 | igt_subtest_f("%s-%s-%s-write-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1605 | igt_require(rendercopy); |
| 1606 | buffers_create(&buffers); |
| 1607 | run_wrap_func(&buffers, |
| 1608 | do_write_read_rcs, |
| 1609 | p->copy, h->hang); |
| 1610 | } |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1611 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1612 | /* and finally try to trick the kernel into loosing the pending write */ |
| 1613 | igt_subtest_f("%s-%s-%s-gpu-read-after-write%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1614 | buffers_create(&buffers); |
| 1615 | run_wrap_func(&buffers, |
| 1616 | do_gpu_read_after_write, |
| 1617 | p->copy, h->hang); |
| 1618 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1619 | } |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1620 | } |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1621 | |
| 1622 | if (!*h->suffix) |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 1623 | igt_fixture |
| 1624 | igt_stop_hang_detector(); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1625 | } |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1626 | |
| 1627 | igt_fixture |
| 1628 | buffers_fini(&buffers); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1629 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1630 | |
| 1631 | static void |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 1632 | run_modes(const char *style, |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 1633 | const struct create *create, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 1634 | const struct access_mode *mode, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1635 | const struct size *size, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1636 | const int num) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1637 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1638 | const struct wrap { |
| 1639 | const char *suffix; |
| 1640 | run_wrap func; |
| 1641 | } wrappers[] = { |
| 1642 | { "", run_single }, |
| 1643 | { "-child", run_child }, |
| 1644 | { "-forked", run_forked }, |
| 1645 | { "-interruptible", run_interruptible }, |
| 1646 | { "-bomb", run_bomb }, |
| 1647 | { NULL }, |
| 1648 | }; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1649 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1650 | while (mode->name) { |
| 1651 | igt_subtest_group { |
| 1652 | igt_fixture { |
| 1653 | if (mode->require) |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 1654 | mode->require(create, num); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | for (const struct wrap *w = wrappers; w->suffix; w++) { |
| 1658 | run_mode(style, create, mode, size, num, |
| 1659 | w->suffix, w->func); |
| 1660 | } |
Daniel Vetter | 9665073 | 2016-03-18 21:55:00 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1663 | mode++; |
Daniel Vetter | 9665073 | 2016-03-18 21:55:00 +0100 | [diff] [blame] | 1664 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1665 | } |
| 1666 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1667 | static unsigned |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1668 | num_buffers(uint64_t max, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1669 | const struct size *s, |
| 1670 | const struct create *c, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1671 | unsigned allow_mem) |
| 1672 | { |
| 1673 | unsigned size = 4*s->width*s->height; |
Chris Wilson | 9e7e7c3 | 2016-04-11 09:17:33 +0100 | [diff] [blame] | 1674 | uint64_t n; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1675 | |
Chris Wilson | 9e7e7c3 | 2016-04-11 09:17:33 +0100 | [diff] [blame] | 1676 | igt_assert(size); |
| 1677 | n = max / (2*size); |
| 1678 | n += MIN_BUFFERS; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1679 | |
Chris Wilson | 9e7e7c3 | 2016-04-11 09:17:33 +0100 | [diff] [blame] | 1680 | igt_require(n < INT32_MAX); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1681 | igt_require(set_max_map_count(2*n)); |
| 1682 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 1683 | if (c->require) |
| 1684 | c->require(c, n); |
| 1685 | |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1686 | intel_require_memory(2*n, size, allow_mem); |
| 1687 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1688 | return n; |
| 1689 | } |
| 1690 | |
Chris Wilson | 3d8af56 | 2016-03-20 10:49:54 +0000 | [diff] [blame] | 1691 | static bool allow_unlimited_files(void) |
| 1692 | { |
| 1693 | struct rlimit rlim; |
| 1694 | unsigned nofile_rlim = 1024*1024; |
| 1695 | |
| 1696 | FILE *file = fopen("/proc/sys/fs/file-max", "r"); |
| 1697 | if (file) { |
| 1698 | igt_assert(fscanf(file, "%u", &nofile_rlim) == 1); |
| 1699 | igt_info("System limit for open files is %u\n", nofile_rlim); |
| 1700 | fclose(file); |
| 1701 | } |
| 1702 | |
| 1703 | if (getrlimit(RLIMIT_NOFILE, &rlim)) |
| 1704 | return false; |
| 1705 | |
| 1706 | rlim.rlim_cur = nofile_rlim; |
| 1707 | rlim.rlim_max = nofile_rlim; |
| 1708 | return setrlimit(RLIMIT_NOFILE, &rlim) == 0; |
| 1709 | } |
| 1710 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 1711 | igt_main |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1712 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1713 | const struct access_mode modes[] = { |
| 1714 | { |
| 1715 | .name = "prw", |
| 1716 | .create_bo = unmapped_create_bo, |
| 1717 | .set_bo = prw_set_bo, |
| 1718 | .cmp_bo = prw_cmp_bo, |
| 1719 | .release_bo = nop_release_bo, |
| 1720 | }, |
| 1721 | { |
| 1722 | .name = "partial", |
| 1723 | .create_bo = unmapped_create_bo, |
| 1724 | .set_bo = partial_set_bo, |
| 1725 | .cmp_bo = partial_cmp_bo, |
| 1726 | .release_bo = nop_release_bo, |
| 1727 | }, |
| 1728 | { |
| 1729 | .name = "cpu", |
| 1730 | .create_bo = unmapped_create_bo, |
| 1731 | .require = create_cpu_require, |
| 1732 | .set_bo = cpu_set_bo, |
| 1733 | .cmp_bo = cpu_cmp_bo, |
| 1734 | .release_bo = nop_release_bo, |
| 1735 | }, |
| 1736 | { |
| 1737 | .name = "snoop", |
| 1738 | .create_bo = snoop_create_bo, |
| 1739 | .require = create_snoop_require, |
| 1740 | .set_bo = cpu_set_bo, |
| 1741 | .cmp_bo = cpu_cmp_bo, |
| 1742 | .release_bo = nop_release_bo, |
| 1743 | }, |
| 1744 | { |
| 1745 | .name = "userptr", |
| 1746 | .create_bo = userptr_create_bo, |
| 1747 | .require = create_userptr_require, |
| 1748 | .set_bo = userptr_set_bo, |
| 1749 | .cmp_bo = userptr_cmp_bo, |
| 1750 | .release_bo = userptr_release_bo, |
| 1751 | }, |
| 1752 | { |
| 1753 | .name = "dmabuf", |
| 1754 | .create_bo = dmabuf_create_bo, |
| 1755 | .require = create_dmabuf_require, |
| 1756 | .set_bo = dmabuf_set_bo, |
| 1757 | .cmp_bo = dmabuf_cmp_bo, |
| 1758 | .release_bo = dmabuf_release_bo, |
| 1759 | }, |
| 1760 | { |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 1761 | .name = "vgem", |
| 1762 | .create_bo = vgem_create_bo, |
| 1763 | .require = create_vgem_require, |
| 1764 | .set_bo = dmabuf_set_bo, |
| 1765 | .cmp_bo = dmabuf_cmp_bo, |
| 1766 | .release_bo = dmabuf_release_bo, |
| 1767 | }, |
| 1768 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1769 | .name = "gtt", |
| 1770 | .create_bo = gtt_create_bo, |
| 1771 | .set_bo = gtt_set_bo, |
| 1772 | .cmp_bo = gtt_cmp_bo, |
| 1773 | .release_bo = nop_release_bo, |
| 1774 | }, |
| 1775 | { |
| 1776 | .name = "gttX", |
| 1777 | .create_bo = gttX_create_bo, |
| 1778 | .set_bo = gtt_set_bo, |
| 1779 | .cmp_bo = gtt_cmp_bo, |
| 1780 | .release_bo = nop_release_bo, |
| 1781 | }, |
| 1782 | { |
| 1783 | .name = "wc", |
| 1784 | .require = wc_create_require, |
| 1785 | .create_bo = wc_create_bo, |
| 1786 | .set_bo = gtt_set_bo, |
| 1787 | .cmp_bo = gtt_cmp_bo, |
| 1788 | .release_bo = wc_release_bo, |
| 1789 | }, |
| 1790 | { |
| 1791 | .name = "gpu", |
| 1792 | .create_bo = gpu_create_bo, |
| 1793 | .set_bo = gpu_set_bo, |
| 1794 | .cmp_bo = gpu_cmp_bo, |
| 1795 | .release_bo = nop_release_bo, |
| 1796 | }, |
| 1797 | { |
| 1798 | .name = "gpuX", |
| 1799 | .create_bo = gpuX_create_bo, |
| 1800 | .set_bo = gpu_set_bo, |
| 1801 | .cmp_bo = gpu_cmp_bo, |
| 1802 | .release_bo = nop_release_bo, |
| 1803 | }, |
| 1804 | { NULL }, |
| 1805 | }; |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 1806 | const struct create create[] = { |
| 1807 | { "", can_create_normal, create_normal_bo}, |
| 1808 | #if HAVE_CREATE_PRIVATE |
| 1809 | { "private-", can_create_private, create_private_bo}, |
| 1810 | #endif |
| 1811 | #if HAVE_CREATE_STOLEN |
| 1812 | { "stolen-", can_create_stolen, create_stolen_bo}, |
| 1813 | #endif |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 1814 | { NULL, NULL } |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1815 | }; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1816 | const struct size sizes[] = { |
| 1817 | { "4KiB", 128, 8 }, |
| 1818 | { "256KiB", 128, 128 }, |
| 1819 | { "1MiB", 512, 512 }, |
| 1820 | { "16MiB", 2048, 2048 }, |
| 1821 | { NULL} |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1822 | }; |
Chris Wilson | 42291f2 | 2016-01-07 11:19:26 +0000 | [diff] [blame] | 1823 | uint64_t pin_sz = 0; |
| 1824 | void *pinned = NULL; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1825 | char name[80]; |
| 1826 | int count = 0; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1827 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1828 | igt_skip_on_simulation(); |
| 1829 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1830 | if (strstr(igt_test_name(), "all")) |
| 1831 | all = true; |
| 1832 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 1833 | igt_fixture { |
Chris Wilson | 98dcf2f | 2016-03-25 00:50:45 +0000 | [diff] [blame] | 1834 | allow_unlimited_files(); |
Chris Wilson | 3d8af56 | 2016-03-20 10:49:54 +0000 | [diff] [blame] | 1835 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 1836 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1837 | intel_detect_and_clear_missed_interrupts(fd); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1838 | devid = intel_get_drm_devid(fd); |
| 1839 | gen = intel_gen(devid); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1840 | rendercopy = igt_get_render_copyfunc(devid); |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 1841 | |
| 1842 | vgem_drv = __drm_open_driver(DRIVER_VGEM); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1843 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1844 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1845 | for (const struct create *c = create; c->name; c++) { |
| 1846 | for (const struct size *s = sizes; s->name; s++) { |
| 1847 | /* Minimum test set */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1848 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1849 | c->name, s->name, "tiny"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1850 | igt_subtest_group { |
| 1851 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1852 | count = num_buffers(0, s, c, CHECK_RAM); |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1853 | } |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1854 | run_modes(name, c, modes, s, count); |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1857 | /* "Average" test set */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1858 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1859 | c->name, s->name, "small"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1860 | igt_subtest_group { |
| 1861 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1862 | count = num_buffers(gem_mappable_aperture_size()/4, |
| 1863 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1864 | } |
| 1865 | run_modes(name, c, modes, s, count); |
| 1866 | } |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1867 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1868 | /* Use the entire mappable aperture */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1869 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1870 | c->name, s->name, "thrash"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1871 | igt_subtest_group { |
| 1872 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1873 | count = num_buffers(gem_mappable_aperture_size(), |
| 1874 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1875 | } |
| 1876 | run_modes(name, c, modes, s, count); |
| 1877 | } |
| 1878 | |
| 1879 | /* Use the entire global GTT */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1880 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1881 | c->name, s->name, "global"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1882 | igt_subtest_group { |
| 1883 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1884 | count = num_buffers(gem_global_aperture_size(fd), |
| 1885 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1886 | } |
| 1887 | run_modes(name, c, modes, s, count); |
| 1888 | } |
| 1889 | |
| 1890 | /* Use the entire per-process GTT */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1891 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1892 | c->name, s->name, "full"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1893 | igt_subtest_group { |
| 1894 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1895 | count = num_buffers(gem_aperture_size(fd), |
| 1896 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1897 | } |
| 1898 | run_modes(name, c, modes, s, count); |
| 1899 | } |
| 1900 | |
| 1901 | /* Use the entire mappable aperture, force swapping */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1902 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1903 | c->name, s->name, "swap"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1904 | igt_subtest_group { |
| 1905 | igt_fixture { |
| 1906 | if (intel_get_avail_ram_mb() > gem_mappable_aperture_size()/(1024*1024)) { |
| 1907 | pin_sz = intel_get_avail_ram_mb() - gem_mappable_aperture_size()/(1024*1024); |
| 1908 | |
| 1909 | igt_debug("Pinning %lld MiB\n", (long long)pin_sz); |
| 1910 | pin_sz *= 1024 * 1024; |
| 1911 | |
| 1912 | if (posix_memalign(&pinned, 4096, pin_sz) || |
| 1913 | mlock(pinned, pin_sz) || |
| 1914 | madvise(pinned, pin_sz, MADV_DONTFORK)) { |
| 1915 | free(pinned); |
| 1916 | pinned = NULL; |
| 1917 | } |
| 1918 | igt_require(pinned); |
| 1919 | } |
| 1920 | |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1921 | count = num_buffers(gem_mappable_aperture_size(), |
| 1922 | s, c, CHECK_RAM | CHECK_SWAP); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1923 | } |
| 1924 | run_modes(name, c, modes, s, count); |
| 1925 | |
| 1926 | igt_fixture { |
| 1927 | if (pinned) { |
| 1928 | munlock(pinned, pin_sz); |
| 1929 | free(pinned); |
| 1930 | pinned = NULL; |
| 1931 | } |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1932 | } |
Chris Wilson | 42291f2 | 2016-01-07 11:19:26 +0000 | [diff] [blame] | 1933 | } |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 1934 | } |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 1935 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1936 | } |