monitor: Use host state to decide power state
phosphos-fan-monitor service is using pgood to decide the power state.
When power state is off, phosphor-fan-monitor should not check
functionality of fans. However, with Ampere's Softoff (e.g via power
cycle), it takes long for pgood to change state after the command to
power cycle host is taken, so phosphor-fan-monitor fails to detect the
power state is off, and continues to check functionality. This results
in fans being marked non-functional when host is off during power cycle.
This patch offers a package configuration option for choosing to use
CurrentHostState instead of pgood to decide the power state. When the
CurrentHostState is TransitioningToOff, which is set right after the
power cycle command, the power state will be considered as off.
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: I6f459384b1d536f61c5df787d696412acc04ba02
diff --git a/meson.build b/meson.build
index 7ede5c5..90cdca1 100644
--- a/meson.build
+++ b/meson.build
@@ -96,6 +96,9 @@
conf.set_quoted(
'FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file'))
conf.set('DELAY_HOST_CONTROL', get_option('delay-host-control'))
+if get_option('monitor-use-host-state').enabled()
+ conf.set('MONITOR_USE_HOST_STATE', '')
+endif
# JSON-or-YAML (all programs)
if get_option('json-config').enabled()
diff --git a/meson_options.txt b/meson_options.txt
index 93681c8..3344cbd 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -72,6 +72,11 @@
description: 'Delay host control when the power is on and the fan sensors are offline.'
)
+option(
+ 'monitor-use-host-state', value : 'disabled', type: 'feature',
+ description: 'Use CurrentHostState for fan monitor to decide power state.'
+)
+
# Presence
option(
diff --git a/monitor/system.cpp b/monitor/system.cpp
index 6408ef4..40cca00 100644
--- a/monitor/system.cpp
+++ b/monitor/system.cpp
@@ -52,7 +52,11 @@
const sdeventplus::Event& event) :
_mode(mode),
_bus(bus), _event(event),
+#ifdef MONITOR_USE_HOST_STATE
+ _powerState(std::make_unique<HostPowerState>(
+#else
_powerState(std::make_unique<PGoodState>(
+#endif
bus, std::bind(std::mem_fn(&System::powerStateChanged), this,
std::placeholders::_1))),
_thermalAlert(bus, THERMAL_ALERT_OBJPATH)