1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
* Copyright © 2007,2014,2020 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#include <dirent.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "i915/gem.h"
#include "igt.h"
#include "igt_debugfs.h"
#include "igt_sysfs.h"
static void __restore_defaults(int engine)
{
struct dirent *de;
int defaults;
DIR *dir;
defaults = openat(engine, ".defaults", O_RDONLY);
if (defaults < 0)
return;
dir = fdopendir(defaults);
if (!dir) {
close(defaults);
return;
}
while ((de = readdir(dir))) {
char buf[256];
int fd, len;
if (*de->d_name == '.')
continue;
fd = openat(defaults, de->d_name, O_RDONLY);
if (fd < 0)
continue;
len = read(fd, buf, sizeof(buf));
close(fd);
if (len < 0)
continue;
fd = openat(engine, de->d_name, O_WRONLY);
if (fd < 0)
continue;
write(fd, buf, len);
close(fd);
}
closedir(dir);
}
static void restore_defaults(int i915)
{
struct dirent *de;
int engines;
DIR *dir;
int sys;
sys = igt_sysfs_open(i915);
if (sys < 0)
return;
engines = openat(sys, "engine", O_RDONLY);
if (engines < 0)
goto close_sys;
dir = fdopendir(engines);
if (!dir) {
close(engines);
goto close_sys;
}
while ((de = readdir(dir))) {
int engine;
if (*de->d_name == '.')
continue;
engine = openat(engines, de->d_name, O_RDONLY);
if (engine < 0)
continue;
__restore_defaults(engine);
close(engine);
}
closedir(dir);
close_sys:
close(sys);
}
static void reset_device(int i915)
{
int dir;
dir = igt_debugfs_dir(i915);
igt_require(dir >= 0);
if (ioctl(i915, DRM_IOCTL_I915_GEM_THROTTLE)) {
igt_info("Found wedged device, trying to reset and continue\n");
igt_sysfs_printf(dir, "i915_wedged", "%llu", -1ull);
}
close(dir);
}
static void restore_params(int i915)
{
/* Re-enable modparams if left clobbered */
igt_params_set(i915, "reset", "%u", -1);
igt_params_set(i915, "enable_hangcheck", "%u", 1);
}
void igt_require_gem(int i915)
{
int err;
igt_require_i915(i915);
/*
* We only want to use the throttle-ioctl for its -EIO reporting
* of a wedged device, not for actually waiting on outstanding
* requests! So create a new drm_file for the device that is clean.
*/
i915 = drm_reopen_driver(i915);
/*
* Reset the global seqno at the start of each test. This ensures that
* the test will not wrap unless it explicitly sets up seqno wrapping
* itself, which avoids accidentally hanging when setting up long
* sequences of batches.
*/
reset_device(i915);
restore_params(i915);
restore_defaults(i915);
err = 0;
if (ioctl(i915, DRM_IOCTL_I915_GEM_THROTTLE)) {
err = -errno;
igt_assume(err);
}
close(i915);
igt_require_f(err == 0, "Unresponsive i915/GEM device\n");
}
/**
* gem_quiescent_gpu:
* @i915: open i915 drm file descriptor
*
* Ensure the gpu is idle by launching a nop execbuf and stalling for it. This
* is automatically run when opening a drm device node and is also installed as
* an exit handler to have the best assurance that the test is run in a pristine
* and controlled environment.
*
* This function simply allows tests to make additional calls in-between, if so
* desired.
*/
void gem_quiescent_gpu(int i915)
{
igt_terminate_spins();
igt_drop_caches_set(i915,
DROP_ACTIVE | DROP_RETIRE | DROP_IDLE | DROP_FREED);
}
|