Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2009 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 | */ |
| 24 | |
| 25 | /** @file gem_exec_whisper.c |
| 26 | * |
| 27 | * Pass around a value to write into a scratch buffer between lots of batches |
| 28 | */ |
| 29 | |
| 30 | #include "igt.h" |
| 31 | #include "igt_gt.h" |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 32 | #include "igt_sysfs.h" |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 33 | |
| 34 | #define LOCAL_I915_EXEC_NO_RELOC (1<<11) |
| 35 | #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) |
| 36 | |
| 37 | #define LOCAL_I915_EXEC_BSD_SHIFT (13) |
| 38 | #define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) |
| 39 | |
| 40 | #define ENGINE_MASK (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) |
| 41 | |
Chris Wilson | 8f6ed9e | 2016-03-12 11:20:03 +0000 | [diff] [blame] | 42 | #define VERIFY 0 |
| 43 | |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 44 | static void write_seqno(unsigned offset) |
| 45 | { |
| 46 | uint32_t seqno = UINT32_MAX - offset; |
| 47 | FILE *file; |
| 48 | |
| 49 | file = igt_debugfs_fopen("i915_next_seqno", "w"); |
| 50 | igt_assert(file); |
| 51 | |
| 52 | igt_assert(fprintf(file, "0x%x", seqno) > 0); |
| 53 | fclose(file); |
| 54 | |
| 55 | igt_debug("next seqno set to: 0x%x\n", seqno); |
| 56 | } |
| 57 | |
| 58 | static void check_bo(int fd, uint32_t handle) |
| 59 | { |
| 60 | uint32_t *map; |
| 61 | int i; |
| 62 | |
| 63 | igt_debug("Verifying result\n"); |
| 64 | map = gem_mmap__cpu(fd, handle, 0, 4096, PROT_READ); |
| 65 | gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, 0); |
| 66 | for (i = 0; i < 1024; i++) |
| 67 | igt_assert_eq(map[i], i); |
| 68 | munmap(map, 4096); |
| 69 | } |
| 70 | |
Chris Wilson | 8f6ed9e | 2016-03-12 11:20:03 +0000 | [diff] [blame] | 71 | static void verify_reloc(int fd, uint32_t handle, |
| 72 | const struct drm_i915_gem_relocation_entry *reloc) |
| 73 | { |
| 74 | if (VERIFY) { |
| 75 | uint64_t target = 0; |
| 76 | if (intel_gen(intel_get_drm_devid(fd)) >= 8) |
| 77 | gem_read(fd, handle, reloc->offset, &target, 8); |
| 78 | else |
| 79 | gem_read(fd, handle, reloc->offset, &target, 4); |
| 80 | igt_assert_eq_u64(target, |
| 81 | reloc->presumed_offset + reloc->delta); |
| 82 | } |
| 83 | } |
| 84 | |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 85 | static int __gem_context_create(int fd, uint32_t *ctx_id) |
| 86 | { |
| 87 | struct drm_i915_gem_context_create arg; |
| 88 | int ret = 0; |
| 89 | |
| 90 | memset(&arg, 0, sizeof(arg)); |
| 91 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &arg)) |
| 92 | ret = -errno; |
| 93 | |
| 94 | *ctx_id = arg.ctx_id; |
| 95 | return ret; |
| 96 | } |
| 97 | |
Chris Wilson | 3b22b89 | 2016-03-21 11:00:52 +0000 | [diff] [blame] | 98 | static bool can_mi_store_dword(int gen, unsigned engine) |
| 99 | { |
| 100 | return !(gen == 6 && (engine & ~(3<<13)) == I915_EXEC_BSD); |
| 101 | } |
| 102 | |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 103 | static bool ignore_engine(int gen, unsigned engine) |
| 104 | { |
Chris Wilson | 5df2de7 | 2016-03-15 09:52:57 +0000 | [diff] [blame] | 105 | if (engine == 0) |
| 106 | return true; |
| 107 | |
Chris Wilson | 3b22b89 | 2016-03-21 11:00:52 +0000 | [diff] [blame] | 108 | if (!can_mi_store_dword(gen, engine)) |
Chris Wilson | 5df2de7 | 2016-03-15 09:52:57 +0000 | [diff] [blame] | 109 | return true; |
| 110 | |
| 111 | return false; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | #define CONTEXTS 0x1 |
Chris Wilson | 9eacbd2 | 2016-03-11 14:31:56 +0000 | [diff] [blame] | 115 | #define FDS 0x2 |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 116 | #define INTERRUPTIBLE 0x4 |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 117 | #define CHAIN 0x8 |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 118 | #define FORKED 0x10 |
Chris Wilson | 1a76d88 | 2016-10-01 16:50:51 +0100 | [diff] [blame^] | 119 | #define HANG 0x20 |
| 120 | |
| 121 | struct hang { |
| 122 | struct drm_i915_gem_exec_object2 obj; |
| 123 | struct drm_i915_gem_relocation_entry reloc; |
| 124 | struct drm_i915_gem_execbuffer2 execbuf; |
| 125 | int fd; |
| 126 | }; |
| 127 | |
| 128 | static void init_hang(struct hang *h) |
| 129 | { |
| 130 | uint32_t *batch; |
| 131 | int i, gen; |
| 132 | |
| 133 | h->fd = drm_open_driver(DRIVER_INTEL); |
| 134 | igt_allow_hang(h->fd, 0, 0); |
| 135 | |
| 136 | gen = intel_gen(intel_get_drm_devid(h->fd)); |
| 137 | |
| 138 | memset(&h->execbuf, 0, sizeof(h->execbuf)); |
| 139 | h->execbuf.buffers_ptr = (uintptr_t)&h->obj; |
| 140 | h->execbuf.buffer_count = 1; |
| 141 | |
| 142 | memset(&h->obj, 0, sizeof(h->obj)); |
| 143 | h->obj.handle = gem_create(h->fd, 4096); |
| 144 | |
| 145 | h->obj.relocs_ptr = (uintptr_t)&h->reloc; |
| 146 | h->obj.relocation_count = 1; |
| 147 | memset(&h->reloc, 0, sizeof(h->reloc)); |
| 148 | |
| 149 | batch = gem_mmap__cpu(h->fd, h->obj.handle, 0, 4096, PROT_WRITE); |
| 150 | gem_set_domain(h->fd, h->obj.handle, |
| 151 | I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); |
| 152 | |
| 153 | h->reloc.target_handle = h->obj.handle; /* recurse */ |
| 154 | h->reloc.presumed_offset = 0; |
| 155 | h->reloc.offset = 5*sizeof(uint32_t); |
| 156 | h->reloc.delta = 0; |
| 157 | h->reloc.read_domains = I915_GEM_DOMAIN_COMMAND; |
| 158 | h->reloc.write_domain = 0; |
| 159 | |
| 160 | i = 0; |
| 161 | batch[i++] = 0xffffffff; |
| 162 | batch[i++] = 0xdeadbeef; |
| 163 | batch[i++] = 0xc00fee00; |
| 164 | batch[i++] = 0x00c00fee; |
| 165 | batch[i] = MI_BATCH_BUFFER_START; |
| 166 | if (gen >= 8) { |
| 167 | batch[i] |= 1 << 8 | 1; |
| 168 | batch[++i] = 0; |
| 169 | batch[++i] = 0; |
| 170 | } else if (gen >= 6) { |
| 171 | batch[i] |= 1 << 8; |
| 172 | batch[++i] = 0; |
| 173 | } else { |
| 174 | batch[i] |= 2 << 6; |
| 175 | batch[++i] = 0; |
| 176 | if (gen < 4) { |
| 177 | batch[i] |= 1; |
| 178 | h->reloc.delta = 1; |
| 179 | } |
| 180 | } |
| 181 | munmap(batch, 4096); |
| 182 | } |
| 183 | |
| 184 | static void submit_hang(struct hang *h, unsigned *engines, int nengine) |
| 185 | { |
| 186 | while (nengine--) { |
| 187 | h->execbuf.flags &= ~ENGINE_MASK; |
| 188 | h->execbuf.flags |= *engines++; |
| 189 | gem_execbuf(h->fd, &h->execbuf); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | static void fini_hang(struct hang *h) |
| 194 | { |
| 195 | close(h->fd); |
| 196 | } |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 197 | |
Chris Wilson | 2fdf5ac | 2016-03-14 13:41:15 +0000 | [diff] [blame] | 198 | static void whisper(int fd, unsigned engine, unsigned flags) |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 199 | { |
Chris Wilson | 3e76584 | 2016-07-02 11:51:29 +0100 | [diff] [blame] | 200 | const uint32_t bbe = MI_BATCH_BUFFER_END; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 201 | const int gen = intel_gen(intel_get_drm_devid(fd)); |
| 202 | struct drm_i915_gem_exec_object2 batches[1024]; |
| 203 | struct drm_i915_gem_relocation_entry inter[1024]; |
| 204 | struct drm_i915_gem_relocation_entry reloc; |
Chris Wilson | 8f6ed9e | 2016-03-12 11:20:03 +0000 | [diff] [blame] | 205 | struct drm_i915_gem_exec_object2 store, scratch; |
| 206 | struct drm_i915_gem_exec_object2 tmp[2]; |
| 207 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | 1a76d88 | 2016-10-01 16:50:51 +0100 | [diff] [blame^] | 208 | struct hang hang; |
Chris Wilson | 9eacbd2 | 2016-03-11 14:31:56 +0000 | [diff] [blame] | 209 | int fds[64]; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 210 | uint32_t contexts[64]; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 211 | unsigned engines[16]; |
| 212 | unsigned nengine; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 213 | uint32_t batch[16]; |
| 214 | int i, n, pass, loc; |
Chris Wilson | 5dcb026 | 2016-03-26 09:48:16 +0000 | [diff] [blame] | 215 | unsigned int relocations = 0; |
Chris Wilson | 488dc3b | 2016-03-15 09:16:30 +0000 | [diff] [blame] | 216 | unsigned int reloc_migrations = 0; |
Chris Wilson | d5e550f | 2016-03-21 11:58:21 +0000 | [diff] [blame] | 217 | unsigned int reloc_interruptions = 0; |
Chris Wilson | 488dc3b | 2016-03-15 09:16:30 +0000 | [diff] [blame] | 218 | unsigned int eb_migrations = 0; |
Chris Wilson | 5dcb026 | 2016-03-26 09:48:16 +0000 | [diff] [blame] | 219 | uint64_t old_offset; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 220 | |
| 221 | nengine = 0; |
Chris Wilson | 2fdf5ac | 2016-03-14 13:41:15 +0000 | [diff] [blame] | 222 | if (engine == -1) { |
| 223 | for_each_engine(fd, engine) { |
| 224 | if (!ignore_engine(gen, engine)) |
| 225 | engines[nengine++] = engine; |
| 226 | } |
| 227 | } else { |
| 228 | igt_require(gem_has_ring(fd, engine)); |
Chris Wilson | d5e550f | 2016-03-21 11:58:21 +0000 | [diff] [blame] | 229 | igt_require(can_mi_store_dword(gen, engine)); |
Chris Wilson | 2fdf5ac | 2016-03-14 13:41:15 +0000 | [diff] [blame] | 230 | engines[nengine++] = engine; |
| 231 | } |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 232 | igt_require(nengine); |
| 233 | |
Chris Wilson | 1a76d88 | 2016-10-01 16:50:51 +0100 | [diff] [blame^] | 234 | if (flags & HANG) |
| 235 | init_hang(&hang); |
| 236 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 237 | intel_detect_and_clear_missed_interrupts(fd); |
| 238 | igt_fork(child, flags & FORKED ? sysconf(_SC_NPROCESSORS_ONLN) : 1) { |
| 239 | memset(&scratch, 0, sizeof(scratch)); |
| 240 | scratch.handle = gem_create(fd, 4096); |
| 241 | scratch.flags = EXEC_OBJECT_WRITE; |
Chris Wilson | 8f6ed9e | 2016-03-12 11:20:03 +0000 | [diff] [blame] | 242 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 243 | memset(&store, 0, sizeof(store)); |
| 244 | store.handle = gem_create(fd, 4096); |
| 245 | store.relocs_ptr = (uintptr_t)&reloc; |
| 246 | store.relocation_count = 1; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 247 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 248 | memset(&reloc, 0, sizeof(reloc)); |
| 249 | reloc.offset = sizeof(uint32_t); |
| 250 | if (gen < 8 && gen >= 4) |
| 251 | reloc.offset += sizeof(uint32_t); |
| 252 | loc = 8; |
| 253 | if (gen >= 4) |
| 254 | loc += 4; |
| 255 | reloc.read_domains = I915_GEM_DOMAIN_INSTRUCTION; |
| 256 | reloc.write_domain = I915_GEM_DOMAIN_INSTRUCTION; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 257 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 258 | { |
| 259 | tmp[0] = scratch; |
| 260 | tmp[1] = store; |
| 261 | gem_write(fd, store.handle, 0, &bbe, sizeof(bbe)); |
Chris Wilson | 8f6ed9e | 2016-03-12 11:20:03 +0000 | [diff] [blame] | 262 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 263 | memset(&execbuf, 0, sizeof(execbuf)); |
| 264 | execbuf.buffers_ptr = (uintptr_t)tmp; |
| 265 | execbuf.buffer_count = 2; |
| 266 | execbuf.flags = LOCAL_I915_EXEC_HANDLE_LUT; |
| 267 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
| 268 | if (gen < 6) |
| 269 | execbuf.flags |= I915_EXEC_SECURE; |
| 270 | igt_require(__gem_execbuf(fd, &execbuf) == 0); |
| 271 | scratch = tmp[0]; |
| 272 | store = tmp[1]; |
Chris Wilson | 3e76584 | 2016-07-02 11:51:29 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 275 | i = 0; |
| 276 | batch[i] = MI_STORE_DWORD_IMM | (gen < 6 ? 1 << 22 : 0); |
| 277 | if (gen >= 8) { |
| 278 | batch[++i] = store.offset + loc; |
| 279 | batch[++i] = (store.offset + loc) >> 32; |
| 280 | } else if (gen >= 4) { |
| 281 | batch[++i] = 0; |
| 282 | batch[++i] = store.offset + loc; |
| 283 | } else { |
| 284 | batch[i]--; |
| 285 | batch[++i] = store.offset + loc; |
| 286 | } |
| 287 | batch[++i] = 0xc0ffee; |
| 288 | igt_assert(loc == sizeof(uint32_t) * i); |
| 289 | batch[++i] = MI_BATCH_BUFFER_END; |
Chris Wilson | 3e76584 | 2016-07-02 11:51:29 +0100 | [diff] [blame] | 290 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 291 | if (flags & CONTEXTS) { |
| 292 | igt_require(__gem_context_create(fd, &contexts[0]) == 0); |
| 293 | for (n = 1; n < 64; n++) |
| 294 | contexts[n] = gem_context_create(fd); |
| 295 | } |
| 296 | if (flags & FDS) { |
| 297 | igt_require(gen >= 6); |
| 298 | for (n = 0; n < 64; n++) |
| 299 | fds[n] = drm_open_driver(DRIVER_INTEL); |
| 300 | } |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 301 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 302 | memset(batches, 0, sizeof(batches)); |
| 303 | for (n = 0; n < 1024; n++) { |
| 304 | batches[n].handle = gem_create(fd, 4096); |
| 305 | gem_write(fd, batches[n].handle, 0, &bbe, sizeof(bbe)); |
| 306 | } |
| 307 | execbuf.buffers_ptr = (uintptr_t)batches; |
| 308 | execbuf.buffer_count = 1024; |
| 309 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 310 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 311 | execbuf.buffers_ptr = (uintptr_t)tmp; |
| 312 | execbuf.buffer_count = 2; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 313 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 314 | old_offset = store.offset; |
| 315 | for (n = 0; n < 1024; n++) { |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 316 | if (gen >= 8) { |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 317 | batch[1] = old_offset + loc; |
| 318 | batch[2] = (old_offset + loc) >> 32; |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 319 | } else if (gen >= 4) { |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 320 | batch[2] = old_offset + loc; |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 321 | } else { |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 322 | batch[1] = old_offset + loc; |
Chris Wilson | 9eacbd2 | 2016-03-11 14:31:56 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 325 | inter[n] = reloc; |
| 326 | inter[n].presumed_offset = old_offset; |
| 327 | inter[n].delta = loc; |
| 328 | batches[n].relocs_ptr = (uintptr_t)&inter[n]; |
| 329 | batches[n].relocation_count = 1; |
| 330 | gem_write(fd, batches[n].handle, 0, batch, sizeof(batch)); |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 331 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 332 | old_offset = batches[n].offset; |
| 333 | } |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 334 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 335 | igt_while_interruptible(flags & INTERRUPTIBLE) { |
| 336 | for (pass = 0; pass < 1024; pass++) { |
| 337 | uint64_t offset; |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 338 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 339 | if (child == 0) |
| 340 | write_seqno(pass); |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 341 | |
Chris Wilson | 1a76d88 | 2016-10-01 16:50:51 +0100 | [diff] [blame^] | 342 | if (flags & HANG) |
| 343 | submit_hang(&hang, engines, nengine); |
| 344 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 345 | if (flags & CHAIN) { |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 346 | execbuf.flags &= ~ENGINE_MASK; |
| 347 | execbuf.flags |= engines[rand() % nengine]; |
| 348 | } |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 349 | |
| 350 | reloc.presumed_offset = scratch.offset; |
| 351 | reloc.delta = 4*pass; |
| 352 | offset = reloc.presumed_offset + reloc.delta; |
| 353 | |
| 354 | i = 0; |
| 355 | if (gen >= 8) { |
| 356 | batch[++i] = offset; |
| 357 | batch[++i] = offset >> 32; |
| 358 | } else if (gen >= 4) { |
| 359 | batch[++i] = 0; |
| 360 | batch[++i] = offset; |
| 361 | } else { |
| 362 | batch[++i] = offset; |
| 363 | } |
| 364 | batch[++i] = ~pass; |
| 365 | gem_write(fd, store.handle, 0, batch, sizeof(batch)); |
| 366 | |
| 367 | tmp[0] = scratch; |
| 368 | igt_assert(tmp[0].flags & EXEC_OBJECT_WRITE); |
| 369 | tmp[1] = store; |
| 370 | verify_reloc(fd, store.handle, &reloc); |
| 371 | execbuf.buffers_ptr = (uintptr_t)tmp; |
| 372 | gem_execbuf(fd, &execbuf); |
| 373 | igt_assert_eq_u64(reloc.presumed_offset, tmp[0].offset); |
| 374 | scratch = tmp[0]; |
| 375 | |
| 376 | gem_write(fd, batches[1023].handle, loc, &pass, sizeof(pass)); |
| 377 | for (n = 1024; --n >= 1; ) { |
| 378 | int this_fd = fd; |
| 379 | uint32_t handle[2]; |
| 380 | |
| 381 | execbuf.buffers_ptr = (uintptr_t)&batches[n-1]; |
| 382 | reloc_migrations += batches[n-1].offset != inter[n].presumed_offset; |
| 383 | batches[n-1].offset = inter[n].presumed_offset; |
| 384 | old_offset = inter[n].presumed_offset; |
| 385 | batches[n-1].relocation_count = 0; |
| 386 | batches[n-1].flags |= EXEC_OBJECT_WRITE; |
| 387 | verify_reloc(fd, batches[n].handle, &inter[n]); |
| 388 | |
| 389 | if (flags & FDS) { |
| 390 | this_fd = fds[rand() % 64]; |
| 391 | handle[0] = batches[n-1].handle; |
| 392 | handle[1] = batches[n].handle; |
| 393 | batches[n-1].handle = |
| 394 | gem_open(this_fd, |
| 395 | gem_flink(fd, handle[0])); |
| 396 | batches[n].handle = |
| 397 | gem_open(this_fd, |
| 398 | gem_flink(fd, handle[1])); |
| 399 | } |
| 400 | |
| 401 | if (!(flags & CHAIN)) { |
| 402 | execbuf.flags &= ~ENGINE_MASK; |
| 403 | execbuf.flags |= engines[rand() % nengine]; |
| 404 | } |
| 405 | if (flags & CONTEXTS) |
| 406 | execbuf.rsvd1 = contexts[rand() % 64]; |
| 407 | gem_execbuf(this_fd, &execbuf); |
| 408 | if (inter[n].presumed_offset == -1) { |
| 409 | reloc_interruptions++; |
| 410 | inter[n].presumed_offset = batches[n-1].offset; |
| 411 | } |
| 412 | igt_assert_eq_u64(inter[n].presumed_offset, batches[n-1].offset); |
| 413 | relocations += inter[n].presumed_offset != old_offset; |
| 414 | |
| 415 | batches[n-1].relocation_count = 1; |
| 416 | batches[n-1].flags &= ~EXEC_OBJECT_WRITE; |
| 417 | |
| 418 | if (this_fd != fd) { |
| 419 | gem_close(this_fd, batches[n-1].handle); |
| 420 | batches[n-1].handle = handle[0]; |
| 421 | |
| 422 | gem_close(this_fd, batches[n].handle); |
| 423 | batches[n].handle = handle[1]; |
| 424 | } |
| 425 | } |
| 426 | execbuf.flags &= ~ENGINE_MASK; |
| 427 | execbuf.rsvd1 = 0; |
| 428 | execbuf.buffers_ptr = (uintptr_t)&tmp; |
| 429 | |
| 430 | tmp[0] = tmp[1]; |
| 431 | tmp[0].relocation_count = 0; |
| 432 | tmp[0].flags = EXEC_OBJECT_WRITE; |
| 433 | reloc_migrations += tmp[0].offset != inter[0].presumed_offset; |
| 434 | tmp[0].offset = inter[0].presumed_offset; |
| 435 | old_offset = tmp[0].offset; |
| 436 | tmp[1] = batches[0]; |
| 437 | verify_reloc(fd, batches[0].handle, &inter[0]); |
| 438 | gem_execbuf(fd, &execbuf); |
| 439 | if (inter[0].presumed_offset == -1) { |
Chris Wilson | 5dcb026 | 2016-03-26 09:48:16 +0000 | [diff] [blame] | 440 | reloc_interruptions++; |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 441 | inter[0].presumed_offset = tmp[0].offset; |
Chris Wilson | 5dcb026 | 2016-03-26 09:48:16 +0000 | [diff] [blame] | 442 | } |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 443 | igt_assert_eq_u64(inter[0].presumed_offset, tmp[0].offset); |
| 444 | relocations += inter[0].presumed_offset != old_offset; |
| 445 | batches[0] = tmp[1]; |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 446 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 447 | tmp[1] = tmp[0]; |
| 448 | tmp[0] = scratch; |
| 449 | igt_assert(tmp[0].flags & EXEC_OBJECT_WRITE); |
| 450 | igt_assert_eq_u64(reloc.presumed_offset, tmp[0].offset); |
| 451 | igt_assert(tmp[1].relocs_ptr == (uintptr_t)&reloc); |
| 452 | tmp[1].relocation_count = 1; |
| 453 | tmp[1].flags &= ~EXEC_OBJECT_WRITE; |
| 454 | verify_reloc(fd, store.handle, &reloc); |
| 455 | gem_execbuf(fd, &execbuf); |
| 456 | eb_migrations += tmp[0].offset != scratch.offset; |
| 457 | eb_migrations += tmp[1].offset != store.offset; |
| 458 | igt_assert_eq_u64(reloc.presumed_offset, tmp[0].offset); |
| 459 | store = tmp[1]; |
| 460 | scratch = tmp[0]; |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 461 | } |
Chris Wilson | 6291678 | 2016-03-11 14:16:13 +0000 | [diff] [blame] | 462 | } |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 463 | igt_info("Number of migrations for execbuf: %d\n", eb_migrations); |
| 464 | igt_info("Number of migrations for reloc: %d, interrupted %d, patched %d\n", reloc_migrations, reloc_interruptions, relocations); |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 465 | |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 466 | check_bo(fd, scratch.handle); |
| 467 | gem_close(fd, scratch.handle); |
| 468 | gem_close(fd, store.handle); |
| 469 | |
| 470 | if (flags & FDS) { |
| 471 | for (n = 0; n < 64; n++) |
| 472 | close(fds[n]); |
| 473 | } |
| 474 | if (flags & CONTEXTS) { |
| 475 | for (n = 0; n < 64; n++) |
| 476 | gem_context_destroy(fd, contexts[n]); |
| 477 | } |
| 478 | for (n = 0; n < 1024; n++) |
| 479 | gem_close(fd, batches[n].handle); |
| 480 | } |
| 481 | |
| 482 | igt_waitchildren(); |
Chris Wilson | 1a76d88 | 2016-10-01 16:50:51 +0100 | [diff] [blame^] | 483 | |
| 484 | if (flags & HANG) |
| 485 | fini_hang(&hang); |
| 486 | else |
| 487 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 490 | static void print_welcome(int fd) |
| 491 | { |
| 492 | bool active; |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 493 | int dir; |
| 494 | |
| 495 | dir = igt_sysfs_open_parameters(fd); |
| 496 | if (dir < 0) |
| 497 | return; |
| 498 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 499 | active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 500 | if (active) { |
| 501 | igt_info("Using GuC submission\n"); |
| 502 | goto out; |
| 503 | } |
| 504 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 505 | active = igt_sysfs_get_boolean(dir, "enable_execlists"); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 506 | if (active) { |
| 507 | igt_info("Using Execlists submission\n"); |
| 508 | goto out; |
| 509 | } |
| 510 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 511 | active = igt_sysfs_get_boolean(dir, "semaphores"); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 512 | igt_info("Using Legacy submission%s\n", |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 513 | active ? ", with semaphores" : ""); |
| 514 | |
| 515 | out: |
| 516 | close(dir); |
| 517 | } |
| 518 | |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 519 | igt_main |
| 520 | { |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 521 | const struct mode { |
| 522 | const char *name; |
| 523 | unsigned flags; |
| 524 | } modes[] = { |
Chris Wilson | 2b4c35e | 2016-05-20 11:20:49 +0100 | [diff] [blame] | 525 | { "normal", 0 }, |
Chris Wilson | 1a722fa | 2016-03-26 10:54:43 +0000 | [diff] [blame] | 526 | { "interruptible", INTERRUPTIBLE }, |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 527 | { "forked", FORKED }, |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 528 | { "chain", CHAIN }, |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 529 | { "chain-forked", CHAIN | FORKED }, |
| 530 | { "chain-interruptible", CHAIN | INTERRUPTIBLE }, |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 531 | { "contexts", CONTEXTS }, |
| 532 | { "contexts-interruptible", CONTEXTS | INTERRUPTIBLE}, |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 533 | { "contexts-forked", CONTEXTS | FORKED}, |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 534 | { "contexts-chain", CONTEXTS | CHAIN }, |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 535 | { "fds", FDS }, |
| 536 | { "fds-interruptible", FDS | INTERRUPTIBLE}, |
Chris Wilson | 587753b | 2016-09-12 16:06:48 +0100 | [diff] [blame] | 537 | { "fds-forked", FDS | FORKED}, |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 538 | { "fds-chain", FDS | CHAIN}, |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 539 | { NULL } |
| 540 | }; |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 541 | int fd; |
| 542 | |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 543 | igt_fixture { |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 544 | fd = drm_open_driver_master(DRIVER_INTEL); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 545 | print_welcome(fd); |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 546 | |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 547 | igt_fork_hang_detector(fd); |
| 548 | } |
Chris Wilson | 756f3e0 | 2016-03-22 11:33:41 +0000 | [diff] [blame] | 549 | |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 550 | for (const struct mode *m = modes; m->name; m++) |
Chris Wilson | 2b4c35e | 2016-05-20 11:20:49 +0100 | [diff] [blame] | 551 | igt_subtest_f("%s", m->name) |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 552 | whisper(fd, -1, m->flags); |
Chris Wilson | 2fdf5ac | 2016-03-14 13:41:15 +0000 | [diff] [blame] | 553 | |
| 554 | for (const struct intel_execution_engine *e = intel_execution_engines; |
| 555 | e->name; e++) { |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 556 | for (const struct mode *m = modes; m->name; m++) { |
| 557 | if (m->flags & CHAIN) |
| 558 | continue; |
| 559 | |
Chris Wilson | 2b4c35e | 2016-05-20 11:20:49 +0100 | [diff] [blame] | 560 | igt_subtest_f("%s-%s", e->name, m->name) |
Chris Wilson | 83cfed8 | 2016-03-19 14:21:34 +0000 | [diff] [blame] | 561 | whisper(fd, e->exec_id | e->flags, m->flags); |
Chris Wilson | 7b34c51 | 2016-06-04 16:12:28 +0100 | [diff] [blame] | 562 | } |
Chris Wilson | 2fdf5ac | 2016-03-14 13:41:15 +0000 | [diff] [blame] | 563 | } |
Chris Wilson | 9eacbd2 | 2016-03-11 14:31:56 +0000 | [diff] [blame] | 564 | |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 565 | igt_fixture { |
| 566 | igt_stop_hang_detector(); |
Chris Wilson | 1a76d88 | 2016-10-01 16:50:51 +0100 | [diff] [blame^] | 567 | } |
| 568 | |
| 569 | igt_subtest_group { |
| 570 | for (const struct mode *m = modes; m->name; m++) { |
| 571 | if (m->flags & INTERRUPTIBLE) |
| 572 | continue; |
| 573 | igt_subtest_f("hang-%s", m->name) |
| 574 | whisper(fd, -1, m->flags | HANG); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | igt_fixture { |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 579 | close(fd); |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 580 | } |
Chris Wilson | 5615ab2 | 2016-03-11 10:48:47 +0000 | [diff] [blame] | 581 | } |