Comment corrections, debug output and assert added

Este cometimento está contido em:
Chris Freehill cometeu 2018-10-22 17:26:38 -05:00
1 ascendente e046fbdddf
cometimento b2f1ee1764
12 ficheiros modificados
+147 -40

Não existem ficheiros que correspondam à sua pesquisa

+6 -2
Ver ficheiro
@@ -441,6 +441,12 @@ static rsmi_status_t get_frequencies(amd::smi::DevInfoTypes type,
for (uint32_t i = 0; i < f->num_supported; ++i) {
f->frequency[i] = freq_string_to_int(val_vec[i], &current);
// Our assumption is that frequencies are read in from lowest to highest.
// Check that that is true.
if (i > 0) {
assert(f->frequency[i-1] <= f->frequency[i]);
}
if (current) {
// Should only be 1 current frequency
assert(f->current == RSMI_MAX_NUM_FREQUENCIES + 1);
@@ -511,8 +517,6 @@ static rsmi_status_t set_power_profile(uint32_t dv_ind,
rsmi_status_t ret;
rsmi_power_profile_status avail_profiles = {0, RSMI_PWR_PROF_PRST_INVALID, 0};
// TODO(cf): test if it is valid to OR profiles; if not the following is
// not necessary:
// Determine if the provided profile is valid
if (!is_power_of_2(profile)) {
return RSMI_STATUS_INPUT_OUT_OF_BOUNDS;
+7 -2
Ver ficheiro
@@ -98,7 +98,7 @@ static bool isRegularFile(std::string fname) {
if (X) return X; \
}
Device::Device(std::string p) : path_(p) {
Device::Device(std::string p, RocmSMI_env_vars const *e) : path_(p), env_(e) {
monitor_ = nullptr;
}
@@ -114,6 +114,7 @@ int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
tempPath += "/device/";
tempPath += kDevAttribNameMap.at(type);
DBG_FILE_ERROR(tempPath);
if (!isRegularFile(tempPath)) {
return EISDIR;
}
@@ -121,6 +122,7 @@ int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
std::ifstream fs;
fs.open(tempPath);
DBG_FILE_ERROR(tempPath);
if (!fs.is_open()) {
return errno;
}
@@ -139,12 +141,14 @@ int Device::writeDevInfoStr(DevInfoTypes type, std::string valStr) {
std::ofstream fs;
fs.open(tempPath);
DBG_FILE_ERROR(tempPath);
if (!isRegularFile(tempPath)) {
return EISDIR;
}
DBG_FILE_ERROR(tempPath);
if (!fs.is_open()) {
return errno;
return errno;
}
fs << valStr;
@@ -206,6 +210,7 @@ int Device::readDevInfoMultiLineStr(DevInfoTypes type,
std::stringstream buffer;
DBG_FILE_ERROR(tempPath);
if (!isRegularFile(tempPath)) {
return EISDIR;
}
+23 -3
Ver ficheiro
@@ -48,6 +48,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string>
#include <cstdint>
@@ -138,6 +139,8 @@ std::vector<std::shared_ptr<amd::smi::Device>> RocmSMI::s_monitor_devices;
RocmSMI::RocmSMI(void) {
auto i = 0;
GetEnvVariables();
while (std::string(kAMDMonitorTypes[i]) != "") {
amd_monitor_types_.insert(kAMDMonitorTypes[i]);
++i;
@@ -165,6 +168,20 @@ RocmSMI& RocmSMI::getInstance(void) {
return singleton;
}
static int GetEnvVarInteger(const char *ev_str) {
ev_str = getenv(ev_str);
if (ev_str) {
return atoi(ev_str);
}
return 0;
}
// Get and store env. variables in this method
void RocmSMI::GetEnvVariables(void) {
env_vars_.debug_output_bitfield = GetEnvVarInteger("RSMI_DEBUG_BITFIELD");
}
void
RocmSMI::AddToDeviceList(std::string dev_name) {
auto ret = 0;
@@ -173,7 +190,7 @@ RocmSMI::AddToDeviceList(std::string dev_name) {
dev_path += "/";
dev_path += dev_name;
auto dev = std::shared_ptr<Device>(new Device(dev_path));
auto dev = std::shared_ptr<Device>(new Device(dev_path, &env_vars_));
auto m = monitors_.begin();
@@ -214,6 +231,8 @@ uint32_t RocmSMI::DiscoverDevices(void) {
}
auto drm_dir = opendir(kPathDRMRoot);
assert(drm_dir != nullptr);
auto dentry = readdir(drm_dir);
while (dentry != nullptr) {
@@ -261,7 +280,8 @@ uint32_t RocmSMI::DiscoverAMDMonitors(void) {
fs.close();
if (amd_monitor_types_.find(mon_type) != amd_monitor_types_.end()) {
monitors_.push_back(std::shared_ptr<Monitor>(new Monitor(mon_name)));
monitors_.push_back(std::shared_ptr<Monitor>(
new Monitor(mon_name, &env_vars_)));
}
}
dentry = readdir(mon_dir);
@@ -311,7 +331,7 @@ uint32_t RocmSMI::DiscoverAMDPowerMonitors(bool force_update) {
if (FileExists(tmp.c_str())) {
std::shared_ptr<PowerMon> mon =
std::shared_ptr<PowerMon>(new PowerMon(mon_name));
std::shared_ptr<PowerMon>(new PowerMon(mon_name, &env_vars_));
power_mons_.push_back(mon);
mon->set_dev_index(GetDeviceIndex(dentry->d_name));
}
+5 -1
Ver ficheiro
@@ -114,7 +114,8 @@ static const std::map<MonitorTypes, const char *> kMonitorNameMap = {
{kMonTempHighest, kMonTempHighestName},
};
Monitor::Monitor(std::string path) : path_(path) {
Monitor::Monitor(std::string path, RocmSMI_env_vars const *e) :
path_(path), env_(e) {
}
Monitor::~Monitor(void) {
}
@@ -135,6 +136,8 @@ Monitor::MakeMonitorPath(MonitorTypes type, int32_t sensor_id) {
int Monitor::writeMonitor(MonitorTypes type, uint32_t sensor_id,
std::string val) {
std::string sysfs_path = MakeMonitorPath(type, sensor_id);
DBG_FILE_ERROR(sysfs_path)
return WriteSysfsStr(sysfs_path, val);
}
@@ -146,6 +149,7 @@ int Monitor::readMonitor(MonitorTypes type, uint32_t sensor_id,
std::string temp_str;
std::string sysfs_path = MakeMonitorPath(type, sensor_id);
DBG_FILE_ERROR(sysfs_path)
return ReadSysfsStr(sysfs_path, val);
}
+5 -1
Ver ficheiro
@@ -55,6 +55,7 @@
#include "rocm_smi/rocm_smi_main.h"
#include "rocm_smi/rocm_smi_monitor.h"
#include "rocm_smi/rocm_smi_utils.h"
#include "rocm_smi/rocm_smi_common.h"
namespace amd {
namespace smi {
@@ -68,7 +69,8 @@ static const std::map<PowerMonTypes, const char *> kMonitorNameMap = {
{kPowerAveGPUPower, kPowerMonPMName},
};
PowerMon::PowerMon(std::string path) : path_(path) {
PowerMon::PowerMon(std::string path, RocmSMI_env_vars const *e) :
path_(path), env_(e) {
}
PowerMon::~PowerMon(void) {
}
@@ -139,6 +141,8 @@ int PowerMon::readPowerValue(PowerMonTypes type, uint64_t *power) {
tempPath += "/";
tempPath += kMonitorNameMap.at(type);
DBG_FILE_ERROR(tempPath)
int ret = ReadSysfsStr(tempPath, &fstr);
if (ret) {