Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set LoaderTimeInitUSec and LoaderTimeExecUSec in GRUB #273

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

bcressey
Copy link
Contributor

Issue number:
Fixes #272

Description of changes:
For systemd-analyze to report the time spent in firmware and in the boot loader, we need to set LoaderTimeInitUSec and LoaderTimeExecUSec, so the values can be read by efi_loader_get_boot_usec() and set by boot_timestamps().

This patch series teaches GRUB to do this for x86 and aarch64. It relies on backported upstream patches from the series that added the Boot Loader Interface module]. That series implemented support for a different part of BLI: the LoaderInfo and LoaderDevicePartUUID variables.

Testing done:
Tested this under the different EFI implementations I have access to - edk2 via QEMU/KVM, EC2 Nitro instances, and VMware ESXi VMs.

Verified that systemd-analyze reports firmware and loader time:

# systemd-analyze
Startup finished in 4.392s (firmware) + 833ms (loader) + 776ms (kernel) + 3.728s (userspace) = 9.729s
multi-user.target reached after 3.727s in userspace.

Confirmed that the variables aren't marked as non-volatile:

[fedora@admin]$ efivar -p --name 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f-LoaderTimeExecUSec
GUID: 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
Name: "LoaderTimeExecUSec"
Attributes:
	Boot Service Access
	Runtime Service Access
Value:
00000000  36 00 36 00 31 00 36 00  30 00 30 00 30 00 00 00  |6.6.1.6.0.0.0...|

[fedora@admin]$ efivar -p --name 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f-LoaderTimeInitUSec
GUID: 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
Name: "LoaderTimeInitUSec"
Attributes:
	Boot Service Access
	Runtime Service Access
Value:
00000000  31 00 37 00 30 00 34 00  30 00 30 00 30 00 00 00  |1.7.0.4.0.0.0...|

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Backport upstream patches from the series that added the Boot Loader
Interface module, which implements a different part of the interface:
support for LoaderInfo and LoaderDevicePartUUID.

The refactoring commits added a new grub_efi_set_variable_to_string
function, along with the ability to set a variable without the non-
volatile flag applied.

Add two patches of our own: one to implement the part of BLI that's
used by `systemd-analyze` to report time spent in the firmware and in
the bootloader; and another to make it so that grub_get_time_ms() on
i386 doesn't treat the time the TSC was calibrated as the epoch for
all timestamps, which otherwise hides the time spent between power on
and when GRUB is started.

Signed-off-by: Ben Cressey <[email protected]>
@bcressey bcressey requested review from larvacea and yeazelm November 15, 2024 22:14
Copy link
Contributor

@yeazelm yeazelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool! Nice set of patches!

@bcressey bcressey merged commit 50c1aeb into bottlerocket-os:develop Nov 25, 2024
2 checks passed
@bcressey bcressey deleted the grub-bli branch November 25, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make systemd-analyze report time spent in firmware and boot loader
4 participants