]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c51d84dc | 2 | /*** |
c51d84dc KS |
3 | Copyright 2012 Lennart Poettering |
4 | Copyright 2013 Kay Sievers | |
c51d84dc | 5 | ***/ |
c51d84dc | 6 | |
c51d84dc | 7 | #include "acpi-fpdt.h" |
cf0fbc49 | 8 | #include "boot-timestamps.h" |
c51d84dc | 9 | #include "efivars.h" |
a8fbdf54 TA |
10 | #include "macro.h" |
11 | #include "time-util.h" | |
c51d84dc KS |
12 | |
13 | int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) { | |
39883f62 | 14 | usec_t x = 0, y = 0, a; |
c51d84dc KS |
15 | int r; |
16 | dual_timestamp _n; | |
17 | ||
18 | assert(firmware); | |
19 | assert(loader); | |
20 | ||
21 | if (!n) { | |
22 | dual_timestamp_get(&_n); | |
23 | n = &_n; | |
24 | } | |
25 | ||
26 | r = acpi_get_boot_usec(&x, &y); | |
27 | if (r < 0) { | |
28 | r = efi_loader_get_boot_usec(&x, &y); | |
29 | if (r < 0) | |
30 | return r; | |
31 | } | |
32 | ||
33 | /* Let's convert this to timestamps where the firmware | |
34 | * began/loader began working. To make this more confusing: | |
35 | * since usec_t is unsigned and the kernel's monotonic clock | |
36 | * begins at kernel initialization we'll actually initialize | |
37 | * the monotonic timestamps here as negative of the actual | |
38 | * value. */ | |
39 | ||
40 | firmware->monotonic = y; | |
41 | loader->monotonic = y - x; | |
42 | ||
43 | a = n->monotonic + firmware->monotonic; | |
44 | firmware->realtime = n->realtime > a ? n->realtime - a : 0; | |
45 | ||
46 | a = n->monotonic + loader->monotonic; | |
47 | loader->realtime = n->realtime > a ? n->realtime - a : 0; | |
48 | ||
49 | return 0; | |
50 | } |