From fd79e5c161cfc987eb04b27b14933b9302c79e9c Mon Sep 17 00:00:00 2001 From: Mukul Joshi Date: Tue, 31 Mar 2020 23:28:29 -0400 Subject: [PATCH] Add rsmi_topo_get_numa_affinity() Given a device index, return the corresponding NUMA node for the device. Also, add NUMA node tests to Sys Info Read test. Change-Id: I0df4937470e6362e6737ccea568d4b3e5890c91a --- include/rocm_smi/rocm_smi.h | 24 +++++++++++++++++++ include/rocm_smi/rocm_smi_device.h | 1 + src/rocm_smi.cc | 16 +++++++++++++ src/rocm_smi_device.cc | 4 ++++ .../rocm_smi_test/functional/sys_info_read.cc | 11 +++++++++ 5 files changed, 56 insertions(+) diff --git a/include/rocm_smi/rocm_smi.h b/include/rocm_smi/rocm_smi.h index 8e045a8182..24813ce03f 100755 --- a/include/rocm_smi/rocm_smi.h +++ b/include/rocm_smi/rocm_smi.h @@ -1166,6 +1166,30 @@ rsmi_dev_pci_bandwidth_get(uint32_t dv_ind, rsmi_pcie_bandwidth_t *bandwidth); */ rsmi_status_t rsmi_dev_pci_id_get(uint32_t dv_ind, uint64_t *bdfid); +/** + * @brief Get the NUMA node associated with a device + * + * @details Given a device index @p dv_ind and a pointer to a uint32_t @p + * numa_node, this function will retrieve the NUMA node value associated + * with device @p dv_ind and store the value at location pointed to by + * @p numa_node. + * + * @param[in] dv_ind a device index + * + * @param[inout] numa_node pointer to location where NUMA node value will + * be written. + * 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. + * + * @retval ::RSMI_STATUS_SUCCESS call was successful + * @retval ::RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not + * support this function with the given arguments + * @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid + */ +rsmi_status_t rsmi_topo_numa_affinity_get(uint32_t dv_ind, uint32_t *numa_node); + /** * @brief Get PCIe traffic information * diff --git a/include/rocm_smi/rocm_smi_device.h b/include/rocm_smi/rocm_smi_device.h index 3d02422d55..560f0200a3 100755 --- a/include/rocm_smi/rocm_smi_device.h +++ b/include/rocm_smi/rocm_smi_device.h @@ -154,6 +154,7 @@ enum DevInfoTypes { kDevFwVersionVcn, kDevSerialNumber, kDevMemPageBad, + kDevNumaNode }; typedef struct { diff --git a/src/rocm_smi.cc b/src/rocm_smi.cc index 75afd392d8..75a1d3aa2e 100755 --- a/src/rocm_smi.cc +++ b/src/rocm_smi.cc @@ -729,6 +729,22 @@ rsmi_dev_pci_id_get(uint32_t dv_ind, uint64_t *bdfid) { CATCH } +rsmi_status_t +rsmi_topo_numa_affinity_get(uint32_t dv_ind, uint32_t *numa_node) { + TRY + rsmi_status_t ret; + uint64_t val = 0; + + CHK_SUPPORT_NAME_ONLY(numa_node) + + DEVICE_MUTEX + ret = get_dev_value_int(amd::smi::kDevNumaNode, dv_ind, &val); + + *numa_node = static_cast(val); + return ret; + CATCH +} + static rsmi_status_t get_id(uint32_t dv_ind, amd::smi::DevInfoTypes typ, uint16_t *id) { TRY diff --git a/src/rocm_smi_device.cc b/src/rocm_smi_device.cc index 0c8dc8a927..8bbb53010a 100755 --- a/src/rocm_smi_device.cc +++ b/src/rocm_smi_device.cc @@ -108,6 +108,7 @@ 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"; +static const char *kDevNumaNodeFName = "numa_node"; // Firmware version files static const char *kDevFwVersionAsdFName = "fw_version/asd_fw_version"; @@ -266,6 +267,7 @@ static const std::map kDevAttribNameMap = { {kDevFwVersionVcn, kDevFwVersionVcnFName}, {kDevSerialNumber, kDevSerialNumberFName}, {kDevMemPageBad, kDevMemPageBadFName}, + {kDevNumaNode, kDevNumaNodeFName}, }; static const std::map kDevPerfLvlMap = { @@ -373,6 +375,7 @@ static const std::map kDevFuncDependsMap = { {"rsmi_dev_xgmi_error_status", {{kDevXGMIErrorFName}, {}}}, {"rsmi_dev_xgmi_error_reset", {{kDevXGMIErrorFName}, {}}}, {"rsmi_dev_memory_reserved_pages_get", {{kDevMemPageBadFName}, {}}}, + {"rsmi_topo_numa_affinity_get", {{kDevNumaNodeFName}, {}}}, // These functions with variants, but no sensors/units. (May or may not // have mandatory dependencies.) @@ -683,6 +686,7 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) { case kDevDFCountersAvailable: case kDevMemBusyPercent: case kDevXGMIError: + case kDevNumaNode: ret = readDevInfoStr(type, &tempStr); RET_IF_NONZERO(ret); if (tempStr == "") { diff --git a/tests/rocm_smi_test/functional/sys_info_read.cc b/tests/rocm_smi_test/functional/sys_info_read.cc index 46aef40c0a..699f94ef9a 100755 --- a/tests/rocm_smi_test/functional/sys_info_read.cc +++ b/tests/rocm_smi_test/functional/sys_info_read.cc @@ -89,6 +89,7 @@ void TestSysInfoRead::Close() { void TestSysInfoRead::Run(void) { rsmi_status_t err; uint64_t val_ui64; + uint32_t val_ui32; char buffer[80]; rsmi_version_t ver = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, nullptr}; @@ -135,6 +136,16 @@ void TestSysInfoRead::Run(void) { err = rsmi_dev_pci_id_get(i, nullptr); ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); + err = rsmi_topo_numa_affinity_get(i, &val_ui32); + CHK_ERR_ASRT(err) + IF_VERB(STANDARD) { + std::cout << "\t**NUMA NODE: 0x" << std::hex << val_ui32; + std::cout << " (" << std::dec << val_ui32 << ")" << std::endl; + } + // Verify api support checking functionality is working + err = rsmi_topo_numa_affinity_get(i, nullptr); + ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); + err = rsmi_dev_unique_id_get(i, &val_ui64); if (err == RSMI_STATUS_NOT_SUPPORTED) { std::cout <<