Merge "Support PCIe vendor name" into amd-dev

[ROCm/amdsmi commit: fc5b481124]
This commit is contained in:
Shuzhou Liu
2023-08-30 09:58:21 -04:00
zatwierdzone przez Gerrit Code Review
12 zmienionych plików z 156 dodań i 11 usunięć
@@ -391,11 +391,12 @@ typedef struct {
typedef struct {
char market_name[AMDSMI_MAX_STRING_LENGTH];
uint32_t vendor_id; //< Use 32 bit to be compatible with other platform.
char vendor_name[AMDSMI_MAX_STRING_LENGTH];
uint32_t subvendor_id; //< The subsystem vendor id
uint64_t device_id; //< The device id of a GPU
uint32_t rev_id;
char asic_serial[AMDSMI_NORMAL_STRING_LENGTH];
uint32_t reserved[3];
uint32_t reserved[19];
} amdsmi_asic_info_t;
typedef struct {
@@ -667,11 +667,12 @@ struct_c__SA_amdsmi_asic_info_t._pack_ = 1 # source:False
struct_c__SA_amdsmi_asic_info_t._fields_ = [
('market_name', ctypes.c_char * 64),
('vendor_id', ctypes.c_uint32),
('vendor_name', ctypes.c_char * 64),
('subvendor_id', ctypes.c_uint32),
('device_id', ctypes.c_uint64),
('rev_id', ctypes.c_uint32),
('asic_serial', ctypes.c_char * 32),
('reserved', ctypes.c_uint32 * 3),
('reserved', ctypes.c_uint32 * 19),
]
amdsmi_asic_info_t = struct_c__SA_amdsmi_asic_info_t
@@ -722,6 +722,11 @@ int main() {
CHK_RSMI_RET_I(ret)
std::cout << "\t**Dev.Rev.ID: 0x" << std::hex << val_ui16 << std::endl;
char pcie_vendor_name[256];
ret = rsmi_dev_pcie_vendor_name_get(i, pcie_vendor_name, 256);
CHK_RSMI_RET_I(ret)
std::cout << "\t**PCIe vendor name: " << pcie_vendor_name << std::endl;
char current_compute_partition[256];
current_compute_partition[0] = '\0';
ret = rsmi_dev_compute_partition_get(i, current_compute_partition, 256);
@@ -1155,6 +1155,43 @@ rsmi_status_t rsmi_dev_sku_get(uint32_t dv_ind, uint16_t *sku);
*/
rsmi_status_t rsmi_dev_vendor_id_get(uint32_t dv_ind, uint16_t *id);
/**
* @brief Get the name string for a give PCIe vendor ID
*
* @details Given a device index @p dv_ind, a pointer to a caller provided
* char buffer @p name, and a length of this buffer @p len, this function will
* write the name of the PCIe vendor (up to @p len characters) buffer @p name.
*
* If the integer ID associated with the PCIe vendor is not found in one of the
* system files containing device name information (e.g.
* /usr/share/misc/pci.ids), then this function will return RSMI_STATUS_NOT_FOUND.
* Updating the system name files can be accompplished with
* "sudo update-pciids".
*
* @param[in] dv_ind a device index
*
* @param[inout] name a pointer to a caller provided char buffer to which the
* name 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.
*
* @param[in] len the length of the caller provided buffer @p name.
*
* @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
* @retval ::RSMI_STATUS_NOT_FOUND the vnedor name are not found
* @retval ::RSMI_STATUS_INSUFFICIENT_SIZE is returned if @p len bytes is not
* large enough to hold the entire name. In this case, only @p len bytes will
* be written.
*
*/
rsmi_status_t rsmi_dev_pcie_vendor_name_get(uint32_t dv_ind, char *name,
size_t len);
/**
* @brief Get the name string of a gpu device.
*
@@ -167,7 +167,12 @@ enum DevInfoTypes {
kDevGpuReset,
kDevAvailableComputePartition,
kDevComputePartition,
kDevMemoryPartition
kDevMemoryPartition,
// The information read from pci core sysfs
kDevPCieTypeStart = 1000,
kDevPCieVendorID = kDevPCieTypeStart,
kDevPCieTypeEND = 2000,
};
typedef struct {
@@ -103,6 +103,7 @@ std::tuple<bool, std::string, std::string, std::string, std::string,
getSystemDetails(void);
void logSystemDetails(void);
rsmi_status_t getBDFString(uint64_t bdf_id, std::string& bfd_str);
rsmi_status_t getBDFWithDomain(uint64_t bdf_id, std::string& bfd_str);
void logHexDump(const char *desc, const void *addr, const size_t len,
size_t perLine);
bool isSystemBigEndian();
@@ -1979,6 +1979,28 @@ static rsmi_status_t get_dev_name_from_file(uint32_t dv_ind, char *name,
return RSMI_STATUS_SUCCESS;
}
// return empty if cannot find it in pci.ids
static std::string get_vendor_name_from_id(uint16_t vendor_id) {
for (auto fl : pci_name_files) {
std::ifstream id_file_strm(fl);
std::string ln;
while (std::getline(id_file_strm, ln)) {
// parse line
if (ln == "" || ln[0] == '#' || ln[0] == '\t') {
continue;
}
std::istringstream ln_str(ln);
std::string val_str = get_id_name_str_from_line(vendor_id, ln, &ln_str);
if (val_str != "") {
return val_str;
}
}
}
return "";
}
// Parse pci.ids files. Comment lines have # in first column. Otherwise,
// Syntax:
// vendor vendor_name
@@ -2157,6 +2179,35 @@ rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len) {
CATCH
}
rsmi_status_t
rsmi_dev_pcie_vendor_name_get(uint32_t dv_ind, char *name, size_t len) {
rsmi_status_t ret;
TRY
std::ostringstream ss;
ss << __PRETTY_FUNCTION__ << "| ======= start =======";
LOG_TRACE(ss);
CHK_SUPPORT_NAME_ONLY(name)
if (len == 0) {
return RSMI_STATUS_INVALID_ARGS;
}
DEVICE_MUTEX
uint16_t id = 0;
ret = get_id(dv_ind, amd::smi::kDevPCieVendorID, &id);
if (ret != RSMI_STATUS_SUCCESS) return ret;
std::string vendor_name = get_vendor_name_from_id(id);
if (vendor_name == "") {
return RSMI_STATUS_NOT_FOUND;
}
memset(name, 0, len);
strncpy(name, vendor_name.c_str(), len-1);
return ret;
CATCH
}
rsmi_status_t
rsmi_dev_brand_get(uint32_t dv_ind, char *brand, uint32_t len) {
TRY
@@ -81,6 +81,9 @@ static const char *kPathDebugRootFName = "/sys/kernel/debug/dri/";
// Device debugfs file names
static const char *kDevGpuResetFName = "amdgpu_gpu_recover";
// PCI sysfs file names
static const char *kDevPCieVendorIDFName = "vendor";
// Device sysfs file names
static const char *kDevPerfLevelFName = "power_dpm_force_performance_level";
static const char *kDevDevProdNameFName = "product_name";
@@ -242,6 +245,7 @@ static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
{kDevDevID, kDevDevIDFName},
{kDevDevRevID, kDevDevRevIDFName},
{kDevVendorID, kDevVendorIDFName},
{kDevPCieVendorID, kDevPCieVendorIDFName},
{kDevSubSysDevID, kDevSubSysDevIDFName},
{kDevSubSysVendorID, kDevSubSysVendorIDFName},
{kDevGPUMClk, kDevGPUMClkFName},
@@ -589,6 +593,20 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) {
sysfs_path += "/device/";
sysfs_path += kDevAttribNameMap.at(type);
// For the file under PCI sysfs
if (type >= kDevPCieTypeStart && type <= kDevPCieTypeEND) {
sysfs_path = "/sys/bus/pci/devices/";
std::string bdf_str;
if (getBDFWithDomain(bdfid_, bdf_str) != RSMI_STATUS_SUCCESS) {
ss << "Fail to craft the bdf string";
LOG_ERROR(ss);
return 1;
}
sysfs_path += bdf_str;
sysfs_path += "/";
sysfs_path += kDevAttribNameMap.at(type);
}
DBG_FILE_ERROR(sysfs_path, str);
bool reg_file;
@@ -611,7 +629,7 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) {
fs->open(sysfs_path);
if (!fs->is_open()) {
if (!fs) {
ss << "Could not open - SYSFS file (" << sysfs_path << ") for "
<< "DevInfoInfoType (" << RocmSMI::devInfoTypesStrings.at(type) << "), "
<< ", returning " << std::to_string(errno) << " ("
@@ -901,6 +919,7 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) {
case kDevSubSysDevID:
case kDevSubSysVendorID:
case kDevVendorID:
case kDevPCieVendorID:
case kDevErrCntFeatures:
ret = readDevInfoStr(type, &tempStr);
RET_IF_NONZERO(ret);
@@ -1038,6 +1057,7 @@ int Device::readDevInfo(DevInfoTypes type, std::string *val) {
case kDevSubSysDevID:
case kDevSubSysVendorID:
case kDevVendorID:
case kDevPCieVendorID:
case kDevVramVendor:
case kDevVBiosVer:
case kDevPCIEThruPut:
@@ -150,7 +150,8 @@ amd::smi::RocmSMI::devInfoTypesStrings = {
{amd::smi::kDevAvailableComputePartition, amdSMI +
"kDevAvailableComputePartition"},
{amd::smi::kDevComputePartition, amdSMI + "kDevComputePartition"},
{amd::smi::kDevMemoryPartition, amdSMI + "kDevMemoryPartition"}
{amd::smi::kDevMemoryPartition, amdSMI + "kDevMemoryPartition"},
{amd::smi::kDevPCieVendorID, amdSMI + "kDevPCieVendorID"},
};
namespace amd {
@@ -54,6 +54,7 @@
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <vector>
@@ -792,6 +793,29 @@ bool isSystemBigEndian() {
return isBigEndian;
}
rsmi_status_t getBDFWithDomain(uint64_t bdf_id, std::string& bfd_str)
{
auto result = rsmi_status_t::RSMI_STATUS_SUCCESS;
auto domain_id = static_cast<uint32_t>(bdf_id >> 32);
auto bus_id = static_cast<uint8_t>((bdf_id & 0x0000FF00) >> 8);
auto dev_id = static_cast<uint8_t>((bdf_id & 0x000000F8) >> 3);
auto func_id = static_cast<uint8_t>(bdf_id & 0x00000003);
bfd_str = std::string();
if (!(bus_id > 0)) {
result = rsmi_status_t::RSMI_STATUS_NO_DATA;
return result;
}
std::stringstream bdf_sstream;
bdf_sstream << std::hex << std::setfill('0') << std::setw(4) << +domain_id << ":";
bdf_sstream << std::hex << std::setfill('0') << std::setw(2) << +bus_id << ":";
bdf_sstream << std::hex << std::setfill('0') << std::setw(2) << +dev_id << ".";
bdf_sstream << std::hex << std::setfill('0') << +func_id;
bfd_str = bdf_sstream.str();
return result;
}
rsmi_status_t getBDFString(uint64_t bdf_id, std::string& bfd_str)
{
auto result = rsmi_status_t::RSMI_STATUS_SUCCESS;
+3 -1
Wyświetl plik
@@ -671,7 +671,6 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
info->rev_id = dev_info.pci_rev;
info->vendor_id = gpu_device->get_vendor_id();
}
// For other sysfs related information, get from rocm-smi
else {
uint64_t dv_uid = 0;
status = rsmi_wrapper(rsmi_dev_unique_id_get, processor_handle, &dv_uid);
@@ -688,6 +687,9 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i
&subvendor_id);
if (status == AMDSMI_STATUS_SUCCESS) info->subvendor_id = subvendor_id;
}
// For other sysfs related information, get from rocm-smi
status = rsmi_wrapper(rsmi_dev_pcie_vendor_name_get, processor_handle,
info->vendor_name, AMDSMI_MAX_STRING_LENGTH);
return AMDSMI_STATUS_SUCCESS;
}
@@ -163,11 +163,8 @@ void TestSysInfoRead::Run(void) {
} else {
if (err == AMDSMI_STATUS_SUCCESS) {
IF_VERB(STANDARD) {
// TODO(bliu): read unique_id
/*
std::cout << "\t**GPU Unique ID : " << std::hex << asci_info.unique_id <<
std::endl;
*/
std:: cout << "\t**GPU PCIe Vendor : "
<< asci_info.vendor_name << std::endl;
}
// Verify api support checking functionality is working
err = amdsmi_get_gpu_asic_info(processor_handles_[i], nullptr);