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

Eric Anholt eric at anholt.net
Thu Nov 15 18:57:37 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 +
 lib/igt_v3d.h => tests/v3d_cl_hang.c |  61 +++++++++----
 5 files changed, 211 insertions(+), 17 deletions(-)
 copy lib/igt_v3d.h => tests/v3d_cl_hang.c (56%)

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 4472536aef65..ec8ad1421b61 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -88,6 +88,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/lib/igt_v3d.h b/tests/v3d_cl_hang.c
similarity index 56%
copy from lib/igt_v3d.h
copy to tests/v3d_cl_hang.c
index 2042995103cc..6ecc337c2432 100644
--- a/lib/igt_v3d.h
+++ b/tests/v3d_cl_hang.c
@@ -21,26 +21,53 @@
  * IN THE SOFTWARE.
  */
 
-#ifndef IGT_V3D_H
-#define IGT_V3D_H
-
+#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"
 
-struct v3d_bo {
-	int handle;
-	uint32_t offset;
-	uint32_t size;
-	void *map;
-};
+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);
 
-struct v3d_bo *igt_v3d_create_bo(int fd, size_t size);
-void igt_v3d_free_bo(int fd, struct v3d_bo *bo);
+		igt_v3d_submit_bcl_and_rcl(hang, nop);
 
-/* IOCTL wrappers */
-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);
+		igt_v3d_submit_rcl(nop);
+		igt_v3d_bo_wait(fd, nop->bo);
 
-void igt_v3d_bo_mmap(int fd, struct v3d_bo *bo);
+		igt_v3d_cl_free(hang);
+		igt_v3d_cl_free(nop);
+	}
 
-#endif /* IGT_V3D_H */
+	igt_fixture
+		close(fd);
+}
-- 
2.19.1



More information about the igt-dev mailing list