Skip to contentSkip to conversation

lib/igt_device_scan: Remember vendor/device for pci devices

PATCH Superseded Zbigniew Kempczyński 2 participants 4 messages Nov 19, 2020

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/3 lib/igt_device_scan: Remember vendor/device for pci devices

If we want to use pci device id for not opened device we need to keep it in card structure.

Export igt_device_get_pretty_name() function to the caller to allow return pretty name (for lsgpu, intel_gpu_top and others).

Cc Tvrtko Ursulin <[email protected]>
Cc Petri Latvala <[email protected]>
---
 lib/igt_device_scan.c | 149 ++++++++++++++++++++++++++++++++++++++----
 lib/igt_device_scan.h |   3 +
 2 files changed, 139 insertions(+), 13 deletions(-)
lib/igt_device_scan.c +136 -13
index e97f7163..209a09bc 100644
@@ -25,7 +25,9 @@
 #include "igt_core.h"
 #include "igt_device_scan.h"
 #include "igt_list.h"
+#include "intel_chipset.h"
 
+#include <ctype.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <glib.h>
@@ -178,12 +180,43 @@ static struct {
 	bool devs_scanned;
 } igt_devs;
 
+typedef char *(*devname_fn)(uint16_t, uint16_t);
+
+static char *devname_hex(uint16_t vendor, uint16_t device)
+{
+	char *s;
+
+	igt_assert(asprintf(&s, "%04x:%04x", vendor, device) == 9);
+
+	return s;
+}
+
+static char *devname_intel(uint16_t vendor, uint16_t device)
+{
+	const struct intel_device_info *info = intel_get_device_info(device);
+	char *devname, *s;
+
+	if (info->codename) {
+		devname = strdup(info->codename);
+		devname[0] = toupper(devname[0]);
+		asprintf(&s, "Intel %s (Gen%u)", devname, ffs(info->gen));
+	} else {
+		devname = devname_hex(vendor, device);
+		asprintf(&s, "Intel %s", devname);
+	}
+
+	free(devname);
+
+	return s;
+}
+
 static struct {
 	const char *name;
 	const char *vendor_id;
+	devname_fn devname;
 } pci_vendor_mapping[] = {
-	{ "intel", "8086" },
-	{ "amd", "1002" },
+	{ "intel", "8086", devname_intel },
+	{ "amd", "1002", devname_hex },
 	{ NULL, },
 };
 
@@ -198,6 +231,42 @@ static const char *get_pci_vendor_id_by_name(const char *name)
 	return NULL;
 }
 
+static devname_fn get_pci_vendor_device_fn(uint16_t vendor)
+{
+	char vendorstr[5];
+
+	snprintf(vendorstr, sizeof(vendorstr), "%04x", vendor);
+
+	for (typeof(*pci_vendor_mapping) *vm = pci_vendor_mapping; vm->name; vm++) {
+		if (!strcasecmp(vendorstr, vm->vendor_id))
+			return vm->devname;
+	}
+
+	return devname_hex;
+}
+
+static void get_pci_vendor_device(const struct igt_device *dev,
+				  uint16_t *vendorp, uint16_t *devicep)
+{
+	igt_assert(dev && dev->vendor && dev->device);
+	igt_assert(vendorp && devicep);
+
+	igt_assert(sscanf(dev->vendor, "%hx", vendorp) == 1);
+	igt_assert(sscanf(dev->device, "%hx", devicep) == 1);
+}
+
+static char *__pci_pretty_name(uint16_t vendor, uint16_t device, bool numeric)
+{
+	devname_fn fn;
+
+	if (!numeric)
+		fn = get_pci_vendor_device_fn(vendor);
+	else
+		fn = devname_hex;
+
+	return fn(vendor, device);
+}
+
 /* Reading sysattr values can take time (even seconds),
  * we want to avoid reading such keys.
  */
@@ -446,23 +515,44 @@ static bool is_vendor_matched(struct igt_device *dev, const char *vendor)
 	return !strcasecmp(dev->vendor, vendor_id);
 }
 
