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/meson.build b/common/meson.build
index 8f515e1..fd9ccf3 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -1,6 +1,14 @@
subdir('pldm')
+conf = configuration_data()
+conf.set(
+ 'HOST_STATE_TRANSITION_TIMEOUT',
+ get_option('host-state-transition-timeout'),
+)
+
+configure_file(output: 'common_config.h', configuration: conf)
+
software_common_lib = static_library(
'software_common_lib',
'src/software_manager.cpp',
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;
}
diff --git a/meson.options b/meson.options
index 32c88c2..a193983 100644
--- a/meson.options
+++ b/meson.options
@@ -210,3 +210,10 @@
value: '/run/media/rwfs-alt/cow',
description: 'The dir for alt-rwfs partition.',
)
+
+option(
+ 'host-state-transition-timeout',
+ type: 'integer',
+ value: 60,
+ description: 'Timeout for host state transition.',
+)