From d0c05a5d686fb5e6d177a87cdd0b48e542e72a04 Mon Sep 17 00:00:00 2001 From: Babis Chalios Date: Wed, 4 Jun 2025 12:33:10 +0200 Subject: [PATCH] fix: boottimer device MMIO address When we re-arranged the MMIO address space in commit 9a165d17f1ba (arch: define 64-bit capable MMIO memory regions) we moved the MMIO region of the boot timer device for x86 systems, but we didn't update the init scripts that hardcode it and use it to report boot time timestamp back to Firecracker. Update the init.c and initramfs values for the region. Also, add a functional test that runs during CI PR tests and makes sure the boot timer works. Signed-off-by: Babis Chalios --- resources/overlay/usr/local/bin/init.c | 2 +- resources/rebuild.sh | 2 +- .../performance/test_boottime.py | 42 +++++++++++++------ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/resources/overlay/usr/local/bin/init.c b/resources/overlay/usr/local/bin/init.c index caa3e9d91d5..4d469171ae5 100644 --- a/resources/overlay/usr/local/bin/init.c +++ b/resources/overlay/usr/local/bin/init.c @@ -13,7 +13,7 @@ // Position on the bus is defined by MMIO_LEN increments, where MMIO_LEN is // defined as 0x1000 in vmm/src/device_manager/mmio.rs. #ifdef __x86_64__ -#define MAGIC_MMIO_SIGNAL_GUEST_BOOT_COMPLETE 0xd0000000 +#define MAGIC_MMIO_SIGNAL_GUEST_BOOT_COMPLETE 0xc0000000 #endif #ifdef __aarch64__ #define MAGIC_MMIO_SIGNAL_GUEST_BOOT_COMPLETE 0x40000000 diff --git a/resources/rebuild.sh b/resources/rebuild.sh index dabffa8c2ae..d3d4ffe052e 100755 --- a/resources/rebuild.sh +++ b/resources/rebuild.sh @@ -92,7 +92,7 @@ function build_initramfs { # Report guest boot time back to Firecracker via MMIO # See arch/src/lib.rs and the BootTimer device - MAGIC_BOOT_ADDRESS=0xd0000000 + MAGIC_BOOT_ADDRESS=0xc0000000 if [ $ARCH = "aarch64" ]; then MAGIC_BOOT_ADDRESS=0x40000000 fi diff --git a/tests/integration_tests/performance/test_boottime.py b/tests/integration_tests/performance/test_boottime.py index ad0822b0436..7708451ec7f 100644 --- a/tests/integration_tests/performance/test_boottime.py +++ b/tests/integration_tests/performance/test_boottime.py @@ -94,6 +94,33 @@ def to_ms(v, unit): return kernel, userspace, total +def launch_vm_with_boot_timer( + microvm_factory, guest_kernel_acpi, rootfs_rw, vcpu_count, mem_size_mib +): + """Launches a microVM with guest-timer and returns the reported metrics for it""" + vm = microvm_factory.build(guest_kernel_acpi, rootfs_rw) + vm.jailer.extra_args.update({"boot-timer": None}) + vm.spawn() + vm.basic_config( + vcpu_count=vcpu_count, + mem_size_mib=mem_size_mib, + boot_args=DEFAULT_BOOT_ARGS + " init=/usr/local/bin/init", + enable_entropy_device=True, + ) + vm.add_net_iface() + vm.start() + vm.pin_threads(0) + + boot_time_us, cpu_boot_time_us = get_boottime_device_info(vm) + + return (vm, boot_time_us, cpu_boot_time_us) + + +def test_boot_timer(microvm_factory, guest_kernel_acpi, rootfs): + """Tests that the boot timer device works""" + launch_vm_with_boot_timer(microvm_factory, guest_kernel_acpi, rootfs, 1, 128) + + @pytest.mark.parametrize( "vcpu_count,mem_size_mib", [(1, 128), (1, 1024), (2, 2048), (4, 4096)], @@ -105,20 +132,9 @@ def test_boottime( """Test boot time with different guest configurations""" for i in range(10): - vm = microvm_factory.build(guest_kernel_acpi, rootfs_rw) - vm.jailer.extra_args.update({"boot-timer": None}) - vm.spawn() - vm.basic_config( - vcpu_count=vcpu_count, - mem_size_mib=mem_size_mib, - boot_args=DEFAULT_BOOT_ARGS + " init=/usr/local/bin/init", - enable_entropy_device=True, + vm, boot_time_us, cpu_boot_time_us = launch_vm_with_boot_timer( + microvm_factory, guest_kernel_acpi, rootfs_rw, vcpu_count, mem_size_mib ) - vm.add_net_iface() - vm.start() - vm.pin_threads(0) - - boot_time_us, cpu_boot_time_us = get_boottime_device_info(vm) if i == 0: metrics.set_dimensions(