common: host power utility: add host-state-transition-timeout option
Introduce a configurable host-state-transition-timeout to control
how long the utility waits for a host state change. The previous 12s
timeout was insufficient for a graceful power off, leading to false
timeout errors.
This option is used by the bios-software-update service to control
the host state transition timeout when turning the host off and on
before and after a BIOS update.
Change-Id: I9209d8f06f55eaf181235198c20c32c93861f841
Signed-off-by: Kevin Tung <kevin.tung.openbmc@gmail.com>
diff --git a/common/src/host_power.cpp b/common/src/host_power.cpp
index 4aeebcb..eba4ae8 100644
--- a/common/src/host_power.cpp
+++ b/common/src/host_power.cpp
@@ -1,5 +1,7 @@
#include "host_power.hpp"
+#include "common_config.h"
+
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/async.hpp>
#include <sdbusplus/async/context.hpp>
@@ -56,13 +58,11 @@
debug("Requested host transition to {STATE}", "STATE", state);
- constexpr size_t retries = 4;
- constexpr size_t retryTimeout = 3;
+ constexpr size_t transitionTimeout = HOST_STATE_TRANSITION_TIMEOUT;
- for (size_t i = 0; i < retries; i++)
+ for (size_t i = 0; i < transitionTimeout; i++)
{
- co_await sdbusplus::async::sleep_for(
- ctx, std::chrono::seconds(retryTimeout));
+ co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(1));
if ((co_await client.current_host_state()) == state)
{
@@ -72,7 +72,7 @@
}
error("Failed to achieve state {STATE} before the timeout of {TIMEOUT}s",
- "STATE", state, "TIMEOUT", retries * retryTimeout);
+ "STATE", state, "TIMEOUT", transitionTimeout);
co_return false;
}