intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH i-g-t 1/2] lib/i915: Allow writing of engine properties
@ 2020-03-13 20:04 Chris Wilson
  2020-03-13 20:04 ` [Intel-gfx] [PATCH i-g-t 2/2] i915/gem_ctx_persistence: Tune reset-timeout Chris Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Wilson @ 2020-03-13 20:04 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

Make setting engine tunables easier!

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/i915/gem_engine_topology.c | 49 +++++++++++++++++++++++++++-------
 lib/i915/gem_engine_topology.h |  4 +++
 2 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
index 6eca28236..79bc977eb 100644
--- a/lib/i915/gem_engine_topology.c
+++ b/lib/i915/gem_engine_topology.c
@@ -333,13 +333,25 @@ bool gem_engine_is_equal(const struct intel_execution_engine2 *e1,
 	return e1->class == e2->class && e1->instance == e2->instance;
 }
 
-static FILE *__open_attr(int dir, ...)
+static int reopen(int dir, int mode)
+{
+	char buf[128];
+	int fd;
+
+	snprintf(buf, sizeof(buf), "/proc/self/fd/%d", dir);
+	fd = open(buf, mode);
+	close(dir);
+
+	return fd;
+}
+
+static FILE *__open_attr(int dir, const char *mode, ...)
 {
 	const char *path;
 	FILE *file;
 	va_list ap;
 
-	va_start(ap, dir);
+	va_start(ap, mode);
 	while (dir >= 0 && (path = va_arg(ap, const char *))) {
 		int fd;
 
@@ -350,7 +362,10 @@ static FILE *__open_attr(int dir, ...)
 	}
 	va_end(ap);
 
-	file = fdopen(dir, "r");
+	if (*mode != 'r') /* clumsy, but fun */
+		dir = reopen(dir, O_RDWR);
+
+	file = fdopen(dir, mode);
 	if (!file) {
 		close(dir);
 		return NULL;
@@ -365,13 +380,9 @@ int gem_engine_property_scanf(int i915, const char *engine, const char *attr,
 	FILE *file;
 	va_list ap;
 	int ret;
-	int fd;
-
-	fd = igt_sysfs_open(i915);
-	if (fd < 0)
-		return fd;
 
-	file = __open_attr(fd, "engine", engine, attr, NULL);
+	file = __open_attr(igt_sysfs_open(i915), "r",
+			   "engine", engine, attr, NULL);
 	if (!file)
 		return -1;
 
@@ -383,6 +394,26 @@ int gem_engine_property_scanf(int i915, const char *engine, const char *attr,
 	return ret;
 }
 
+int gem_engine_property_printf(int i915, const char *engine, const char *attr,
+			       const char *fmt, ...)
+{
+	FILE *file;
+	va_list ap;
+	int ret;
+
+	file = __open_attr(igt_sysfs_open(i915), "w",
+			   "engine", engine, attr, NULL);
+	if (!file)
+		return -1;
+
+	va_start(ap, fmt);
+	ret = vfprintf(file, fmt, ap);
+	va_end(ap);
+
+	fclose(file);
+	return ret;
+}
+
 uint32_t gem_engine_mmio_base(int i915, const char *engine)
 {
 	unsigned int mmio = 0;
diff --git a/lib/i915/gem_engine_topology.h b/lib/i915/gem_engine_topology.h
index 219c84b72..5e3440fa8 100644
--- a/lib/i915/gem_engine_topology.h
+++ b/lib/i915/gem_engine_topology.h
@@ -78,6 +78,10 @@ struct intel_execution_engine2 gem_eb_flags_to_engine(unsigned int flags);
 __attribute__((format(scanf, 4, 5)))
 int gem_engine_property_scanf(int i915, const char *engine, const char *attr,
 			      const char *fmt, ...);
+__attribute__((format(printf, 4, 5)))
+int gem_engine_property_printf(int i915, const char *engine, const char *attr,
+			       const char *fmt, ...);
+
 uint32_t gem_engine_mmio_base(int i915, const char *engine);
 
 #endif /* GEM_ENGINE_TOPOLOGY_H */
-- 
2.25.1

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

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

* [Intel-gfx] [PATCH i-g-t 2/2] i915/gem_ctx_persistence: Tune reset-timeout
  2020-03-13 20:04 [Intel-gfx] [PATCH i-g-t 1/2] lib/i915: Allow writing of engine properties Chris Wilson
@ 2020-03-13 20:04 ` Chris Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Wilson @ 2020-03-13 20:04 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

