From 32645f25a6dbb5b32c78f1bcdfd6f52ec68662fa Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Mon, 22 Jul 2019 07:09:53 -0500 Subject: [PATCH] Add rsmi_dev_serial_number_get() Also correct whitespace issues Change-Id: I7ffe23672304c31ed08d7148b04a19a7d4c3d7ef [ROCm/rocm_smi_lib commit: cf13d6f4d88ad15c1b366e77625947160e659517] --- .../rocm-smi-lib/include/rocm_smi/rocm_smi.h | 23 +++++++++++++++ .../include/rocm_smi/rocm_smi_device.h | 1 + projects/rocm-smi-lib/src/rocm_smi.cc | 29 ++++++++++++++++++- projects/rocm-smi-lib/src/rocm_smi_device.cc | 3 ++ .../rocm_smi_test/functional/id_info_read.cc | 12 ++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h index a9d49c305e..007d9cb930 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -782,6 +782,29 @@ rsmi_status_t rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len); */ rsmi_status_t rsmi_dev_vendor_name_get(uint32_t id, char *name, size_t len); +/** + * @brief Get the serial number string for a device + * + * @details Given a device index @p dv_ind, a pointer to a buffer of chars + * @p serial_num, and the length of the provided buffer @p len, this function + * will write the serial number string (up to @p len characters) to the buffer + * pointed to by @p serial_num. + * + * @param[in] dv_ind a device index + * + * @param[inout] serial_num a pointer to caller-provided memory to which the + * serial number will be written + * + * @param[in] len the length of the caller provided buffer @p serial_num. + * + * @retval ::RSMI_STATUS_SUCCESS is returned upon successful call. + * @retval ::RSMI_STATUS_INSUFFICIENT_SIZE is returned if @p len bytes is not + * large enough to hold the entire name. In this case, only @p len bytes will + * be written. + * + */ +rsmi_status_t rsmi_dev_serial_number_get(uint32_t dv_ind, + char *serial_num, uint32_t len); /** * @brief Get the subsystem device id associated with the device with * provided device index. diff --git a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_device.h b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_device.h index 03c3a777f3..9905835582 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_device.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_device.h @@ -118,6 +118,7 @@ enum DevInfoTypes { kDevFwVersionUvd, kDevFwVersionVce, kDevFwVersionVcn, + kDevSerialNumber, }; class Device { diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index 7e6de08bf7..dc510bcd90 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -1428,7 +1428,6 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name, static rsmi_status_t get_dev_drm_render_minor(uint32_t dv_ind, uint32_t *minor) { - GET_DEV_FROM_INDX *minor = dev->drm_render_minor(); @@ -2244,6 +2243,34 @@ rsmi_version_str_get(rsmi_sw_component_t component, char *ver_str, CATCH } +rsmi_status_t rsmi_dev_serial_number_get(uint32_t dv_ind, + char *serial_num, uint32_t len) { + if (serial_num == nullptr || len == 0) { + return RSMI_STATUS_INVALID_ARGS; + } + + TRY + + std::string val_str; + rsmi_status_t ret = get_dev_value_str(amd::smi::kDevSerialNumber, + dv_ind, &val_str); + + if (ret != RSMI_STATUS_SUCCESS) { + return ret; + } + + uint32_t ln = val_str.copy(serial_num, len); + + serial_num[std::min(len - 1, ln)] = '\0'; + + if (len < (val_str.size() + 1)) { + return RSMI_STATUS_INSUFFICIENT_SIZE; + } + return RSMI_STATUS_SUCCESS; + + CATCH +} + rsmi_status_t rsmi_dev_pci_replay_counter_get(uint32_t dv_ind, uint64_t *counter) { TRY diff --git a/projects/rocm-smi-lib/src/rocm_smi_device.cc b/projects/rocm-smi-lib/src/rocm_smi_device.cc index f399bdc000..5090244efe 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_device.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_device.cc @@ -102,6 +102,7 @@ static const char *kDevUniqueIdFName = "unique_id"; static const char *kDevDFCountersAvailableFName = "df_cntr_avail"; static const char *kDevMemBusyPercentFName = "mem_busy_percent"; static const char *kDevXGMIErrorFName = "xgmi_error"; +static const char *kDevSerialNumberFName = "serial_number"; // Strings that are found within sysfs files static const char *kDevPerfLevelAutoStr = "auto"; @@ -192,6 +193,7 @@ static const std::map kDevAttribNameMap = { {kDevFwVersionUvd, kDevFwVersionUvdFName}, {kDevFwVersionVce, kDevFwVersionVceFName}, {kDevFwVersionVcn, kDevFwVersionVcnFName}, + {kDevSerialNumber, kDevSerialNumberFName}, }; static const std::map kDevPerfLvlMap = { @@ -505,6 +507,7 @@ int Device::readDevInfo(DevInfoTypes type, std::string *val) { case kDevVendorID: case kDevVBiosVer: case kDevPCIEThruPut: + case kDevSerialNumber: return readDevInfoStr(type, val); break; diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/id_info_read.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/id_info_read.cc index 9eb88643c3..92ca8f7d6c 100755 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/id_info_read.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/id_info_read.cc @@ -195,5 +195,17 @@ void TestIdInfoRead::Run(void) { std::cout << "\t**PCI ID (BDFID): 0x" << std::hex << val_ui64; std::cout << " (" << std::dec << val_ui64 << ")" << std::endl; } + + err = rsmi_dev_serial_number_get(i, buffer, kBufferLen); + if (err == RSMI_STATUS_NOT_SUPPORTED) { + std::cout << + "\t**Serial Number string not supported on this system." << std::endl; + } else if (err != RSMI_STATUS_SUCCESS) { + CHK_ERR_ASRT(err) + } else { + IF_VERB(STANDARD) { + std::cout << "\t**Device Serial Number:" << buffer << std::endl; + } + } } }