cffa9d30b330e3bbdf6acf6f9e48319cb84277f9
[ust.git] / include / ust / marker.h
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>
7 * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca>
8 * (C) Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation;
13 * version 2.1 of the License.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef _UST_MARKER_H
26 #define _UST_MARKER_H
27
28 #include <stdarg.h>
29 #include <ust/core.h>
30 #include <urcu/list.h>
31 #include <ust/kcompat/kcompat.h>
32
33 #include <bits/wordsize.h>
34
35 struct ust_marker;
36
37 /**
38 * ust_marker_probe_func - Type of a marker probe function
39 * @mdata: marker data
40 * @probe_private: probe private data
41 * @call_private: call site private data
42 * @fmt: format string
43 * @args: variable argument list pointer. Use a pointer to overcome C's
44 * inability to pass this around as a pointer in a portable manner in
45 * the callee otherwise.
46 *
47 * Type of marker probe functions. They receive the mdata and need to parse the
48 * format string to recover the variable argument list.
49 */
50 typedef void ust_marker_probe_func(const struct ust_marker *mdata,
51 void *probe_private, void *call_private,
52 const char *fmt, va_list *args);
53
54 struct ust_marker_probe_closure {
55 ust_marker_probe_func *func; /* Callback */
56 void *probe_private; /* Private probe data */
57 };
58
59 struct ust_marker {
60 const char *channel; /* Name of channel where to send data */
61 const char *name; /* Marker name */
62 const char *format; /* Marker format string, describing the
63 * variable argument list.
64 */
65 char state; /* State. */
66 char ptype; /* probe type : 0 : single, 1 : multi */
67 /* Probe wrapper */
68 u16 channel_id; /* Numeric channel identifier, dynamic */
69 u16 event_id; /* Numeric event identifier, dynamic */
70 void (*call)(const struct ust_marker *mdata, void *call_private, ...);
71 struct ust_marker_probe_closure single;
72 struct ust_marker_probe_closure *multi;
73 const char *tp_name; /* Optional tracepoint name */
74 void *tp_cb; /* Optional tracepoint callback */
75 };
76
77 #define GET_UST_MARKER(name) (__ust_marker_def_##name)
78
79 /*
80 * We keep the "channel" as internal field for marker.c *only*. It will be
81 * removed soon.
82 */
83
84 /*
85 * __ust_marker_ptrs section is not const (read-only) because it needs to be
86 * read-write to let the linker apply relocations and keep the object PIC.
87 */
88 #define _DEFINE_UST_MARKER(channel, name, tp_name_str, tp_cb, format) \
89 static const char __mstrtab_##channel##_##name[] \
90 __attribute__((section("__ust_markers_strings"))) \
91 = #channel "\0" #name "\0" format; \
92 static struct ust_marker __ust_marker_def_##name \
93 __attribute__((section("__ust_markers"))) = \
94 { __mstrtab_##channel##_##name, \
95 &__mstrtab_##channel##_##name[sizeof(#channel)], \
96 &__mstrtab_##channel##_##name[sizeof(#channel) + \
97 sizeof(#name)], \
98 0, 0, 0, 0, ust_marker_probe_cb, \
99 { __ust_marker_empty_function, NULL}, \
100 NULL, tp_name_str, tp_cb }; \
101 static struct ust_marker * __ust_marker_ptr_##name \
102 __attribute__((used, section("__ust_marker_ptrs"))) = \
103 &__ust_marker_def_##name
104
105 #define DEFINE_UST_MARKER(name, format) \
106 _DEFINE_UST_MARKER(ust, name, NULL, NULL, format)
107
108 #define DEFINE_UST_MARKER_TP(name, tp_name, tp_cb, format) \
109 _DEFINE_UST_MARKER(ust, name, #tp_name, tp_cb, format)
110
111 /*
112 * Make sure the alignment of the structure in the __ust_marker section will
113 * not add unwanted padding between the beginning of the section and the
114 * structure. Force alignment to the same alignment as the section start.
115 */
116
117 #define __ust_marker(channel, name, call_private, format, args...) \
118 do { \
119 _DEFINE_UST_MARKER(channel, name, NULL, NULL, format); \
120 __ust_marker_check_format(format, ## args); \
121 if (unlikely(__ust_marker_def_##name.state)) \
122 (__ust_marker_def_##name.call) \
123 (&__ust_marker_def_##name, call_private,\
124 ## args); \
125 } while (0)
126
127 #define __ust_marker_tp(name, call_private, tp_name, tp_cb, \
128 format, args...) \
129 do { \
130 void __check_tp_type(void) \
131 { \
132 register_trace_##tp_name(tp_cb, call_private); \
133 } \
134 DEFINE_UST_MARKER_TP(name, #tp_name, tp_cb, format); \
135 __ust_marker_check_format(format, ## args); \
136 (*__ust_marker_def_##name.call) \
137 (&__ust_marker_def_##name, call_private, ## args); \
138 } while (0)
139
140 extern void ust_marker_update_probe_range(struct ust_marker * const *begin,
141 struct ust_marker * const *end);
142
143 /**
144 * ust_marker - Marker using code patching
145 * @name: marker name, not quoted.
146 * @format: format string
147 * @args...: variable argument list
148 *
149 * Places a marker at caller site.
150 */
151 #define ust_marker(name, format, args...) \
152 __ust_marker(ust, name, NULL, format, ## args)
153
154 static inline __attribute__((deprecated))
155 void __trace_mark_is_deprecated()
156 {
157 }
158
159 /**
160 * ust_marker_tp - Marker in a tracepoint callback
161 * @name: marker name, not quoted.
162 * @tp_name: tracepoint name, not quoted.
163 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
164 * is not optimized away by the compiler (should not be static).
165 * @format: format string
166 * @args...: variable argument list
167 *
168 * Places a marker in a tracepoint callback.
169 */
170 #define ust_marker_tp(name, tp_name, tp_cb, format, args...) \
171 __ust_marker_tp(ust, name, NULL, tp_name, tp_cb, format, ## args)
172
173 /**
174 * UST_MARKER_NOARGS - Format string for a marker with no argument.
175 */
176 #define UST_MARKER_NOARGS " "
177
178 extern void lock_ust_marker(void);
179 extern void unlock_ust_marker(void);
180
181 extern void ust_marker_compact_event_ids(void);
182
183 /* To be used for string format validity checking with gcc */
184 static inline void __printf(1, 2) ___ust_marker_check_format(const char *fmt, ...)
185 {
186 }
187
188 #define __ust_marker_check_format(format, args...) \
189 do { \
190 if (0) \
191 ___ust_marker_check_format(format, ## args); \
192 } while (0)
193
194 extern ust_marker_probe_func __ust_marker_empty_function;
195
196 extern void ust_marker_probe_cb(const struct ust_marker *mdata,
197 void *call_private, ...);
198
199 /*
200 * Connect a probe to a marker.
201 * private data pointer must be a valid allocated memory address, or NULL.
202 */
203 extern int ust_marker_probe_register(const char *channel, const char *name,
204 const char *format, ust_marker_probe_func *probe, void *probe_private);
205
206 /*
207 * Returns the private data given to ust_marker_probe_register.
208 */
209 extern int ust_marker_probe_unregister(const char *channel, const char *name,
210 ust_marker_probe_func *probe, void *probe_private);
211 /*
212 * Unregister a marker by providing the registered private data.
213 */
214 extern int ust_marker_probe_unregister_private_data(ust_marker_probe_func *probe,
215 void *probe_private);
216
217 extern void *ust_marker_get_private_data(const char *channel, const char *name,
218 ust_marker_probe_func *probe, int num);
219
220 /*
221 * ust_marker_synchronize_unregister must be called between the last marker probe
222 * unregistration and the first one of
223 * - the end of module exit function
224 * - the free of any resource used by the probes
225 * to ensure the code and data are valid for any possibly running probes.
226 */
227 #define ust_marker_synchronize_unregister() synchronize_sched()
228
229 struct ust_marker_iter {
230 //ust// struct module *module;
231 struct ust_marker_lib *lib;
232 struct ust_marker * const *ust_marker;
233 };
234
235 extern void ust_marker_iter_start(struct ust_marker_iter *iter);
236 extern void ust_marker_iter_next(struct ust_marker_iter *iter);
237 extern void ust_marker_iter_stop(struct ust_marker_iter *iter);
238 extern void ust_marker_iter_reset(struct ust_marker_iter *iter);
239 extern int ust_marker_get_iter_range(struct ust_marker * const **marker, struct ust_marker * const *begin,
240 struct ust_marker * const *end);
241
242 extern void ust_marker_update_process(void);
243 extern int is_ust_marker_enabled(const char *channel, const char *name);
244
245 //ust// #ifdef CONFIG_UST_MARKER_USERSPACE
246 //ust// extern void exit_user_ust_marker(struct task_struct *p);
247 //ust// #else
248 //ust// static inline void exit_user_ust_marker(struct task_struct *p)
249 //ust// {
250 //ust// }
251 //ust// #endif
252
253 struct ust_marker_addr {
254 struct ust_marker *marker;
255 void *addr;
256 };
257
258 struct ust_marker_lib {
259 struct ust_marker * const *ust_marker_start;
260 int ust_marker_count;
261 struct cds_list_head list;
262 };
263
264 extern int ust_marker_register_lib(struct ust_marker * const *ust_marker_start, int ust_marker_count);
265 extern int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start);
266
267 #define UST_MARKER_LIB \
268 extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
269 extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
270 static struct ust_marker * __ust_marker_ptr_dummy \
271 __attribute__((used, section("__ust_marker_ptrs"))); \
272 \
273 static void __attribute__((constructor)) __ust_marker__init(void) \
274 { \
275 ust_marker_register_lib(__start___ust_marker_ptrs, \
276 __stop___ust_marker_ptrs \
277 - __start___ust_marker_ptrs); \
278 } \
279 \
280 static void __attribute__((destructor)) __ust_marker__destroy(void)\
281 { \
282 ust_marker_unregister_lib(__start___ust_marker_ptrs); \
283 }
284
285 extern void ust_marker_set_new_ust_marker_cb(void (*cb)(struct ust_marker *));
286 extern void init_ust_marker(void);
287
288 /*
289 * trace_mark() -- TO BE DEPRECATED
290 * @channel: name prefix, not quoted. Ignored.
291 * @name: marker name, not quoted.
292 * @format: format string
293 * @args...: variable argument list
294 *
295 * Kept as a compatibility API and will be *DEPRECATED* in favor of
296 * ust_marker().
297 */
298 #define trace_mark(channel, name, format, args...) \
299 __trace_mark_is_deprecated(); \
300 ust_marker(name, format, ## args)
301
302 static inline __attribute__((deprecated))
303 void __MARKER_LIB_IS_DEPRECATED()
304 {
305 }
306
307 /*
308 * MARKER_LIB is kept for backward compatibility and will be
309 * *DEPRECATED*. Use UST_MARKER_LIB instead.
310 */
311 #define MARKER_LIB \
312 __MARKER_LIB_IS_DEPRECATED(); \
313 UST_MARKER_LIB
314
315 /**
316 * MARKER_NOARGS - Compatibility API. Will be *DEPRECATED*. Use
317 * UST_MARKER_NOARGS instead.
318 */
319 #define MARK_NOARGS UST_MARKER_NOARGS
320
321 #endif /* _UST_MARKER_H */
This page took 0.034478 seconds and 3 git commands to generate.