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
Subject: [igt-dev] [PATCH i-g-t 2/3] lib/drmtest: add multigpu helpers
Date: Wed, 20 Sep 2023 18:19:12 +0200	[thread overview]
Message-ID: <20230920161913.54521-3-kamil.konieczny@linux.intel.com> (raw)
In-Reply-To: <20230920161913.54521-1-kamil.konieczny@linux.intel.com>

Create helpers for multigpu tests so they may use not only cards
but also renders.

Signed-off-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
---
 lib/drmtest.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++---
 lib/drmtest.h |  4 +++
 2 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 926f388ee..72fa22ee9 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -293,6 +293,10 @@ static struct {
 
 static int _opened_fds_count;
 
+static struct igt_device_card _multigpu_cards[64];
+static int _multigpu_count;
+static bool _multigpu_use_render;
+
 static void _set_opened_fd(int idx, int fd)
 {
 	assert(idx < ARRAY_SIZE(_opened_fds));
@@ -499,6 +503,7 @@ int __drm_open_driver_another(int idx, int chipset)
 	igt_debug("card idx: %d chipset: %d\n", idx, chipset);
 	if (chipset != DRIVER_VGEM && igt_device_filter_count() > idx) {
 		struct igt_device_card card;
+		char *name;
 		bool found;
 
 		found = __get_card_for_nth_filter(idx, &card);
@@ -509,14 +514,15 @@ int __drm_open_driver_another(int idx, int chipset)
 			found = __get_card_for_nth_filter(idx, &card);
 		}
 
-		if (!found || !strlen(card.card))
+		name = _multigpu_use_render ? card.render : card.card;
+		if (!found || !strlen(name))
 			igt_warn("No card matches the filter! [%s]\n",
 				 igt_device_filter_get(idx));
-		else if (_is_already_opened(card.card, idx))
+		else if (_is_already_opened(name, idx))
 			igt_warn("card maching filter %d is already opened\n", idx);
 		else {
-			igt_debug("card idx: %d found: %s\n", idx, card.card);
-			fd = __open_driver_exact(card.card, chipset);
+			igt_debug("card idx: %d found: %s\n", idx, name);
+			fd = __open_driver_exact(name, chipset);
 		}
 
 	} else {
@@ -794,6 +800,86 @@ int drm_reopen_driver(int fd)
 	return fd;
 }
 
+static int __drm_multigpu_prepare(int chipset)
+{
+	int gpu_count;
+
+	if (_multigpu_count)
+		return _multigpu_count < 0 ? 0 : _multigpu_count; /* already prepared */
+
+	memset(&_multigpu_cards[0], 0, sizeof(_multigpu_cards));
+
+	gpu_count = igt_device_filter_count();
+	for (int i = 0; i < gpu_count; i++) {
+		struct igt_device_card *newcard;
+		const char *filter;
+
+		newcard = &_multigpu_cards[i];
+		filter = igt_device_filter_get(i);
+		if (strlen(filter) > 0 && igt_device_card_match(filter, newcard)) {
+			igt_debug("Filter matched %s | %s\n", newcard->card, newcard->render);
+			++_multigpu_count;
+		}
+	}
+
+	if (_multigpu_count < 2) {
+		igt_debug("Multigpu prepare failed, no multi-gpu board or no --device nor IGT_DEVICE used\n");
+		_multigpu_count = -1; /* do not count 1 as multigpu */
+
+		/* check if we may find intel discrete cards with filters */
+		if (chipset & (DRIVER_INTEL | DRIVER_XE)) {
+			struct igt_device_card gpucard;
+			char filter[128];
+
+			for (int i = 0; i < 16; i++) {
+				snprintf(filter, sizeof(filter), "pci:vendor=Intel,device=discrete,card=%d", i);
+				if (igt_device_card_match(filter, &gpucard))
+					igt_debug("Found card: %s\n", gpucard.card);
+			}
+		}
+	}
+
+	return _multigpu_count;
+}
+/**
+ * drm_multigpu_prepare_cards:
+ * @chipset: flag for chipset to use in multigpu opens
+ *
+ * Prepares __drm_open_drivers_another to use card.card at opens.
+ * Returns: number of cards found by filter given by --device or IGT_DEVICE
+ */
+int drm_multigpu_prepare_cards(int chipset)
+{
+	_multigpu_use_render = false;
+
+	return __drm_multigpu_prepare(chipset);
+}
+
+/**
+ * drm_multigpu_prepare_renders:
+ * @chipset: flag for chipset to use in multigpu opens
+ *
+ * Prepares __drm_open_drivers_another to use card.render at opens.
+ * Returns: number of cards found by filter given by --device or IGT_DEVICE
+ */
+int drm_multigpu_prepare_renders(int chipset)
+{
+	_multigpu_use_render = true;
+
+	return __drm_multigpu_prepare(chipset);
+}
+
+/**
+ * drm_get_multigpu_count:
+ *
+ * Returns: number of cards found by drm_multigpu_prepare_cards or
+ * drm_multigpu_prepare_renders
+ */
+int drm_get_multigpu_count(void)
+{
+	return _multigpu_count;
+}
+
 void igt_require_amdgpu(int fd)
 {
 	igt_require(is_amdgpu_device(fd));
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 97ab6e759..2fab50a36 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -109,6 +109,10 @@ int drm_close_driver(int fd);
 
 int drm_reopen_driver(int fd);
 
+int drm_multigpu_prepare_cards(int chipset);
+int drm_multigpu_prepare_renders(int chipset);
+int drm_get_multigpu_count(void);
+
 void igt_require_amdgpu(int fd);
 void igt_require_intel(int fd);
 void igt_require_i915(int fd);
-- 
2.42.0

  parent reply	other threads:[~2023-09-20 16:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 16:19 [igt-dev] [PATCH i-g-t 0/3] drmtest changes for running tests on multi-gpu Kamil Konieczny
2023-09-20 16:19 ` [igt-dev] [PATCH i-g-t 1/3] lib/drmtest: allow out of order device opening Kamil Konieczny
2023-09-20 16:19 ` Kamil Konieczny [this message]
2023-09-25 20:30   ` [igt-dev] [PATCH i-g-t 2/3] lib/drmtest: add multigpu helpers Zbigniew Kempczyński
2023-09-26  5:41     ` Zbigniew Kempczyński
2023-09-20 16:19 ` [igt-dev] [PATCH i-g-t 3/3] RFC: tests/intel/xe_create: extend massive subtest to multi-gpu Kamil Konieczny
2023-09-20 19:50 ` [igt-dev] ✗ CI.xeBAT: failure for drmtest changes for running tests on multi-gpu Patchwork
2023-09-20 19:55 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2023-09-21  2:11 ` [igt-dev] ✗ Fi.CI.IGT: failure " 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=20230920161913.54521-3-kamil.konieczny@linux.intel.com \
    --to=kamil.konieczny@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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