monitor: Use only init mode when using JSON
Fan monitor is currently split into 2 modes - 'init' which is used
right after a power on, and 'monitor', which is used later after the
fans-ready target is started. Normally, the 'init' mode just sets the
fans to functional and then exits, and the real monitoring work is done
in the 'monitor' mode.
In the future this application will need to be able to check for fan
problems as soon as it starts up after power on so that it can handle
shutting down due to missing fans. To prepare for this, move all
functionality into the init mode, and just exit immediately when called
to run in the monitor mode. Only do this when compiled to use the JSON
configuration, as this is new and I don't want to change how the
existing YAML setups work.
This also creates a new 'monitor_start_delay' entry in the JSON to say
how long to wait after startup before actually doing any sensor
monitoring, which then gives the same behavior as how the monitor mode
would delay by waiting for the fan control ready target, which itself is
started by fan control --init after a hardcoded delay. This field is
optional to preserve backwards compatibility and defaults to 0s.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I623a233f50233e734f50cd9e80139c60467518d8
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index 603be10..537d8fd 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "config.h"
+
#include "tach_sensor.hpp"
#include "trust_manager.hpp"
#include "types.hpp"
@@ -17,6 +19,8 @@
namespace monitor
{
+class System;
+
/**
* @class InvalidSensorError
*
@@ -83,9 +87,11 @@
* @param event - event loop reference
* @param trust - the tach trust manager
* @param def - the fan definition structure
+ * @param system - Reference to the system object
*/
Fan(Mode mode, sdbusplus::bus::bus& bus, const sdeventplus::Event& event,
- std::unique_ptr<trust::Manager>& trust, const FanDefinition& def);
+ std::unique_ptr<trust::Manager>& trust, const FanDefinition& def,
+ System& system);
/**
* @brief Callback function for when an input sensor changes
@@ -157,6 +163,12 @@
void updateInventory(bool functional);
/**
+ * @brief Called by _monitorTimer to start fan monitoring some
+ * amount of time after startup.
+ */
+ void startMonitor();
+
+ /**
* @brief the dbus object
*/
sdbusplus::bus::bus& _bus;
@@ -199,6 +211,29 @@
* The tach trust manager object
*/
std::unique_ptr<trust::Manager>& _trustManager;
+
+#ifdef MONITOR_USE_JSON
+ /**
+ * @brief The number of seconds to wait after startup until
+ * fan sensors should checked against their targets.
+ */
+ size_t _monitorDelay;
+
+ /**
+ * @brief Expires after _monitorDelay to start fan monitoring.
+ */
+ sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _monitorTimer;
+#endif
+
+ /**
+ * @brief Set to true when monitoring can start.
+ */
+ bool _monitorReady = false;
+
+ /**
+ * @brief Reference to the System object
+ */
+ System& _system;
};
} // namespace monitor