[igt-dev] [PATCH i-g-t 4/5] lib/i915/gem_multigpu: Introduced gem_multigpu_count_class and igt_multi_fork_foreach_gpu

Kamil Konieczny kamil.konieczny at linux.intel.com
Fri Oct 13 18:57:31 UTC 2023


From: Dominik Karol Piątkowski <dominik.karol.piatkowski at intel.com>

Introduced gem_multigpu_count_class function that returns an actual
number of GPUs present in system, which allows for writing multi-GPU
test scenarios that does not require
--device pci:vendor=intel,device=discrete,card=all
to run as intended. Based on patch by Chris Wilson.

Introduced igt_multi_fork_foreach_gpu macro that helps with
writing multi-GPU test scenarios in idiomatic form:

igt_multi_fork_foreach_gpu(i915, DRIVER_INTEL)
	test_function(i915);
igt_waitchildren();

Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski at intel.com>
Signed-off-by: Chris Wilson <chris.p.wilson at linux.intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 lib/i915/gem_multigpu.c | 11 +++++++++++
 lib/i915/gem_multigpu.h | 16 ++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/lib/i915/gem_multigpu.c b/lib/i915/gem_multigpu.c
index d4d2d3d6a..e4b739a9b 100644
--- a/lib/i915/gem_multigpu.c
+++ b/lib/i915/gem_multigpu.c
@@ -3,10 +3,21 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include "drmtest.h"
 #include "i915/gem_multigpu.h"
 #include "igt_core.h"
 #include "igt_device_scan.h"
 
+int gem_multigpu_count_class(int class)
+{
+	int count = 0;
+
+	igt_foreach_gpu(fd, class)
+		count++;
+
+	return count;
+}
+
 void gem_require_multigpu(int count)
 {
 	struct igt_devices_print_format fmt = {
diff --git a/lib/i915/gem_multigpu.h b/lib/i915/gem_multigpu.h
index 4bde96c15..feb4176fa 100644
--- a/lib/i915/gem_multigpu.h
+++ b/lib/i915/gem_multigpu.h
@@ -6,6 +6,22 @@
 #ifndef GEM_MULTIGPU_H
 #define GEM_MULTIGPU_H
 
+#include "igt_core.h"
+#include "igt_device_scan.h"
+
+int gem_multigpu_count_class(int class);
+
+#define igt_foreach_gpu(fd__, id__) \
+	for (int igt_unique(i) = 0, fd__; \
+		(fd__ = __drm_open_driver_another(igt_unique(i)++, id__)) >= 0; \
+		close(fd__))
+
+#define igt_multi_fork_foreach_gpu(__fd, id) \
+	igt_multi_fork(igt_unique(__i), gem_multigpu_count_class(id)) \
+		for (int __fd = drm_open_driver_another(igt_unique(__i), id); \
+			__fd >= 0; \
+			close(__fd), __fd = -1) \
+
 void gem_require_multigpu(int count);
 
 #endif /* GEM_MULTIGPU_H */
-- 
2.42.0



More information about the igt-dev mailing list