blob: 00502378e2b26964bfe19d8191c82118b12c73fa [file] [log] [blame]
Chris Wilsoneb7d60e2015-06-17 18:29:49 +01001/*
2 * Copyright © 2015 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 */
24
25/*
26 * Testcase: Test that only specific ioctl report a wedged GPU.
27 *
28 */
29
Thomas Wood804e11f2015-08-17 17:57:43 +010030#include "igt.h"
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010031#include <stdlib.h>
32#include <stdio.h>
33#include <string.h>
34#include <unistd.h>
35#include <fcntl.h>
36#include <inttypes.h>
37#include <errno.h>
38#include <sys/ioctl.h>
39
40#include <drm.h>
41
Chris Wilson92e457d2017-09-08 11:33:15 +010042#include "sw_sync.h"
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010043
44IGT_TEST_DESCRIPTION("Test that specific ioctls report a wedged GPU (EIO).");
45
46static bool i915_reset_control(bool enable)
47{
48 const char *path = "/sys/module/i915/parameters/reset";
49 int fd, ret;
50
51 igt_debug("%s GPU reset\n", enable ? "Enabling" : "Disabling");
52
53 fd = open(path, O_RDWR);
54 igt_require(fd >= 0);
55
Chris Wilson6b2dddd2017-07-25 17:11:16 +010056 ret = write(fd, &"01"[enable], 1) == 1;
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010057 close(fd);
58
59 return ret;
60}
61
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010062static void trigger_reset(int fd)
63{
Chris Wilson83884e92017-03-21 17:16:03 +000064 igt_force_gpu_reset(fd);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +010065
66 /* And just check the gpu is indeed running again */
67 igt_debug("Checking that the GPU recovered\n");
68 gem_quiescent_gpu(fd);
69}
70
71static void wedge_gpu(int fd)
72{
73 /* First idle the GPU then disable GPU resets before injecting a hang */
74 gem_quiescent_gpu(fd);
75
76 igt_require(i915_reset_control(false));
77
78 igt_debug("Wedging GPU by injecting hang\n");
79 igt_post_hang_ring(fd, igt_hang_ring(fd, I915_EXEC_DEFAULT));
80
81 igt_assert(i915_reset_control(true));
82}
83
84static int __gem_throttle(int fd)
85{
86 int err = 0;
87 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL))
88 err = -errno;
89 return err;
90}
91
92static void test_throttle(int fd)
93{
94 wedge_gpu(fd);
95
96 igt_assert_eq(__gem_throttle(fd), -EIO);
97
98 trigger_reset(fd);
99}
100
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100101static void test_execbuf(int fd)
102{
103 struct drm_i915_gem_execbuffer2 execbuf;
104 struct drm_i915_gem_exec_object2 exec;
105 uint32_t tmp[] = { MI_BATCH_BUFFER_END };
106
107 memset(&exec, 0, sizeof(exec));
108 memset(&execbuf, 0, sizeof(execbuf));
109
110 exec.handle = gem_create(fd, 4096);
111 gem_write(fd, exec.handle, 0, tmp, sizeof(tmp));
112
Chris Wilson4de67b22017-01-02 11:05:21 +0000113 execbuf.buffers_ptr = to_user_pointer(&exec);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100114 execbuf.buffer_count = 1;
115
116 wedge_gpu(fd);
117
118 igt_assert_eq(__gem_execbuf(fd, &execbuf), -EIO);
119 gem_close(fd, exec.handle);
120
121 trigger_reset(fd);
122}
123
Chris Wilson32c89882015-07-15 16:18:10 +0100124static int __gem_wait(int fd, uint32_t handle, int64_t timeout)
125{
126 struct drm_i915_gem_wait wait;
127 int err = 0;
128
129 memset(&wait, 0, sizeof(wait));
130 wait.bo_handle = handle;
131 wait.timeout_ns = timeout;
132 if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait))
133 err = -errno;
134
135 return err;
136}
137
138static void test_wait(int fd)
139{
Chris Wilson0a1fc452016-09-13 11:13:14 +0100140 igt_hang_t hang;
Chris Wilson32c89882015-07-15 16:18:10 +0100141
Daniel Vetter40798ef2015-12-16 13:13:58 +0000142 /* If the request we wait on completes due to a hang (even for
143 * that request), the user expects the return value to 0 (success).
144 */
Chris Wilson32c89882015-07-15 16:18:10 +0100145 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
Daniel Vetter40798ef2015-12-16 13:13:58 +0000146 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
Chris Wilson32c89882015-07-15 16:18:10 +0100147 igt_post_hang_ring(fd, hang);
148
Daniel Vetter40798ef2015-12-16 13:13:58 +0000149 /* If the GPU is wedged during the wait, again we expect the return
150 * value to be 0 (success).
151 */
152 igt_require(i915_reset_control(false));
153 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
154 igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0);
155 igt_post_hang_ring(fd, hang);
156 igt_require(i915_reset_control(true));
157
Chris Wilson32c89882015-07-15 16:18:10 +0100158 trigger_reset(fd);
159}
160
Chris Wilson92e457d2017-09-08 11:33:15 +0100161static void test_inflight_external(int fd)
Chris Wilson9bbf6422016-11-18 08:50:33 +0000162{
163 struct drm_i915_gem_execbuffer2 execbuf;
Chris Wilson92e457d2017-09-08 11:33:15 +0100164 struct drm_i915_gem_exec_object2 obj;
Chris Wilson9bbf6422016-11-18 08:50:33 +0000165 uint32_t bbe = MI_BATCH_BUFFER_END;
166 igt_hang_t hang;
Chris Wilson92e457d2017-09-08 11:33:15 +0100167 int timeline, fence;
168
169 igt_require_sw_sync();
170 igt_require(gem_has_exec_fence(fd));
171
172 timeline = sw_sync_timeline_create();
173 fence = sw_sync_timeline_create_fence(timeline, 1);
Chris Wilson9bbf6422016-11-18 08:50:33 +0000174
175 igt_require(i915_reset_control(false));
176 hang = igt_hang_ring(fd, I915_EXEC_DEFAULT);
177
Chris Wilson92e457d2017-09-08 11:33:15 +0100178 memset(&obj, 0, sizeof(obj));
179 obj.handle = gem_create(fd, 4096);
180 gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe));
Chris Wilson9bbf6422016-11-18 08:50:33 +0000181
182 memset(&execbuf, 0, sizeof(execbuf));
Chris Wilson92e457d2017-09-08 11:33:15 +0100183 execbuf.buffers_ptr = to_user_pointer(&obj);
184 execbuf.buffer_count = 1;
185 execbuf.flags = I915_EXEC_FENCE_IN | I915_EXEC_FENCE_OUT;
186 execbuf.rsvd2 = (uint32_t)fence;
Chris Wilson9bbf6422016-11-18 08:50:33 +0000187
Chris Wilson92e457d2017-09-08 11:33:15 +0100188 gem_execbuf_wr(fd, &execbuf);
189 close(fence);
Chris Wilson9bbf6422016-11-18 08:50:33 +0000190
Chris Wilson92e457d2017-09-08 11:33:15 +0100191 fence = execbuf.rsvd2 >> 32;
192 igt_assert(fence != -1);
Chris Wilson9bbf6422016-11-18 08:50:33 +0000193
Chris Wilson92e457d2017-09-08 11:33:15 +0100194 igt_post_hang_ring(fd, hang); /* wedged, with an unready batch */
195 sw_sync_timeline_inc(timeline, 1); /* only now submit our batches */
196
197 igt_assert_eq(__gem_wait(fd, obj.handle, -1), 0);
198 igt_assert_eq(sync_fence_status(fence), -EIO);
199 close(fence);
200
201 igt_assert(i915_reset_control(true));
Chris Wilson9bbf6422016-11-18 08:50:33 +0000202 trigger_reset(fd);
Chris Wilson92e457d2017-09-08 11:33:15 +0100203 close(timeline);
Chris Wilson9bbf6422016-11-18 08:50:33 +0000204}
205
Chris Wilson4f082c32017-09-08 13:48:05 +0100206static int fd = -1;
207
208static void
209exit_handler(int sig)
210{
211 i915_reset_control(true);
212 igt_force_gpu_reset(fd);
213}
214
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100215igt_main
216{
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100217
218 igt_skip_on_simulation();
219
220 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000221 fd = drm_open_driver(DRIVER_INTEL);
Chris Wilson4f082c32017-09-08 13:48:05 +0100222
223 igt_require(i915_reset_control(true));
224 igt_force_gpu_reset(fd);
225 igt_install_exit_handler(exit_handler);
226
Chris Wilson28a2f142017-03-08 12:22:13 +0000227 igt_require_gem(fd);
Chris Wilson92caf132015-12-16 09:23:56 +0000228 igt_require_hang_ring(fd, I915_EXEC_DEFAULT);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100229 }
230
231 igt_subtest("throttle")
232 test_throttle(fd);
233
234 igt_subtest("execbuf")
235 test_execbuf(fd);
236
Chris Wilson32c89882015-07-15 16:18:10 +0100237 igt_subtest("wait")
238 test_wait(fd);
239
Chris Wilson92e457d2017-09-08 11:33:15 +0100240 igt_subtest("in-flight-external")
241 test_inflight_external(fd);
Chris Wilsoneb7d60e2015-06-17 18:29:49 +0100242}