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 5/8] lib/drmtest: create helper for countig number of GPUs
Date: Fri, 20 Oct 2023 15:00:13 +0200	[thread overview]
Message-ID: <20231020130016.86398-6-kamil.konieczny@linux.intel.com> (raw)
In-Reply-To: <20231020130016.86398-1-kamil.konieczny@linux.intel.com>

Create a function for counting number of GPUs present on system.
When no filters used this will count discrete GPUs, otherwise
will count them using given filters.

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

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 89d045200..2cdeb8e3b 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -804,6 +804,78 @@ int drm_reopen_driver(int fd)
 	return fd;
 }
 
+/**
+ * drm_open_driver_render:
+ * @chipset: flag for one chipset to search, eg. #DRIVER_INTEL
+ *
+ * Get number of GPUs for given chipset. If used --device option or IGT_DEVICE
+ * environment variable, perform countig based on supplied filters.
+ *
+ * Returns:
+ * Number of GPUs for given chipset or filters.
+ */
+int drm_get_gpu_count(int chipset)
+{
+	struct igt_device_card card;
+	int gpu_count;
+	bool found;
+	char v[16];
+
+	if (chipset == DRIVER_VGEM || chipset == DRIVER_ANY) {
+		igt_debug("No multi-gpu for chipset %d\n", chipset);
+		return 0;
+	}
+
+	gpu_count = igt_device_filter_count();
+	if (!gpu_count) {
+		char gpu_filter[256];
+
+		if (chipset == DRIVER_INTEL || chipset == DRIVER_XE)
+			strncpy(v, "Intel", sizeof(v) - 1);
+		else
+			strncpy(v, chipset_to_str(chipset), sizeof(v) - 1);
+		igt_debug("Counting GPUs for chipset: %d vendor: %s\n", chipset, v);
+		for (int i = 0; i < 64; i++) {
+			igt_assert(snprintf(gpu_filter, sizeof(gpu_filter),
+					    "pci:vendor=%s,device=discrete,card=%d",
+					    v, i) < sizeof(gpu_filter));
+
+			memset(&card, 0, sizeof(card));
+			found = igt_device_card_match(gpu_filter, &card);
+			if (found && strlen(card.card)) {
+				igt_debug("Found gpu %d with %s\n", i, card.card);
+				++gpu_count;
+			} else {
+				igt_debug("Counted GPUs number: %d\n", gpu_count);
+				break;
+			}
+		}
+	} else {
+		int count = 0;
+
+		for (int i = 0; i < gpu_count; i++) {
+			const char *filter;
+
+			filter = igt_device_filter_get(i);
+			memset(&card, 0, sizeof(card));
+			found = igt_device_card_match(filter, &card);
+			if (found && strlen(card.card)) {
+				igt_debug("Found gpu %d with %s\n", i, card.card);
+				++count;
+			} else {
+				break;
+			}
+		}
+
+		if (count < gpu_count)
+			igt_debug("Counted GPUs %d lower than number of filters %d\n", count, gpu_count);
+
+		gpu_count = count;
+	}
+
+	return gpu_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..7db2292cb 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -109,6 +109,8 @@ int drm_close_driver(int fd);
 
 int drm_reopen_driver(int fd);
 
+int drm_get_gpu_count(int chipset);
+
 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-10-20 13:01 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 ` [igt-dev] [PATCH i-g-t v9 1/8] lib/drmtest: allow out of order device opening Kamil Konieczny
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 ` Kamil Konieczny [this message]
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-6-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