From 54f86b86ba8168faccbfc2ad16ceeccefde98a51 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Tue, 26 Mar 2024 22:30:43 +0000 Subject: [PATCH] core: add SoftRebootStartTimestamp Will be useful to calculate how long it took to shut down the system before starting in the new root --- man/org.freedesktop.systemd1.xml | 36 +++++++++++++++++++++----------- src/core/dbus-manager.c | 1 + src/core/main.c | 2 ++ src/core/manager.c | 13 +++++++++++- src/core/manager.h | 3 +++ 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml index 4e43b4ba20..1f30f65bf7 100644 --- a/man/org.freedesktop.systemd1.xml +++ b/man/org.freedesktop.systemd1.xml @@ -340,6 +340,10 @@ node /org/freedesktop/systemd1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly t FinishTimestampMonotonic = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly t SoftRebootStartTimestamp = ...; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly t SoftRebootStartTimestampMonotonic = ...; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly t SecurityStartTimestamp = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly t SecurityStartTimestampMonotonic = ...; @@ -1033,6 +1037,10 @@ node /org/freedesktop/systemd1 { + + + + @@ -1733,17 +1741,19 @@ node /org/freedesktop/systemd1 { KernelTimestamp, KernelTimestampMonotonic, InitRDTimestamp, InitRDTimestampMonotonic, UserspaceTimestamp, UserspaceTimestampMonotonic, - FinishTimestamp, and FinishTimestampMonotonic encode - CLOCK_REALTIME and CLOCK_MONOTONIC microsecond timestamps - taken when the firmware first began execution, when the boot loader first began execution, when the - kernel first began execution, when the initrd first began execution, when the main systemd instance - began execution and finally, when all queued startup jobs finished execution. These values are useful - for determining boot-time performance. Note that as monotonic time begins with the kernel startup, the - KernelTimestampMonotonic timestamp will always be 0 and - FirmwareTimestampMonotonic and LoaderTimestampMonotonic are to - be read as negative values. Also, not all fields are always available, depending on the used firmware, - boot loader or initrd implementation. In these cases the respective pairs of timestamps are both 0, - indicating that no data is available. + FinishTimestamp, FinishTimestampMonotonic, + SoftRebootStartTimestamp and SoftRebootStartTimestampMonotonic + encode CLOCK_REALTIME and CLOCK_MONOTONIC microsecond + timestamps taken when the firmware first began execution, when the boot loader first began execution, + when the kernel first began execution, when the initrd first began execution, when the main systemd + instance began execution, when all queued startup jobs finished execution and finally, when a + systemd-soft-reboot.service8 + operation first began execution. These values are useful for determining boot-time performance. Note + that as monotonic time begins with the kernel startup, the KernelTimestampMonotonic + timestamp will always be 0 and FirmwareTimestampMonotonic and + LoaderTimestampMonotonic are to be read as negative values. Also, not all fields + are always available, depending on the used firmware, boot loader or initrd implementation. In these + cases the respective pairs of timestamps are both 0, indicating that no data is available. UnitsLoadTimestamp and UnitsLoadTimestampMonotonic encode CLOCK_REALTIME and CLOCK_MONOTONIC microseconds timestamps @@ -11982,7 +11992,9 @@ $ gdbus introspect --system --dest org.freedesktop.systemd1 \ QueueSignalUnit(), SoftReboot(), and DumpUnitFileDescriptorStore() were added in version 254. - StartAuxiliaryScope() was added in version 256. + StartAuxiliaryScope(), + SoftRebootStartTimestamp and + SoftRebootStartTimestampMonotonic were added in version 256. Unit Objects diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 11f93b0c80..e7ad850d35 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -3042,6 +3042,7 @@ const sd_bus_vtable bus_manager_vtable[] = { BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD]), SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_USERSPACE]), SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), + BUS_PROPERTY_DUAL_TIMESTAMP("SoftRebootStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SOFTREBOOT_START]), SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("SecurityStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_START]), SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("SecurityFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("GeneratorsStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_GENERATORS_START]), SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/src/core/main.c b/src/core/main.c index 1c57cce748..b086122a8c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -2129,6 +2129,8 @@ static int invoke_main_loop( manager_send_reloading(m); manager_set_switching_root(m, true); + dual_timestamp_now(m->timestamps + MANAGER_TIMESTAMP_SOFTREBOOT_START); + r = prepare_reexecute(m, &arg_serialization, ret_fds, /* switching_root= */ true); if (r < 0) { *ret_error_message = "Failed to prepare for reexecution"; diff --git a/src/core/manager.c b/src/core/manager.c index b2d8457790..97e54d68a4 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3694,7 +3694,17 @@ static void manager_notify_finished(Manager *m) { if (MANAGER_IS_TEST_RUN(m)) return; - if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) { + if (MANAGER_IS_SYSTEM(m) && dual_timestamp_is_set(&m->timestamps[MANAGER_TIMESTAMP_SOFTREBOOT_START])) { + /* The soft-reboot case, where we only report data for the last reboot */ + firmware_usec = loader_usec = initrd_usec = kernel_usec = 0; + total_usec = userspace_usec = m->timestamps[MANAGER_TIMESTAMP_FINISH].monotonic - m->timestamps[MANAGER_TIMESTAMP_SOFTREBOOT_START].monotonic; + + log_struct(LOG_INFO, + "MESSAGE_ID=" SD_MESSAGE_STARTUP_FINISHED_STR, + "USERSPACE_USEC="USEC_FMT, userspace_usec, + LOG_MESSAGE("Soft-reboot finished in %s.", + FORMAT_TIMESPAN(total_usec, USEC_PER_MSEC))); + } else if (MANAGER_IS_SYSTEM(m) && detect_container() <= 0) { char buf[FORMAT_TIMESPAN_MAX + STRLEN(" (firmware) + ") + FORMAT_TIMESPAN_MAX + STRLEN(" (loader) + ")] = {}; char *p = buf; @@ -5041,6 +5051,7 @@ static const char *const manager_timestamp_table[_MANAGER_TIMESTAMP_MAX] = { [MANAGER_TIMESTAMP_INITRD] = "initrd", [MANAGER_TIMESTAMP_USERSPACE] = "userspace", [MANAGER_TIMESTAMP_FINISH] = "finish", + [MANAGER_TIMESTAMP_SOFTREBOOT_START] = "softreboot-start", [MANAGER_TIMESTAMP_SECURITY_START] = "security-start", [MANAGER_TIMESTAMP_SECURITY_FINISH] = "security-finish", [MANAGER_TIMESTAMP_GENERATORS_START] = "generators-start", diff --git a/src/core/manager.h b/src/core/manager.h index 4d82c4a6a0..c1782ea5f7 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -120,6 +120,9 @@ typedef enum ManagerTimestamp { MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH, MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START, MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH, + + MANAGER_TIMESTAMP_SOFTREBOOT_START, + _MANAGER_TIMESTAMP_MAX, _MANAGER_TIMESTAMP_INVALID = -EINVAL, } ManagerTimestamp; -- 2.25.1