+static char *safe_strncpy(char *dst, const char *src, int n)
+{
+	char *s;
+
+	igt_assert(n > 0);
+	igt_assert(dst && src);
+
+	s = strncpy(dst, src, n - 1);
+	s[n - 1] = '\0';
+
+	return s;
+}
+
 static void
 __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
 {
 	if (dev->subsystem != NULL)
-		strncpy(card->subsystem, dev->subsystem,
-			sizeof(card->subsystem) - 1);
+		safe_strncpy(card->subsystem, dev->subsystem,
+			     sizeof(card->subsystem));
 
 	if (dev->drm_card != NULL)
-		strncpy(card->card, dev->drm_card, sizeof(card->card) - 1);
+		safe_strncpy(card->card, dev->drm_card, sizeof(card->card));
 
 	if (dev->drm_render != NULL)
-		strncpy(card->render, dev->drm_render,
-			sizeof(card->render) - 1);
+		safe_strncpy(card->render, dev->drm_render,
+			     sizeof(card->render));
 
 	if (dev->pci_slot_name != NULL)
-		strncpy(card->pci_slot_name, dev->pci_slot_name,
-			PCI_SLOT_NAME_SIZE + 1);
+		safe_strncpy(card->pci_slot_name, dev->pci_slot_name,
+			     sizeof(card->pci_slot_name));
+
+	if (dev->vendor != NULL)
+		if (sscanf(dev->vendor, "%hx", &card->pci_vendor) != 1)
+			card->pci_vendor = 0;
+
+	if (dev->device != NULL)
+		if (sscanf(dev->device, "%hx", &card->pci_device) != 1)
+			card->pci_device = 0;
 }
 
 /*
@@ -852,6 +942,7 @@ static void __print_filter(char *buf, int len,
 	};
 }
 
+#define VENDOR_SIZE 30
 static void
 igt_devs_print_user(struct igt_list_head *view,
 		    const struct igt_devices_print_format *fmt)
@@ -883,11 +974,19 @@ igt_devs_print_user(struct igt_list_head *view,
 			continue;
 
 		if (pci_dev) {
+			uint16_t vendor, device;
+			char *devname;
+
+			get_pci_vendor_device(pci_dev, &vendor, &device);
+			devname = __pci_pretty_name(vendor, device, fmt->numeric);
+
 			__print_filter(filter, sizeof(filter), fmt, pci_dev,
 				       false);
-			printf("%-24s%4s:%4s    %s\n",
-			       drm_name, pci_dev->vendor, pci_dev->device,
-			       filter);
+
+			printf("%-24s %-*s    %s\n",
+			       drm_name, VENDOR_SIZE, devname, filter);
+
+			free(devname);
 		} else {
 			__print_filter(filter, sizeof(filter), fmt, dev, false);
 			printf("%-24s             %s\n", drm_name, filter);
@@ -919,7 +1018,7 @@ igt_devs_print_user(struct igt_list_head *view,
 			if (fmt->option != IGT_PRINT_PCI) {
 				__print_filter(filter, sizeof(filter), fmt,
 					       dev2, true);
-				printf("             %s\n", filter);
+				printf("%-*s     %s\n", VENDOR_SIZE, "", filter);
 			} else {
 				printf("\n");
 			}
@@ -1479,6 +1578,30 @@ bool igt_device_card_match_pci(const char *filter,
        return __igt_device_card_match(filter, card, true);
 }
 
+/**
+ * igt_device_get_pretty_name
+ * @card: pointer to igt_device_card struct
+ *
+ * For card function returns allocated string having pretty name
+ * or vendor:device as hex if no backend pretty-resolver is implemented.
+ *
+ * Returns: newly allocated string.
+ */
+char *igt_device_get_pretty_name(struct igt_device_card *card, bool numeric)
+{
+	char *devname;
+
+	igt_assert(card);
+
+	if (strlen(card->pci_slot_name))
+		devname = __pci_pretty_name(card->pci_vendor, card->pci_device,
+					    numeric);
+	else
+		devname = strdup(card->subsystem);
+
+	return devname;
+}
+
 /**
  * igt_open_card:
  * @card: pointer to igt_device_card structure
lib/igt_device_scan.h +3 -0
index bb4be723..5f583a06 100644
@@ -49,6 +49,7 @@ enum igt_devices_print_option {
 struct igt_devices_print_format {
 	enum igt_devices_print_type   type;
 	enum igt_devices_print_option option;
+	bool numeric;
 };
 
 #define INTEGRATED_I915_GPU_PCI_ID "0000:00:02.0"
@@ -58,6 +59,7 @@ struct igt_device_card {
 	char card[NAME_MAX];
 	char render[NAME_MAX];
 	char pci_slot_name[PCI_SLOT_NAME_SIZE+1];
+	uint16_t pci_vendor, pci_device;
 };
 
 void igt_devices_scan(bool force);
@@ -84,6 +86,7 @@ bool igt_device_card_match_pci(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);
+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);
 
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

PATCH v5 2/3 tools/intel_gpu_top: Add generation info in header

In multi device world we may want to see generation of device we're tracking counters. Add pretty name of the device to be more verbose.

---
 lib/Makefile.am       | 4 +++-
 lib/meson.build       | 1 +
 tools/intel_gpu_top.c | 8 ++++++--
 3 files changed, 10 insertions(+), 3 deletions(-)
lib/Makefile.am +3 -1
index fecf34cd..c476eeab 100644
@@ -118,7 +118,9 @@ libigt_device_scan_la_SOURCES = \
 	igt_list.c		\
 	igt_tools_stub.c	\
 	igt_device_scan.c	\
-	igt_device_scan.h
+	igt_device_scan.h	\
+	intel_device_info.c	\
+	intel_chipset.h
 
 libigt_perf_la_SOURCES = \
 	igt_perf.c	 \
lib/meson.build +1 -0
index 090a10cd..540facb2 100644
@@ -182,6 +182,7 @@ lib_igt_device_scan_build = static_library('igt_device_scan',
 	['igt_device_scan.c',
 	'igt_list.c',
 	'igt_tools_stub.c',
+	'intel_device_info.c',
 	],
 	dependencies : scan_dep,
 	include_directories : inc)
tools/intel_gpu_top.c +6 -2
index 86de09aa..3e97be2c 100644
@@ -1028,6 +1028,7 @@ static bool print_groups(struct cnt_group **groups)
 
 static int
 print_header(const struct igt_device_card *card,
+	     const char *codename,
 	     struct engines *engines, double t,
 	     int lines, int con_w, int con_h, bool *consumed)
 {
@@ -1107,7 +1108,7 @@ print_header(const struct igt_device_card *card,
 		printf("\033[H\033[J");
 
 		if (lines++ < con_h) {
-			printf("intel-gpu-top: %s - ", card->card);
+			printf("intel-gpu-top: %s @ %s - ", codename, card->card);
 			if (!engines->discrete)
 				printf("%s/%s MHz;  %s%% RC6; %s %s; %s irqs/s\n",
 					freq_items[1].buf, freq_items[0].buf,
@@ -1317,6 +1318,7 @@ int main(int argc, char **argv)
 	bool list_device = false;
 	char *pmu_device, *opt_device = NULL;
 	struct igt_device_card card;
+	char *codename = NULL;
 
 	/* Parse options */
 	while ((ch = getopt(argc, argv, "o:s:d:JLlh")) != -1) {
@@ -1441,6 +1443,7 @@ int main(int argc, char **argv)
 	ret = EXIT_SUCCESS;
 
 	pmu_sample(engines);
+	codename = igt_device_get_pretty_name(&card, false);
 
 	while (!stop_top) {
 		bool consumed = false;
@@ -1463,7 +1466,7 @@ int main(int argc, char **argv)
 			break;
 
 		while (!consumed) {
-			lines = print_header(&card, engines,
+			lines = print_header(&card, codename, engines,
 					     t, lines, con_w, con_h,
 					     &consumed);
 
@@ -1490,6 +1493,7 @@ int main(int argc, char **argv)
 		usleep(period_us);
 	}
 
+	free(codename);
 err:
 	free(engines);
 	free(pmu_device);
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#2 lore raw

PATCH v5 3/3 tools/lsgpu: Add -n switch to list devices using vendor:device hex id

In reply to Zbigniew Kempczyński

Default device list prefers vendor and device names. Add -n switch to display vendor/device as hex strings.

---
 tools/lsgpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/lsgpu.c +7 -1
index 169ab0c2..25358bbe 100644
@@ -72,6 +72,7 @@
 enum {
 	OPT_PRINT_SIMPLE   = 's',
 	OPT_PRINT_DETAIL   = 'p',
+	OPT_NUMERIC        = 'n',
 	OPT_LIST_VENDORS   = 'v',
 	OPT_LIST_FILTERS   = 'l',
 	OPT_DEVICE         = 'd',
@@ -86,6 +87,7 @@ static char *igt_device;
 static const char *usage_str =
 	"usage: lsgpu [options]\n\n"
 	"Options:\n"
+	"  -n, --numeric               Print vendor/device as hex\n"
 	"  -s, --print-simple          Print simple (legacy) device details\n"
 	"  -p, --print-details         Print devices with details\n"
 	"  -v, --list-vendors          List recognized vendors\n"
@@ -160,6 +162,7 @@ int main(int argc, char *argv[])
 		{"drm",               no_argument,       NULL, 0},
 		{"sysfs",             no_argument,       NULL, 1},
 		{"pci",               no_argument,       NULL, 2},
+		{"numeric",           no_argument,       NULL, OPT_NUMERIC},
 		{"print-simple",      no_argument,       NULL, OPT_PRINT_SIMPLE},
 		{"print-detail",      no_argument,       NULL, OPT_PRINT_DETAIL},
 		{"list-vendors",      no_argument,       NULL, OPT_LIST_VENDORS},
@@ -174,10 +177,13 @@ int main(int argc, char *argv[])
 			.type = IGT_PRINT_USER,
 	};
 
-	while ((c = getopt_long(argc, argv, "spvld:h",
+	while ((c = getopt_long(argc, argv, "nspvld:h",
 				long_options, &index)) != -1) {
 		switch(c) {
 
+		case OPT_NUMERIC:
+			fmt.numeric = true;
+			break;
 		case OPT_PRINT_SIMPLE:
 			fmt.type = IGT_PRINT_SIMPLE;
 			break;
Signature · 6 lines
2.26.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#3 lore raw

[igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v5,1/3] lib/igt_device_scan: Remember vendor/device for pci devices

In reply to Zbigniew Kempczyński
== Series Details ==

== Series Details ==

Series: series starting with [i-g-t,v5,1/3] lib/igt_device_scan: Remember vendor/device for pci devices
URL : https://patchwork.freedesktop.org/series/84040/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_9358 -> IGTPW_5191
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with IGTPW_5191 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in IGTPW_5191, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/index.html

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in IGTPW_5191:

### IGT changes ###

#### Possible regressions ####

* igt@gem_exec_suspend@basic-s0:
- fi-glk-dsi: NOTRUN -> [INCOMPLETE][1]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-glk-dsi/igt@[email protected]

Known issues
------------

Here are the changes found in IGTPW_5191 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@core_hotunplug@unbind-rebind:
- fi-skl-lmem: [PASS][2] -> [DMESG-WARN][3] ([i915#2605])
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-skl-lmem/igt@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-skl-lmem/igt@[email protected]

* igt@i915_module_load@reload:
- fi-byt-j1900: [PASS][4] -> [DMESG-WARN][5] ([i915#1982])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-byt-j1900/igt@[email protected]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-byt-j1900/igt@[email protected]
- fi-tgl-y: [PASS][6] -> [DMESG-WARN][7] ([i915#1982] / [k.org#205379])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-tgl-y/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-tgl-y/igt@[email protected]

* igt@kms_flip@basic-flip-vs-wf_vblank@b-edp1:
- fi-icl-u2: [PASS][8] -> [DMESG-WARN][9] ([i915#1982]) +1 similar issue
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-icl-u2/igt@kms_flip@[email protected]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-icl-u2/igt@kms_flip@[email protected]

* igt@prime_self_import@basic-with_two_bos:
- fi-tgl-y: [PASS][10] -> [DMESG-WARN][11] ([i915#402]) +2 similar issues
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-tgl-y/igt@prime_self_import@basic-with_two_bos.html
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-tgl-y/igt@prime_self_import@basic-with_two_bos.html

#### Possible fixes ####

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-apl-guc: [DMESG-WARN][12] ([i915#1635] / [i915#1982]) -> [PASS][13]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-apl-guc/igt@[email protected]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-apl-guc/igt@[email protected]

* igt@kms_flip@basic-flip-vs-wf_vblank@c-edp1:
- fi-icl-u2: [DMESG-WARN][14] ([i915#1982]) -> [PASS][15]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-icl-u2/igt@kms_flip@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-icl-u2/igt@kms_flip@[email protected]

* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
- fi-tgl-y: [DMESG-WARN][16] ([i915#1982]) -> [PASS][17]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-tgl-y/igt@[email protected]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-tgl-y/igt@[email protected]

* igt@vgem_basic@setversion:
- fi-tgl-y: [DMESG-WARN][18] ([i915#402]) -> [PASS][19] +1 similar issue
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9358/fi-tgl-y/igt@[email protected]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/fi-tgl-y/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#1635]: https://gitlab.freedesktop.org/drm/intel/issues/1635
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#2605]: https://gitlab.freedesktop.org/drm/intel/issues/2605
[i915#402]: https://gitlab.freedesktop.org/drm/intel/issues/402
[k.org#205379]: https://bugzilla.kernel.org/show_bug.cgi?id=205379

Participating hosts (40 -> 36)
------------------------------

Additional (1): fi-glk-dsi
Missing (5): fi-ilk-m540 fi-tgl-dsi fi-hsw-4200u fi-bsw-cyan fi-bdw-samus

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_5858 -> IGTPW_5191

CI-20190529: 20190529
CI_DRM_9358: 9e68bcbf28298badf1bc95f3ca4d899e99a268d5 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_5191: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/index.html
IGT_5858: 300ee395f5c0ed53ab0757d9c5b311f9c1f641c8 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5191/index.html

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev