chiark / gitweb /
util: add timeout to generator execution
[elogind.git] / src / shared / boot-timestamps.c
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 = 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 #ifdef ENABLE_EFI
44                 r = efi_loader_get_boot_usec(&x, &y);
45                 if (r < 0)
46 #endif
47                         return r;
48         }
49
50         /* Let's convert this to timestamps where the firmware
51          * began/loader began working. To make this more confusing:
52          * since usec_t is unsigned and the kernel's monotonic clock
53          * begins at kernel initialization we'll actually initialize
54          * the monotonic timestamps here as negative of the actual
55          * value. */
56
57         firmware->monotonic = y;
58         loader->monotonic = y - x;
59
60         a = n->monotonic + firmware->monotonic;
61         firmware->realtime = n->realtime > a ? n->realtime - a : 0;
62
63         a = n->monotonic + loader->monotonic;
64         loader->realtime = n->realtime > a ? n->realtime - a : 0;
65
66         return 0;
67 }