[igt-dev] [PATCH i-g-t 2/2] v3d: Add tests for hanging V3D using an RCL.

Eric Anholt eric at anholt.net
Tue Nov 27 20:46:03 UTC 2018


drm-misc-next recently regressed GPU hang recovery, and these
reproduce those bugs.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 lib/igt_v3d.c             | 126 ++++++++++++++++++++++++++++++++++++++
 lib/igt_v3d.h             |  38 ++++++++++++
 tests/meson.build         |   1 +
 tests/v3d_ci/v3d.testlist |   2 +
 tests/v3d_cl_hang.c       |  73 ++++++++++++++++++++++
 5 files changed, 240 insertions(+)
 create mode 100644 tests/v3d_cl_hang.c

diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c
index 619c072c0e47..9a9f32e0ced4 100644
--- a/lib/igt_v3d.c
+++ b/lib/igt_v3d.c
@@ -124,3 +124,129 @@ void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo)
 				  PROT_READ | PROT_WRITE);
 	igt_assert(bo->map);
 }
+
+void *
+igt_v3d_wait_bo(int fd, uint32_t handle)
+{
+	struct drm_v3d_wait_bo wait_bo = {
+		.handle = handle,
+		.timeout_ns = ~0ull,
+	};
+
+	do_ioctl(fd, DRM_IOCTL_V3D_WAIT_BO, &wait_bo);
+
+	return 0;
+}
+
+void igt_v3d_bo_wait(int fd, struct v3d_bo *bo)
+{
+	igt_v3d_wait_bo(fd, bo->handle);
+}
+
+struct v3d_cl *
+igt_v3d_cl_create(int fd, size_t size)
+{
+	struct v3d_cl *cl = calloc(1, sizeof(*cl));
+
+	cl->fd = fd;
+	cl->bo = igt_v3d_create_bo(fd, size);
+	v3d_cl_reference_bo(cl, cl->bo);
+
+	igt_v3d_bo_mmap(fd, cl->bo);
+	cl->next = cl->bo->map;
+
+	return cl;
+}
+
+/** Creates a simple CL consisting of a single NOP instruction. */
+struct v3d_cl *
+igt_v3d_cl_create_nop(int fd)
+{
+	struct v3d_cl *cl = igt_v3d_cl_create(fd, 1);
+        uint8_t nop_opcode = 1;
+
+	memcpy(cl->next, &nop_opcode, 1);
+	cl->next++;
+
+	return cl;
+}
+
+/**
+ * Creates a simple CL consisting of an infinite loop branching to itself.
+ */
+struct v3d_cl *
+igt_v3d_cl_create_infinite_loop(int fd)
+{
+	struct v3d_cl *cl = igt_v3d_cl_create(fd, 5);
+        uint8_t branch_opcode = 16;
+
+	memcpy(cl->next, &branch_opcode, 1);
+	cl->next++;
+
+	memcpy(cl->next, &cl->bo->offset, 4);
+	cl->next += 4;
+
+	return cl;
+}
+
+void
+igt_v3d_cl_free(struct v3d_cl *cl)
+{
+	igt_v3d_free_bo(cl->fd, cl->bo);
+	free(cl);
+}
+
+void
+igt_v3d_submit_cl(int fd, struct drm_v3d_submit_cl *submit)
+{
+	do_ioctl(fd, DRM_IOCTL_V3D_SUBMIT_CL, submit);
+}
+
+void
+igt_v3d_submit_rcl(struct v3d_cl *rcl)
+{
+	struct drm_v3d_submit_cl submit = {
+		.rcl_start = rcl->bo->offset,
+		.rcl_end = rcl->bo->offset + cl_offset(rcl),
+		.bo_handles = (uintptr_t)rcl->handles,
+		.bo_handle_count = rcl->handle_count,
+	};
+	igt_v3d_submit_cl(rcl->fd, &submit);
+}
+
+static bool
+handle_in_list(uint32_t *handles, int handle_count, int handle)
+{
+	for (int i = 0; i < handle_count; i++) {
+		if (handles[i] == handle)
+			return true;
+	}
+	return false;
+}
+
+void
+igt_v3d_submit_bcl_and_rcl(struct v3d_cl *bcl, struct v3d_cl *rcl)
+{
+	uint32_t handles[32];
+	int handle_count = 0;
+
+	/* Merge the two incoming handle lists. */
+	igt_assert(rcl->handle_count + bcl->handle_count <= ARRAY_SIZE(handles));
+	for (int i = 0; i < rcl->handle_count; i++)
+		handles[handle_count++] = rcl->handles[i];
+
+	for (int i = 0; i < bcl->handle_count; i++) {
+		if (!handle_in_list(handles, handle_count, bcl->handles[i]))
+			handles[handle_count++] = bcl->handles[i];
+	}
+
+	struct drm_v3d_submit_cl submit = {
+		.rcl_start = rcl->bo->offset,
+		.rcl_end = rcl->bo->offset + cl_offset(rcl),
+		.bcl_start = bcl->bo->offset,
+		.bcl_end = bcl->bo->offset + cl_offset(bcl),
+		.bo_handles = (uintptr_t)handles,
+		.bo_handle_count = handle_count,
+	};
+	igt_v3d_submit_cl(rcl->fd, &submit);
+}
diff --git a/lib/igt_v3d.h b/lib/igt_v3d.h
index 2042995103cc..7ddbee36a547 100644
--- a/lib/igt_v3d.h
+++ b/lib/igt_v3d.h
@@ -33,6 +33,15 @@ struct v3d_bo {
 	void *map;
 };
 
