lib/igt_device_scan: Remember vendor/device for pci devices
Subsystems (2)
PATCH v3 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.
--- lib/igt_device_scan.c | 88 +++++++++++++++++++++++++++++++++++++++---- lib/igt_device_scan.h | 2 + 2 files changed, 82 insertions(+), 8 deletions(-)
lib/igt_device_scan.c +80 -8
@@ -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 30static 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" ); }
lib/igt_device_scan.h +2 -0
@@ -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);
Signature · 6 lines
2.26.0 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
PATCH v3 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 generation number/codename to be more verbose.
--- lib/Makefile.am | 4 +++- lib/meson.build | 1 + tools/intel_gpu_top.c | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-)
lib/Makefile.am +3 -1
@@ -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
@@ -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 +16 -2
@@ -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);
Signature · 6 lines
2.26.0 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
Re: [igt-dev] [PATCH i-g-t v3 2/3] tools/intel_gpu_top: Add generation info in header
Quoted 68 lines · Zbigniew Kempczyński
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 <[email protected]>Cc Tvrtko Ursulin <[email protected]>Cc Petri Latvala <[email protected]>--- lib/Makefile.am | 4 +++- lib/meson.build | 1 + tools/intel_gpu_top.c | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-)lib/Makefile.am +3
-1@@ -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@@ -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 +4
-0@@ -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" );
tools/intel_gpu_top.c print_header(const struct igt_device_card *card, · line 1121
Quoted 10 lines
tools/intel_gpu_top.c +8
-1+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.
Quoted 22 lines
tools/intel_gpu_top.c +3
-0if (!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;
tools/intel_gpu_top.c int main(int argc, char **argv) · line 1483
Quoted 8 lines
tools/intel_gpu_top.c +1
-1@@ -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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
PATCH v3 3/3 tools/lsgpu: Add -n switch to list devices using vendor:device hex id
In reply to Zbigniew KempczyńskiDefault 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
@@ -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
Patchwork
CI[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
In reply to Zbigniew Kempczyński== Series Details ==
== 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@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-byt-j1900/igt@[email protected]
#### 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@[email protected]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-byt-j1900/igt@[email protected]
* 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@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_5181/fi-icl-u2/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#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
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Quoted 26 lines · Zbigniew Kempczyński
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 <[email protected]>Cc Tvrtko Ursulin <[email protected]>Cc Petri Latvala <[email protected]>--- lib/igt_device_scan.c | 88 +++++++++++++++++++++++++++++++++++++++---- lib/igt_device_scan.h | 2 + 2 files changed, 82 insertions(+), 8 deletions(-)lib/igt_device_scan.c +2
-0@@ -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>
lib/igt_device_scan.c static struct { · line 189
Quoted 10 lines
lib/igt_device_scan.c +7
-0@@ -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.
lib/igt_device_scan.c static struct { · line 194
Quoted 5 lines
lib/igt_device_scan.c +5
-0+ +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?
lib/igt_device_scan.c static struct { · line 201
Quoted 7 lines
lib/igt_device_scan.c +7
-0+{ +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.
Quoted 47 lines
lib/igt_device_scan.c +30
-2+ 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. */
lib/igt_device_scan.c __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card) · line 515
Quoted 9 lines
lib/igt_device_scan.c +3
-2@@ -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.
lib/igt_device_scan.c __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card) · line 518
Quoted 3 lines
lib/igt_device_scan.c +3
-0+ } + +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?
Quoted 18 lines
lib/igt_device_scan.c +7
-0+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 30static void igt_devs_print_user (struct igt_list_head *view,const struct igt_devices_print_format *fmt)
lib/igt_device_scan.c igt_devs_print_user(struct igt_list_head *view, · line 951
Quoted 9 lines
lib/igt_device_scan.c +6
-0@@ -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.
Quoted 40 lines
lib/igt_device_scan.c +10
-4+ +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" ); }lib/igt_device_scan.h +1
-0@@ -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"
lib/igt_device_scan.h struct igt_device_card { · line 65
Quoted 7 lines
lib/igt_device_scan.h +1
-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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Quoted 39 lines · Tvrtko Ursulin
Quoted 25 lines · Zbigniew Kempczyński
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 <[email protected]>Cc Tvrtko Ursulin <[email protected]>Cc Petri Latvala <[email protected]>--- lib/igt_device_scan.c | 88 +++++++++++++++++++++++++++++++++++++++---- lib/igt_device_scan.h | 2 + 2 files changed, 82 insertions(+), 8 deletions(-)lib/igt_device_scan.c +2
-0@@ -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> lib/igt_device_scan.c static struct { · line 188
Quoted 9 lines
lib/igt_device_scan.c +7
-0@@ -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.
Quoted 8 lines
lib/igt_device_scan.c static struct { · line 194
Quoted 5 lines
lib/igt_device_scan.c +5
-0+ +return s; +} + +static char *devname_intel (uint16_t vendor,uint16_t device)Plan export so later patch to
intel_gpu_topdoes not need to re-implement it?
Hmm, didn't plan it before but is most reasonable option.
Quoted 11 lines
lib/igt_device_scan.c static struct { · line 201
Quoted 8 lines
lib/igt_device_scan.c +7
-0+{ +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.
Quoted 58 lines
Quoted 46 lines
lib/igt_device_scan.c +30
-2+ 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. */ lib/igt_device_scan.c __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card) · line 514
Quoted 8 lines
lib/igt_device_scan.c +3
-2@@ -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.
Quoted 5 lines
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.
Quoted 7 lines
lib/igt_device_scan.c __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card) · line 518
Quoted 4 lines
lib/igt_device_scan.c +3
-0+ } + +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.
Quoted 20 lines
Quoted 20 lines
lib/igt_device_scan.c +8
-0+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 30static 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;
Quoted 8 lines
lib/igt_device_scan.c igt_devs_print_user(struct igt_list_head *view, · line 951
Quoted 5 lines
lib/igt_device_scan.c +5
-0+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_hexso the flow of fn assignment is totally consolidated and obvious.
Ok.
Quoted 49 lines
Quoted 39 lines
lib/igt_device_scan.c +10
-4+ +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" ); }lib/igt_device_scan.h +1
-0@@ -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"lib/igt_device_scan.h struct igt_device_card { · line 65
Quoted 7 lines
lib/igt_device_scan.h +1
-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,
Quoted 1 line
Tvrtko
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev