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