]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/boot-timestamps.c
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / shared / boot-timestamps.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright © 2013 Kay Sievers
4 ***/
5
6 #include "acpi-fpdt.h"
7 #include "boot-timestamps.h"
8 #include "efivars.h"
9 #include "macro.h"
10 #include "time-util.h"
11
12 int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) {
13 usec_t x = 0, y = 0, a;
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 }