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 v9 1/8] lib/drmtest: allow out of order device opening
Date: Fri, 20 Oct 2023 15:00:09 +0200	[thread overview]
Message-ID: <20231020130016.86398-2-kamil.konieczny@linux.intel.com> (raw)
In-Reply-To: <20231020130016.86398-1-kamil.konieczny@linux.intel.com>

Allow to open cards with filters out of order, not in
the sequence 0...N. This will fix problem found out with test
gem_exec_gttfill@multigpu-basic with three discrete GPUs:

Opened device: /dev/dri/card1
Starting subtest: multigpu-basic
<g:1> Opened device: /dev/dri/card2
gem_exec_gttfill: ../lib/drmtest.c:313: _is_already_opened: Assertion `as_idx <= _opened_fds_count' failed.

Added also some debug prints for diagnosing problems with
multi-GPU tests.

v2: fix setting opened count in _set_opened_fd()
v3: search all already opened fds in _is_already_opened()
v4: revert change in v3, this will cause treating zero as
    special index (no checks) as some test depend on it
v5: start searching for driver from requested index,
    limit checks for already opened drivers to currently
    opened count (Kamil)
v6: remove if condition in _set_opened_fd (Zbigniew)

Cc: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
---
 lib/drmtest.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index e1da66c87..baff82b25 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -296,13 +296,16 @@ static int _opened_fds_count;
 static void _set_opened_fd(int idx, int fd)
 {
 	assert(idx < ARRAY_SIZE(_opened_fds));
-	assert(idx <= _opened_fds_count);
+
+	for (int i = _opened_fds_count; i < idx; ++i)
+		_opened_fds[i].fd = -1;
 
 	_opened_fds[idx].fd = fd;
 
 	assert(fstat(fd, &_opened_fds[idx].stat) == 0);
 
-	_opened_fds_count = idx+1;
+	if (idx >= _opened_fds_count)
+		_opened_fds_count = idx + 1;
 }
 
 static bool _is_already_opened(const char *path, int as_idx)
@@ -310,16 +313,23 @@ static bool _is_already_opened(const char *path, int as_idx)
 	struct stat new;
 
 	assert(as_idx < ARRAY_SIZE(_opened_fds));
-	assert(as_idx <= _opened_fds_count);
 
 	/*
 	 * we cannot even stat the device, so it's of no use - let's claim it's
 	 * already opened
 	 */
-	if (igt_debug_on(stat(path, &new) != 0))
+	if (igt_debug_on(stat(path, &new) != 0)) {
+		igt_debug("cannot stat device: %s\n", path);
 		return true;
+	}
+
+	if (as_idx > _opened_fds_count)
+		as_idx = _opened_fds_count;
 
 	for (int i = 0; i < as_idx; ++i) {
+		if (_opened_fds[i].fd == -1)
+			continue;
+
 		/* did we cross filesystem boundary? */
 		assert(_opened_fds[i].stat.st_dev == new.st_dev);
 
@@ -338,6 +348,7 @@ static int __search_and_open(const char *base, int offset, unsigned int chipset,
 	if (forced)
 		igt_debug("Force option used: Using driver %s\n", forced);
 
+	offset += as_idx;
 	for (int i = 0; i < 16; i++) {
 		char name[80];
 		int fd;
@@ -484,6 +495,7 @@ int __drm_open_driver_another(int idx, int chipset)
 {
 	int fd = -1;
 
+	igt_debug("card idx: %d chipset: %d\n", idx, chipset);
 	if (chipset != DRIVER_VGEM && igt_device_filter_count() > idx) {
 		struct igt_device_card card;
 		bool found;
@@ -491,6 +503,7 @@ int __drm_open_driver_another(int idx, int chipset)
 		found = __get_card_for_nth_filter(idx, &card);
 
 		if (!found) {
+			igt_debug("cannot find card idx: %d, loading module\n", idx);
 			drm_load_module(chipset);
 			found = __get_card_for_nth_filter(idx, &card);
 		}
@@ -500,11 +513,14 @@ int __drm_open_driver_another(int idx, int chipset)
 				 igt_device_filter_get(idx));
 		else if (_is_already_opened(card.card, idx))
 			igt_warn("card maching filter %d is already opened\n", idx);
-		else
+		else {
+			igt_debug("card idx: %d found: %s\n", idx, card.card);
 			fd = __open_driver_exact(card.card, chipset);
+		}
 
 	} else {
 		/* no filter for device idx, let's open whatever is available */
+		igt_debug("No filter for device idx: %d\n", idx);
 		fd = __open_driver("/dev/dri/card", 0, chipset, idx);
 	}
 
-- 
2.42.0

  reply	other threads:[~2023-10-20 13:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 13:00 [igt-dev] [PATCH i-g-t v9 0/8] drmtest changes for running tests on multi-gpu Kamil Konieczny
2023-10-20 13:00 ` Kamil Konieczny [this message]
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 2/8] tests/intel/xe_create: extend massive subtest to multi-gpu Kamil Konieczny
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 3/8] lib/drmtest: drop checks for opened device for filters Kamil Konieczny
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 4/8] lib/drmtest: save skip offset for first opened device Kamil Konieczny
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 5/8] lib/drmtest: create helper for countig number of GPUs Kamil Konieczny
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 6/8] tests/intel/xe_create: use drm helper for GPUs count Kamil Konieczny
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 7/8] lib/drmtest: create helper for dropping opened paths Kamil Konieczny
2023-10-20 13:00 ` [igt-dev] [PATCH i-g-t v9 8/8] tests/intel/xe_create: print first opened card Kamil Konieczny
2023-10-24  0:23 ` [igt-dev] ✓ Fi.CI.BAT: success for drmtest changes for running tests on multi-gpu (rev8) Patchwork
2023-10-24  1:22 ` [igt-dev] ✓ CI.xeBAT: " 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=20231020130016.86398-2-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