blob: 66c2fc1dfa3ca89163cc02aecbd096bb5f7ae978 [file] [log] [blame]
Chris Wilson07d59b32011-01-20 22:10:10 +00001/*
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 Wood804e11f2015-08-17 17:57:43 +010028#include "igt.h"
Chris Wilson9fbf72b2017-01-22 18:24:37 +000029#include "igt_rand.h"
Chris Wilsonc6e26e42016-07-22 12:58:54 +010030#include "igt_sysfs.h"
Chris Wilson9fbf72b2017-01-22 18:24:37 +000031
Chris Wilson07d59b32011-01-20 22:10:10 +000032#include <unistd.h>
33#include <stdlib.h>
34#include <stdint.h>
35#include <stdio.h>
36#include <string.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000037#include <fcntl.h>
38#include <inttypes.h>
39#include <errno.h>
40#include <sys/stat.h>
41#include <sys/ioctl.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000042#include <sys/time.h>
Chris Wilsonb4307092015-07-01 13:53:07 +010043#include <time.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000044#include "drm.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000045
Chris Wilsoncd8d3802015-03-24 09:15:12 +000046#define LOCAL_I915_EXEC_NO_RELOC (1<<11)
47#define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
48
Chris Wilson3a7325e2016-03-08 11:43:31 +000049#define LOCAL_I915_EXEC_BSD_SHIFT (13)
50#define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT)
Daniel Vetter51f08302012-12-05 19:29:11 +010051
Chris Wilson3a7325e2016-03-08 11:43:31 +000052#define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK)
Chris Wilson2659cbb2015-03-26 12:09:57 +000053
Chris Wilson9fbf72b2017-01-22 18:24:37 +000054#define FORKED 1
55#define CHAINED 2
56#define CONTEXT 4
57
Chris Wilson3a7325e2016-03-08 11:43:31 +000058static 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 Wilson870c7742016-03-28 15:29:46 +010064static double nop_on_ring(int fd, uint32_t handle, unsigned ring_id,
65 int timeout, unsigned long *out)
Chris Wilson07d59b32011-01-20 22:10:10 +000066{
67 struct drm_i915_gem_execbuffer2 execbuf;
Chris Wilson3a7325e2016-03-08 11:43:31 +000068 struct drm_i915_gem_exec_object2 obj;
69 struct timespec start, now;
Chris Wilson870c7742016-03-28 15:29:46 +010070 unsigned long count;
Daniel Vetter8f5387e2013-08-13 13:20:58 +020071
Chris Wilson3a7325e2016-03-08 11:43:31 +000072 memset(&obj, 0, sizeof(obj));
73 obj.handle = handle;
Chris Wilson07d59b32011-01-20 22:10:10 +000074
Chris Wilsoncd8d3802015-03-24 09:15:12 +000075 memset(&execbuf, 0, sizeof(execbuf));
Chris Wilson4de67b22017-01-02 11:05:21 +000076 execbuf.buffers_ptr = to_user_pointer(&obj);
Chris Wilsoncd8d3802015-03-24 09:15:12 +000077 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 Wilson3e2443f2016-03-10 11:50:53 +000081 if (__gem_execbuf(fd, &execbuf)) {
Chris Wilsoncd8d3802015-03-24 09:15:12 +000082 execbuf.flags = ring_id;
Chris Wilson3a7325e2016-03-08 11:43:31 +000083 gem_execbuf(fd, &execbuf);
Chris Wilsoncd8d3802015-03-24 09:15:12 +000084 }
Chris Wilson71f41532016-04-22 16:55:29 +010085 intel_detect_and_clear_missed_interrupts(fd);
Chris Wilsoncd8d3802015-03-24 09:15:12 +000086
Chris Wilson870c7742016-03-28 15:29:46 +010087 count = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +000088 clock_gettime(CLOCK_MONOTONIC, &start);
89 do {
Chris Wilson870c7742016-03-28 15:29:46 +010090 for (int loop = 0; loop < 1024; loop++)
Chris Wilson3a7325e2016-03-08 11:43:31 +000091 gem_execbuf(fd, &execbuf);
Chris Wilson870c7742016-03-28 15:29:46 +010092
93 count += 1024;
Chris Wilson3a7325e2016-03-08 11:43:31 +000094 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson870c7742016-03-28 15:29:46 +010095 } while (elapsed(&start, &now) < timeout);
Chris Wilson71f41532016-04-22 16:55:29 +010096 igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
Chris Wilson3a7325e2016-03-08 11:43:31 +000097
Chris Wilson870c7742016-03-28 15:29:46 +010098 *out = count;
99 return elapsed(&start, &now);
100}
101
102static 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 Wilson3a7325e2016-03-08 11:43:31 +0000113}
114
Tvrtko Ursulin8e4cfb22017-04-13 14:11:05 +0100115static double
116stable_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
147static 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 Wilson0aacdac2016-03-09 21:06:16 +0000182static 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 Wilson4cce7152016-09-08 13:43:17 +0100193static 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 Wilson4cce7152016-09-08 13:43:17 +0100197 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 Wilson4de67b22017-01-02 11:05:21 +0000225 execbuf.buffers_ptr = to_user_pointer(&obj);
Chris Wilson4cce7152016-09-08 13:43:17 +0100226 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 Wilson4cce7152016-09-08 13:43:17 +0100233 intel_detect_and_clear_missed_interrupts(fd);
234
235 igt_fork(child, nengine) {
Chris Wilsonf565b6c2016-09-08 20:59:55 +0100236 struct timespec start, now;
237
Chris Wilson4cce7152016-09-08 13:43:17 +0100238 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 Wilson4cce7152016-09-08 13:43:17 +0100249 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
258static void series(int fd, uint32_t handle, int timeout)
Chris Wilson3a7325e2016-03-08 11:43:31 +0000259{
260 struct drm_i915_gem_execbuffer2 execbuf;
261 struct drm_i915_gem_exec_object2 obj;
Chris Wilsonf565b6c2016-09-08 20:59:55 +0100262 struct timespec start, now, sync;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000263 unsigned engines[16];
264 unsigned nengine;
265 unsigned engine;
Chris Wilson870c7742016-03-28 15:29:46 +0100266 unsigned long count;
Chris Wilson41a26b52016-03-28 16:26:01 +0100267 double time, max = 0, min = HUGE_VAL, sum = 0;
Chris Wilson870c7742016-03-28 15:29:46 +0100268 const char *name;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000269
270 nengine = 0;
Chris Wilson870c7742016-03-28 15:29:46 +0100271 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 Wilson41a26b52016-03-28 16:26:01 +0100280 if (time < min)
281 min = time;
Chris Wilson870c7742016-03-28 15:29:46 +0100282 sum += time;
283 engines[nengine++] = engine;
284 }
Chris Wilson0aacdac2016-03-09 21:06:16 +0000285 igt_require(nengine);
Chris Wilsonf565b6c2016-09-08 20:59:55 +0100286 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 Wilson3a7325e2016-03-08 11:43:31 +0000288
289 memset(&obj, 0, sizeof(obj));
290 obj.handle = handle;
291
292 memset(&execbuf, 0, sizeof(execbuf));
Chris Wilson4de67b22017-01-02 11:05:21 +0000293 execbuf.buffers_ptr = to_user_pointer(&obj);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000294 execbuf.buffer_count = 1;
295 execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT;
296 execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC;
Chris Wilson3e2443f2016-03-10 11:50:53 +0000297 if (__gem_execbuf(fd, &execbuf)) {
Chris Wilson3a7325e2016-03-08 11:43:31 +0000298 execbuf.flags = 0;
299 gem_execbuf(fd, &execbuf);
Chris Wilson07d59b32011-01-20 22:10:10 +0000300 }
Chris Wilson71f41532016-04-22 16:55:29 +0100301 intel_detect_and_clear_missed_interrupts(fd);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000302
Chris Wilson870c7742016-03-28 15:29:46 +0100303 count = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000304 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 Wilson772393e2016-03-14 14:31:36 +0000315 } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */
Chris Wilson3a7325e2016-03-08 11:43:31 +0000316 gem_sync(fd, handle);
Chris Wilsonf565b6c2016-09-08 20:59:55 +0100317 clock_gettime(CLOCK_MONOTONIC, &sync);
318 igt_debug("sync time: %.3fus\n", elapsed(&now, &sync)*1e6);
Chris Wilson71f41532016-04-22 16:55:29 +0100319 igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000320
Chris Wilson870c7742016-03-28 15:29:46 +0100321 time = elapsed(&start, &now) / count;
Chris Wilsonf565b6c2016-09-08 20:59:55 +0100322 igt_info("All (%d engines): %'lu cycles, average %.3fus per cycle [expected %.3fus]\n",
Chris Wilson61b19a42016-09-08 14:50:32 +0100323 nengine, count, 1e6*time, 1e6*((max-min)/nengine+min));
Chris Wilson41a26b52016-03-28 16:26:01 +0100324
Chris Wilsona0eebbd2016-09-08 13:29:31 +0100325 /* 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 Wilson41a26b52016-03-28 16:26:01 +0100337 */
Chris Wilsona0eebbd2016-09-08 13:29:31 +0100338 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 Vetterd9d95782012-12-04 17:13:05 +0100341}
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200342
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000343static void xchg(void *array, unsigned i, unsigned j)
Chris Wilson817d57f2017-01-20 17:17:42 +0000344{
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000345 unsigned *u = array;
346 unsigned tmp = u[i];
347 u[i] = u[j];
348 u[j] = tmp;
349}
350
351static 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}
363static void sequential(int fd, uint32_t handle, unsigned flags, int timeout)
364{
365 const int ncpus = flags & FORKED ? sysconf(_SC_NPROCESSORS_ONLN) : 1;
Chris Wilson817d57f2017-01-20 17:17:42 +0000366 struct drm_i915_gem_execbuffer2 execbuf;
367 struct drm_i915_gem_exec_object2 obj[2];
Chris Wilson817d57f2017-01-20 17:17:42 +0000368 unsigned engines[16];
369 unsigned nengine;
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000370 double *results;
Chris Wilson817d57f2017-01-20 17:17:42 +0000371 double time, sum;
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000372 unsigned n;
373
374 results = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
375 igt_assert(results != MAP_FAILED);
Chris Wilson817d57f2017-01-20 17:17:42 +0000376
377 nengine = 0;
378 sum = 0;
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000379 for_each_engine(fd, n) {
380 unsigned long count;
381
382 if (ignore_engine(fd, n))
Chris Wilson817d57f2017-01-20 17:17:42 +0000383 continue;
384
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000385 time = nop_on_ring(fd, handle, n, 1, &count) / count;
Chris Wilson817d57f2017-01-20 17:17:42 +0000386 sum += time;
387 igt_debug("%s: %.3fus\n", e__->name, 1e6*time);
388
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000389 engines[nengine++] = n;
Chris Wilson817d57f2017-01-20 17:17:42 +0000390 }
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 Wilson9fbf72b2017-01-22 18:24:37 +0000407 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 Wilson817d57f2017-01-20 17:17:42 +0000420 intel_detect_and_clear_missed_interrupts(fd);
421
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000422 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 Wilson817d57f2017-01-20 17:17:42 +0000453 }
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000454 count += 1024;
455 clock_gettime(CLOCK_MONOTONIC, &now);
456 } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */
Chris Wilsone7a0d062017-03-21 13:12:07 +0000457
458 gem_sync(fd, obj[0].handle);
459 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000460 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 Wilson817d57f2017-01-20 17:17:42 +0000468 igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
469
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000470 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 Wilson817d57f2017-01-20 17:17:42 +0000480
481 gem_close(fd, obj[0].handle);
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000482 munmap(results, 4096);
Chris Wilson817d57f2017-01-20 17:17:42 +0000483}
484
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100485static void print_welcome(int fd)
486{
487 bool active;
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100488 int dir;
489
490 dir = igt_sysfs_open_parameters(fd);
491 if (dir < 0)
492 return;
493
Chris Wilsonb64d10c2016-07-22 17:53:51 +0100494 active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100495 if (active) {
496 igt_info("Using GuC submission\n");
497 goto out;
498 }
499
Chris Wilsonb64d10c2016-07-22 17:53:51 +0100500 active = igt_sysfs_get_boolean(dir, "enable_execlists");
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100501 if (active) {
502 igt_info("Using Execlists submission\n");
503 goto out;
504 }
505
Chris Wilsonb64d10c2016-07-22 17:53:51 +0100506 active = igt_sysfs_get_boolean(dir, "semaphores");
Chris Wilsonf565b6c2016-09-08 20:59:55 +0100507 igt_info("Using Legacy submission%s\n",
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100508 active ? ", with semaphores" : "");
509
510out:
511 close(dir);
512}
513
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100514igt_main
Daniel Vetterd9d95782012-12-04 17:13:05 +0100515{
Chris Wilson7e0853c2016-01-27 14:17:53 +0000516 const struct intel_execution_engine *e;
Chris Wilson2659cbb2015-03-26 12:09:57 +0000517 uint32_t handle = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000518 int device = -1;
Daniel Vetterd9d95782012-12-04 17:13:05 +0100519
Chris Wilson2659cbb2015-03-26 12:09:57 +0000520 igt_fixture {
Chris Wilson3a7325e2016-03-08 11:43:31 +0000521 const uint32_t bbe = MI_BATCH_BUFFER_END;
522
Micah Fedkec81d2932015-07-22 21:54:02 +0000523 device = drm_open_driver(DRIVER_INTEL);
Chris Wilson9518cb52017-02-22 15:24:54 +0000524 igt_require_gem(device);
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100525 print_welcome(device);
526
Chris Wilson2659cbb2015-03-26 12:09:57 +0000527 handle = gem_create(device, 4096);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000528 gem_write(device, handle, 0, &bbe, sizeof(bbe));
Daniel Vetterd9d95782012-12-04 17:13:05 +0100529
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200530 igt_fork_hang_detector(device);
531 }
Chris Wilson9d61a682016-03-25 18:22:54 +0000532
Chris Wilson4cce7152016-09-08 13:43:17 +0100533 igt_subtest("basic-series")
Chris Wilson69b29f82016-10-18 10:23:49 +0100534 series(device, handle, 5);
Chris Wilson4cce7152016-09-08 13:43:17 +0100535
536 igt_subtest("basic-parallel")
Chris Wilson69b29f82016-10-18 10:23:49 +0100537 parallel(device, handle, 5);
Chris Wilson772393e2016-03-14 14:31:36 +0000538
Chris Wilson817d57f2017-01-20 17:17:42 +0000539 igt_subtest("basic-sequential")
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000540 sequential(device, handle, 0, 5);
Chris Wilson817d57f2017-01-20 17:17:42 +0000541
Chris Wilson7e0853c2016-01-27 14:17:53 +0000542 for (e = intel_execution_engines; e->name; e++)
543 igt_subtest_f("%s", e->name)
Chris Wilson3a7325e2016-03-08 11:43:31 +0000544 single(device, handle, e->exec_id | e->flags, e->name);
545
Chris Wilson4cce7152016-09-08 13:43:17 +0100546 igt_subtest("series")
547 series(device, handle, 150);
548
549 igt_subtest("parallel")
550 parallel(device, handle, 150);
Daniel Vetterd9d95782012-12-04 17:13:05 +0100551
Chris Wilson817d57f2017-01-20 17:17:42 +0000552 igt_subtest("sequential")
Chris Wilson9fbf72b2017-01-22 18:24:37 +0000553 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 Wilson817d57f2017-01-20 17:17:42 +0000563
Tvrtko Ursulin8e4cfb22017-04-13 14:11:05 +0100564 igt_subtest("headless")
565 headless(device, handle);
566
Daniel Vetterb3880d32013-08-14 18:02:46 +0200567 igt_fixture {
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200568 igt_stop_hang_detector();
Chris Wilson2659cbb2015-03-26 12:09:57 +0000569 gem_close(device, handle);
Chris Wilson2659cbb2015-03-26 12:09:57 +0000570 close(device);
Daniel Vetterb3880d32013-08-14 18:02:46 +0200571 }
Chris Wilson07d59b32011-01-20 22:10:10 +0000572}