[igt-dev] [PATCH i-g-t] lib/igt_dummyload: Helper to spin till a specified timeout

Ashutosh Dixit ashutosh.dixit at intel.com
Thu May 30 05:26:41 UTC 2019


From: "Dixit, Ashutosh" <ashutosh.dixit at intel.com>

Even though similar functionality exists in other tests, perhaps there
is value in having a helper function which generates an artificial
load on an engine by spinning on it for a specified time.

Signed-off-by: Ashutosh Dixit <ashutosh.dixit at intel.com>
---
 lib/igt_dummyload.c         | 23 +++++++++++++++++++++++
 lib/igt_dummyload.h         |  1 +
 tests/i915/gem_spin_batch.c | 17 +++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 0e06276a..7a2e5f4d 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -473,6 +473,29 @@ void igt_unshare_spins(void)
 	igt_list_init(&spin_list);
 }
 
+/**
+ * igt_spin_timeout:
+ * @fd: open i915 drm file descriptor
+ * @opts: controlling options such as context, engine, dependencies etc
+ * @ns: timeout in nano seconds
+ *
+ * Generate an artificial load on an engine by spinning for a specified
+ * timeout.
+ */
+int igt_spin_timeout(int fd, const struct igt_spin_factory *opts, int64_t ns)
+{
+       igt_spin_t *spin;
+
+       spin = igt_spin_factory(fd, opts);
+       if (!spin)
+	       return -EINVAL;
+
+       igt_spin_set_timeout(spin, ns);
+       gem_sync(fd, spin->handle);
+       igt_spin_free(fd, spin);
+       return 0;
+}
+
 static uint32_t plug_vgem_handle(struct igt_cork *cork, int fd)
 {
 	struct vgem_bo bo;
diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h
index bb25751a..b3cf2124 100644
--- a/lib/igt_dummyload.h
+++ b/lib/igt_dummyload.h
@@ -94,6 +94,7 @@ static inline void igt_spin_busywait_until_started(igt_spin_t *spin)
 
 void igt_terminate_spins(void);
 void igt_unshare_spins(void);
+int igt_spin_timeout(int fd, const struct igt_spin_factory *opts, int64_t nsec);
 
 enum igt_cork_type {
 	CORK_SYNC_FD = 1,
diff --git a/tests/i915/gem_spin_batch.c b/tests/i915/gem_spin_batch.c
index 3b4f9073..3b050ad0 100644
--- a/tests/i915/gem_spin_batch.c
+++ b/tests/i915/gem_spin_batch.c
@@ -32,6 +32,20 @@
 		     "'%s' != '%s' (%lld not within %d%% tolerance of %lld)\n",\
 		     #x, #ref, (long long)x, tolerance, (long long)ref)
 
+static void spin_timeout_all_engines(int fd, unsigned int sec)
+{
+	unsigned engine;
+
+	for_each_physical_engine(fd, engine) {
+		struct igt_spin_factory opts = { .engine = engine };
+
+		igt_fork(child, 1)
+			igt_spin_timeout(fd, &opts, sec * NSEC_PER_SEC);
+	}
+
+	igt_waitchildren();
+}
+
 static void spin(int fd, unsigned int engine, unsigned int timeout_sec)
 {
 	const uint64_t timeout_100ms = 100000000LL;
@@ -162,6 +176,9 @@ igt_main
 	igt_subtest("spin-each")
 		spin_on_all_engines(fd, 3);
 
+	igt_subtest("spin-timeout")
+		spin_timeout_all_engines(fd, 1);
+
 	igt_fixture {
 		igt_stop_hang_detector();
 		close(fd);
-- 
2.21.0



More information about the igt-dev mailing list