[Intel-gfx] [PATCH i-g-t v2 1/4] lib: Extract helpers for determining submission method

Michał Winiarski michal.winiarski at intel.com
Mon Oct 16 09:05:14 UTC 2017


Couple of tests are using either determining submission method, or
pretty printing. Let's move those to helpers in lib.

v2: s/igt_show/gem_show

Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Katarzyna Dec <katarzyna.dec at intel.com>
Cc: Petri Latvala <petri.latvala at intel.com>
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
Reviewed-by: Katarzyna Dec <katarzyna.dec at intel.com>
Acked-by: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
 lib/igt_aux.c               | 18 +++++++++++++
 lib/igt_aux.h               |  2 ++
 lib/igt_gt.c                | 63 +++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_gt.h                |  7 +++++
 tests/gem_ctx_thrash.c      | 19 ++------------
 tests/gem_eio.c             | 45 ++------------------------------
 tests/gem_exec_await.c      | 39 ++--------------------------
 tests/gem_exec_fence.c      | 41 +++--------------------------
 tests/gem_exec_latency.c    | 31 +---------------------
 tests/gem_exec_nop.c        | 31 +---------------------
 tests/gem_exec_schedule.c   | 40 ++--------------------------
 tests/gem_exec_whisper.c    | 31 +---------------------
 tests/gem_read_read_speed.c | 17 +-----------
 tests/gem_sync.c            | 31 +---------------------
 14 files changed, 106 insertions(+), 309 deletions(-)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index fa6594c3..cacc8f98 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1455,6 +1455,24 @@ igt_show_stat(proc_t *info, int *state, const char *fn)
 	++*state;
 }
 
+void gem_show_submission_method(int fd)
+{
+	const unsigned flags = gem_submission_method(fd);
+
+	if (flags & GEM_SUBMISSION_GUC) {
+		igt_info("Using GuC submission\n");
+		return;
+	}
+
+	if (flags & GEM_SUBMISSION_EXECLISTS) {
+		igt_info("Using Execlists submission\n");
+		return;
+	}
+
+	igt_info("Using Legacy submission%s\n",
+		 flags & GEM_SUBMISSION_SEMAPHORES ? ", with semaphores" : "");
+}
+
 static void
 __igt_lsof_fds(proc_t *proc_info, int *state, char *proc_path, const char *dir)
 {
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 499a1679..1fdb2259 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -278,6 +278,8 @@ void igt_unlock_mem(void);
 	ret_;								\
 })
 
+void gem_show_submission_method(int fd);
+
 struct igt_mean;
 void igt_start_siglatency(int sig); /* 0 => SIGRTMIN (default) */
 double igt_stop_siglatency(struct igt_mean *result);
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index b3f3b380..de38656a 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -568,3 +568,66 @@ bool gem_can_store_dword(int fd, unsigned int engine)
 
 	return true;
 }
+
+/**
+ * gem_submission_method:
+ * @fd: open i915 drm file descriptor
+ *
+ * Returns: Submission method bitmap.
+ */
+unsigned gem_submission_method(int fd)
+{
+	unsigned flags = 0;
+	bool active;
+	int dir;
+
+	dir = igt_sysfs_open_parameters(fd);
+	if (dir < 0)
+		return 0;
+
+	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
+	if (active) {
+		flags |= GEM_SUBMISSION_GUC | GEM_SUBMISSION_EXECLISTS;
+		goto out;
+	}
+
+	active = igt_sysfs_get_boolean(dir, "enable_execlists");
+	if (active) {
+		flags |= GEM_SUBMISSION_EXECLISTS;
+		goto out;
+	}
+
+	active = igt_sysfs_get_boolean(dir, "semaphores");
+	if (active) {
+		flags |= GEM_SUBMISSION_SEMAPHORES;
+	}
+
+out:
+	close(dir);
+	return flags;
+}
+
+
+/**
+ * gem_has_semaphores:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether the driver is using semaphores for
+ * synchronization between engines.
+ */
+bool gem_has_semaphores(int fd)
+{
+	return gem_submission_method(fd) & GEM_SUBMISSION_SEMAPHORES;
+}
+
+/**
+ * gem_has_execlists:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether the driver is using execlists as a
+ * hardware submission method.
+ */
+bool gem_has_execlists(int fd)
+{
+	return gem_submission_method(fd) & GEM_SUBMISSION_EXECLISTS;
+}
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index 2579cbd3..6b8f78eb 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -80,4 +80,11 @@ extern const struct intel_execution_engine {
 
 bool gem_can_store_dword(int fd, unsigned int engine);
 
+#define GEM_SUBMISSION_SEMAPHORES	(1 << 0)
+#define GEM_SUBMISSION_EXECLISTS	(1 << 1)
+#define GEM_SUBMISSION_GUC		(1 << 2)
+unsigned gem_submission_method(int fd);
+bool gem_has_semaphores(int fd);
+bool gem_has_execlists(int fd);
+
 #endif /* IGT_GT_H */
diff --git a/tests/gem_ctx_thrash.c b/tests/gem_ctx_thrash.c
index f79a1f4f..c0740b9f 100644
--- a/tests/gem_ctx_thrash.c
+++ b/tests/gem_ctx_thrash.c
@@ -42,21 +42,6 @@ static void xchg_int(void *array, unsigned i, unsigned j)
 	igt_swap(A[i], A[j]);
 }
 
