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