summaryrefslogtreecommitdiff
path: root/lib/i915/gem.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2020-05-05 13:08:54 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2020-05-19 14:18:56 +0100
commitf3072b262d01c1d2837b73c658faba77686dd154 (patch)
tree3de2331d188c77ec357711300eba0404d22a969c /lib/i915/gem.c
parent66ab5e42811fee3dea8c21ab29e70e323a0650de (diff)
lib/i915: Reset all engine properties to defaults prior to the start of a test
We need each test in an isolated context, so that bad results from one test do not interfere with the next. In particular, we want to clean up the device and reset it to the defaults so that they are known for the next test, and the test can focus on behaviour it wants to control. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Acked-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Diffstat (limited to 'lib/i915/gem.c')
-rw-r--r--lib/i915/gem.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/i915/gem.c b/lib/i915/gem.c
index cabd23768..3ef31ed33 100644
--- a/lib/i915/gem.c
+++ b/lib/i915/gem.c
@@ -22,6 +22,7 @@
*
*/
+#include <dirent.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -30,6 +31,89 @@
#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;
@@ -66,6 +150,7 @@ void igt_require_gem(int i915)
* sequences of batches.
*/
reset_device(i915);
+ restore_defaults(i915);
err = 0;
if (ioctl(i915, DRM_IOCTL_I915_GEM_THROTTLE)) {