Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 1 | /* |
| 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 Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 30 | #include "igt.h" |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 31 | #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 Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 42 | |
| 43 | IGT_TEST_DESCRIPTION("Test that specific ioctls report a wedged GPU (EIO)."); |
| 44 | |
| 45 | static bool i915_reset_control(bool enable) |
| 46 | { |
| 47 | const char *path = "/sys/module/i915/parameters/reset"; |
| 48 | int fd, ret; |
| 49 | |
| 50 | igt_debug("%s GPU reset\n", enable ? "Enabling" : "Disabling"); |
| 51 | |
| 52 | fd = open(path, O_RDWR); |
| 53 | igt_require(fd >= 0); |
| 54 | |
| 55 | ret = write(fd, &"NY"[enable], 1) == 1; |
| 56 | close(fd); |
| 57 | |
| 58 | return ret; |
| 59 | } |
| 60 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 61 | static void trigger_reset(int fd) |
| 62 | { |
Daniele Ceraolo Spurio | 03c7f84 | 2016-03-01 11:01:32 +0000 | [diff] [blame] | 63 | igt_force_gpu_reset(); |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 64 | |
| 65 | /* And just check the gpu is indeed running again */ |
| 66 | igt_debug("Checking that the GPU recovered\n"); |
| 67 | gem_quiescent_gpu(fd); |
| 68 | } |
| 69 | |
| 70 | static void wedge_gpu(int fd) |
| 71 | { |
| 72 | /* First idle the GPU then disable GPU resets before injecting a hang */ |
| 73 | gem_quiescent_gpu(fd); |
| 74 | |
| 75 | igt_require(i915_reset_control(false)); |
| 76 | |
| 77 | igt_debug("Wedging GPU by injecting hang\n"); |
| 78 | igt_post_hang_ring(fd, igt_hang_ring(fd, I915_EXEC_DEFAULT)); |
| 79 | |
| 80 | igt_assert(i915_reset_control(true)); |
| 81 | } |
| 82 | |
| 83 | static int __gem_throttle(int fd) |
| 84 | { |
| 85 | int err = 0; |
| 86 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL)) |
| 87 | err = -errno; |
| 88 | return err; |
| 89 | } |
| 90 | |
| 91 | static void test_throttle(int fd) |
| 92 | { |
| 93 | wedge_gpu(fd); |
| 94 | |
| 95 | igt_assert_eq(__gem_throttle(fd), -EIO); |
| 96 | |
| 97 | trigger_reset(fd); |
| 98 | } |
| 99 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 100 | static void test_execbuf(int fd) |
| 101 | { |
| 102 | struct drm_i915_gem_execbuffer2 execbuf; |
| 103 | struct drm_i915_gem_exec_object2 exec; |
| 104 | uint32_t tmp[] = { MI_BATCH_BUFFER_END }; |
| 105 | |
| 106 | memset(&exec, 0, sizeof(exec)); |
| 107 | memset(&execbuf, 0, sizeof(execbuf)); |
| 108 | |
| 109 | exec.handle = gem_create(fd, 4096); |
| 110 | gem_write(fd, exec.handle, 0, tmp, sizeof(tmp)); |
| 111 | |
| 112 | execbuf.buffers_ptr = (uintptr_t)&exec; |
| 113 | execbuf.buffer_count = 1; |
| 114 | |
| 115 | wedge_gpu(fd); |
| 116 | |
| 117 | igt_assert_eq(__gem_execbuf(fd, &execbuf), -EIO); |
| 118 | gem_close(fd, exec.handle); |
| 119 | |
| 120 | trigger_reset(fd); |
| 121 | } |
| 122 | |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 123 | static int __gem_wait(int fd, uint32_t handle, int64_t timeout) |
| 124 | { |
| 125 | struct drm_i915_gem_wait wait; |
| 126 | int err = 0; |
| 127 | |
| 128 | memset(&wait, 0, sizeof(wait)); |
| 129 | wait.bo_handle = handle; |
| 130 | wait.timeout_ns = timeout; |
| 131 | if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait)) |
| 132 | err = -errno; |
| 133 | |
| 134 | return err; |
| 135 | } |
| 136 | |
| 137 | static void test_wait(int fd) |
| 138 | { |
Chris Wilson | 0a1fc45 | 2016-09-13 11:13:14 +0100 | [diff] [blame^] | 139 | igt_hang_t hang; |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 140 | |
Daniel Vetter | 40798ef | 2015-12-16 13:13:58 +0000 | [diff] [blame] | 141 | /* If the request we wait on completes due to a hang (even for |
| 142 | * that request), the user expects the return value to 0 (success). |
| 143 | */ |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 144 | hang = igt_hang_ring(fd, I915_EXEC_DEFAULT); |
Daniel Vetter | 40798ef | 2015-12-16 13:13:58 +0000 | [diff] [blame] | 145 | igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0); |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 146 | igt_post_hang_ring(fd, hang); |
| 147 | |
Daniel Vetter | 40798ef | 2015-12-16 13:13:58 +0000 | [diff] [blame] | 148 | /* If the GPU is wedged during the wait, again we expect the return |
| 149 | * value to be 0 (success). |
| 150 | */ |
| 151 | igt_require(i915_reset_control(false)); |
| 152 | hang = igt_hang_ring(fd, I915_EXEC_DEFAULT); |
| 153 | igt_assert_eq(__gem_wait(fd, hang.handle, -1), 0); |
| 154 | igt_post_hang_ring(fd, hang); |
| 155 | igt_require(i915_reset_control(true)); |
| 156 | |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 157 | trigger_reset(fd); |
| 158 | } |
| 159 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 160 | igt_main |
| 161 | { |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 162 | int fd = -1; |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 163 | |
| 164 | igt_skip_on_simulation(); |
| 165 | |
| 166 | igt_fixture { |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 167 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 92caf13 | 2015-12-16 09:23:56 +0000 | [diff] [blame] | 168 | igt_require_hang_ring(fd, I915_EXEC_DEFAULT); |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | igt_subtest("throttle") |
| 172 | test_throttle(fd); |
| 173 | |
| 174 | igt_subtest("execbuf") |
| 175 | test_execbuf(fd); |
| 176 | |
Chris Wilson | 32c8988 | 2015-07-15 16:18:10 +0100 | [diff] [blame] | 177 | igt_subtest("wait") |
| 178 | test_wait(fd); |
| 179 | |
Chris Wilson | eb7d60e | 2015-06-17 18:29:49 +0100 | [diff] [blame] | 180 | igt_fixture |
| 181 | close(fd); |
| 182 | } |