55#include "efi-loader.h"
66#include "macro.h"
77#include "time-util.h"
8+ #include "virt.h"
89
910int boot_timestamps (const dual_timestamp * n , dual_timestamp * firmware , dual_timestamp * loader ) {
1011 usec_t x = 0 , y = 0 , a ;
1112 int r ;
1213 dual_timestamp _n ;
14+ bool use_firmware = true;
1315
1416 assert (firmware );
1517 assert (loader );
@@ -24,6 +26,10 @@ int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_time
2426 r = efi_loader_get_boot_usec (& x , & y );
2527 if (r < 0 )
2628 return r ;
29+
30+ /* If we are running in a VM, the init timestamp would
31+ * be equivalent to the host uptime. */
32+ use_firmware = detect_vm () <= 0 ;
2733 }
2834
2935 /* Let's convert this to timestamps where the firmware
@@ -33,12 +39,14 @@ int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_time
3339 * the monotonic timestamps here as negative of the actual
3440 * value. */
3541
36- firmware -> monotonic = y ;
37- loader -> monotonic = y - x ;
38-
39- a = n -> monotonic + firmware -> monotonic ;
40- firmware -> realtime = n -> realtime > a ? n -> realtime - a : 0 ;
42+ if (use_firmware ) {
43+ firmware -> monotonic = y ;
44+ a = n -> monotonic + firmware -> monotonic ;
45+ firmware -> realtime = n -> realtime > a ? n -> realtime - a : 0 ;
46+ } else
47+ firmware -> monotonic = firmware -> realtime = 0 ;
4148
49+ loader -> monotonic = y - x ;
4250 a = n -> monotonic + loader -> monotonic ;
4351 loader -> realtime = n -> realtime > a ? n -> realtime - a : 0 ;
4452
0 commit comments