From: Soham Purkait <soham.purkait@intel.com>
To: igt-dev@lists.freedesktop.org, riana.tauro@intel.com,
vinay.belgaumkar@intel.com, kamil.konieczny@intel.com,
krzysztof.karas@intel.com, zbigniew.kempczynski@intel.com
Cc: anshuman.gupta@intel.com, lucas.demarchi@intel.com,
rodrigo.vivi@intel.com, soham.purkait@intel.com,
ashutosh.dixit@intel.com
Subject: [PATCH i-g-t v11 2/5] lib/igt_device_scan: Enable finding all matched IGT devices
Date: Thu, 22 May 2025 21:14:44 +0530 [thread overview]
Message-ID: <20250522154447.496407-3-soham.purkait@intel.com> (raw)
In-Reply-To: <20250522154447.496407-1-soham.purkait@intel.com>
Use filter to find all the available
GPUs or few among them by driver name
and card type or card number.
v2 : Fix for refactoring GPUTOP into a
vendor-agnostic tool. (Lucas)
v3 : Separate commit for lib. (Kamil)
v4 : Refactor to use composition strategy
for driver and device type filtering.
Refactor code to improve memory
allocation and error handling. (Lucas)
v5 : Introduce device card match function
to return collection of matching
devices using device filter.
v6 : Separate commit for device card match
function. (Zbigniew)
Function description modification for device
card match function. (Zbigniew)
v7 : Single return for card match function.
(Krzysztof)
v8 : Removed 'drivers' array as card match
function parameter. (Zbigniew)
v9 : Fixed allocation in card match instead of
multiple realloc. (Zbigniew)
Signed-off-by: Soham Purkait <soham.purkait@intel.com>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
---
lib/igt_device_scan.c | 48 +++++++++++++++++++++++++++++++++++++++++++
lib/igt_device_scan.h | 1 +
2 files changed, 49 insertions(+)
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index a250e7ee9..f11ebf02e 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -2143,6 +2143,54 @@ bool igt_device_card_match_pci(const char *filter,
return __igt_device_card_match(filter, card, true);
}
+/**
+ * igt_device_card_match_all
+ * @filter: filter string.
+ * @card: double pointer to igt_device_card structure, containing
+ * an array of igt_device_card structures upon successful return.
+ *
+ * Function applies filter to match device from device array.
+ *
+ * Returns: the number of cards found.
+ *
+ * Note: The caller is responsible for freeing the memory which is
+ * dynamically allocated for the array of igt_device_card structures
+ * upon successful return.
+ */
+int igt_device_card_match_all(const char *filter, struct igt_device_card **card)
+{
+ struct igt_device *dev = NULL;
+ struct igt_device_card *crd = NULL;
+ int count = 0;
+
+ igt_devices_scan();
+
+ if (igt_device_filter_apply(filter) == false)
+ return 0;
+
+ if (igt_list_empty(&igt_devs.filtered))
+ return 0;
+
+ igt_list_for_each_entry(dev, &igt_devs.filtered, link) {
+ count++;
+ }
+
+ crd = calloc(count, sizeof(struct igt_device_card));
+ if (!crd)
+ return 0;
+
+ count = 0;
+
+ igt_list_for_each_entry(dev, &igt_devs.filtered, link) {
+ __copy_dev_to_card(dev, crd + count++);
+ }
+
+ if (count)
+ *card = crd;
+
+ return count;
+}
+
/**
* igt_device_get_pretty_name
* @card: pointer to igt_device_card struct
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index f1cd3b1e9..e6e31e799 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -89,6 +89,7 @@ int igt_device_filter_pci(void);
bool igt_device_card_match(const char *filter, struct igt_device_card *card);
bool igt_device_card_match_pci(const char *filter,
struct igt_device_card *card);
+int igt_device_card_match_all(const char *filter, struct igt_device_card **card);
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);
--
2.34.1
next prev parent reply other threads:[~2025-05-22 15:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 15:44 [PATCH i-g-t v11 0/5] Add per-device engine activity stats in GPUTOP Soham Purkait
2025-05-22 15:44 ` [PATCH i-g-t v11 1/5] lib/igt_device_scan: Add support for the device filter Soham Purkait
2025-05-22 15:44 ` Soham Purkait [this message]
2025-05-22 15:44 ` [PATCH i-g-t v11 3/5] tools/gputop/utils: Add gputop utility functions common to all drivers Soham Purkait
2025-05-22 15:44 ` [PATCH i-g-t v11 4/5] tools/gputop/xe_gputop: Add gputop support for xe specific devices Soham Purkait
2025-06-05 17:16 ` Riana Tauro
2025-06-11 7:58 ` Purkait, Soham
2025-05-22 15:44 ` [PATCH i-g-t v11 5/5] tools/gputop/gputop: Enable support for multiple GPUs and instances Soham Purkait
2025-06-05 16:57 ` Riana Tauro
2025-06-11 7:11 ` Purkait, Soham
2025-06-11 7:24 ` Riana Tauro
2025-05-22 16:34 ` ✗ Fi.CI.BUILD: failure for Add per-device engine activity stats in GPUTOP (rev7) 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=20250522154447.496407-3-soham.purkait@intel.com \
--to=soham.purkait@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=ashutosh.dixit@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@intel.com \
--cc=krzysztof.karas@intel.com \
--cc=lucas.demarchi@intel.com \
--cc=riana.tauro@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=vinay.belgaumkar@intel.com \
--cc=zbigniew.kempczynski@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.