Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kamil Konieczny <kamil.konieczny@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>,
	"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
	"Chris Wilson" <chris.p.wilson@linux.intel.com>,
	"Kamil Konieczny" <kamil.konieczny@linux.intel.com>
Subject: [PATCH i-g-t v6 5/8] lib/intel_multigpu: Introduced gem_multigpu_count_class and igt_multi_fork_foreach_gpu
Date: Thu,  1 Feb 2024 16:50:44 +0100	[thread overview]
Message-ID: <20240201155047.48608-6-kamil.konieczny@linux.intel.com> (raw)
In-Reply-To: <20240201155047.48608-1-kamil.konieczny@linux.intel.com>

From: Dominik Karol Piątkowski <dominik.karol.piatkowski@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();

Cc: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@intel.com>
Signed-off-by: Chris Wilson <chris.p.wilson@linux.intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
---
 lib/intel_multigpu.c | 11 +++++++++++
 lib/intel_multigpu.h | 15 +++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/lib/intel_multigpu.c b/lib/intel_multigpu.c
index 34c9f936d..0e76d8aa3 100644
--- a/lib/intel_multigpu.c
+++ b/lib/intel_multigpu.c
@@ -3,10 +3,21 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include "drmtest.h"
 #include "igt_core.h"
 #include "igt_device_scan.h"
 #include "intel_multigpu.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/intel_multigpu.h b/lib/intel_multigpu.h
index 98dc5a4ce..0ebc73e4a 100644
--- a/lib/intel_multigpu.h
+++ b/lib/intel_multigpu.h
@@ -6,6 +6,21 @@
 #ifndef __INTEL_MULTIGPU_H
 #define __INTEL_MULTIGPU_H
 
+#include "drmtest.h"
+#include "igt_core.h"
+
 void gem_require_multigpu(int count);
+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) \
 
 #endif /* __INTEL_MULTIGPU_H */
-- 
2.42.0


  parent reply	other threads:[~2024-02-01 15:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 15:50 [PATCH i-g-t v6 0/8] introduce Xe multigpu and other multi-GPU helpers Kamil Konieczny
2024-02-01 15:50 ` [PATCH i-g-t v6 1/8] lib/igt_device_scan: Introduce filtering out non-PCI devices Kamil Konieczny
2024-02-01 15:50 ` [PATCH i-g-t v6 2/8] lib/drmtest: Introduced drm_open_driver_another Kamil Konieczny
2024-02-01 15:50 ` [PATCH i-g-t v6 3/8] lib/drmtest: allow opening cards out of order Kamil Konieczny
2024-02-02 11:38   ` Janusz Krzysztofik
2024-02-02 15:32     ` Kamil Konieczny
2024-02-01 15:50 ` [PATCH i-g-t v6 4/8] lib/intel_multigpu: Introduce library for multi-GPU scenarios Kamil Konieczny
2024-02-01 15:50 ` Kamil Konieczny [this message]
2024-02-01 15:50 ` [PATCH i-g-t v6 6/8] lib/intel_multigpu: Add xe_multi_fork_foreach_gpu Kamil Konieczny
2024-02-01 15:50 ` [PATCH i-g-t v6 7/8] tests/intel/xe_exec_basic: add multigpu subtests Kamil Konieczny
2024-02-01 15:50 ` [PATCH i-g-t v6 8/8] tests/intel/gem_mmap: add basic multi-GPU subtest Kamil Konieczny
2024-02-01 17:03 ` ✓ CI.xeBAT: success for introduce Xe multigpu and other multi-GPU helpers (rev6) Patchwork
2024-02-01 17:21 ` ✓ Fi.CI.BAT: " Patchwork
2024-02-01 19:14 ` ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240201155047.48608-6-kamil.konieczny@linux.intel.com \
    --to=kamil.konieczny@linux.intel.com \
    --cc=chris.p.wilson@linux.intel.com \
    --cc=dominik.karol.piatkowski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=janusz.krzysztofik@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox