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 | |
f37142a4 MD |
11 | * License as published by the Free Software Foundation; |
12 | * version 2.1 of the License. | |
8fc2d8db PMF |
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 | ||
2288bf6d PMF |
24 | #ifndef _UST_MARKER_H |
25 | #define _UST_MARKER_H | |
e4621c7f | 26 | |
a72ca31a | 27 | #include <stdarg.h> |
518d7abb | 28 | #include <ust/core.h> |
22d9080d | 29 | #include <urcu/list.h> |
2782fc4b | 30 | #include <ust/processor.h> |
518d7abb | 31 | #include <ust/kcompat/kcompat.h> |
7b2c5007 | 32 | #include <ust/kcompat/stringify.h> |
59b161cd | 33 | |
9389f19d PMF |
34 | #include <bits/wordsize.h> |
35 | ||
b521931e | 36 | struct ust_marker; |
a72ca31a PMF |
37 | |
38 | /** | |
b521931e | 39 | * ust_marker_probe_func - Type of a marker probe function |
a72ca31a PMF |
40 | * @mdata: marker data |
41 | * @probe_private: probe private data | |
42 | * @call_private: call site private data | |
43 | * @fmt: format string | |
44 | * @args: variable argument list pointer. Use a pointer to overcome C's | |
45 | * inability to pass this around as a pointer in a portable manner in | |
46 | * the callee otherwise. | |
47 | * | |
48 | * Type of marker probe functions. They receive the mdata and need to parse the | |
49 | * format string to recover the variable argument list. | |
50 | */ | |
b521931e | 51 | typedef void ust_marker_probe_func(const struct ust_marker *mdata, |
75667d04 | 52 | void *probe_private, struct registers *regs, void *call_private, |
a72ca31a PMF |
53 | const char *fmt, va_list *args); |
54 | ||
b521931e MD |
55 | struct ust_marker_probe_closure { |
56 | ust_marker_probe_func *func; /* Callback */ | |
a72ca31a PMF |
57 | void *probe_private; /* Private probe data */ |
58 | }; | |
59 | ||
b521931e | 60 | struct ust_marker { |
a72ca31a PMF |
61 | const char *channel; /* Name of channel where to send data */ |
62 | const char *name; /* Marker name */ | |
63 | const char *format; /* Marker format string, describing the | |
64 | * variable argument list. | |
65 | */ | |
f36c12ab | 66 | char state; /* State. */ |
a72ca31a PMF |
67 | char ptype; /* probe type : 0 : single, 1 : multi */ |
68 | /* Probe wrapper */ | |
69 | u16 channel_id; /* Numeric channel identifier, dynamic */ | |
70 | u16 event_id; /* Numeric event identifier, dynamic */ | |
b521931e MD |
71 | void (*call)(const struct ust_marker *mdata, void *call_private, struct registers *regs, ...); |
72 | struct ust_marker_probe_closure single; | |
73 | struct ust_marker_probe_closure *multi; | |
a72ca31a PMF |
74 | const char *tp_name; /* Optional tracepoint name */ |
75 | void *tp_cb; /* Optional tracepoint callback */ | |
3ea1e2fc | 76 | void *location; /* Address of marker in code */ |
eb5d20c6 | 77 | }; |
a72ca31a | 78 | |
b521931e | 79 | #define GET_UST_MARKER(name) (__ust_marker_ust_##name) |
7b2c5007 | 80 | |
b521931e MD |
81 | #define _DEFINE_UST_MARKER(channel, name, tp_name_str, tp_cb, format, unique, m) \ |
82 | struct registers __ust_marker_regs; \ | |
bb9ade29 | 83 | \ |
a4db742a | 84 | /* This next asm has to be a basic inline asm (no input/output/clobber), \ |
9692fa18 PMF |
85 | * because it must not require %-sign escaping, as we most certainly \ |
86 | * have some %-signs in the format string. \ | |
87 | */ \ | |
f91aa730 DG |
88 | asm volatile ( \ |
89 | /* We only define these symbols if they have not yet been defined. Indeed, \ | |
90 | * if two markers with the same channel/name are on the same line, they \ | |
91 | * will try to create the same symbols, resulting in a conflict. This \ | |
92 | * is not unusual as it can be the result of function inlining. \ | |
93 | */ \ | |
94 | ".ifndef __mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) "\n\t" \ | |
b521931e MD |
95 | /*".section __ust_marker_strings\n\t"*/ \ |
96 | ".section __ust_marker_strings,\"aw\"\n\t" \ | |
f91aa730 DG |
97 | "__mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) ":\n\t" \ |
98 | ".string \"" __stringify(channel) "\"\n\t" \ | |
99 | "__mstrtab_" __stringify(channel) "_" __stringify(name) "_name_" __stringify(unique) ":\n\t" \ | |
100 | ".string \"" __stringify(name) "\"\n\t" \ | |
101 | "__mstrtab_" __stringify(channel) "_" __stringify(name) "_format_" __stringify(unique) ":\n\t" \ | |
102 | ".string " "\"" format "\"" "\n\t" \ | |
103 | ".previous\n\t" \ | |
104 | ".endif\n\t" \ | |
9692fa18 PMF |
105 | ); \ |
106 | asm volatile ( \ | |
b521931e MD |
107 | /*".section __ust_marker\n\t"*/ \ |
108 | ".section __ust_marker,\"aw\"\n\t" \ | |
f91aa730 DG |
109 | "2:\n\t" \ |
110 | _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) ")\n\t" /* channel string */ \ | |
111 | _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_name_" __stringify(unique) ")\n\t" /* name string */ \ | |
112 | _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_format_" __stringify(unique) ")\n\t" /* format string */ \ | |
113 | ".byte 0\n\t" /* state imv */ \ | |
114 | ".byte 0\n\t" /* ptype */ \ | |
34174843 MD |
115 | ".hword 0\n\t" /* channel_id */ \ |
116 | ".hword 0\n\t" /* event_id */ \ | |
f91aa730 | 117 | ".balign " __stringify(__WORDSIZE) " / 8\n\t" /* alignment */ \ |
b521931e MD |
118 | _ASM_PTR "(ust_marker_probe_cb)\n\t" /* call */ \ |
119 | _ASM_PTR "(__ust_marker_empty_function)\n\t" /* ust_marker_probe_closure single.field1 */ \ | |
120 | _ASM_PTR "0\n\t" /* ust_marker_probe_closure single.field2 */ \ | |
121 | _ASM_PTR "0\n\t" /* ust_marker_probe_closure *multi */ \ | |
f91aa730 DG |
122 | _ASM_PTR "0\n\t" /* tp_name */ \ |
123 | _ASM_PTR "0\n\t" /* tp_cb */ \ | |
124 | _ASM_PTR "(1f)\n\t" /* location */ \ | |
125 | ".previous\n\t" \ | |
b521931e | 126 | /*".section __ust_marker_ptrs\n\t"*/ \ |
7b2cd9b7 | 127 | ".section __ust_marker_ptrs,\"aw\"\n\t" \ |
eb5d20c6 MD |
128 | _ASM_PTR "(2b)\n\t" \ |
129 | ".previous\n\t" \ | |
130 | "1:\n\t" \ | |
f91aa730 | 131 | ARCH_COPY_ADDR("%[outptr]") \ |
9692fa18 | 132 | : [outptr] "=r" (m) ); \ |
bb9ade29 | 133 | \ |
b521931e | 134 | save_registers(&__ust_marker_regs) |
3ea1e2fc PMF |
135 | |
136 | ||
b521931e MD |
137 | #define DEFINE_UST_MARKER(name, format, unique, m) \ |
138 | _DEFINE_UST_MARKER(ust, name, NULL, NULL, format, unique, m) | |
a72ca31a | 139 | |
b521931e MD |
140 | #define DEFINE_UST_MARKER_TP(name, tp_name, tp_cb, format) \ |
141 | _DEFINE_UST_MARKER_TP(ust, name, #tp_name, tp_cb, format) | |
7166e240 | 142 | |
b521931e | 143 | #define _DEFINE_UST_MARKER_TP(channel, name, tp_name_str, tp_cb, format)\ |
7166e240 | 144 | static const char __mstrtab_##channel##_##name[] \ |
b521931e | 145 | __attribute__((section("__ust_marker_strings"))) \ |
7166e240 | 146 | = #channel "\0" #name "\0" format; \ |
b521931e MD |
147 | static struct ust_marker __ust_marker_##channel##_##name\ |
148 | __attribute__((section("__ust_marker"))) = \ | |
7166e240 | 149 | { __mstrtab_##channel##_##name, \ |
b521931e | 150 | &__mstrtab_##channel##_##name[sizeof(#channel)],\ |
f91aa730 | 151 | &__mstrtab_##channel##_##name[sizeof(#channel) + sizeof(#name)], \ |
b521931e MD |
152 | 0, 0, 0, 0, ust_marker_probe_cb, \ |
153 | { __ust_marker_empty_function, NULL}, \ | |
eb5d20c6 | 154 | NULL, tp_name_str, tp_cb }; \ |
b521931e MD |
155 | static struct ust_marker * const __ust_marker_ptr_##channel##_##name \ |
156 | __attribute__((used, section("__ust_marker_ptrs"))) = \ | |
157 | &__ust_marker_##channel##_##name; | |
a72ca31a PMF |
158 | |
159 | /* | |
b521931e | 160 | * Make sure the alignment of the structure in the __ust_marker section will |
a72ca31a PMF |
161 | * not add unwanted padding between the beginning of the section and the |
162 | * structure. Force alignment to the same alignment as the section start. | |
a72ca31a | 163 | */ |
bb9ade29 | 164 | |
f36c12ab MD |
165 | #define __ust_marker(channel, name, call_private, format, args...) \ |
166 | __ust_marker_counter(channel, name, __LINE__, call_private, format, ## args) | |
bb9ade29 | 167 | |
f36c12ab | 168 | #define __ust_marker_counter(channel, name, unique, call_private, format, args...) \ |
a72ca31a | 169 | do { \ |
b521931e MD |
170 | struct ust_marker *__ust_marker_counter_ptr; \ |
171 | _DEFINE_UST_MARKER(channel, name, NULL, NULL, format, unique, __ust_marker_counter_ptr); \ | |
172 | __ust_marker_check_format(format, ## args); \ | |
f36c12ab MD |
173 | if (unlikely(__ust_marker_counter_ptr->state)) \ |
174 | (__ust_marker_counter_ptr->call)(__ust_marker_counter_ptr, call_private, &__ust_marker_regs, ## args); \ | |
a72ca31a PMF |
175 | } while (0) |
176 | ||
686debc3 MD |
177 | #define __ust_marker_tp(channel, name, call_private, tp_name, tp_cb, format, args...) \ |
178 | __ust_marker_tp_counter(channel, name, __LINE__, call_private, tp_name, tp_cb, format, ## args) | |
bb9ade29 | 179 | |
686debc3 | 180 | #define __ust_marker_tp_counter(channel, name, unique, call_private, tp_name, tp_cb, format, args...) \ |
a72ca31a | 181 | do { \ |
b521931e | 182 | struct registers __ust_marker_regs; \ |
a72ca31a PMF |
183 | void __check_tp_type(void) \ |
184 | { \ | |
245d371e | 185 | register_trace_##tp_name(tp_cb, call_private); \ |
a72ca31a | 186 | } \ |
b521931e MD |
187 | _DEFINE_UST_MARKER_TP(channel, name, #tp_name, tp_cb, format); \ |
188 | __ust_marker_check_format(format, ## args); \ | |
189 | (*__ust_marker_##channel##_##name.call)(&__ust_marker_##channel##_##name, \ | |
190 | call_private, &__ust_marker_regs, ## args); \ | |
a72ca31a PMF |
191 | } while (0) |
192 | ||
b521931e MD |
193 | extern void ust_marker_update_probe_range(struct ust_marker * const *begin, |
194 | struct ust_marker * const *end); | |
a72ca31a | 195 | |
a72ca31a | 196 | /** |
686debc3 | 197 | * ust_marker - Marker using code patching |
a72ca31a PMF |
198 | * @name: marker name, not quoted. |
199 | * @format: format string | |
200 | * @args...: variable argument list | |
201 | * | |
f36c12ab | 202 | * Places a marker at caller site. |
a72ca31a | 203 | */ |
686debc3 | 204 | #define ust_marker(name, format, args...) \ |
f36c12ab | 205 | __ust_marker(ust, name, NULL, format, ## args) |
a72ca31a PMF |
206 | |
207 | /** | |
686debc3 | 208 | * ust_marker_tp - Marker in a tracepoint callback |
a72ca31a PMF |
209 | * @name: marker name, not quoted. |
210 | * @tp_name: tracepoint name, not quoted. | |
211 | * @tp_cb: tracepoint callback. Should have an associated global symbol so it | |
212 | * is not optimized away by the compiler (should not be static). | |
213 | * @format: format string | |
214 | * @args...: variable argument list | |
215 | * | |
216 | * Places a marker in a tracepoint callback. | |
217 | */ | |
686debc3 MD |
218 | #define ust_marker_tp(name, tp_name, tp_cb, format, args...) \ |
219 | __ust_marker_tp(ust, name, NULL, tp_name, tp_cb, format, ## args) | |
a72ca31a PMF |
220 | |
221 | /** | |
b521931e | 222 | * UST_MARKER_NOARGS - Format string for a marker with no argument. |
a72ca31a | 223 | */ |
b521931e | 224 | #define UST_MARKER_NOARGS " " |
a72ca31a | 225 | |
b521931e MD |
226 | extern void lock_ust_marker(void); |
227 | extern void unlock_ust_marker(void); | |
a72ca31a | 228 | |
b521931e | 229 | extern void ust_marker_compact_event_ids(void); |
a72ca31a PMF |
230 | |
231 | /* To be used for string format validity checking with gcc */ | |
b521931e | 232 | static inline void __printf(1, 2) ___ust_marker_check_format(const char *fmt, ...) |
a72ca31a PMF |
233 | { |
234 | } | |
235 | ||
b521931e | 236 | #define __ust_marker_check_format(format, args...) \ |
a72ca31a PMF |
237 | do { \ |
238 | if (0) \ | |
b521931e | 239 | ___ust_marker_check_format(format, ## args); \ |
a72ca31a PMF |
240 | } while (0) |
241 | ||
b521931e | 242 | extern ust_marker_probe_func __ust_marker_empty_function; |
a72ca31a | 243 | |
b521931e | 244 | extern void ust_marker_probe_cb(const struct ust_marker *mdata, |
75667d04 | 245 | void *call_private, struct registers *regs, ...); |
a72ca31a PMF |
246 | |
247 | /* | |
248 | * Connect a probe to a marker. | |
249 | * private data pointer must be a valid allocated memory address, or NULL. | |
250 | */ | |
b521931e MD |
251 | extern int ust_marker_probe_register(const char *channel, const char *name, |
252 | const char *format, ust_marker_probe_func *probe, void *probe_private); | |
a72ca31a PMF |
253 | |
254 | /* | |
b521931e | 255 | * Returns the private data given to ust_marker_probe_register. |
a72ca31a | 256 | */ |
b521931e MD |
257 | extern int ust_marker_probe_unregister(const char *channel, const char *name, |
258 | ust_marker_probe_func *probe, void *probe_private); | |
a72ca31a PMF |
259 | /* |
260 | * Unregister a marker by providing the registered private data. | |
261 | */ | |
b521931e | 262 | extern int ust_marker_probe_unregister_private_data(ust_marker_probe_func *probe, |
a72ca31a PMF |
263 | void *probe_private); |
264 | ||
b521931e MD |
265 | extern void *ust_marker_get_private_data(const char *channel, const char *name, |
266 | ust_marker_probe_func *probe, int num); | |
a72ca31a PMF |
267 | |
268 | /* | |
b521931e | 269 | * ust_marker_synchronize_unregister must be called between the last marker probe |
a72ca31a PMF |
270 | * unregistration and the first one of |
271 | * - the end of module exit function | |
272 | * - the free of any resource used by the probes | |
273 | * to ensure the code and data are valid for any possibly running probes. | |
274 | */ | |
b521931e | 275 | #define ust_marker_synchronize_unregister() synchronize_sched() |
a72ca31a | 276 | |
b521931e | 277 | struct ust_marker_iter { |
98963de4 | 278 | //ust// struct module *module; |
b521931e MD |
279 | struct ust_marker_lib *lib; |
280 | struct ust_marker * const *ust_marker; | |
a72ca31a PMF |
281 | }; |
282 | ||
b521931e MD |
283 | extern void ust_marker_iter_start(struct ust_marker_iter *iter); |
284 | extern void ust_marker_iter_next(struct ust_marker_iter *iter); | |
285 | extern void ust_marker_iter_stop(struct ust_marker_iter *iter); | |
286 | extern void ust_marker_iter_reset(struct ust_marker_iter *iter); | |
287 | extern int ust_marker_get_iter_range(struct ust_marker * const **marker, struct ust_marker * const *begin, | |
288 | struct ust_marker * const *end); | |
a72ca31a | 289 | |
b521931e MD |
290 | extern void ust_marker_update_process(void); |
291 | extern int is_ust_marker_enabled(const char *channel, const char *name); | |
a72ca31a | 292 | |
b521931e MD |
293 | //ust// #ifdef CONFIG_UST_MARKER_USERSPACE |
294 | //ust// extern void exit_user_ust_marker(struct task_struct *p); | |
59b161cd | 295 | //ust// #else |
b521931e | 296 | //ust// static inline void exit_user_ust_marker(struct task_struct *p) |
59b161cd PMF |
297 | //ust// { |
298 | //ust// } | |
299 | //ust// #endif | |
a72ca31a | 300 | |
b521931e MD |
301 | struct ust_marker_addr { |
302 | struct ust_marker *marker; | |
3ea1e2fc PMF |
303 | void *addr; |
304 | }; | |
98963de4 | 305 | |
b521931e MD |
306 | struct ust_marker_lib { |
307 | struct ust_marker * const *ust_marker_start; | |
defa46a7 | 308 | #ifdef CONFIG_UST_GDB_INTEGRATION |
b521931e | 309 | struct ust_marker_addr *ust_marker_addr_start; |
defa46a7 | 310 | #endif |
b521931e | 311 | int ust_marker_count; |
0222e121 | 312 | struct cds_list_head list; |
98963de4 PMF |
313 | }; |
314 | ||
b521931e MD |
315 | extern int ust_marker_register_lib(struct ust_marker * const *ust_marker_start, int ust_marker_count); |
316 | extern int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start); | |
defa46a7 | 317 | |
b521931e MD |
318 | #define UST_MARKER_LIB \ |
319 | extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
320 | extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
321 | static struct ust_marker * const __ust_marker_ptr_dummy \ | |
322 | __attribute__((used, section("__ust_marker_ptrs"))) = NULL;\ | |
55994a67 | 323 | \ |
b521931e | 324 | static void __attribute__((constructor)) __ust_marker__init(void) \ |
55994a67 | 325 | { \ |
b521931e MD |
326 | ust_marker_register_lib(__start___ust_marker_ptrs, \ |
327 | __stop___ust_marker_ptrs \ | |
328 | - __start___ust_marker_ptrs); \ | |
900e307e MD |
329 | } \ |
330 | \ | |
b521931e | 331 | static void __attribute__((destructor)) __ust_marker__destroy(void)\ |
24b6668c | 332 | { \ |
b521931e | 333 | ust_marker_unregister_lib(__start___ust_marker_ptrs); \ |
55994a67 | 334 | } |
98963de4 | 335 | |
b521931e MD |
336 | extern void ust_marker_set_new_ust_marker_cb(void (*cb)(struct ust_marker *)); |
337 | extern void init_ust_marker(void); | |
9160b4e4 | 338 | |
defa46a7 | 339 | #endif /* _UST_MARKER_H */ |