Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Soham Purkait <soham.purkait@intel.com>
To: igt-dev@lists.freedesktop.org, riana.tauro@intel.com,
	vinay.belgaumkar@intel.com
Cc: anshuman.gupta@intel.com, lucas.demarchi@intel.com,
	rodrigo.vivi@intel.com, soham.purkait@intel.com,
	jonathan.ming.jun.lui@intel.com
Subject: [PATCH i-g-t v3 1/4] Enable finding all IGT devices for xe driver
Date: Fri, 28 Feb 2025 19:48:07 +0530	[thread overview]
Message-ID: <20250228141810.1417657-2-soham.purkait@intel.com> (raw)
In-Reply-To: <20250228141810.1417657-1-soham.purkait@intel.com>

v2 : fix for refactoring GPUTOP into a
     vendor-agnostic tool (Lucas)

v3 : Separate commit for lib (Kamil)

---
 lib/igt_device_scan.c | 97 +++++++++++++++++++++++++++++++++++++++++++
 lib/igt_device_scan.h |  3 ++
 2 files changed, 100 insertions(+)

diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index 711bedc5c..bdbe09761 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -774,6 +774,10 @@ __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
 		safe_strncpy(card->render, dev->drm_render,
 			     sizeof(card->render));
 
+	if (dev->driver != NULL)
+		safe_strncpy(card->driver, dev->driver,
+			     sizeof(card->driver));
+
 	if (dev->pci_slot_name != NULL)
 		safe_strncpy(card->pci_slot_name, dev->pci_slot_name,
 			     sizeof(card->pci_slot_name));
@@ -820,6 +824,99 @@ static bool __find_first_intel_card_by_driver_name(struct igt_device_card *card,
 	return false;
 }
 
+/*
+ * Iterate over all igt_devices array and find all discrete/integrated card.
+ * @card: double pointer to igt_device_card structure, containing
+ * an array of igt_device_card structure upon successful return.
+ */
+static int __find_all_intel_card_by_driver_name(struct igt_device_card **card,
+						bool want_discrete, const char *drv_name)
+{
+	int count = 0;
+	struct igt_device *dev;
+	int is_integrated;
+	struct igt_device_card *tmp;
+	struct igt_device_card *crd =
+		(struct igt_device_card *)calloc(1, sizeof(struct igt_device_card));
+
+	igt_assert(drv_name);
+	memset(card, 0, sizeof(*card));
+
+	igt_list_for_each_entry(dev, &igt_devs.all, link) {
+		if (!is_pci_subsystem(dev) || strcmp(dev->driver, drv_name))
+			continue;
+
+		is_integrated = !strncmp(dev->pci_slot_name, INTEGRATED_I915_GPU_PCI_ID,
+				PCI_SLOT_NAME_SIZE);
+
+		if (want_discrete && !is_integrated) {
+			__copy_dev_to_card(dev, (crd + count));
+			count++;
+			tmp = realloc(crd, sizeof(struct igt_device_card) * (1 + count));
+			if (!tmp) {
+				free(crd);
+				return -1;
+			}
+			crd = tmp;
+
+		} else if (!want_discrete && is_integrated) {
+			__copy_dev_to_card(dev, (crd + count));
+			count++;
+			tmp = realloc(crd, sizeof(struct igt_device_card) * (1 + count));
+			if (!tmp) {
+				free(crd);
+				return -1;
+			}
+			crd = tmp;
+		}
+	}
+	if (count == 0) {
+		free(crd);
+		return 0;
+	}
+
+	*card = crd;
+	return count;
+}
+
+/**
+ * igt_device_find_all_xe_integrated_card
+ * @card: double pointer to igt_device_card structure
+ *
+ * Iterate over all igt_devices array and find only xe integrated
+ * cards and populate an array of igt_device_card structure upon
+ * successful return.
+ * card will be updated with the pointer to the array of
+ * igt_device_card structure only if at least a single such device
+ * is found.
+ *
+ * Returns: number of integrated xe device is found.
+ */
+int igt_device_find_all_xe_integrated_card(struct igt_device_card **card)
+{
+	igt_assert(card);
+	return __find_all_intel_card_by_driver_name(card, false, "xe");
+}
+
+/**
+ * igt_device_find_all_xe_discrete_card
+ * @card: double pointer to igt_device_card structure
+ *
+ * Iterate over all igt_devices array and find only xe discrete
+ * cards and populate an array of igt_device_card structure upon
+ * successful return.
+ * card will be updated with the pointer to the array of
+ * igt_device_card structure only if at least a single such device
+ * is found.
+ *
+ * Returns: number of discrete xe device is found.
+ */
+int igt_device_find_all_xe_discrete_card(struct igt_device_card **card)
+{
+	igt_assert(card);
+	return __find_all_intel_card_by_driver_name(card, true, "xe");
+}
+
 bool igt_device_find_first_i915_discrete_card(struct igt_device_card *card)
 {
 	igt_assert(card);
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index 92741fe3c..25d3c462f 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -59,6 +59,7 @@ struct igt_device_card {
 	char subsystem[NAME_MAX];
 	char card[NAME_MAX];
 	char render[NAME_MAX];
+	char driver[NAME_MAX];
 	char pci_slot_name[PCI_SLOT_NAME_SIZE+1];
 	uint16_t pci_vendor, pci_device;
 };
@@ -92,6 +93,8 @@ bool igt_device_find_first_i915_discrete_card(struct igt_device_card *card);
 bool igt_device_find_integrated_card(struct igt_device_card *card);
 bool igt_device_find_first_xe_discrete_card(struct igt_device_card *card);
 bool igt_device_find_xe_integrated_card(struct igt_device_card *card);
+int igt_device_find_all_xe_integrated_card(struct igt_device_card **card);
+int igt_device_find_all_xe_discrete_card(struct igt_device_card **card);
 char *igt_device_get_pretty_name(struct igt_device_card *card, bool numeric);
 int igt_open_card(struct igt_device_card *card);
 int igt_open_render(struct igt_device_card *card);
-- 
2.34.1


  reply	other threads:[~2025-02-28 14:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28 14:18 [PATCH i-g-t v3 0/4] Add single engine busyness stats in GPUTOP Soham Purkait
2025-02-28 14:18 ` Soham Purkait [this message]
2025-02-28 16:58   ` [PATCH i-g-t v3 1/4] Enable finding all IGT devices for xe driver Lucas De Marchi
2025-02-28 14:18 ` [PATCH i-g-t v3 2/4] Add gputop functionality common to all drivers Soham Purkait
2025-03-04 10:07   ` Riana Tauro
2025-02-28 14:18 ` [PATCH i-g-t v3 3/4] Add gputop support for xe specific devices Soham Purkait
2025-03-04 10:22   ` Riana Tauro
2025-02-28 14:18 ` [PATCH i-g-t v3 4/4] Enable support for multiple GPUs and instances Soham Purkait
2025-02-28 22:37 ` ✓ i915.CI.BAT: success for Add single engine busyness stats in GPUTOP (rev4) Patchwork
2025-02-28 23:06 ` ✓ Xe.CI.BAT: " Patchwork
2025-03-01  7:45 ` ✗ Xe.CI.Full: failure " Patchwork
2025-03-01 11:23 ` ✗ i915.CI.Full: " 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=20250228141810.1417657-2-soham.purkait@intel.com \
    --to=soham.purkait@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jonathan.ming.jun.lui@intel.com \
    --cc=lucas.demarchi@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=vinay.belgaumkar@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