Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 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 | * Chris Wilson <chris@chris-wilson.co.uk> |
| 25 | * |
| 26 | */ |
| 27 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 28 | #include "igt.h" |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 29 | #include "igt_rand.h" |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 30 | #include "igt_sysfs.h" |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 31 | |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 32 | #include <unistd.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <stdint.h> |
| 35 | #include <stdio.h> |
| 36 | #include <string.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 37 | #include <fcntl.h> |
| 38 | #include <inttypes.h> |
| 39 | #include <errno.h> |
| 40 | #include <sys/stat.h> |
| 41 | #include <sys/ioctl.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 42 | #include <sys/time.h> |
Chris Wilson | b430709 | 2015-07-01 13:53:07 +0100 | [diff] [blame] | 43 | #include <time.h> |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 44 | #include "drm.h" |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 45 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 46 | #define LOCAL_I915_EXEC_NO_RELOC (1<<11) |
| 47 | #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) |
| 48 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 49 | #define LOCAL_I915_EXEC_BSD_SHIFT (13) |
| 50 | #define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) |
Daniel Vetter | 51f0830 | 2012-12-05 19:29:11 +0100 | [diff] [blame] | 51 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 52 | #define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 53 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 54 | #define FORKED 1 |
| 55 | #define CHAINED 2 |
| 56 | #define CONTEXT 4 |
| 57 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 58 | static double elapsed(const struct timespec *start, const struct timespec *end) |
| 59 | { |
| 60 | return ((end->tv_sec - start->tv_sec) + |
| 61 | (end->tv_nsec - start->tv_nsec)*1e-9); |
| 62 | } |
| 63 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 64 | static double nop_on_ring(int fd, uint32_t handle, unsigned ring_id, |
| 65 | int timeout, unsigned long *out) |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 66 | { |
| 67 | struct drm_i915_gem_execbuffer2 execbuf; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 68 | struct drm_i915_gem_exec_object2 obj; |
| 69 | struct timespec start, now; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 70 | unsigned long count; |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 71 | |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 72 | memset(&obj, 0, sizeof(obj)); |
| 73 | obj.handle = handle; |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 74 | |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 75 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 76 | execbuf.buffers_ptr = to_user_pointer(&obj); |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 77 | execbuf.buffer_count = 1; |
| 78 | execbuf.flags = ring_id; |
| 79 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 80 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
Chris Wilson | 3e2443f | 2016-03-10 11:50:53 +0000 | [diff] [blame] | 81 | if (__gem_execbuf(fd, &execbuf)) { |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 82 | execbuf.flags = ring_id; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 83 | gem_execbuf(fd, &execbuf); |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 84 | } |
Chris Wilson | 71f4153 | 2016-04-22 16:55:29 +0100 | [diff] [blame] | 85 | intel_detect_and_clear_missed_interrupts(fd); |
Chris Wilson | cd8d380 | 2015-03-24 09:15:12 +0000 | [diff] [blame] | 86 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 87 | count = 0; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 88 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 89 | do { |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 90 | for (int loop = 0; loop < 1024; loop++) |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 91 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 92 | |
| 93 | count += 1024; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 94 | clock_gettime(CLOCK_MONOTONIC, &now); |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 95 | } while (elapsed(&start, &now) < timeout); |
Chris Wilson | 71f4153 | 2016-04-22 16:55:29 +0100 | [diff] [blame] | 96 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 97 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 98 | *out = count; |
| 99 | return elapsed(&start, &now); |
| 100 | } |
| 101 | |
| 102 | static void single(int fd, uint32_t handle, |
| 103 | unsigned ring_id, const char *ring_name) |
| 104 | { |
| 105 | double time; |
| 106 | unsigned long count; |
| 107 | |
| 108 | gem_require_ring(fd, ring_id); |
| 109 | |
| 110 | time = nop_on_ring(fd, handle, ring_id, 20, &count); |
| 111 | igt_info("%s: %'lu cycles: %.3fus\n", |
| 112 | ring_name, count, time*1e6 / count); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Chris Wilson | 0aacdac | 2016-03-09 21:06:16 +0000 | [diff] [blame] | 115 | static bool ignore_engine(int fd, unsigned engine) |
| 116 | { |
| 117 | if (engine == 0) |
| 118 | return true; |
| 119 | |
| 120 | if (gem_has_bsd2(fd) && engine == I915_EXEC_BSD) |
| 121 | return true; |
| 122 | |
| 123 | return false; |
| 124 | } |
| 125 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 126 | static void parallel(int fd, uint32_t handle, int timeout) |
| 127 | { |
| 128 | struct drm_i915_gem_execbuffer2 execbuf; |
| 129 | struct drm_i915_gem_exec_object2 obj; |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 130 | unsigned engines[16]; |
| 131 | const char *names[16]; |
| 132 | unsigned nengine; |
| 133 | unsigned engine; |
| 134 | unsigned long count; |
| 135 | double time, sum; |
| 136 | |
| 137 | sum = 0; |
| 138 | nengine = 0; |
| 139 | for_each_engine(fd, engine) { |
| 140 | if (ignore_engine(fd, engine)) |
| 141 | continue; |
| 142 | |
| 143 | engines[nengine] = engine; |
| 144 | names[nengine] = e__->name; |
| 145 | nengine++; |
| 146 | |
| 147 | time = nop_on_ring(fd, handle, engine, 1, &count) / count; |
| 148 | sum += time; |
| 149 | igt_debug("%s: %.3fus\n", e__->name, 1e6*time); |
| 150 | } |
| 151 | igt_require(nengine); |
| 152 | igt_info("average (individually): %.3fus\n", sum/nengine*1e6); |
| 153 | |
| 154 | memset(&obj, 0, sizeof(obj)); |
| 155 | obj.handle = handle; |
| 156 | |
| 157 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 158 | execbuf.buffers_ptr = to_user_pointer(&obj); |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 159 | execbuf.buffer_count = 1; |
| 160 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 161 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
| 162 | if (__gem_execbuf(fd, &execbuf)) { |
| 163 | execbuf.flags = 0; |
| 164 | gem_execbuf(fd, &execbuf); |
| 165 | } |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 166 | intel_detect_and_clear_missed_interrupts(fd); |
| 167 | |
| 168 | igt_fork(child, nengine) { |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 169 | struct timespec start, now; |
| 170 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 171 | execbuf.flags &= ~ENGINE_FLAGS; |
| 172 | execbuf.flags |= engines[child]; |
| 173 | |
| 174 | count = 0; |
| 175 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 176 | do { |
| 177 | for (int loop = 0; loop < 1024; loop++) |
| 178 | gem_execbuf(fd, &execbuf); |
| 179 | count += 1024; |
| 180 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 181 | } while (elapsed(&start, &now) < timeout); |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 182 | time = elapsed(&start, &now) / count; |
| 183 | igt_info("%s: %ld cycles, %.3fus\n", names[child], count, 1e6*time); |
| 184 | } |
| 185 | |
| 186 | igt_waitchildren(); |
| 187 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
| 188 | |
| 189 | } |
| 190 | |
| 191 | static void series(int fd, uint32_t handle, int timeout) |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 192 | { |
| 193 | struct drm_i915_gem_execbuffer2 execbuf; |
| 194 | struct drm_i915_gem_exec_object2 obj; |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 195 | struct timespec start, now, sync; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 196 | unsigned engines[16]; |
| 197 | unsigned nengine; |
| 198 | unsigned engine; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 199 | unsigned long count; |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 200 | double time, max = 0, min = HUGE_VAL, sum = 0; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 201 | const char *name; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 202 | |
| 203 | nengine = 0; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 204 | for_each_engine(fd, engine) { |
| 205 | if (ignore_engine(fd, engine)) |
| 206 | continue; |
| 207 | |
| 208 | time = nop_on_ring(fd, handle, engine, 1, &count) / count; |
| 209 | if (time > max) { |
| 210 | name = e__->name; |
| 211 | max = time; |
| 212 | } |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 213 | if (time < min) |
| 214 | min = time; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 215 | sum += time; |
| 216 | engines[nengine++] = engine; |
| 217 | } |
Chris Wilson | 0aacdac | 2016-03-09 21:06:16 +0000 | [diff] [blame] | 218 | igt_require(nengine); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 219 | igt_info("Maximum execution latency on %s, %.3fus, min %.3fus, total %.3fus per cycle, average %.3fus\n", |
| 220 | name, max*1e6, min*1e6, sum*1e6, sum/nengine*1e6); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 221 | |
| 222 | memset(&obj, 0, sizeof(obj)); |
| 223 | obj.handle = handle; |
| 224 | |
| 225 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 226 | execbuf.buffers_ptr = to_user_pointer(&obj); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 227 | execbuf.buffer_count = 1; |
| 228 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 229 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
Chris Wilson | 3e2443f | 2016-03-10 11:50:53 +0000 | [diff] [blame] | 230 | if (__gem_execbuf(fd, &execbuf)) { |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 231 | execbuf.flags = 0; |
| 232 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 233 | } |
Chris Wilson | 71f4153 | 2016-04-22 16:55:29 +0100 | [diff] [blame] | 234 | intel_detect_and_clear_missed_interrupts(fd); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 235 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 236 | count = 0; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 237 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 238 | do { |
| 239 | for (int loop = 0; loop < 1024; loop++) { |
| 240 | for (int n = 0; n < nengine; n++) { |
| 241 | execbuf.flags &= ~ENGINE_FLAGS; |
| 242 | execbuf.flags |= engines[n]; |
| 243 | gem_execbuf(fd, &execbuf); |
| 244 | } |
| 245 | } |
| 246 | count += nengine * 1024; |
| 247 | clock_gettime(CLOCK_MONOTONIC, &now); |
Chris Wilson | 772393e | 2016-03-14 14:31:36 +0000 | [diff] [blame] | 248 | } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */ |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 249 | gem_sync(fd, handle); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 250 | clock_gettime(CLOCK_MONOTONIC, &sync); |
| 251 | igt_debug("sync time: %.3fus\n", elapsed(&now, &sync)*1e6); |
Chris Wilson | 71f4153 | 2016-04-22 16:55:29 +0100 | [diff] [blame] | 252 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 253 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 254 | time = elapsed(&start, &now) / count; |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 255 | igt_info("All (%d engines): %'lu cycles, average %.3fus per cycle [expected %.3fus]\n", |
Chris Wilson | 61b19a4 | 2016-09-08 14:50:32 +0100 | [diff] [blame] | 256 | nengine, count, 1e6*time, 1e6*((max-min)/nengine+min)); |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 257 | |
Chris Wilson | a0eebbd | 2016-09-08 13:29:31 +0100 | [diff] [blame] | 258 | /* The rate limiting step should be how fast the slowest engine can |
| 259 | * execute its queue of requests, as when we wait upon a full ring all |
| 260 | * dispatch is frozen. So in general we cannot go faster than the |
| 261 | * slowest engine (but as all engines are in lockstep, they should all |
| 262 | * be executing in parallel and so the average should be max/nengines), |
| 263 | * but we should equally not go any slower. |
| 264 | * |
| 265 | * However, that depends upon being able to submit fast enough, and |
| 266 | * that in turns depends upon debugging turned off and no bottlenecks |
| 267 | * within the driver. We cannot assert that we hit ideal conditions |
| 268 | * across all engines, so we only look for an outrageous error |
| 269 | * condition. |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 270 | */ |
Chris Wilson | a0eebbd | 2016-09-08 13:29:31 +0100 | [diff] [blame] | 271 | igt_assert_f(time < 2*sum, |
| 272 | "Average time (%.3fus) exceeds expectation for parallel execution (min %.3fus, max %.3fus; limit set at %.3fus)\n", |
| 273 | 1e6*time, 1e6*min, 1e6*max, 1e6*sum*2); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 274 | } |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 275 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 276 | static void xchg(void *array, unsigned i, unsigned j) |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 277 | { |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 278 | unsigned *u = array; |
| 279 | unsigned tmp = u[i]; |
| 280 | u[i] = u[j]; |
| 281 | u[j] = tmp; |
| 282 | } |
| 283 | |
| 284 | static int __gem_context_create(int fd, uint32_t *ctx_id) |
| 285 | { |
| 286 | struct drm_i915_gem_context_create arg; |
| 287 | int ret = 0; |
| 288 | |
| 289 | memset(&arg, 0, sizeof(arg)); |
| 290 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &arg)) |
| 291 | ret = -errno; |
| 292 | |
| 293 | *ctx_id = arg.ctx_id; |
| 294 | return ret; |
| 295 | } |
| 296 | static void sequential(int fd, uint32_t handle, unsigned flags, int timeout) |
| 297 | { |
| 298 | const int ncpus = flags & FORKED ? sysconf(_SC_NPROCESSORS_ONLN) : 1; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 299 | struct drm_i915_gem_execbuffer2 execbuf; |
| 300 | struct drm_i915_gem_exec_object2 obj[2]; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 301 | unsigned engines[16]; |
| 302 | unsigned nengine; |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 303 | double *results; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 304 | double time, sum; |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 305 | unsigned n; |
| 306 | |
| 307 | results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 308 | igt_assert(results != MAP_FAILED); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 309 | |
| 310 | nengine = 0; |
| 311 | sum = 0; |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 312 | for_each_engine(fd, n) { |
| 313 | unsigned long count; |
| 314 | |
| 315 | if (ignore_engine(fd, n)) |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 316 | continue; |
| 317 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 318 | time = nop_on_ring(fd, handle, n, 1, &count) / count; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 319 | sum += time; |
| 320 | igt_debug("%s: %.3fus\n", e__->name, 1e6*time); |
| 321 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 322 | engines[nengine++] = n; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 323 | } |
| 324 | igt_require(nengine); |
| 325 | igt_info("Total (individual) execution latency %.3fus per cycle\n", |
| 326 | 1e6*sum); |
| 327 | |
| 328 | memset(obj, 0, sizeof(obj)); |
| 329 | obj[0].handle = gem_create(fd, 4096); |
| 330 | obj[0].flags = EXEC_OBJECT_WRITE; |
| 331 | obj[1].handle = handle; |
| 332 | |
| 333 | memset(&execbuf, 0, sizeof(execbuf)); |
| 334 | execbuf.buffers_ptr = to_user_pointer(obj); |
| 335 | execbuf.buffer_count = 2; |
| 336 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 337 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
| 338 | igt_require(__gem_execbuf(fd, &execbuf) == 0); |
| 339 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 340 | if (flags & CONTEXT) { |
| 341 | uint32_t id; |
| 342 | |
| 343 | igt_require(__gem_context_create(fd, &id) == 0); |
| 344 | execbuf.rsvd1 = id; |
| 345 | } |
| 346 | |
| 347 | for (n = 0; n < nengine; n++) { |
| 348 | execbuf.flags &= ~ENGINE_FLAGS; |
| 349 | execbuf.flags |= engines[n]; |
| 350 | igt_require(__gem_execbuf(fd, &execbuf) == 0); |
| 351 | } |
| 352 | |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 353 | intel_detect_and_clear_missed_interrupts(fd); |
| 354 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 355 | igt_fork(child, ncpus) { |
| 356 | struct timespec start, now; |
| 357 | unsigned long count; |
| 358 | |
| 359 | obj[0].handle = gem_create(fd, 4096); |
| 360 | gem_execbuf(fd, &execbuf); |
| 361 | |
| 362 | if (flags & CONTEXT) |
| 363 | execbuf.rsvd1 = gem_context_create(fd); |
| 364 | |
| 365 | hars_petruska_f54_1_random_perturb(child); |
| 366 | |
| 367 | count = 0; |
| 368 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 369 | do { |
| 370 | igt_permute_array(engines, nengine, xchg); |
| 371 | if (flags & CHAINED) { |
| 372 | for (n = 0; n < nengine; n++) { |
| 373 | execbuf.flags &= ~ENGINE_FLAGS; |
| 374 | execbuf.flags |= engines[n]; |
| 375 | for (int loop = 0; loop < 1024; loop++) |
| 376 | gem_execbuf(fd, &execbuf); |
| 377 | } |
| 378 | } else { |
| 379 | for (int loop = 0; loop < 1024; loop++) { |
| 380 | for (n = 0; n < nengine; n++) { |
| 381 | execbuf.flags &= ~ENGINE_FLAGS; |
| 382 | execbuf.flags |= engines[n]; |
| 383 | gem_execbuf(fd, &execbuf); |
| 384 | } |
| 385 | } |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 386 | } |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 387 | count += 1024; |
| 388 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 389 | } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */ |
Chris Wilson | e7a0d06 | 2017-03-21 13:12:07 +0000 | [diff] [blame^] | 390 | |
| 391 | gem_sync(fd, obj[0].handle); |
| 392 | clock_gettime(CLOCK_MONOTONIC, &now); |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 393 | results[child] = elapsed(&start, &now) / count; |
| 394 | |
| 395 | if (flags & CONTEXT) |
| 396 | gem_context_destroy(fd, execbuf.rsvd1); |
| 397 | |
| 398 | gem_close(fd, obj[0].handle); |
| 399 | } |
| 400 | igt_waitchildren(); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 401 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
| 402 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 403 | results[ncpus] = 0; |
| 404 | for (n = 0; n < ncpus; n++) |
| 405 | results[ncpus] += results[n]; |
| 406 | results[ncpus] /= ncpus; |
| 407 | |
| 408 | igt_info("Sequential (%d engines, %d processes): average %.3fus per cycle [expected %.3fus]\n", |
| 409 | nengine, ncpus, 1e6*results[ncpus], 1e6*sum*ncpus); |
| 410 | |
| 411 | if (flags & CONTEXT) |
| 412 | gem_context_destroy(fd, execbuf.rsvd1); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 413 | |
| 414 | gem_close(fd, obj[0].handle); |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 415 | munmap(results, 4096); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 418 | static void print_welcome(int fd) |
| 419 | { |
| 420 | bool active; |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 421 | int dir; |
| 422 | |
| 423 | dir = igt_sysfs_open_parameters(fd); |
| 424 | if (dir < 0) |
| 425 | return; |
| 426 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 427 | active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 428 | if (active) { |
| 429 | igt_info("Using GuC submission\n"); |
| 430 | goto out; |
| 431 | } |
| 432 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 433 | active = igt_sysfs_get_boolean(dir, "enable_execlists"); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 434 | if (active) { |
| 435 | igt_info("Using Execlists submission\n"); |
| 436 | goto out; |
| 437 | } |
| 438 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 439 | active = igt_sysfs_get_boolean(dir, "semaphores"); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 440 | igt_info("Using Legacy submission%s\n", |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 441 | active ? ", with semaphores" : ""); |
| 442 | |
| 443 | out: |
| 444 | close(dir); |
| 445 | } |
| 446 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 447 | igt_main |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 448 | { |
Chris Wilson | 7e0853c | 2016-01-27 14:17:53 +0000 | [diff] [blame] | 449 | const struct intel_execution_engine *e; |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 450 | uint32_t handle = 0; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 451 | int device = -1; |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 452 | |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 453 | igt_fixture { |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 454 | const uint32_t bbe = MI_BATCH_BUFFER_END; |
| 455 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 456 | device = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 9518cb5 | 2017-02-22 15:24:54 +0000 | [diff] [blame] | 457 | igt_require_gem(device); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 458 | print_welcome(device); |
| 459 | |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 460 | handle = gem_create(device, 4096); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 461 | gem_write(device, handle, 0, &bbe, sizeof(bbe)); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 462 | |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 463 | igt_fork_hang_detector(device); |
| 464 | } |
Chris Wilson | 9d61a68 | 2016-03-25 18:22:54 +0000 | [diff] [blame] | 465 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 466 | igt_subtest("basic-series") |
Chris Wilson | 69b29f8 | 2016-10-18 10:23:49 +0100 | [diff] [blame] | 467 | series(device, handle, 5); |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 468 | |
| 469 | igt_subtest("basic-parallel") |
Chris Wilson | 69b29f8 | 2016-10-18 10:23:49 +0100 | [diff] [blame] | 470 | parallel(device, handle, 5); |
Chris Wilson | 772393e | 2016-03-14 14:31:36 +0000 | [diff] [blame] | 471 | |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 472 | igt_subtest("basic-sequential") |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 473 | sequential(device, handle, 0, 5); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 474 | |
Chris Wilson | 7e0853c | 2016-01-27 14:17:53 +0000 | [diff] [blame] | 475 | for (e = intel_execution_engines; e->name; e++) |
| 476 | igt_subtest_f("%s", e->name) |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 477 | single(device, handle, e->exec_id | e->flags, e->name); |
| 478 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 479 | igt_subtest("series") |
| 480 | series(device, handle, 150); |
| 481 | |
| 482 | igt_subtest("parallel") |
| 483 | parallel(device, handle, 150); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 484 | |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 485 | igt_subtest("sequential") |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 486 | sequential(device, handle, 0, 150); |
| 487 | |
| 488 | igt_subtest("forked-sequential") |
| 489 | sequential(device, handle, FORKED, 150); |
| 490 | |
| 491 | igt_subtest("chained-sequential") |
| 492 | sequential(device, handle, FORKED | CHAINED, 150); |
| 493 | |
| 494 | igt_subtest("context-sequential") |
| 495 | sequential(device, handle, FORKED | CONTEXT, 150); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 496 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 497 | igt_fixture { |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 498 | igt_stop_hang_detector(); |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 499 | gem_close(device, handle); |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 500 | close(device); |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 501 | } |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 502 | } |