[SWDEV-451104] Update static --board + amdsmi_get_gpu_board_info()
Updates:
* Expanded `amdsmi_get_gpu_board_info()` amdsmi_board_info_t structure size
Updated sizes that work for retrieving relevant board
information across AMD's ASIC products.
* Fixed `amdsmi_get_gpu_board_info()` to no longer return junk char strings
Change-Id: Ie1553c6109d678d283d82c24e9284f8e19cd6ccc
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
[ROCm/amdsmi commit: 4295bba37f]
This commit is contained in:
1 parent
96f603783c
commit
aaed28aaab
6 files changed
+195
-62
No files matched your search
@@ -389,7 +389,6 @@ amdsmi_get_gpu_device_bdf(amdsmi_processor_handle processor_handle, amdsmi_bdf_t
|
||||
}
|
||||
|
||||
amdsmi_status_t amdsmi_get_gpu_board_info(amdsmi_processor_handle processor_handle, amdsmi_board_info_t *board_info) {
|
||||
|
||||
AMDSMI_CHECK_INIT();
|
||||
|
||||
if (board_info == nullptr) {
|
||||
@@ -405,17 +404,86 @@ amdsmi_status_t amdsmi_get_gpu_board_info(amdsmi_processor_handle processor_hand
|
||||
if (gpu_device->check_if_drm_is_supported()) {
|
||||
// Populate product_serial, product_name, & product_number from sysfs
|
||||
status = smi_amdgpu_get_board_info(gpu_device, board_info);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// ignore the errors so that it can populate as many fields as possible.
|
||||
// call rocm-smi which search multiple places for device name
|
||||
status = rsmi_wrapper(rsmi_dev_name_get, processor_handle,
|
||||
board_info->product_name, AMDSMI_PRODUCT_NAME_LENGTH);
|
||||
board_info->product_name, AMDSMI_256_LENGTH);
|
||||
|
||||
status = rsmi_wrapper(rsmi_dev_serial_number_get, processor_handle,
|
||||
board_info->product_serial, AMDSMI_NORMAL_STRING_LENGTH);
|
||||
}
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__ << "[Before rocm smi correction] "
|
||||
<< "Returning status = AMDSMI_STATUS_SUCCESS"
|
||||
<< "\n; info->model_number: |" << board_info->model_number << "|"
|
||||
<< "\n; info->product_serial: |" << board_info->product_serial << "|"
|
||||
<< "\n; info->fru_id: |" << board_info->fru_id << "|"
|
||||
<< "\n; info->manufacturer_name: |" << board_info->manufacturer_name << "|"
|
||||
<< "\n; info->product_name: |" << board_info->product_name << "|";
|
||||
LOG_INFO(ss);
|
||||
|
||||
// Correct any missing details
|
||||
if (board_info->model_number[0] == '\0') {
|
||||
status = rsmi_wrapper(rsmi_dev_name_get, processor_handle, board_info->model_number,
|
||||
AMDSMI_256_LENGTH);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
memset(board_info->model_number, 0,
|
||||
AMDSMI_256_LENGTH * sizeof(board_info->model_number[0]));
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__ << " | [rsmi_correction] board_info->model_number= |"
|
||||
<< board_info->model_number << "|";
|
||||
LOG_INFO(ss);
|
||||
}
|
||||
|
||||
if (board_info->product_serial[0] == '\0') {
|
||||
status = rsmi_wrapper(rsmi_dev_serial_number_get, processor_handle,
|
||||
board_info->product_serial, AMDSMI_NORMAL_STRING_LENGTH);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
memset(board_info->product_serial, 0,
|
||||
AMDSMI_NORMAL_STRING_LENGTH * sizeof(board_info->product_serial[0]));
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__ << " | [rsmi_correction] board_info->product_serial= |"
|
||||
<< board_info->product_serial << "|";
|
||||
LOG_INFO(ss);
|
||||
}
|
||||
|
||||
if (board_info->product_name[0] == '\0') {
|
||||
status = rsmi_wrapper(rsmi_dev_subsystem_name_get,
|
||||
processor_handle, board_info->product_name,
|
||||
AMDSMI_256_LENGTH);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
memset(board_info->product_name, 0,
|
||||
AMDSMI_256_LENGTH * sizeof(board_info->product_name[0]));
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__ << " | [rsmi_correction] board_info->product_name= |"
|
||||
<< board_info->product_name << "|";
|
||||
LOG_INFO(ss);
|
||||
}
|
||||
|
||||
if (board_info->manufacturer_name[0] == '\0') {
|
||||
status = rsmi_wrapper(rsmi_dev_vendor_name_get,
|
||||
processor_handle, board_info->manufacturer_name,
|
||||
AMDSMI_MAX_STRING_LENGTH);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
memset(board_info->manufacturer_name, 0,
|
||||
AMDSMI_MAX_STRING_LENGTH * sizeof(board_info->manufacturer_name[0]));
|
||||
}
|
||||
ss << __PRETTY_FUNCTION__ << " | [rsmi_correction] board_info->manufacturer_name= |"
|
||||
<< board_info->manufacturer_name << "|";
|
||||
LOG_INFO(ss);
|
||||
}
|
||||
|
||||
ss << __PRETTY_FUNCTION__ << "[After rocm smi correction] "
|
||||
<< "Returning status = AMDSMI_STATUS_SUCCESS"
|
||||
<< "\n; info->model_number: |" << board_info->model_number << "|"
|
||||
<< "\n; info->product_serial: |" << board_info->product_serial << "|"
|
||||
<< "\n; info->fru_id: |" << board_info->fru_id << "|"
|
||||
<< "\n; info->manufacturer_name: |" << board_info->manufacturer_name << "|"
|
||||
<< "\n; info->product_name: |" << board_info->product_name << "|";
|
||||
LOG_INFO(ss);
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -654,7 +722,7 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
status = smi_amdgpu_get_market_name_from_dev_id(dev_info.device_id, info->market_name);
|
||||
if (status != AMDSMI_STATUS_SUCCESS) {
|
||||
rsmi_wrapper(rsmi_dev_brand_get, processor_handle,
|
||||
info->market_name, AMDSMI_NORMAL_STRING_LENGTH);
|
||||
info->market_name, AMDSMI_256_LENGTH);
|
||||
}
|
||||
|
||||
info->device_id = dev_info.device_id;
|
||||
@@ -667,7 +735,7 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
|
||||
if (status == AMDSMI_STATUS_SUCCESS) snprintf(info->asic_serial, sizeof(info->asic_serial), "%lu", dv_uid);
|
||||
|
||||
status = rsmi_wrapper(rsmi_dev_brand_get, processor_handle,
|
||||
info->market_name, AMDSMI_NORMAL_STRING_LENGTH);
|
||||
info->market_name, AMDSMI_256_LENGTH);
|
||||
|
||||
status = rsmi_wrapper(rsmi_dev_vendor_id_get, processor_handle,
|
||||
&vendor_id);
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <sys/ioctl.h>
|
||||
#include <algorithm>
|
||||
#include <limits.h>
|
||||
@@ -45,6 +47,69 @@
|
||||
#include "shared_mutex.h" // NOLINT
|
||||
#include "rocm_smi/rocm_smi_logger.h"
|
||||
|
||||
std::string leftTrim(const std::string &s) {
|
||||
if (!s.empty()) {
|
||||
return std::regex_replace(s, std::regex("^\\s+"), "");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string rightTrim(const std::string &s) {
|
||||
if (!s.empty()) {
|
||||
return std::regex_replace(s, std::regex("\\s+$"), "");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string removeNewLines(const std::string &s) {
|
||||
if (!s.empty()) {
|
||||
return std::regex_replace(s, std::regex("\n+"), "");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string trim(const std::string &s) {
|
||||
if (!s.empty()) {
|
||||
// remove new lines -> trim white space at ends
|
||||
std::string noNewLines = removeNewLines(s);
|
||||
return leftTrim(rightTrim(noNewLines));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// Given original string and string to remove (removeMe)
|
||||
// Return will provide the resulting modified string with the removed string(s)
|
||||
std::string removeString(const std::string origStr,
|
||||
const std::string &removeMe) {
|
||||
std::string modifiedStr = origStr;
|
||||
std::string::size_type l = removeMe.length();
|
||||
for (std::string::size_type i = modifiedStr.find(removeMe);
|
||||
i != std::string::npos;
|
||||
i = modifiedStr.find(removeMe)) {
|
||||
modifiedStr.erase(i, l);
|
||||
}
|
||||
return modifiedStr;
|
||||
}
|
||||
|
||||
void openFileAndModifyBuffer(std::string path, char *buff, size_t sizeOfBuff) {
|
||||
bool errorDiscovered = false;
|
||||
std::ifstream file(path, std::ifstream::in);
|
||||
std::string contents = {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
|
||||
memset(buff, 0, sizeof(char) * sizeOfBuff);
|
||||
if (!file.is_open()) {
|
||||
errorDiscovered = true;
|
||||
} else {
|
||||
contents = trim(contents);
|
||||
}
|
||||
|
||||
file.close();
|
||||
if (!errorDiscovered && file.good() && !file.bad() && !file.fail() && !file.eof()
|
||||
&& !contents.empty()) {
|
||||
std::strncpy(buff, contents.c_str(), sizeOfBuff-1);
|
||||
buff[sizeOfBuff-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t kAmdGpuId = 0x1002;
|
||||
|
||||
static bool isAMDGPU(std::string dev_path) {
|
||||
@@ -123,50 +188,26 @@ amdsmi_status_t smi_amdgpu_get_board_info(amd::smi::AMDSmiGPUDevice* device, amd
|
||||
std::string manufacturer_name_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/manufacturer");
|
||||
std::string product_name_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/product_name");
|
||||
|
||||
FILE *fp;
|
||||
openFileAndModifyBuffer(model_number_path, info->model_number, AMDSMI_256_LENGTH);
|
||||
openFileAndModifyBuffer(product_serial_path, info->product_serial, AMDSMI_NORMAL_STRING_LENGTH);
|
||||
openFileAndModifyBuffer(fru_id_path, info->fru_id, AMDSMI_NORMAL_STRING_LENGTH);
|
||||
openFileAndModifyBuffer(manufacturer_name_path, info->manufacturer_name,
|
||||
AMDSMI_MAX_STRING_LENGTH);
|
||||
openFileAndModifyBuffer(product_name_path, info->product_name, AMDSMI_256_LENGTH);
|
||||
|
||||
fp = fopen(model_number_path.c_str(), "rb");
|
||||
if (fp) {
|
||||
fgets(info->model_number, sizeof(info->model_number), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
fp = fopen(product_serial_path.c_str(), "rb");
|
||||
if (fp) {
|
||||
fgets(info->product_serial, sizeof(info->product_serial), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
fp = fopen(fru_id_path.c_str(), "rb");
|
||||
if (fp) {
|
||||
fgets(info->fru_id, sizeof(info->fru_id), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
fp = fopen(manufacturer_name_path.c_str(), "rb");
|
||||
if (fp) {
|
||||
fgets(info->manufacturer_name, sizeof(info->manufacturer_name), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
fp = fopen(product_name_path.c_str(), "rb");
|
||||
if (fp) {
|
||||
fgets(info->product_name, sizeof(info->product_name), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
std::ostringstream ss;
|
||||
ss << __PRETTY_FUNCTION__
|
||||
ss << __PRETTY_FUNCTION__ << "[Before correction] "
|
||||
<< "Returning status = AMDSMI_STATUS_SUCCESS"
|
||||
<< " | model_number_path = " << model_number_path
|
||||
<< "; info->model_number: " << info->model_number
|
||||
<< "\n product_serial_path = " << product_serial_path
|
||||
<< "; info->product_serial: " << info->product_serial
|
||||
<< "\n fru_id_path = " << fru_id_path
|
||||
<< "; info->fru_id: " << info->fru_id
|
||||
<< "\n manufacturer_name_path = " << manufacturer_name_path
|
||||
<< "; info->manufacturer_name: " << info->manufacturer_name
|
||||
<< "\n product_name_path = " << product_name_path
|
||||
<< "; info->product_name: " << info->product_name;
|
||||
<< " | model_number_path = |" << model_number_path << "|\n"
|
||||
<< "; info->model_number: |" << info->model_number << "|\n"
|
||||
<< "\n product_serial_path = |" << product_serial_path << "|\n"
|
||||
<< "; info->product_serial: |" << info->product_serial << "|\n"
|
||||
<< "\n fru_id_path = |" << fru_id_path << "|\n"
|
||||
<< "; info->fru_id: |" << info->fru_id << "|\n"
|
||||
<< "\n manufacturer_name_path = |" << manufacturer_name_path << "|\n"
|
||||
<< "; info->manufacturer_name: |" << info->manufacturer_name << "|\n"
|
||||
<< "\n product_name_path = |" << product_name_path << "|\n"
|
||||
<< "; info->product_name: |" << info->product_name << "|";
|
||||
LOG_INFO(ss);
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
|
||||
Reference in new issue
Block a user