Skip to content

Commit 0886545

Browse files
committed
discover_system_state: apply power restore policy as early as BMC ready
Add a waitBmcReady() to monitor BMC state every second, this function returns true if BMC enters ready state early or returns flase if timeout reached. This allows phosphor-diecover-system-state service can perform power restore policy as early as BMC enters ready state. Signed-off-by: Potin Lai <[email protected]> Change-Id: I3f1ef2957c9c8218d094b0e7643dc2eec03535b4
1 parent 30538e8 commit 0886545

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ The [RestorePolicy][6] defines the behavior the user wants when the BMC is
9696
reset. If the chassis or host is on/running then this service will not run. If
9797
they are off then the `RestorePolicy` will be read and executed by PSM code.
9898

99-
The `PowerRestoreDelay` property within the interface defines how long the
100-
service will wait before issuing the power on request.
99+
The `PowerRestoreDelay` property within the interface defines a maximum time the
100+
service will wait for the BMC to enter the `Ready` state before issuing the
101+
power on request, this allows host to be powered on as early as the BMC is
102+
ready.
101103

102104
## Only Allow System Boot When BMC Ready
103105

Diff for: discover_system_state.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int main(int argc, char** argv)
166166
info(
167167
"power_policy=ALWAYS_POWER_ON, powering host on ({DELAY}s delay)",
168168
"DELAY", powerRestoreDelaySec.count());
169-
std::this_thread::sleep_for(powerRestoreDelayUsec);
169+
utils::waitBmcReady(bus, powerRestoreDelaySec);
170170
phosphor::state::manager::utils::setProperty(
171171
bus, hostPath, HOST_BUSNAME, "RestartCause",
172172
convertForMessage(
@@ -192,7 +192,7 @@ int main(int argc, char** argv)
192192
info(
193193
"power_policy=ALWAYS_POWER_OFF, set requested state to off ({DELAY}s delay)",
194194
"DELAY", powerRestoreDelaySec.count());
195-
std::this_thread::sleep_for(powerRestoreDelayUsec);
195+
utils::waitBmcReady(bus, powerRestoreDelaySec);
196196
// Read last requested state and re-request it to execute it
197197
auto hostReqState = phosphor::state::manager::utils::getProperty(
198198
bus, hostPath, HOST_BUSNAME, "RequestedHostTransition");
@@ -209,7 +209,7 @@ int main(int argc, char** argv)
209209
{
210210
info("power_policy=RESTORE, restoring last state ({DELAY}s delay)",
211211
"DELAY", powerRestoreDelaySec.count());
212-
std::this_thread::sleep_for(powerRestoreDelayUsec);
212+
utils::waitBmcReady(bus, powerRestoreDelaySec);
213213
// Read last requested state and re-request it to execute it
214214
auto hostReqState = phosphor::state::manager::utils::getProperty(
215215
bus, hostPath, HOST_BUSNAME, "RequestedHostTransition");

Diff for: utils.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ bool isBmcReady(sdbusplus::bus_t& bus)
244244
return true;
245245
}
246246

247+
bool waitBmcReady(sdbusplus::bus_t& bus, std::chrono::seconds timeout)
248+
{
249+
while (timeout.count() != 0)
250+
{
251+
timeout--;
252+
if (isBmcReady(bus))
253+
{
254+
return true;
255+
}
256+
std::this_thread::sleep_for(std::chrono::seconds(1));
257+
}
258+
return false;
259+
}
260+
247261
} // namespace utils
248262
} // namespace manager
249263
} // namespace state

Diff for: utils.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ bool checkACLoss(size_t& chassisId);
9595
*/
9696
bool isBmcReady(sdbusplus::bus_t& bus);
9797

98+
/** @brief Wait BMC to enter ready state or timeout reached.
99+
*
100+
* @param[in] bus - The Dbus bus object
101+
* @param[in] timeout - Timeout in second
102+
*/
103+
bool waitBmcReady(sdbusplus::bus_t& bus, std::chrono::seconds timeout);
104+
98105
} // namespace utils
99106
} // namespace manager
100107
} // namespace state

0 commit comments

Comments
 (0)