blob: 4134b24a89b8e771fc08ba3f43d25a34922bdf38 [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 Wilson07d59b32011-01-20 22:10:10 +000029#include <unistd.h>
30#include <stdlib.h>
31#include <stdint.h>
32#include <stdio.h>
33#include <string.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000034#include <fcntl.h>
35#include <inttypes.h>
36#include <errno.h>
37#include <sys/stat.h>
38#include <sys/ioctl.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000039#include <sys/time.h>
Chris Wilsonb4307092015-07-01 13:53:07 +010040#include <time.h>
Chris Wilson07d59b32011-01-20 22:10:10 +000041#include "drm.h"
Chris Wilson07d59b32011-01-20 22:10:10 +000042
Chris Wilsoncd8d3802015-03-24 09:15:12 +000043#define LOCAL_I915_EXEC_NO_RELOC (1<<11)
44#define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
45
Chris Wilson3a7325e2016-03-08 11:43:31 +000046#define LOCAL_I915_EXEC_BSD_SHIFT (13)
47#define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT)
Daniel Vetter51f08302012-12-05 19:29:11 +010048
Chris Wilson3a7325e2016-03-08 11:43:31 +000049#define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK)
Chris Wilson2659cbb2015-03-26 12:09:57 +000050
Chris Wilson3a7325e2016-03-08 11:43:31 +000051static double elapsed(const struct timespec *start, const struct timespec *end)
52{
53 return ((end->tv_sec - start->tv_sec) +
54 (end->tv_nsec - start->tv_nsec)*1e-9);
55}
56
57static void single(int fd, uint32_t handle, unsigned ring_id, const char *ring_name)
Chris Wilson07d59b32011-01-20 22:10:10 +000058{
59 struct drm_i915_gem_execbuffer2 execbuf;
Chris Wilson3a7325e2016-03-08 11:43:31 +000060 struct drm_i915_gem_exec_object2 obj;
61 struct timespec start, now;
62 unsigned int count = 0;
Chris Wilson07d59b32011-01-20 22:10:10 +000063
Daniel Vetter8f5387e2013-08-13 13:20:58 +020064 gem_require_ring(fd, ring_id);
65
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);
80
Chris Wilson3a7325e2016-03-08 11:43:31 +000081 clock_gettime(CLOCK_MONOTONIC, &start);
82 do {
83 for (int loop = 0; loop < 1024; loop++) {
84 gem_execbuf(fd, &execbuf);
85 count++;
86 }
87 clock_gettime(CLOCK_MONOTONIC, &now);
88 } while (elapsed(&start, &now) < 20.);
89 gem_sync(fd, handle);
90 clock_gettime(CLOCK_MONOTONIC, &now);
91
92 igt_info("%s: %'u cycles: %.3fus\n",
93 ring_name, count, elapsed(&start, &now)*1e6 / count);
94}
95
Chris Wilson0aacdac2016-03-09 21:06:16 +000096static bool ignore_engine(int fd, unsigned engine)
97{
98 if (engine == 0)
99 return true;
100
101 if (gem_has_bsd2(fd) && engine == I915_EXEC_BSD)
102 return true;
103
104 return false;
105}
106
Chris Wilson772393e2016-03-14 14:31:36 +0000107static void all(int fd, uint32_t handle, int timeout)
Chris Wilson3a7325e2016-03-08 11:43:31 +0000108{
109 struct drm_i915_gem_execbuffer2 execbuf;
110 struct drm_i915_gem_exec_object2 obj;
111 struct timespec start, now;
112 unsigned engines[16];
113 unsigned nengine;
114 unsigned engine;
115 unsigned int count = 0;
116
117 nengine = 0;
118 for_each_engine(fd, engine)
Chris Wilson0aacdac2016-03-09 21:06:16 +0000119 if (!ignore_engine(fd, engine)) engines[nengine++] = engine;
120 igt_require(nengine);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000121
122 memset(&obj, 0, sizeof(obj));
123 obj.handle = handle;
124
125 memset(&execbuf, 0, sizeof(execbuf));
126 execbuf.buffers_ptr = (uintptr_t)&obj;
127 execbuf.buffer_count = 1;
128 execbuf.flags |= LOCAL_I915_EXEC_HANDLE_LUT;
129 execbuf.flags |= LOCAL_I915_EXEC_NO_RELOC;
Chris Wilson3e2443f2016-03-10 11:50:53 +0000130 if (__gem_execbuf(fd, &execbuf)) {
Chris Wilson3a7325e2016-03-08 11:43:31 +0000131 execbuf.flags = 0;
132 gem_execbuf(fd, &execbuf);
Chris Wilson07d59b32011-01-20 22:10:10 +0000133 }
Chris Wilson3a7325e2016-03-08 11:43:31 +0000134 gem_sync(fd, handle);
135
136 clock_gettime(CLOCK_MONOTONIC, &start);
137 do {
138 for (int loop = 0; loop < 1024; loop++) {
139 for (int n = 0; n < nengine; n++) {
140 execbuf.flags &= ~ENGINE_FLAGS;
141 execbuf.flags |= engines[n];
142 gem_execbuf(fd, &execbuf);
143 }
144 }
145 count += nengine * 1024;
146 clock_gettime(CLOCK_MONOTONIC, &now);
Chris Wilson772393e2016-03-14 14:31:36 +0000147 } while (elapsed(&start, &now) < timeout); /* Hang detection ~120s */
Chris Wilson3a7325e2016-03-08 11:43:31 +0000148 gem_sync(fd, handle);
149 clock_gettime(CLOCK_MONOTONIC, &now);
150
151 igt_info("All (%d engines): %'u cycles: %.3fus\n",
152 nengine, count, elapsed(&start, &now)*1e6 / count);
Daniel Vetterd9d95782012-12-04 17:13:05 +0100153}
Daniel Vetter8f5387e2013-08-13 13:20:58 +0200154
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100155igt_main
Daniel Vetterd9d95782012-12-04 17:13:05 +0100156{
Chris Wilson7e0853c2016-01-27 14:17:53 +0000157 const struct intel_execution_engine *e;
Chris Wilson2659cbb2015-03-26 12:09:57 +0000158 uint32_t handle = 0;
Chris Wilson3a7325e2016-03-08 11:43:31 +0000159 int device = -1;
Daniel Vetterd9d95782012-12-04 17:13:05 +0100160
Chris Wilson2659cbb2015-03-26 12:09:57 +0000161 igt_fixture {
Chris Wilson3a7325e2016-03-08 11:43:31 +0000162 const uint32_t bbe = MI_BATCH_BUFFER_END;
163
Micah Fedkec81d2932015-07-22 21:54:02 +0000164 device = drm_open_driver(DRIVER_INTEL);
Chris Wilson2659cbb2015-03-26 12:09:57 +0000165 handle = gem_create(device, 4096);
Chris Wilson3a7325e2016-03-08 11:43:31 +0000166 gem_write(device, handle, 0, &bbe, sizeof(bbe));
Daniel Vetterb3880d32013-08-14 18:02:46 +0200167 }
Daniel Vetterd9d95782012-12-04 17:13:05 +0100168
Chris Wilson9d61a682016-03-25 18:22:54 +0000169 igt_fork_hang_detector(device);
170
Chris Wilson772393e2016-03-14 14:31:36 +0000171 igt_subtest("basic")
172 all(device, handle, 10);
173
Chris Wilson7e0853c2016-01-27 14:17:53 +0000174 for (e = intel_execution_engines; e->name; e++)
175 igt_subtest_f("%s", e->name)
Chris Wilson3a7325e2016-03-08 11:43:31 +0000176 single(device, handle, e->exec_id | e->flags, e->name);
177
Chris Wilson772393e2016-03-14 14:31:36 +0000178 igt_subtest("all")
179 all(device, handle, 150);
Daniel Vetterd9d95782012-12-04 17:13:05 +0100180
Chris Wilson9d61a682016-03-25 18:22:54 +0000181 igt_stop_hang_detector();
182
Daniel Vetterb3880d32013-08-14 18:02:46 +0200183 igt_fixture {
Chris Wilson2659cbb2015-03-26 12:09:57 +0000184 gem_close(device, handle);
Chris Wilson2659cbb2015-03-26 12:09:57 +0000185 close(device);
Daniel Vetterb3880d32013-08-14 18:02:46 +0200186 }
Chris Wilson07d59b32011-01-20 22:10:10 +0000187}