+struct v3d_cl {
+	int fd;
+	struct v3d_bo *bo;
+	void *next;
+
+	uint32_t handles[32];
+	uint32_t handle_count;
+};
+
 struct v3d_bo *igt_v3d_create_bo(int fd, size_t size);
 void igt_v3d_free_bo(int fd, struct v3d_bo *bo);
 
@@ -40,7 +49,36 @@ void igt_v3d_free_bo(int fd, struct v3d_bo *bo);
 uint32_t igt_v3d_get_bo_offset(int fd, uint32_t handle);
 uint32_t igt_v3d_get_param(int fd, enum drm_v3d_param param);
 void *igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot);
+void *igt_v3d_wait_bo(int fd, uint32_t handle);
+void igt_v3d_submit_cl(int fd, struct drm_v3d_submit_cl *submit);
+void igt_v3d_submit_rcl(struct v3d_cl *rcl);
+void igt_v3d_submit_bcl_and_rcl(struct v3d_cl *bcl, struct v3d_cl *rcl);
 
 void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo);
+void igt_v3d_bo_wait(int fd, struct v3d_bo *bo);
+
+static inline void v3d_cl_reference_bo(struct v3d_cl *cl,
+				       const struct v3d_bo *bo)
+{
+	if (!bo)
+		return;
+
+	for (int i = 0; i < cl->handle_count; i++) {
+		if (cl->handles[i] == bo->handle)
+			return;
+	}
+
+	cl->handles[cl->handle_count++] = bo->handle;
+}
+
+static inline uint32_t cl_offset(struct v3d_cl *cl)
+{
+	return (char *)cl->next - (char *)cl->bo->map;
+}
+
+struct v3d_cl *igt_v3d_cl_create(int fd, size_t size);
+struct v3d_cl *igt_v3d_cl_create_infinite_loop(int fd);
+struct v3d_cl *igt_v3d_cl_create_nop(int fd);
+void igt_v3d_cl_free(struct v3d_cl *cl);
 
 #endif /* IGT_V3D_H */
diff --git a/tests/meson.build b/tests/meson.build
index b8a6e61b3404..92c9e14ca40a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -82,6 +82,7 @@ test_progs = [
 	'v3d_get_bo_offset',
 	'v3d_get_param',
 	'v3d_mmap',
+	'v3d_cl_hang',
 	'vc4_create_bo',
 	'vc4_dmabuf_poll',
 	'vc4_label_bo',
diff --git a/tests/v3d_ci/v3d.testlist b/tests/v3d_ci/v3d.testlist
index b55e8e571d7d..bf625f788f79 100644
--- a/tests/v3d_ci/v3d.testlist
+++ b/tests/v3d_ci/v3d.testlist
@@ -1,3 +1,5 @@
+igt at v3d_cl_hang@rcl-infinite-loop
+igt at v3d_cl_hang@bcl-infinite-loop
 igt at v3d_get_bo_offset@create-get-offsets
 igt at v3d_get_bo_offset@get-bad-handle
 igt at v3d_get_param@base-params
diff --git a/tests/v3d_cl_hang.c b/tests/v3d_cl_hang.c
new file mode 100644
index 000000000000..6ecc337c2432
--- /dev/null
+++ b/tests/v3d_cl_hang.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2016 Broadcom
+ *
+ * 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_v3d.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "v3d_drm.h"
+
+igt_main
+{
+	int fd;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_V3D);
+	}
+
+	igt_subtest("rcl-infinite-loop") {
+		struct v3d_cl *hang = igt_v3d_cl_create_infinite_loop(fd);
+		struct v3d_cl *nop = igt_v3d_cl_create_nop(fd);
+
+		igt_v3d_submit_rcl(hang);
+
+		igt_v3d_submit_rcl(nop);
+		igt_v3d_bo_wait(fd, nop->bo);
+
+		igt_v3d_cl_free(hang);
+		igt_v3d_cl_free(nop);
+	}
+
+	igt_subtest("bcl-infinite-loop") {
+		struct v3d_cl *hang = igt_v3d_cl_create_infinite_loop(fd);
+		struct v3d_cl *nop = igt_v3d_cl_create_nop(fd);
+
+		igt_v3d_submit_bcl_and_rcl(hang, nop);
+
+		igt_v3d_submit_rcl(nop);
+		igt_v3d_bo_wait(fd, nop->bo);
+
+		igt_v3d_cl_free(hang);
+		igt_v3d_cl_free(nop);
+	}
+
+	igt_fixture
+		close(fd);
+}
-- 
2.20.0.rc1



More information about the igt-dev mailing list