From a42ab41d65944ea96bf65cf74b4260890cd2bd75 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Wed, 24 Apr 2019 17:46:53 -0500 Subject: [PATCH] Added rsmi_version_str_get() [ROCm/rocm_smi_lib commit: bb73c2607ff5255f86f3b2e90f5efe5614ca677b] --- .../rocm-smi-lib/include/rocm_smi/rocm_smi.h | 51 +++++++++++++-- projects/rocm-smi-lib/src/rocm_smi.cc | 62 ++++++++++++++++++- .../rocm_smi_test/functional/power_read.cc | 2 +- .../rocm_smi_test/functional/version_read.cc | 20 ++++++ 4 files changed, 128 insertions(+), 7 deletions(-) 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 5b9dd47a07..f6b20536ae 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -144,6 +144,18 @@ typedef rsmi_dev_perf_level_t rsmi_dev_perf_level; /** * @brief Available clock types. */ + +/** + * @brief Software components + */ +typedef enum { + RSMI_SW_COMP_FIRST = 0x0, + + RSMI_SW_COMP_DRIVER = RSMI_SW_COMP_FIRST, //!< Driver + + RSMI_SW_COMP_LAST = RSMI_SW_COMP_DRIVER +} rsmi_sw_component_t; + typedef enum { RSMI_CLK_TYPE_SYS = 0x0, //!< System clock RSMI_CLK_TYPE_FIRST = RSMI_CLK_TYPE_SYS, @@ -174,22 +186,29 @@ typedef enum { RSMI_TEMP_MAX, //!< Temperature max value. RSMI_TEMP_MIN, //!< Temperature min value. RSMI_TEMP_MAX_HYST, //!< Temperature hysteresis value for max limit. + //!< (This is an absolute temperature, not a + //!< delta). RSMI_TEMP_MIN_HYST, //!< Temperature hysteresis value for min limit. + //!< (This is an absolute temperature, + //!< not a delta). RSMI_TEMP_CRITICAL, //!< Temperature critical max value, typically //!< greater than corresponding temp_max values. RSMI_TEMP_CRITICAL_HYST, //!< Temperature hysteresis value for critical - //!< limit. + //!< limit. (This is an absolute temperature, + //!< not a delta). RSMI_TEMP_EMERGENCY, //!< Temperature emergency max value, for chips //!< supporting more than two upper temperature //!< limits. Must be equal or greater than //!< corresponding temp_crit values. RSMI_TEMP_EMERGENCY_HYST, //!< Temperature hysteresis value for emergency - //!< limit. + //!< limit. (This is an absolute temperature, + //!< not a delta). RSMI_TEMP_CRIT_MIN, //!< Temperature critical min value, typically //!< lower than corresponding temperature //!< minimum values. RSMI_TEMP_CRIT_MIN_HYST, //!< Temperature hysteresis value for critical - //!< minimum limit. + //!< minimum limit. (This is an absolute + //!< temperature, not a delta). RSMI_TEMP_OFFSET, //!< Temperature offset which is added to the //! temperature reading by the chip. RSMI_TEMP_LOWEST, //!< Historical minimum temperature. @@ -440,7 +459,7 @@ typedef rsmi_od_volt_curve_t rsmi_od_volt_curve; typedef struct { rsmi_range_t curr_sclk_range; //!< The current SCLK frequency range rsmi_range_t curr_mclk_range; //!< The current MCLK frequency range; - //!< (upper bound only) + //!< (upper bound only) rsmi_range_t sclk_freq_limits; //!< The range possible of SCLK values rsmi_range_t mclk_freq_limits; //!< The range possible of MCLK values @@ -1387,6 +1406,30 @@ rsmi_status_t rsmi_dev_od_freq_range_set(uint32_t dv_ind, rsmi_clk_type_t clk, rsmi_status_t rsmi_version_get(rsmi_version_t *version); +/** + * @brief Get the driver version string for the current system. + * + * @details Given a software component @p component, a pointer to a char + * buffer, @p ver_str, this function will write the driver version string + * (up to @p len characters) for the current system to @p ver_str. The caller + * must ensure that it is safe to write at least @p len characters to @p + * ver_str. + * + * @param[in] component The component for which the version string is being + * requested + * + * @param[inout] ver_str A pointer to a buffer of char's to which the VBIOS + * name will be written + * + * @param[in] len The number of char's pointed to by @p ver_str which can + * safely be written to by this function. + * + * @retval ::RSMI_STATUS_SUCCESS is returned upon successful call. + */ +rsmi_status_t +rsmi_version_str_get(rsmi_sw_component_t component, char *ver_str, + uint32_t len); + /** * @brief Get the VBIOS identifer string * diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index 4ddad121ff..2da8a54ba4 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -1231,7 +1232,7 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name, name[std::min(len - 1, ct)] = '\0'; - if (len < val_str.size()) { + if (len < (val_str.size() + 1)) { return RSMI_STATUS_INSUFFICIENT_SIZE; } @@ -1872,11 +1873,18 @@ rsmi_dev_vbios_version_get(uint32_t dv_ind, char *vbios, uint32_t len) { std::string val_str; int ret = dev->readDevInfo(amd::smi::kDevVBiosVer, &val_str); + if (ret != 0) { + return errno_to_rsmi_status(ret); + } + uint32_t ln = val_str.copy(vbios, len); vbios[std::min(len - 1, ln)] = '\0'; - return errno_to_rsmi_status(ret); + if (len < (val_str.size() + 1)) { + return RSMI_STATUS_INSUFFICIENT_SIZE; + } + return RSMI_STATUS_SUCCESS; CATCH } @@ -1897,3 +1905,53 @@ rsmi_version_get(rsmi_version_t *version) { CATCH } + +static const char *kROCmDriverVersionPath = "/sys/module/amdgpu/version"; + +rsmi_status_t +rsmi_version_str_get(rsmi_sw_component_t component, char *ver_str, + uint32_t len) { + if (ver_str == nullptr || len == 0) { + return RSMI_STATUS_INVALID_ARGS; + } + + TRY + + int err; + std::string val_str; + std::string ver_path; + + switch (component) { + case RSMI_SW_COMP_DRIVER: + ver_path = kROCmDriverVersionPath; + break; + + default: + assert(!"Unexpected component type provided"); + return RSMI_STATUS_INVALID_ARGS; + } + + err = amd::smi::ReadSysfsStr(ver_path, &val_str); + + if (err != 0) { + struct utsname buf; + err = uname(&buf); + + if (err != 0) { + return errno_to_rsmi_status(err); + } + + val_str = buf.release; + } + + uint32_t ln = val_str.copy(ver_str, len); + + ver_str[std::min(len - 1, ln)] = '\0'; + + if (len < (val_str.size() + 1)) { + return RSMI_STATUS_INSUFFICIENT_SIZE; + } + return RSMI_STATUS_SUCCESS; + + CATCH +} diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/power_read.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/power_read.cc index f3396caf39..bef80da4bb 100755 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/power_read.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/power_read.cc @@ -111,7 +111,7 @@ void TestPowerRead::Run(void) { std::cout << "\t**Averge Power Usage: "; CHK_RSMI_PERM_ERR(err) if (err == RSMI_STATUS_SUCCESS) { - std::cout << static_cast(val_ui64)/1000 << " W" << std::endl; + std::cout << static_cast(val_ui64)/1000 << " mW" << std::endl; } } } diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/version_read.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/version_read.cc index 5e819a19bd..6133286645 100755 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/version_read.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/version_read.cc @@ -47,6 +47,7 @@ #include #include +#include #include "gtest/gtest.h" #include "rocm_smi/rocm_smi.h" @@ -83,6 +84,12 @@ void TestVersionRead::Close() { TestBase::Close(); } +static const uint32_t kVerMaxStrLen = 80; + +static const std::map + kComponentNameMap = { + {RSMI_SW_COMP_DRIVER, "Driver Version"}, +}; void TestVersionRead::Run(void) { rsmi_status_t err; @@ -99,4 +106,17 @@ void TestVersionRead::Run(void) { std::cout << "\t**RocM SMI Library version: " << ver.major << "." << ver.minor << "." << ver.patch << " (" << ver.build << ")" << std::endl; } + + char ver_str[kVerMaxStrLen]; + + for (uint32_t cmp = RSMI_SW_COMP_FIRST; cmp <= RSMI_SW_COMP_LAST; ++cmp) { + err = rsmi_version_str_get(static_cast(cmp), + ver_str, kVerMaxStrLen); + CHK_ERR_ASRT(err) + + IF_VERB(STANDARD) { + std::cout << "\t**" << kComponentNameMap.at(cmp) << ": " << + ver_str << std::endl; + } + } }