From 9f3a6dbd29740a3ec5e1fd78f767ec6b90bfc934 Mon Sep 17 00:00:00 2001 From: Deepak Mewar Date: Wed, 27 Dec 2023 10:13:35 -0500 Subject: [PATCH] amdsmi library and sample code updated for amdsmi_get_metrics_table Change-Id: Ie03c556f5c38fe4a0365743d3a94220e3aa62b23 --- example/amdsmi_esmi_intg_example.cc | 124 ++++++++++++++++++---------- include/amd_smi/amdsmi.h | 84 ++++++++++++++++++- src/amd_smi/amd_smi.cc | 6 +- 3 files changed, 168 insertions(+), 46 deletions(-) diff --git a/example/amdsmi_esmi_intg_example.cc b/example/amdsmi_esmi_intg_example.cc index da83dd868d..376d8ababb 100644 --- a/example/amdsmi_esmi_intg_example.cc +++ b/example/amdsmi_esmi_intg_example.cc @@ -86,51 +86,57 @@ int main(int argc, char **argv) { // Get all sockets uint32_t socket_count = 0; - /*ret = amdsmi_get_cpusocket_handles(&socket_count, nullptr); - CHK_AMDSMI_RET(ret) - - // Allocate the memory for the sockets - vector sockets(socket_count); - - // Get the sockets of the system - ret = amdsmi_get_cpusocket_handles(&socket_count, &sockets[0]); - CHK_AMDSMI_RET(ret)*/ ret = amdsmi_get_socket_handles(&socket_count, nullptr); CHK_AMDSMI_RET(ret) + // Allocate the memory for the sockets vector sockets(socket_count); + // Get the sockets of the system ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]); CHK_AMDSMI_RET(ret) + cout << "Total Socket: " << socket_count << endl; - // For each socket, get identifier and cores - for (uint8_t i = 0; i < socket_count; i++) { + + // For each socket, get cpus and cores + for (uint32_t i = 0; i < socket_count; i++) { + cout << endl << "Socket " << i << endl; uint32_t cpu_count = 0; uint32_t core_count = 0; + + // Set processor type as AMD_CPU processor_type_t processor_type = AMD_CPU; ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, nullptr, &cpu_count); CHK_AMDSMI_RET(ret) + + // Allocate the memory for the cpus vector plist(cpu_count); + + // Get the cpus for each socket ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, &plist[0], &cpu_count); CHK_AMDSMI_RET(ret) - cout << endl; - // Read core count for each sockets + + // Set processor type as AMD_CPU_CORE processor_type = AMD_CPU_CORE; ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, nullptr, &core_count); CHK_AMDSMI_RET(ret) + + // Allocate the memory for the cpu cores vector core_list(core_count); + + // Get the cpu cores for each socket ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, &core_list[0], &core_count); CHK_AMDSMI_RET(ret) - for (int index = 0; index < plist.size(); index++) { - socket_count = plist.size(); - ret = amdsmi_get_cpu_hsmp_proto_ver(plist[i], &proto_ver); + + for (uint32_t index = 0; index < plist.size(); index++) { + ret = amdsmi_get_cpu_hsmp_proto_ver(plist[index], &proto_ver); CHK_AMDSMI_RET(ret) cout<<"\n------------------------------------------"; cout<<"\n| HSMP Proto Version | "<< proto_ver <<"\t\t |"<< endl; cout<<"------------------------------------------\n"; - ret = amdsmi_get_cpu_smu_fw_version(plist[i], &smu_fw); + ret = amdsmi_get_cpu_smu_fw_version(plist[index], &smu_fw); CHK_AMDSMI_RET(ret) cout<<"\n------------------------------------------"; @@ -144,14 +150,10 @@ int main(int argc, char **argv) { uint32_t err_bits = 0; uint32_t prochot; - cout<<"\n-------------------------------------------------"; - cout<<"\n| Sensor Name\t\t\t |"; - for (uint32_t i = 0; i < socket_count; i++) { - cout<>input_power; - ret = amdsmi_get_cpu_socket_power_cap_max(plist[i], &power_max); + ret = amdsmi_get_cpu_socket_power_cap_max(plist[index], &power_max); CHK_AMDSMI_RET(ret) if ((ret == AMDSMI_STATUS_SUCCESS) && (input_power > power_max)) { cout<<"Input power is more than max power limit," " limiting to "<(power_max)/1000<<"Watts\n"; input_power = power_max; } - ret = amdsmi_set_cpu_socket_power_cap(plist[i], input_power); + ret = amdsmi_set_cpu_socket_power_cap(plist[index], input_power); CHK_AMDSMI_RET(ret) if (!ret) { - cout<<"Socket["<(input_power)/1000<<" Watts successfully\n"; } + + power_limit = 0; + cout<<"\n| PowerLimit (Watts) \t\t | "; + ret = amdsmi_get_cpu_socket_power_cap(plist[index], &power_limit); + CHK_AMDSMI_RET(ret) + + if (!ret) { + cout<(power_limit)/1000<<"\t|"; + } else { + err_bits |= 1 << ret; + cout<<" NA (Err:" <(esmi_metrics_table_get(sock_ind, &metrics_tbl)); - *metrics_table = metrics_tbl; - if (status != AMDSMI_STATUS_SUCCESS) return status; + std::memcpy(metrics_table, &metrics_tbl, sizeof(amdsmi_hsmp_metric_table_t)); + return AMDSMI_STATUS_SUCCESS; }