Syntax cleanup
[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
a72ca31a
PMF
37struct marker;
38
39/**
40 * marker_probe_func - Type of a marker probe function
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 */
52typedef void marker_probe_func(const struct marker *mdata,
75667d04 53 void *probe_private, struct registers *regs, void *call_private,
a72ca31a
PMF
54 const char *fmt, va_list *args);
55
56struct marker_probe_closure {
57 marker_probe_func *func; /* Callback */
58 void *probe_private; /* Private probe data */
59};
60
61struct marker {
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 */
75667d04 72 void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...);
a72ca31a
PMF
73 struct marker_probe_closure single;
74 struct marker_probe_closure *multi;
75 const char *tp_name; /* Optional tracepoint name */
76 void *tp_cb; /* Optional tracepoint callback */
3ea1e2fc 77 void *location; /* Address of marker in code */
a72ca31a
PMF
78} __attribute__((aligned(8)));
79
872037bb
PMF
80#define CONFIG_MARKERS
81#ifdef CONFIG_MARKERS
a72ca31a 82
7b2c5007
DG
83#define GET_MARKER(channel, name) (__mark_##channel##_##name)
84
9692fa18 85#define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format, unique, m) \
bb9ade29 86 struct registers regs; \
bb9ade29 87 \
a4db742a 88 /* This next asm has to be a basic inline asm (no input/output/clobber), \
9692fa18
PMF
89 * because it must not require %-sign escaping, as we most certainly \
90 * have some %-signs in the format string. \
91 */ \
f91aa730
DG
92 asm volatile ( \
93 /* We only define these symbols if they have not yet been defined. Indeed, \
94 * if two markers with the same channel/name are on the same line, they \
95 * will try to create the same symbols, resulting in a conflict. This \
96 * is not unusual as it can be the result of function inlining. \
97 */ \
98 ".ifndef __mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) "\n\t" \
99 /*".section __markers_strings\n\t"*/ \
100 ".section __markers_strings,\"aw\",@progbits\n\t" \
101 "__mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) ":\n\t" \
102 ".string \"" __stringify(channel) "\"\n\t" \
103 "__mstrtab_" __stringify(channel) "_" __stringify(name) "_name_" __stringify(unique) ":\n\t" \
104 ".string \"" __stringify(name) "\"\n\t" \
105 "__mstrtab_" __stringify(channel) "_" __stringify(name) "_format_" __stringify(unique) ":\n\t" \
106 ".string " "\"" format "\"" "\n\t" \
107 ".previous\n\t" \
108 ".endif\n\t" \
9692fa18
PMF
109 ); \
110 asm volatile ( \
f91aa730
DG
111 /*".section __markers\n\t"*/ \
112 ".section __markers,\"aw\",@progbits\n\t" \
113 ".balign 8\n\t" \
114 "2:\n\t" \
115 _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) ")\n\t" /* channel string */ \
116 _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_name_" __stringify(unique) ")\n\t" /* name string */ \
117 _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_format_" __stringify(unique) ")\n\t" /* format string */ \
118 ".byte 0\n\t" /* state imv */ \
119 ".byte 0\n\t" /* ptype */ \
120 ".word 0\n\t" /* channel_id */ \
121 ".word 0\n\t" /* event_id */ \
122 ".balign " __stringify(__WORDSIZE) " / 8\n\t" /* alignment */ \
123 _ASM_PTR "(marker_probe_cb)\n\t" /* call */ \
124 _ASM_PTR "(__mark_empty_function)\n\t" /* marker_probe_closure single.field1 */ \
125 _ASM_PTR "0\n\t" /* marker_probe_closure single.field2 */ \
126 _ASM_PTR "0\n\t" /* marker_probe_closure *multi */ \
127 _ASM_PTR "0\n\t" /* tp_name */ \
128 _ASM_PTR "0\n\t" /* tp_cb */ \
129 _ASM_PTR "(1f)\n\t" /* location */ \
130 ".previous\n\t" \
131 "1:\n\t" \
132 ARCH_COPY_ADDR("%[outptr]") \
9692fa18 133 : [outptr] "=r" (m) ); \
bb9ade29 134 \
3ea1e2fc
PMF
135 save_registers(&regs)
136
137
9692fa18
PMF
138#define DEFINE_MARKER(channel, name, format, unique, m) \
139 _DEFINE_MARKER(channel, name, NULL, NULL, format, unique, m)
a72ca31a 140
7166e240
PMF
141#define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
142 _DEFINE_MARKER_TP(channel, name, #tp_name, tp_cb, format)
143
144#define _DEFINE_MARKER_TP(channel, name, tp_name_str, tp_cb, format) \
145 static const char __mstrtab_##channel##_##name[] \
146 __attribute__((section("__markers_strings"))) \
147 = #channel "\0" #name "\0" format; \
7b2c5007 148 static struct marker GET_MARKER(channel, name) \
7166e240
PMF
149 __attribute__((section("__markers"), aligned(8))) = \
150 { __mstrtab_##channel##_##name, \
f91aa730
DG
151 &__mstrtab_##channel##_##name[sizeof(#channel)], \
152 &__mstrtab_##channel##_##name[sizeof(#channel) + sizeof(#name)], \
153 0, 0, 0, 0, marker_probe_cb, \
154 { __mark_empty_function, NULL}, \
155 NULL, tp_name_str, tp_cb }
a72ca31a
PMF
156
157/*
158 * Make sure the alignment of the structure in the __markers section will
159 * not add unwanted padding between the beginning of the section and the
160 * structure. Force alignment to the same alignment as the section start.
161 *
162 * The "generic" argument controls which marker enabling mechanism must be used.
163 * If generic is true, a variable read is used.
164 * If generic is false, immediate values are used.
165 */
bb9ade29 166
a72ca31a 167#define __trace_mark(generic, channel, name, call_private, format, args...) \
e05cba90 168 __trace_mark_counter(generic, channel, name, __LINE__, call_private, format, ## args)
bb9ade29
PMF
169
170#define __trace_mark_counter(generic, channel, name, unique, call_private, format, args...) \
a72ca31a 171 do { \
9692fa18
PMF
172 struct marker *m; \
173 DEFINE_MARKER(channel, name, format, unique, m); \
a72ca31a
PMF
174 __mark_check_format(format, ## args); \
175 if (!generic) { \
9692fa18
PMF
176 if (unlikely(imv_read(m->state))) \
177 (m->call)(m, call_private, &regs, ## args); \
a72ca31a 178 } else { \
9692fa18
PMF
179 if (unlikely(_imv_read(m->state))) \
180 (m->call)(m, call_private, &regs, ## args); \
a72ca31a
PMF
181 } \
182 } while (0)
183
bb9ade29 184#define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, format, args...) \
e05cba90 185 __trace_mark_tp_counter(channel, name, __LINE__, call_private, tp_name, tp_cb, format, ## args)
bb9ade29
PMF
186
187#define __trace_mark_tp_counter(channel, name, unique, call_private, tp_name, tp_cb, format, args...) \
a72ca31a 188 do { \
b2cc3e50 189 struct registers regs; \
a72ca31a
PMF
190 void __check_tp_type(void) \
191 { \
245d371e 192 register_trace_##tp_name(tp_cb, call_private); \
a72ca31a 193 } \
b2cc3e50 194 DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
a72ca31a 195 __mark_check_format(format, ## args); \
7b2c5007 196 (*GET_MARKER(channel, name).call)(&GET_MARKER(channel, name), \
75667d04 197 call_private, &regs, ## args); \
a72ca31a
PMF
198 } while (0)
199
200extern void marker_update_probe_range(struct marker *begin,
201 struct marker *end);
202
872037bb 203#else /* !CONFIG_MARKERS */
9692fa18 204#define DEFINE_MARKER(channel, name, tp_name, tp_cb, format, m)
872037bb
PMF
205#define __trace_mark(generic, channel, name, call_private, format, args...) \
206 __mark_check_format(format, ## args)
207#define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
208 format, args...) \
209 do { \
210 void __check_tp_type(void) \
211 { \
245d371e 212 register_trace_##tp_name(tp_cb, call_private); \
872037bb
PMF
213 } \
214 __mark_check_format(format, ## args); \
215 } while (0)
216static inline void marker_update_probe_range(struct marker *begin,
217 struct marker *end)
218{ }
219#define GET_MARKER(channel, name)
220#endif /* CONFIG_MARKERS */
a72ca31a
PMF
221
222/**
223 * trace_mark - Marker using code patching
224 * @channel: marker channel (where to send the data), not quoted.
225 * @name: marker name, not quoted.
226 * @format: format string
227 * @args...: variable argument list
228 *
229 * Places a marker using optimized code patching technique (imv_read())
230 * to be enabled when immediate values are present.
231 */
232#define trace_mark(channel, name, format, args...) \
233 __trace_mark(0, channel, name, NULL, format, ## args)
234
235/**
236 * _trace_mark - Marker using variable read
237 * @channel: marker channel (where to send the data), not quoted.
238 * @name: marker name, not quoted.
239 * @format: format string
240 * @args...: variable argument list
241 *
242 * Places a marker using a standard memory read (_imv_read()) to be
243 * enabled. Should be used for markers in code paths where instruction
c1f20530 244 * modification based enabling is not welcome.
a72ca31a
PMF
245 */
246#define _trace_mark(channel, name, format, args...) \
247 __trace_mark(1, channel, name, NULL, format, ## args)
248
249/**
250 * trace_mark_tp - Marker in a tracepoint callback
251 * @channel: marker channel (where to send the data), not quoted.
252 * @name: marker name, not quoted.
253 * @tp_name: tracepoint name, not quoted.
254 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
255 * is not optimized away by the compiler (should not be static).
256 * @format: format string
257 * @args...: variable argument list
258 *
259 * Places a marker in a tracepoint callback.
260 */
261#define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
262 __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
263
264/**
265 * MARK_NOARGS - Format string for a marker with no argument.
266 */
267#define MARK_NOARGS " "
268
269extern void lock_markers(void);
270extern void unlock_markers(void);
271
272extern void markers_compact_event_ids(void);
273
274/* To be used for string format validity checking with gcc */
275static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
276{
277}
278
279#define __mark_check_format(format, args...) \
280 do { \
281 if (0) \
282 ___mark_check_format(format, ## args); \
283 } while (0)
284
285extern marker_probe_func __mark_empty_function;
286
287extern void marker_probe_cb(const struct marker *mdata,
75667d04 288 void *call_private, struct registers *regs, ...);
a72ca31a
PMF
289
290/*
291 * Connect a probe to a marker.
292 * private data pointer must be a valid allocated memory address, or NULL.
293 */
294extern int marker_probe_register(const char *channel, const char *name,
295 const char *format, marker_probe_func *probe, void *probe_private);
296
297/*
298 * Returns the private data given to marker_probe_register.
299 */
300extern int marker_probe_unregister(const char *channel, const char *name,
301 marker_probe_func *probe, void *probe_private);
302/*
303 * Unregister a marker by providing the registered private data.
304 */
305extern int marker_probe_unregister_private_data(marker_probe_func *probe,
306 void *probe_private);
307
308extern void *marker_get_private_data(const char *channel, const char *name,
309 marker_probe_func *probe, int num);
310
311/*
312 * marker_synchronize_unregister must be called between the last marker probe
313 * unregistration and the first one of
314 * - the end of module exit function
315 * - the free of any resource used by the probes
316 * to ensure the code and data are valid for any possibly running probes.
317 */
318#define marker_synchronize_unregister() synchronize_sched()
319
320struct marker_iter {
98963de4
PMF
321//ust// struct module *module;
322 struct lib *lib;
a72ca31a
PMF
323 struct marker *marker;
324};
325
326extern void marker_iter_start(struct marker_iter *iter);
327extern void marker_iter_next(struct marker_iter *iter);
328extern void marker_iter_stop(struct marker_iter *iter);
329extern void marker_iter_reset(struct marker_iter *iter);
330extern int marker_get_iter_range(struct marker **marker, struct marker *begin,
331 struct marker *end);
332
333extern void marker_update_process(void);
334extern int is_marker_enabled(const char *channel, const char *name);
335
59b161cd
PMF
336//ust// #ifdef CONFIG_MARKERS_USERSPACE
337//ust// extern void exit_user_markers(struct task_struct *p);
338//ust// #else
339//ust// static inline void exit_user_markers(struct task_struct *p)
340//ust// {
341//ust// }
342//ust// #endif
a72ca31a 343
3ea1e2fc
PMF
344struct marker_addr {
345 struct marker *marker;
346 void *addr;
347};
98963de4
PMF
348
349struct lib {
350 struct marker *markers_start;
defa46a7 351#ifdef CONFIG_UST_GDB_INTEGRATION
3ea1e2fc 352 struct marker_addr *markers_addr_start;
defa46a7 353#endif
98963de4
PMF
354 int markers_count;
355 struct list_head list;
356};
357
bf961c7e 358extern int marker_register_lib(struct marker *markers_start, int markers_count);
24b6668c 359extern int marker_unregister_lib(struct marker *markers_start);
defa46a7 360
55994a67
JB
361#define MARKER_LIB \
362 extern struct marker __start___markers[] __attribute__((weak, visibility("hidden"))); \
363 extern struct marker __stop___markers[] __attribute__((weak, visibility("hidden"))); \
55994a67
JB
364 \
365 static void __attribute__((constructor)) __markers__init(void) \
366 { \
bf961c7e 367 marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \
24b6668c
PMF
368 } \
369 \
370 static void __attribute__((destructor)) __markers__destroy(void) \
371 { \
372 marker_unregister_lib(__start___markers); \
55994a67 373 }
98963de4 374
064842c6
PMF
375extern void marker_set_new_marker_cb(void (*cb)(struct marker *));
376extern void init_markers(void);
9160b4e4 377
defa46a7 378#endif /* _UST_MARKER_H */
This page took 0.069685 seconds and 4 git commands to generate.