intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH i-g-t] lib/i915: Reset all engine properties to defaults prior to the start of a test
@ 2020-05-18 21:39 Chris Wilson
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Wilson @ 2020-05-18 21:39 UTC (permalink / raw)
  To: igt-dev; +Cc: intel-gfx, Chris Wilson

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>
---
 lib/i915/gem.c                   | 85 ++++++++++++++++++++++++++++++++
 lib/igt_dummyload.c              |  2 -
 lib/igt_gt.c                     |  2 -
 tests/i915/gem_ctx_persistence.c |  1 -
 4 files changed, 85 insertions(+), 5 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)) {
diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 0b52eb5b5..a733bd674 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -355,8 +355,6 @@ igt_spin_factory(int fd, const struct igt_spin_factory *opts)
 {
 	igt_spin_t *spin;
 
-	igt_require_gem(fd);
-
 	if (opts->engine != ALL_ENGINES) {
 		struct intel_execution_engine2 e;
 		int class;
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index a806b567a..101627973 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -172,8 +172,6 @@ igt_hang_t igt_allow_hang(int fd, unsigned ctx, unsigned flags)
 	 * to recover from reset and for it to remain wedged. It's hard to
 	 * say even if we do hang/reset making the test suspect.
 	 */
-	igt_require_gem(fd);
-
 	if (!igt_check_boolean_env_var("IGT_HANG", true))
 		igt_skip("hang injection disabled by user [IGT_HANG=0]\n");
 	gem_context_require_bannable(fd);
diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c
index ce9f02350..cca4c3a91 100644
--- a/tests/i915/gem_ctx_persistence.c
+++ b/tests/i915/gem_ctx_persistence.c
@@ -56,7 +56,6 @@ static void cleanup(int i915)
 			    DROP_RESET_ACTIVE | DROP_RESET_SEQNO |
 			    /* cleanup */
 			    DROP_ACTIVE | DROP_RETIRE | DROP_IDLE | DROP_FREED);
-	igt_require_gem(i915);
 }
 
 static int wait_for_status(int fence, int timeout)
-- 
2.26.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Intel-gfx] [PATCH i-g-t] lib/i915: Reset all engine properties to defaults prior to the start of a test
@ 2020-05-14  7:44 Chris Wilson
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Wilson @ 2020-05-14  7:44 UTC (permalink / raw)
  To: igt-dev; +Cc: intel-gfx, Chris Wilson

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>
---
 lib/i915/gem.c      | 85 +++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_dummyload.c |  2 --
 lib/igt_gt.c        |  2 --
 3 files changed, 85 insertions(+), 4 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)) {
diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 0b52eb5b5..a733bd674 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -355,8 +355,6 @@ igt_spin_factory(int fd, const struct igt_spin_factory *opts)
 {
 	igt_spin_t *spin;
 
-	igt_require_gem(fd);
-
 	if (opts->engine != ALL_ENGINES) {
 		struct intel_execution_engine2 e;
 		int class;
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index a806b567a..101627973 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -172,8 +172,6 @@ igt_hang_t igt_allow_hang(int fd, unsigned ctx, unsigned flags)
 	 * to recover from reset and for it to remain wedged. It's hard to
 	 * say even if we do hang/reset making the test suspect.
 	 */
-	igt_require_gem(fd);
-
 	if (!igt_check_boolean_env_var("IGT_HANG", true))
 		igt_skip("hang injection disabled by user [IGT_HANG=0]\n");
 	gem_context_require_bannable(fd);
-- 
2.26.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Intel-gfx] [PATCH i-g-t] lib/i915: Reset all engine properties to defaults prior to the start of a test
@ 2020-05-05 12:13 Chris Wilson
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Wilson @ 2020-05-05 12:13 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev, Chris Wilson

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>
---
 lib/i915/gem.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/lib/i915/gem.c b/lib/i915/gem.c
index b2717ba6a..6fa8abf21 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,87 @@
 #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);
+
+		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 +148,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)) {
-- 
2.26.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-18 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18 21:39 [Intel-gfx] [PATCH i-g-t] lib/i915: Reset all engine properties to defaults prior to the start of a test Chris Wilson
  -- strict thread matches above, loose matches on Subject: below --
2020-05-14  7:44 Chris Wilson
2020-05-05 12:13 Chris Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).