Merge pull request #19 from cfreehill/master

Add VBIOS version get function

[ROCm/rocm_smi_lib commit: 3e4280d03e]
Αυτή η υποβολή περιλαμβάνεται σε:
Chris Freehill
2019-02-24 11:31:16 -06:00
υποβλήθηκε από GitHub
γονέας 76201111f4 168ac647dd
υποβολή f3b78f353c
7 αρχεία άλλαξαν με 136 προσθήκες και 65 διαγραφές
@@ -993,6 +993,29 @@ rsmi_dev_power_profile_presets_get(uint32_t dv_ind, uint32_t sensor_ind,
rsmi_status_t
rsmi_dev_power_profile_set(uint32_t dv_ind, uint32_t sensor_ind,
rsmi_power_profile_preset_masks profile);
/**
* @brief Get the VBIOS identifer string
*
* @details Given a device ID @p dv_ind, and a pointer to a char buffer,
* @p vbios, this function will write the VBIOS string (up to @p len
* characters) for device @p dv_ind to @p vbios. The caller must ensure that
* it is safe to write at least @p len characters to @p vbios.
*
* @param[in] dv_ind a device index
*
* @param[inout] vbios A pointer to a buffer of char's to which the VBIOS name
* will be written
*
* @param[in] len The number of char's pointed to by @p vbios which can safely
* be written to by this function.
*
* @retval ::RSMI_STATUS_SUCCESS is returned upon successful call.
*
*/
rsmi_status_t
rsmi_dev_vbios_version_get(uint32_t dv_ind, char *vbios, uint32_t len);
/**
* @brief Get a description of a provided RSMI error status
*
@@ -68,6 +68,7 @@ enum DevInfoTypes {
kDevPowerProfileMode,
kDevUsage,
kDevPowerODVoltage,
kDevVBiosVer,
};
class Device {
@@ -102,6 +103,9 @@ class Device {
std::string path_;
uint32_t index_;
const RocmSMI_env_vars *env_;
template <typename T> int openSysfsFileStream(DevInfoTypes type, T *fs,
bool write = false);
int readDevInfoStr(DevInfoTypes type, std::string *retStr);
int readDevInfoMultiLineStr(DevInfoTypes type,
std::vector<std::string> *retVec);
@@ -1369,6 +1369,26 @@ rsmi_dev_busy_percent_get(uint32_t dv_ind, uint32_t *busy_percent) {
CATCH
}
rsmi_status_t
rsmi_dev_vbios_version_get(uint32_t dv_ind, char *vbios, uint32_t len) {
if (vbios == nullptr || len == 0) {
return RSMI_STATUS_INVALID_ARGS;
}
TRY
GET_DEV_FROM_INDX
std::string val_str;
int ret = dev->readDevInfo(amd::smi::kDevVBiosVer, &val_str);
uint32_t ln = val_str.copy(vbios, len);
vbios[std::min(len - 1, ln)] = '\0';
return errno_to_rsmi_status(ret);
CATCH
}
rsmi_status_t
rsmi_version_get(rsmi_version *version) {
TRY
@@ -68,6 +68,7 @@ static const char *kDevGPUPCIEClkFname = "pp_dpm_pcie";
static const char *kDevPowerProfileModeFName = "pp_power_profile_mode";
static const char *kDevPowerODVoltageFName = "pp_od_clk_voltage";
static const char *kDevUsageFName = "gpu_busy_percent";
static const char *kDevVBiosVerFName = "vbios_version";
static const char *kDevPerfLevelAutoStr = "auto";
static const char *kDevPerfLevelLowStr = "low";
@@ -89,6 +90,7 @@ static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
{kDevPowerProfileMode, kDevPowerProfileModeFName},
{kDevUsage, kDevUsageFName},
{kDevPowerODVoltage, kDevPowerODVoltageFName},
{kDevVBiosVer, kDevVBiosVerFName},
};
static const std::map<rsmi_dev_perf_level, const char *> kDevPerfLvlMap = {
@@ -121,30 +123,45 @@ Device::Device(std::string p, RocmSMI_env_vars const *e) : path_(p), env_(e) {
Device:: ~Device() {
}
int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
auto tempPath = path_;
assert(retStr != nullptr);
template <typename T>
int Device::openSysfsFileStream(DevInfoTypes type, T *fs, bool write) {
auto sysfs_path = path_;
if (env_->path_DRM_root_override && type == env_->enum_override) {
tempPath = env_->path_DRM_root_override;
sysfs_path = env_->path_DRM_root_override;
}
if (write) {
sysfs_path += ".write";
}
tempPath += "/device/";
tempPath += kDevAttribNameMap.at(type);
sysfs_path += "/device/";
sysfs_path += kDevAttribNameMap.at(type);
DBG_FILE_ERROR(tempPath, (std::string *)nullptr);
if (!isRegularFile(tempPath)) {
DBG_FILE_ERROR(sysfs_path, (std::string *)nullptr);
if (!isRegularFile(sysfs_path)) {
return EISDIR;
}
std::ifstream fs;
fs.open(tempPath);
fs->open(sysfs_path);
if (!fs.is_open()) {
if (!fs->is_open()) {
return errno;
}
return 0;
}
int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
std::ifstream fs;
int ret = 0;
assert(retStr != nullptr);
ret = openSysfsFileStream(type, &fs);
if (ret != 0) {
return ret;
}
fs >> *retStr;
fs.close();
@@ -153,28 +170,12 @@ int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
int Device::writeDevInfoStr(DevInfoTypes type, std::string valStr) {
auto tempPath = path_;
if (env_->path_DRM_root_override && type == env_->enum_override) {
tempPath = env_->path_DRM_root_override;
}
tempPath += "/device/";
tempPath += kDevAttribNameMap.at(type);
if (env_->path_DRM_root_override && type == env_->enum_override) {
tempPath += ".write";
}
std::ofstream fs;
fs.open(tempPath);
int ret;
DBG_FILE_ERROR(tempPath, &valStr);
if (!isRegularFile(tempPath)) {
return EISDIR;
}
if (!fs.is_open()) {
return errno;
ret = openSysfsFileStream(type, &fs, true);
if (ret != 0) {
return ret;
}
try {
@@ -245,21 +246,14 @@ int Device::readDevInfoMultiLineStr(DevInfoTypes type,
std::vector<std::string> *retVec) {
auto tempPath = path_;
std::string line;
int ret;
std::ifstream fs;
assert(retVec != nullptr);
if (env_->path_DRM_root_override && type == env_->enum_override) {
tempPath = env_->path_DRM_root_override;
}
tempPath += "/device/";
tempPath += kDevAttribNameMap.at(type);
std::ifstream fs(tempPath);
std::stringstream buffer;
DBG_FILE_ERROR(tempPath, (std::string *)nullptr);
if (!isRegularFile(tempPath)) {
return EISDIR;
ret = openSysfsFileStream(type, &fs);
if (ret != 0) {
return ret;
}
while (std::getline(fs, line)) {
@@ -329,6 +323,7 @@ int Device::readDevInfo(DevInfoTypes type, std::string *val) {
case kDevUsage:
case kDevOverDriveLevel:
case kDevDevID:
case kDevVBiosVer:
return readDevInfoStr(type, val);
break;
@@ -51,54 +51,83 @@
#include "gtest/gtest.h"
#include "rocm_smi/rocm_smi.h"
#include "rocm_smi_test/functional/bdfid_read.h"
#include "rocm_smi_test/functional/sys_info_read.h"
#include "rocm_smi_test/test_common.h"
TestBDFIDRead::TestBDFIDRead() : TestBase() {
set_title("RSMI BDFID Read Test");
set_description("The BDFID Read tests verifies that the BDFID "
"value can be read properly.");
TestSysInfoRead::TestSysInfoRead() : TestBase() {
set_title("RSMI System Info Read Test");
set_description("This test verifies that system information such as the "
"BDFID, RSMI version, VBIOS version, etc. can be read properly.");
}
TestBDFIDRead::~TestBDFIDRead(void) {
TestSysInfoRead::~TestSysInfoRead(void) {
}
void TestBDFIDRead::SetUp(void) {
void TestSysInfoRead::SetUp(void) {
TestBase::SetUp();
return;
}
void TestBDFIDRead::DisplayTestInfo(void) {
void TestSysInfoRead::DisplayTestInfo(void) {
TestBase::DisplayTestInfo();
}
void TestBDFIDRead::DisplayResults(void) const {
void TestSysInfoRead::DisplayResults(void) const {
TestBase::DisplayResults();
return;
}
void TestBDFIDRead::Close() {
void TestSysInfoRead::Close() {
// This will close handles opened within rsmitst utility calls and call
// rsmi_shut_down(), so it should be done after other hsa cleanup
TestBase::Close();
}
void TestBDFIDRead::Run(void) {
void TestSysInfoRead::Run(void) {
rsmi_status_t err;
uint64_t val_ui64;
char buffer[80];
rsmi_version ver = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, nullptr};
TestBase::Run();
for (uint32_t i = 0; i < num_monitor_devs(); ++i) {
PrintDeviceHeader(i);
err = rsmi_dev_vbios_version_get(i, buffer, 80);
if (err != RSMI_STATUS_SUCCESS) {
if (err == RSMI_STATUS_FILE_ERROR) {
IF_VERB(STANDARD) {
std::cout << "\t**VBIOS read: Not supported on this machine"
<< std::endl;
}
} else {
CHK_ERR_ASRT(err)
}
} else {
IF_VERB(STANDARD) {
std::cout << "\t**VBIOS Version: " << std::hex << buffer << std::endl;
}
}
err = rsmi_dev_pci_id_get(i, &val_ui64);
CHK_ERR_ASRT(err)
IF_VERB(STANDARD) {
std::cout << "\t**PCI ID (BDFID): 0x" << std::hex << val_ui64;
std::cout << " (" << std::dec << val_ui64 << ")" << std::endl;
}
err = rsmi_version_get(&ver);
CHK_ERR_ASRT(err)
ASSERT_TRUE(ver.major != 0xFFFFFFFF && ver.minor != 0xFFFFFFFF &&
ver.patch != 0xFFFFFFFF && ver.build != nullptr);
IF_VERB(STANDARD) {
std::cout << "\t**RocM SMI Library version: " << ver.major << "." <<
ver.minor << "." << ver.patch << " (" << ver.build << ")" << std::endl;
}
}
}
@@ -42,17 +42,17 @@
* DEALINGS WITH THE SOFTWARE.
*
*/
#ifndef TESTS_ROCM_SMI_TEST_FUNCTIONAL_BDFID_READ_H_
#define TESTS_ROCM_SMI_TEST_FUNCTIONAL_BDFID_READ_H_
#ifndef TESTS_ROCM_SMI_TEST_FUNCTIONAL_SYS_INFO_READ_H_
#define TESTS_ROCM_SMI_TEST_FUNCTIONAL_SYS_INFO_READ_H_
#include "rocm_smi_test/test_base.h"
class TestBDFIDRead : public TestBase {
class TestSysInfoRead : public TestBase {
public:
TestBDFIDRead();
TestSysInfoRead();
// @Brief: Destructor for test case of TestBDFIDRead
virtual ~TestBDFIDRead();
// @Brief: Destructor for test case of TestSysInfoRead
virtual ~TestSysInfoRead();
// @Brief: Setup the environment for measurement
virtual void SetUp();
@@ -70,4 +70,4 @@ class TestBDFIDRead : public TestBase {
virtual void DisplayTestInfo(void);
};
#endif // TESTS_ROCM_SMI_TEST_FUNCTIONAL_BDFID_READ_H_
#endif // TESTS_ROCM_SMI_TEST_FUNCTIONAL_SYS_INFO_READ_H_
@@ -58,7 +58,7 @@
#include "functional/perf_level_read.h"
#include "functional/overdrive_read.h"
#include "functional/frequencies_read.h"
#include "functional/bdfid_read.h"
#include "functional/sys_info_read.h"
#include "functional/gpu_busy_read.h"
#include "functional/power_read.h"
#include "functional/overdrive_read_write.h"
@@ -161,8 +161,8 @@ TEST(rsmitstReadWrite, TestPciBWReadWrite) {
TestPciBWReadWrite tst;
RunGenericTest(&tst);
}
TEST(rsmitstReadOnly, TestBDFIDRead) {
TestBDFIDRead tst;
TEST(rsmitstReadOnly, TestSysInfoRead) {
TestSysInfoRead tst;
RunGenericTest(&tst);
}
TEST(rsmitstReadOnly, TestGPUBusyRead) {