Add threshold value scanning logic into cpusensor
Threshold values of a CPU sensor can be changed at runtime by BIOS
based on the thermal policy changes of the host machine. So this
commit adds runtime scanning logic for reading threshold values
from hwmon subsystem attributes.
Tested:
Check threshold properties in xyz.openbmc_projects.CPUSensor.
All threshold vaues should reflect peci hwmon values dynamically.
Change-Id: Ib5b0ce72f567437e69879a7e655d6f34f156013e
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index 8bcc4fa..cd1e3b5 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -28,6 +28,12 @@
double value;
bool writeable;
bool asserted = false;
+
+ bool operator==(const Threshold& rhs) const
+ {
+ return (level == rhs.level && direction == rhs.direction &&
+ value == rhs.value);
+ }
};
bool parseThresholdsFromConfig(
@@ -48,6 +54,7 @@
const thresholds::Threshold& threshold,
std::shared_ptr<sdbusplus::asio::connection>& conn);
+void updateThresholds(Sensor* sensor);
// returns false if a critical threshold has been crossed, true otherwise
bool checkThresholds(Sensor* sensor);
void assertThresholds(Sensor* sensor, thresholds::Level level,
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index 0d0dd1b..d8d0ecb 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -107,6 +107,25 @@
{
updateValue(nvalue);
}
+ if (!thresholds.empty())
+ {
+ std::vector<thresholds::Threshold> newThresholds;
+ if (parseThresholdsFromAttr(newThresholds, path,
+ CPUSensor::sensorScaleFactor))
+ {
+ if (!std::equal(thresholds.begin(), thresholds.end(),
+ newThresholds.begin(), newThresholds.end()))
+ {
+ thresholds = newThresholds;
+ thresholds::updateThresholds(this);
+ }
+ }
+ else
+ {
+ std::cerr << "Failure to update thresholds for " << name
+ << "\n";
+ }
+ }
errCount = 0;
}
catch (const std::invalid_argument&)
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index 725829e..49dca1f 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -162,6 +162,53 @@
}
}
+void updateThresholds(Sensor* sensor)
+{
+ if (sensor->thresholds.empty())
+ {
+ return;
+ }
+
+ for (const auto& threshold : sensor->thresholds)
+ {
+ std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
+ std::string property;
+ if (threshold.level == thresholds::Level::CRITICAL)
+ {
+ interface = sensor->thresholdInterfaceCritical;
+ if (threshold.direction == thresholds::Direction::HIGH)
+ {
+ property = "CriticalHigh";
+ }
+ else
+ {
+ property = "CriticalLow";
+ }
+ }
+ else if (threshold.level == thresholds::Level::WARNING)
+ {
+ interface = sensor->thresholdInterfaceWarning;
+ if (threshold.direction == thresholds::Direction::HIGH)
+ {
+ property = "WarningHigh";
+ }
+ else
+ {
+ property = "WarningLow";
+ }
+ }
+ else
+ {
+ continue;
+ }
+ if (!interface)
+ {
+ continue;
+ }
+ interface->set_property(property, threshold.value);
+ }
+}
+
bool checkThresholds(Sensor* sensor)
{
bool status = true;