* [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices
@ 2020-11-17 16:34 Zbigniew Kempczyński
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header Zbigniew Kempczyński
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Zbigniew Kempczyński @ 2020-11-17 16:34 UTC (permalink / raw)
To: igt-dev; +Cc: Petri Latvala, Tvrtko Ursulin
If we want to use pci device id for not opened device we need to
keep it in card structure.
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Petri Latvala <petri.latvala@intel.com>
---
lib/igt_device_scan.c | 88 +++++++++++++++++++++++++++++++++++++++----
lib/igt_device_scan.h | 2 +
2 files changed, 82 insertions(+), 8 deletions(-)
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index e97f7163..6c8ab8b1 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -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,39 @@ 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;
+
+ (void) vendor;
+
+ devname = info->codename ? strdup(info->codename) : strdup("unknown");
+ devname[0] = toupper(devname[0]);
+
+ asprintf(&s, "Intel %s (Gen%u)", devname, ffs(info->gen));
+
+ 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 +227,26 @@ static const char *get_pci_vendor_id_by_name(const char *name)
return NULL;
}
+static devname_fn get_pci_vendor_device_fn(const char *vendor_id)
+{
+ for (typeof(*pci_vendor_mapping) *vm = pci_vendor_mapping; vm->name; vm++) {
+ if (!strcasecmp(vendor_id, 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);
+}
+
/* Reading sysattr values can take time (even seconds),
* we want to avoid reading such keys.
*/
@@ -460,9 +509,19 @@ __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
strncpy(card->render, dev->drm_render,
sizeof(card->render) - 1);
- if (dev->pci_slot_name != NULL)
+ if (dev->pci_slot_name != NULL) {
strncpy(card->pci_slot_name, dev->pci_slot_name,
- PCI_SLOT_NAME_SIZE + 1);
+ PCI_SLOT_NAME_SIZE);
+ card->pci_slot_name[PCI_SLOT_NAME_SIZE] = '\0';
+ }
+
+ if (dev->vendor != NULL && strlen(dev->vendor) == 4)
+ if (sscanf(dev->vendor, "%hx", &card->pci_vendor) != 1)
+ card->pci_vendor = 0;
+
+ if (dev->device != NULL && strlen(dev->device) == 4)
+ if (sscanf(dev->device, "%hx", &card->pci_device) != 1)
+ card->pci_device = 0;
}
/*
@@ -852,6 +911,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 +943,23 @@ igt_devs_print_user(struct igt_list_head *view,
continue;
if (pci_dev) {
+ uint16_t vendor, device;
+ char *devname;
+ devname_fn fn = devname_hex;
+
+ if (!fmt->numeric)
+ fn = get_pci_vendor_device_fn(pci_dev->vendor);
+
+ get_pci_vendor_device(pci_dev, &vendor, &device);
+ devname = fn(vendor, device);
+
__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 +991,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");
}
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index bb4be723..42066eeb 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -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);
--
2.26.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header
2020-11-17 16:34 [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices Zbigniew Kempczyński
@ 2020-11-17 16:34 ` Zbigniew Kempczyński
2020-11-18 10:04 ` Tvrtko Ursulin
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 3/3] tools/lsgpu: Add -n switch to list devices using vendor:device hex id Zbigniew Kempczyński
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Zbigniew Kempczyński @ 2020-11-17 16:34 UTC (permalink / raw)
To: igt-dev; +Cc: Petri Latvala, Tvrtko Ursulin
In multi device world we may want to see generation of device we're
tracking counters. Add generation number/codename to be more verbose.
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Petri Latvala <petri.latvala@intel.com>
---
lib/Makefile.am | 4 +++-
lib/meson.build | 1 +
tools/intel_gpu_top.c | 18 ++++++++++++++++--
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index fecf34cd..c476eeab 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -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 \
diff --git a/lib/meson.build b/lib/meson.build
index 090a10cd..540facb2 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -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)
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index 86de09aa..399416c3 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -22,6 +22,7 @@
*/
#include "igt_device_scan.h"
+#include "intel_chipset.h"
#include <stdio.h>
#include <sys/types.h>
@@ -1028,9 +1029,12 @@ static bool print_groups(struct cnt_group **groups)
static int
print_header(const struct igt_device_card *card,
+ const struct intel_device_info *info,
struct engines *engines, double t,
int lines, int con_w, int con_h, bool *consumed)
{
+ static char *codename;
+ unsigned int gen = info ? ffs(info->gen) : 0;
struct pmu_counter fake_pmu = {
.present = true,
.val.cur = 1,
@@ -1106,8 +1110,15 @@ print_header(const struct igt_device_card *card,
if (output_mode == INTERACTIVE) {
printf("\033[H\033[J");
+ if (!codename) {
+ codename = info->codename ? strdup(info->codename) :
+ strdup("unknown");
+ codename[0] = toupper(codename[0]);
+ }
+
if (lines++ < con_h) {
- printf("intel-gpu-top: %s - ", card->card);
+ printf("intel-gpu-top: %s (Gen%u) @ %s - ",
+ codename, gen, 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 +1328,7 @@ int main(int argc, char **argv)
bool list_device = false;
char *pmu_device, *opt_device = NULL;
struct igt_device_card card;
+ const struct intel_device_info *info = NULL;
/* Parse options */
while ((ch = getopt(argc, argv, "o:s:d:JLlh")) != -1) {
@@ -1441,6 +1453,8 @@ int main(int argc, char **argv)
ret = EXIT_SUCCESS;
pmu_sample(engines);
+ if (card.pci_device)
+ info = intel_get_device_info(card.pci_device);
while (!stop_top) {
bool consumed = false;
@@ -1463,7 +1477,7 @@ int main(int argc, char **argv)
break;
while (!consumed) {
- lines = print_header(&card, engines,
+ lines = print_header(&card, info, engines,
t, lines, con_w, con_h,
&consumed);
--
2.26.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [igt-dev] [PATCH i-g-t v3 3/3] tools/lsgpu: Add -n switch to list devices using vendor:device hex id
2020-11-17 16:34 [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices Zbigniew Kempczyński
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header Zbigniew Kempczyński
@ 2020-11-17 16:34 ` Zbigniew Kempczyński
2020-11-17 18:50 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v3,1/3] lib/igt_device_scan: Remember vendor/device for pci devices Patchwork
2020-11-18 9:56 ` [igt-dev] [PATCH i-g-t v3 1/3] " Tvrtko Ursulin
3 siblings, 0 replies; 7+ messages in thread
From: Zbigniew Kempczyński @ 2020-11-17 16:34 UTC (permalink / raw)
To: igt-dev; +Cc: Petri Latvala, Tvrtko Ursulin
Default device list prefers vendor and device names. Add -n switch
to display vendor/device as hex strings.
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Petri Latvala <petri.latvala@intel.com>
---
tools/lsgpu.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/lsgpu.c b/tools/lsgpu.c
index 169ab0c2..25358bbe 100644
--- a/tools/lsgpu.c
+++ b/tools/lsgpu.c
@@ -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;
--
2.26.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v3,1/3] lib/igt_device_scan: Remember vendor/device for pci devices
2020-11-17 16:34 [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices Zbigniew Kempczyński
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header Zbigniew Kempczyński
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 3/3] tools/lsgpu: Add -n switch to list devices using vendor:device hex id Zbigniew Kempczyński
@ 2020-11-17 18:50 ` Patchwork
2020-11-18 9:56 ` [igt-dev] [PATCH i-g-t v3 1/3] " Tvrtko Ursulin
3 siblings, 0 replies; 7+ messages in thread
From: Patchwork @ 2020-11-17 18:50 UTC (permalink / raw)
To: Zbigniew Kempczyński; +Cc: igt-dev
[-- Attachment #1.1: Type: text/plain, Size: 3392 bytes --]
== Series Details ==
Series: series starting with [i-g-t,v3,1/3] lib/igt_device_scan: Remember vendor/device for pci devices
URL : https://patchwork.freedesktop.org/series/83978/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_9348 -> IGTPW_5181
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with IGTPW_5181 absolutely need to be
verified manually.
If you think the reported changes have nothing to do with the changes
introduced in IGTPW_5181, 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_5181/index.html
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in IGTPW_5181:
### IGT changes ###
#### Possible regressions ####
* igt@i915_selftest@live@gt_pm:
- fi-tgl-y: NOTRUN -> [DMESG-FAIL][1]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-tgl-y/igt@i915_selftest@live@gt_pm.html
Known issues
------------
Here are the changes found in IGTPW_5181 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic:
- fi-byt-j1900: [PASS][2] -> [DMESG-WARN][3] ([i915#1982])
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9348/fi-byt-j1900/igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic.html
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-byt-j1900/igt@kms_cursor_legacy@basic-busy-flip-before-cursor-atomic.html
#### Possible fixes ####
* igt@i915_module_load@reload:
- fi-byt-j1900: [DMESG-WARN][4] ([i915#1982]) -> [PASS][5]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9348/fi-byt-j1900/igt@i915_module_load@reload.html
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-byt-j1900/igt@i915_module_load@reload.html
* igt@kms_cursor_legacy@basic-flip-after-cursor-atomic:
- fi-icl-u2: [DMESG-WARN][6] ([i915#1982]) -> [PASS][7] +2 similar issues
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_9348/fi-icl-u2/igt@kms_cursor_legacy@basic-flip-after-cursor-atomic.html
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-icl-u2/igt@kms_cursor_legacy@basic-flip-after-cursor-atomic.html
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[i915#1759]: https://gitlab.freedesktop.org/drm/intel/issues/1759
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
Participating hosts (42 -> 41)
------------------------------
Additional (3): fi-kbl-soraka fi-blb-e6850 fi-tgl-y
Missing (4): fi-ilk-m540 fi-bsw-cyan fi-bdw-samus fi-hsw-4200u
Build changes
-------------
* CI: CI-20190529 -> None
* IGT: IGT_5855 -> IGTPW_5181
CI-20190529: 20190529
CI_DRM_9348: 8dc6152ada31b8d128be55f1dacc13c2b5b61666 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_5181: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/index.html
IGT_5855: d9b3c7058efe41e5224dd1e43fac05dc6d049380 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/index.html
[-- Attachment #1.2: Type: text/html, Size: 4164 bytes --]
[-- Attachment #2: Type: text/plain, Size: 154 bytes --]
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices
2020-11-17 16:34 [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices Zbigniew Kempczyński
` (2 preceding siblings ...)
2020-11-17 18:50 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v3,1/3] lib/igt_device_scan: Remember vendor/device for pci devices Patchwork
@ 2020-11-18 9:56 ` Tvrtko Ursulin
2020-11-18 12:10 ` Zbigniew Kempczyński
3 siblings, 1 reply; 7+ messages in thread
From: Tvrtko Ursulin @ 2020-11-18 9:56 UTC (permalink / raw)
To: Zbigniew Kempczyński, igt-dev; +Cc: Petri Latvala, Tvrtko Ursulin
On 17/11/2020 16:34, Zbigniew Kempczyński wrote:
> If we want to use pci device id for not opened device we need to
> keep it in card structure.
>
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Petri Latvala <petri.latvala@intel.com>
> ---
> lib/igt_device_scan.c | 88 +++++++++++++++++++++++++++++++++++++++----
> lib/igt_device_scan.h | 2 +
> 2 files changed, 82 insertions(+), 8 deletions(-)
>
> diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
> index e97f7163..6c8ab8b1 100644
> --- a/lib/igt_device_scan.c
> +++ b/lib/igt_device_scan.c
> @@ -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,39 @@ 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);
-1 or 9 are the only possible returns here, okay.
> +
> + return s;
> +}
> +
> +static char *devname_intel(uint16_t vendor, uint16_t device)
Plan export so later patch to intel_gpu_top does not need to
re-implement it?
> +{
> + const struct intel_device_info *info = intel_get_device_info(device);
> + char *devname, *s;
> +
> + (void) vendor;
> +
> + devname = info->codename ? strdup(info->codename) : strdup("unknown");
1) Leaks devname?
2) I think hex value would be better if unknown.
> + devname[0] = toupper(devname[0]);
> +
> + asprintf(&s, "Intel %s (Gen%u)", devname, ffs(info->gen));
> +
> + 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 +227,26 @@ static const char *get_pci_vendor_id_by_name(const char *name)
> return NULL;
> }
>
> +static devname_fn get_pci_vendor_device_fn(const char *vendor_id)
> +{
> + for (typeof(*pci_vendor_mapping) *vm = pci_vendor_mapping; vm->name; vm++) {
> + if (!strcasecmp(vendor_id, 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);
> +}
> +
> /* Reading sysattr values can take time (even seconds),
> * we want to avoid reading such keys.
> */
> @@ -460,9 +509,19 @@ __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
> strncpy(card->render, dev->drm_render,
> sizeof(card->render) - 1);
>
> - if (dev->pci_slot_name != NULL)
> + if (dev->pci_slot_name != NULL) {
> strncpy(card->pci_slot_name, dev->pci_slot_name,
> - PCI_SLOT_NAME_SIZE + 1);
> + PCI_SLOT_NAME_SIZE);
> + card->pci_slot_name[PCI_SLOT_NAME_SIZE] = '\0';
I would still prefer the same "sizeof - 1" pattern as the other copies
in this function.
Then indeed ensuring strings are null terminated is something which
could be added to all. Possibly a local wrapper on strncpy?
PCI slot length is probably the most defined of the bunch so it feels
wrong to have safest handling compared to other strings.
> + }
> +
> + if (dev->vendor != NULL && strlen(dev->vendor) == 4)
Can strlen be not four here in some situations or this could be an
assert just as well?
> + if (sscanf(dev->vendor, "%hx", &card->pci_vendor) != 1)
> + card->pci_vendor = 0;
> +
> + if (dev->device != NULL && strlen(dev->device) == 4)
> + if (sscanf(dev->device, "%hx", &card->pci_device) != 1)
> + card->pci_device = 0;
> }
>
> /*
> @@ -852,6 +911,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 +943,23 @@ igt_devs_print_user(struct igt_list_head *view,
> continue;
>
> if (pci_dev) {
> + uint16_t vendor, device;
> + char *devname;
> + devname_fn fn = devname_hex;
> +
> + if (!fmt->numeric)
> + fn = get_pci_vendor_device_fn(pci_dev->vendor);
Nit - maybe I would assing devname_hex so the flow of fn assignment is
totally consolidated and obvious.
> +
> + get_pci_vendor_device(pci_dev, &vendor, &device);
> + devname = fn(vendor, device);
> +
> __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 +991,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");
> }
> diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
> index bb4be723..42066eeb 100644
> --- a/lib/igt_device_scan.h
> +++ b/lib/igt_device_scan.h
> @@ -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);
>
Regards,
Tvrtko
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header Zbigniew Kempczyński
@ 2020-11-18 10:04 ` Tvrtko Ursulin
0 siblings, 0 replies; 7+ messages in thread
From: Tvrtko Ursulin @ 2020-11-18 10:04 UTC (permalink / raw)
To: Zbigniew Kempczyński, igt-dev; +Cc: Petri Latvala, Tvrtko Ursulin
On 17/11/2020 16:34, Zbigniew Kempczyński wrote:
> In multi device world we may want to see generation of device we're
> tracking counters. Add generation number/codename to be more verbose.
>
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Petri Latvala <petri.latvala@intel.com>
> ---
> lib/Makefile.am | 4 +++-
> lib/meson.build | 1 +
> tools/intel_gpu_top.c | 18 ++++++++++++++++--
> 3 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/lib/Makefile.am b/lib/Makefile.am
> index fecf34cd..c476eeab 100644
> --- a/lib/Makefile.am
> +++ b/lib/Makefile.am
> @@ -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 \
> diff --git a/lib/meson.build b/lib/meson.build
> index 090a10cd..540facb2 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -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)
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index 86de09aa..399416c3 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -22,6 +22,7 @@
> */
>
> #include "igt_device_scan.h"
> +#include "intel_chipset.h"
>
> #include <stdio.h>
> #include <sys/types.h>
> @@ -1028,9 +1029,12 @@ static bool print_groups(struct cnt_group **groups)
>
> static int
> print_header(const struct igt_device_card *card,
> + const struct intel_device_info *info,
> struct engines *engines, double t,
> int lines, int con_w, int con_h, bool *consumed)
> {
> + static char *codename;
> + unsigned int gen = info ? ffs(info->gen) : 0;
> struct pmu_counter fake_pmu = {
> .present = true,
> .val.cur = 1,
> @@ -1106,8 +1110,15 @@ print_header(const struct igt_device_card *card,
> if (output_mode == INTERACTIVE) {
> printf("\033[H\033[J");
>
> + if (!codename) {
> + codename = info->codename ? strdup(info->codename) :
> + strdup("unknown");
> + codename[0] = toupper(codename[0]);
> + }
> +
> if (lines++ < con_h) {
> - printf("intel-gpu-top: %s - ", card->card);
> + printf("intel-gpu-top: %s (Gen%u) @ %s - ",
> + codename, gen, card->card);
Leaks codename and lets try and avoid code duplication. And print hex
string if unknown - so same comments as in previous patch.
> 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 +1328,7 @@ int main(int argc, char **argv)
> bool list_device = false;
> char *pmu_device, *opt_device = NULL;
> struct igt_device_card card;
> + const struct intel_device_info *info = NULL;
>
> /* Parse options */
> while ((ch = getopt(argc, argv, "o:s:d:JLlh")) != -1) {
> @@ -1441,6 +1453,8 @@ int main(int argc, char **argv)
> ret = EXIT_SUCCESS;
>
> pmu_sample(engines);
> + if (card.pci_device)
> + info = intel_get_device_info(card.pci_device);
>
> while (!stop_top) {
> bool consumed = false;
> @@ -1463,7 +1477,7 @@ int main(int argc, char **argv)
> break;
>
> while (!consumed) {
> - lines = print_header(&card, engines,
> + lines = print_header(&card, info, engines,
> t, lines, con_w, con_h,
> &consumed);
>
>
I would really prefer print_header would not need to rebuild the pretty
string every time. And also that we try and limit adding new arguments
to it. So I have this idea:
Add the pretty string to struct engines and build it once on probe.
Probably change discover_engines to take the card and move the block
which figures out the pmu_device into the function. It can then build
the pretty string and store in engines->codename / engines->drm_card or
something.
Since I am bikeshedding a lot I am happy to take over the intel_gpu_top
patch at least. But if you feel these suggestions are solid also feel
free to carry on yourself.
Regards,
Tvrtko
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices
2020-11-18 9:56 ` [igt-dev] [PATCH i-g-t v3 1/3] " Tvrtko Ursulin
@ 2020-11-18 12:10 ` Zbigniew Kempczyński
0 siblings, 0 replies; 7+ messages in thread
From: Zbigniew Kempczyński @ 2020-11-18 12:10 UTC (permalink / raw)
To: Tvrtko Ursulin; +Cc: igt-dev, Petri Latvala, Tvrtko Ursulin
On Wed, Nov 18, 2020 at 09:56:43AM +0000, Tvrtko Ursulin wrote:
>
> On 17/11/2020 16:34, Zbigniew Kempczyński wrote:
> > If we want to use pci device id for not opened device we need to
> > keep it in card structure.
> >
> > Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
> > Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > Cc: Petri Latvala <petri.latvala@intel.com>
> > ---
> > lib/igt_device_scan.c | 88 +++++++++++++++++++++++++++++++++++++++----
> > lib/igt_device_scan.h | 2 +
> > 2 files changed, 82 insertions(+), 8 deletions(-)
> >
> > diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
> > index e97f7163..6c8ab8b1 100644
> > --- a/lib/igt_device_scan.c
> > +++ b/lib/igt_device_scan.c
> > @@ -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,39 @@ 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);
>
> -1 or 9 are the only possible returns here, okay.
>
> > +
> > + return s;
> > +}
> > +
> > +static char *devname_intel(uint16_t vendor, uint16_t device)
>
> Plan export so later patch to intel_gpu_top does not need to re-implement
> it?
Hmm, didn't plan it before but is most reasonable option.
>
> > +{
> > + const struct intel_device_info *info = intel_get_device_info(device);
> > + char *devname, *s;
> > +
> > + (void) vendor;
> > +
> > + devname = info->codename ? strdup(info->codename) : strdup("unknown");
>
> 1) Leaks devname?
> 2) I think hex value would be better if unknown.
Yes, missed that.
>
> > + devname[0] = toupper(devname[0]);
> > +
> > + asprintf(&s, "Intel %s (Gen%u)", devname, ffs(info->gen));
> > +
> > + 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 +227,26 @@ static const char *get_pci_vendor_id_by_name(const char *name)
> > return NULL;
> > }
> > +static devname_fn get_pci_vendor_device_fn(const char *vendor_id)
> > +{
> > + for (typeof(*pci_vendor_mapping) *vm = pci_vendor_mapping; vm->name; vm++) {
> > + if (!strcasecmp(vendor_id, 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);
> > +}
> > +
> > /* Reading sysattr values can take time (even seconds),
> > * we want to avoid reading such keys.
> > */
> > @@ -460,9 +509,19 @@ __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
> > strncpy(card->render, dev->drm_render,
> > sizeof(card->render) - 1);
> > - if (dev->pci_slot_name != NULL)
> > + if (dev->pci_slot_name != NULL) {
> > strncpy(card->pci_slot_name, dev->pci_slot_name,
> > - PCI_SLOT_NAME_SIZE + 1);
> > + PCI_SLOT_NAME_SIZE);
> > + card->pci_slot_name[PCI_SLOT_NAME_SIZE] = '\0';
>
> I would still prefer the same "sizeof - 1" pattern as the other copies in
> this function.
>
> Then indeed ensuring strings are null terminated is something which could be
> added to all. Possibly a local wrapper on strncpy?
>
> PCI slot length is probably the most defined of the bunch so it feels wrong
> to have safest handling compared to other strings.
Ok, I'm going to add safe_strncpy() local wrapper for this situation.
>
> > + }
> > +
> > + if (dev->vendor != NULL && strlen(dev->vendor) == 4)
>
> Can strlen be not four here in some situations or this could be an assert
> just as well?
You're right, we parse PCI_ID so we're sure vendor/device strings
have length 4.
>
> > + if (sscanf(dev->vendor, "%hx", &card->pci_vendor) != 1)
> > + card->pci_vendor = 0;
> > +
> > + if (dev->device != NULL && strlen(dev->device) == 4)
> > + if (sscanf(dev->device, "%hx", &card->pci_device) != 1)
> > + card->pci_device = 0;
> > }
> > /*
> > @@ -852,6 +911,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 +943,23 @@ igt_devs_print_user(struct igt_list_head *view,
> > continue;
> > if (pci_dev) {
> > + uint16_t vendor, device;
> > + char *devname;
> > + devname_fn fn = devname_hex;
> > +
> > + if (!fmt->numeric)
> > + fn = get_pci_vendor_device_fn(pci_dev->vendor);
>
> Nit - maybe I would assing devname_hex so the flow of fn assignment is
> totally consolidated and obvious.
Ok.
>
> > +
> > + get_pci_vendor_device(pci_dev, &vendor, &device);
> > + devname = fn(vendor, device);
> > +
> > __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 +991,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");
> > }
> > diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
> > index bb4be723..42066eeb 100644
> > --- a/lib/igt_device_scan.h
> > +++ b/lib/igt_device_scan.h
> > @@ -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);
> >
>
> Regards,
>
> Tvrtko
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-11-18 12:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-17 16:34 [igt-dev] [PATCH i-g-t v3 1/3] lib/igt_device_scan: Remember vendor/device for pci devices Zbigniew Kempczyński
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header Zbigniew Kempczyński
2020-11-18 10:04 ` Tvrtko Ursulin
2020-11-17 16:34 ` [igt-dev] [PATCH i-g-t v3 3/3] tools/lsgpu: Add -n switch to list devices using vendor:device hex id Zbigniew Kempczyński
2020-11-17 18:50 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,v3,1/3] lib/igt_device_scan: Remember vendor/device for pci devices Patchwork
2020-11-18 9:56 ` [igt-dev] [PATCH i-g-t v3 1/3] " Tvrtko Ursulin
2020-11-18 12:10 ` Zbigniew Kempczyński
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox