From 9fa8519b3898e64cfffdbd4b611c8fdb804979fb Mon Sep 17 00:00:00 2001 From: Chris Freehill <13054697+cfreehill@users.noreply.github.com> Date: Thu, 16 May 2019 16:15:17 -0500 Subject: [PATCH] If vendor/device/subsystem name is not found, use device ID string (#41) * If vendor/device/subsystem name is not found, use device ID string [ROCm/amdsmi commit: 59538cd0042668d0c9595204b9a7ab546f42a2f3] --- projects/amdsmi/include/rocm_smi/rocm_smi.h | 18 ++++++++++ projects/amdsmi/src/rocm_smi.cc | 39 +++++++++++++++++---- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/projects/amdsmi/include/rocm_smi/rocm_smi.h b/projects/amdsmi/include/rocm_smi/rocm_smi.h index acf27e7718..c0f1ed38c0 100755 --- a/projects/amdsmi/include/rocm_smi/rocm_smi.h +++ b/projects/amdsmi/include/rocm_smi/rocm_smi.h @@ -595,6 +595,12 @@ rsmi_status_t rsmi_dev_vendor_id_get(uint32_t dv_ind, uint16_t *id); * will write the name of the device (up to @p len characters) to the buffer * @p name. * + * If the integer ID associated with the device is not found in one of the + * system files containing device name information (e.g. + * /usr/share/misc/pci.ids), then this function will return the hex device ID + * as a string. Updating the system name files can be accompplished with + * "sudo update-pciids". + * * @param[in] dv_ind a device index * * @param[inout] name a pointer to a caller provided char buffer to which the @@ -618,6 +624,12 @@ rsmi_status_t rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len); * name of the vendor (up to @p len characters) buffer @p name. The @p id may * be a device vendor or subsystem vendor ID. * + * If the integer ID associated with the vendor is not found in one of the + * system files containing device name information (e.g. + * /usr/share/misc/pci.ids), then this function will return the hex vendor ID + * as a string. Updating the system name files can be accompplished with + * "sudo update-pciids". + * * @param[in] id a vendor ID * * @param[inout] name a pointer to a caller provided char buffer to which the @@ -659,6 +671,12 @@ rsmi_status_t rsmi_dev_subsystem_id_get(uint32_t dv_ind, uint16_t *id); * will write the name of the device subsystem (up to @p len characters) * to the buffer @p name. * + * If the integer ID associated with the sub-system is not found in one of the + * system files containing device name information (e.g. + * /usr/share/misc/pci.ids), then this function will return the hex sub-system + * ID as a string. Updating the system name files can be accompplished with + * "sudo update-pciids". + * * @param[in] dv_ind a device index * * @param[inout] name a pointer to a caller provided char buffer to which the diff --git a/projects/amdsmi/src/rocm_smi.cc b/projects/amdsmi/src/rocm_smi.cc index fe33abed07..c9951af2a9 100755 --- a/projects/amdsmi/src/rocm_smi.cc +++ b/projects/amdsmi/src/rocm_smi.cc @@ -1180,6 +1180,27 @@ get_id_name_str_from_line(uint64_t id, std::string ln, return ret_str; } +static rsmi_status_t get_backup_name(uint16_t id, char *name, + size_t len, eNameStrType typ) { + std::string name_str; + + name_str += "0x"; + + std::stringstream strm; + strm << std::hex << id; + name_str += strm.str(); + + name[0] = '\0'; + size_t ct = name_str.copy(name, len); + + name[std::min(len - 1, ct)] = '\0'; + + if (len < (name_str.size() + 1)) { + return RSMI_STATUS_INSUFFICIENT_SIZE; + } + return RSMI_STATUS_SUCCESS; +} + // Parse pci.ids files. Comment lines have # in first column. Otherwise, // Syntax: // vendor vendor_name @@ -1264,10 +1285,13 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name, } } else { // ln[0] != '\t'; Vendor line if (found_device_vendor) { + assert(typ != NAME_STR_VENDOR); // We already found the vendor but didn't find the device or // subsystem we were looking for, so bail out. val_str.clear(); - return RSMI_STATUS_NOT_FOUND; + + return get_backup_name(typ == NAME_STR_DEVICE ? + device_id : subsys_id, name, len, typ); } val_str = get_id_name_str_from_line(vendor_id, ln, &ln_str); @@ -1287,6 +1311,12 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name, } } + if (val_str.size() == 0) { + // We should have already returned if we were looking for + // device or subdivce + assert(typ == NAME_STR_VENDOR); + return get_backup_name(vendor_id, name, len, typ); + } size_t ct = val_str.copy(name, len); name[std::min(len - 1, ct)] = '\0'; @@ -1309,11 +1339,8 @@ rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len) { DEVICE_MUTEX ret = get_dev_name_from_id(dv_ind, name, len, NAME_STR_DEVICE); - if (ret != RSMI_STATUS_SUCCESS) { - return ret; - } - return RSMI_STATUS_SUCCESS; + return ret; CATCH } @@ -2068,7 +2095,6 @@ rsmi_version_str_get(rsmi_sw_component_t component, char *ver_str, rsmi_status_t rsmi_dev_pci_replay_counter_get(uint32_t dv_ind, uint64_t *counter) { TRY - DEVICE_MUTEX rsmi_status_t ret; @@ -2077,3 +2103,4 @@ rsmi_dev_pci_replay_counter_get(uint32_t dv_ind, uint64_t *counter) { CATCH } +