-static bool has_execlists(int fd)
-{
-	bool enabled = false;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return false;
-
-	enabled = igt_sysfs_get_boolean(dir, "enable_execlists");
-	close(dir);
-
-	return enabled;
-}
-
 static unsigned context_size(int fd)
 {
 	const int gen = intel_gen(intel_get_drm_devid(fd));
@@ -86,7 +71,7 @@ static unsigned get_num_contexts(int fd, int num_engines)
 	ggtt_size = gem_global_aperture_size(fd);
 
 	size = context_size(fd);
-	if (has_execlists(fd)) {
+	if (gem_has_execlists(fd)) {
 		size += 4 << 12; /* ringbuffer as well */
 		if (num_engines) /* one per engine with execlists */
 			size *= num_engines;
@@ -95,7 +80,7 @@ static unsigned get_num_contexts(int fd, int num_engines)
 	count = 3 * (ggtt_size / size) / 2;
 	igt_info("Creating %lld contexts (assuming of size %lld%s)\n",
 		 (long long)count, (long long)size,
-		 has_execlists(fd) ? " with execlists" : "");
+		 gem_has_execlists(fd) ? " with execlists" : "");
 
 	intel_require_memory(count, size, CHECK_RAM | CHECK_SWAP);
 	return count;
diff --git a/tests/gem_eio.c b/tests/gem_eio.c
index 899cb627..c30212f4 100644
--- a/tests/gem_eio.c
+++ b/tests/gem_eio.c
@@ -411,45 +411,6 @@ static void test_inflight_internal(int fd)
 	trigger_reset(fd);
 }
 
-#define HAVE_EXECLISTS 0x1
-#define HAVE_GUC 0x2
-#define HAVE_SEMAPHORES 0x4
-
-static unsigned print_welcome(int fd)
-{
-	unsigned flags = 0;
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return 0;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		flags |= HAVE_GUC | HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		flags |= HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	if (active)
-		flags |= HAVE_SEMAPHORES;
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-	return flags;
-}
-
 static int fd = -1;
 
 static void
@@ -461,8 +422,6 @@ exit_handler(int sig)
 
 igt_main
 {
-	unsigned int caps = 0;
-
 	igt_skip_on_simulation();
 
 	igt_fixture {
@@ -472,7 +431,7 @@ igt_main
 		igt_force_gpu_reset(fd);
 		igt_install_exit_handler(exit_handler);
 
-		caps = print_welcome(fd);
+		gem_show_submission_method(fd);
 		igt_require_gem(fd);
 		igt_require_hang_ring(fd, I915_EXEC_DEFAULT);
 	}
@@ -496,7 +455,7 @@ igt_main
 		test_inflight_external(fd);
 
 	igt_subtest("in-flight-internal") {
-		igt_skip_on(caps & HAVE_SEMAPHORES);
+		igt_skip_on(gem_has_semaphores(fd));
 		test_inflight_internal(fd);
 	}
 
diff --git a/tests/gem_exec_await.c b/tests/gem_exec_await.c
index fb5c0f30..326783a1 100644
--- a/tests/gem_exec_await.c
+++ b/tests/gem_exec_await.c
@@ -246,40 +246,6 @@ static void wide(int fd, int ring_size, int timeout, unsigned int flags)
 	free(exec);
 }
 
-#define HAVE_EXECLISTS 0x1
-static unsigned int print_welcome(int fd)
-{
-	unsigned int result = 0;
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return 0;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		result |= HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		result |= HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-	return result;
-}
-
 struct cork {
 	int device;
 	uint32_t handle;
@@ -374,14 +340,13 @@ igt_main
 	int device = -1;
 
 	igt_fixture {
-		unsigned int caps;
 
 		device = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(device);
-		caps = print_welcome(device);
+		gem_show_submission_method(device);
 
 		ring_size = measure_ring_size(device) - 10;
-		if (!(caps & HAVE_EXECLISTS))
+		if (!gem_has_execlists(device))
 			ring_size /= 2;
 		igt_info("Ring size: %d batches\n", ring_size);
 		igt_require(ring_size > 0);
diff --git a/tests/gem_exec_fence.c b/tests/gem_exec_fence.c
index 477386b4..ae3760c9 100644
--- a/tests/gem_exec_fence.c
+++ b/tests/gem_exec_fence.c
@@ -692,40 +692,6 @@ static void test_fence_flip(int i915)
 	igt_skip_on_f(1, "no fence-in for atomic flips\n");
 }
 
-#define HAVE_EXECLISTS 0x1
-static unsigned int print_welcome(int fd)
-{
-	unsigned int result = 0;
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return 0;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		result |= HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		result |= HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-	return result;
-}
-
 static bool has_submit_fence(int fd)
 {
 	struct drm_i915_getparam gp;
@@ -1458,7 +1424,6 @@ static void test_syncobj_channel(int fd)
 igt_main
 {
 	const struct intel_execution_engine *e;
-	unsigned int caps = 0;
 	int i915 = -1;
 
 	igt_skip_on_simulation();
@@ -1469,7 +1434,7 @@ igt_main
 		igt_require(gem_has_exec_fence(i915));
 		gem_require_mmap_wc(i915);
 
-		caps = print_welcome(i915);
+		gem_show_submission_method(i915);
 	}
 
 	for (e = intel_execution_engines; e->name; e++) {
@@ -1541,7 +1506,7 @@ igt_main
 		igt_info("Ring size: %ld batches\n", ring_size);
 		igt_require(ring_size);
 
-		test_long_history(i915, ring_size, caps);
+		test_long_history(i915, ring_size, 0);
 	}
 
 	igt_subtest("expired-history") {
@@ -1550,7 +1515,7 @@ igt_main
 		igt_info("Ring size: %ld batches\n", ring_size);
 		igt_require(ring_size);
 
-		test_long_history(i915, ring_size, caps | EXPIRED);
+		test_long_history(i915, ring_size, EXPIRED);
 	}
 
 	igt_subtest("flip") {
diff --git a/tests/gem_exec_latency.c b/tests/gem_exec_latency.c
index f86dfcb5..a942c205 100644
--- a/tests/gem_exec_latency.c
+++ b/tests/gem_exec_latency.c
@@ -407,35 +407,6 @@ static void latency_from_ring(int fd,
 	gem_close(fd, obj[2].handle);
 }
 
-static void print_welcome(int fd)
-{
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-}
-
 igt_main
 {
 	const struct intel_execution_engine *e;
@@ -446,7 +417,7 @@ igt_main
 		igt_require_gem(device);
 		gem_require_mmap_wc(device);
 
-		print_welcome(device);
+		gem_show_submission_method(device);
 
 		ring_size = measure_ring_size(device);
 		igt_info("Ring size: %d batches\n", ring_size);
diff --git a/tests/gem_exec_nop.c b/tests/gem_exec_nop.c
index 0af64557..feb89ee3 100644
--- a/tests/gem_exec_nop.c
+++ b/tests/gem_exec_nop.c
@@ -665,35 +665,6 @@ static void preempt(int fd, uint32_t handle,
 		 ring_name, count, elapsed(&start, &now)*1e6 / count);
 }
 
-static void print_welcome(int fd)
-{
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-}
-
 static unsigned int has_scheduler(int fd)
 {
 	drm_i915_getparam_t gp;
@@ -727,7 +698,7 @@ igt_main
 
 		device = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(device);
-		print_welcome(device);
+		gem_show_submission_method(device);
 		sched_caps = has_scheduler(device);
 
 		handle = gem_create(device, 4096);
diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c
index ad3688cf..f5c849d0 100644
--- a/tests/gem_exec_schedule.c
+++ b/tests/gem_exec_schedule.c
@@ -1000,45 +1000,9 @@ static unsigned int has_scheduler(int fd)
 	return caps;
 }
 
-#define HAVE_EXECLISTS 0x1
-#define HAVE_GUC 0x2
-static unsigned print_welcome(int fd)
-{
-	unsigned flags = 0;
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return 0;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		flags |= HAVE_GUC | HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		flags |= HAVE_EXECLISTS;
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-	return flags;
-}
-
 igt_main
 {
 	const struct intel_execution_engine *e;
-	unsigned int exec_caps = 0;
 	unsigned int sched_caps = 0;
 	int fd = -1;
 
@@ -1046,7 +1010,7 @@ igt_main
 
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_INTEL);
-		exec_caps = print_welcome(fd);
+		gem_show_submission_method(fd);
 		sched_caps = has_scheduler(fd);
 		igt_require_gem(fd);
 		gem_require_mmap_wc(fd);
@@ -1135,7 +1099,7 @@ igt_main
 			ctx_has_priority(fd);
 
 			/* need separate rings */
-			igt_require(exec_caps & HAVE_EXECLISTS);
+			igt_require(gem_has_execlists(fd));
 		}
 
 		for (e = intel_execution_engines; e->name; e++) {
diff --git a/tests/gem_exec_whisper.c b/tests/gem_exec_whisper.c
index 15989616..e7f7b1f1 100644
--- a/tests/gem_exec_whisper.c
+++ b/tests/gem_exec_whisper.c
@@ -552,35 +552,6 @@ static void whisper(int fd, unsigned engine, unsigned flags)
 	close(debugfs);
 }
 
-static void print_welcome(int fd)
-{
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission%s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-}
-
 igt_main
 {
 	const struct mode {
@@ -615,7 +586,7 @@ igt_main
 		fd = drm_open_driver_master(DRIVER_INTEL);
 		igt_require_gem(fd);
 		igt_require(gem_can_store_dword(fd, 0));
-		print_welcome(fd);
+		gem_show_submission_method(fd);
 
 		igt_fork_hang_detector(fd);
 	}
diff --git a/tests/gem_read_read_speed.c b/tests/gem_read_read_speed.c
index c1d30f24..bbd8e54e 100644
--- a/tests/gem_read_read_speed.c
+++ b/tests/gem_read_read_speed.c
@@ -49,21 +49,6 @@ igt_render_copyfunc_t rendercopy;
 struct intel_batchbuffer *batch;
 int width, height;
 
-static int semaphores_enabled(int fd)
-{
-	bool enabled = false;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return false;
-
-	enabled = igt_sysfs_get_boolean(dir, "semaphores");
-	close(dir);
-
-	return enabled;
-}
-
 static drm_intel_bo *rcs_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
 {
 	struct igt_buf d = {
@@ -212,7 +197,7 @@ igt_main
 
 		batch =  intel_batchbuffer_alloc(bufmgr, devid);
 
-		igt_info("Semaphores: %d\n", semaphores_enabled(fd));
+		gem_show_submission_method(fd);
 	}
 
 	for (i = 0; sizes[i] != 0; i++) {
diff --git a/tests/gem_sync.c b/tests/gem_sync.c
index c9e2f014..f0c5d76f 100644
--- a/tests/gem_sync.c
+++ b/tests/gem_sync.c
@@ -807,35 +807,6 @@ preempt(int fd, unsigned ring, int num_children, int timeout)
 	gem_context_destroy(fd, ctx[0]);
 }
 
-static void print_welcome(int fd)
-{
-	bool active;
-	int dir;
-
-	dir = igt_sysfs_open_parameters(fd);
-	if (dir < 0)
-		return;
-
-	active = igt_sysfs_get_boolean(dir, "enable_guc_submission");
-	if (active) {
-		igt_info("Using GuC submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "enable_execlists");
-	if (active) {
-		igt_info("Using Execlists submission\n");
-		goto out;
-	}
-
-	active = igt_sysfs_get_boolean(dir, "semaphores");
-	igt_info("Using Legacy submission %s\n",
-		 active ? ", with semaphores" : "");
-
-out:
-	close(dir);
-}
-
 static unsigned int has_scheduler(int fd)
 {
 	drm_i915_getparam_t gp;
@@ -869,7 +840,7 @@ igt_main
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
-		print_welcome(fd);
+		gem_show_submission_method(fd);
 		sched_caps = has_scheduler(fd);
 
 		igt_fork_hang_detector(fd);
-- 
2.13.5



More information about the Intel-gfx mailing list