| #pragma once | |
| #include "boottime_api/boottime_api.h" | |
| #include <boost/asio/steady_timer.hpp> | |
| #include <sdbusplus/asio/connection.hpp> | |
| #include <sdbusplus/asio/object_server.hpp> | |
| #include <sdbusplus/bus.hpp> | |
| #include <sdbusplus/bus/match.hpp> | |
| #include <functional> | |
| #include <optional> | |
| #include <vector> | |
| namespace boot_time_monitor | |
| { | |
| /** | |
| * @brief Contains functionality related to interacting with systemd for boot | |
| * time information. | |
| */ | |
| namespace systemd | |
| { | |
| namespace btm = boot_time_monitor; | |
| /** | |
| * @brief Handles monitoring of systemd boot timestamps for BMC nodes. | |
| * | |
| * This class periodically queries systemd's D-Bus interface | |
| * (`org.freedesktop.systemd1.Manager`) to retrieve various monotonic | |
| * timestamps related to the boot process (Firmware, Loader, Kernel, InitRD, | |
| * Userspace, Finish). It waits until the `FinishTimestampMonotonic` is | |
| * available, indicating the userspace boot is complete. Once available, it | |
| * calculates the duration of each stage and records these durations using the | |
| * provided `IApi` instance, specifically targeting nodes tagged with | |
| * `kBootTimeTagBMC`. | |
| */ | |
| class Handler | |
| { | |
| public: | |
| /** | |
| * @brief Constructs the systemd Handler. | |
| * | |
| * Initializes the handler and starts a timer (`m_bmc_finish_timer`) to | |
| * periodically check for systemd boot completion. | |
| * | |
| * @param conn Shared pointer to the sdbusplus ASIO connection. | |
| * @param api Shared pointer to the central boot time monitoring API. | |
| */ | |
| Handler(std::shared_ptr<sdbusplus::asio::connection> conn, | |
| std::shared_ptr<btm::api::IBoottimeApi> api, | |
| btm::NodeConfig bmcNode); | |
| private: | |
| /** @brief Interval for polling systemd properties until boot is finished. | |
| */ | |
| const std::chrono::seconds kCheckBmcFinishInterval = | |
| std::chrono::seconds(10); | |
| /** | |
| * @brief Timer callback function to check systemd boot timestamps. | |
| * | |
| * Queries systemd D-Bus properties for boot timestamps. If the finish | |
| * timestamp is available, calculates stage durations and records them via | |
| * `mApi`. Otherwise, reschedules the timer. | |
| * | |
| * @param ec Boost error code from the timer operation. | |
| * @param conn Shared pointer to the sdbusplus ASIO connection. | |
| */ | |
| void UpdateBmcCheckpoints(const boost::system::error_code& ec); | |
| /** | |
| * @brief Queries a specific timestamp property from systemd via D-Bus. | |
| * | |
| * @param[in] propertyName The name of the systemd property to query. | |
| * | |
| * @return A `std::optional<uint64_t>` containing the timestamp on success, | |
| * or an empty optional on failure. | |
| */ | |
| std::optional<uint64_t> | |
| QuerySystemdTimestamp(std::string_view propertyName); | |
| /** | |
| * @brief Reschedules the timer to continue polling systemd. | |
| * | |
| * This helper function resets the polling timer to fire again after the | |
| * predefined interval, triggering another call to UpdateBmcCheckpoints. | |
| */ | |
| void RestartPolling(); | |
| #ifdef NPCM7XX_OR_NEWER | |
| /** | |
| * The below 2 functions are to support the (Firmware + Loader) time | |
| * logging for NPCM7XX or newer Nuvoton BMCs. | |
| */ | |
| /** | |
| * @brief Read 4 byte value from given memory address. | |
| * | |
| * @param target Memory address to read from. | |
| * @return The value from the memory address. Return nullopt if failed. | |
| */ | |
| std::optional<uint32_t> readMem4Bytes(uint32_t target); | |
| /** | |
| * @brief Get system uptime from /proc/uptime. | |
| * | |
| * @return System uptime in milliseconds. Return nullopt if failed. | |
| */ | |
| std::optional<int64_t> getUpTimeInMs(); | |
| #endif | |
| /** @brief Shared pointer to the central boot time monitoring API. */ | |
| std::shared_ptr<btm::api::IBoottimeApi> mApi; | |
| /** @brief ASIO timer used to periodically check for systemd boot | |
| * completion. */ | |
| boost::asio::steady_timer mBMCFinishTimer; | |
| /** @brief Shared pointer to the sdbusplus D-Bus connection. */ | |
| std::shared_ptr<sdbusplus::asio::connection> mDbusConn; | |
| /** @brief Configuration for the node being monitored. */ | |
| btm::NodeConfig mNode; | |
| }; | |
| } // namespace systemd | |
| } // namespace boot_time_monitor |