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> |
fe566790 | 8 | * (C) Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
a72ca31a | 9 | * |
8fc2d8db PMF |
10 | * This library is free software; you can redistribute it and/or |
11 | * modify it under the terms of the GNU Lesser General Public | |
f37142a4 MD |
12 | * License as published by the Free Software Foundation; |
13 | * version 2.1 of the License. | |
8fc2d8db PMF |
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 | |
a72ca31a PMF |
23 | */ |
24 | ||
2288bf6d PMF |
25 | #ifndef _UST_MARKER_H |
26 | #define _UST_MARKER_H | |
e4621c7f | 27 | |
a72ca31a | 28 | #include <stdarg.h> |
518d7abb | 29 | #include <ust/core.h> |
22d9080d | 30 | #include <urcu/list.h> |
518d7abb | 31 | #include <ust/kcompat/kcompat.h> |
59b161cd | 32 | |
9389f19d PMF |
33 | #include <bits/wordsize.h> |
34 | ||
b521931e | 35 | struct ust_marker; |
a72ca31a PMF |
36 | |
37 | /** | |
b521931e | 38 | * ust_marker_probe_func - Type of a marker probe function |
a72ca31a PMF |
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 | */ | |
b521931e | 50 | typedef void ust_marker_probe_func(const struct ust_marker *mdata, |
fe566790 | 51 | void *probe_private, void *call_private, |
a72ca31a PMF |
52 | const char *fmt, va_list *args); |
53 | ||
b521931e MD |
54 | struct ust_marker_probe_closure { |
55 | ust_marker_probe_func *func; /* Callback */ | |
a72ca31a PMF |
56 | void *probe_private; /* Private probe data */ |
57 | }; | |
58 | ||
b521931e | 59 | struct ust_marker { |
a72ca31a PMF |
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 | */ | |
f36c12ab | 65 | char state; /* State. */ |
a72ca31a PMF |
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 */ | |
fe566790 | 70 | void (*call)(const struct ust_marker *mdata, void *call_private, ...); |
b521931e MD |
71 | struct ust_marker_probe_closure single; |
72 | struct ust_marker_probe_closure *multi; | |
a72ca31a PMF |
73 | const char *tp_name; /* Optional tracepoint name */ |
74 | void *tp_cb; /* Optional tracepoint callback */ | |
eb5d20c6 | 75 | }; |
a72ca31a | 76 | |
fe566790 | 77 | #define GET_UST_MARKER(name) (__ust_marker_def_##name) |
a72ca31a | 78 | |
fe566790 MD |
79 | /* |
80 | * We keep the "channel" as internal field for marker.c *only*. It will be | |
81 | * removed soon. | |
82 | */ | |
7166e240 | 83 | |
fe566790 MD |
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) \ | |
7166e240 | 89 | static const char __mstrtab_##channel##_##name[] \ |
fe566790 | 90 | __attribute__((section("__ust_markers_strings"))) \ |
7166e240 | 91 | = #channel "\0" #name "\0" format; \ |
fe566790 MD |
92 | static struct ust_marker __ust_marker_def_##name \ |
93 | __attribute__((section("__ust_markers"))) = \ | |
7166e240 | 94 | { __mstrtab_##channel##_##name, \ |
fe566790 MD |
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 \ | |
b521931e | 102 | __attribute__((used, section("__ust_marker_ptrs"))) = \ |
fe566790 MD |
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) | |
a72ca31a PMF |
110 | |
111 | /* | |
b521931e | 112 | * Make sure the alignment of the structure in the __ust_marker section will |
a72ca31a PMF |
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. | |
a72ca31a | 115 | */ |
bb9ade29 | 116 | |
fe566790 | 117 | #define __ust_marker(channel, name, call_private, format, args...) \ |
a72ca31a | 118 | do { \ |
fe566790 | 119 | _DEFINE_UST_MARKER(channel, name, NULL, NULL, format); \ |
b521931e | 120 | __ust_marker_check_format(format, ## args); \ |
fe566790 MD |
121 | if (unlikely(__ust_marker_def_##name.state)) \ |
122 | (__ust_marker_def_##name.call) \ | |
123 | (&__ust_marker_def_##name, call_private,\ | |
124 | ## args); \ | |
a72ca31a PMF |
125 | } while (0) |
126 | ||
fe566790 MD |
127 | #define __ust_marker_tp(name, call_private, tp_name, tp_cb, \ |
128 | format, args...) \ | |
a72ca31a PMF |
129 | do { \ |
130 | void __check_tp_type(void) \ | |
131 | { \ | |
fe566790 | 132 | register_trace_##tp_name(tp_cb, call_private); \ |
a72ca31a | 133 | } \ |
fe566790 | 134 | DEFINE_UST_MARKER_TP(name, #tp_name, tp_cb, format); \ |
b521931e | 135 | __ust_marker_check_format(format, ## args); \ |
fe566790 MD |
136 | (*__ust_marker_def_##name.call) \ |
137 | (&__ust_marker_def_##name, call_private, ## args); \ | |
a72ca31a PMF |
138 | } while (0) |
139 | ||
b521931e MD |
140 | extern void ust_marker_update_probe_range(struct ust_marker * const *begin, |
141 | struct ust_marker * const *end); | |
a72ca31a | 142 | |
a72ca31a | 143 | /** |
686debc3 | 144 | * ust_marker - Marker using code patching |
a72ca31a PMF |
145 | * @name: marker name, not quoted. |
146 | * @format: format string | |
147 | * @args...: variable argument list | |
148 | * | |
f36c12ab | 149 | * Places a marker at caller site. |
a72ca31a | 150 | */ |
686debc3 | 151 | #define ust_marker(name, format, args...) \ |
f36c12ab | 152 | __ust_marker(ust, name, NULL, format, ## args) |
a72ca31a | 153 | |
5389de4d MD |
154 | |
155 | /* | |
156 | * trace_mark() -- TO BE DEPRECATED | |
157 | * @channel: name prefix, not quoted. Ignored. | |
158 | * @name: marker name, not quoted. | |
159 | * @format: format string | |
160 | * @args...: variable argument list | |
161 | * | |
162 | * Kept as a compatibility API and will be *DEPRECATED* in favor of | |
163 | * ust_marker(). | |
164 | */ | |
165 | #define trace_mark(channel, name, format, args...) \ | |
5dac4513 | 166 | ust_marker(name, format, ## args) |
5389de4d | 167 | |
a72ca31a | 168 | /** |
686debc3 | 169 | * ust_marker_tp - Marker in a tracepoint callback |
a72ca31a PMF |
170 | * @name: marker name, not quoted. |
171 | * @tp_name: tracepoint name, not quoted. | |
172 | * @tp_cb: tracepoint callback. Should have an associated global symbol so it | |
173 | * is not optimized away by the compiler (should not be static). | |
174 | * @format: format string | |
175 | * @args...: variable argument list | |
176 | * | |
177 | * Places a marker in a tracepoint callback. | |
178 | */ | |
686debc3 MD |
179 | #define ust_marker_tp(name, tp_name, tp_cb, format, args...) \ |
180 | __ust_marker_tp(ust, name, NULL, tp_name, tp_cb, format, ## args) | |
a72ca31a PMF |
181 | |
182 | /** | |
b521931e | 183 | * UST_MARKER_NOARGS - Format string for a marker with no argument. |
a72ca31a | 184 | */ |
b521931e | 185 | #define UST_MARKER_NOARGS " " |
a72ca31a | 186 | |
1790c2fe MD |
187 | /** |
188 | * MARKER_NOARGS - Compatibility API. Will be *DEPRECATED*. Use | |
189 | * UST_MARKER_NOARGS instead. | |
190 | */ | |
191 | #define MARK_NOARGS UST_MARKER_NOARGS | |
192 | ||
b521931e MD |
193 | extern void lock_ust_marker(void); |
194 | extern void unlock_ust_marker(void); | |
a72ca31a | 195 | |
b521931e | 196 | extern void ust_marker_compact_event_ids(void); |
a72ca31a PMF |
197 | |
198 | /* To be used for string format validity checking with gcc */ | |
b521931e | 199 | static inline void __printf(1, 2) ___ust_marker_check_format(const char *fmt, ...) |
a72ca31a PMF |
200 | { |
201 | } | |
202 | ||
b521931e | 203 | #define __ust_marker_check_format(format, args...) \ |
a72ca31a PMF |
204 | do { \ |
205 | if (0) \ | |
b521931e | 206 | ___ust_marker_check_format(format, ## args); \ |
a72ca31a PMF |
207 | } while (0) |
208 | ||
b521931e | 209 | extern ust_marker_probe_func __ust_marker_empty_function; |
a72ca31a | 210 | |
b521931e | 211 | extern void ust_marker_probe_cb(const struct ust_marker *mdata, |
fe566790 | 212 | void *call_private, ...); |
a72ca31a PMF |
213 | |
214 | /* | |
215 | * Connect a probe to a marker. | |
216 | * private data pointer must be a valid allocated memory address, or NULL. | |
217 | */ | |
b521931e MD |
218 | extern int ust_marker_probe_register(const char *channel, const char *name, |
219 | const char *format, ust_marker_probe_func *probe, void *probe_private); | |
a72ca31a PMF |
220 | |
221 | /* | |
b521931e | 222 | * Returns the private data given to ust_marker_probe_register. |
a72ca31a | 223 | */ |
b521931e MD |
224 | extern int ust_marker_probe_unregister(const char *channel, const char *name, |
225 | ust_marker_probe_func *probe, void *probe_private); | |
a72ca31a PMF |
226 | /* |
227 | * Unregister a marker by providing the registered private data. | |
228 | */ | |
b521931e | 229 | extern int ust_marker_probe_unregister_private_data(ust_marker_probe_func *probe, |
a72ca31a PMF |
230 | void *probe_private); |
231 | ||
b521931e MD |
232 | extern void *ust_marker_get_private_data(const char *channel, const char *name, |
233 | ust_marker_probe_func *probe, int num); | |
a72ca31a PMF |
234 | |
235 | /* | |
b521931e | 236 | * ust_marker_synchronize_unregister must be called between the last marker probe |
a72ca31a PMF |
237 | * unregistration and the first one of |
238 | * - the end of module exit function | |
239 | * - the free of any resource used by the probes | |
240 | * to ensure the code and data are valid for any possibly running probes. | |
241 | */ | |
b521931e | 242 | #define ust_marker_synchronize_unregister() synchronize_sched() |
a72ca31a | 243 | |
b521931e | 244 | struct ust_marker_iter { |
98963de4 | 245 | //ust// struct module *module; |
b521931e MD |
246 | struct ust_marker_lib *lib; |
247 | struct ust_marker * const *ust_marker; | |
a72ca31a PMF |
248 | }; |
249 | ||
b521931e MD |
250 | extern void ust_marker_iter_start(struct ust_marker_iter *iter); |
251 | extern void ust_marker_iter_next(struct ust_marker_iter *iter); | |
252 | extern void ust_marker_iter_stop(struct ust_marker_iter *iter); | |
253 | extern void ust_marker_iter_reset(struct ust_marker_iter *iter); | |
254 | extern int ust_marker_get_iter_range(struct ust_marker * const **marker, struct ust_marker * const *begin, | |
255 | struct ust_marker * const *end); | |
a72ca31a | 256 | |
b521931e MD |
257 | extern void ust_marker_update_process(void); |
258 | extern int is_ust_marker_enabled(const char *channel, const char *name); | |
a72ca31a | 259 | |
b521931e MD |
260 | //ust// #ifdef CONFIG_UST_MARKER_USERSPACE |
261 | //ust// extern void exit_user_ust_marker(struct task_struct *p); | |
59b161cd | 262 | //ust// #else |
b521931e | 263 | //ust// static inline void exit_user_ust_marker(struct task_struct *p) |
59b161cd PMF |
264 | //ust// { |
265 | //ust// } | |
266 | //ust// #endif | |
a72ca31a | 267 | |
b521931e MD |
268 | struct ust_marker_addr { |
269 | struct ust_marker *marker; | |
3ea1e2fc PMF |
270 | void *addr; |
271 | }; | |
98963de4 | 272 | |
b521931e MD |
273 | struct ust_marker_lib { |
274 | struct ust_marker * const *ust_marker_start; | |
b521931e | 275 | int ust_marker_count; |
0222e121 | 276 | struct cds_list_head list; |
98963de4 PMF |
277 | }; |
278 | ||
b521931e MD |
279 | extern int ust_marker_register_lib(struct ust_marker * const *ust_marker_start, int ust_marker_count); |
280 | extern int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start); | |
defa46a7 | 281 | |
b521931e MD |
282 | #define UST_MARKER_LIB \ |
283 | extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
284 | extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
fe566790 MD |
285 | static struct ust_marker * __ust_marker_ptr_dummy \ |
286 | __attribute__((used, section("__ust_marker_ptrs"))); \ | |
55994a67 | 287 | \ |
b521931e | 288 | static void __attribute__((constructor)) __ust_marker__init(void) \ |
55994a67 | 289 | { \ |
b521931e MD |
290 | ust_marker_register_lib(__start___ust_marker_ptrs, \ |
291 | __stop___ust_marker_ptrs \ | |
292 | - __start___ust_marker_ptrs); \ | |
900e307e MD |
293 | } \ |
294 | \ | |
b521931e | 295 | static void __attribute__((destructor)) __ust_marker__destroy(void)\ |
24b6668c | 296 | { \ |
b521931e | 297 | ust_marker_unregister_lib(__start___ust_marker_ptrs); \ |
55994a67 | 298 | } |
98963de4 | 299 | |
7a05c99d MD |
300 | /* |
301 | * MARKER_LIB is kept for backward compatibility and will be | |
302 | * *DEPRECATED*. Use UST_MARKER_LIB instead. | |
303 | */ | |
304 | #define MARKER_LIB UST_MARKER_LIB | |
305 | ||
b521931e MD |
306 | extern void ust_marker_set_new_ust_marker_cb(void (*cb)(struct ust_marker *)); |
307 | extern void init_ust_marker(void); | |
9160b4e4 | 308 | |
defa46a7 | 309 | #endif /* _UST_MARKER_H */ |