Store sensor return codes for dbus removal
Add any return codes defined at the device level and/or the sensor
within the hwmon device config file for removal of the sensor.
The sensor is removed from dbus when any of those return codes given are
received by hwmon when doing a read.
ex.)
Removal return codes 2 & 11 defined at device level apply for all
sensors(gpu0 core & mem) whereas removal return code 5 applies to only
the the gpu0 core temp sensor.
REMOVERCS = "2,11"
LABEL_temp1 = "gpu0_core_temp"
WARNHI_temp1 = "75000"
WARNLO_temp1 = "0"
CRITHI_temp1 = "80000"
CRITLO_temp1 = "0"
REMOVERCS_temp1 = "5"
LABEL_temp2 = "gpu0_mem_temp"
WARNHI_temp2 = "75000"
WARNLO_temp2 = "0"
CRITHI_temp2 = "80000"
CRITLO_temp2 = "0"
Tested:
All device sensors contain removal return code defined on the device
Each sensor contains removal return codes defined on them
Change-Id: Ib0bf1e38ae40aaaea06e93d96322f9499eeefdb1
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index 50eb514..d33ea44 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -18,6 +18,7 @@
#include <memory>
#include <cstdlib>
#include <string>
+#include <unordered_set>
#include <phosphor-logging/elog-errors.hpp>
#include "config.h"
@@ -68,6 +69,7 @@
{
double gain = 1.0;
int offset = 0;
+ std::unordered_set<int> rmRCs;
};
// Store the valueAdjust for sensors
@@ -155,6 +157,32 @@
return true;
}
+void addRemoveRCs(const SensorSet::key_type& sensor,
+ const std::string& rcList)
+{
+ // Convert to a char* for strtok
+ std::vector<char> rmRCs(rcList.c_str(),
+ rcList.c_str() + rcList.size() + 1);
+ auto rmRC = strtok(&rmRCs[0], ", ");
+ while (rmRC != nullptr)
+ {
+ try
+ {
+ sensorAdjusts[sensor].rmRCs.insert(std::stoi(rmRC));
+ }
+ catch (const std::logic_error& le)
+ {
+ // Unable to convert to int, continue to next token
+ std::string name = sensor.first + "_" + sensor.second;
+ log<level::INFO>("Unable to convert sensor removal return code",
+ entry("SENSOR=%s", name.c_str()),
+ entry("RC=%s", rmRC),
+ entry("EXCEPTION=%s", le.what()));
+ }
+ rmRC = strtok(nullptr, ", ");
+ }
+}
+
int64_t adjustValue(const SensorSet::key_type& sensor, int64_t value)
{
// Because read doesn't have an out pointer to store errors.
@@ -191,6 +219,13 @@
auto& obj = std::get<Object>(info);
auto& objPath = std::get<std::string>(info);
+ auto senRmRCs = getEnv("REMOVERCS", sensor);
+ if (!senRmRCs.empty())
+ {
+ // Add sensor removal return codes defined per sensor
+ addRemoveRCs(sensor, senRmRCs);
+ }
+
int64_t val = 0;
try
{
@@ -368,6 +403,14 @@
}
}
+ // Get list of return codes for removing sensors on device
+ std::string deviceRmRCs;
+ auto devRmRCs = getenv("REMOVERCS");
+ if (devRmRCs)
+ {
+ deviceRmRCs.assign(devRmRCs);
+ }
+
// Check sysfs for available sensors.
auto sensors = std::make_unique<SensorSet>(_hwmonRoot + '/' + _instance);
@@ -413,6 +456,12 @@
continue;
}
+ if (!deviceRmRCs.empty())
+ {
+ // Add sensor removal return codes defined at the device level
+ addRemoveRCs(i.first, deviceRmRCs);
+ }
+
std::string objectPath{_root};
objectPath.append(1, '/');
objectPath.append(getNamespace(attrs));