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