cpusensor: Add thresold offset
Added DTS critical offset parameter to change critical thresold
value of DTS sensors.
Tested by setting value in entity manager and seeing output
reflect in dbus interface.
Change-Id: Ib819d20322b7eca5f6e8690827bf97d49695e995
Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
diff --git a/include/CPUSensor.hpp b/include/CPUSensor.hpp
index 2cac56e..1c25655 100644
--- a/include/CPUSensor.hpp
+++ b/include/CPUSensor.hpp
@@ -18,7 +18,8 @@
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& sensorName,
std::vector<thresholds::Threshold>&& thresholds,
- const std::string& configuration, int cpuId, bool show);
+ const std::string& configuration, int cpuId, bool show,
+ double dtsOffset);
~CPUSensor();
static constexpr unsigned int sensorScaleFactor = 1000;
static constexpr unsigned int sensorPollMs = 1000;
@@ -35,6 +36,7 @@
std::string nameTcontrol;
std::string path;
double privTcontrol;
+ double dtsOffset;
bool show;
int errCount;
void setupRead(void);
@@ -117,4 +119,4 @@
}
cpuPresence[gpioNum] = resp;
return resp;
-}
\ No newline at end of file
+}
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index 16b8bb9..f374ab6 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -104,7 +104,8 @@
bool parseThresholdsFromAttr(std::vector<thresholds::Threshold>& thresholds,
const std::string& inputPath,
- const double& scaleFactor);
+ const double& scaleFactor,
+ const double& offset = 0);
bool hasCriticalInterface(
const std::vector<thresholds::Threshold>& thresholdVector);
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index 0920754..7654fde 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -33,12 +33,12 @@
boost::asio::io_service& io, const std::string& sensorName,
std::vector<thresholds::Threshold>&& _thresholds,
const std::string& sensorConfiguration, int cpuId,
- bool show) :
+ bool show, double dtsOffset) :
Sensor(boost::replace_all_copy(sensorName, " ", "_"),
std::move(_thresholds), sensorConfiguration, objectType, maxReading,
minReading),
objServer(objectServer), inputDev(io, open(path.c_str(), O_RDONLY)),
- path(path), waitTimer(io), show(show),
+ path(path), waitTimer(io), show(show), dtsOffset(dtsOffset),
privTcontrol(std::numeric_limits<double>::quiet_NaN()), errCount(0)
{
nameTcontrol = labelTcontrol;
@@ -132,7 +132,8 @@
{
std::vector<thresholds::Threshold> newThresholds;
if (parseThresholdsFromAttr(newThresholds, path,
- CPUSensor::sensorScaleFactor))
+ CPUSensor::sensorScaleFactor,
+ dtsOffset))
{
if (!std::equal(thresholds.begin(), thresholds.end(),
newThresholds.begin(),
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index 44c5178..2f2319d 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -289,6 +289,22 @@
}
}
+ /*
+ * Find if there is DtsCritOffset is configured in config file
+ * set it if configured or else set it to 0
+ */
+ double dtsOffset = 0;
+ if (label == "DTS")
+ {
+ auto findThrOffset =
+ baseConfiguration->second.find("DtsCritOffset");
+ if (findThrOffset != baseConfiguration->second.end())
+ {
+ dtsOffset = std::visit(VariantToDoubleVisitor(),
+ findThrOffset->second);
+ }
+ }
+
std::vector<thresholds::Threshold> sensorThresholds;
std::string labelHead = label.substr(0, label.find(" "));
parseThresholdsFromConfig(*sensorData, sensorThresholds,
@@ -296,7 +312,8 @@
if (sensorThresholds.empty())
{
if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr,
- CPUSensor::sensorScaleFactor))
+ CPUSensor::sensorScaleFactor,
+ dtsOffset))
{
std::cerr << "error populating thresholds for "
<< sensorName << "\n";
@@ -305,7 +322,7 @@
gCpuSensors[sensorName] = std::make_unique<CPUSensor>(
inputPathStr, sensorType, objectServer, dbusConnection, io,
sensorName, std::move(sensorThresholds), *interfacePath, cpuId,
- show);
+ show, dtsOffset);
createdSensors.insert(sensorName);
if (DEBUG)
{
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index a15da17..3dd444d 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -330,7 +330,8 @@
bool parseThresholdsFromAttr(
std::vector<thresholds::Threshold>& thresholdVector,
- const std::string& inputPath, const double& scaleFactor)
+ const std::string& inputPath, const double& scaleFactor,
+ const double& offset)
{
for (auto& type : attrTypes)
{
@@ -364,6 +365,11 @@
direction = Direction::HIGH;
}
+ if (type == "crit")
+ {
+ val += offset;
+ }
+
if (DEBUG)
{
std::cout << "Threshold: " << attrPath << ": " << val << "\n";