Skip to content

Commit e6710b7

Browse files
committed
BMC state manager support for LastRebootTime
Use the uptime value to calculate the time of the last BMC reboot when the LastRebootTime property is read. Calculates it on the fly instead of once at startup so that if someone changes the BMC time the value will still be accurate. Resolves openbmc/openbmc#3159 Tested: Verify the property returns the right value. Change-Id: I4bc8d2cdf18c225b24c98d9567d053c3246b7506 Signed-off-by: Matt Spinler <[email protected]>
1 parent 9a2f37c commit e6710b7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

bmc_state_manager.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#include <iostream>
2-
#include <string>
31
#include <phosphor-logging/log.hpp>
2+
#include <sys/sysinfo.h>
43
#include "bmc_state_manager.hpp"
54

65
namespace phosphor
@@ -164,6 +163,21 @@ BMC::BMCState BMC::currentBMCState(BMCState value)
164163
return server::BMC::currentBMCState(value);
165164
}
166165

166+
uint64_t BMC::lastRebootTime() const
167+
{
168+
using namespace std::chrono;
169+
struct sysinfo info;
170+
171+
auto rc = sysinfo(&info);
172+
assert(rc == 0);
173+
174+
// Since uptime is in seconds, also get the current time in seconds.
175+
auto now = time_point_cast<seconds>(system_clock::now());
176+
auto rebootTime = now - seconds(info.uptime);
177+
178+
return duration_cast<milliseconds>(rebootTime.time_since_epoch()).count();
179+
}
180+
167181
} // namespace manager
168182
} // namespace state
169183
} // namepsace phosphor

bmc_state_manager.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ class BMC : public BMCInherit
5050
/** @brief Set value of CurrentBMCState **/
5151
BMCState currentBMCState(BMCState value) override;
5252

53+
/** @brief Returns the last time the BMC was rebooted
54+
*
55+
* @details Uses uptime information to determine when
56+
* the BMC was last rebooted.
57+
*
58+
* @return uint64_t - Epoch time, in milliseconds, of the
59+
* last reboot.
60+
*/
61+
uint64_t lastRebootTime() const override;
62+
5363
private:
5464
/**
5565
* @brief discover the state of the bmc

0 commit comments

Comments
 (0)