When we can control the preempt_timeout_ms property on an engine, we can
specify a much faster timeout and so expect our tests to run much
faster.

Then we can also avoid the embarrassment if the preempt reset is disabled
and the tests start failing because we are not waiting 10+s for the
hangcheck.

Closes: https://gitlab.freedesktop.org/drm/intel/issues/1440
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 tests/i915/gem_ctx_persistence.c | 39 ++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c
index f6d98f850..3b94ba962 100644
--- a/tests/i915/gem_ctx_persistence.c
+++ b/tests/i915/gem_ctx_persistence.c
@@ -41,7 +41,8 @@
 #include "ioctl_wrappers.h" /* gem_wait()! */
 #include "sw_sync.h"
 
-static unsigned long reset_timeout_ms = 2 * MSEC_PER_SEC; /* default: 640ms */
+#define RESET_TIMEOUT_MS 2 * MSEC_PER_SEC; /* default: 640ms */
+static unsigned long reset_timeout_ms = RESET_TIMEOUT_MS;
 #define NSEC_PER_MSEC (1000 * 1000ull)
 
 static bool has_persistence(int i915)
@@ -1010,6 +1011,28 @@ static void replace_engines_hostile(int i915,
 	gem_quiescent_gpu(i915);
 }
 
+static void do_test(void (*test)(int i915, unsigned int engine),
+		    int i915, unsigned int engine,
+		    const char *name)
+{
+#define ATTR "preempt_timeout_ms"
+	int timeout = -1;
+
+	gem_engine_property_scanf(i915, name, ATTR, "%d", &timeout);
+	if (timeout != -1) {
+		igt_require(gem_engine_property_printf(i915, name,
+						       ATTR, "%d", 50) > 0);
+		reset_timeout_ms = 200;
+	}
+
+	test(i915, engine);
+
+	if (timeout != -1) {
+		gem_engine_property_printf(i915, name, ATTR, "%d", timeout);
+		reset_timeout_ms = RESET_TIMEOUT_MS;
+	}
+}
+
 int i915;
 
 static void exit_handler(int sig)
@@ -1079,8 +1102,11 @@ igt_main
 			igt_subtest_with_dynamic_f("legacy-engines-%s",
 						   test->name) {
 				for_each_engine(e, i915) {
-					igt_dynamic_f("%s", e->name)
-						test->func(i915, eb_ring(e));
+					igt_dynamic_f("%s", e->name) {
+						do_test(test->func,
+							i915, eb_ring(e),
+							e->name);
+					}
 				}
 			}
 		}
@@ -1100,8 +1126,11 @@ igt_main
 		for (test = tests; test->name; test++) {
 			igt_subtest_with_dynamic_f("engines-%s", test->name) {
 				__for_each_physical_engine(i915, e) {
-					igt_dynamic_f("%s", e->name)
-						test->func(i915, e->flags);
+					igt_dynamic_f("%s", e->name) {
+						do_test(test->func,
+							i915, e->flags,
+							e->name);
+					}
 				}
 			}
 		}
-- 
2.25.1

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

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

end of thread, other threads:[~2020-03-13 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 20:04 [Intel-gfx] [PATCH i-g-t 1/2] lib/i915: Allow writing of engine properties Chris Wilson
2020-03-13 20:04 ` [Intel-gfx] [PATCH i-g-t 2/2] i915/gem_ctx_persistence: Tune reset-timeout 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).