From: Eric Anholt <eric@anholt.net>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/2] v3d: Add tests for hanging V3D using an RCL.
Date: Tue, 27 Nov 2018 12:46:03 -0800 [thread overview]
Message-ID: <20181127204603.24042-2-eric@anholt.net> (raw)
In-Reply-To: <20181127204603.24042-1-eric@anholt.net>
drm-misc-next recently regressed GPU hang recovery, and these
reproduce those bugs.
Signed-off-by: Eric Anholt <eric@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@v3d_cl_hang@rcl-infinite-loop
+igt@v3d_cl_hang@bcl-infinite-loop
igt@v3d_get_bo_offset@create-get-offsets
igt@v3d_get_bo_offset@get-bad-handle
igt@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2018-11-27 20:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-27 20:46 [igt-dev] [PATCH i-g-t 1/2] meson: Drop -Wdeclaration-after-statement Eric Anholt
2018-11-27 20:46 ` Eric Anholt [this message]
2018-11-28 11:24 ` [igt-dev] [PATCH i-g-t 2/2] v3d: Add tests for hanging V3D using an RCL Jani Nikula
2018-11-28 22:04 ` Eric Anholt
2018-11-27 23:30 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] meson: Drop -Wdeclaration-after-statement Patchwork
2018-11-28 11:21 ` [igt-dev] [PATCH i-g-t 1/2] " Jani Nikula
2018-11-28 11:48 ` [igt-dev] ✗ Fi.CI.IGT: failure for series starting with [i-g-t,1/2] " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181127204603.24042-2-eric@anholt.net \
--to=eric@anholt.net \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox