Add assertValue in thresholdAsserted signal
When threshold property changes, send thresholdAsserted signal
that includes threshold properties and sensor value that caused
the property change. This enables the SEL logger to record the
correct sensor reading in the SEL messages.
Tested:
busctl set-property xyz.openbmc_project.ADCSensor
/xyz/openbmc_project/sensors/voltage/P1V8_PCH xyz.openbmc_project.Sensor.Value
Value d 1.97
thresholdAsserted signal is received with the below data:
assertSignal from P1V8_PCH interface xyz.openbmc_project.Sensor.Threshold.Critical
event CriticalAlarmHighassert 1 assertValue 1.97
assertSignal from P1V8_PCH interface xyz.openbmc_project.Sensor.Threshold.Warning
event WarningAlarmHighassert 1 assertValue 1.97
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I0de317dd716f71acdcd6f12e43dbd239232fea86
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index 183fa34..57d6f52 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -42,8 +42,9 @@
}
};
-void assertThresholds(Sensor* sensor, thresholds::Level level,
- thresholds::Direction direction, bool assert);
+void assertThresholds(Sensor* sensor, double assertValue,
+ thresholds::Level level, thresholds::Direction direction,
+ bool assert);
struct TimerUsed
{
@@ -78,7 +79,7 @@
}
}
- void startTimer(const Threshold& threshold)
+ void startTimer(const Threshold& threshold, double assertValue)
{
struct TimerUsed timerUsed = {};
constexpr const size_t waitTime = 5;
@@ -102,7 +103,7 @@
pair->first.direction = threshold.direction;
pair->second.expires_from_now(boost::posix_time::seconds(waitTime));
pair->second.async_wait(
- [this, pair, threshold](boost::system::error_code ec) {
+ [this, pair, threshold, assertValue](boost::system::error_code ec) {
pair->first.used = false;
if (ec == boost::asio::error::operation_aborted)
@@ -116,7 +117,7 @@
}
if (isPowerOn())
{
- assertThresholds(sensor, threshold.level,
+ assertThresholds(sensor, assertValue, threshold.level,
threshold.direction, true);
}
});
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index 61f951b..adc1f68 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -245,10 +245,20 @@
static int cLoMidstate = 0;
static int cDebugThrottle = 0;
-static std::vector<std::pair<Threshold, bool>> checkThresholds(Sensor* sensor,
- double value)
+struct ChangeParam
{
- std::vector<std::pair<Threshold, bool>> thresholdChanges;
+ ChangeParam(Threshold whichThreshold, bool status, double value) :
+ threshold(whichThreshold), asserted(status), assertValue(value)
+ {}
+
+ Threshold threshold;
+ bool asserted;
+ double assertValue;
+};
+
+static std::vector<ChangeParam> checkThresholds(Sensor* sensor, double value)
+{
+ std::vector<ChangeParam> thresholdChanges;
if (sensor->thresholds.empty())
{
return thresholdChanges;
@@ -265,12 +275,12 @@
{
if (value >= threshold.value)
{
- thresholdChanges.push_back(std::make_pair(threshold, true));
+ thresholdChanges.emplace_back(threshold, true, value);
++cHiTrue;
}
else if (value < (threshold.value - sensor->hysteresisTrigger))
{
- thresholdChanges.push_back(std::make_pair(threshold, false));
+ thresholdChanges.emplace_back(threshold, false, value);
++cHiFalse;
}
else
@@ -282,12 +292,12 @@
{
if (value <= threshold.value)
{
- thresholdChanges.push_back(std::make_pair(threshold, true));
+ thresholdChanges.emplace_back(threshold, true, value);
++cLoTrue;
}
else if (value > (threshold.value + sensor->hysteresisTrigger))
{
- thresholdChanges.push_back(std::make_pair(threshold, false));
+ thresholdChanges.emplace_back(threshold, false, value);
++cLoFalse;
}
else
@@ -321,13 +331,13 @@
bool checkThresholds(Sensor* sensor)
{
bool status = true;
- std::vector<std::pair<Threshold, bool>> changes =
- checkThresholds(sensor, sensor->value);
- for (const auto& [threshold, asserted] : changes)
+ std::vector<ChangeParam> changes = checkThresholds(sensor, sensor->value);
+ for (const auto& change : changes)
{
- assertThresholds(sensor, threshold.level, threshold.direction,
- asserted);
- if (threshold.level == thresholds::Level::CRITICAL && asserted)
+ assertThresholds(sensor, change.assertValue, change.threshold.level,
+ change.threshold.direction, change.asserted);
+ if (change.threshold.level == thresholds::Level::CRITICAL &&
+ change.asserted)
{
status = false;
}
@@ -339,25 +349,25 @@
void checkThresholdsPowerDelay(Sensor* sensor, ThresholdTimer& thresholdTimer)
{
- std::vector<std::pair<Threshold, bool>> changes =
- checkThresholds(sensor, sensor->value);
- for (const auto& [threshold, asserted] : changes)
+ std::vector<ChangeParam> changes = checkThresholds(sensor, sensor->value);
+ for (const auto& change : changes)
{
- if (asserted)
+ if (change.asserted)
{
- thresholdTimer.startTimer(threshold);
+ thresholdTimer.startTimer(change.threshold, change.assertValue);
}
else
{
- thresholdTimer.stopTimer(threshold);
- assertThresholds(sensor, threshold.level, threshold.direction,
- false);
+ thresholdTimer.stopTimer(change.threshold);
+ assertThresholds(sensor, change.assertValue, change.threshold.level,
+ change.threshold.direction, false);
}
}
}
-void assertThresholds(Sensor* sensor, thresholds::Level level,
- thresholds::Direction direction, bool assert)
+void assertThresholds(Sensor* sensor, double assertValue,
+ thresholds::Level level, thresholds::Direction direction,
+ bool assert)
{
std::string property;
std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
@@ -396,7 +406,25 @@
std::cout << "trying to set uninitialized interface\n";
return;
}
- interface->set_property(property, assert);
+
+ if (interface->set_property<bool, true>(property, assert))
+ {
+ try
+ {
+ // msg.get_path() is interface->get_object_path()
+ sdbusplus::message::message msg =
+ interface->new_signal("ThresholdAsserted");
+
+ msg.append(sensor->name, interface->get_interface_name(), property,
+ assert, assertValue);
+ msg.signal_send();
+ }
+ catch (const sdbusplus::exception::exception& e)
+ {
+ std::cerr
+ << "Failed to send thresholdAsserted signal with assertValue\n";
+ }
+ }
}
bool parseThresholdsFromAttr(