Commit | Line | Data |
---|---|---|
a72ca31a PMF |
1 | /* |
2 | * Code markup for dynamic and static tracing. | |
3 | * | |
4 | * See Documentation/marker.txt. | |
5 | * | |
6 | * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
59b161cd | 7 | * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca> |
a72ca31a | 8 | * |
8fc2d8db PMF |
9 | * This library is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License as published by the Free Software Foundation; either | |
12 | * version 2.1 of the License, or (at your option) any later version. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, | |
15 | * but 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 | |
20 | * License along with this library; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
a72ca31a PMF |
22 | */ |
23 | ||
e4621c7f PMF |
24 | #ifndef _LINUX_MARKER_H |
25 | #define _LINUX_MARKER_H | |
26 | ||
a72ca31a | 27 | #include <stdarg.h> |
59b161cd PMF |
28 | //ust// #include <linux/types.h> |
29 | #include "immediate.h" | |
30 | //ust// #include <linux/ltt-channels.h> | |
31 | #include "kernelcompat.h" | |
32 | #include "compiler.h" | |
769d0157 | 33 | #include <kcompat/list.h> |
4d65ee62 | 34 | #include "localerr.h" |
59b161cd PMF |
35 | |
36 | //ust// struct module; | |
37 | //ust// struct task_struct; | |
a72ca31a PMF |
38 | struct marker; |
39 | ||
40 | /** | |
41 | * marker_probe_func - Type of a marker probe function | |
42 | * @mdata: marker data | |
43 | * @probe_private: probe private data | |
44 | * @call_private: call site private data | |
45 | * @fmt: format string | |
46 | * @args: variable argument list pointer. Use a pointer to overcome C's | |
47 | * inability to pass this around as a pointer in a portable manner in | |
48 | * the callee otherwise. | |
49 | * | |
50 | * Type of marker probe functions. They receive the mdata and need to parse the | |
51 | * format string to recover the variable argument list. | |
52 | */ | |
53 | typedef void marker_probe_func(const struct marker *mdata, | |
54 | void *probe_private, void *call_private, | |
55 | const char *fmt, va_list *args); | |
56 | ||
57 | struct marker_probe_closure { | |
58 | marker_probe_func *func; /* Callback */ | |
59 | void *probe_private; /* Private probe data */ | |
60 | }; | |
61 | ||
62 | struct marker { | |
63 | const char *channel; /* Name of channel where to send data */ | |
64 | const char *name; /* Marker name */ | |
65 | const char *format; /* Marker format string, describing the | |
66 | * variable argument list. | |
67 | */ | |
59b161cd | 68 | DEFINE_IMV(char, state);/* Immediate value state. */ |
a72ca31a PMF |
69 | char ptype; /* probe type : 0 : single, 1 : multi */ |
70 | /* Probe wrapper */ | |
71 | u16 channel_id; /* Numeric channel identifier, dynamic */ | |
72 | u16 event_id; /* Numeric event identifier, dynamic */ | |
73 | void (*call)(const struct marker *mdata, void *call_private, ...); | |
74 | struct marker_probe_closure single; | |
75 | struct marker_probe_closure *multi; | |
76 | const char *tp_name; /* Optional tracepoint name */ | |
77 | void *tp_cb; /* Optional tracepoint callback */ | |
78 | } __attribute__((aligned(8))); | |
79 | ||
872037bb PMF |
80 | #define CONFIG_MARKERS |
81 | #ifdef CONFIG_MARKERS | |
a72ca31a PMF |
82 | |
83 | #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \ | |
84 | static const char __mstrtab_##channel##_##name[] \ | |
85 | __attribute__((section("__markers_strings"))) \ | |
86 | = #channel "\0" #name "\0" format; \ | |
87 | static struct marker __mark_##channel##_##name \ | |
88 | __attribute__((section("__markers"), aligned(8))) = \ | |
89 | { __mstrtab_##channel##_##name, \ | |
90 | &__mstrtab_##channel##_##name[sizeof(#channel)], \ | |
91 | &__mstrtab_##channel##_##name[sizeof(#channel) + \ | |
92 | sizeof(#name)], \ | |
93 | 0, 0, 0, 0, marker_probe_cb, \ | |
94 | { __mark_empty_function, NULL}, \ | |
95 | NULL, tp_name_str, tp_cb } | |
96 | ||
97 | #define DEFINE_MARKER(channel, name, format) \ | |
98 | _DEFINE_MARKER(channel, name, NULL, NULL, format) | |
99 | ||
100 | #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \ | |
101 | _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format) | |
102 | ||
103 | /* | |
104 | * Make sure the alignment of the structure in the __markers section will | |
105 | * not add unwanted padding between the beginning of the section and the | |
106 | * structure. Force alignment to the same alignment as the section start. | |
107 | * | |
108 | * The "generic" argument controls which marker enabling mechanism must be used. | |
109 | * If generic is true, a variable read is used. | |
110 | * If generic is false, immediate values are used. | |
111 | */ | |
112 | #define __trace_mark(generic, channel, name, call_private, format, args...) \ | |
113 | do { \ | |
114 | DEFINE_MARKER(channel, name, format); \ | |
115 | __mark_check_format(format, ## args); \ | |
116 | if (!generic) { \ | |
117 | if (unlikely(imv_read( \ | |
118 | __mark_##channel##_##name.state))) \ | |
119 | (*__mark_##channel##_##name.call) \ | |
120 | (&__mark_##channel##_##name, \ | |
121 | call_private, ## args); \ | |
122 | } else { \ | |
123 | if (unlikely(_imv_read( \ | |
124 | __mark_##channel##_##name.state))) \ | |
125 | (*__mark_##channel##_##name.call) \ | |
126 | (&__mark_##channel##_##name, \ | |
127 | call_private, ## args); \ | |
128 | } \ | |
129 | } while (0) | |
130 | ||
131 | #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \ | |
132 | format, args...) \ | |
133 | do { \ | |
134 | void __check_tp_type(void) \ | |
135 | { \ | |
136 | register_trace_##tp_name(tp_cb); \ | |
137 | } \ | |
138 | DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\ | |
139 | __mark_check_format(format, ## args); \ | |
140 | (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \ | |
141 | call_private, ## args); \ | |
142 | } while (0) | |
143 | ||
144 | extern void marker_update_probe_range(struct marker *begin, | |
145 | struct marker *end); | |
146 | ||
147 | #define GET_MARKER(channel, name) (__mark_##channel##_##name) | |
148 | ||
872037bb PMF |
149 | #else /* !CONFIG_MARKERS */ |
150 | #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format) | |
151 | #define __trace_mark(generic, channel, name, call_private, format, args...) \ | |
152 | __mark_check_format(format, ## args) | |
153 | #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \ | |
154 | format, args...) \ | |
155 | do { \ | |
156 | void __check_tp_type(void) \ | |
157 | { \ | |
158 | register_trace_##tp_name(tp_cb); \ | |
159 | } \ | |
160 | __mark_check_format(format, ## args); \ | |
161 | } while (0) | |
162 | static inline void marker_update_probe_range(struct marker *begin, | |
163 | struct marker *end) | |
164 | { } | |
165 | #define GET_MARKER(channel, name) | |
166 | #endif /* CONFIG_MARKERS */ | |
a72ca31a PMF |
167 | |
168 | /** | |
169 | * trace_mark - Marker using code patching | |
170 | * @channel: marker channel (where to send the data), not quoted. | |
171 | * @name: marker name, not quoted. | |
172 | * @format: format string | |
173 | * @args...: variable argument list | |
174 | * | |
175 | * Places a marker using optimized code patching technique (imv_read()) | |
176 | * to be enabled when immediate values are present. | |
177 | */ | |
178 | #define trace_mark(channel, name, format, args...) \ | |
179 | __trace_mark(0, channel, name, NULL, format, ## args) | |
180 | ||
181 | /** | |
182 | * _trace_mark - Marker using variable read | |
183 | * @channel: marker channel (where to send the data), not quoted. | |
184 | * @name: marker name, not quoted. | |
185 | * @format: format string | |
186 | * @args...: variable argument list | |
187 | * | |
188 | * Places a marker using a standard memory read (_imv_read()) to be | |
189 | * enabled. Should be used for markers in code paths where instruction | |
190 | * modification based enabling is not welcome. (__init and __exit functions, | |
191 | * lockdep, some traps, printk). | |
192 | */ | |
193 | #define _trace_mark(channel, name, format, args...) \ | |
194 | __trace_mark(1, channel, name, NULL, format, ## args) | |
195 | ||
196 | /** | |
197 | * trace_mark_tp - Marker in a tracepoint callback | |
198 | * @channel: marker channel (where to send the data), not quoted. | |
199 | * @name: marker name, not quoted. | |
200 | * @tp_name: tracepoint name, not quoted. | |
201 | * @tp_cb: tracepoint callback. Should have an associated global symbol so it | |
202 | * is not optimized away by the compiler (should not be static). | |
203 | * @format: format string | |
204 | * @args...: variable argument list | |
205 | * | |
206 | * Places a marker in a tracepoint callback. | |
207 | */ | |
208 | #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \ | |
209 | __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args) | |
210 | ||
211 | /** | |
212 | * MARK_NOARGS - Format string for a marker with no argument. | |
213 | */ | |
214 | #define MARK_NOARGS " " | |
215 | ||
216 | extern void lock_markers(void); | |
217 | extern void unlock_markers(void); | |
218 | ||
219 | extern void markers_compact_event_ids(void); | |
220 | ||
221 | /* To be used for string format validity checking with gcc */ | |
222 | static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...) | |
223 | { | |
224 | } | |
225 | ||
226 | #define __mark_check_format(format, args...) \ | |
227 | do { \ | |
228 | if (0) \ | |
229 | ___mark_check_format(format, ## args); \ | |
230 | } while (0) | |
231 | ||
232 | extern marker_probe_func __mark_empty_function; | |
233 | ||
234 | extern void marker_probe_cb(const struct marker *mdata, | |
235 | void *call_private, ...); | |
236 | ||
237 | /* | |
238 | * Connect a probe to a marker. | |
239 | * private data pointer must be a valid allocated memory address, or NULL. | |
240 | */ | |
241 | extern int marker_probe_register(const char *channel, const char *name, | |
242 | const char *format, marker_probe_func *probe, void *probe_private); | |
243 | ||
244 | /* | |
245 | * Returns the private data given to marker_probe_register. | |
246 | */ | |
247 | extern int marker_probe_unregister(const char *channel, const char *name, | |
248 | marker_probe_func *probe, void *probe_private); | |
249 | /* | |
250 | * Unregister a marker by providing the registered private data. | |
251 | */ | |
252 | extern int marker_probe_unregister_private_data(marker_probe_func *probe, | |
253 | void *probe_private); | |
254 | ||
255 | extern void *marker_get_private_data(const char *channel, const char *name, | |
256 | marker_probe_func *probe, int num); | |
257 | ||
258 | /* | |
259 | * marker_synchronize_unregister must be called between the last marker probe | |
260 | * unregistration and the first one of | |
261 | * - the end of module exit function | |
262 | * - the free of any resource used by the probes | |
263 | * to ensure the code and data are valid for any possibly running probes. | |
264 | */ | |
265 | #define marker_synchronize_unregister() synchronize_sched() | |
266 | ||
267 | struct marker_iter { | |
98963de4 PMF |
268 | //ust// struct module *module; |
269 | struct lib *lib; | |
a72ca31a PMF |
270 | struct marker *marker; |
271 | }; | |
272 | ||
273 | extern void marker_iter_start(struct marker_iter *iter); | |
274 | extern void marker_iter_next(struct marker_iter *iter); | |
275 | extern void marker_iter_stop(struct marker_iter *iter); | |
276 | extern void marker_iter_reset(struct marker_iter *iter); | |
277 | extern int marker_get_iter_range(struct marker **marker, struct marker *begin, | |
278 | struct marker *end); | |
279 | ||
280 | extern void marker_update_process(void); | |
281 | extern int is_marker_enabled(const char *channel, const char *name); | |
282 | ||
59b161cd PMF |
283 | //ust// #ifdef CONFIG_MARKERS_USERSPACE |
284 | //ust// extern void exit_user_markers(struct task_struct *p); | |
285 | //ust// #else | |
286 | //ust// static inline void exit_user_markers(struct task_struct *p) | |
287 | //ust// { | |
288 | //ust// } | |
289 | //ust// #endif | |
a72ca31a | 290 | |
98963de4 PMF |
291 | |
292 | struct lib { | |
293 | struct marker *markers_start; | |
294 | int markers_count; | |
295 | struct list_head list; | |
296 | }; | |
297 | ||
872037bb PMF |
298 | extern int marker_register_lib(struct marker *markers_start, |
299 | int markers_count); | |
c463904d | 300 | |
872037bb PMF |
301 | #define MARKER_LIB \ |
302 | extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \ | |
fbd8191b PMF |
303 | extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ |
304 | \ | |
305 | static void __attribute__((constructor)) __markers__init(void) \ | |
306 | { \ | |
4d65ee62 | 307 | DBG("next registration in "__FILE__"\n");\ |
c463904d PMF |
308 | marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\ |
309 | } | |
98963de4 | 310 | |
20b37a31 | 311 | void marker_set_new_marker_cb(void (*cb)(struct marker *)); |
474d745f | 312 | |
9160b4e4 PMF |
313 | void init_markers(void); |
314 | ||
474d745f | 315 | #endif |