ESMI - Clean-up example code
Change-Id: Iacd150209d4695a39de39bd5633293d3e040ff4b
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
[ROCm/amdsmi commit: 8333ffc640]
这个提交包含在:
@@ -51,6 +51,7 @@ set(AMD_SMI_PACKAGE
|
|||||||
project(${AMD_SMI_LIBS_TARGET})
|
project(${AMD_SMI_LIBS_TARGET})
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,10 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include "amd_smi/amdsmi.h"
|
#include "amd_smi/amdsmi.h"
|
||||||
|
#include "asm/amd_hsmp.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#define SHOWLINESZ 256
|
#define SHOWLINESZ 256
|
||||||
|
|
||||||
#define CHK_AMDSMI_RET(RET) \
|
#define CHK_AMDSMI_RET(RET) \
|
||||||
@@ -68,6 +67,13 @@ using namespace std;
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::fixed;
|
||||||
|
using std::setprecision;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
amdsmi_status_t ret;
|
amdsmi_status_t ret;
|
||||||
uint32_t proto_ver;
|
uint32_t proto_ver;
|
||||||
@@ -196,7 +202,7 @@ int main(int argc, char **argv) {
|
|||||||
cout<<"\n| CPU["<<i<<"] core clock current frequency limit (MHz) : "<<c_clk<<"\t|\n";
|
cout<<"\n| CPU["<<i<<"] core clock current frequency limit (MHz) : "<<c_clk<<"\t|\n";
|
||||||
cout<<"--------------------------------------------------------------\n";
|
cout<<"--------------------------------------------------------------\n";
|
||||||
|
|
||||||
uint32_t power;
|
uint32_t socket_power;
|
||||||
cout<<"\n-------------------------------------------------";
|
cout<<"\n-------------------------------------------------";
|
||||||
cout<<"\n| Sensor Name\t\t\t |";
|
cout<<"\n| Sensor Name\t\t\t |";
|
||||||
for (uint32_t i = 0; i < socket_count; i++) {
|
for (uint32_t i = 0; i < socket_count; i++) {
|
||||||
@@ -205,37 +211,37 @@ int main(int argc, char **argv) {
|
|||||||
cout<<"\n-------------------------------------------------";
|
cout<<"\n-------------------------------------------------";
|
||||||
cout<<"\n| Power (Watts)\t\t\t | ";
|
cout<<"\n| Power (Watts)\t\t\t | ";
|
||||||
|
|
||||||
ret = amdsmi_get_cpu_socket_power(sockets[i], i, &power);
|
ret = amdsmi_get_cpu_socket_power(sockets[i], i, &socket_power);
|
||||||
CHK_AMDSMI_RET(ret)
|
CHK_AMDSMI_RET(ret)
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
cout<<fixed<<setprecision(3)<<static_cast<double>(power)/1000<<"\t|";
|
cout<<fixed<<setprecision(3)<<static_cast<double>(socket_power)/1000<<"\t|";
|
||||||
} else {
|
} else {
|
||||||
err_bits |= 1 << ret;
|
err_bits |= 1 << ret;
|
||||||
cout<<" NA (Err:" <<ret<<" |";
|
cout<<" NA (Err:" <<ret<<" |";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t powerlimit;
|
uint32_t power_limit;
|
||||||
cout<<"\n| PowerLimit (Watts)\t\t | ";
|
cout<<"\n| PowerLimit (Watts)\t\t | ";
|
||||||
|
|
||||||
ret = amdsmi_get_cpu_socket_power_cap(sockets[i], i, &powerlimit);
|
ret = amdsmi_get_cpu_socket_power_cap(sockets[i], i, &power_limit);
|
||||||
CHK_AMDSMI_RET(ret)
|
CHK_AMDSMI_RET(ret)
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
cout<<fixed<<setprecision(3)<<static_cast<double>(powerlimit)/1000<<"\t|";
|
cout<<fixed<<setprecision(3)<<static_cast<double>(power_limit)/1000<<"\t|";
|
||||||
} else {
|
} else {
|
||||||
err_bits |= 1 << ret;
|
err_bits |= 1 << ret;
|
||||||
cout<<" NA (Err:" <<ret<<" |";
|
cout<<" NA (Err:" <<ret<<" |";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t powermax;
|
uint32_t power_max;
|
||||||
cout<<"\n| PowerLimitMax (Watts)\t\t | ";
|
cout<<"\n| PowerLimitMax (Watts)\t\t | ";
|
||||||
|
|
||||||
ret = amdsmi_get_cpu_socket_power_cap_max(sockets[i], i, &powermax);
|
ret = amdsmi_get_cpu_socket_power_cap_max(sockets[i], i, &power_max);
|
||||||
CHK_AMDSMI_RET(ret)
|
CHK_AMDSMI_RET(ret)
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
cout<<fixed<<setprecision(3)<<static_cast<double>(powermax)/1000<<"\t|";
|
cout<<fixed<<setprecision(3)<<static_cast<double>(power_max)/1000<<"\t|";
|
||||||
} else {
|
} else {
|
||||||
err_bits |= 1 << ret;
|
err_bits |= 1 << ret;
|
||||||
cout<<" NA (Err:" <<ret<<" |";
|
cout<<" NA (Err:" <<ret<<" |";
|
||||||
@@ -243,15 +249,15 @@ int main(int argc, char **argv) {
|
|||||||
cout<<"\n-------------------------------------------------\n";
|
cout<<"\n-------------------------------------------------\n";
|
||||||
|
|
||||||
uint32_t input_power;
|
uint32_t input_power;
|
||||||
powermax = 0;
|
power_max = 0;
|
||||||
cout<<"\nEnter the max power to be set:\n";
|
cout<<"\nEnter the max power to be set:\n";
|
||||||
cin>>input_power;
|
cin>>input_power;
|
||||||
ret = amdsmi_get_cpu_socket_power_cap_max(sockets[i], i, &powermax);
|
ret = amdsmi_get_cpu_socket_power_cap_max(sockets[i], i, &power_max);
|
||||||
CHK_AMDSMI_RET(ret)
|
CHK_AMDSMI_RET(ret)
|
||||||
if ((ret == AMDSMI_STATUS_SUCCESS) && (input_power > powermax)) {
|
if ((ret == AMDSMI_STATUS_SUCCESS) && (input_power > power_max)) {
|
||||||
cout<<"Input power is more than max power limit,"
|
cout<<"Input power is more than max power limit,"
|
||||||
" limiting to "<<static_cast<double>(powermax)/1000<<"Watts\n";
|
" limiting to "<<static_cast<double>(power_max)/1000<<"Watts\n";
|
||||||
input_power = powermax;
|
input_power = power_max;
|
||||||
}
|
}
|
||||||
ret = amdsmi_set_cpu_socket_power_cap(sockets[i], i, input_power);
|
ret = amdsmi_set_cpu_socket_power_cap(sockets[i], i, input_power);
|
||||||
CHK_AMDSMI_RET(ret)
|
CHK_AMDSMI_RET(ret)
|
||||||
@@ -389,15 +395,15 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
cout<<"\n-------------------------------------------------\n";
|
cout<<"\n-------------------------------------------------\n";
|
||||||
|
|
||||||
amdsmi_dimm_power_t p;
|
amdsmi_dimm_power_t dimm_power;
|
||||||
cout<<"\n| Socket DIMM power consumption\t\t |\n";
|
cout<<"\n| Socket DIMM power consumption\t\t |\n";
|
||||||
ret = amdsmi_get_cpu_dimm_power_consumption(sockets[i], i, dimm_addr, &p);
|
ret = amdsmi_get_cpu_dimm_power_consumption(sockets[i], i, dimm_addr, &dimm_power);
|
||||||
CHK_AMDSMI_RET(ret)
|
CHK_AMDSMI_RET(ret)
|
||||||
|
|
||||||
if(ret) {
|
if(ret) {
|
||||||
cout<<"\n| Power(mWatts)\t\t |"<<p.power<<"\t|"<<endl;
|
cout<<"\n| Power(mWatts)\t\t |"<<dimm_power.power<<"\t|"<<endl;
|
||||||
cout<<"\n| Power update rate(ms)\t |"<<p.update_rate<<"\t|"<<endl;
|
cout<<"\n| Power update rate(ms)\t |"<<dimm_power.update_rate<<"\t|"<<endl;
|
||||||
cout<<"\n| Dimm address \t\t |"<<p.dimm_addr<<"\t|"<<endl;
|
cout<<"\n| Dimm address \t\t |"<<dimm_power.dimm_addr<<"\t|"<<endl;
|
||||||
} else
|
} else
|
||||||
cout<<"Failed: to get socket"<<"["<<i<<"] DIMM power and update rate, Err["<<ret<<"]: "
|
cout<<"Failed: to get socket"<<"["<<i<<"] DIMM power and update rate, Err["<<ret<<"]: "
|
||||||
<<*amdsmi_get_esmi_err_msg(ret, &err_str1)<<endl;
|
<<*amdsmi_get_esmi_err_msg(ret, &err_str1)<<endl;
|
||||||
@@ -508,7 +514,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
uint8_t rate_ctrl;
|
uint8_t rate_ctrl;
|
||||||
uint8_t prev_mode;
|
uint8_t prev_mode;
|
||||||
string pcie_strings[] = {
|
std::string pcie_strings[] = {
|
||||||
"automatically detect based on bandwidth utilisation",
|
"automatically detect based on bandwidth utilisation",
|
||||||
"limited to Gen4 rate",
|
"limited to Gen4 rate",
|
||||||
"limited to Gen5 rate"
|
"limited to Gen5 rate"
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户