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