Skip to content

Commit 98e6305

Browse files
Alexandra Iordacheacatangiu
authored andcommitted
vmm: guest boot time in CPU us and wall clock us
Signed-off-by: Alexandra Iordache <[email protected]>
1 parent 260189c commit 98e6305

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

vmm/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
authors = ["Amazon firecracker team <[email protected]>"]
55

66
[dependencies]
7+
chrono = ">=0.4"
78
libc = ">=0.2.39"
89
epoll = "=2.1.0"
910
futures = ">=0.1.18"
@@ -15,6 +16,7 @@ timerfd = ">=1.0"
1516

1617
data_model = { path = "../data_model" }
1718
devices = { path = "../devices" }
19+
fc_util = { path = "../fc_util" }
1820
kernel = { path = "../kernel" }
1921
kvm = { path = "../kvm" }
2022
logger = { path = "../logger" }

vmm/src/lib.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
extern crate chrono;
12
extern crate epoll;
23
extern crate futures;
34
extern crate libc;
@@ -9,6 +10,7 @@ extern crate timerfd;
910

1011
extern crate data_model;
1112
extern crate devices;
13+
extern crate fc_util;
1214
extern crate kernel;
1315
extern crate kvm;
1416
#[macro_use]
@@ -50,6 +52,7 @@ use device_manager::legacy::LegacyDeviceManager;
5052
use device_manager::mmio::MMIODeviceManager;
5153
use devices::virtio;
5254
use devices::{DeviceEventT, EpollHandler, EpollHandlerPayload};
55+
use fc_util::now_cputime_us;
5356
use kernel::cmdline as kernel_cmdline;
5457
use kernel::loader as kernel_loader;
5558
use kvm::*;
@@ -71,6 +74,7 @@ const DEFAULT_KERNEL_CMDLINE: &str = "reboot=k panic=1 pci=off nomodules 8250.nr
7174
const VCPU_RTSIG_OFFSET: i32 = 0;
7275
const WRITE_METRICS_PERIOD_SECONDS: u64 = 60;
7376
static START_INSTANCE_REQUEST_TS: AtomicUsize = ATOMIC_USIZE_INIT;
77+
static START_INSTANCE_REQUEST_CPU_TS: AtomicUsize = ATOMIC_USIZE_INIT;
7478

7579
/// Errors associated with the VMM internal logic. These errors cannot be generated by direct user
7680
/// input, but can result from bad configuration of the host (for example if Firecracker doesn't
@@ -807,12 +811,22 @@ impl Vmm {
807811
if addr == MAGIC_IOPORT_SIGNAL_GUEST_BOOT_COMPLETE
808812
&& data[0] == MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE
809813
{
810-
let boot_time_ns = time::precise_time_ns() as usize
814+
let now_cpu_us = now_cputime_us();
815+
let now_us =
816+
chrono::Utc::now().timestamp_nanos() / 1000;
817+
818+
let boot_time_us = now_us as usize
811819
- START_INSTANCE_REQUEST_TS.load(Ordering::Acquire);
820+
let boot_time_cpu_us = now_cpu_us as usize
821+
- START_INSTANCE_REQUEST_CPU_TS
822+
.load(Ordering::Acquire);
812823
warn!(
813-
"Guest-boot-time = {:>6} us {} ms",
814-
boot_time_ns / 1000,
815-
boot_time_ns / 1000000
824+
"Guest-boot-time = {:>6} us {} ms, \
825+
{:>6} CPU us {} CPU ms",
826+
boot_time_us,
827+
boot_time_us / 1000,
828+
boot_time_cpu_us,
829+
boot_time_cpu_us / 1000
816830
);
817831
}
818832
io_bus.write(addr as u64, data);
@@ -955,7 +969,11 @@ impl Vmm {
955969
}
956970

957971
fn start_microvm(&mut self) -> std::result::Result<VmmData, VmmActionError> {
958-
START_INSTANCE_REQUEST_TS.store(time::precise_time_ns() as usize, Ordering::Release);
972+
START_INSTANCE_REQUEST_CPU_TS.store(now_cputime_us() as usize, Ordering::Release);
973+
START_INSTANCE_REQUEST_TS.store(
974+
(chrono::Utc::now().timestamp_nanos() / 1000) as usize,
975+
Ordering::Release,
976+
);
959977
info!("VMM received instance start command");
960978
if self.is_instance_initialized() {
961979
return Err(VmmActionError::StartMicrovm(

0 commit comments

Comments
 (0)