intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH igt] lib: Avoid actually throttling from igt_require_gem()
@ 2017-08-18 10:46 Chris Wilson
  2017-08-18 10:51 ` Chris Wilson
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Chris Wilson @ 2017-08-18 10:46 UTC (permalink / raw)
  To: intel-gfx

igt_require_gem() checks whether we can use the i915 fd for submitting
requests by detecting a wedged driver. It was intended to be used just
after opening DRIVER_INTEL for a gem test to provide an early skip if
the device was unusable. However, it is also used at the start of
library functions like igt_spin_batch_new() which may be called after
the test has setup some state, and importantly submitted some batches.
igt_require_gem() has the risk of then waiting on those batches, unless
we tell it to use a clean fd.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
 lib/drmtest.c        | 37 +++++++++++++++++++++++++++++++++++++
 lib/ioctl_wrappers.c |  8 ++++++++
 2 files changed, 45 insertions(+)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 158af682..0f8bd604 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -318,6 +318,43 @@ static int __drm_open_driver_render(int chipset)
 	return fd;
 }
 
+int __drm_reopen_driver(int fd)
+{
+	struct stat target;
+	const char *base;
+	int offset;
+
+	if (fstat(fd, &target))
+		return -errno;
+
+	if (target.st_rdev & 0x80) { /* render node */
+		base = "/dev/dri/renderD%d";
+		offset = 0x80;
+	} else {
+		base = "/dev/dri/card%d";
+		offset = 0;
+	}
+
+	for (int i = 0; i < 16; i++) {
+		struct stat st;
+		char buf[256];
+
+		snprintf(buf, sizeof(buf), base, i + offset);
+		fd = open(buf, O_RDWR);
+		if (fd < 0)
+			continue;
+
+		if (fstat(fd, &st) == 0 &&
+		    st.st_mode == target.st_mode &&
+		    st.st_rdev == target.st_rdev)
+			return fd;
+
+		close(fd);
+	}
+
+	return -ENOENT;
+}
+
 static int at_exit_drm_fd = -1;
 static int at_exit_drm_render_fd = -1;
 
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 51000bac..948b8f0c 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1602,9 +1602,17 @@ void igt_require_gem(int fd)
 
 	igt_require_intel(fd);
 
+	/* We only want to use the throttle-ioctl for its -EIO reporting
+	 * of a wedged device, not for actually waiting on outstanding
+	 * requests! So create a new drm_file for the device that is clean.
+	 */
+	fd = __drm_reopen_driver(fd);
+	igt_assert_lte(0, fd);
+
 	err = 0;
 	if (ioctl(fd, DRM_IOCTL_I915_GEM_THROTTLE))
 		err = -errno;
+	close(fd);
 
 	igt_require_f(err == 0, "Unresponsive i915/GEM device\n");
 }
-- 
2.14.1

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

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

end of thread, other threads:[~2017-08-25 18:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-18 10:46 [PATCH igt] lib: Avoid actually throttling from igt_require_gem() Chris Wilson
2017-08-18 10:51 ` Chris Wilson
2017-08-18 10:53 ` Chris Wilson
2017-08-18 11:46   ` Michal Wajdeczko
2017-08-18 13:04     ` Michał Winiarski
2017-08-18 12:52   ` Michał Winiarski
2017-08-18 13:05 ` ✗ Fi.CI.BAT: failure for " Patchwork
2017-08-24 12:42 ` [PATCH igt v2] " Chris Wilson
2017-08-24 13:08   ` Michał Winiarski
2017-08-24 13:09   ` Fiedorowicz, Lukasz
2017-08-24 13:22 ` ✗ Fi.CI.BAT: failure for lib: Avoid actually throttling from igt_require_gem() (rev2) Patchwork
2017-08-25 17:11   ` Daniel Vetter
2017-08-25 17:39     ` Chris Wilson
2017-08-25 18:45       ` Daniel Vetter

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).