Skip to content

Commit f699bd8

Browse files
medhefgokeszybz
authored andcommitted
boot-timestamps: Discard firmware init time when running in a VM
Fixes: systemd#22060
1 parent 4600461 commit f699bd8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/shared/boot-timestamps.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include "efi-loader.h"
66
#include "macro.h"
77
#include "time-util.h"
8+
#include "virt.h"
89

910
int 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

Comments
 (0)