monitor: Use the number of failed tach sensors at startup
When marking a fan nonfunctional due to its tach sensors failing
to be read from dbus, a check against the configured number of
sensors that should result in the fan being marked as nonfunctional
should be checked.
Tested:
Run phosphor-fan-monitor --monitor in witherspoon qemu,
when the number of failed tach sensor is larger than the
configured _numSensorFailsForNonFunc then mark the
associated fan as nonfunctional.
Change-Id: I6ff97b9aae4279d6ce402d3aecda087d45dfa318
Signed-off-by: Jolie Ku <jolie_ku@wistron.com>
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 4b84fff..3b12905 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -61,8 +61,12 @@
}
catch (InvalidSensorError& e)
{
- // mark associated fan as nonfunctional
- updateInventory(false);
+ // Count the number of failed tach sensors
+ if (++_numFailedSensor >= _numSensorFailsForNonFunc)
+ {
+ // Mark associated fan as nonfunctional
+ updateInventory(false);
+ }
}
}
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index 5136cee..603be10 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -181,6 +181,11 @@
const size_t _numSensorFailsForNonFunc;
/**
+ * The number of failed sensors
+ */
+ size_t _numFailedSensor = 0;
+
+ /**
* @brief The current functional state of the fan
*/
bool _functional = true;
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index 078b213..01baada 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -97,7 +97,7 @@
log<level::ERR>(
fmt::format("Failed to retrieve tach sensor {}", _name)
.c_str());
- // mark tach sensor as nonfunctional
+ // Mark tach sensor as nonfunctional
setFunctional(false);
throw InvalidSensorError();
}