Handle NaN in threshold interface
dbus-sensor threshold has been changed to always create high and low
interfaces. Threshold value is set to NaN when there is no actual limit.
When creating threshold attributes in SDR, verify that sensor threshold
value is not NaN.
When getting min and max from threshold interfaces, use std::fmin and
std::fmax instead of std::min and std::max. If one of the two arguments
is NaN, the value of the other argument is returned. Since sensors are
always created with default min/max values, the other argument is not
going to be NaN.
Tested:
ipmitool sensor list returns without error.
Sensor limit is na when threshold interface value is NaN.
Credit: Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Migrated from intel-ipmi-oem:
SHA: 41a6e9f336aa1161cd0680bfab5a5fe1effbe976
Change-Id: I51451aab12d9bf5cc5f2d61ff2e603839910afe0
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index f3cd385..2c5e3e2 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -286,7 +286,7 @@
double value = std::visit(VariantToDoubleVisitor(), lower->second);
if (std::isfinite(value))
{
- min = std::min(value, min);
+ min = std::fmin(value, min);
}
}
if (upper != critical->second.end())
@@ -294,7 +294,7 @@
double value = std::visit(VariantToDoubleVisitor(), upper->second);
if (std::isfinite(value))
{
- max = std::max(value, max);
+ max = std::fmax(value, max);
}
}
}
@@ -307,7 +307,7 @@
double value = std::visit(VariantToDoubleVisitor(), lower->second);
if (std::isfinite(value))
{
- min = std::min(value, min);
+ min = std::fmin(value, min);
}
}
if (upper != warning->second.end())
@@ -315,7 +315,7 @@
double value = std::visit(VariantToDoubleVisitor(), upper->second);
if (std::isfinite(value))
{
- max = std::max(value, max);
+ max = std::fmax(value, max);
}
}
}
@@ -1529,17 +1529,31 @@
auto warningLow = warningMap.find("WarningLow");
if (warningHigh != warningMap.end())
{
- assertionEnabledLsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh);
- deassertionEnabledLsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::upperNonCriticalGoingLow);
+ double value = std::visit(VariantToDoubleVisitor(),
+ warningHigh->second);
+ if (std::isfinite(value))
+ {
+ assertionEnabledLsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::
+ upperNonCriticalGoingHigh);
+ deassertionEnabledLsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::
+ upperNonCriticalGoingLow);
+ }
}
if (warningLow != warningMap.end())
{
- assertionEnabledLsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow);
- deassertionEnabledLsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::lowerNonCriticalGoingHigh);
+ double value = std::visit(VariantToDoubleVisitor(),
+ warningLow->second);
+ if (std::isfinite(value))
+ {
+ assertionEnabledLsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::
+ lowerNonCriticalGoingLow);
+ deassertionEnabledLsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::
+ lowerNonCriticalGoingHigh);
+ }
}
}
if (criticalInterface != sensorMap.end())
@@ -1551,17 +1565,29 @@
if (criticalHigh != criticalMap.end())
{
- assertionEnabledMsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::upperCriticalGoingHigh);
- deassertionEnabledMsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::upperCriticalGoingLow);
+ double value = std::visit(VariantToDoubleVisitor(),
+ criticalHigh->second);
+ if (std::isfinite(value))
+ {
+ assertionEnabledMsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::
+ upperCriticalGoingHigh);
+ deassertionEnabledMsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::upperCriticalGoingLow);
+ }
}
if (criticalLow != criticalMap.end())
{
- assertionEnabledLsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::lowerCriticalGoingLow);
- deassertionEnabledLsb |= static_cast<uint8_t>(
- IPMISensorEventEnableThresholds::lowerCriticalGoingHigh);
+ double value = std::visit(VariantToDoubleVisitor(),
+ criticalLow->second);
+ if (std::isfinite(value))
+ {
+ assertionEnabledLsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::lowerCriticalGoingLow);
+ deassertionEnabledLsb |= static_cast<uint8_t>(
+ IPMISensorEventEnableThresholds::
+ lowerCriticalGoingHigh);
+ }
}
}
}