Commit | Line | Data |
---|---|---|
f99be407 PMF |
1 | #ifndef _LINUX_TRACEPOINT_H |
2 | #define _LINUX_TRACEPOINT_H | |
3 | ||
4 | /* | |
5 | * Kernel Tracepoint API. | |
6 | * | |
7 | * See Documentation/tracepoint.txt. | |
8 | * | |
9 | * (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
10 | * | |
11 | * Heavily inspired from the Linux Kernel Markers. | |
12 | * | |
13 | * This file is released under the GPLv2. | |
14 | * See the file COPYING for more details. | |
15 | */ | |
16 | ||
17 | #include <linux/immediate.h> | |
18 | #include <linux/types.h> | |
19 | #include <linux/rcupdate.h> | |
20 | ||
21 | struct module; | |
22 | struct tracepoint; | |
23 | ||
24 | struct tracepoint { | |
25 | const char *name; /* Tracepoint name */ | |
26 | DEFINE_IMV(char, state); /* State. */ | |
27 | void **funcs; | |
28 | } __attribute__((aligned(32))); /* | |
29 | * Aligned on 32 bytes because it is | |
30 | * globally visible and gcc happily | |
31 | * align these on the structure size. | |
32 | * Keep in sync with vmlinux.lds.h. | |
33 | */ | |
34 | ||
35 | #define TPPROTO(args...) args | |
36 | #define TPARGS(args...) args | |
37 | ||
38 | #ifdef CONFIG_TRACEPOINTS | |
39 | ||
40 | /* | |
41 | * it_func[0] is never NULL because there is at least one element in the array | |
42 | * when the array itself is non NULL. | |
43 | */ | |
44 | #define __DO_TRACE(tp, proto, args) \ | |
45 | do { \ | |
46 | void **it_func; \ | |
47 | \ | |
48 | rcu_read_lock_sched_notrace(); \ | |
49 | it_func = rcu_dereference((tp)->funcs); \ | |
50 | if (it_func) { \ | |
51 | do { \ | |
52 | ((void(*)(proto))(*it_func))(args); \ | |
53 | } while (*(++it_func)); \ | |
54 | } \ | |
55 | rcu_read_unlock_sched_notrace(); \ | |
56 | } while (0) | |
57 | ||
58 | #define __CHECK_TRACE(name, generic, proto, args) \ | |
59 | do { \ | |
60 | if (!generic) { \ | |
61 | if (unlikely(imv_read(__tracepoint_##name.state))) \ | |
62 | __DO_TRACE(&__tracepoint_##name, \ | |
63 | TPPROTO(proto), TPARGS(args)); \ | |
64 | } else { \ | |
65 | if (unlikely(_imv_read(__tracepoint_##name.state))) \ | |
66 | __DO_TRACE(&__tracepoint_##name, \ | |
67 | TPPROTO(proto), TPARGS(args)); \ | |
68 | } \ | |
69 | } while (0) | |
70 | ||
71 | /* | |
72 | * Make sure the alignment of the structure in the __tracepoints section will | |
73 | * not add unwanted padding between the beginning of the section and the | |
74 | * structure. Force alignment to the same alignment as the section start. | |
75 | * | |
76 | * The "generic" argument, passed to the declared __trace_##name inline | |
77 | * function controls which tracepoint enabling mechanism must be used. | |
78 | * If generic is true, a variable read is used. | |
79 | * If generic is false, immediate values are used. | |
80 | */ | |
81 | #define DECLARE_TRACE(name, proto, args) \ | |
82 | extern struct tracepoint __tracepoint_##name; \ | |
83 | static inline void trace_##name(proto) \ | |
84 | { \ | |
85 | __CHECK_TRACE(name, 0, TPPROTO(proto), TPARGS(args)); \ | |
86 | } \ | |
87 | static inline void _trace_##name(proto) \ | |
88 | { \ | |
89 | __CHECK_TRACE(name, 1, TPPROTO(proto), TPARGS(args)); \ | |
90 | } \ | |
91 | static inline int register_trace_##name(void (*probe)(proto)) \ | |
92 | { \ | |
93 | return tracepoint_probe_register(#name, (void *)probe); \ | |
94 | } \ | |
95 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | |
96 | { \ | |
97 | return tracepoint_probe_unregister(#name, (void *)probe);\ | |
98 | } | |
99 | ||
100 | #define DEFINE_TRACE(name) \ | |
101 | static const char __tpstrtab_##name[] \ | |
102 | __attribute__((section("__tracepoints_strings"))) = #name; \ | |
103 | struct tracepoint __tracepoint_##name \ | |
104 | __attribute__((section("__tracepoints"), aligned(32))) = \ | |
105 | { __tpstrtab_##name, 0, NULL } | |
106 | ||
107 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \ | |
108 | EXPORT_SYMBOL_GPL(__tracepoint_##name) | |
109 | #define EXPORT_TRACEPOINT_SYMBOL(name) \ | |
110 | EXPORT_SYMBOL(__tracepoint_##name) | |
111 | ||
112 | extern void tracepoint_update_probe_range(struct tracepoint *begin, | |
113 | struct tracepoint *end); | |
114 | ||
115 | #else /* !CONFIG_TRACEPOINTS */ | |
116 | #define DECLARE_TRACE(name, proto, args) \ | |
117 | static inline void trace_##name(proto) \ | |
118 | { } \ | |
119 | static inline void _trace_##name(proto) \ | |
120 | { } \ | |
121 | static inline int register_trace_##name(void (*probe)(proto)) \ | |
122 | { \ | |
123 | return -ENOSYS; \ | |
124 | } \ | |
125 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | |
126 | { \ | |
127 | return -ENOSYS; \ | |
128 | } | |
129 | ||
130 | #define DEFINE_TRACE(name) | |
131 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) | |
132 | #define EXPORT_TRACEPOINT_SYMBOL(name) | |
133 | ||
134 | static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |
135 | struct tracepoint *end) | |
136 | { } | |
137 | #endif /* CONFIG_TRACEPOINTS */ | |
138 | ||
139 | /* | |
140 | * Connect a probe to a tracepoint. | |
141 | * Internal API, should not be used directly. | |
142 | */ | |
143 | extern int tracepoint_probe_register(const char *name, void *probe); | |
144 | ||
145 | /* | |
146 | * Disconnect a probe from a tracepoint. | |
147 | * Internal API, should not be used directly. | |
148 | */ | |
149 | extern int tracepoint_probe_unregister(const char *name, void *probe); | |
150 | ||
151 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | |
152 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | |
153 | extern void tracepoint_probe_update_all(void); | |
154 | ||
155 | struct tracepoint_iter { | |
156 | struct module *module; | |
157 | struct tracepoint *tracepoint; | |
158 | }; | |
159 | ||
160 | extern void tracepoint_iter_start(struct tracepoint_iter *iter); | |
161 | extern void tracepoint_iter_next(struct tracepoint_iter *iter); | |
162 | extern void tracepoint_iter_stop(struct tracepoint_iter *iter); | |
163 | extern void tracepoint_iter_reset(struct tracepoint_iter *iter); | |
164 | extern int tracepoint_get_iter_range(struct tracepoint **tracepoint, | |
165 | struct tracepoint *begin, struct tracepoint *end); | |
166 | ||
167 | /* | |
168 | * tracepoint_synchronize_unregister must be called between the last tracepoint | |
169 | * probe unregistration and the end of module exit to make sure there is no | |
170 | * caller executing a probe when it is freed. | |
171 | */ | |
172 | static inline void tracepoint_synchronize_unregister(void) | |
173 | { | |
174 | synchronize_sched(); | |
175 | } | |
176 | ||
177 | #endif |