From 4a8d4b28789971cb9b150051bc48f319439ed16c Mon Sep 17 00:00:00 2001 From: Divya Shikre Date: Fri, 6 May 2022 09:14:46 -0400 Subject: [PATCH 1/3] Add RSMI_CLK_TYPE_PCIE to rsmi_clk_type_t showclocks/showclkfrq does not display pp_dpm_pcie values in sriov. This fix adds pcie clocks to rsmi_clk_type_t where rest of the clocks are present. Signed-off-by: Divya Shikre Change-Id: I6d129ae412623b369c14456ae9781b2dbceb2139 [ROCm/rocm_smi_lib commit: c9b42bff57ef674724c71030d3d511741392d9b4] --- projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h | 1 + projects/rocm-smi-lib/src/rocm_smi_device.cc | 1 + 2 files changed, 2 insertions(+) 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 77090fac6d..97b9bcd019 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -341,6 +341,7 @@ typedef enum { RSMI_CLK_TYPE_DCEF, //!< Display Controller Engine clock RSMI_CLK_TYPE_SOC, //!< SOC clock RSMI_CLK_TYPE_MEM, //!< Memory clock + RSMI_CLK_TYPE_PCIE, //!< PCIE clock // Add new clocks to the end (not in the middle) and update // RSMI_CLK_TYPE_LAST diff --git a/projects/rocm-smi-lib/src/rocm_smi_device.cc b/projects/rocm-smi-lib/src/rocm_smi_device.cc index dc65816513..cd6956cad0 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_device.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_device.cc @@ -319,6 +319,7 @@ static std::map kDevInfoVarTypeToRSMIVariant = { {kDevFClk, RSMI_CLK_TYPE_DF}, {kDevDCEFClk, RSMI_CLK_TYPE_DCEF}, {kDevSOCClk, RSMI_CLK_TYPE_SOC}, + {kDevPCIEClk, RSMI_CLK_TYPE_PCIE}, // rsmi_fw_block_t {kDevFwVersionAsd, RSMI_FW_BLOCK_ASD}, From 853a6e517ce33e4c61cbcf09c932678a8d9f86b1 Mon Sep 17 00:00:00 2001 From: Divya Shikre Date: Fri, 6 May 2022 09:33:58 -0400 Subject: [PATCH 2/3] Add DEBUG_LOG macro Add DEBUG_LOG that will optionally print error message when RSMI_DEBUG_BITFIELD is set to 2. Signed-off-by: Divya Shikre Change-Id: I6017e92d8a9e5f9861ae29ece0488d4bc198f996 [ROCm/rocm_smi_lib commit: 99be3451d7467ff4a2d551b5d7d77fb1133643ae] --- .../rocm-smi-lib/include/rocm_smi/rocm_smi_common.h | 10 +++++++++- projects/rocm-smi-lib/include/rocm_smi/rocm_smi_main.h | 1 + projects/rocm-smi-lib/src/rocm_smi_main.cc | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_common.h b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_common.h index 98a2df5c62..dad39ad13f 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_common.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_common.h @@ -133,8 +133,16 @@ std::endl;\ } +#define DEBUG_LOG(WR_STR, VR) \ + amd::smi::RocmSMI& smi = amd::smi::RocmSMI::getInstance(); \ + if (smi.getEnv().debug_output_bitfield & RSMI_DEBUG_VAL) { \ + if ((WR_STR) != nullptr) \ + std::cout << (WR_STR) << " " << (VR) << std::endl;\ + } + // Add different debug filters here, as powers of 2; e.g, 1, 2, 4, 8, ... -#define RSMI_DEBUG_SYSFS_FILE_PATHS 1 +#define RSMI_DEBUG_SYSFS_FILE_PATHS 1<<0 +#define RSMI_DEBUG_VAL 1<<1 struct rsmi_func_id_iter_handle { uintptr_t func_id_iter; diff --git a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_main.h b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_main.h index b8141b4568..126bbd7436 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_main.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_main.h @@ -112,6 +112,7 @@ class RocmSMI { int get_io_link_weight(uint32_t node_from, uint32_t node_to, uint64_t *weight); int get_node_index(uint32_t dv_ind, uint32_t *node_ind); + const RocmSMI_env_vars& getEnv(void); private: std::vector> devices_; diff --git a/projects/rocm-smi-lib/src/rocm_smi_main.cc b/projects/rocm-smi-lib/src/rocm_smi_main.cc index 2d51333c91..40541d9280 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_main.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_main.cc @@ -376,6 +376,10 @@ void RocmSMI::GetEnvVariables(void) { #endif } +const RocmSMI_env_vars& RocmSMI::getEnv(void) { + return env_vars_; +} + std::shared_ptr RocmSMI::FindMonitor(std::string monitor_path) { std::string tmp; From 231a61a3945fb3b1216bd8f246750ce6940a63d6 Mon Sep 17 00:00:00 2001 From: Divya Shikre Date: Tue, 3 May 2022 18:41:45 -0400 Subject: [PATCH 3/3] Update get_frequencies to handle failures. Show an optional debug log (RSMI_DEBUG_BITFIELD=2) to the user in the following scenarios: 1. If more than one current frequency is found 2. If frequencies are not read in increasing order of their value If current frequency is not available, index for it is set to -1, values will not have * next to it in the output. This will also be handled in rocm_smi.py. Signed-off-by: Divya Shikre Change-Id: I477ec065f7513c8045d6392f12ef6cb835a6b8f6 [ROCm/rocm_smi_lib commit: afe996c2edb791ee3f7a7bdb4803da8a886fc016] --- .../rocm-smi-lib/include/rocm_smi/rocm_smi.h | 5 ++- .../rocm-smi-lib/python_smi_tools/rocm_smi.py | 9 +++++ projects/rocm-smi-lib/src/rocm_smi.cc | 40 +++++++++++++++---- 3 files changed, 45 insertions(+), 9 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 97b9bcd019..b57e7dfd1d 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -2269,11 +2269,14 @@ rsmi_status_t rsmi_dev_overdrive_level_get(uint32_t dv_ind, uint32_t *od); * * @param[inout] f a pointer to a caller provided ::rsmi_frequencies_t structure * to which the frequency information will be written. Frequency values are in - * Hz. + * Hz. * If this parameter is nullptr, this function will return * ::RSMI_STATUS_INVALID_ARGS if the function is supported with the provided, * arguments and ::RSMI_STATUS_NOT_SUPPORTED if it is not supported with the * provided arguments. + * If multiple current frequencies are found, a warning is shown. If no + * current frequency is found, it is reflected as -1. If frequencies are not + * read from low to high a warning is shown as well. * * @retval ::RSMI_STATUS_SUCCESS call was successful * @retval ::RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not diff --git a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py index 5070994789..a85d65f630 100755 --- a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py +++ b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py @@ -1453,6 +1453,9 @@ def showCurrentClocks(deviceList, clk_defined=None, concise=False): ret = rocmsmi.rsmi_dev_gpu_clk_freq_get(device, rsmi_clk_names_dict[clk_defined], byref(freq)) if rsmi_ret_ok(ret, device, clk_defined, True): levl = freq.current + if levl >= freq.num_supported: + printLog(device, '%s current clock frequency not found' % (clk_defined), None) + continue fr = freq.frequency[levl] / 1000000 if concise: # in case function is used for concise output, no need to print. return '{:.0f}Mhz'.format(fr) @@ -1466,6 +1469,9 @@ def showCurrentClocks(deviceList, clk_defined=None, concise=False): ret = rocmsmi.rsmi_dev_gpu_clk_freq_get(device, rsmi_clk_names_dict[clk_type], byref(freq)) if rsmi_ret_ok(ret, device, clk_type, True): levl = freq.current + if levl >= freq.num_supported: + printLog(device, '%s current clock frequency not found' % (clk_type), None) + continue fr = freq.frequency[levl] / 1000000 if PRINT_JSON: printLog(device, '%s clock speed:' % (clk_type), '(%sMhz)' % (str(fr)[:-2])) @@ -1479,6 +1485,9 @@ def showCurrentClocks(deviceList, clk_defined=None, concise=False): ret = rocmsmi.rsmi_dev_pci_bandwidth_get(device, byref(bw)) if rsmi_ret_ok(ret, device, 'PCIe', True): current_f = bw.transfer_rate.current + if current_f >= bw.transfer_rate.num_supported: + printLog(device, 'PCIe current clock frequency not found', None ) + continue fr = '{:.1f}GT/s x{}'.format(bw.transfer_rate.frequency[current_f] / 1000000000, bw.lanes[current_f]) printLog(device, 'pcie clock level', '{} ({})'.format(current_f, fr)) diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index c8e521aac0..b8b2d0b7aa 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -77,6 +77,15 @@ static const uint32_t kMaxOverdriveLevel = 20; static const float kEnergyCounterResolution = 15.3f; +std::map ClkStateMap = { + {RSMI_CLK_TYPE_SYS, "SCLK"}, + {RSMI_CLK_TYPE_DF, "DFCLK"}, + {RSMI_CLK_TYPE_DCEF, "DCEFCLK"}, + {RSMI_CLK_TYPE_SOC, "SOCCLK"}, + {RSMI_CLK_TYPE_MEM, "MCLK"}, + {RSMI_CLK_TYPE_PCIE, "PCIECLK"}, + }; + #define TRY try { #define CATCH } catch (...) {return amd::smi::handleException();} @@ -895,7 +904,7 @@ rsmi_dev_perf_level_set_v1(uint32_t dv_ind, rsmi_dev_perf_level_t perf_level) { } -static rsmi_status_t get_frequencies(amd::smi::DevInfoTypes type, +static rsmi_status_t get_frequencies(amd::smi::DevInfoTypes type, rsmi_clk_type_t clk_type, uint32_t dv_ind, rsmi_frequencies_t *f, uint32_t *lanes = nullptr) { TRY std::vector val_vec; @@ -925,19 +934,34 @@ static rsmi_status_t get_frequencies(amd::smi::DevInfoTypes type, // Our assumption is that frequencies are read in from lowest to highest. // Check that that is true. if (i > 0) { - assert(f->frequency[i-1] <= f->frequency[i]); + if (f->frequency[i] < f->frequency[i-1]) { + std::string sysvalue = ClkStateMap[clk_type]; + sysvalue += " Current Value"; + sysvalue += ' ' + std::to_string(f->frequency[i]); + sysvalue += " Previous Value"; + sysvalue += ' ' + std::to_string(f->frequency[i-1]); + DEBUG_LOG("Frequencies are not read from lowest to highest. ", sysvalue); + } } if (current) { - // Should only be 1 current frequency - assert(f->current == RSMI_MAX_NUM_FREQUENCIES + 1); - f->current = i; + // set the current frequency + if (f->current != RSMI_MAX_NUM_FREQUENCIES + 1) { + std::string sysvalue = ClkStateMap[clk_type]; + sysvalue += " Current Value"; + sysvalue += ' ' + std::to_string(f->frequency[i]); + sysvalue += " Previous Value"; + sysvalue += ' ' + std::to_string(f->frequency[f->current]); + DEBUG_LOG("More than one current clock. ", sysvalue); + } + else + f->current = i; } } // Some older drivers will not have the current frequency set // assert(f->current < f->num_supported); if (f->current >= f->num_supported) { - return RSMI_STATUS_NOT_SUPPORTED; + f->current = -1; } return RSMI_STATUS_SUCCESS; @@ -1444,7 +1468,7 @@ rsmi_dev_gpu_clk_freq_get(uint32_t dv_ind, rsmi_clk_type_t clk_type, DEVICE_MUTEX - return get_frequencies(dev_type, dv_ind, f); + return get_frequencies(dev_type, clk_type, dv_ind, f); CATCH } @@ -2006,7 +2030,7 @@ rsmi_dev_pci_bandwidth_get(uint32_t dv_ind, rsmi_pcie_bandwidth_t *b) { DEVICE_MUTEX - return get_frequencies(amd::smi::kDevPCIEClk, dv_ind, + return get_frequencies(amd::smi::kDevPCIEClk, RSMI_CLK_TYPE_PCIE, dv_ind, &b->transfer_rate, b->lanes); CATCH