Add support for junction, edge and memory temperature sensors (#42)

* If vendor/device/subsystem name is not found, use device ID string

* Update documentation for get-name functions

* Add support for junction, edge and memory temperature sensors


[ROCm/rocm_smi_lib commit: 11f714326b]
This commit is contained in:
Chris Freehill
2019-05-24 15:24:49 -05:00
committed by GitHub
parent d9e3cf70d0
commit a8fb2a5f29
6 changed files with 128 additions and 42 deletions
+17 -14
View File
@@ -1180,8 +1180,7 @@ get_id_name_str_from_line(uint64_t id, std::string ln,
return ret_str;
}
static rsmi_status_t get_backup_name(uint16_t id, char *name,
size_t len, eNameStrType typ) {
static rsmi_status_t get_backup_name(uint16_t id, char *name, size_t len) {
std::string name_str;
name_str += "0x";
@@ -1291,7 +1290,7 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name,
val_str.clear();
return get_backup_name(typ == NAME_STR_DEVICE ?
device_id : subsys_id, name, len, typ);
device_id : subsys_id, name, len);
}
val_str = get_id_name_str_from_line(vendor_id, ln, &ln_str);
@@ -1315,7 +1314,7 @@ static rsmi_status_t get_dev_name_from_id(uint32_t dv_ind, char *name,
// We should have already returned if we were looking for
// device or subdivce
assert(typ == NAME_STR_VENDOR);
return get_backup_name(vendor_id, name, len, typ);
return get_backup_name(vendor_id, name, len);
}
size_t ct = val_str.copy(name, len);
@@ -1467,7 +1466,7 @@ rsmi_dev_pci_throughput_get(uint32_t dv_ind, uint64_t *sent,
}
rsmi_status_t
rsmi_dev_temp_metric_get(uint32_t dv_ind, uint32_t sensor_ind,
rsmi_dev_temp_metric_get(uint32_t dv_ind, uint32_t sensor_type,
rsmi_temperature_metric_t metric, int64_t *temperature) {
TRY
@@ -1478,14 +1477,6 @@ rsmi_dev_temp_metric_get(uint32_t dv_ind, uint32_t sensor_ind,
rsmi_status_t ret;
amd::smi::MonitorTypes mon_type;
// Make any adjustments to sensor_ind here, if index is not a 0 based. For
// rocm_smi we are using a 0-based index. However, most of the Linux sysfs
// monitor files are 1-based, so we will increment by 1 and make adjustments
// for exceptions later.
// See https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
++sensor_ind;
switch (metric) {
case RSMI_TEMP_CURRENT:
mon_type = amd::smi::kMonTemp;
@@ -1535,7 +1526,19 @@ rsmi_dev_temp_metric_get(uint32_t dv_ind, uint32_t sensor_ind,
DEVICE_MUTEX
ret = get_dev_mon_value(mon_type, dv_ind, sensor_ind, temperature);
GET_DEV_FROM_INDX
assert(dev->monitor() != nullptr);
std::shared_ptr<amd::smi::Monitor> m = dev->monitor();
uint32_t err = m->setSensorLabelMap();
if (err) {
return errno_to_rsmi_status(err);
}
uint32_t sensor_index =
m->getSensorIndex(static_cast<rsmi_temperature_type_t>(sensor_type));
ret = get_dev_mon_value(mon_type, dv_ind, sensor_index, temperature);
return ret;
CATCH
@@ -86,6 +86,18 @@ static const char *kMonTempCritMinHystName = "temp#_lcrit_hyst";
static const char *kMonTempOffsetName = "temp#_offset";
static const char *kMonTempLowestName = "temp#_lowest";
static const char *kMonTempHighestName = "temp#_highest";
static const char *kMonTempLabelName = "temp#_label";
static const char *kTempSensorTypeMemoryName = "mem";
static const char *kTempSensorTypeJunctionName = "junction";
static const char *kTempSensorTypeEdgeName = "edge";
static const std::map<std::string, rsmi_temperature_type_t>
kTempSensorNameMap = {
{kTempSensorTypeMemoryName, RSMI_TEMP_TYPE_MEMORY},
{kTempSensorTypeJunctionName, RSMI_TEMP_TYPE_JUNCTION},
{kTempSensorTypeEdgeName, RSMI_TEMP_TYPE_EDGE},
};
static const std::map<MonitorTypes, const char *> kMonitorNameMap = {
{kMonName, kMonNameFName},
@@ -111,6 +123,7 @@ static const std::map<MonitorTypes, const char *> kMonitorNameMap = {
{kMonTempOffset, kMonTempOffsetName},
{kMonTempLowest, kMonTempLowestName},
{kMonTempHighest, kMonTempHighestName},
{kMonTempLabel, kMonTempLabelName},
};
Monitor::Monitor(std::string path, RocmSMI_env_vars const *e) :
@@ -152,6 +165,39 @@ int Monitor::readMonitor(MonitorTypes type, uint32_t sensor_id,
return ReadSysfsStr(sysfs_path, val);
}
uint32_t
Monitor::setSensorLabelMap(void) {
std::string type_str;
int ret;
if (temp_type_index_map_.size() > 0) {
return 0; // We've already filled in the map
}
auto add_temp_sensor_entry = [&](uint32_t file_index) {
ret = readMonitor(kMonTempLabel, file_index, &type_str);
if (ret) {
return ret;
}
rsmi_temperature_type_t t_type = kTempSensorNameMap.at(type_str);
temp_type_index_map_.insert({t_type, file_index});
return 0;
};
for (uint32_t i = 1; i <= 3; ++i) {
ret = add_temp_sensor_entry(i);
if (ret) {
return ret;
}
}
return 0;
}
uint32_t
Monitor::getSensorIndex(rsmi_temperature_type_t type) {
return temp_type_index_map_.at(type);
}
} // namespace smi
} // namespace amd