Commit | Line | Data |
---|---|---|
886d51a3 MD |
1 | #ifndef _LTTNG_TRACE_CLOCK_H |
2 | #define _LTTNG_TRACE_CLOCK_H | |
3 | ||
f6c19f6e | 4 | /* |
886d51a3 | 5 | * wrapper/trace-clock.h |
f6c19f6e MD |
6 | * |
7 | * Contains LTTng trace clock mapping to LTTng trace clock or mainline monotonic | |
8 | * clock. This wrapper depends on CONFIG_HIGH_RES_TIMERS=y. | |
9 | * | |
886d51a3 MD |
10 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
11 | * | |
12 | * This library is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public | |
14 | * License as published by the Free Software Foundation; only | |
15 | * version 2.1 of the License. | |
16 | * | |
17 | * This library is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * Lesser General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this library; if not, write to the Free Software | |
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
f6c19f6e MD |
25 | */ |
26 | ||
f6c19f6e MD |
27 | #ifdef CONFIG_HAVE_TRACE_CLOCK |
28 | #include <linux/trace-clock.h> | |
29 | #else /* CONFIG_HAVE_TRACE_CLOCK */ | |
30 | ||
31 | #include <linux/hardirq.h> | |
32 | #include <linux/ktime.h> | |
33 | #include <linux/time.h> | |
34 | #include <linux/hrtimer.h> | |
a82c63f1 | 35 | #include "random.h" |
f6c19f6e MD |
36 | |
37 | static inline u64 trace_clock_monotonic_wrapper(void) | |
38 | { | |
39 | ktime_t ktime; | |
40 | ||
41 | /* | |
42 | * Refuse to trace from NMIs with this wrapper, because an NMI could | |
43 | * nest over the xtime write seqlock and deadlock. | |
44 | */ | |
45 | if (in_nmi()) | |
97ca2c54 | 46 | return (u64) -EIO; |
f6c19f6e MD |
47 | |
48 | ktime = ktime_get(); | |
cfaf9f3d | 49 | return ktime_to_ns(ktime); |
f6c19f6e MD |
50 | } |
51 | ||
52 | static inline u32 trace_clock_read32(void) | |
53 | { | |
54 | return (u32) trace_clock_monotonic_wrapper(); | |
55 | } | |
56 | ||
57 | static inline u64 trace_clock_read64(void) | |
58 | { | |
59 | return (u64) trace_clock_monotonic_wrapper(); | |
60 | } | |
61 | ||
a3ccff4f | 62 | static inline u64 trace_clock_freq(void) |
f6c19f6e | 63 | { |
a3ccff4f | 64 | return (u64) NSEC_PER_SEC; |
f6c19f6e MD |
65 | } |
66 | ||
a82c63f1 | 67 | static inline int trace_clock_uuid(char *uuid) |
f6c19f6e | 68 | { |
a82c63f1 | 69 | return wrapper_get_bootid(uuid); |
f6c19f6e MD |
70 | } |
71 | ||
72 | static inline int get_trace_clock(void) | |
73 | { | |
22f8d33a MD |
74 | /* |
75 | * LTTng: Using mainline kernel monotonic clock. NMIs will not be | |
76 | * traced, and expect significant performance degradation compared to | |
77 | * the LTTng trace clocks. Integration of the LTTng 0.x trace clocks | |
78 | * into LTTng 2.0 is planned in a near future. | |
79 | */ | |
f6c19f6e MD |
80 | printk(KERN_WARNING "LTTng: Using mainline kernel monotonic clock.\n"); |
81 | printk(KERN_WARNING " * NMIs will not be traced,\n"); | |
82 | printk(KERN_WARNING " * expect significant performance degradation compared to the\n"); | |
83 | printk(KERN_WARNING " LTTng trace clocks.\n"); | |
cff67ebe MD |
84 | printk(KERN_WARNING "Integration of the LTTng 0.x trace clocks into LTTng 2.0 is planned\n"); |
85 | printk(KERN_WARNING "in a near future.\n"); | |
f3bc08c5 | 86 | |
f6c19f6e MD |
87 | return 0; |
88 | } | |
89 | ||
90 | static inline void put_trace_clock(void) | |
91 | { | |
92 | } | |
93 | ||
94 | #endif /* CONFIG_HAVE_TRACE_CLOCK */ | |
95 | ||
a90917c3 | 96 | #endif /* _LTTNG_TRACE_CLOCK_H */ |