Implement HostEpoch set time logic
1. When setting host epoch, follow below logic:
Mode | Owner | Set Host Time
----- | ----- | -------------
NTP | BMC | Not allowed
NTP | HOST | Not allowed
NTP | SPLIT | OK, and just save offset
NTP | BOTH | Not allowed
MANUAL| BMC | Not allowed
MANUAL| HOST | OK, and set time to BMC
MANUAL| SPLIT | OK, and just save offset
MANUAL| BOTH | OK, and set time to BMC
2. If owner is SPLIT and BMC time is changed, update the offset accordinly;
3. Use timerfd to get notified on BMC time change, and update host time
diff accordingly;
4. Add unit test cases.
Change-Id: I2d60a821f7da9b689c579ae7ab672cc37967322c
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/host_epoch.hpp b/host_epoch.hpp
index 3798f8f..1eb3167 100644
--- a/host_epoch.hpp
+++ b/host_epoch.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "bmc_time_change_listener.hpp"
#include "config.h"
#include "epoch_base.hpp"
@@ -15,7 +16,7 @@
* @details A concrete implementation for xyz.openbmc_project.Time.EpochTime
* DBus API for HOST's epoch time.
*/
-class HostEpoch : public EpochBase
+class HostEpoch : public EpochBase, public BmcTimeChangeListener
{
public:
friend class TestHostEpoch;
@@ -38,10 +39,31 @@
**/
uint64_t elapsed(uint64_t value) override;
+ /** @brief Notified on time owner changed */
+ void onOwnerChanged(Owner owner) override;
+
+ /** @brief Notified on bmc time is changed
+ *
+ * @param[in] bmcTime - The epoch time in microseconds
+ */
+ void onBmcTimeChanged(
+ const std::chrono::microseconds& bmcTime) override;
+
private:
/** @brief The diff between BMC and Host time */
std::chrono::microseconds offset;
+ /**
+ * @brief The diff between host time and steady clock
+ * @details This diff is used to calculate the host time if BMC time
+ * is changed and the owner is SPLIT.
+ * Without this the host time is lost if BMC time is changed.
+ */
+ std::chrono::microseconds diffToSteadyClock;
+
+ /** @brief Save the offset value into offsetFile */
+ void saveOffset();
+
/** @brief The file to store the offset in File System.
* Read back when starts
**/