]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/boot-timestamps.c
Merge pull request #2092 from poettering/dnssec2
[thirdparty/systemd.git] / src / shared / boot-timestamps.c
CommitLineData
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***/
c51d84dc 22
c51d84dc 23#include "acpi-fpdt.h"
cf0fbc49 24#include "boot-timestamps.h"
c51d84dc
KS
25#include "efivars.h"
26
27int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) {
39883f62 28 usec_t x = 0, y = 0, a;
c51d84dc
KS
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}