Merge tag 'v3.14.25' into backport/v3.14.24-ltsi-rc1+v3.14.25/snapshot-merge.wip
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / lttng / wrapper / trace-clock.h
1 #ifndef _LTTNG_TRACE_CLOCK_H
2 #define _LTTNG_TRACE_CLOCK_H
3
4 /*
5  * wrapper/trace-clock.h
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  *
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
25  */
26
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>
35 #include <linux/version.h>
36 #include "../lttng-kernel-version.h"
37 #include "random.h"
38
39 #if LTTNG_KERNEL_RANGE(3,10,0, 3,10,14) || LTTNG_KERNEL_RANGE(3,11,0, 3,11,3)
40 #error "Linux kernels 3.10 and 3.11 introduce a deadlock in the timekeeping subsystem. Fixed by commit 7bd36014460f793c19e7d6c94dab67b0afcfcb7f \"timekeeping: Fix HRTICK related deadlock from ntp lock changes\" in Linux."
41 #endif
42
43 static inline u64 trace_clock_monotonic_wrapper(void)
44 {
45         ktime_t ktime;
46
47         /*
48          * Refuse to trace from NMIs with this wrapper, because an NMI could
49          * nest over the xtime write seqlock and deadlock.
50          */
51         if (in_nmi())
52                 return (u64) -EIO;
53
54         ktime = ktime_get();
55         return ktime_to_ns(ktime);
56 }
57
58 static inline u32 trace_clock_read32(void)
59 {
60         return (u32) trace_clock_monotonic_wrapper();
61 }
62
63 static inline u64 trace_clock_read64(void)
64 {
65         return (u64) trace_clock_monotonic_wrapper();
66 }
67
68 static inline u64 trace_clock_freq(void)
69 {
70         return (u64) NSEC_PER_SEC;
71 }
72
73 static inline int trace_clock_uuid(char *uuid)
74 {
75         return wrapper_get_bootid(uuid);
76 }
77
78 static inline int get_trace_clock(void)
79 {
80         /*
81          * LTTng: Using mainline kernel monotonic clock. NMIs will not be
82          * traced, and expect significant performance degradation compared to
83          * the LTTng trace clocks. Integration of the LTTng 0.x trace clocks
84          * into LTTng 2.0 is planned in a near future.
85          */
86         printk(KERN_WARNING "LTTng: Using mainline kernel monotonic clock.\n");
87         printk(KERN_WARNING "  * NMIs will not be traced,\n");
88         printk(KERN_WARNING "  * expect significant performance degradation compared to the\n");
89         printk(KERN_WARNING "    LTTng trace clocks.\n");
90         printk(KERN_WARNING "Integration of the LTTng 0.x trace clocks into LTTng 2.0 is planned\n");
91         printk(KERN_WARNING "in a near future.\n");
92
93         return 0;
94 }
95
96 static inline void put_trace_clock(void)
97 {
98 }
99
100 #endif /* CONFIG_HAVE_TRACE_CLOCK */
101
102 #endif /* _LTTNG_TRACE_CLOCK_H */