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; |
Chris Wilson | 8f39310 | 2017-01-02 11:23:33 +0000 | [diff] [blame] | 246 | free(from_user_pointer(arg.user_ptr)); |
Chris Wilson | 0143d4f | 2016-01-21 09:53:50 +0000 | [diff] [blame] | 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); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 266 | userptr.user_ptr = to_user_pointer(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 |
Chris Wilson | 8f39310 | 2017-01-02 11:23:33 +0000 | [diff] [blame] | 278 | bo->virtual = from_user_pointer(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; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 488 | |
| 489 | drm_intel_gem_bo_start_gtt_access(bo, true); |
Chris Wilson | 94ca170 | 2016-09-26 09:23:42 +0100 | [diff] [blame] | 490 | for (int y = 0; y < b->height; y++) |
| 491 | vaddr[pixel(y, b->width)] = val; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 495 | 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] | 496 | { |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 497 | uint32_t *vaddr = bo->virtual; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 498 | |
Chris Wilson | 3e766b8 | 2014-09-26 07:55:49 +0100 | [diff] [blame] | 499 | /* GTT access is slow. So we just compare a few points */ |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 500 | drm_intel_gem_bo_start_gtt_access(bo, false); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 501 | for (int y = 0; y < b->height; y++) |
| 502 | igt_assert_eq_u32(vaddr[pixel(y, b->width)], val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 506 | map_bo(drm_intel_bo *bo) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 507 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 508 | /* gtt map doesn't have a write parameter, so just keep the mapping |
| 509 | * around (to avoid the set_domain with the gtt write domain set) and |
| 510 | * manually tell the kernel when we start access the gtt. */ |
| 511 | do_or_die(drm_intel_gem_bo_map_gtt(bo)); |
| 512 | |
| 513 | return bo; |
| 514 | } |
| 515 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 516 | static drm_intel_bo * |
| 517 | tile_bo(drm_intel_bo *bo, int width) |
| 518 | { |
| 519 | uint32_t tiling = I915_TILING_X; |
| 520 | uint32_t stride = width * 4; |
| 521 | |
| 522 | do_or_die(drm_intel_bo_set_tiling(bo, &tiling, stride)); |
| 523 | |
| 524 | return bo; |
| 525 | } |
| 526 | |
| 527 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 528 | gtt_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 529 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 530 | return map_bo(unmapped_create_bo(b)); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 534 | gttX_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 535 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 536 | return tile_bo(gtt_create_bo(b), b->width); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 537 | } |
| 538 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 539 | static void bit17_require(void) |
| 540 | { |
| 541 | static struct drm_i915_gem_get_tiling2 { |
| 542 | uint32_t handle; |
| 543 | uint32_t tiling_mode; |
| 544 | uint32_t swizzle_mode; |
| 545 | uint32_t phys_swizzle_mode; |
| 546 | } arg; |
| 547 | #define DRM_IOCTL_I915_GEM_GET_TILING2 DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling2) |
| 548 | |
| 549 | if (arg.handle == 0) { |
| 550 | arg.handle = gem_create(fd, 4096); |
| 551 | gem_set_tiling(fd, arg.handle, I915_TILING_X, 512); |
| 552 | |
| 553 | do_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING2, &arg); |
| 554 | gem_close(fd, arg.handle); |
| 555 | } |
| 556 | igt_require(arg.phys_swizzle_mode == arg.swizzle_mode); |
| 557 | } |
| 558 | |
| 559 | static void wc_require(void) |
| 560 | { |
| 561 | bit17_require(); |
| 562 | gem_require_mmap_wc(fd); |
| 563 | } |
| 564 | |
| 565 | static void |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 566 | wc_create_require(const struct create *create, unsigned count) |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 567 | { |
| 568 | wc_require(); |
| 569 | } |
| 570 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 571 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 572 | wc_create_bo(const struct buffers *b) |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 573 | { |
| 574 | drm_intel_bo *bo; |
| 575 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 576 | bo = unmapped_create_bo(b); |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 577 | 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] | 578 | return bo; |
| 579 | } |
| 580 | |
| 581 | static void |
| 582 | wc_release_bo(drm_intel_bo *bo) |
| 583 | { |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 584 | igt_assert(bo->virtual); |
| 585 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 586 | munmap(bo->virtual, bo->size); |
| 587 | bo->virtual = NULL; |
| 588 | |
| 589 | nop_release_bo(bo); |
| 590 | } |
| 591 | |
| 592 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 593 | gpu_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 594 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 595 | return unmapped_create_bo(b); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 596 | } |
| 597 | |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 598 | static drm_intel_bo * |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 599 | gpuX_create_bo(const struct buffers *b) |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 600 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 601 | return tile_bo(gpu_create_bo(b), b->width); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 602 | } |
| 603 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 604 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 605 | 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] | 606 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 607 | int size = b->npixels; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 608 | uint32_t *vaddr; |
| 609 | |
| 610 | do_or_die(drm_intel_bo_map(bo, true)); |
| 611 | vaddr = bo->virtual; |
| 612 | while (size--) |
| 613 | *vaddr++ = val; |
| 614 | drm_intel_bo_unmap(bo); |
| 615 | } |
| 616 | |
| 617 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 618 | 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] | 619 | { |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 620 | int size = b->npixels; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 621 | uint32_t *vaddr; |
| 622 | |
| 623 | do_or_die(drm_intel_bo_map(bo, false)); |
| 624 | vaddr = bo->virtual; |
| 625 | while (size--) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 626 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 627 | drm_intel_bo_unmap(bo); |
| 628 | } |
| 629 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 630 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 631 | 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] | 632 | { |
| 633 | struct drm_i915_gem_relocation_entry reloc[1]; |
| 634 | struct drm_i915_gem_exec_object2 gem_exec[2]; |
| 635 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 636 | uint32_t buf[10], *b; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 637 | uint32_t tiling, swizzle; |
| 638 | |
| 639 | drm_intel_bo_get_tiling(bo, &tiling, &swizzle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 640 | |
| 641 | memset(reloc, 0, sizeof(reloc)); |
| 642 | memset(gem_exec, 0, sizeof(gem_exec)); |
| 643 | memset(&execbuf, 0, sizeof(execbuf)); |
| 644 | |
| 645 | b = buf; |
| 646 | *b++ = XY_COLOR_BLT_CMD_NOLEN | |
| 647 | ((gen >= 8) ? 5 : 4) | |
| 648 | COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 649 | if (gen >= 4 && tiling) { |
| 650 | b[-1] |= XY_COLOR_BLT_TILED; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 651 | *b = buffers->width; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 652 | } else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 653 | *b = buffers->width << 2; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 654 | *b++ |= 0xf0 << 16 | 1 << 25 | 1 << 24; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 655 | *b++ = 0; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 656 | *b++ = buffers->height << 16 | buffers->width; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 657 | reloc[0].offset = (b - buf) * sizeof(uint32_t); |
| 658 | reloc[0].target_handle = bo->handle; |
| 659 | reloc[0].read_domains = I915_GEM_DOMAIN_RENDER; |
| 660 | reloc[0].write_domain = I915_GEM_DOMAIN_RENDER; |
| 661 | *b++ = 0; |
| 662 | if (gen >= 8) |
| 663 | *b++ = 0; |
| 664 | *b++ = val; |
| 665 | *b++ = MI_BATCH_BUFFER_END; |
| 666 | if ((b - buf) & 1) |
| 667 | *b++ = 0; |
| 668 | |
| 669 | gem_exec[0].handle = bo->handle; |
| 670 | gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE; |
| 671 | |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 672 | gem_exec[1].handle = gem_create(fd, 4096); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 673 | gem_exec[1].relocation_count = 1; |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 674 | gem_exec[1].relocs_ptr = to_user_pointer(reloc); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 675 | |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 676 | execbuf.buffers_ptr = to_user_pointer(gem_exec); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 677 | execbuf.buffer_count = 2; |
| 678 | execbuf.batch_len = (b - buf) * sizeof(buf[0]); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 679 | if (gen >= 6) |
| 680 | execbuf.flags = I915_EXEC_BLT; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 681 | |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 682 | gem_write(fd, gem_exec[1].handle, 0, buf, execbuf.batch_len); |
| 683 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 684 | |
Chris Wilson | 6f75990 | 2016-01-27 11:17:03 +0000 | [diff] [blame] | 685 | gem_close(fd, gem_exec[1].handle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static void |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 689 | 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] | 690 | { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 691 | blt_copy_bo(b, b->snoop, bo); |
| 692 | cpu_cmp_bo(b, b->snoop, val); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 693 | } |
| 694 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 695 | struct access_mode { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 696 | const char *name; |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 697 | void (*require)(const struct create *, unsigned); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 698 | drm_intel_bo *(*create_bo)(const struct buffers *b); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 699 | void (*set_bo)(struct buffers *b, drm_intel_bo *bo, uint32_t val); |
| 700 | 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] | 701 | void (*release_bo)(drm_intel_bo *bo); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 702 | }; |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 703 | igt_render_copyfunc_t rendercopy; |
| 704 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 705 | static int read_sysctl(const char *path) |
| 706 | { |
| 707 | FILE *file = fopen(path, "r"); |
| 708 | int max = 0; |
| 709 | if (file) { |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 710 | if (fscanf(file, "%d", &max) != 1) |
| 711 | max = 0; /* silence! */ |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 712 | fclose(file); |
| 713 | } |
| 714 | return max; |
| 715 | } |
| 716 | |
| 717 | static int write_sysctl(const char *path, int value) |
| 718 | { |
| 719 | FILE *file = fopen(path, "w"); |
| 720 | if (file) { |
| 721 | fprintf(file, "%d", value); |
| 722 | fclose(file); |
| 723 | } |
| 724 | return read_sysctl(path); |
| 725 | } |
| 726 | |
| 727 | static bool set_max_map_count(int num_buffers) |
| 728 | { |
| 729 | int max = read_sysctl("/proc/sys/vm/max_map_count"); |
| 730 | if (max < num_buffers + 1024) |
| 731 | max = write_sysctl("/proc/sys/vm/max_map_count", |
| 732 | num_buffers + 1024); |
| 733 | return max > num_buffers; |
| 734 | } |
| 735 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 736 | static void buffers_init(struct buffers *b, |
| 737 | const char *name, |
| 738 | const struct create *create, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 739 | const struct access_mode *mode, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 740 | const struct size *size, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 741 | int num_buffers, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 742 | int _fd, int enable_reuse) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 743 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 744 | memset(b, 0, sizeof(*b)); |
| 745 | b->name = name; |
| 746 | b->create = create; |
| 747 | b->mode = mode; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 748 | b->size = size; |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 749 | b->num_buffers = num_buffers; |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 750 | b->count = 0; |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 751 | |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 752 | b->width = size->width; |
| 753 | b->height = size->height; |
| 754 | b->npixels = size->width * size->height; |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 755 | b->page_size = 4*b->npixels; |
| 756 | b->page_size = (b->page_size + 4095) & -4096; |
| 757 | b->tmp = malloc(b->page_size); |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 758 | igt_assert(b->tmp); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 759 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 760 | b->bufmgr = drm_intel_bufmgr_gem_init(_fd, 4096); |
| 761 | igt_assert(b->bufmgr); |
| 762 | |
| 763 | b->src = malloc(2*sizeof(drm_intel_bo *)*num_buffers); |
| 764 | igt_assert(b->src); |
| 765 | b->dst = b->src + num_buffers; |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 766 | |
Chris Wilson | a1b47ef | 2016-01-27 19:44:16 +0000 | [diff] [blame] | 767 | if (enable_reuse) |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 768 | drm_intel_bufmgr_gem_enable_reuse(b->bufmgr); |
| 769 | b->batch = intel_batchbuffer_alloc(b->bufmgr, devid); |
| 770 | igt_assert(b->batch); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 773 | static void buffers_destroy(struct buffers *b) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 774 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 775 | int count = b->count; |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 776 | if (count == 0) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 777 | return; |
| 778 | |
Chris Wilson | c19b049 | 2016-03-20 11:13:30 +0000 | [diff] [blame] | 779 | /* Be safe so that we can clean up a partial creation */ |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 780 | b->count = 0; |
Chris Wilson | c19b049 | 2016-03-20 11:13:30 +0000 | [diff] [blame] | 781 | for (int i = 0; i < count; i++) { |
| 782 | if (b->src[i]) { |
| 783 | b->mode->release_bo(b->src[i]); |
| 784 | b->src[i] = NULL; |
| 785 | } else |
| 786 | break; |
| 787 | |
| 788 | if (b->dst[i]) { |
| 789 | b->mode->release_bo(b->dst[i]); |
| 790 | b->dst[i] = NULL; |
| 791 | } |
| 792 | } |
| 793 | if (b->snoop) { |
| 794 | nop_release_bo(b->snoop); |
| 795 | b->snoop = NULL; |
| 796 | } |
| 797 | if (b->spare) { |
| 798 | b->mode->release_bo(b->spare); |
| 799 | b->spare = NULL; |
| 800 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 803 | static void buffers_create(struct buffers *b) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 804 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 805 | int count = b->num_buffers; |
| 806 | igt_assert(b->bufmgr); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 807 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 808 | buffers_destroy(b); |
| 809 | igt_assert(b->count == 0); |
Chris Wilson | c19b049 | 2016-03-20 11:13:30 +0000 | [diff] [blame] | 810 | b->count = count; |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 811 | |
| 812 | for (int i = 0; i < count; i++) { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 813 | b->src[i] = b->mode->create_bo(b); |
| 814 | b->dst[i] = b->mode->create_bo(b); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 815 | } |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 816 | b->spare = b->mode->create_bo(b); |
| 817 | b->snoop = snoop_create_bo(b); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 820 | static void buffers_reset(struct buffers *b, bool enable_reuse) |
| 821 | { |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 822 | b->bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 823 | igt_assert(b->bufmgr); |
| 824 | |
| 825 | if (enable_reuse) |
| 826 | drm_intel_bufmgr_gem_enable_reuse(b->bufmgr); |
| 827 | b->batch = intel_batchbuffer_alloc(b->bufmgr, devid); |
| 828 | igt_assert(b->batch); |
| 829 | } |
| 830 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 831 | static void buffers_fini(struct buffers *b) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 832 | { |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 833 | if (b->bufmgr == NULL) |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 834 | return; |
| 835 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 836 | buffers_destroy(b); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 837 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 838 | free(b->tmp); |
| 839 | free(b->src); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 840 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 841 | intel_batchbuffer_free(b->batch); |
| 842 | drm_intel_bufmgr_destroy(b->bufmgr); |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 843 | |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 844 | memset(b, 0, sizeof(*b)); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 847 | 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] | 848 | typedef igt_hang_t (*do_hang)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 849 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 850 | 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] | 851 | { |
| 852 | struct igt_buf d = { |
| 853 | .bo = dst, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 854 | .size = b->npixels * 4, |
| 855 | .num_tiles = b->npixels * 4, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 856 | .stride = b->width * 4, |
Maarten Lankhorst | 10c9830 | 2018-11-16 15:18:24 +0100 | [diff] [blame] | 857 | .bpp = 32, |
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, |
Maarten Lankhorst | 10c9830 | 2018-11-16 15:18:24 +0100 | [diff] [blame] | 863 | .bpp = 32, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 864 | }; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 865 | uint32_t swizzle; |
| 866 | |
| 867 | drm_intel_bo_get_tiling(dst, &d.tiling, &swizzle); |
| 868 | drm_intel_bo_get_tiling(src, &s.tiling, &swizzle); |
| 869 | |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 870 | rendercopy(b->batch, NULL, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 871 | &s, 0, 0, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 872 | b->width, b->height, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 873 | &d, 0, 0); |
| 874 | } |
| 875 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 876 | 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] | 877 | { |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 878 | intel_blt_copy(b->batch, |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 879 | src, 0, 0, 4*b->width, |
| 880 | dst, 0, 0, 4*b->width, |
| 881 | b->width, b->height, 32); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 882 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 883 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 884 | 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] | 885 | { |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 886 | const int size = b->page_size; |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 887 | void *d, *s; |
| 888 | |
| 889 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_CPU, 0); |
| 890 | 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] | 891 | s = gem_mmap__cpu(fd, src->handle, 0, size, PROT_READ); |
| 892 | d = gem_mmap__cpu(fd, dst->handle, 0, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 893 | |
| 894 | memcpy(d, s, size); |
| 895 | |
| 896 | munmap(d, size); |
| 897 | munmap(s, size); |
| 898 | } |
| 899 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 900 | 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] | 901 | { |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 902 | const int size = b->page_size; |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 903 | void *d, *s; |
| 904 | |
| 905 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_GTT, 0); |
| 906 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 907 | |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 908 | s = gem_mmap__gtt(fd, src->handle, size, PROT_READ); |
| 909 | d = gem_mmap__gtt(fd, dst->handle, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 910 | |
| 911 | memcpy(d, s, size); |
| 912 | |
| 913 | munmap(d, size); |
| 914 | munmap(s, size); |
| 915 | } |
| 916 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 917 | 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] | 918 | { |
Chris Wilson | d199ad8 | 2016-07-27 23:19:41 +0100 | [diff] [blame] | 919 | const int size = b->page_size; |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 920 | void *d, *s; |
| 921 | |
Chris Wilson | e9cd7d5 | 2017-04-13 10:08:09 +0100 | [diff] [blame] | 922 | gem_set_domain(fd, src->handle, I915_GEM_DOMAIN_WC, 0); |
| 923 | gem_set_domain(fd, dst->handle, I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 924 | |
Ville Syrjälä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 925 | s = gem_mmap__wc(fd, src->handle, 0, size, PROT_READ); |
| 926 | d = gem_mmap__wc(fd, dst->handle, 0, size, PROT_WRITE); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 927 | |
| 928 | memcpy(d, s, size); |
| 929 | |
| 930 | munmap(d, size); |
| 931 | munmap(s, size); |
| 932 | } |
| 933 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 934 | static igt_hang_t no_hang(void) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 935 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 936 | return (igt_hang_t){0, 0}; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 939 | static igt_hang_t bcs_hang(void) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 940 | { |
Daniel Vetter | 3cd45de | 2015-02-10 17:46:43 +0100 | [diff] [blame] | 941 | return igt_hang_ring(fd, I915_EXEC_BLT); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 942 | } |
| 943 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 944 | static igt_hang_t rcs_hang(void) |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 945 | { |
Daniel Vetter | 3cd45de | 2015-02-10 17:46:43 +0100 | [diff] [blame] | 946 | return igt_hang_ring(fd, I915_EXEC_RENDER); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 949 | static igt_hang_t all_hang(void) |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 950 | { |
Antonio Argenziano | 140a67c | 2018-07-10 16:45:26 -0700 | [diff] [blame] | 951 | igt_hang_t hang = igt_hang_ring(fd, I915_EXEC_RENDER); |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 952 | unsigned engine; |
| 953 | |
Chris Wilson | 305ebce | 2018-02-21 14:13:16 +0000 | [diff] [blame] | 954 | for_each_physical_engine(fd, engine) { |
Antonio Argenziano | 140a67c | 2018-07-10 16:45:26 -0700 | [diff] [blame] | 955 | struct drm_i915_gem_execbuffer2 eb = hang.spin->execbuf; |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 956 | |
Antonio Argenziano | 140a67c | 2018-07-10 16:45:26 -0700 | [diff] [blame] | 957 | if (engine == I915_EXEC_RENDER) |
| 958 | continue; |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 959 | |
Antonio Argenziano | 140a67c | 2018-07-10 16:45:26 -0700 | [diff] [blame] | 960 | eb.flags = engine; |
| 961 | __gem_execbuf(fd, &eb); |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 964 | return hang; |
| 965 | } |
| 966 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 967 | static void do_basic0(struct buffers *buffers, |
| 968 | do_copy do_copy_func, |
| 969 | do_hang do_hang_func) |
| 970 | { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 971 | buffers->mode->set_bo(buffers, buffers->src[0], 0xdeadbeef); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 972 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 973 | igt_hang_t hang = do_hang_func(); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 974 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 975 | do_copy_func(buffers, buffers->dst[i], buffers->src[0]); |
| 976 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 977 | |
| 978 | igt_post_hang_ring(fd, hang); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | static void do_basic1(struct buffers *buffers, |
| 983 | do_copy do_copy_func, |
| 984 | do_hang do_hang_func) |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 985 | { |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 986 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 987 | igt_hang_t hang = do_hang_func(); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 988 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 989 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 990 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 991 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 992 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 993 | usleep(0); /* let someone else claim the mutex */ |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 994 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 995 | |
| 996 | igt_post_hang_ring(fd, hang); |
| 997 | } |
| 998 | } |
| 999 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1000 | static void do_basicN(struct buffers *buffers, |
| 1001 | do_copy do_copy_func, |
| 1002 | do_hang do_hang_func) |
| 1003 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1004 | igt_hang_t hang; |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1005 | |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1006 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1007 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1008 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | hang = do_hang_func(); |
| 1012 | |
| 1013 | for (int i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1014 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1015 | usleep(0); /* let someone else claim the mutex */ |
| 1016 | } |
| 1017 | |
| 1018 | for (int i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1019 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1020 | |
| 1021 | igt_post_hang_ring(fd, hang); |
| 1022 | } |
| 1023 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1024 | static void do_overwrite_source(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1025 | do_copy do_copy_func, |
| 1026 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1027 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1028 | igt_hang_t hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1029 | int i; |
| 1030 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1031 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1032 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1033 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1034 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1035 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1036 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1037 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1038 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1039 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1040 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1041 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1042 | igt_post_hang_ring(fd, hang); |
| 1043 | } |
| 1044 | |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1045 | static void do_overwrite_source_read(struct buffers *buffers, |
| 1046 | do_copy do_copy_func, |
| 1047 | do_hang do_hang_func, |
| 1048 | int do_rcs) |
| 1049 | { |
| 1050 | const int half = buffers->count/2; |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1051 | igt_hang_t hang; |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1052 | int i; |
| 1053 | |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1054 | for (i = 0; i < half; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1055 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1056 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
| 1057 | buffers->mode->set_bo(buffers, buffers->dst[i+half], ~i); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1058 | } |
| 1059 | for (i = 0; i < half; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1060 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1061 | if (do_rcs) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1062 | render_copy_bo(buffers, buffers->dst[i+half], buffers->src[i]); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1063 | else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1064 | blt_copy_bo(buffers, buffers->dst[i+half], buffers->src[i]); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1065 | } |
| 1066 | hang = do_hang_func(); |
| 1067 | for (i = half; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1068 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1069 | for (i = 0; i < half; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1070 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
| 1071 | buffers->mode->cmp_bo(buffers, buffers->dst[i+half], i); |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1072 | } |
| 1073 | igt_post_hang_ring(fd, hang); |
| 1074 | } |
| 1075 | |
| 1076 | static void do_overwrite_source_read_bcs(struct buffers *buffers, |
| 1077 | do_copy do_copy_func, |
| 1078 | do_hang do_hang_func) |
| 1079 | { |
| 1080 | do_overwrite_source_read(buffers, do_copy_func, do_hang_func, 0); |
| 1081 | } |
| 1082 | |
| 1083 | static void do_overwrite_source_read_rcs(struct buffers *buffers, |
| 1084 | do_copy do_copy_func, |
| 1085 | do_hang do_hang_func) |
| 1086 | { |
| 1087 | do_overwrite_source_read(buffers, do_copy_func, do_hang_func, 1); |
| 1088 | } |
| 1089 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1090 | static void do_overwrite_source__rev(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1091 | do_copy do_copy_func, |
| 1092 | do_hang do_hang_func) |
| 1093 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1094 | igt_hang_t hang; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1095 | int i; |
| 1096 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1097 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1098 | buffers->mode->set_bo(buffers, buffers->src[i], i); |
| 1099 | buffers->mode->set_bo(buffers, buffers->dst[i], ~i); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1100 | } |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1101 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1102 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1103 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1104 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1105 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1106 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1107 | buffers->mode->cmp_bo(buffers, buffers->dst[i], i); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1108 | igt_post_hang_ring(fd, hang); |
| 1109 | } |
| 1110 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1111 | static void do_overwrite_source__one(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1112 | do_copy do_copy_func, |
| 1113 | do_hang do_hang_func) |
| 1114 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1115 | igt_hang_t hang; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1116 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1117 | buffers->mode->set_bo(buffers, buffers->src[0], 0); |
| 1118 | buffers->mode->set_bo(buffers, buffers->dst[0], ~0); |
| 1119 | do_copy_func(buffers, buffers->dst[0], buffers->src[0]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1120 | hang = do_hang_func(); |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1121 | buffers->mode->set_bo(buffers, buffers->src[0], 0xdeadbeef); |
| 1122 | buffers->mode->cmp_bo(buffers, buffers->dst[0], 0); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1123 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1124 | } |
| 1125 | |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1126 | static void do_intermix(struct buffers *buffers, |
| 1127 | do_copy do_copy_func, |
| 1128 | do_hang do_hang_func, |
| 1129 | int do_rcs) |
| 1130 | { |
| 1131 | const int half = buffers->count/2; |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1132 | igt_hang_t hang; |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1133 | int i; |
| 1134 | |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1135 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1136 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef^~i); |
| 1137 | buffers->mode->set_bo(buffers, buffers->dst[i], i); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1138 | } |
| 1139 | for (i = 0; i < half; i++) { |
| 1140 | if (do_rcs == 1 || (do_rcs == -1 && i & 1)) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1141 | render_copy_bo(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1142 | else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1143 | blt_copy_bo(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1144 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1145 | do_copy_func(buffers, buffers->dst[i+half], buffers->src[i]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1146 | |
| 1147 | if (do_rcs == 1 || (do_rcs == -1 && (i & 1) == 0)) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1148 | render_copy_bo(buffers, buffers->dst[i], buffers->dst[i+half]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1149 | else |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1150 | blt_copy_bo(buffers, buffers->dst[i], buffers->dst[i+half]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1151 | |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1152 | do_copy_func(buffers, buffers->dst[i+half], buffers->src[i+half]); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1153 | } |
| 1154 | hang = do_hang_func(); |
| 1155 | for (i = 0; i < 2*half; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1156 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef^~i); |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1157 | igt_post_hang_ring(fd, hang); |
| 1158 | } |
| 1159 | |
| 1160 | static void do_intermix_rcs(struct buffers *buffers, |
| 1161 | do_copy do_copy_func, |
| 1162 | do_hang do_hang_func) |
| 1163 | { |
| 1164 | do_intermix(buffers, do_copy_func, do_hang_func, 1); |
| 1165 | } |
| 1166 | |
| 1167 | static void do_intermix_bcs(struct buffers *buffers, |
| 1168 | do_copy do_copy_func, |
| 1169 | do_hang do_hang_func) |
| 1170 | { |
| 1171 | do_intermix(buffers, do_copy_func, do_hang_func, 0); |
| 1172 | } |
| 1173 | |
| 1174 | static void do_intermix_both(struct buffers *buffers, |
| 1175 | do_copy do_copy_func, |
| 1176 | do_hang do_hang_func) |
| 1177 | { |
| 1178 | do_intermix(buffers, do_copy_func, do_hang_func, -1); |
| 1179 | } |
| 1180 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1181 | static void do_early_read(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1182 | do_copy do_copy_func, |
| 1183 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1184 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1185 | igt_hang_t hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1186 | int i; |
| 1187 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1188 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1189 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1190 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1191 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1192 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1193 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1194 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1195 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1196 | } |
| 1197 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1198 | static void do_read_read_bcs(struct buffers *buffers, |
| 1199 | do_copy do_copy_func, |
| 1200 | do_hang do_hang_func) |
| 1201 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1202 | igt_hang_t hang; |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1203 | int i; |
| 1204 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1205 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1206 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1207 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1208 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
| 1209 | blt_copy_bo(buffers, buffers->spare, buffers->src[i]); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1210 | } |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1211 | buffers->mode->cmp_bo(buffers, buffers->spare, 0xdeadbeef^(buffers->count-1)); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1212 | hang = do_hang_func(); |
| 1213 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1214 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1215 | igt_post_hang_ring(fd, hang); |
| 1216 | } |
| 1217 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1218 | static void do_write_read_bcs(struct buffers *buffers, |
| 1219 | do_copy do_copy_func, |
| 1220 | do_hang do_hang_func) |
| 1221 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1222 | igt_hang_t hang; |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1223 | int i; |
| 1224 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1225 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1226 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1227 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1228 | blt_copy_bo(buffers, buffers->spare, buffers->src[i]); |
| 1229 | do_copy_func(buffers, buffers->dst[i], buffers->spare); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1230 | } |
| 1231 | hang = do_hang_func(); |
| 1232 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1233 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1234 | igt_post_hang_ring(fd, hang); |
| 1235 | } |
| 1236 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1237 | static void do_read_read_rcs(struct buffers *buffers, |
| 1238 | do_copy do_copy_func, |
| 1239 | do_hang do_hang_func) |
| 1240 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1241 | igt_hang_t hang; |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1242 | int i; |
| 1243 | |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1244 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1245 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1246 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1247 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
| 1248 | render_copy_bo(buffers, buffers->spare, buffers->src[i]); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1249 | } |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1250 | buffers->mode->cmp_bo(buffers, buffers->spare, 0xdeadbeef^(buffers->count-1)); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1251 | hang = do_hang_func(); |
| 1252 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1253 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1254 | igt_post_hang_ring(fd, hang); |
| 1255 | } |
| 1256 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1257 | static void do_write_read_rcs(struct buffers *buffers, |
| 1258 | do_copy do_copy_func, |
| 1259 | do_hang do_hang_func) |
| 1260 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1261 | igt_hang_t hang; |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1262 | int i; |
| 1263 | |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1264 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1265 | buffers->mode->set_bo(buffers, buffers->src[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1266 | for (i = 0; i < buffers->count; i++) { |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1267 | render_copy_bo(buffers, buffers->spare, buffers->src[i]); |
| 1268 | do_copy_func(buffers, buffers->dst[i], buffers->spare); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1269 | } |
| 1270 | hang = do_hang_func(); |
| 1271 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1272 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xdeadbeef ^ i); |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1273 | igt_post_hang_ring(fd, hang); |
| 1274 | } |
| 1275 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1276 | static void do_gpu_read_after_write(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1277 | do_copy do_copy_func, |
| 1278 | do_hang do_hang_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1279 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame] | 1280 | igt_hang_t hang; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1281 | int i; |
| 1282 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1283 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1284 | buffers->mode->set_bo(buffers, buffers->src[i], 0xabcdabcd); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1285 | for (i = 0; i < buffers->count; i++) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1286 | do_copy_func(buffers, buffers->dst[i], buffers->src[i]); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1287 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1288 | do_copy_func(buffers, buffers->spare, buffers->dst[i]); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1289 | hang = do_hang_func(); |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1290 | for (i = buffers->count; i--; ) |
Chris Wilson | 37f4da0 | 2016-01-27 13:02:35 +0000 | [diff] [blame] | 1291 | buffers->mode->cmp_bo(buffers, buffers->dst[i], 0xabcdabcd); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1292 | igt_post_hang_ring(fd, hang); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1293 | } |
| 1294 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1295 | typedef void (*do_test)(struct buffers *buffers, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1296 | do_copy do_copy_func, |
| 1297 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1298 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1299 | typedef void (*run_wrap)(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1300 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1301 | do_copy do_copy_func, |
| 1302 | do_hang do_hang_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1303 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1304 | static void run_single(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1305 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1306 | do_copy do_copy_func, |
| 1307 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1308 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1309 | pass = 0; |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1310 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1311 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
Chris Wilson | 99b5ee8 | 2015-01-22 10:03:45 +0000 | [diff] [blame] | 1314 | static void run_interruptible(struct buffers *buffers, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1315 | do_test do_test_func, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1316 | do_copy do_copy_func, |
| 1317 | do_hang do_hang_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1318 | { |
Chris Wilson | 1c61c0f | 2016-01-08 10:51:09 +0000 | [diff] [blame] | 1319 | pass = 0; |
Daniel Vetter | d7050f9 | 2016-05-11 17:06:28 +0200 | [diff] [blame] | 1320 | igt_while_interruptible(true) |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1321 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1322 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
Chris Wilson | 4645630 | 2016-01-22 19:29:07 +0000 | [diff] [blame] | 1325 | static void run_child(struct buffers *buffers, |
| 1326 | do_test do_test_func, |
| 1327 | do_copy do_copy_func, |
| 1328 | do_hang do_hang_func) |
| 1329 | |
| 1330 | { |
Chris Wilson | 69ecede | 2016-01-22 22:14:33 +0000 | [diff] [blame] | 1331 | /* We inherit the buffers from the parent, but the bufmgr/batch |
| 1332 | * needs to be local as the cache of reusable itself will be COWed, |
| 1333 | * leading to the child closing an object without the parent knowing. |
| 1334 | */ |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1335 | pass = 0; |
Chris Wilson | a1b47ef | 2016-01-27 19:44:16 +0000 | [diff] [blame] | 1336 | igt_fork(child, 1) |
Chris Wilson | 4645630 | 2016-01-22 19:29:07 +0000 | [diff] [blame] | 1337 | do_test_func(buffers, do_copy_func, do_hang_func); |
Chris Wilson | 4645630 | 2016-01-22 19:29:07 +0000 | [diff] [blame] | 1338 | igt_waitchildren(); |
| 1339 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
| 1340 | } |
| 1341 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1342 | static void __run_forked(struct buffers *buffers, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1343 | int num_children, int loops, bool interrupt, |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1344 | do_test do_test_func, |
| 1345 | do_copy do_copy_func, |
| 1346 | do_hang do_hang_func) |
| 1347 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1348 | { |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 1349 | /* purge the libdrm caches before cloing the process */ |
Chris Wilson | bca3ab2 | 2016-09-23 07:39:57 +0100 | [diff] [blame] | 1350 | buffers_destroy(buffers); |
| 1351 | intel_batchbuffer_free(buffers->batch); |
| 1352 | drm_intel_bufmgr_destroy(buffers->bufmgr); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1353 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1354 | igt_fork(child, num_children) { |
Chris Wilson | 459ff6b | 2016-04-20 07:49:02 +0100 | [diff] [blame] | 1355 | int num_buffers; |
| 1356 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 1357 | /* recreate process local variables */ |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 1358 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1359 | |
Chris Wilson | 459ff6b | 2016-04-20 07:49:02 +0100 | [diff] [blame] | 1360 | num_buffers = buffers->num_buffers / num_children; |
| 1361 | num_buffers += MIN_BUFFERS; |
| 1362 | if (num_buffers < buffers->num_buffers) |
| 1363 | buffers->num_buffers = num_buffers; |
Chris Wilson | c46f3c3 | 2016-04-10 20:44:58 +0100 | [diff] [blame] | 1364 | |
| 1365 | buffers_reset(buffers, true); |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 1366 | buffers_create(buffers); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 1367 | |
Daniel Vetter | d7050f9 | 2016-05-11 17:06:28 +0200 | [diff] [blame] | 1368 | igt_while_interruptible(interrupt) { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1369 | for (pass = 0; pass < loops; pass++) |
| 1370 | do_test_func(buffers, |
| 1371 | do_copy_func, |
| 1372 | do_hang_func); |
| 1373 | } |
| 1374 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 1375 | igt_waitchildren(); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1376 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Chris Wilson | bca3ab2 | 2016-09-23 07:39:57 +0100 | [diff] [blame] | 1377 | |
| 1378 | buffers_reset(buffers, true); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 1379 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1380 | |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1381 | static void run_forked(struct buffers *buffers, |
| 1382 | do_test do_test_func, |
| 1383 | do_copy do_copy_func, |
| 1384 | do_hang do_hang_func) |
| 1385 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1386 | const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
| 1387 | __run_forked(buffers, ncpus, ncpus, false, |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1388 | do_test_func, do_copy_func, do_hang_func); |
| 1389 | } |
| 1390 | |
| 1391 | static void run_bomb(struct buffers *buffers, |
| 1392 | do_test do_test_func, |
| 1393 | do_copy do_copy_func, |
| 1394 | do_hang do_hang_func) |
| 1395 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1396 | const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); |
| 1397 | __run_forked(buffers, 8*ncpus, 2, true, |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1398 | do_test_func, do_copy_func, do_hang_func); |
| 1399 | } |
| 1400 | |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1401 | static void cpu_require(void) |
| 1402 | { |
| 1403 | bit17_require(); |
| 1404 | } |
| 1405 | |
| 1406 | static void gtt_require(void) |
| 1407 | { |
| 1408 | } |
| 1409 | |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1410 | static void bcs_require(void) |
| 1411 | { |
| 1412 | } |
| 1413 | |
| 1414 | static void rcs_require(void) |
| 1415 | { |
| 1416 | igt_require(rendercopy); |
| 1417 | } |
| 1418 | |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1419 | static void |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1420 | run_mode(const char *prefix, |
| 1421 | const struct create *create, |
| 1422 | const struct access_mode *mode, |
| 1423 | const struct size *size, |
| 1424 | const int num_buffers, |
| 1425 | const char *suffix, |
| 1426 | run_wrap run_wrap_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1427 | { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1428 | const struct { |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1429 | const char *prefix; |
| 1430 | do_copy copy; |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1431 | void (*require)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1432 | } pipelines[] = { |
Chris Wilson | f2a045f | 2015-01-02 16:33:33 +0530 | [diff] [blame] | 1433 | { "cpu", cpu_copy_bo, cpu_require }, |
| 1434 | { "gtt", gtt_copy_bo, gtt_require }, |
| 1435 | { "wc", wc_copy_bo, wc_require }, |
Daniel Vetter | 3e9b4e3 | 2015-02-06 23:10:26 +0100 | [diff] [blame] | 1436 | { "blt", blt_copy_bo, bcs_require }, |
| 1437 | { "render", render_copy_bo, rcs_require }, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1438 | { NULL, NULL } |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1439 | }, *pskip = pipelines + 3, *p; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1440 | const struct { |
| 1441 | const char *suffix; |
| 1442 | do_hang hang; |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1443 | } hangs[] = { |
Chris Wilson | 92caf13 | 2015-12-16 09:23:56 +0000 | [diff] [blame] | 1444 | { "", no_hang }, |
| 1445 | { "-hang-blt", bcs_hang }, |
| 1446 | { "-hang-render", rcs_hang }, |
Chris Wilson | fcb4cfa | 2016-03-20 11:38:26 +0000 | [diff] [blame] | 1447 | { "-hang-all", all_hang }, |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1448 | { NULL, NULL }, |
| 1449 | }, *h; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1450 | struct buffers buffers; |
| 1451 | |
| 1452 | igt_fixture |
| 1453 | buffers_init(&buffers, prefix, create, mode, |
| 1454 | size, num_buffers, |
| 1455 | fd, run_wrap_func != run_child); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1456 | |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1457 | for (h = hangs; h->suffix; h++) { |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1458 | if (!all && *h->suffix) |
| 1459 | continue; |
| 1460 | |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1461 | if (!*h->suffix) |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 1462 | igt_fixture |
| 1463 | igt_fork_hang_detector(fd); |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1464 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1465 | for (p = all ? pipelines : pskip; p->prefix; p++) { |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1466 | igt_subtest_group { |
| 1467 | igt_fixture p->require(); |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1468 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1469 | igt_subtest_f("%s-%s-%s-sanitycheck0%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1470 | buffers_create(&buffers); |
| 1471 | run_wrap_func(&buffers, do_basic0, |
| 1472 | p->copy, h->hang); |
| 1473 | } |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1474 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1475 | igt_subtest_f("%s-%s-%s-sanitycheck1%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1476 | buffers_create(&buffers); |
| 1477 | run_wrap_func(&buffers, do_basic1, |
| 1478 | p->copy, h->hang); |
| 1479 | } |
Chris Wilson | 8bf09f3 | 2015-12-17 09:16:42 +0000 | [diff] [blame] | 1480 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1481 | igt_subtest_f("%s-%s-%s-sanitycheckN%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1482 | buffers_create(&buffers); |
| 1483 | run_wrap_func(&buffers, do_basicN, |
| 1484 | p->copy, h->hang); |
| 1485 | } |
Chris Wilson | 197db86 | 2015-12-09 20:54:10 +0000 | [diff] [blame] | 1486 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1487 | /* try to overwrite the source values */ |
| 1488 | igt_subtest_f("%s-%s-%s-overwrite-source-one%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1489 | buffers_create(&buffers); |
| 1490 | run_wrap_func(&buffers, |
| 1491 | do_overwrite_source__one, |
| 1492 | p->copy, h->hang); |
| 1493 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1494 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1495 | igt_subtest_f("%s-%s-%s-overwrite-source%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1496 | buffers_create(&buffers); |
| 1497 | run_wrap_func(&buffers, |
| 1498 | do_overwrite_source, |
| 1499 | p->copy, h->hang); |
| 1500 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1501 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1502 | igt_subtest_f("%s-%s-%s-overwrite-source-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1503 | buffers_create(&buffers); |
| 1504 | run_wrap_func(&buffers, |
| 1505 | do_overwrite_source_read_bcs, |
| 1506 | p->copy, h->hang); |
| 1507 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1508 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1509 | igt_subtest_f("%s-%s-%s-overwrite-source-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1510 | igt_require(rendercopy); |
| 1511 | buffers_create(&buffers); |
| 1512 | run_wrap_func(&buffers, |
| 1513 | do_overwrite_source_read_rcs, |
| 1514 | p->copy, h->hang); |
| 1515 | } |
Chris Wilson | a172676 | 2015-03-16 16:29:57 +0000 | [diff] [blame] | 1516 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1517 | igt_subtest_f("%s-%s-%s-overwrite-source-rev%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1518 | buffers_create(&buffers); |
| 1519 | run_wrap_func(&buffers, |
| 1520 | do_overwrite_source__rev, |
| 1521 | p->copy, h->hang); |
| 1522 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1523 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1524 | /* try to intermix copies with GPU copies*/ |
| 1525 | igt_subtest_f("%s-%s-%s-intermix-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1526 | igt_require(rendercopy); |
| 1527 | buffers_create(&buffers); |
| 1528 | run_wrap_func(&buffers, |
| 1529 | do_intermix_rcs, |
| 1530 | p->copy, h->hang); |
| 1531 | } |
| 1532 | igt_subtest_f("%s-%s-%s-intermix-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1533 | igt_require(rendercopy); |
| 1534 | buffers_create(&buffers); |
| 1535 | run_wrap_func(&buffers, |
| 1536 | do_intermix_bcs, |
| 1537 | p->copy, h->hang); |
| 1538 | } |
| 1539 | igt_subtest_f("%s-%s-%s-intermix-both%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1540 | igt_require(rendercopy); |
| 1541 | buffers_create(&buffers); |
| 1542 | run_wrap_func(&buffers, |
| 1543 | do_intermix_both, |
| 1544 | p->copy, h->hang); |
| 1545 | } |
Chris Wilson | a72d405 | 2015-03-18 14:15:22 +0000 | [diff] [blame] | 1546 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1547 | /* try to read the results before the copy completes */ |
| 1548 | igt_subtest_f("%s-%s-%s-early-read%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1549 | buffers_create(&buffers); |
| 1550 | run_wrap_func(&buffers, |
| 1551 | do_early_read, |
| 1552 | p->copy, h->hang); |
| 1553 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1554 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1555 | /* concurrent reads */ |
| 1556 | igt_subtest_f("%s-%s-%s-read-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1557 | buffers_create(&buffers); |
| 1558 | run_wrap_func(&buffers, |
| 1559 | do_read_read_bcs, |
| 1560 | p->copy, h->hang); |
| 1561 | } |
| 1562 | igt_subtest_f("%s-%s-%s-read-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1563 | igt_require(rendercopy); |
| 1564 | buffers_create(&buffers); |
| 1565 | run_wrap_func(&buffers, |
| 1566 | do_read_read_rcs, |
| 1567 | p->copy, h->hang); |
| 1568 | } |
Chris Wilson | 35b0ac9 | 2015-03-16 11:55:46 +0000 | [diff] [blame] | 1569 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1570 | /* split copying between rings */ |
| 1571 | igt_subtest_f("%s-%s-%s-write-read-bcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1572 | buffers_create(&buffers); |
| 1573 | run_wrap_func(&buffers, |
| 1574 | do_write_read_bcs, |
| 1575 | p->copy, h->hang); |
| 1576 | } |
| 1577 | igt_subtest_f("%s-%s-%s-write-read-rcs%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1578 | igt_require(rendercopy); |
| 1579 | buffers_create(&buffers); |
| 1580 | run_wrap_func(&buffers, |
| 1581 | do_write_read_rcs, |
| 1582 | p->copy, h->hang); |
| 1583 | } |
Chris Wilson | 0c26652 | 2015-11-11 16:37:16 +0000 | [diff] [blame] | 1584 | |
Chris Wilson | b2e8d2c | 2016-07-27 23:21:45 +0100 | [diff] [blame] | 1585 | /* and finally try to trick the kernel into loosing the pending write */ |
| 1586 | igt_subtest_f("%s-%s-%s-gpu-read-after-write%s%s", prefix, mode->name, p->prefix, suffix, h->suffix) { |
| 1587 | buffers_create(&buffers); |
| 1588 | run_wrap_func(&buffers, |
| 1589 | do_gpu_read_after_write, |
| 1590 | p->copy, h->hang); |
| 1591 | } |
Chris Wilson | 16bafdf | 2014-09-04 09:26:24 +0100 | [diff] [blame] | 1592 | } |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame] | 1593 | } |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1594 | |
| 1595 | if (!*h->suffix) |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 1596 | igt_fixture |
| 1597 | igt_stop_hang_detector(); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1598 | } |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1599 | |
| 1600 | igt_fixture |
| 1601 | buffers_fini(&buffers); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 1602 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1603 | |
| 1604 | static void |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 1605 | run_modes(const char *style, |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 1606 | const struct create *create, |
Chris Wilson | 094e0cb | 2016-03-01 13:22:03 +0000 | [diff] [blame] | 1607 | const struct access_mode *mode, |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1608 | const struct size *size, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1609 | const int num) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1610 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1611 | const struct wrap { |
| 1612 | const char *suffix; |
| 1613 | run_wrap func; |
| 1614 | } wrappers[] = { |
| 1615 | { "", run_single }, |
| 1616 | { "-child", run_child }, |
| 1617 | { "-forked", run_forked }, |
| 1618 | { "-interruptible", run_interruptible }, |
| 1619 | { "-bomb", run_bomb }, |
| 1620 | { NULL }, |
| 1621 | }; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1622 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1623 | while (mode->name) { |
| 1624 | igt_subtest_group { |
| 1625 | igt_fixture { |
| 1626 | if (mode->require) |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 1627 | mode->require(create, num); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | for (const struct wrap *w = wrappers; w->suffix; w++) { |
| 1631 | run_mode(style, create, mode, size, num, |
| 1632 | w->suffix, w->func); |
| 1633 | } |
Daniel Vetter | 9665073 | 2016-03-18 21:55:00 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1636 | mode++; |
Daniel Vetter | 9665073 | 2016-03-18 21:55:00 +0100 | [diff] [blame] | 1637 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1640 | static unsigned |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1641 | num_buffers(uint64_t max, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1642 | const struct size *s, |
| 1643 | const struct create *c, |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1644 | unsigned allow_mem) |
| 1645 | { |
| 1646 | unsigned size = 4*s->width*s->height; |
Chris Wilson | 9e7e7c3 | 2016-04-11 09:17:33 +0100 | [diff] [blame] | 1647 | uint64_t n; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1648 | |
Chris Wilson | 9e7e7c3 | 2016-04-11 09:17:33 +0100 | [diff] [blame] | 1649 | igt_assert(size); |
| 1650 | n = max / (2*size); |
| 1651 | n += MIN_BUFFERS; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1652 | |
Chris Wilson | 9e7e7c3 | 2016-04-11 09:17:33 +0100 | [diff] [blame] | 1653 | igt_require(n < INT32_MAX); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1654 | igt_require(set_max_map_count(2*n)); |
| 1655 | |
Chris Wilson | e85613b | 2016-03-19 14:01:38 +0000 | [diff] [blame] | 1656 | if (c->require) |
| 1657 | c->require(c, n); |
| 1658 | |
Chris Wilson | 6867b87 | 2016-03-24 07:57:30 +0000 | [diff] [blame] | 1659 | intel_require_memory(2*n, size, allow_mem); |
| 1660 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1661 | return n; |
| 1662 | } |
| 1663 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 1664 | igt_main |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1665 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1666 | const struct access_mode modes[] = { |
| 1667 | { |
| 1668 | .name = "prw", |
| 1669 | .create_bo = unmapped_create_bo, |
| 1670 | .set_bo = prw_set_bo, |
| 1671 | .cmp_bo = prw_cmp_bo, |
| 1672 | .release_bo = nop_release_bo, |
| 1673 | }, |
| 1674 | { |
| 1675 | .name = "partial", |
| 1676 | .create_bo = unmapped_create_bo, |
| 1677 | .set_bo = partial_set_bo, |
| 1678 | .cmp_bo = partial_cmp_bo, |
| 1679 | .release_bo = nop_release_bo, |
| 1680 | }, |
| 1681 | { |
| 1682 | .name = "cpu", |
| 1683 | .create_bo = unmapped_create_bo, |
| 1684 | .require = create_cpu_require, |
| 1685 | .set_bo = cpu_set_bo, |
| 1686 | .cmp_bo = cpu_cmp_bo, |
| 1687 | .release_bo = nop_release_bo, |
| 1688 | }, |
| 1689 | { |
| 1690 | .name = "snoop", |
| 1691 | .create_bo = snoop_create_bo, |
| 1692 | .require = create_snoop_require, |
| 1693 | .set_bo = cpu_set_bo, |
| 1694 | .cmp_bo = cpu_cmp_bo, |
| 1695 | .release_bo = nop_release_bo, |
| 1696 | }, |
| 1697 | { |
| 1698 | .name = "userptr", |
| 1699 | .create_bo = userptr_create_bo, |
| 1700 | .require = create_userptr_require, |
| 1701 | .set_bo = userptr_set_bo, |
| 1702 | .cmp_bo = userptr_cmp_bo, |
| 1703 | .release_bo = userptr_release_bo, |
| 1704 | }, |
| 1705 | { |
| 1706 | .name = "dmabuf", |
| 1707 | .create_bo = dmabuf_create_bo, |
| 1708 | .require = create_dmabuf_require, |
| 1709 | .set_bo = dmabuf_set_bo, |
| 1710 | .cmp_bo = dmabuf_cmp_bo, |
| 1711 | .release_bo = dmabuf_release_bo, |
| 1712 | }, |
| 1713 | { |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 1714 | .name = "vgem", |
| 1715 | .create_bo = vgem_create_bo, |
| 1716 | .require = create_vgem_require, |
| 1717 | .set_bo = dmabuf_set_bo, |
| 1718 | .cmp_bo = dmabuf_cmp_bo, |
| 1719 | .release_bo = dmabuf_release_bo, |
| 1720 | }, |
| 1721 | { |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1722 | .name = "gtt", |
| 1723 | .create_bo = gtt_create_bo, |
| 1724 | .set_bo = gtt_set_bo, |
| 1725 | .cmp_bo = gtt_cmp_bo, |
| 1726 | .release_bo = nop_release_bo, |
| 1727 | }, |
| 1728 | { |
| 1729 | .name = "gttX", |
| 1730 | .create_bo = gttX_create_bo, |
| 1731 | .set_bo = gtt_set_bo, |
| 1732 | .cmp_bo = gtt_cmp_bo, |
| 1733 | .release_bo = nop_release_bo, |
| 1734 | }, |
| 1735 | { |
| 1736 | .name = "wc", |
| 1737 | .require = wc_create_require, |
| 1738 | .create_bo = wc_create_bo, |
| 1739 | .set_bo = gtt_set_bo, |
| 1740 | .cmp_bo = gtt_cmp_bo, |
| 1741 | .release_bo = wc_release_bo, |
| 1742 | }, |
| 1743 | { |
| 1744 | .name = "gpu", |
| 1745 | .create_bo = gpu_create_bo, |
| 1746 | .set_bo = gpu_set_bo, |
| 1747 | .cmp_bo = gpu_cmp_bo, |
| 1748 | .release_bo = nop_release_bo, |
| 1749 | }, |
| 1750 | { |
| 1751 | .name = "gpuX", |
| 1752 | .create_bo = gpuX_create_bo, |
| 1753 | .set_bo = gpu_set_bo, |
| 1754 | .cmp_bo = gpu_cmp_bo, |
| 1755 | .release_bo = nop_release_bo, |
| 1756 | }, |
| 1757 | { NULL }, |
| 1758 | }; |
Chris Wilson | 4eba8e2 | 2016-03-18 10:44:31 +0000 | [diff] [blame] | 1759 | const struct create create[] = { |
| 1760 | { "", can_create_normal, create_normal_bo}, |
| 1761 | #if HAVE_CREATE_PRIVATE |
| 1762 | { "private-", can_create_private, create_private_bo}, |
| 1763 | #endif |
| 1764 | #if HAVE_CREATE_STOLEN |
| 1765 | { "stolen-", can_create_stolen, create_stolen_bo}, |
| 1766 | #endif |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 1767 | { NULL, NULL } |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1768 | }; |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1769 | const struct size sizes[] = { |
| 1770 | { "4KiB", 128, 8 }, |
| 1771 | { "256KiB", 128, 128 }, |
| 1772 | { "1MiB", 512, 512 }, |
| 1773 | { "16MiB", 2048, 2048 }, |
| 1774 | { NULL} |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1775 | }; |
Chris Wilson | 42291f2 | 2016-01-07 11:19:26 +0000 | [diff] [blame] | 1776 | uint64_t pin_sz = 0; |
| 1777 | void *pinned = NULL; |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1778 | char name[80]; |
| 1779 | int count = 0; |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1780 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1781 | igt_skip_on_simulation(); |
| 1782 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 1783 | if (strstr(igt_test_name(), "all")) |
| 1784 | all = true; |
| 1785 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 1786 | igt_fixture { |
Lucas De Marchi | 8bc8086 | 2019-04-04 15:16:11 -0700 | [diff] [blame] | 1787 | igt_allow_unlimited_files(); |
Chris Wilson | 3d8af56 | 2016-03-20 10:49:54 +0000 | [diff] [blame] | 1788 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 1789 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 9518cb5 | 2017-02-22 15:24:54 +0000 | [diff] [blame] | 1790 | igt_require_gem(fd); |
Chris Wilson | 5b675f7 | 2016-01-22 17:33:40 +0000 | [diff] [blame] | 1791 | intel_detect_and_clear_missed_interrupts(fd); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1792 | devid = intel_get_drm_devid(fd); |
| 1793 | gen = intel_gen(devid); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 1794 | rendercopy = igt_get_render_copyfunc(devid); |
Chris Wilson | e7ed4ef | 2016-07-18 11:38:09 +0100 | [diff] [blame] | 1795 | |
| 1796 | vgem_drv = __drm_open_driver(DRIVER_VGEM); |
Chris Wilson | 2d08e9e | 2015-12-11 09:25:03 +0000 | [diff] [blame] | 1797 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 1798 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1799 | for (const struct create *c = create; c->name; c++) { |
| 1800 | for (const struct size *s = sizes; s->name; s++) { |
| 1801 | /* Minimum test set */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1802 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1803 | c->name, s->name, "tiny"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1804 | igt_subtest_group { |
| 1805 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1806 | count = num_buffers(0, s, c, CHECK_RAM); |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1807 | } |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1808 | run_modes(name, c, modes, s, count); |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1811 | /* "Average" test set */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1812 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1813 | c->name, s->name, "small"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1814 | igt_subtest_group { |
| 1815 | igt_fixture { |
Ville Syrjälä | e408d56 | 2019-03-27 20:52:52 +0200 | [diff] [blame] | 1816 | count = num_buffers(gem_mappable_aperture_size()/4, |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1817 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1818 | } |
| 1819 | run_modes(name, c, modes, s, count); |
| 1820 | } |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1821 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1822 | /* Use the entire mappable aperture */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1823 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1824 | c->name, s->name, "thrash"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1825 | igt_subtest_group { |
| 1826 | igt_fixture { |
Ville Syrjälä | e408d56 | 2019-03-27 20:52:52 +0200 | [diff] [blame] | 1827 | count = num_buffers(gem_mappable_aperture_size(), |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1828 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1829 | } |
| 1830 | run_modes(name, c, modes, s, count); |
| 1831 | } |
| 1832 | |
| 1833 | /* Use the entire global GTT */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1834 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1835 | c->name, s->name, "global"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1836 | igt_subtest_group { |
| 1837 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1838 | count = num_buffers(gem_global_aperture_size(fd), |
| 1839 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1840 | } |
| 1841 | run_modes(name, c, modes, s, count); |
| 1842 | } |
| 1843 | |
| 1844 | /* Use the entire per-process GTT */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1845 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1846 | c->name, s->name, "full"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1847 | igt_subtest_group { |
| 1848 | igt_fixture { |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1849 | count = num_buffers(gem_aperture_size(fd), |
| 1850 | s, c, CHECK_RAM); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1851 | } |
| 1852 | run_modes(name, c, modes, s, count); |
| 1853 | } |
| 1854 | |
Chris Wilson | e8eb9af | 2017-03-08 13:09:00 +0000 | [diff] [blame] | 1855 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1856 | c->name, s->name, "shrink"); |
| 1857 | igt_subtest_group { |
| 1858 | igt_fixture { |
Ville Syrjälä | e408d56 | 2019-03-27 20:52:52 +0200 | [diff] [blame] | 1859 | count = num_buffers(gem_mappable_aperture_size(), |
Chris Wilson | e8eb9af | 2017-03-08 13:09:00 +0000 | [diff] [blame] | 1860 | s, c, CHECK_RAM); |
| 1861 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 1862 | igt_fork_shrink_helper(fd); |
Chris Wilson | e8eb9af | 2017-03-08 13:09:00 +0000 | [diff] [blame] | 1863 | } |
| 1864 | run_modes(name, c, modes, s, count); |
| 1865 | |
| 1866 | igt_fixture |
| 1867 | igt_stop_shrink_helper(); |
| 1868 | } |
| 1869 | |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1870 | /* Use the entire mappable aperture, force swapping */ |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1871 | snprintf(name, sizeof(name), "%s%s-%s", |
| 1872 | c->name, s->name, "swap"); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1873 | igt_subtest_group { |
| 1874 | igt_fixture { |
Ville Syrjälä | e408d56 | 2019-03-27 20:52:52 +0200 | [diff] [blame] | 1875 | if (intel_get_avail_ram_mb() > gem_mappable_aperture_size()/(1024*1024)) { |
| 1876 | pin_sz = intel_get_avail_ram_mb() - gem_mappable_aperture_size()/(1024*1024); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1877 | |
| 1878 | igt_debug("Pinning %lld MiB\n", (long long)pin_sz); |
| 1879 | pin_sz *= 1024 * 1024; |
| 1880 | |
| 1881 | if (posix_memalign(&pinned, 4096, pin_sz) || |
| 1882 | mlock(pinned, pin_sz) || |
| 1883 | madvise(pinned, pin_sz, MADV_DONTFORK)) { |
| 1884 | free(pinned); |
| 1885 | pinned = NULL; |
| 1886 | } |
| 1887 | igt_require(pinned); |
| 1888 | } |
| 1889 | |
Ville Syrjälä | e408d56 | 2019-03-27 20:52:52 +0200 | [diff] [blame] | 1890 | count = num_buffers(gem_mappable_aperture_size(), |
Chris Wilson | f338e98 | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1891 | s, c, CHECK_RAM | CHECK_SWAP); |
Chris Wilson | c2248ef | 2016-03-19 13:10:17 +0000 | [diff] [blame] | 1892 | } |
| 1893 | run_modes(name, c, modes, s, count); |
| 1894 | |
| 1895 | igt_fixture { |
| 1896 | if (pinned) { |
| 1897 | munlock(pinned, pin_sz); |
| 1898 | free(pinned); |
| 1899 | pinned = NULL; |
| 1900 | } |
Chris Wilson | 5d669bf | 2016-03-18 14:44:53 +0000 | [diff] [blame] | 1901 | } |
Chris Wilson | 42291f2 | 2016-01-07 11:19:26 +0000 | [diff] [blame] | 1902 | } |
Chris Wilson | 1d6e5d3 | 2016-01-03 13:44:17 +0000 | [diff] [blame] | 1903 | } |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 1904 | } |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1905 | } |