Add MissingIsAcceptable feature to avoid failsafe

This is a partial implementation of the ideas here:
https://github.com/openbmc/phosphor-pid-control/issues/31

A new configuration item is supported in the PID object, named
"MissingIsAcceptable" (for D-Bus) or "missingIsAcceptable" (for the old
config.json). The value is an array of strings. If these strings match
sensor names, those sensors will be flagged as "missing is acceptable",
that is, they can go missing and the zone will not be thrown into
failsafe mode as a result.

This can be handy for sensors that are not always available on your
particular machine. It is independent of the existing Availability
interface, because the decision to go into failsafe mode or not is a
property of the PID loop, not of the sensor itself.

If a PID loop consists of all sensors that are missing, the output
will be deemed to be the setpoint, thus essentially making the PID
loop a no-op. Now initializing sensor values to NaN, not zero, as zero
is not a good default if PID loop is margin, undoing a bug I made:
https://gerrit.openbmc.org/c/openbmc/phosphor-pid-control/+/38228

Tested: It worked for me. Also, added a unit test case.

Change-Id: Idc7978ab06fcc9ed8c6c9df9483101376e5df4d1
Signed-off-by: Josh Lehan <krellan@google.com>
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 0b46841..e5eddca 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -96,6 +96,17 @@
     return !_failSafeSensors.empty();
 }
 
+void DbusPidZone::markSensorMissing(const std::string& name)
+{
+    if (_missingAcceptable.find(name) != _missingAcceptable.end())
+    {
+        // Disallow sensors in MissingIsAcceptable list from causing failsafe
+        return;
+    }
+
+    _failSafeSensors.emplace(name);
+}
+
 int64_t DbusPidZone::getZoneID(void) const
 {
     return _zoneId;
@@ -184,14 +195,25 @@
     _cachedFanOutputs[std::string{name}] = values;
 }
 
-void DbusPidZone::addFanInput(const std::string& fan)
+void DbusPidZone::addFanInput(const std::string& fan, bool missingAcceptable)
 {
     _fanInputs.push_back(fan);
+
+    if (missingAcceptable)
+    {
+        _missingAcceptable.emplace(fan);
+    }
 }
 
-void DbusPidZone::addThermalInput(const std::string& therm)
+void DbusPidZone::addThermalInput(const std::string& therm,
+                                  bool missingAcceptable)
 {
     _thermalInputs.push_back(therm);
+
+    if (missingAcceptable)
+    {
+        _missingAcceptable.emplace(therm);
+    }
 }
 
 // Updates desired RPM setpoint from optional text file
@@ -389,21 +411,23 @@
 
 void DbusPidZone::initializeCache(void)
 {
+    auto nan = std::numeric_limits<double>::quiet_NaN();
+
     for (const auto& f : _fanInputs)
     {
-        _cachedValuesByName[f] = {0, 0};
-        _cachedFanOutputs[f] = {0, 0};
+        _cachedValuesByName[f] = {nan, nan};
+        _cachedFanOutputs[f] = {nan, nan};
 
         // Start all fans in fail-safe mode.
-        _failSafeSensors.insert(f);
+        markSensorMissing(f);
     }
 
     for (const auto& t : _thermalInputs)
     {
-        _cachedValuesByName[t] = {0, 0};
+        _cachedValuesByName[t] = {nan, nan};
 
         // Start all sensors in fail-safe mode.
-        _failSafeSensors.insert(t);
+        markSensorMissing(t);
     }
     // Initialize Pid FailSafePercent
     initPidFailSafePercent();