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