From 7c5f8839ec3d71a2170b8f3514a16a67c69d1c7c Mon Sep 17 00:00:00 2001 From: "Jason M. Bills" Date: Wed, 27 Jan 2021 11:47:14 -0800 Subject: Update to internal 0.29 Signed-off-by: Jason M. Bills --- .../datetime/pch-time-sync/pch-time-sync.cpp | 35 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'meta-openbmc-mods/meta-common/recipes-phosphor/datetime') diff --git a/meta-openbmc-mods/meta-common/recipes-phosphor/datetime/pch-time-sync/pch-time-sync.cpp b/meta-openbmc-mods/meta-common/recipes-phosphor/datetime/pch-time-sync/pch-time-sync.cpp index 3d0b7fd98..00e2b53fe 100644 --- a/meta-openbmc-mods/meta-common/recipes-phosphor/datetime/pch-time-sync/pch-time-sync.cpp +++ b/meta-openbmc-mods/meta-common/recipes-phosphor/datetime/pch-time-sync/pch-time-sync.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ extern "C" { static constexpr uint32_t syncIntervalNormalMS = 60000; static constexpr uint32_t syncIntervalFastMS = (syncIntervalNormalMS / 2); +static constexpr uint32_t syncIntervalBootMS = 5000; static uint32_t syncIntervalMS = syncIntervalNormalMS; @@ -37,6 +39,7 @@ static constexpr uint8_t timeDiffAllowedSecond = 1; static uint8_t pchDevI2cBusNo = 0; static uint8_t pchDevI2cSlaveAddr = 0; static bool getPCHI2cAddrFlag = false; +static constexpr const char* clockFile = "/var/lib/systemd/timesync/clock"; static inline uint8_t bcd2Decimal(uint8_t hex) { uint8_t dec = ((hex & 0xF0) >> 4) * 10 + (hex & 0x0F); @@ -250,6 +253,26 @@ class PCHSync return true; } + bool updateClockFileTimestamp() + { + if (!std::filesystem::exists(clockFile)) + { + phosphor::logging::log( + "The systemd timestamp synchronization file doesn't exist: ", + phosphor::logging::entry("PATHNAME=%s", clockFile)); + return false; + } + int rc = utimensat(AT_FDCWD, clockFile, nullptr, 0); + if (rc) + { + phosphor::logging::log( + "utimensat systemd timestamp synchronization file fail: ", + phosphor::logging::entry("PATHNAME=%s", clockFile), + phosphor::logging::entry("ERRCODE=%x", errno)); + return false; + } + return true; + } bool setSystemTime(uint32_t timeSeconds) { struct timespec sTime = {0}; @@ -305,12 +328,20 @@ class PCHSync phosphor::logging::entry("TIME=%s", dateString.c_str())); } + // During the boot time, systemd-timesyncd.service checks + // "/var/lib/systemd/timesync/clock" and updates the system time with + // the timestamp of the file + if (!updateClockFileTimestamp()) + { + return false; + } + return true; } void startSyncTimer(std::shared_ptr& conn) { - // retry 10 times (10 * 30 sec = 5min ) to get the pch timer + // retry 10 times (10 * 5s = 50s ) to get the pch timer // configuration. static uint8_t retrytimes = 10; if (!getPCHI2cAddrFlag) @@ -321,7 +352,7 @@ class PCHSync "Get pch timer configuration fail"); return; } - syncIntervalMS = syncIntervalFastMS; + syncIntervalMS = syncIntervalBootMS; getPCHTimerConfiguration(conn); retrytimes--; } -- cgit v1.2.3