]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/boot-timestamps.c
Add SPDX license identifiers to source files under the LGPL
[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 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "acpi-fpdt.h"
23 #include "boot-timestamps.h"
24 #include "efivars.h"
25 #include "macro.h"
26 #include "time-util.h"
27
28 int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) {
29 usec_t x = 0, y = 0, a;
30 int r;
31 dual_timestamp _n;
32
33 assert(firmware);
34 assert(loader);
35
36 if (!n) {
37 dual_timestamp_get(&_n);
38 n = &_n;
39 }
40
41 r = acpi_get_boot_usec(&x, &y);
42 if (r < 0) {
43 r = efi_loader_get_boot_usec(&x, &y);
44 if (r < 0)
45 return r;
46 }
47
48 /* Let's convert this to timestamps where the firmware
49 * began/loader began working. To make this more confusing:
50 * since usec_t is unsigned and the kernel's monotonic clock
51 * begins at kernel initialization we'll actually initialize
52 * the monotonic timestamps here as negative of the actual
53 * value. */
54
55 firmware->monotonic = y;
56 loader->monotonic = y - x;
57
58 a = n->monotonic + firmware->monotonic;
59 firmware->realtime = n->realtime > a ? n->realtime - a : 0;
60
61 a = n->monotonic + loader->monotonic;
62 loader->realtime = n->realtime > a ? n->realtime - a : 0;
63
64 return 0;
65 }