[PATCH i-g-t] lib/drmtest: idle all GPUs before test

Kamil Konieczny kamil.konieczny at linux.intel.com
Tue Mar 19 11:19:32 UTC 2024


Until now open function made sure first GPU is idle before test
starts but it did not account for more than one discrete GPU.
Create function for cleaning up state of second and subsequent
GPU and make sure it is done only once per given GPU.

Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski at intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 lib/drmtest.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 52b5a2020..210eb78ae 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -470,6 +470,45 @@ static bool __get_card_for_nth_filter(int idx, struct igt_device_card *card)
 	return false;
 }
 
+static void __reset_gpu(int fd)
+{
+	igt_params_set(fd, "reset", "%u", -1u /* any method */);
+}
+
+static void __drop_gpu_caches(int fd)
+{
+	igt_drop_caches_set(fd,
+			    /* cancel everything */
+			    DROP_RESET_ACTIVE | DROP_RESET_SEQNO |
+			    /* cleanup */
+			    DROP_ACTIVE | DROP_RETIRE | DROP_IDLE | DROP_FREED);
+}
+
+static void __gpu_make_idle(int fd)
+{
+	__reset_gpu(fd);
+
+	if (is_i915_device(fd))
+		__drop_gpu_caches(fd);
+}
+
+/*
+ * Ensure that the driver is idle before starting a test, and make sure
+ * it is done only once per GPU.
+ */
+static void __multigpu_make_idle_once(int fd, inr idx)
+{
+	static int open_count[256]; /* max card size + max renderD size */
+
+	igt_assert_lte(0, idx);
+	igt_assert_lt(idx, ARRAY_SIZE(open_count));
+	if (fd < 0)
+		return;
+
+	if (__sync_fetch_and_add(&open_count[idx], 1) == 0)
+		__gpu_make_idle(fd);
+}
+
 /**
  * __drm_open_driver_another:
  * @idx: index of the device you are opening
@@ -558,6 +597,8 @@ int __drm_open_driver_another(int idx, int chipset)
 		/* Cache xe_device struct. */
 		if (is_xe_device(fd))
 			xe_device_get(fd);
+
+		__multigpu_make_idle_once(fd, idx);
 	}
 
 	return fd;
-- 
2.42.0



More information about the igt-dev mailing list