Debian Codegraph @

src/shared/boot-timestamps.c

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