[igt-dev] [PATCH i-g-t v2] tests/gem_watchdog: Initial set of tests for GPU watchdog

Carlos Santa carlos.santa at intel.com
Sat Oct 6 01:05:25 UTC 2018


This test adds basic set of tests to reset the different
GPU engines through the watchdog timer.

Credits to Antonio for the original codebase this is based on.

This was verified on SKL/ULT GT3:

$./gem_watchdog --run-subtest basic-vecs0
IGT-Version: 1.23-gaaeb2007206d (x86_64) (Linux: 4.18.0-rc7+ x86_64)
Starting subtest: basic-vecs0
Subtest basic-vecs0: SUCCESS (2.402s)
$ sudo cat /sys/kernel/debug/dri/0/i915_reset_info
full gpu reset = 0
GuC watchdog/media reset = 0
rcs0 = 0
bcs0 = 0
vcs0 = 0
vcs1 = 0
vecs0 = 1

v2: (Review comments from Chris Wilson)
 * Replace send_canary() by timestamps before/after the hang
   and measure dt. Use dt < 2*threshold + reset + submission
   to check watchdog vs hangcheck
 * Initialize drm_i915_gem_context_param args only once at
   the struct declaration
 * Avoid using MAX_ENGINES implicitly to declare engines_thresholds
   array
 * Remove unnecessary igt_assert(!check_error_state(fd))
 * Use the class:instance interface when looping through the engines

  (Review by Petri Latvala)
 * Update the correct patch's year timestamp
 * Include IGT_DESCRIPTION() label

Cc: Antonio Argenziano <antonio.argenziano at intel.com>
Cc: Michel Thierry <michel.thierry at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Carlos Santa <carlos.santa at intel.com>
---
 tests/Makefile.sources |   1 +
 tests/gem_watchdog.c   | 186 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build      |   1 +
 3 files changed, 188 insertions(+)
 create mode 100644 tests/gem_watchdog.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index c84933f1d971..9b298886a2e1 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -155,6 +155,7 @@ TESTS_progs = \
 	gem_unref_active_buffers \
 	gem_userptr_blits \
 	gem_wait \
+        gem_watchdog \
 	gem_workarounds \
 	gem_write_read_ring_switch \
 	gen3_mixed_blits \
