Adding functionality that will parse gpu_metrics sysfs file
Signed-off-by: Divya Shikre <DivyaUday.Shikre@amd.com> Change-Id: I3a84870b83eb4cd0ed46f10bb19169c91f99fd8e
This commit is contained in:
committed by
Divya Uday Shikre
parent
3522e94ed0
commit
8b48564ce3
+23
-1
@@ -1033,7 +1033,6 @@ static rsmi_status_t get_od_clk_volt_info(uint32_t dv_ind,
|
||||
CATCH
|
||||
}
|
||||
|
||||
|
||||
rsmi_status_t rsmi_dev_od_clk_info_set(uint32_t dv_ind, rsmi_freq_ind_t level,
|
||||
uint64_t clkvalue,
|
||||
rsmi_clk_type_t clkType) {
|
||||
@@ -2158,6 +2157,29 @@ rsmi_dev_od_volt_info_get(uint32_t dv_ind, rsmi_od_volt_freq_data_t *odv) {
|
||||
CATCH
|
||||
}
|
||||
|
||||
rsmi_status_t
|
||||
rsmi_dev_gpu_metrics_info_get(uint32_t dv_ind, rsmi_gpu_metrics_t *smu) {
|
||||
TRY
|
||||
DEVICE_MUTEX
|
||||
CHK_SUPPORT_NAME_ONLY(smu)
|
||||
|
||||
std::vector<unsigned char> val_vec;
|
||||
rsmi_status_t ret = GetDevBinaryVec(amd::smi::kDevGpuMetrics, dv_ind,
|
||||
&val_vec);
|
||||
if (ret != RSMI_STATUS_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (val_vec.size() == 0) {
|
||||
return RSMI_STATUS_NOT_YET_IMPLEMENTED;
|
||||
}
|
||||
|
||||
smu = reinterpret_cast<rsmi_gpu_metrics_t *>(val_vec.data());
|
||||
|
||||
return ret;
|
||||
CATCH
|
||||
}
|
||||
|
||||
rsmi_status_t rsmi_dev_od_volt_curve_regions_get(uint32_t dv_ind,
|
||||
uint32_t *num_regions, rsmi_freq_volt_region_t *buffer) {
|
||||
TRY
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "rocm_smi/rocm_smi_main.h"
|
||||
#include "rocm_smi/rocm_smi_device.h"
|
||||
@@ -106,6 +107,7 @@ static const char *kDevMemBusyPercentFName = "mem_busy_percent";
|
||||
static const char *kDevXGMIErrorFName = "xgmi_error";
|
||||
static const char *kDevSerialNumberFName = "serial_number";
|
||||
static const char *kDevNumaNodeFName = "numa_node";
|
||||
static const char *kDevGpuMetricsFName = "gpu_metrics";
|
||||
|
||||
// Firmware version files
|
||||
static const char *kDevFwVersionAsdFName = "fw_version/asd_fw_version";
|
||||
@@ -265,6 +267,7 @@ static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
|
||||
{kDevSerialNumber, kDevSerialNumberFName},
|
||||
{kDevMemPageBad, kDevMemPageBadFName},
|
||||
{kDevNumaNode, kDevNumaNodeFName},
|
||||
{kDevGpuMetrics, kDevGpuMetricsFName},
|
||||
};
|
||||
|
||||
static const std::map<rsmi_dev_perf_level, const char *> kDevPerfLvlMap = {
|
||||
@@ -375,6 +378,7 @@ static const std::map<const char *, dev_depends_t> kDevFuncDependsMap = {
|
||||
{"rsmi_dev_xgmi_error_reset", {{kDevXGMIErrorFName}, {}}},
|
||||
{"rsmi_dev_memory_reserved_pages_get", {{kDevMemPageBadFName}, {}}},
|
||||
{"rsmi_topo_numa_affinity_get", {{kDevNumaNodeFName}, {}}},
|
||||
{"rsmi_dev_gpu_metrics_info_get", {{kDevGpuMetricsFName}, {}}},
|
||||
|
||||
// These functions with variants, but no sensors/units. (May or may not
|
||||
// have mandatory dependencies.)
|
||||
@@ -624,6 +628,24 @@ int Device::readDevInfoLine(DevInfoTypes type, std::string *line) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Device::readDevInfoBinary(DevInfoTypes type,
|
||||
std::vector<unsigned char> *retVec) {
|
||||
auto sysfs_path = path_;
|
||||
|
||||
sysfs_path += "/device/";
|
||||
sysfs_path += kDevAttribNameMap.at(type);
|
||||
|
||||
std::ifstream fs(sysfs_path, std::ios::binary);
|
||||
if (!fs.is_open()) {
|
||||
return errno;
|
||||
}
|
||||
// copies all data into buffer
|
||||
retVec->insert(retVec->begin(),
|
||||
std::istreambuf_iterator<char>(fs),{});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Device::readDevInfoMultiLineStr(DevInfoTypes type,
|
||||
std::vector<std::string> *retVec) {
|
||||
std::string line;
|
||||
@@ -754,6 +776,21 @@ int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Device::readDevInfo(DevInfoTypes type, std::vector<unsigned char> *val) {
|
||||
assert(val != nullptr);
|
||||
|
||||
switch (type) {
|
||||
case kDevGpuMetrics:
|
||||
return readDevInfoBinary(type, val);
|
||||
break;
|
||||
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Device::readDevInfo(DevInfoTypes type, std::string *val) {
|
||||
assert(val != nullptr);
|
||||
|
||||
|
||||
@@ -204,6 +204,18 @@ rsmi_status_t GetDevValueVec(amd::smi::DevInfoTypes type,
|
||||
return ErrnoToRsmiStatus(ret);
|
||||
}
|
||||
|
||||
rsmi_status_t GetDevBinaryVec(amd::smi::DevInfoTypes type,
|
||||
uint32_t dv_ind, std::vector<unsigned char> *val_vec) {
|
||||
assert(val_vec != nullptr);
|
||||
if (val_vec == nullptr) {
|
||||
return RSMI_STATUS_INVALID_ARGS;
|
||||
}
|
||||
GET_DEV_FROM_INDX
|
||||
|
||||
int ret = dev->readDevInfo(type, val_vec);
|
||||
return ErrnoToRsmiStatus(ret);
|
||||
}
|
||||
|
||||
rsmi_status_t ErrnoToRsmiStatus(uint32_t err) {
|
||||
switch (err) {
|
||||
case 0: return RSMI_STATUS_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user