[PATCH i-g-t v12 4/6] lib/igt_multigpu: Add igt_foreach_gpu_chip

Kamil Konieczny kamil.konieczny at linux.intel.com
Wed Mar 13 19:29:43 UTC 2024


Create two macros for testing drm driver in multigpu scenarios,
first igt_foreach_gpu_chip which will work with one or more GPUs
and second igt_foreach_multigpu_chip which will require two or
more GPUs.

v2: corrected description (Kamil), rebased on corrected patches
  after Dominik review
v3: corrected descriptions, renamed function to print_gpus
  and did small refactoring (Kamil)
  fixed typo in function name (Dominik)
v4: fixed typos (Dominik)
v10: rename new macro into multi_fork_foreach_gpu_chip (Zbigniew)
v12: correct description, remove non-needed '/', moved skip to
 place where it is done, removed assert which prohibits macro to
 work for only one GPU, shorten macro name and create two
 variants of it (Janusz)

Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski at intel.com>
Cc: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
Reviewed-by: "Dominik Karol Piątkowski" <dominik.karol.piatkowski at intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 lib/igt_multigpu.c | 51 +++++++++++++++++++++++++++++++++++++++++++++-
 lib/igt_multigpu.h | 15 ++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/lib/igt_multigpu.c b/lib/igt_multigpu.c
index 9750ffda4..19f1cc7f8 100644
--- a/lib/igt_multigpu.c
+++ b/lib/igt_multigpu.c
@@ -78,9 +78,58 @@ int multigpu_open_another(int idx, unsigned int chipset)
 	int fd;
 
 	fd = drm_open_driver_another(idx, chipset);
-
 	if (chipset == DRIVER_INTEL)
 		igt_require_gem(fd);
 
 	return fd;
 }
+
+/**
+ * multigpu_acquire_view:
+ * @gpus_wanted: minimum number of GPUs required
+ * @chipset: chipset, e.g. DRIVER_XE or DRIVER_INTEL
+ *
+ * Function prepares filtered view for GPU cards with given chipset.
+ * On error skips and prints available GPUs found on PCI bus.
+ * Returns: number of GPUs found
+ */
+int multigpu_acquire_view(int gpus_wanted, unsigned int chipset)
+{
+	int gpu_count = drm_prepare_filtered_multigpu(chipset);
+	int num;
+
+	igt_assert(gpus_wanted > 0);
+	if (gpu_count >= gpus_wanted)
+		return gpu_count;
+
+	num = print_gpus(gpus_wanted, gpu_count);
+	igt_skip_on_f(gpu_count < gpus_wanted, "Test requires at least %d GPUs, got %d, available: %d\n", gpus_wanted, gpu_count, num);
+
+	return gpu_count; /* non-reachable */
+}
+
+/**
+ * multigpu_open_filtered_card:
+ * @idx: index of GPU card, starting from 0
+ * @chipset: chipset, e.g. DRIVER_XE or DRIVER_INTEL
+ *
+ * Function opens GPU card prepared with filtered view. It also checks if
+ * opened card agrees with desired chipset or checks if opened card is
+ * functional. It do not use drm_open_* nor __drm_open_* functions.
+ * Skips on errors.
+ *
+ * Returns: opened fd for @idx card
+ */
+int multigpu_open_filtered_card(int idx, unsigned int chipset)
+{
+	int fd;
+
+	fd = drm_open_filtered_card(idx);
+	igt_assert(fd >= 0);
+	if (chipset == DRIVER_XE)
+		igt_require_xe(fd);
+	else if (chipset == DRIVER_INTEL)
+		igt_require_gem(fd);
+
+	return fd;
+}
diff --git a/lib/igt_multigpu.h b/lib/igt_multigpu.h
index 874b020c2..292208685 100644
--- a/lib/igt_multigpu.h
+++ b/lib/igt_multigpu.h
@@ -14,6 +14,9 @@ int igt_multigpu_count_class(int chipset);
 
 int multigpu_open_another(int idx, unsigned int chipset);
 
+int multigpu_acquire_view(int min_gpus_wanted, unsigned int chipset);
+int multigpu_open_filtered_card(int idx, unsigned int chipset);
+
 #define igt_foreach_gpu(fd__, chipset__) \
 	for (int igt_unique(i) = 0, fd__; \
 		(fd__ = __drm_open_driver_another(igt_unique(i)++, chipset__)) >= 0; \
@@ -25,4 +28,16 @@ int multigpu_open_another(int idx, unsigned int chipset);
 			__fd >= 0; \
 			drm_close_driver(__fd), __fd = -1)
 
+#define __igt_foreach_num_gpu_chip(__gpu_wanted, __fd, __gpu_index, __chipset) \
+	igt_multi_fork(__gpu_index, multigpu_acquire_view(__gpu_wanted, __chipset)) \
+		for (int __fd = multigpu_open_filtered_card(__gpu_index, __chipset); \
+			__fd >= 0; \
+			drm_close_driver(__fd), __fd = -1)
+
+#define igt_foreach_gpu_chip(__fd, __gpu_index, __chipset) \
+		__igt_foreach_num_gpu_chip(1, __fd, __gpu_index, __chipset)
+
+#define igt_foreach_multigpu_chip(__fd, __gpu_index, __chipset) \
+		__igt_foreach_num_gpu_chip(2, __fd, __gpu_index, __chipset)
+
 #endif /* __INTEL_MULTIGPU_H */
-- 
2.42.0



More information about the igt-dev mailing list