Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016 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 | #include "igt.h" |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 26 | #include <unistd.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <stdint.h> |
| 29 | #include <stdio.h> |
| 30 | #include <string.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <inttypes.h> |
| 33 | #include <errno.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/ioctl.h> |
| 36 | #include <sys/time.h> |
Chris Wilson | ef999ae | 2017-03-01 10:57:06 +0000 | [diff] [blame] | 37 | #include <sys/signal.h> |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 38 | #include <time.h> |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 39 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 40 | #include "drm.h" |
| 41 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 42 | #include "igt_sysfs.h" |
| 43 | #include "igt_vgem.h" |
| 44 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 45 | #define LOCAL_I915_EXEC_NO_RELOC (1<<11) |
| 46 | #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) |
| 47 | |
| 48 | #define LOCAL_I915_EXEC_BSD_SHIFT (13) |
| 49 | #define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) |
| 50 | |
| 51 | #define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) |
| 52 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 53 | #define CORK 1 |
| 54 | |
Chris Wilson | ef999ae | 2017-03-01 10:57:06 +0000 | [diff] [blame] | 55 | static unsigned int ring_size; |
| 56 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 57 | struct cork { |
| 58 | int device; |
| 59 | uint32_t handle; |
| 60 | uint32_t fence; |
| 61 | }; |
| 62 | |
| 63 | static void plug(int fd, struct cork *c) |
| 64 | { |
| 65 | struct vgem_bo bo; |
| 66 | int dmabuf; |
| 67 | |
| 68 | c->device = drm_open_driver(DRIVER_VGEM); |
| 69 | |
| 70 | bo.width = bo.height = 1; |
| 71 | bo.bpp = 4; |
| 72 | vgem_create(c->device, &bo); |
| 73 | c->fence = vgem_fence_attach(c->device, &bo, VGEM_FENCE_WRITE); |
| 74 | |
| 75 | dmabuf = prime_handle_to_fd(c->device, bo.handle); |
| 76 | c->handle = prime_fd_to_handle(fd, dmabuf); |
| 77 | close(dmabuf); |
| 78 | } |
| 79 | |
| 80 | static void unplug(struct cork *c) |
| 81 | { |
| 82 | vgem_fence_signal(c->device, c->fence); |
| 83 | close(c->device); |
| 84 | } |
| 85 | |
Chris Wilson | ef999ae | 2017-03-01 10:57:06 +0000 | [diff] [blame] | 86 | static void alarm_handler(int sig) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | static void set_timeout(int seconds) |
| 91 | { |
| 92 | struct sigaction sa = { .sa_handler = alarm_handler }; |
| 93 | |
| 94 | sigaction(SIGALRM, seconds ? &sa : NULL, NULL); |
| 95 | alarm(seconds); |
| 96 | } |
| 97 | |
| 98 | static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf) |
| 99 | { |
| 100 | return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf); |
| 101 | } |
| 102 | |
| 103 | static unsigned int measure_ring_size(int fd) |
| 104 | { |
| 105 | struct drm_i915_gem_exec_object2 obj[2]; |
| 106 | struct drm_i915_gem_execbuffer2 execbuf; |
| 107 | const uint32_t bbe = MI_BATCH_BUFFER_END; |
| 108 | unsigned int count; |
| 109 | struct cork c; |
| 110 | |
| 111 | memset(obj, 0, sizeof(obj)); |
| 112 | obj[1].handle = gem_create(fd, 4096); |
| 113 | gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe)); |
| 114 | |
| 115 | plug(fd, &c); |
| 116 | obj[0].handle = c.handle; |
| 117 | |
| 118 | memset(&execbuf, 0, sizeof(execbuf)); |
| 119 | execbuf.buffers_ptr = to_user_pointer(obj); |
| 120 | execbuf.buffer_count = 2; |
| 121 | |
| 122 | count = 0; |
| 123 | set_timeout(1); |
| 124 | while (__execbuf(fd, &execbuf) == 0) |
| 125 | count++; |
| 126 | set_timeout(0); |
| 127 | |
| 128 | unplug(&c); |
| 129 | gem_close(fd, obj[1].handle); |
| 130 | |
| 131 | return count; |
| 132 | } |
| 133 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 134 | #define RCS_TIMESTAMP (0x2000 + 0x358) |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 135 | static void latency_on_ring(int fd, |
| 136 | unsigned ring, const char *name, |
| 137 | unsigned flags) |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 138 | { |
| 139 | const int gen = intel_gen(intel_get_drm_devid(fd)); |
| 140 | const int has_64bit_reloc = gen >= 8; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 141 | struct drm_i915_gem_exec_object2 obj[3]; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 142 | struct drm_i915_gem_relocation_entry reloc; |
| 143 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 144 | struct cork c; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 145 | volatile uint32_t *reg; |
Chris Wilson | ef999ae | 2017-03-01 10:57:06 +0000 | [diff] [blame] | 146 | unsigned repeats = ring_size; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 147 | uint32_t start, end, *map, *results; |
| 148 | uint64_t offset; |
| 149 | double gpu_latency; |
| 150 | int i, j; |
| 151 | |
| 152 | reg = (volatile uint32_t *)((volatile char *)igt_global_mmio + RCS_TIMESTAMP); |
| 153 | |
| 154 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 155 | execbuf.buffers_ptr = to_user_pointer(&obj[1]); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 156 | execbuf.buffer_count = 2; |
| 157 | execbuf.flags = ring; |
| 158 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC | LOCAL_I915_EXEC_HANDLE_LUT; |
| 159 | |
| 160 | memset(obj, 0, sizeof(obj)); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 161 | obj[1].handle = gem_create(fd, 4096); |
| 162 | obj[1].flags = EXEC_OBJECT_WRITE; |
| 163 | results = gem_mmap__wc(fd, obj[1].handle, 0, 4096, PROT_READ); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 164 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 165 | obj[2].handle = gem_create(fd, 64*1024); |
| 166 | map = gem_mmap__wc(fd, obj[2].handle, 0, 64*1024, PROT_WRITE); |
| 167 | gem_set_domain(fd, obj[2].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 168 | I915_GEM_DOMAIN_GTT, |
| 169 | I915_GEM_DOMAIN_GTT); |
| 170 | map[0] = MI_BATCH_BUFFER_END; |
| 171 | gem_execbuf(fd, &execbuf); |
| 172 | |
| 173 | memset(&reloc,0, sizeof(reloc)); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 174 | obj[2].relocation_count = 1; |
| 175 | obj[2].relocs_ptr = to_user_pointer(&reloc); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 176 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 177 | gem_set_domain(fd, obj[2].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 178 | I915_GEM_DOMAIN_GTT, |
| 179 | I915_GEM_DOMAIN_GTT); |
| 180 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 181 | reloc.target_handle = flags & CORK ? 1 : 0; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 182 | reloc.read_domains = I915_GEM_DOMAIN_INSTRUCTION; |
| 183 | reloc.write_domain = I915_GEM_DOMAIN_INSTRUCTION; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 184 | reloc.presumed_offset = obj[1].offset; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 185 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 186 | for (j = 0; j < repeats; j++) { |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 187 | execbuf.batch_start_offset = 64 * j; |
| 188 | reloc.offset = |
| 189 | execbuf.batch_start_offset + sizeof(uint32_t); |
| 190 | reloc.delta = sizeof(uint32_t) * j; |
| 191 | |
| 192 | offset = reloc.presumed_offset; |
| 193 | offset += reloc.delta; |
| 194 | |
| 195 | i = 16 * j; |
| 196 | /* MI_STORE_REG_MEM */ |
| 197 | map[i++] = 0x24 << 23 | 1; |
| 198 | if (has_64bit_reloc) |
| 199 | map[i-1]++; |
| 200 | map[i++] = RCS_TIMESTAMP; /* ring local! */ |
| 201 | map[i++] = offset; |
| 202 | if (has_64bit_reloc) |
| 203 | map[i++] = offset >> 32; |
| 204 | map[i++] = MI_BATCH_BUFFER_END; |
| 205 | } |
| 206 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 207 | if (flags & CORK) { |
| 208 | plug(fd, &c); |
| 209 | obj[0].handle = c.handle; |
| 210 | execbuf.buffers_ptr = to_user_pointer(&obj[0]); |
| 211 | execbuf.buffer_count = 3; |
| 212 | } |
| 213 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 214 | start = *reg; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 215 | for (j = 0; j < repeats; j++) { |
Chris Wilson | a7c9add | 2017-02-23 02:04:31 +0000 | [diff] [blame] | 216 | uint64_t presumed_offset = reloc.presumed_offset; |
| 217 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 218 | execbuf.batch_start_offset = 64 * j; |
| 219 | reloc.offset = |
| 220 | execbuf.batch_start_offset + sizeof(uint32_t); |
| 221 | reloc.delta = sizeof(uint32_t) * j; |
| 222 | |
| 223 | gem_execbuf(fd, &execbuf); |
Chris Wilson | a7c9add | 2017-02-23 02:04:31 +0000 | [diff] [blame] | 224 | igt_assert(reloc.presumed_offset == presumed_offset); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 225 | } |
| 226 | end = *reg; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 227 | igt_assert(reloc.presumed_offset == obj[1].offset); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 228 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 229 | if (flags & CORK) |
| 230 | unplug(&c); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 231 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 232 | gem_set_domain(fd, obj[1].handle, I915_GEM_DOMAIN_GTT, 0); |
| 233 | gpu_latency = (results[repeats-1] - results[0]) / (double)(repeats-1); |
| 234 | |
| 235 | gem_set_domain(fd, obj[2].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 236 | I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); |
| 237 | |
| 238 | execbuf.batch_start_offset = 0; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 239 | for (j = 0; j < repeats - 1; j++) { |
| 240 | offset = obj[2].offset; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 241 | offset += 64 * (j + 1); |
| 242 | |
| 243 | i = 16 * j + (has_64bit_reloc ? 4 : 3); |
| 244 | map[i] = MI_BATCH_BUFFER_START; |
| 245 | if (gen >= 8) { |
| 246 | map[i] |= 1 << 8 | 1; |
| 247 | map[i + 1] = offset; |
| 248 | map[i + 2] = offset >> 32; |
| 249 | } else if (gen >= 6) { |
| 250 | map[i] |= 1 << 8; |
| 251 | map[i + 1] = offset; |
| 252 | } else { |
| 253 | map[i] |= 2 << 6; |
| 254 | map[i + 1] = offset; |
| 255 | if (gen < 4) |
| 256 | map[i] |= 1; |
| 257 | } |
| 258 | } |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 259 | offset = obj[2].offset; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 260 | gem_execbuf(fd, &execbuf); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 261 | igt_assert(offset == obj[2].offset); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 262 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 263 | gem_set_domain(fd, obj[1].handle, I915_GEM_DOMAIN_GTT, 0); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 264 | igt_info("%s: dispatch latency: %.2f, execution latency: %.2f (target %.2f)\n", |
| 265 | name, |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 266 | (end - start) / (double)repeats, |
| 267 | gpu_latency, (results[repeats - 1] - results[0]) / (double)(repeats - 1)); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 268 | |
| 269 | munmap(map, 64*1024); |
| 270 | munmap(results, 4096); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 271 | gem_close(fd, obj[1].handle); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 272 | gem_close(fd, obj[2].handle); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 275 | static void latency_from_ring(int fd, |
| 276 | unsigned ring, const char *name, |
| 277 | unsigned flags) |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 278 | { |
| 279 | const struct intel_execution_engine *e; |
| 280 | const int gen = intel_gen(intel_get_drm_devid(fd)); |
| 281 | const int has_64bit_reloc = gen >= 8; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 282 | struct drm_i915_gem_exec_object2 obj[3]; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 283 | struct drm_i915_gem_relocation_entry reloc; |
| 284 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | ef999ae | 2017-03-01 10:57:06 +0000 | [diff] [blame] | 285 | const unsigned int repeats = ring_size / 2; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 286 | uint32_t *map, *results; |
| 287 | int i, j; |
| 288 | |
| 289 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 290 | execbuf.buffers_ptr = to_user_pointer(&obj[1]); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 291 | execbuf.buffer_count = 2; |
| 292 | execbuf.flags = ring; |
| 293 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC | LOCAL_I915_EXEC_HANDLE_LUT; |
| 294 | |
| 295 | memset(obj, 0, sizeof(obj)); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 296 | obj[1].handle = gem_create(fd, 4096); |
| 297 | obj[1].flags = EXEC_OBJECT_WRITE; |
| 298 | results = gem_mmap__wc(fd, obj[1].handle, 0, 4096, PROT_READ); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 299 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 300 | obj[2].handle = gem_create(fd, 64*1024); |
| 301 | map = gem_mmap__wc(fd, obj[2].handle, 0, 64*1024, PROT_WRITE); |
| 302 | gem_set_domain(fd, obj[2].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 303 | I915_GEM_DOMAIN_GTT, |
| 304 | I915_GEM_DOMAIN_GTT); |
| 305 | map[0] = MI_BATCH_BUFFER_END; |
| 306 | gem_execbuf(fd, &execbuf); |
| 307 | |
| 308 | memset(&reloc,0, sizeof(reloc)); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 309 | obj[2].relocation_count = 1; |
| 310 | obj[2].relocs_ptr = to_user_pointer(&reloc); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 311 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 312 | gem_set_domain(fd, obj[2].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 313 | I915_GEM_DOMAIN_GTT, |
| 314 | I915_GEM_DOMAIN_GTT); |
| 315 | |
| 316 | reloc.read_domains = I915_GEM_DOMAIN_INSTRUCTION; |
| 317 | reloc.write_domain = I915_GEM_DOMAIN_INSTRUCTION; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 318 | reloc.presumed_offset = obj[1].offset; |
| 319 | reloc.target_handle = flags & CORK ? 1 : 0; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 320 | |
| 321 | for (e = intel_execution_engines; e->name; e++) { |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 322 | struct cork c; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 323 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 324 | if (e->exec_id == 0) |
| 325 | continue; |
| 326 | |
| 327 | if (!gem_has_ring(fd, e->exec_id | e->flags)) |
| 328 | continue; |
| 329 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 330 | gem_set_domain(fd, obj[2].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 331 | I915_GEM_DOMAIN_GTT, |
| 332 | I915_GEM_DOMAIN_GTT); |
| 333 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 334 | if (flags & CORK) { |
| 335 | plug(fd, &c); |
| 336 | obj[0].handle = c.handle; |
| 337 | execbuf.buffers_ptr = to_user_pointer(&obj[0]); |
| 338 | execbuf.buffer_count = 3; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | for (j = 0; j < repeats; j++) { |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 342 | uint64_t offset; |
| 343 | |
| 344 | execbuf.flags &= ~ENGINE_FLAGS; |
| 345 | execbuf.flags |= ring; |
| 346 | |
| 347 | execbuf.batch_start_offset = 64 * j; |
| 348 | reloc.offset = |
| 349 | execbuf.batch_start_offset + sizeof(uint32_t); |
| 350 | reloc.delta = sizeof(uint32_t) * j; |
| 351 | |
| 352 | offset = reloc.presumed_offset; |
| 353 | offset += reloc.delta; |
| 354 | |
| 355 | i = 16 * j; |
| 356 | /* MI_STORE_REG_MEM */ |
| 357 | map[i++] = 0x24 << 23 | 1; |
| 358 | if (has_64bit_reloc) |
| 359 | map[i-1]++; |
| 360 | map[i++] = RCS_TIMESTAMP; /* ring local! */ |
| 361 | map[i++] = offset; |
| 362 | if (has_64bit_reloc) |
| 363 | map[i++] = offset >> 32; |
| 364 | map[i++] = MI_BATCH_BUFFER_END; |
| 365 | |
| 366 | gem_execbuf(fd, &execbuf); |
| 367 | |
| 368 | execbuf.flags &= ~ENGINE_FLAGS; |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 369 | execbuf.flags |= e->exec_id | e->flags; |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 370 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 371 | execbuf.batch_start_offset = 64 * (j + repeats); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 372 | reloc.offset = |
| 373 | execbuf.batch_start_offset + sizeof(uint32_t); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 374 | reloc.delta = sizeof(uint32_t) * (j + repeats); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 375 | |
| 376 | offset = reloc.presumed_offset; |
| 377 | offset += reloc.delta; |
| 378 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 379 | i = 16 * (j + repeats); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 380 | /* MI_STORE_REG_MEM */ |
| 381 | map[i++] = 0x24 << 23 | 1; |
| 382 | if (has_64bit_reloc) |
| 383 | map[i-1]++; |
| 384 | map[i++] = RCS_TIMESTAMP; /* ring local! */ |
| 385 | map[i++] = offset; |
| 386 | if (has_64bit_reloc) |
| 387 | map[i++] = offset >> 32; |
| 388 | map[i++] = MI_BATCH_BUFFER_END; |
| 389 | |
| 390 | gem_execbuf(fd, &execbuf); |
| 391 | } |
| 392 | |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 393 | if (flags & CORK) |
| 394 | unplug(&c); |
| 395 | |
| 396 | gem_set_domain(fd, obj[1].handle, |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 397 | I915_GEM_DOMAIN_GTT, |
| 398 | I915_GEM_DOMAIN_GTT); |
| 399 | |
| 400 | igt_info("%s-%s delay: %.2f\n", |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 401 | name, e->name, (results[2*repeats-1] - results[0]) / (double)repeats); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | munmap(map, 64*1024); |
| 405 | munmap(results, 4096); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 406 | gem_close(fd, obj[1].handle); |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 407 | gem_close(fd, obj[2].handle); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static void print_welcome(int fd) |
| 411 | { |
| 412 | bool active; |
| 413 | int dir; |
| 414 | |
| 415 | dir = igt_sysfs_open_parameters(fd); |
| 416 | if (dir < 0) |
| 417 | return; |
| 418 | |
| 419 | active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); |
| 420 | if (active) { |
| 421 | igt_info("Using GuC submission\n"); |
| 422 | goto out; |
| 423 | } |
| 424 | |
| 425 | active = igt_sysfs_get_boolean(dir, "enable_execlists"); |
| 426 | if (active) { |
| 427 | igt_info("Using Execlists submission\n"); |
| 428 | goto out; |
| 429 | } |
| 430 | |
| 431 | active = igt_sysfs_get_boolean(dir, "semaphores"); |
| 432 | igt_info("Using Legacy submission%s\n", |
| 433 | active ? ", with semaphores" : ""); |
| 434 | |
| 435 | out: |
| 436 | close(dir); |
| 437 | } |
| 438 | |
| 439 | igt_main |
| 440 | { |
| 441 | const struct intel_execution_engine *e; |
| 442 | int device = -1; |
| 443 | |
| 444 | igt_fixture { |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 445 | device = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 9518cb5 | 2017-02-22 15:24:54 +0000 | [diff] [blame] | 446 | igt_require_gem(device); |
Chris Wilson | cf27943 | 2017-05-23 15:44:40 +0100 | [diff] [blame] | 447 | gem_require_mmap_wc(device); |
| 448 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 449 | print_welcome(device); |
Chris Wilson | ef999ae | 2017-03-01 10:57:06 +0000 | [diff] [blame] | 450 | |
| 451 | ring_size = measure_ring_size(device); |
| 452 | igt_info("Ring size: %d batches\n", ring_size); |
| 453 | igt_require(ring_size > 8); |
| 454 | ring_size -= 8; /* leave some spare */ |
| 455 | if (ring_size > 1024) |
| 456 | ring_size = 1024; |
Chris Wilson | cf27943 | 2017-05-23 15:44:40 +0100 | [diff] [blame] | 457 | |
| 458 | intel_register_access_init(intel_get_pci_device(), false, device); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | igt_subtest_group { |
| 462 | igt_fixture |
| 463 | igt_require(intel_gen(intel_get_drm_devid(device)) >= 7); |
| 464 | |
| 465 | for (e = intel_execution_engines; e->name; e++) { |
| 466 | if (e->exec_id == 0) |
| 467 | continue; |
| 468 | |
| 469 | igt_subtest_f("%s-dispatch", e->name) { |
| 470 | gem_require_ring(device, e->exec_id | e->flags); |
| 471 | latency_on_ring(device, |
| 472 | e->exec_id | e->flags, |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 473 | e->name, 0); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 474 | } |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 475 | |
| 476 | igt_subtest_f("%s-dispatch-queued", e->name) { |
| 477 | gem_require_ring(device, e->exec_id | e->flags); |
| 478 | latency_on_ring(device, |
| 479 | e->exec_id | e->flags, |
| 480 | e->name, CORK); |
| 481 | } |
| 482 | |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 483 | igt_subtest_f("%s-synchronisation", e->name) { |
| 484 | gem_require_ring(device, e->exec_id | e->flags); |
| 485 | latency_from_ring(device, |
| 486 | e->exec_id | e->flags, |
Chris Wilson | c460b41 | 2017-01-15 21:13:43 +0000 | [diff] [blame] | 487 | e->name, 0); |
| 488 | } |
| 489 | |
| 490 | igt_subtest_f("%s-synchronisation-queued", e->name) { |
| 491 | gem_require_ring(device, e->exec_id | e->flags); |
| 492 | latency_from_ring(device, |
| 493 | e->exec_id | e->flags, |
| 494 | e->name, CORK); |
Chris Wilson | 5c81016 | 2016-09-08 19:06:54 +0100 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | |
| 500 | igt_fixture { |
| 501 | close(device); |
| 502 | } |
| 503 | } |