]>
Commit | Line | Data |
---|---|---|
c51d84dc KS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2012 Lennart Poettering | |
7 | Copyright 2013 Kay Sievers | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | #include <unistd.h> | |
23 | ||
24 | #include "boot-timestamps.h" | |
25 | #include "acpi-fpdt.h" | |
26 | #include "efivars.h" | |
27 | ||
28 | int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) { | |
29 | usec_t x, y, 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 | } |