Add rsmi_dev_busy_percent_get()

Also: correct some comments, ifdef out unused code
This commit is contained in:
Chris Freehill
2018-11-12 17:25:14 -06:00
parent 59a952666f
commit 861c2c2e33
6 changed files with 81 additions and 34 deletions
+28 -8
View File
@@ -277,10 +277,10 @@ rsmi_status_t rsmi_num_monitor_devices(uint32_t *num_devices);
/**
* @brief Get the unique PCI device identifier associated for a device
*
* @details Give a device index @p dev_ind and a pointer to a uint64_t @p
* @details Give a device index @p dv_ind and a pointer to a uint64_t @p
* bdfid, this function will write the Bus/Device/Function PCI identifier
* (BDFID) associated with device @p dev_ind to the value pointed to by
* @bdfid.
* (BDFID) associated with device @p dv_ind to the value pointed to by
* @p bdfid.
*
* @param[in] dv_ind a device index
*
@@ -290,7 +290,7 @@ rsmi_status_t rsmi_num_monitor_devices(uint32_t *num_devices);
* @retval RSMI_STATUS_SUCCESS is returned upon successful call.
*/
rsmi_status_t rsmi_dev_pci_id_get(uint32_t dev_ind, uint64_t *bdfid);
rsmi_status_t rsmi_dev_pci_id_get(uint32_t dv_ind, uint64_t *bdfid);
/**
* @brief Get the device id associated with the device with provided device
@@ -739,8 +739,8 @@ rsmi_dev_power_max_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *power);
*
* @param[in] dv_ind a device index
*
* @param[in] sensor_ind a 0-based sensor index. Normally, this will be 0.
* If a device has more than one sensor, it could be greater than 0.
* @param[in] sensor_ind a 0-based sensor index. Normally, this will be 0.
* If a device has more than one sensor, it could be greater than 0.
*
* @param[inout] status a pointer to rsmi_power_profile_status that will be
* populated by a call to this function
@@ -769,7 +769,7 @@ rsmi_dev_power_profile_presets_get(uint32_t dv_ind, uint32_t sensor_ind,
* @param[in] profile a rsmi_power_profile_preset_masks that hold the mask
* of the desired new power profile
*
* @retval RSMI_STATUS_SUCCESS is returned upon successful call.
* @retval RSMI_STATUS_SUCCESS is returned upon successful call.
*
*/
rsmi_status_t
@@ -786,11 +786,31 @@ rsmi_dev_power_profile_set(uint32_t dv_ind, uint32_t sensor_ind,
* @param[inout] status_string A pointer to a const char * which will be made
* to point to a description of the provided error code
*
* @retval RSMI_STATUS_SUCCESS is returned upon successful call
* @retval RSMI_STATUS_SUCCESS is returned upon successful call
*
*/
rsmi_status_t
rsmi_status_string(rsmi_status_t status, const char **status_string);
/**
* @brief Get percentage of time device is busy doing any processing
*
* @details Given a device index @p dv_ind, this function returns the
* percentage of time that the specified device is busy. The device is
* considered busy if any one or more of its sub-blocks are working, and idle
* if none of the sub-blocks are working.
*
* @param[in] dv_ind a device index
*
* @param[inout] busy_percent a pointer to the uint32_t to which the busy
* percent will be written
*
* @retval RSMI_STATUS_SUCCESS is returned upon successful call
*
*/
rsmi_status_t
rsmi_dev_busy_percent_get(uint32_t dv_ind, uint32_t *busy_percent);
#ifdef __cplusplus
}
#endif // __cplusplus
+5 -1
View File
@@ -64,7 +64,8 @@ enum DevInfoTypes {
kDevDevID,
kDevGPUMClk,
kDevGPUSClk,
kDevPowerProfileMode
kDevPowerProfileMode,
kDevUsage,
};
class Device {
@@ -78,7 +79,10 @@ class Device {
const std::shared_ptr<PowerMon>& power_monitor() {return power_monitor_;}
void set_power_monitor(std::shared_ptr<PowerMon> pm) {power_monitor_ = pm;}
#if 0 // This is not being used right now.
int readDevInfo(DevInfoTypes type, uint32_t *val);
#endif
int readDevInfo(DevInfoTypes type, std::string *val);
int readDevInfo(DevInfoTypes type, std::vector<std::string> *retVec);
int writeDevInfo(DevInfoTypes type, uint64_t val);
+21 -1
View File
@@ -102,7 +102,8 @@ static rsmi_status_t errno_to_rsmi_status(uint32_t err) {
case 0: return RSMI_STATUS_SUCCESS;
case EACCES: return RSMI_STATUS_PERMISSION;
case EPERM: return RSMI_STATUS_NOT_SUPPORTED;
case ENOENT: return RSMI_STATUS_FILE_ERROR;
case ENOENT:
case EISDIR: return RSMI_STATUS_FILE_ERROR;
default: return RSMI_STATUS_UNKNOWN_ERROR;
}
}
@@ -1026,3 +1027,22 @@ rsmi_status_string(rsmi_status_t status, const char **status_string) {
return RSMI_STATUS_SUCCESS;
CATCH
}
rsmi_status_t
rsmi_dev_busy_percent_get(uint32_t dv_ind, uint32_t *busy_percent) {
TRY
std::string val_str;
rsmi_status_t ret = get_dev_value_str(amd::smi::kDevUsage, dv_ind,
&val_str);
if (ret != RSMI_STATUS_SUCCESS) {
return ret;
}
errno = 0;
*busy_percent = strtoul(val_str.c_str(), nullptr, 10);
assert(errno == 0);
return RSMI_STATUS_SUCCESS;
CATCH
}
+9 -5
View File
@@ -64,7 +64,9 @@ static const char *kDevDevIDFName = "device";
static const char *kDevOverDriveLevelFName = "pp_sclk_od";
static const char *kDevGPUSClkFName = "pp_dpm_sclk";
static const char *kDevGPUMClkFName = "pp_dpm_mclk";
static const char *kDevPowerProfileModeName = "pp_power_profile_mode";
static const char *kDevPowerProfileModeFName = "pp_power_profile_mode";
static const char *kDevUsageFName = "gpu_busy_percent";
static const char *kDevPerfLevelAutoStr = "auto";
static const char *kDevPerfLevelLowStr = "low";
static const char *kDevPerfLevelHighStr = "high";
@@ -81,7 +83,8 @@ static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
{kDevDevID, kDevDevIDFName},
{kDevGPUMClk, kDevGPUMClkFName},
{kDevGPUSClk, kDevGPUSClkFName},
{kDevPowerProfileMode, kDevPowerProfileModeName},
{kDevPowerProfileMode, kDevPowerProfileModeFName},
{kDevUsage, kDevUsageFName},
};
static const std::map<rsmi_dev_perf_level, const char *> kDevPerfLvlMap = {
@@ -114,7 +117,6 @@ Device::Device(std::string p, RocmSMI_env_vars const *e) : path_(p), env_(e) {
Device:: ~Device() {
}
// TODO(cfreehil): cache values that are constant
int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
auto tempPath = path_;
@@ -242,12 +244,12 @@ int Device::readDevInfoMultiLineStr(DevInfoTypes type,
return 0;
}
#if 0
int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
assert(val != nullptr);
std::string tempStr;
int ret;
switch (type) {
case kDevDevID:
ret = readDevInfoStr(type, &tempStr);
@@ -255,6 +257,7 @@ int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
*val = std::stoi(tempStr, 0, 16);
break;
case kDevUsage:
case kDevOverDriveLevel:
ret = readDevInfoStr(type, &tempStr);
RET_IF_NONZERO(ret);
@@ -266,7 +269,7 @@ int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
}
return 0;
}
#endif
int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
assert(val != nullptr);
@@ -289,6 +292,7 @@ int Device::readDevInfo(DevInfoTypes type, std::string *val) {
switch (type) {
case kDevPerfLevel:
case kDevUsage:
case kDevOverDriveLevel:
case kDevDevID:
return readDevInfoStr(type, val);
@@ -549,6 +549,23 @@ void TestSanity::Run(void) {
std::cout << f.num_supported << std::endl;
print_frequencies(&f);
}
err = rsmi_dev_busy_percent_get(i, &val_ui32);
if (err != RSMI_STATUS_SUCCESS) {
if (err == RSMI_STATUS_FILE_ERROR) {
IF_VERB(STANDARD) {
std::cout << "\t**GPU Busy Percent: Not supported on this machine"
<< std::endl;
}
} else {
CHK_ERR_ASRT(err)
}
} else {
IF_VERB(STANDARD) {
std::cout << "\t**GPU Busy Percent (Percent Idle):" << std::dec <<
val_ui32 << " (" << 100 - val_ui32 << ")" << std::endl;
}
}
char name[20];
err = rsmi_dev_name_get(i, name, 20);
CHK_ERR_ASRT(err)
+1 -19
View File
@@ -103,24 +103,6 @@ TEST(rsmitst, RSMISanityTest) {
RunGenericTest(&tst);
}
#if 0
TEST(rocrtstFunc, IPC) {
IPCTest ipc;
RunGenericTest(&ipc);
}
TEST(rocrtstFunc, MemoryAccessTests) {
MemoryAccessTest mt;
RunCustomTestProlog(&mt);
mt.CPUAccessToGPUMemoryTest();
mt.GPUAccessToCPUMemoryTest();
RunCustomTestEpilog(&mt);
}
#endif
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
@@ -130,7 +112,7 @@ int main(int argc, char** argv) {
// Set some default values
settings.verbosity = 1;
settings.monitor_verbosity = 1;
settings.num_iterations = 5;
settings.num_iterations = 1;
if (ProcessCmdline(&settings, argc, argv)) {