blob: dc7f5143133f175402909b807c2428a09e415a43 [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 Wilsonc6e26e42016-07-22 12:58:54 +010029#include "igt_sysfs.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000030#include <unistd.h>
31#include <stdlib.h>
32#include <stdint.h>
33#include <stdio.h>
34#include <string.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000035#include <fcntl.h>
36#include <inttypes.h>
37#include <errno.h>
38#include <sys/stat.h>
39#include <sys/ioctl.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000040#include <sys/time.h>
Chris Wilsonb4307092015-07-01 13:53:07 +010041#include <time.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000042#include "drm.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000043
Chris Wilsoncd8d3802015-03-24 09:15:12 +000044#define LOCAL_I915_EXEC_NO_RELOC (1<<11)
45#define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
46
Chris Wilson3a7325e2016-03-08 11:43:31 +000047#define LOCAL_I915_EXEC_BSD_SHIFT (13)
48#define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT)
Daniel Vetter51f08302012-12-05 19:29:11 +010049
Chris Wilson3a7325e2016-03-08 11:43:31 +000050#define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK)
Chris Wilson2659cbb2015-03-26 12:09:57 +000051
Chris Wilson3a7325e2016-03-08 11:43:31 +000052static double elapsed(const struct timespec *start, const struct timespec *end)
53{
54 return ((end->tv_sec - start->tv_sec) +
55 (end->tv_nsec - start->tv_nsec)*1e-9);
56}
57
Chris Wilson870c7742016-03-28 15:29:46 +010058static double nop_on_ring(int fd, uint32_t handle, unsigned ring_id,
59 int timeout, unsigned long *out)
Chris Wilson07d59b32011-01-20 22:10:10 +000060{
61 struct drm_i915_gem_execbuffer2 execbuf;
Chris Wilson3a7325e2016-03-08 11:43:31 +000062 struct drm_i915_gem_exec_object2 obj;
63 struct timespec start, now;
Chris Wilson870c7742016-03-28 15:29:46 +010064 unsigned long count;
Daniel Vetter8f5387e2013-08-13 13:20:58 +020065
Chris Wilson3a7325e2016-03-08 11:43:31 +000066 memset(&obj, 0, sizeof(obj));
67 obj.handle = handle;
Chris Wilson07d59b32011-01-20 22:10:10 +000068
Chris Wilsoncd8d3802015-03-24 09:15:12 +000069 memset(&execbuf, 0, sizeof(execbuf));
Chris Wilson3a7325e2016-03-08 11:43:31 +000070 execbuf.buffers_ptr = (uintptr_t)&obj;
Chris Wilsoncd8d3802015-03-24 09:15:12 +000071 execbuf.buffer_count = 1;
72 execbuf.flags = ring_id;
73 execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT;
74 execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC;
Chris Wilson3e2443f2016-03-10 11:50:53 +000075 if (__gem_execbuf(fd, &execbuf)) {
Chris Wilsoncd8d3802015-03-24 09:15:12 +000076 execbuf.flags = ring_id;
Chris Wilson3a7325e2016-03-08 11:43:31 +000077 gem_execbuf(fd, &execbuf);
Chris Wilsoncd8d3802015-03-24 09:15:12 +000078 }
79 gem_sync(fd, handle);
Chris Wilson71f41532016-04-22 16:55:29 +010080 intel_detect_and_clear_missed_interrupts(fd);
Chris Wilsoncd8d3802015-03-24 09:15:12 +000081
Chris Wilson870c7742016-03-28 15:29:46 +010082 count = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +000083 clock_gettime(CLOCK_MONOTONIC, &start);
84 do {
Chris Wilson870c7742016-03-28 15:29:46 +010085 for (int loop = 0; loop < 1024; loop++)
Chris Wilson3a7325e2016-03-08 11:43:31 +000086 gem_execbuf(fd, &execbuf);
Chris Wilson870c7742016-03-28 15:29:46 +010087
88 count += 1024;
Chris Wilson3a7325e2016-03-08 11:43:31 +000089 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson870c7742016-03-28 15:29:46 +010090 } while (elapsed(&start, &now) < timeout);
Chris Wilson3a7325e2016-03-08 11:43:31 +000091 gem_sync(fd, handle);
92 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson71f41532016-04-22 16:55:29 +010093 igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
Chris Wilson3a7325e2016-03-08 11:43:31 +000094
Chris Wilson870c7742016-03-28 15:29:46 +010095 *out = count;
96 return elapsed(&start, &now);
97}
98
99static void single(int fd, uint32_t handle,
100 unsigned ring_id, const char *ring_name)
101{
102 double time;
103 unsigned long count;
104
105 gem_require_ring(fd, ring_id);
106
107 time = nop_on_ring(fd, handle, ring_id, 20, &count);
108 igt_info("%s: %'lu cycles: %.3fus\n",
109 ring_name, count, time*1e6 / count);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000110}
111
Chris Wilson0aacdac2016-03-09 21:06:16 +0000112static bool ignore_engine(int fd, unsigned engine)
113{
114 if (engine == 0)
115 return true;
116
117 if (gem_has_bsd2(fd) && engine == I915_EXEC_BSD)
118 return true;
119
120 return false;
121}
122
Chris Wilson772393e2016-03-14 14:31:36 +0000123static void all(int fd, uint32_t handle, int timeout)
Chris Wilson3a7325e2016-03-08 11:43:31 +0000124{
125 struct drm_i915_gem_execbuffer2 execbuf;
126 struct drm_i915_gem_exec_object2 obj;
127 struct timespec start, now;
128 unsigned engines[16];
129 unsigned nengine;
130 unsigned engine;
Chris Wilson870c7742016-03-28 15:29:46 +0100131 unsigned long count;
Chris Wilson41a26b52016-03-28 16:26:01 +0100132 double time, max = 0, min = HUGE_VAL, sum = 0;
Chris Wilson870c7742016-03-28 15:29:46 +0100133 const char *name;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000134
135 nengine = 0;
Chris Wilson870c7742016-03-28 15:29:46 +0100136 for_each_engine(fd, engine) {
137 if (ignore_engine(fd, engine))
138 continue;
139
140 time = nop_on_ring(fd, handle, engine, 1, &count) / count;
141 if (time > max) {
142 name = e__->name;
143 max = time;
144 }
Chris Wilson41a26b52016-03-28 16:26:01 +0100145 if (time < min)
146 min = time;
Chris Wilson870c7742016-03-28 15:29:46 +0100147 sum += time;
148 engines[nengine++] = engine;
149 }
Chris Wilson0aacdac2016-03-09 21:06:16 +0000150 igt_require(nengine);
Chris Wilson870c7742016-03-28 15:29:46 +0100151 igt_info("Maximum execution latency on %s, %.3fus, total %.3fus per cycle\n",
152 name, max*1e6, sum*1e6);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000153
154 memset(&obj, 0, sizeof(obj));
155 obj.handle = handle;
156
157 memset(&execbuf, 0, sizeof(execbuf));
158 execbuf.buffers_ptr = (uintptr_t)&obj;
159 execbuf.buffer_count = 1;
160 execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT;
161 execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC;
Chris Wilson3e2443f2016-03-10 11:50:53 +0000162 if (__gem_execbuf(fd, &execbuf)) {
Chris Wilson3a7325e2016-03-08 11:43:31 +0000163 execbuf.flags = 0;
164 gem_execbuf(fd, &execbuf);
Chris Wilson07d59b32011-01-20 22:10:10 +0000165 }
Chris Wilson3a7325e2016-03-08 11:43:31 +0000166 gem_sync(fd, handle);
Chris Wilson71f41532016-04-22 16:55:29 +0100167 intel_detect_and_clear_missed_interrupts(fd);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000168
Chris Wilson870c7742016-03-28 15:29:46 +0100169 count = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000170 clock_gettime(CLOCK_MONOTONIC, &start);
171 do {
172 for (int loop = 0; loop < 1024; loop++) {
173 for (int n = 0; n < nengine; n++) {
174 execbuf.flags &= ~ENGINE_FLAGS;
175 execbuf.flags |= engines[n];
176 gem_execbuf(fd, &execbuf);
177 }
178 }
179 count += nengine * 1024;
180 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson772393e2016-03-14 14:31:36 +0000181 } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */
Chris Wilson3a7325e2016-03-08 11:43:31 +0000182 gem_sync(fd, handle);
183 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson71f41532016-04-22 16:55:29 +0100184 igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000185
Chris Wilson870c7742016-03-28 15:29:46 +0100186 time = elapsed(&start, &now) / count;
187 igt_info("All (%d engines): %'lu cycles, average %.3fus per cycle\n",
188 nengine, count, 1e6*time);
Chris Wilson41a26b52016-03-28 16:26:01 +0100189
190 /* The rate limiting step is how fast the slowest engine can
191 * its queue of requests, if we wait upon a full ring all dispatch
192 * is frozen. So in general we cannot go faster than the slowest
193 * engine, but we should equally not go any slower.
194 */
Chris Wilson7bd4f912016-04-14 17:03:07 +0100195 igt_assert_f(time < max + 10*min/9, /* ensure parallel execution */
Chris Wilson082fb262016-04-15 10:57:33 +0100196 "Average time (%.3fus) exceeds expecation for parallel execution (min %.3fus, max %.3fus; limit set at %.3fus)\n",
Chris Wilson77b8a5b2016-04-18 10:26:05 +0100197 1e6*time, 1e6*min, 1e6*max, 1e6*(max + 10*min/9));
Daniel Vetterd9d95782012-12-04 17:13:05 +0100198}
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200199
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100200static void print_welcome(int fd)
201{
202 bool active;
203 char *str;
204 int dir;
205
206 dir = igt_sysfs_open_parameters(fd);
207 if (dir < 0)
208 return;
209
210 str = igt_sysfs_get(dir, "enable_guc_submission");
211 active = str && atoi(str) > 0;
212 free(str);
213
214 if (active) {
215 igt_info("Using GuC submission\n");
216 goto out;
217 }
218
219 str = igt_sysfs_get(dir, "enable_execlists");
220 active = str && atoi(str) > 0;
221 free(str);
222
223 if (active) {
224 igt_info("Using Execlists submission\n");
225 goto out;
226 }
227
228 str = igt_sysfs_get(dir, "semaphores");
229 active = str && atoi(str) > 0;
230 free(str);
231
232 igt_info("Using Legacy submission %s\n",
233 active ? ", with semaphores" : "");
234
235out:
236 close(dir);
237}
238
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100239igt_main
Daniel Vetterd9d95782012-12-04 17:13:05 +0100240{
Chris Wilson7e0853c2016-01-27 14:17:53 +0000241 const struct intel_execution_engine *e;
Chris Wilson2659cbb2015-03-26 12:09:57 +0000242 uint32_t handle = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000243 int device = -1;
Daniel Vetterd9d95782012-12-04 17:13:05 +0100244
Chris Wilson2659cbb2015-03-26 12:09:57 +0000245 igt_fixture {
Chris Wilson3a7325e2016-03-08 11:43:31 +0000246 const uint32_t bbe = MI_BATCH_BUFFER_END;
247
Micah Fedkec81d2932015-07-22 21:54:02 +0000248 device = drm_open_driver(DRIVER_INTEL);
Chris Wilsonc6e26e42016-07-22 12:58:54 +0100249 print_welcome(device);
250
Chris Wilson2659cbb2015-03-26 12:09:57 +0000251 handle = gem_create(device, 4096);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000252 gem_write(device, handle, 0, &bbe, sizeof(bbe));
Daniel Vetterd9d95782012-12-04 17:13:05 +0100253
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200254 igt_fork_hang_detector(device);
255 }
Chris Wilson9d61a682016-03-25 18:22:54 +0000256
Chris Wilson772393e2016-03-14 14:31:36 +0000257 igt_subtest("basic")
258 all(device, handle, 10);
259
Chris Wilson7e0853c2016-01-27 14:17:53 +0000260 for (e = intel_execution_engines; e->name; e++)
261 igt_subtest_f("%s", e->name)
Chris Wilson3a7325e2016-03-08 11:43:31 +0000262 single(device, handle, e->exec_id | e->flags, e->name);
263
Chris Wilson772393e2016-03-14 14:31:36 +0000264 igt_subtest("all")
265 all(device, handle, 150);
Daniel Vetterd9d95782012-12-04 17:13:05 +0100266
Daniel Vetterb3880d32013-08-14 18:02:46 +0200267 igt_fixture {
Daniel Vetterbe21fc02016-06-17 16:04:09 +0200268 igt_stop_hang_detector();
Chris Wilson2659cbb2015-03-26 12:09:57 +0000269 gem_close(device, handle);
Chris Wilson2659cbb2015-03-26 12:09:57 +0000270 close(device);
Daniel Vetterb3880d32013-08-14 18:02:46 +0200271 }
Chris Wilson07d59b32011-01-20 22:10:10 +0000272}