<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 23-04-2025 12:01, Zbigniew
KempczyĆski wrote:<br>
</div>
<blockquote type="cite" cite="mid:20250423063109.gadkamns7yzcgy6e@zkempczy-mobl2">
<pre wrap="" class="moz-quote-pre">On Tue, Apr 22, 2025 at 10:41:04PM +0530, Soham Purkait wrote:
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">Add support for the device filter based on
driver string, device type (integrated or discrete)
and card number.
v5 : Add device filter to filter out
matching devices. (Zbigniew)
v6 : Move device filter with Separate
commit. (Zbigniew)
v7 : Fix interpretation of card numbering
and add 'all' option for all the cards.
(Zbigniew)
v8 : Fix for card filter output. (Zbigniew)
v9 : Render node enabled with 'device:' option
through iterating only pci subsystem
devices in filter. (Zbigniew)
Signed-off-by: Soham Purkait <a class="moz-txt-link-rfc2396E" href="mailto:soham.purkait@intel.com"><soham.purkait@intel.com></a>
---
lib/igt_device_scan.c | 74 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index 3f26a1737..8859b9489 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -1709,6 +1709,74 @@ static struct igt_list_head *filter_sriov(const struct filter_class *fcls,
return &igt_devs.filtered;
}
+/*
+ * Find appropriate gpu device through matching driver, device type and
+ * card filter arguments.
+ */
+static struct igt_list_head *filter_device(const struct filter_class *fcls,
+ const struct filter *filter)
+{
+ struct igt_device *dev;
+ bool allcards = false;
+ int card = 0;
+ (void)fcls;
+
+ DBG("filter device\n");
+ if (filter->data.card) {
+ char crdop[5] = {0};
+
+ if (sscanf(filter->data.card, "%d", &card) == 1) {
+ if (card < 0)
+ return &igt_devs.filtered;
+ } else {
+ card = 0;
+ if (sscanf(filter->data.card, "%4s", crdop) == 1) {
+ if (!strcmp(crdop, "all"))
+ allcards = true;
+ else
+ return &igt_devs.filtered;
+ } else {
+ return &igt_devs.filtered;
+ }
+ }
+ } else {
+ card = 0;
+ }
+
+ igt_list_for_each_entry(dev, &igt_devs.all, link) {
+ if (!is_pci_subsystem(dev))
+ continue;
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
For 'device' filter this condition should be removed. You contain
'subsystem' field in igt_device_card so you may skip cards which
are not pci on populate_devices().<span style="white-space: normal">
</span></pre>
</blockquote>
As far as GPUTOP is concern this could be managed through various
means as previously it was being handled with in
igt_device_card_match_all()<br>
through 'request_pci_ss' flag parameter or through comparing
'subsystem' field in populate_devices(), as the case may be.
<pre wrap="" class="moz-quote-pre"><span style="white-space: normal">But if this is removed and then this filter is used with lsgpu, it may not open render node if any of the filtered device is not the part of
pci subsystem.</span></pre>
that is :<br>
lsgpu -d device:<br>
(doesn't open render node).
<p>Regards,<br>
Soham <br>
</p>
<blockquote type="cite" cite="mid:20250423063109.gadkamns7yzcgy6e@zkempczy-mobl2">
<pre wrap="" class="moz-quote-pre">
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">+
+ /* Skip if 'driver' doesn't match */
+ if (filter->data.driver && !strequal(filter->data.driver, dev->driver))
+ continue;
+
+ /* Skip if 'device' doesn't match */
+ if (filter->data.device && !is_device_matched(dev, filter->data.device))
+ continue;
+
+ /* We get n-th card */
+ if (!allcards && !card) {
+ struct igt_device *dup = duplicate_device(dev);
+
+ igt_list_add_tail(&dup->link, &igt_devs.filtered);
+ break;
+ } else if (!allcards) {
+ card--;
+ }
+ /* Include all the cards */
+ else if (allcards) {
+ struct igt_device *dup = duplicate_device(dev);
+
+ igt_list_add(&dup->link, &igt_devs.filtered);
+ }
+ }
+
+ DBG("Filter device filtered size: %d\n", igt_list_length(&igt_devs.filtered));
+
+ return &igt_devs.filtered;
+}
+
static bool sys_path_valid(const struct filter_class *fcls,
const struct filter *filter)
{
@@ -1750,6 +1818,12 @@ static struct filter_class filter_definition_list[] = {
.help = "sriov:[vendor=%04x/name][,device=%04x][,card=%d][,pf=%d][,vf=%d]",
.detail = "find pf or vf\n",
},
+ {
+ .name = "device",
+ .filter_function = filter_device,
+ .help = "device:[driver=name][,device=type][,card=%d|all]",
</pre>
</blockquote>
<pre wrap="" class="moz-quote-pre">
Or you may add 'bus=pci' in 'device:[driver=name][,bus=all(default)|pci|nonpci][,device=type][,card=all]'
and then use filter in gputop.c:
device:bus=pci,card=all
Another alternative is to fix 'pci' filter to collect all devices
like 'device' filter is doing now.
--
Zbigniew
</pre>
<blockquote type="cite">
<pre wrap="" class="moz-quote-pre">+ .detail = "find device by driver name, device type and card number\n",
+ },
{
.name = NULL,
},
--
2.34.1
</pre>
</blockquote>
</blockquote>
</body>
</html>