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 | |
Tvrtko Ursulin | 8e4cfb2 | 2017-04-13 14:11:05 +0100 | [diff] [blame^] | 115 | static double |
| 116 | stable_nop_on_ring(int fd, uint32_t handle, unsigned int engine, |
| 117 | int timeout, int reps) |
| 118 | { |
| 119 | igt_stats_t s; |
| 120 | double n; |
| 121 | |
| 122 | igt_assert(reps >= 5); |
| 123 | |
| 124 | igt_stats_init_with_size(&s, reps); |
| 125 | s.is_float = true; |
| 126 | |
| 127 | while (reps--) { |
| 128 | unsigned long count; |
| 129 | double time; |
| 130 | |
| 131 | time = nop_on_ring(fd, handle, engine, timeout, &count); |
| 132 | igt_stats_push_float(&s, time / count); |
| 133 | } |
| 134 | |
| 135 | n = igt_stats_get_median(&s); |
| 136 | igt_stats_fini(&s); |
| 137 | |
| 138 | return n; |
| 139 | } |
| 140 | |
| 141 | #define assert_within_epsilon(x, ref, tolerance) \ |
| 142 | igt_assert_f((x) <= (1.0 + tolerance) * ref && \ |
| 143 | (x) >= (1.0 - tolerance) * ref, \ |
| 144 | "'%s' != '%s' (%f not within %f%% tolerance of %f)\n",\ |
| 145 | #x, #ref, x, tolerance * 100.0, ref) |
| 146 | |
| 147 | static void headless(int fd, uint32_t handle) |
| 148 | { |
| 149 | unsigned int nr_connected = 0; |
| 150 | drmModeConnector *connector; |
| 151 | drmModeRes *res; |
| 152 | double n_display, n_headless; |
| 153 | |
| 154 | res = drmModeGetResources(fd); |
| 155 | igt_assert(res); |
| 156 | |
| 157 | /* require at least one connected connector for the test */ |
| 158 | for (int i = 0; i < res->count_connectors; i++) { |
| 159 | connector = drmModeGetConnectorCurrent(fd, res->connectors[i]); |
| 160 | if (connector->connection == DRM_MODE_CONNECTED) |
| 161 | nr_connected++; |
| 162 | drmModeFreeConnector(connector); |
| 163 | } |
| 164 | igt_require(nr_connected > 0); |
| 165 | |
| 166 | /* set graphics mode to prevent blanking */ |
| 167 | kmstest_set_vt_graphics_mode(); |
| 168 | |
| 169 | /* benchmark nops */ |
| 170 | n_display = stable_nop_on_ring(fd, handle, I915_EXEC_DEFAULT, 1, 5); |
| 171 | |
| 172 | /* force all connectors off */ |
| 173 | kmstest_unset_all_crtcs(fd, res); |
| 174 | |
| 175 | /* benchmark nops again */ |
| 176 | n_headless = stable_nop_on_ring(fd, handle, I915_EXEC_DEFAULT, 1, 5); |
| 177 | |
| 178 | /* check that the two execution speeds are roughly the same */ |
| 179 | assert_within_epsilon(n_headless, n_display, 0.1f); |
| 180 | } |
| 181 | |
Chris Wilson | 0aacdac | 2016-03-09 21:06:16 +0000 | [diff] [blame] | 182 | static bool ignore_engine(int fd, unsigned engine) |
| 183 | { |
| 184 | if (engine == 0) |
| 185 | return true; |
| 186 | |
| 187 | if (gem_has_bsd2(fd) && engine == I915_EXEC_BSD) |
| 188 | return true; |
| 189 | |
| 190 | return false; |
| 191 | } |
| 192 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 193 | static void parallel(int fd, uint32_t handle, int timeout) |
| 194 | { |
| 195 | struct drm_i915_gem_execbuffer2 execbuf; |
| 196 | struct drm_i915_gem_exec_object2 obj; |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 197 | unsigned engines[16]; |
| 198 | const char *names[16]; |
| 199 | unsigned nengine; |
| 200 | unsigned engine; |
| 201 | unsigned long count; |
| 202 | double time, sum; |
| 203 | |
| 204 | sum = 0; |
| 205 | nengine = 0; |
| 206 | for_each_engine(fd, engine) { |
| 207 | if (ignore_engine(fd, engine)) |
| 208 | continue; |
| 209 | |
| 210 | engines[nengine] = engine; |
| 211 | names[nengine] = e__->name; |
| 212 | nengine++; |
| 213 | |
| 214 | time = nop_on_ring(fd, handle, engine, 1, &count) / count; |
| 215 | sum += time; |
| 216 | igt_debug("%s: %.3fus\n", e__->name, 1e6*time); |
| 217 | } |
| 218 | igt_require(nengine); |
| 219 | igt_info("average (individually): %.3fus\n", sum/nengine*1e6); |
| 220 | |
| 221 | memset(&obj, 0, sizeof(obj)); |
| 222 | obj.handle = handle; |
| 223 | |
| 224 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 225 | execbuf.buffers_ptr = to_user_pointer(&obj); |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 226 | execbuf.buffer_count = 1; |
| 227 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 228 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
| 229 | if (__gem_execbuf(fd, &execbuf)) { |
| 230 | execbuf.flags = 0; |
| 231 | gem_execbuf(fd, &execbuf); |
| 232 | } |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 233 | intel_detect_and_clear_missed_interrupts(fd); |
| 234 | |
| 235 | igt_fork(child, nengine) { |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 236 | struct timespec start, now; |
| 237 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 238 | execbuf.flags &= ~ENGINE_FLAGS; |
| 239 | execbuf.flags |= engines[child]; |
| 240 | |
| 241 | count = 0; |
| 242 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 243 | do { |
| 244 | for (int loop = 0; loop < 1024; loop++) |
| 245 | gem_execbuf(fd, &execbuf); |
| 246 | count += 1024; |
| 247 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 248 | } while (elapsed(&start, &now) < timeout); |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 249 | time = elapsed(&start, &now) / count; |
| 250 | igt_info("%s: %ld cycles, %.3fus\n", names[child], count, 1e6*time); |
| 251 | } |
| 252 | |
| 253 | igt_waitchildren(); |
| 254 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
| 255 | |
| 256 | } |
| 257 | |
| 258 | static void series(int fd, uint32_t handle, int timeout) |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 259 | { |
| 260 | struct drm_i915_gem_execbuffer2 execbuf; |
| 261 | struct drm_i915_gem_exec_object2 obj; |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 262 | struct timespec start, now, sync; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 263 | unsigned engines[16]; |
| 264 | unsigned nengine; |
| 265 | unsigned engine; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 266 | unsigned long count; |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 267 | double time, max = 0, min = HUGE_VAL, sum = 0; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 268 | const char *name; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 269 | |
| 270 | nengine = 0; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 271 | for_each_engine(fd, engine) { |
| 272 | if (ignore_engine(fd, engine)) |
| 273 | continue; |
| 274 | |
| 275 | time = nop_on_ring(fd, handle, engine, 1, &count) / count; |
| 276 | if (time > max) { |
| 277 | name = e__->name; |
| 278 | max = time; |
| 279 | } |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 280 | if (time < min) |
| 281 | min = time; |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 282 | sum += time; |
| 283 | engines[nengine++] = engine; |
| 284 | } |
Chris Wilson | 0aacdac | 2016-03-09 21:06:16 +0000 | [diff] [blame] | 285 | igt_require(nengine); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 286 | igt_info("Maximum execution latency on %s, %.3fus, min %.3fus, total %.3fus per cycle, average %.3fus\n", |
| 287 | name, max*1e6, min*1e6, sum*1e6, sum/nengine*1e6); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 288 | |
| 289 | memset(&obj, 0, sizeof(obj)); |
| 290 | obj.handle = handle; |
| 291 | |
| 292 | memset(&execbuf, 0, sizeof(execbuf)); |
Chris Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 293 | execbuf.buffers_ptr = to_user_pointer(&obj); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 294 | execbuf.buffer_count = 1; |
| 295 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 296 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
Chris Wilson | 3e2443f | 2016-03-10 11:50:53 +0000 | [diff] [blame] | 297 | if (__gem_execbuf(fd, &execbuf)) { |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 298 | execbuf.flags = 0; |
| 299 | gem_execbuf(fd, &execbuf); |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 300 | } |
Chris Wilson | 71f4153 | 2016-04-22 16:55:29 +0100 | [diff] [blame] | 301 | intel_detect_and_clear_missed_interrupts(fd); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 302 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 303 | count = 0; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 304 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 305 | do { |
| 306 | for (int loop = 0; loop < 1024; loop++) { |
| 307 | for (int n = 0; n < nengine; n++) { |
| 308 | execbuf.flags &= ~ENGINE_FLAGS; |
| 309 | execbuf.flags |= engines[n]; |
| 310 | gem_execbuf(fd, &execbuf); |
| 311 | } |
| 312 | } |
| 313 | count += nengine * 1024; |
| 314 | clock_gettime(CLOCK_MONOTONIC, &now); |
Chris Wilson | 772393e | 2016-03-14 14:31:36 +0000 | [diff] [blame] | 315 | } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */ |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 316 | gem_sync(fd, handle); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 317 | clock_gettime(CLOCK_MONOTONIC, &sync); |
| 318 | igt_debug("sync time: %.3fus\n", elapsed(&now, &sync)*1e6); |
Chris Wilson | 71f4153 | 2016-04-22 16:55:29 +0100 | [diff] [blame] | 319 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 320 | |
Chris Wilson | 870c774 | 2016-03-28 15:29:46 +0100 | [diff] [blame] | 321 | time = elapsed(&start, &now) / count; |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 322 | 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] | 323 | nengine, count, 1e6*time, 1e6*((max-min)/nengine+min)); |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 324 | |
Chris Wilson | a0eebbd | 2016-09-08 13:29:31 +0100 | [diff] [blame] | 325 | /* The rate limiting step should be how fast the slowest engine can |
| 326 | * execute its queue of requests, as when we wait upon a full ring all |
| 327 | * dispatch is frozen. So in general we cannot go faster than the |
| 328 | * slowest engine (but as all engines are in lockstep, they should all |
| 329 | * be executing in parallel and so the average should be max/nengines), |
| 330 | * but we should equally not go any slower. |
| 331 | * |
| 332 | * However, that depends upon being able to submit fast enough, and |
| 333 | * that in turns depends upon debugging turned off and no bottlenecks |
| 334 | * within the driver. We cannot assert that we hit ideal conditions |
| 335 | * across all engines, so we only look for an outrageous error |
| 336 | * condition. |
Chris Wilson | 41a26b5 | 2016-03-28 16:26:01 +0100 | [diff] [blame] | 337 | */ |
Chris Wilson | a0eebbd | 2016-09-08 13:29:31 +0100 | [diff] [blame] | 338 | igt_assert_f(time < 2*sum, |
| 339 | "Average time (%.3fus) exceeds expectation for parallel execution (min %.3fus, max %.3fus; limit set at %.3fus)\n", |
| 340 | 1e6*time, 1e6*min, 1e6*max, 1e6*sum*2); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 341 | } |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 342 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 343 | static void xchg(void *array, unsigned i, unsigned j) |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 344 | { |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 345 | unsigned *u = array; |
| 346 | unsigned tmp = u[i]; |
| 347 | u[i] = u[j]; |
| 348 | u[j] = tmp; |
| 349 | } |
| 350 | |
| 351 | static int __gem_context_create(int fd, uint32_t *ctx_id) |
| 352 | { |
| 353 | struct drm_i915_gem_context_create arg; |
| 354 | int ret = 0; |
| 355 | |
| 356 | memset(&arg, 0, sizeof(arg)); |
| 357 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &arg)) |
| 358 | ret = -errno; |
| 359 | |
| 360 | *ctx_id = arg.ctx_id; |
| 361 | return ret; |
| 362 | } |
| 363 | static void sequential(int fd, uint32_t handle, unsigned flags, int timeout) |
| 364 | { |
| 365 | const int ncpus = flags & FORKED ? sysconf(_SC_NPROCESSORS_ONLN) : 1; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 366 | struct drm_i915_gem_execbuffer2 execbuf; |
| 367 | struct drm_i915_gem_exec_object2 obj[2]; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 368 | unsigned engines[16]; |
| 369 | unsigned nengine; |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 370 | double *results; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 371 | double time, sum; |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 372 | unsigned n; |
| 373 | |
| 374 | results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); |
| 375 | igt_assert(results != MAP_FAILED); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 376 | |
| 377 | nengine = 0; |
| 378 | sum = 0; |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 379 | for_each_engine(fd, n) { |
| 380 | unsigned long count; |
| 381 | |
| 382 | if (ignore_engine(fd, n)) |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 383 | continue; |
| 384 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 385 | time = nop_on_ring(fd, handle, n, 1, &count) / count; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 386 | sum += time; |
| 387 | igt_debug("%s: %.3fus\n", e__->name, 1e6*time); |
| 388 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 389 | engines[nengine++] = n; |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 390 | } |
| 391 | igt_require(nengine); |
| 392 | igt_info("Total (individual) execution latency %.3fus per cycle\n", |
| 393 | 1e6*sum); |
| 394 | |
| 395 | memset(obj, 0, sizeof(obj)); |
| 396 | obj[0].handle = gem_create(fd, 4096); |
| 397 | obj[0].flags = EXEC_OBJECT_WRITE; |
| 398 | obj[1].handle = handle; |
| 399 | |
| 400 | memset(&execbuf, 0, sizeof(execbuf)); |
| 401 | execbuf.buffers_ptr = to_user_pointer(obj); |
| 402 | execbuf.buffer_count = 2; |
| 403 | execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT; |
| 404 | execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC; |
| 405 | igt_require(__gem_execbuf(fd, &execbuf) == 0); |
| 406 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 407 | if (flags & CONTEXT) { |
| 408 | uint32_t id; |
| 409 | |
| 410 | igt_require(__gem_context_create(fd, &id) == 0); |
| 411 | execbuf.rsvd1 = id; |
| 412 | } |
| 413 | |
| 414 | for (n = 0; n < nengine; n++) { |
| 415 | execbuf.flags &= ~ENGINE_FLAGS; |
| 416 | execbuf.flags |= engines[n]; |
| 417 | igt_require(__gem_execbuf(fd, &execbuf) == 0); |
| 418 | } |
| 419 | |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 420 | intel_detect_and_clear_missed_interrupts(fd); |
| 421 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 422 | igt_fork(child, ncpus) { |
| 423 | struct timespec start, now; |
| 424 | unsigned long count; |
| 425 | |
| 426 | obj[0].handle = gem_create(fd, 4096); |
| 427 | gem_execbuf(fd, &execbuf); |
| 428 | |
| 429 | if (flags & CONTEXT) |
| 430 | execbuf.rsvd1 = gem_context_create(fd); |
| 431 | |
| 432 | hars_petruska_f54_1_random_perturb(child); |
| 433 | |
| 434 | count = 0; |
| 435 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 436 | do { |
| 437 | igt_permute_array(engines, nengine, xchg); |
| 438 | if (flags & CHAINED) { |
| 439 | for (n = 0; n < nengine; n++) { |
| 440 | execbuf.flags &= ~ENGINE_FLAGS; |
| 441 | execbuf.flags |= engines[n]; |
| 442 | for (int loop = 0; loop < 1024; loop++) |
| 443 | gem_execbuf(fd, &execbuf); |
| 444 | } |
| 445 | } else { |
| 446 | for (int loop = 0; loop < 1024; loop++) { |
| 447 | for (n = 0; n < nengine; n++) { |
| 448 | execbuf.flags &= ~ENGINE_FLAGS; |
| 449 | execbuf.flags |= engines[n]; |
| 450 | gem_execbuf(fd, &execbuf); |
| 451 | } |
| 452 | } |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 453 | } |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 454 | count += 1024; |
| 455 | clock_gettime(CLOCK_MONOTONIC, &now); |
| 456 | } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */ |
Chris Wilson | e7a0d06 | 2017-03-21 13:12:07 +0000 | [diff] [blame] | 457 | |
| 458 | gem_sync(fd, obj[0].handle); |
| 459 | clock_gettime(CLOCK_MONOTONIC, &now); |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 460 | results[child] = elapsed(&start, &now) / count; |
| 461 | |
| 462 | if (flags & CONTEXT) |
| 463 | gem_context_destroy(fd, execbuf.rsvd1); |
| 464 | |
| 465 | gem_close(fd, obj[0].handle); |
| 466 | } |
| 467 | igt_waitchildren(); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 468 | igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); |
| 469 | |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 470 | results[ncpus] = 0; |
| 471 | for (n = 0; n < ncpus; n++) |
| 472 | results[ncpus] += results[n]; |
| 473 | results[ncpus] /= ncpus; |
| 474 | |
| 475 | igt_info("Sequential (%d engines, %d processes): average %.3fus per cycle [expected %.3fus]\n", |
| 476 | nengine, ncpus, 1e6*results[ncpus], 1e6*sum*ncpus); |
| 477 | |
| 478 | if (flags & CONTEXT) |
| 479 | gem_context_destroy(fd, execbuf.rsvd1); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 480 | |
| 481 | gem_close(fd, obj[0].handle); |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 482 | munmap(results, 4096); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 485 | static void print_welcome(int fd) |
| 486 | { |
| 487 | bool active; |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 488 | int dir; |
| 489 | |
| 490 | dir = igt_sysfs_open_parameters(fd); |
| 491 | if (dir < 0) |
| 492 | return; |
| 493 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 494 | active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 495 | if (active) { |
| 496 | igt_info("Using GuC submission\n"); |
| 497 | goto out; |
| 498 | } |
| 499 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 500 | active = igt_sysfs_get_boolean(dir, "enable_execlists"); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 501 | if (active) { |
| 502 | igt_info("Using Execlists submission\n"); |
| 503 | goto out; |
| 504 | } |
| 505 | |
Chris Wilson | b64d10c | 2016-07-22 17:53:51 +0100 | [diff] [blame] | 506 | active = igt_sysfs_get_boolean(dir, "semaphores"); |
Chris Wilson | f565b6c | 2016-09-08 20:59:55 +0100 | [diff] [blame] | 507 | igt_info("Using Legacy submission%s\n", |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 508 | active ? ", with semaphores" : ""); |
| 509 | |
| 510 | out: |
| 511 | close(dir); |
| 512 | } |
| 513 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 514 | igt_main |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 515 | { |
Chris Wilson | 7e0853c | 2016-01-27 14:17:53 +0000 | [diff] [blame] | 516 | const struct intel_execution_engine *e; |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 517 | uint32_t handle = 0; |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 518 | int device = -1; |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 519 | |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 520 | igt_fixture { |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 521 | const uint32_t bbe = MI_BATCH_BUFFER_END; |
| 522 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 523 | device = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 9518cb5 | 2017-02-22 15:24:54 +0000 | [diff] [blame] | 524 | igt_require_gem(device); |
Chris Wilson | c6e26e4 | 2016-07-22 12:58:54 +0100 | [diff] [blame] | 525 | print_welcome(device); |
| 526 | |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 527 | handle = gem_create(device, 4096); |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 528 | gem_write(device, handle, 0, &bbe, sizeof(bbe)); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 529 | |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 530 | igt_fork_hang_detector(device); |
| 531 | } |
Chris Wilson | 9d61a68 | 2016-03-25 18:22:54 +0000 | [diff] [blame] | 532 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 533 | igt_subtest("basic-series") |
Chris Wilson | 69b29f8 | 2016-10-18 10:23:49 +0100 | [diff] [blame] | 534 | series(device, handle, 5); |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 535 | |
| 536 | igt_subtest("basic-parallel") |
Chris Wilson | 69b29f8 | 2016-10-18 10:23:49 +0100 | [diff] [blame] | 537 | parallel(device, handle, 5); |
Chris Wilson | 772393e | 2016-03-14 14:31:36 +0000 | [diff] [blame] | 538 | |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 539 | igt_subtest("basic-sequential") |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 540 | sequential(device, handle, 0, 5); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 541 | |
Chris Wilson | 7e0853c | 2016-01-27 14:17:53 +0000 | [diff] [blame] | 542 | for (e = intel_execution_engines; e->name; e++) |
| 543 | igt_subtest_f("%s", e->name) |
Chris Wilson | 3a7325e | 2016-03-08 11:43:31 +0000 | [diff] [blame] | 544 | single(device, handle, e->exec_id | e->flags, e->name); |
| 545 | |
Chris Wilson | 4cce715 | 2016-09-08 13:43:17 +0100 | [diff] [blame] | 546 | igt_subtest("series") |
| 547 | series(device, handle, 150); |
| 548 | |
| 549 | igt_subtest("parallel") |
| 550 | parallel(device, handle, 150); |
Daniel Vetter | d9d9578 | 2012-12-04 17:13:05 +0100 | [diff] [blame] | 551 | |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 552 | igt_subtest("sequential") |
Chris Wilson | 9fbf72b | 2017-01-22 18:24:37 +0000 | [diff] [blame] | 553 | sequential(device, handle, 0, 150); |
| 554 | |
| 555 | igt_subtest("forked-sequential") |
| 556 | sequential(device, handle, FORKED, 150); |
| 557 | |
| 558 | igt_subtest("chained-sequential") |
| 559 | sequential(device, handle, FORKED | CHAINED, 150); |
| 560 | |
| 561 | igt_subtest("context-sequential") |
| 562 | sequential(device, handle, FORKED | CONTEXT, 150); |
Chris Wilson | 817d57f | 2017-01-20 17:17:42 +0000 | [diff] [blame] | 563 | |
Tvrtko Ursulin | 8e4cfb2 | 2017-04-13 14:11:05 +0100 | [diff] [blame^] | 564 | igt_subtest("headless") |
| 565 | headless(device, handle); |
| 566 | |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 567 | igt_fixture { |
Daniel Vetter | be21fc0 | 2016-06-17 16:04:09 +0200 | [diff] [blame] | 568 | igt_stop_hang_detector(); |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 569 | gem_close(device, handle); |
Chris Wilson | 2659cbb | 2015-03-26 12:09:57 +0000 | [diff] [blame] | 570 | close(device); |
Daniel Vetter | b3880d3 | 2013-08-14 18:02:46 +0200 | [diff] [blame] | 571 | } |
Chris Wilson | 07d59b3 | 2011-01-20 22:10:10 +0000 | [diff] [blame] | 572 | } |