diff --git a/tests/gem_watchdog.c b/tests/gem_watchdog.c
new file mode 100644
index 000000000000..ba5b77766d4c
--- /dev/null
+++ b/tests/gem_watchdog.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright © 2018 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 "igt.h"
+#include "igt_sysfs.h"
+
+#include <fcntl.h>
+#include <sys/time.h>
+
+IGT_TEST_DESCRIPTION("This test adds basic set of tests to reset the different,"
+                     " GPU engines through the watchdog timer.");
+
+#define WATCHDOG_THRESHOLD (1500)
+
+#define RENDER_CLASS 0
+#define VIDEO_DECODE_CLASS 1
+#define VIDEO_ENHANCEMENT_CLASS 2
+#define COPY_ENGINE_CLASS 3
+
+#define LOCAL_I915_CONTEXT_PARAM_WATCHDOG 0x7
+
+static void clear_error_state(int fd)
+{
+	int dir;
+
+	dir = igt_sysfs_open(fd, NULL);
+
+	if (dir < 0)
+		return;
+
+	/* Any write to the error state clears it */
+	igt_sysfs_set(dir, "error", "");
+	close(dir);
+}
+
+static bool check_error_state(int fd)
+{
+	char *error, *str;
+	bool found = false;
+	int dir;
+
+	dir = igt_sysfs_open(fd, NULL);
+
+	error = igt_sysfs_get(dir, "error");
+	igt_sysfs_set(dir, "error", "Begone!");
+
+	igt_assert(error);
+	igt_debug("Error: %s\n", error);
+
+	if ((str = strstr(error, "GPU HANG"))) {
+		igt_debug("Found error state! GPU hang triggered! %s\n", str);
+		found = true;
+	}
+
+	close(dir);
+
+	return found;
+}
+
+static void context_set_watchdog(int fd, const struct intel_execution_engine2 *e,
+                                 unsigned ctx, unsigned threshold)
+{
+	unsigned engines_threshold[16];
+	unsigned engine_id;
+	struct drm_i915_gem_context_param arg = {
+		.ctx_id = ctx,
+		.param = LOCAL_I915_CONTEXT_PARAM_WATCHDOG,
+		.value = (uint64_t)&engines_threshold,
+		.size = sizeof(arg.value)
+	};
+
+	memset(&engines_threshold, 0, sizeof(engines_threshold));
+
+	engine_id = gem_class_instance_to_eb_flags(fd, e->class, e->instance);
+
+	/* read existing values */
+	gem_context_get_param(fd, &arg);
+
+	switch (engine_id & I915_EXEC_RING_MASK) {
+	case I915_EXEC_RENDER:
+		engines_threshold[RENDER_CLASS] = threshold;
+		break;
+	case I915_EXEC_BSD:
+		engines_threshold[VIDEO_DECODE_CLASS] = threshold;
+		break;
+	case I915_EXEC_VEBOX:
+		engines_threshold[VIDEO_ENHANCEMENT_CLASS] = threshold;
+		break;
+	default:
+	break;
+	}
+
+	gem_context_set_param(fd, &arg);
+}
+
+static double elapsed(const struct timeval *start,
+		const struct timeval *end)
+{
+	return 1e6*(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec);
+}
+
+static void inject_hang(uint32_t fd, uint32_t ctx, const struct intel_execution_engine2 *e, unsigned flags)
+{
+	igt_hang_t hang;
+	unsigned engine_id;
+
+	engine_id = gem_class_instance_to_eb_flags(fd, e->class, e->instance);
+	hang = igt_hang_ctx(fd, ctx, engine_id, flags);
+	gem_sync(fd, hang.spin->handle);
+}
+
+static void media_hang_simple(int fd, const struct intel_execution_engine2 *e)
+{
+	uint32_t ctx;
+	unsigned flags = HANG_ALLOW_CAPTURE;
+	struct timeval start, end;
+	double dt_msecs;
+
+	/* Submit on default context */
+	ctx = 0;
+	context_set_watchdog(fd, e, ctx, WATCHDOG_THRESHOLD);
+
+	clear_error_state(fd);
+
+	gettimeofday(&start, NULL);
+	inject_hang(fd, ctx, e, flags);
+	gettimeofday(&end, NULL);
+	dt_msecs = elapsed(&start, &end)/1000;
+
+	/* reset time for watchdog should be less than 2*threshold + engine reset time + submission */
+	igt_assert(dt_msecs < 2*WATCHDOG_THRESHOLD + 15);
+
+	/* Assert if error state is not clean */
+	igt_assert(!check_error_state(fd));
+}
+
+igt_main
+{
+	int fd = -1;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_INTEL);
+		igt_require_gem(fd);
+	}
+
+	for (const struct intel_execution_engine2 *e = intel_execution_engines2; e->name; e++) {
+		igt_subtest_group {
+			igt_fixture {
+				gem_require_engine(fd, e->class, e->instance);
+			}
+
+			/* default exec-id is purely symbolic */
+			if (strcmp(e->name, "bcs0") == 0)
+				continue;
+
+			igt_subtest_f("basic-%s", e->name) {
+				media_hang_simple(fd, e);
+			}
+		}
+	}
+
+	igt_fixture {
+		close(fd);
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index 17deb945ec95..3b864d891a08 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -130,6 +130,7 @@ test_progs = [
 	'gem_unref_active_buffers',
 	'gem_userptr_blits',
 	'gem_wait',
+        'gem_watchdog',
 	'gem_workarounds',
 	'gem_write_read_ring_switch',
 	'gen3_mixed_blits',
-- 
2.7.4



More information about the igt-dev mailing list