From 106c87ad0e3c339d4f7fd1fee547c7465d140f00 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Mon, 4 Nov 2019 13:45:47 -0600 Subject: [PATCH] Docs., error checking and test improvements * Update doc. on api-support function * Check for valid integer value when reading a monitor int. val. * If fan-write test attempts to set speed higher than max. possible, then skip the test Change-Id: I01ad0ab1f4caffdb0d2c26e9575f278c35a6b017 [ROCm/amdsmi commit: 52dfa4bccab015bd6a53704f50f7f53957c555cc] --- projects/amdsmi/include/rocm_smi/rocm_smi.h | 6 ++++++ projects/amdsmi/include/rocm_smi/rocm_smi_utils.h | 2 ++ projects/amdsmi/src/rocm_smi.cc | 6 ++++++ projects/amdsmi/src/rocm_smi_utils.cc | 12 ++++++++++++ .../tests/rocm_smi_test/functional/fan_read_write.cc | 11 +++++++++++ 5 files changed, 37 insertions(+) diff --git a/projects/amdsmi/include/rocm_smi/rocm_smi.h b/projects/amdsmi/include/rocm_smi/rocm_smi.h index 798ba579b0..93b78d67de 100755 --- a/projects/amdsmi/include/rocm_smi/rocm_smi.h +++ b/projects/amdsmi/include/rocm_smi/rocm_smi.h @@ -2636,6 +2636,12 @@ rsmi_dev_xgmi_error_reset(uint32_t dv_ind); * iterator handle to the caller-provided memory pointed to by @p handle. This * handle can be used to iterate through all the supported functions. * + * Note that although this function takes in @p dv_ind as an argument, + * ::rsmi_dev_supported_func_iterator_open itself will not be among the + * functions listed as supported. This is because + * ::rsmi_dev_supported_func_iterator_open does not depend on hardware or + * driver support and should always be supported. + * * @param[in] dv_ind a device index of device for which support information is * requested * diff --git a/projects/amdsmi/include/rocm_smi/rocm_smi_utils.h b/projects/amdsmi/include/rocm_smi/rocm_smi_utils.h index 7b2ccbf113..3bf131f3ca 100755 --- a/projects/amdsmi/include/rocm_smi/rocm_smi_utils.h +++ b/projects/amdsmi/include/rocm_smi/rocm_smi_utils.h @@ -69,6 +69,8 @@ int isRegularFile(std::string fname, bool *is_reg); int ReadSysfsStr(std::string path, std::string *retStr); int WriteSysfsStr(std::string path, std::string val); +bool IsInteger(const std::string & n_str); + struct pthread_wrap { public: explicit pthread_wrap(pthread_mutex_t &p_mut) : mutex_(p_mut) {} diff --git a/projects/amdsmi/src/rocm_smi.cc b/projects/amdsmi/src/rocm_smi.cc index d2c6b793e7..91f1747383 100755 --- a/projects/amdsmi/src/rocm_smi.cc +++ b/projects/amdsmi/src/rocm_smi.cc @@ -408,6 +408,12 @@ static rsmi_status_t get_dev_mon_value(amd::smi::MonitorTypes type, return errno_to_rsmi_status(ret); } + if (!amd::smi::IsInteger(val_str)) { + std::cerr << "Expected integer value, but got \"" << val_str << "\"" << + std::endl; + } + assert(amd::smi::IsInteger(val_str)); + *val = std::stoul(val_str); return RSMI_STATUS_SUCCESS; diff --git a/projects/amdsmi/src/rocm_smi_utils.cc b/projects/amdsmi/src/rocm_smi_utils.cc index 6a150faf33..c12e0b7de0 100755 --- a/projects/amdsmi/src/rocm_smi_utils.cc +++ b/projects/amdsmi/src/rocm_smi_utils.cc @@ -140,5 +140,17 @@ int ReadSysfsStr(std::string path, std::string *retStr) { return ret; } +bool IsInteger(const std::string & n_str) +{ + if(n_str.empty() || ((!isdigit(n_str[0])) && (n_str[0] != '-') + && (n_str[0] != '+'))) { + return false; + } + + char * tmp; + strtol(n_str.c_str(), &tmp, 10); + + return (*tmp == 0); +} } // namespace smi } // namespace amd diff --git a/projects/amdsmi/tests/rocm_smi_test/functional/fan_read_write.cc b/projects/amdsmi/tests/rocm_smi_test/functional/fan_read_write.cc index ca53f2945e..2ad12a11ee 100755 --- a/projects/amdsmi/tests/rocm_smi_test/functional/fan_read_write.cc +++ b/projects/amdsmi/tests/rocm_smi_test/functional/fan_read_write.cc @@ -89,6 +89,7 @@ void TestFanReadWrite::Run(void) { int64_t orig_speed; int64_t new_speed; int64_t cur_speed; + uint64_t max_speed; TestBase::Run(); @@ -107,8 +108,18 @@ void TestFanReadWrite::Run(void) { return; } + ret = rsmi_dev_fan_speed_max_get(dv_ind, 0, &max_speed); + CHK_ERR_ASRT(ret) + new_speed = 1.1 * orig_speed; + if (new_speed > static_cast(max_speed)) { + std::cout << + "***System fan speed value is close to max. Will not adjust upward." << + std::endl; + continue; + } + IF_VERB(STANDARD) { std::cout << "Setting fan speed to " << new_speed << std::endl; }