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