Markers: trace_mark should not pass "ust" to ust_mark
[ust.git] / include / ust / marker.h
CommitLineData
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 36struct 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 51typedef 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
55struct ust_marker_probe_closure {
56 ust_marker_probe_func *func; /* Callback */
a72ca31a
PMF
57 void *probe_private; /* Private probe data */
58};
59
b521931e 60struct 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
193extern 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 206
5389de4d
MD
207
208/*
209 * trace_mark() -- TO BE DEPRECATED
210 * @channel: name prefix, not quoted. Ignored.
211 * @name: marker name, not quoted.
212 * @format: format string
213 * @args...: variable argument list
214 *
215 * Kept as a compatibility API and will be *DEPRECATED* in favor of
216 * ust_marker().
217 */
218#define trace_mark(channel, name, format, args...) \
5dac4513 219 ust_marker(name, format, ## args)
5389de4d 220
a72ca31a 221/**
686debc3 222 * ust_marker_tp - Marker in a tracepoint callback
a72ca31a
PMF
223 * @name: marker name, not quoted.
224 * @tp_name: tracepoint name, not quoted.
225 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
226 * is not optimized away by the compiler (should not be static).
227 * @format: format string
228 * @args...: variable argument list
229 *
230 * Places a marker in a tracepoint callback.
231 */
686debc3
MD
232#define ust_marker_tp(name, tp_name, tp_cb, format, args...) \
233 __ust_marker_tp(ust, name, NULL, tp_name, tp_cb, format, ## args)
a72ca31a
PMF
234
235/**
b521931e 236 * UST_MARKER_NOARGS - Format string for a marker with no argument.
a72ca31a 237 */
b521931e 238#define UST_MARKER_NOARGS " "
a72ca31a 239
1790c2fe
MD
240/**
241 * MARKER_NOARGS - Compatibility API. Will be *DEPRECATED*. Use
242 * UST_MARKER_NOARGS instead.
243 */
244#define MARK_NOARGS UST_MARKER_NOARGS
245
b521931e
MD
246extern void lock_ust_marker(void);
247extern void unlock_ust_marker(void);
a72ca31a 248
b521931e 249extern void ust_marker_compact_event_ids(void);
a72ca31a
PMF
250
251/* To be used for string format validity checking with gcc */
b521931e 252static inline void __printf(1, 2) ___ust_marker_check_format(const char *fmt, ...)
a72ca31a
PMF
253{
254}
255
b521931e 256#define __ust_marker_check_format(format, args...) \
a72ca31a
PMF
257 do { \
258 if (0) \
b521931e 259 ___ust_marker_check_format(format, ## args); \
a72ca31a
PMF
260 } while (0)
261
b521931e 262extern ust_marker_probe_func __ust_marker_empty_function;
a72ca31a 263
b521931e 264extern void ust_marker_probe_cb(const struct ust_marker *mdata,
75667d04 265 void *call_private, struct registers *regs, ...);
a72ca31a
PMF
266
267/*
268 * Connect a probe to a marker.
269 * private data pointer must be a valid allocated memory address, or NULL.
270 */
b521931e
MD
271extern int ust_marker_probe_register(const char *channel, const char *name,
272 const char *format, ust_marker_probe_func *probe, void *probe_private);
a72ca31a
PMF
273
274/*
b521931e 275 * Returns the private data given to ust_marker_probe_register.
a72ca31a 276 */
b521931e
MD
277extern int ust_marker_probe_unregister(const char *channel, const char *name,
278 ust_marker_probe_func *probe, void *probe_private);
a72ca31a
PMF
279/*
280 * Unregister a marker by providing the registered private data.
281 */
b521931e 282extern int ust_marker_probe_unregister_private_data(ust_marker_probe_func *probe,
a72ca31a
PMF
283 void *probe_private);
284
b521931e
MD
285extern void *ust_marker_get_private_data(const char *channel, const char *name,
286 ust_marker_probe_func *probe, int num);
a72ca31a
PMF
287
288/*
b521931e 289 * ust_marker_synchronize_unregister must be called between the last marker probe
a72ca31a
PMF
290 * unregistration and the first one of
291 * - the end of module exit function
292 * - the free of any resource used by the probes
293 * to ensure the code and data are valid for any possibly running probes.
294 */
b521931e 295#define ust_marker_synchronize_unregister() synchronize_sched()
a72ca31a 296
b521931e 297struct ust_marker_iter {
98963de4 298//ust// struct module *module;
b521931e
MD
299 struct ust_marker_lib *lib;
300 struct ust_marker * const *ust_marker;
a72ca31a
PMF
301};
302
b521931e
MD
303extern void ust_marker_iter_start(struct ust_marker_iter *iter);
304extern void ust_marker_iter_next(struct ust_marker_iter *iter);
305extern void ust_marker_iter_stop(struct ust_marker_iter *iter);
306extern void ust_marker_iter_reset(struct ust_marker_iter *iter);
307extern int ust_marker_get_iter_range(struct ust_marker * const **marker, struct ust_marker * const *begin,
308 struct ust_marker * const *end);
a72ca31a 309
b521931e
MD
310extern void ust_marker_update_process(void);
311extern int is_ust_marker_enabled(const char *channel, const char *name);
a72ca31a 312
b521931e
MD
313//ust// #ifdef CONFIG_UST_MARKER_USERSPACE
314//ust// extern void exit_user_ust_marker(struct task_struct *p);
59b161cd 315//ust// #else
b521931e 316//ust// static inline void exit_user_ust_marker(struct task_struct *p)
59b161cd
PMF
317//ust// {
318//ust// }
319//ust// #endif
a72ca31a 320
b521931e
MD
321struct ust_marker_addr {
322 struct ust_marker *marker;
3ea1e2fc
PMF
323 void *addr;
324};
98963de4 325
b521931e
MD
326struct ust_marker_lib {
327 struct ust_marker * const *ust_marker_start;
defa46a7 328#ifdef CONFIG_UST_GDB_INTEGRATION
b521931e 329 struct ust_marker_addr *ust_marker_addr_start;
defa46a7 330#endif
b521931e 331 int ust_marker_count;
0222e121 332 struct cds_list_head list;
98963de4
PMF
333};
334
b521931e
MD
335extern int ust_marker_register_lib(struct ust_marker * const *ust_marker_start, int ust_marker_count);
336extern int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start);
defa46a7 337
b521931e
MD
338#define UST_MARKER_LIB \
339 extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
340 extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
341 static struct ust_marker * const __ust_marker_ptr_dummy \
342 __attribute__((used, section("__ust_marker_ptrs"))) = NULL;\
55994a67 343 \
b521931e 344 static void __attribute__((constructor)) __ust_marker__init(void) \
55994a67 345 { \
b521931e
MD
346 ust_marker_register_lib(__start___ust_marker_ptrs, \
347 __stop___ust_marker_ptrs \
348 - __start___ust_marker_ptrs); \
900e307e
MD
349 } \
350 \
b521931e 351 static void __attribute__((destructor)) __ust_marker__destroy(void)\
24b6668c 352 { \
b521931e 353 ust_marker_unregister_lib(__start___ust_marker_ptrs); \
55994a67 354 }
98963de4 355
b521931e
MD
356extern void ust_marker_set_new_ust_marker_cb(void (*cb)(struct ust_marker *));
357extern void init_ust_marker(void);
9160b4e4 358
defa46a7 359#endif /* _UST_MARKER_H */
This page took 0.058001 seconds and 4 git commands to generate.