Rename for the new liburcu API namespace
[ust.git] / include / ust / tracepoint.h
CommitLineData
27b052e3
PMF
1#ifndef _UST_TRACEPOINT_H
2#define _UST_TRACEPOINT_H
f99be407
PMF
3
4/*
1f8b0dff
PMF
5 * Copyright (C) 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
6 * Copyright (C) 2009 Pierre-Marc Fournier
22d72948 7 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
f99be407 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.
f99be407 13 *
8fc2d8db 14 * This library is distributed in the hope that it will be useful,
1f8b0dff 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8fc2d8db
PMF
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
1f8b0dff 18 *
8fc2d8db
PMF
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
f99be407
PMF
22 *
23 * Heavily inspired from the Linux Kernel Markers.
24 *
1f8b0dff 25 * Ported to userspace by Pierre-Marc Fournier.
f99be407
PMF
26 */
27
872037bb 28#define _LGPL_SOURCE
b7ea1a1c 29#include <urcu-bp.h>
93d0f2ea 30#include <ust/immediate.h>
518d7abb 31#include <ust/core.h>
f99be407
PMF
32
33struct module;
34struct tracepoint;
35
9dec086e
NC
36struct probe {
37 void *func;
38 void *data;
39};
40
f99be407
PMF
41struct tracepoint {
42 const char *name; /* Tracepoint name */
43 DEFINE_IMV(char, state); /* State. */
9dec086e 44 struct probe *probes;
f99be407
PMF
45} __attribute__((aligned(32))); /*
46 * Aligned on 32 bytes because it is
47 * globally visible and gcc happily
48 * align these on the structure size.
49 * Keep in sync with vmlinux.lds.h.
50 */
51
22d72948
NC
52#define PARAMS(args...) args
53
7166e240
PMF
54#define TP_PROTO(args...) args
55#define TP_ARGS(args...) args
f99be407 56
872037bb
PMF
57#define CONFIG_TRACEPOINTS
58#ifdef CONFIG_TRACEPOINTS
f99be407
PMF
59
60/*
61 * it_func[0] is never NULL because there is at least one element in the array
62 * when the array itself is non NULL.
63 */
64#define __DO_TRACE(tp, proto, args) \
65 do { \
9dec086e
NC
66 struct probe *it_probe_ptr; \
67 void *it_func; \
68 void *__data; \
f99be407 69 \
9dec086e
NC
70 rcu_read_lock(); \
71 it_probe_ptr = rcu_dereference((tp)->probes); \
72 if (it_probe_ptr) { \
f99be407 73 do { \
9dec086e
NC
74 it_func = (it_probe_ptr)->func; \
75 __data = (it_probe_ptr)->data; \
76 ((void(*)(proto))(it_func))(args); \
77 } while ((++it_probe_ptr)->func); \
f99be407 78 } \
9dec086e 79 rcu_read_unlock(); \
f99be407
PMF
80 } while (0)
81
82#define __CHECK_TRACE(name, generic, proto, args) \
83 do { \
84 if (!generic) { \
85 if (unlikely(imv_read(__tracepoint_##name.state))) \
86 __DO_TRACE(&__tracepoint_##name, \
7166e240 87 TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
88 } else { \
89 if (unlikely(_imv_read(__tracepoint_##name.state))) \
90 __DO_TRACE(&__tracepoint_##name, \
7166e240 91 TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
92 } \
93 } while (0)
94
95/*
96 * Make sure the alignment of the structure in the __tracepoints section will
97 * not add unwanted padding between the beginning of the section and the
98 * structure. Force alignment to the same alignment as the section start.
99 *
100 * The "generic" argument, passed to the declared __trace_##name inline
101 * function controls which tracepoint enabling mechanism must be used.
102 * If generic is true, a variable read is used.
103 * If generic is false, immediate values are used.
104 */
9dec086e 105#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
f99be407
PMF
106 extern struct tracepoint __tracepoint_##name; \
107 static inline void trace_##name(proto) \
108 { \
9dec086e
NC
109 __CHECK_TRACE(name, 0, TP_PROTO(data_proto), \
110 TP_ARGS(data_args)); \
f99be407
PMF
111 } \
112 static inline void _trace_##name(proto) \
113 { \
9dec086e
NC
114 __CHECK_TRACE(name, 1, TP_PROTO(data_proto), \
115 TP_ARGS(data_args)); \
f99be407 116 } \
9dec086e
NC
117 static inline int \
118 register_trace_##name(void (*probe)(data_proto), void *data) \
f99be407 119 { \
9dec086e
NC
120 return tracepoint_probe_register(#name, (void *)probe, \
121 data); \
122 \
f99be407 123 } \
9dec086e
NC
124 static inline int \
125 unregister_trace_##name(void (*probe)(data_proto), void *data) \
f99be407 126 { \
9dec086e
NC
127 return tracepoint_probe_unregister(#name, (void *)probe, \
128 data); \
f99be407
PMF
129 }
130
9dec086e 131#define DEFINE_TRACE_FN(name, reg, unreg) \
f99be407
PMF
132 static const char __tpstrtab_##name[] \
133 __attribute__((section("__tracepoints_strings"))) = #name; \
134 struct tracepoint __tracepoint_##name \
135 __attribute__((section("__tracepoints"), aligned(32))) = \
136 { __tpstrtab_##name, 0, NULL }
137
9dec086e
NC
138#define DEFINE_TRACE(name) \
139 DEFINE_TRACE_FN(name, NULL, NULL);
140
f99be407
PMF
141extern void tracepoint_update_probe_range(struct tracepoint *begin,
142 struct tracepoint *end);
143
872037bb 144#else /* !CONFIG_TRACEPOINTS */
9dec086e 145#define __DECLARE_TRACE(name, proto, args) \
872037bb
PMF
146 static inline void trace_##name(proto) \
147 { } \
148 static inline void _trace_##name(proto) \
149 { } \
150 static inline int register_trace_##name(void (*probe)(proto)) \
151 { \
152 return -ENOSYS; \
153 } \
154 static inline int unregister_trace_##name(void (*probe)(proto)) \
155 { \
156 return -ENOSYS; \
157 }
158
159#define DEFINE_TRACE(name)
160#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
161#define EXPORT_TRACEPOINT_SYMBOL(name)
162
163static inline void tracepoint_update_probe_range(struct tracepoint *begin,
164 struct tracepoint *end)
165{ }
166#endif /* CONFIG_TRACEPOINTS */
f99be407 167
9dec086e
NC
168#define DECLARE_TRACE(name, proto, args) \
169 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
170 PARAMS(void *__data, proto), \
171 PARAMS(__data, args))
172
f99be407
PMF
173/*
174 * Connect a probe to a tracepoint.
175 * Internal API, should not be used directly.
176 */
9dec086e 177extern int tracepoint_probe_register(const char *name, void *probe, void *data);
f99be407
PMF
178
179/*
180 * Disconnect a probe from a tracepoint.
181 * Internal API, should not be used directly.
182 */
9dec086e 183extern int tracepoint_probe_unregister(const char *name, void *probe, void *data);
f99be407 184
9dec086e
NC
185extern int tracepoint_probe_register_noupdate(const char *name, void *probe,
186 void *data);
187extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
188 void *data);
f99be407
PMF
189extern void tracepoint_probe_update_all(void);
190
191struct tracepoint_iter {
474d745f
PMF
192//ust// struct module *module;
193 struct tracepoint_lib *lib;
f99be407
PMF
194 struct tracepoint *tracepoint;
195};
196
197extern void tracepoint_iter_start(struct tracepoint_iter *iter);
198extern void tracepoint_iter_next(struct tracepoint_iter *iter);
199extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
200extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
201extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
202 struct tracepoint *begin, struct tracepoint *end);
203
204/*
205 * tracepoint_synchronize_unregister must be called between the last tracepoint
206 * probe unregistration and the end of module exit to make sure there is no
207 * caller executing a probe when it is freed.
208 */
209static inline void tracepoint_synchronize_unregister(void)
210{
270c6b98 211//ust// synchronize_sched();
f99be407
PMF
212}
213
474d745f
PMF
214struct tracepoint_lib {
215 struct tracepoint *tracepoints_start;
216 int tracepoints_count;
0222e121 217 struct cds_list_head list;
474d745f
PMF
218};
219
872037bb
PMF
220extern int tracepoint_register_lib(struct tracepoint *tracepoints_start,
221 int tracepoints_count);
24b6668c 222extern int tracepoint_unregister_lib(struct tracepoint *tracepoints_start);
872037bb
PMF
223
224#define TRACEPOINT_LIB \
55994a67
JB
225 extern struct tracepoint __start___tracepoints[] __attribute__((weak, visibility("hidden"))); \
226 extern struct tracepoint __stop___tracepoints[] __attribute__((weak, visibility("hidden"))); \
872037bb
PMF
227 static void __attribute__((constructor)) __tracepoints__init(void) \
228 { \
229 tracepoint_register_lib(__start___tracepoints, \
230 (((long)__stop___tracepoints)-((long)__start___tracepoints))/sizeof(struct tracepoint)); \
24b6668c
PMF
231 } \
232 \
233 static void __attribute__((destructor)) __tracepoints__destroy(void) \
234 { \
235 tracepoint_unregister_lib(__start___tracepoints); \
872037bb
PMF
236 }
237
22d72948
NC
238
239#ifndef TRACE_EVENT
240/*
241 * For use with the TRACE_EVENT macro:
242 *
243 * We define a tracepoint, its arguments, its printf format
244 * and its 'fast binary record' layout.
245 *
246 * Firstly, name your tracepoint via TRACE_EVENT(name : the
247 * 'subsystem_event' notation is fine.
248 *
249 * Think about this whole construct as the
250 * 'trace_sched_switch() function' from now on.
251 *
252 *
253 * TRACE_EVENT(sched_switch,
254 *
255 * *
256 * * A function has a regular function arguments
257 * * prototype, declare it via TP_PROTO():
258 * *
259 *
260 * TP_PROTO(struct rq *rq, struct task_struct *prev,
261 * struct task_struct *next),
262 *
263 * *
264 * * Define the call signature of the 'function'.
265 * * (Design sidenote: we use this instead of a
266 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
267 * *
268 *
269 * TP_ARGS(rq, prev, next),
270 *
271 * *
272 * * Fast binary tracing: define the trace record via
273 * * TP_STRUCT__entry(). You can think about it like a
274 * * regular C structure local variable definition.
275 * *
276 * * This is how the trace record is structured and will
277 * * be saved into the ring buffer. These are the fields
278 * * that will be exposed to readers.
279 * *
280 * * The declared 'local variable' is called '__entry'
281 * *
282 * * __field(pid_t, prev_prid) is equivalent to a standard declariton:
283 * *
284 * * pid_t prev_pid;
285 * *
286 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
287 * *
288 * * char prev_comm[TASK_COMM_LEN];
289 * *
290 *
291 * TP_STRUCT__entry(
292 * __array( char, prev_comm, TASK_COMM_LEN )
293 * __field( pid_t, prev_pid )
294 * __field( int, prev_prio )
295 * __array( char, next_comm, TASK_COMM_LEN )
296 * __field( pid_t, next_pid )
297 * __field( int, next_prio )
298 * ),
299 *
300 * *
301 * * Assign the entry into the trace record, by embedding
302 * * a full C statement block into TP_fast_assign(). You
303 * * can refer to the trace record as '__entry' -
304 * * otherwise you can put arbitrary C code in here.
305 * *
306 * * Note: this C code will execute every time a trace event
307 * * happens, on an active tracepoint.
308 * *
309 *
310 * TP_fast_assign(
311 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
312 * __entry->prev_pid = prev->pid;
313 * __entry->prev_prio = prev->prio;
314 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
315 * __entry->next_pid = next->pid;
316 * __entry->next_prio = next->prio;
317 * )
318 *
319 * *
320 * * Formatted output of a trace record via TP_printf().
321 * * This is how the tracepoint will appear under debugging
322 * * of tracepoints.
323 * *
324 * * (raw-binary tracing wont actually perform this step.)
325 * *
326 *
327 * TP_printf("task %s:%d [%d] ==> %s:%d [%d]",
328 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
329 * __entry->next_comm, __entry->next_pid, __entry->next_prio),
330 *
331 * );
332 *
333 * This macro construct is thus used for the regular printf format
334 * tracing setup.
335 *
336 * A set of (un)registration functions can be passed to the variant
337 * TRACE_EVENT_FN to perform any (un)registration work.
338 */
339
0c0686ee
NC
340struct trace_event {
341 const char *name;
342 int (*regfunc)(void *data);
343 int (*unregfunc)(void *data);
344} __attribute__((aligned(32)));
345
346struct trace_event_lib {
347 struct trace_event *trace_events_start;
348 int trace_events_count;
0222e121 349 struct cds_list_head list;
0c0686ee
NC
350};
351
352struct trace_event_iter {
353 struct trace_event_lib *lib;
354 struct trace_event *trace_event;
355};
356
357extern void lock_trace_events(void);
358extern void unlock_trace_events(void);
359
360extern void trace_event_iter_start(struct trace_event_iter *iter);
361extern void trace_event_iter_next(struct trace_event_iter *iter);
362extern void trace_event_iter_reset(struct trace_event_iter *iter);
363
364extern int trace_event_get_iter_range(struct trace_event **trace_event,
365 struct trace_event *begin,
366 struct trace_event *end);
367
368extern void trace_event_update_process(void);
369extern int is_trace_event_enabled(const char *channel, const char *name);
370
371extern int trace_event_register_lib(struct trace_event *start_trace_events,
372 int trace_event_count);
373
374extern int trace_event_unregister_lib(struct trace_event *start_trace_events);
375
376#define TRACE_EVENT_LIB \
377 extern struct trace_event __start___trace_events[] \
378 __attribute__((weak, visibility("hidden"))); \
379 extern struct trace_event __stop___trace_events[] \
380 __attribute__((weak, visibility("hidden"))); \
381 static void __attribute__((constructor)) \
382 __trace_events__init(void) \
383 { \
384 long trace_event_count =((long)__stop___trace_events- \
385 (long)__start___trace_events) \
386 /sizeof(struct trace_event); \
387 trace_event_register_lib(__start___trace_events, \
388 trace_event_count); \
389 } \
390 \
391 static void __attribute__((destructor)) \
392 __trace_event__destroy(void) \
393 { \
394 trace_event_unregister_lib(__start___trace_events); \
395 }
396
22d72948
NC
397#define DECLARE_TRACE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
398#define DEFINE_TRACE_EVENT(template, name, proto, args) \
399 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
400#define DEFINE_TRACE_EVENT_PRINT(template, name, proto, args, print) \
401 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
402
403#define TRACE_EVENT(name, proto, args, struct, assign, print) \
404 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
405#define TRACE_EVENT_FN(name, proto, args, struct, \
406 assign, print, reg, unreg) \
407 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
408
409#endif /* ifdef TRACE_EVENT (see note above) */
410
411
27b052e3 412#endif /* _UST_TRACEPOINT_H */
This page took 0.048823 seconds and 4 git commands to generate.