Mark __tp_cb_data as possibly unused for backward compat API
[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
f37142a4
MD
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License.
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
b7ea1a1c 28#include <urcu-bp.h>
b0c4126f 29#include <urcu/list.h>
f99be407 30
b979b346 31struct tracepoint_probe {
9dec086e
NC
32 void *func;
33 void *data;
34};
35
f99be407
PMF
36struct tracepoint {
37 const char *name; /* Tracepoint name */
f36c12ab 38 char state; /* State. */
b979b346 39 struct tracepoint_probe *probes;
f218ff28 40};
f99be407 41
cc7b66ba
MD
42/*
43 * Tracepoints should be added to the instrumented code using the
44 * "tracepoint()" macro.
45 */
46#define tracepoint(name, args...) __trace_##name(args)
47
81614639
MD
48/*
49 * Library should be made known to libust by declaring TRACEPOINT_LIB in
50 * the source file. (Usually at the end of the file, in the outermost
51 * scope).
52 */
53#define TRACEPOINT_LIB \
54 extern struct tracepoint * const __start___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \
55 extern struct tracepoint * const __stop___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \
56 static struct tracepoint * __tracepoint_ptr_dummy \
57 __attribute__((used, section("__tracepoints_ptrs"))); \
58 static void __attribute__((constructor)) __tracepoints__init(void) \
59 { \
60 tracepoint_register_lib(__start___tracepoints_ptrs, \
61 __stop___tracepoints_ptrs - \
62 __start___tracepoints_ptrs); \
63 } \
64 \
65 static void __attribute__((destructor)) __tracepoints__destroy(void) \
66 { \
67 tracepoint_unregister_lib(__start___tracepoints_ptrs); \
68 }
f99be407
PMF
69
70/*
71 * it_func[0] is never NULL because there is at least one element in the array
72 * when the array itself is non NULL.
34dca3cc 73 * __attribute__((unused)) is for backward compatibility API.
f99be407
PMF
74 */
75#define __DO_TRACE(tp, proto, args) \
76 do { \
b979b346
MD
77 struct tracepoint_probe *__tp_it_probe_ptr; \
78 void *__tp_it_func; \
34dca3cc 79 void *__tp_cb_data __attribute__((unused)); \
f99be407 80 \
9dec086e 81 rcu_read_lock(); \
b979b346
MD
82 __tp_it_probe_ptr = rcu_dereference((tp)->probes); \
83 if (__tp_it_probe_ptr) { \
f99be407 84 do { \
b979b346
MD
85 __tp_it_func = __tp_it_probe_ptr->func; \
86 __tp_cb_data = __tp_it_probe_ptr->data; \
87 ((void(*)(proto))__tp_it_func)(args); \
88 } while ((++__tp_it_probe_ptr)->func); \
f99be407 89 } \
9dec086e 90 rcu_read_unlock(); \
f99be407
PMF
91 } while (0)
92
81614639
MD
93#define TP_PARAMS(args...) args
94#define TP_PROTO(args...) args
95#define TP_ARGS(args...) args
96
f36c12ab 97#define __CHECK_TRACE(name, proto, args) \
f99be407 98 do { \
f36c12ab
MD
99 if (unlikely(__tracepoint_##name.state)) \
100 __DO_TRACE(&__tracepoint_##name, \
101 TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
102 } while (0)
103
104/*
105 * Make sure the alignment of the structure in the __tracepoints section will
106 * not add unwanted padding between the beginning of the section and the
107 * structure. Force alignment to the same alignment as the section start.
f99be407 108 */
8d71973c 109#define __DECLARE_TRACEPOINT(name, proto, args, data_proto, data_args) \
f99be407 110 extern struct tracepoint __tracepoint_##name; \
cc7b66ba 111 static inline void __trace_##name(proto) \
f99be407 112 { \
f36c12ab 113 __CHECK_TRACE(name, TP_PROTO(data_proto), \
9dec086e 114 TP_ARGS(data_args)); \
f99be407 115 } \
9dec086e 116 static inline int \
cc7b66ba 117 __register_trace_##name(void (*probe)(data_proto), void *data) \
f99be407 118 { \
81614639 119 return __tracepoint_probe_register(#name, (void *)probe,\
9dec086e
NC
120 data); \
121 \
f99be407 122 } \
9dec086e 123 static inline int \
cc7b66ba 124 __unregister_trace_##name(void (*probe)(data_proto), void *data)\
f99be407 125 { \
81614639 126 return __tracepoint_probe_unregister(#name, (void *)probe, \
9dec086e 127 data); \
2874fee5
MD
128 } \
129 /* \
130 * Backward-compatibility API (will be deprecated): \
131 * trace_* \
132 * register_trace_* \
133 * unregister_trace_* \
134 */ \
135 static inline void trace_##name(proto) \
136 { \
137 __CHECK_TRACE(name, TP_PROTO(proto), \
138 TP_ARGS(args)); \
139 } \
140 static inline int \
141 register_trace_##name(void (*probe)(proto)) \
142 { \
143 return __tracepoint_probe_register(#name, (void *)probe,\
144 NULL); \
145 } \
146 static inline int \
147 unregister_trace_##name(void (*probe)(proto)) \
148 { \
149 return __tracepoint_probe_unregister(#name, (void *)probe, \
150 NULL); \
f99be407
PMF
151 }
152
332b3a18 153/*
81614639 154 * The need for the _DECLARE_TRACEPOINT_NOARGS() is to handle the prototype
377d33ed 155 * (void). "void" is a special value in a function prototype and can
8d71973c 156 * not be combined with other arguments. Since the DECLARE_TRACEPOINT()
377d33ed
MD
157 * macro adds a data element at the beginning of the prototype,
158 * we need a way to differentiate "(void *data, proto)" from
159 * "(void *data, void)". The second prototype is invalid.
160 *
8d71973c 161 * DECLARE_TRACEPOINT_NOARGS() passes "void" as the tracepoint prototype
b979b346 162 * and "void *__tp_cb_data" as the callback prototype.
377d33ed 163 *
8d71973c 164 * DECLARE_TRACEPOINT() passes "proto" as the tracepoint protoype and
b979b346 165 * "void *__tp_cb_data, proto" as the callback prototype.
377d33ed 166 */
81614639
MD
167#define _DECLARE_TRACEPOINT_NOARGS(name) \
168 __DECLARE_TRACEPOINT(name, void, , void *__tp_cb_data, __tp_cb_data)
377d33ed 169
81614639
MD
170#define _DECLARE_TRACEPOINT(name, proto, args) \
171 __DECLARE_TRACEPOINT(name, TP_PARAMS(proto), TP_PARAMS(args), \
172 TP_PARAMS(void *__tp_cb_data, proto), \
173 TP_PARAMS(__tp_cb_data, args))
9dec086e 174
f99be407 175/*
81614639
MD
176 * __tracepoints_ptrs section is not const (read-only) to let the linker update
177 * the pointer, allowing PIC code.
f99be407 178 */
81614639
MD
179#define _DEFINE_TRACEPOINT(name) \
180 static const char __tpstrtab_##name[] \
181 __attribute__((section("__tracepoints_strings"))) = #name; \
182 struct tracepoint __tracepoint_##name \
183 __attribute__((section("__tracepoints"))) = \
184 { __tpstrtab_##name, 0, NULL }; \
185 static struct tracepoint * __tracepoint_ptr_##name \
186 __attribute__((used, section("__tracepoints_ptrs"))) = \
187 &__tracepoint_##name;
f99be407 188
f99be407 189
81614639
MD
190#define __register_tracepoint(name, probe, data) \
191 __register_trace_##name(probe, data)
192#define __unregister_tracepoint(name, probe, data) \
193 __unregister_trace_##name(probe, data)
f99be407 194
81614639
MD
195/*
196 * Connect a probe to a tracepoint.
197 * Internal API.
198 */
199extern
200int __tracepoint_probe_register(const char *name, void *probe, void *data);
f99be407
PMF
201
202/*
81614639
MD
203 * Disconnect a probe from a tracepoint.
204 * Internal API.
f99be407 205 */
81614639
MD
206extern
207int __tracepoint_probe_unregister(const char *name, void *probe, void *data);
f99be407 208
474d745f 209struct tracepoint_lib {
f218ff28 210 struct tracepoint * const *tracepoints_start;
474d745f 211 int tracepoints_count;
0222e121 212 struct cds_list_head list;
474d745f
PMF
213};
214
81614639
MD
215extern
216int tracepoint_register_lib(struct tracepoint * const *tracepoints_start,
217 int tracepoints_count);
218extern
219int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start);
872037bb 220
2874fee5
MD
221/*
222 * Backward-compatibility API (will be deprecated):
223 * DEFINE_TRACE
224 * DECLARE_TRACE
225 * register_tracepoint
226 * unregister_tracepoint
227 */
228#define DEFINE_TRACE _DEFINE_TRACEPOINT
229#define DECLARE_TRACE(name, proto, args) \
230 _DECLARE_TRACEPOINT(name, TP_PARAMS(proto), TP_PARAMS(args))
22d72948 231
8d71973c 232#ifndef TRACEPOINT_EVENT
22d72948 233/*
8d71973c 234 * For use with the TRACEPOINT_EVENT macro:
22d72948
NC
235 *
236 * We define a tracepoint, its arguments, its printf format
237 * and its 'fast binary record' layout.
238 *
8d71973c 239 * Firstly, name your tracepoint via TRACEPOINT_EVENT(name : the
22d72948
NC
240 * 'subsystem_event' notation is fine.
241 *
242 * Think about this whole construct as the
243 * 'trace_sched_switch() function' from now on.
244 *
245 *
8d71973c 246 * TRACEPOINT_EVENT(sched_switch,
22d72948
NC
247 *
248 * *
249 * * A function has a regular function arguments
250 * * prototype, declare it via TP_PROTO():
251 * *
252 *
253 * TP_PROTO(struct rq *rq, struct task_struct *prev,
254 * struct task_struct *next),
255 *
256 * *
257 * * Define the call signature of the 'function'.
258 * * (Design sidenote: we use this instead of a
259 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
260 * *
261 *
262 * TP_ARGS(rq, prev, next),
263 *
264 * *
265 * * Fast binary tracing: define the trace record via
81614639 266 * * TP_FIELDS(). You can think about it like a
22d72948
NC
267 * * regular C structure local variable definition.
268 * *
269 * * This is how the trace record is structured and will
270 * * be saved into the ring buffer. These are the fields
271 * * that will be exposed to readers.
272 * *
81614639
MD
273 * * tp_field(pid_t, prev_pid, prev->pid) is equivalent
274 * * to a standard declaraton:
22d72948 275 * *
81614639 276 * * pid_t prev_pid;
22d72948 277 * *
81614639 278 * * followed by an assignment:
22d72948 279 * *
81614639 280 * * prev_pid = prev->pid;
22d72948 281 * *
81614639
MD
282 * * tp_array(char, prev_comm, TASK_COMM_LEN, prev->comm) is
283 * * equivalent to:
22d72948 284 * *
81614639 285 * * char prev_comm[TASK_COMM_LEN];
22d72948 286 * *
81614639 287 * * followed by an assignment:
22d72948 288 * *
81614639 289 * * memcpy(prev_comm, prev->comm, TASK_COMM_LEN);
22d72948
NC
290 * *
291 *
81614639
MD
292 * TP_FIELDS(
293 * tp_array(char, prev_comm, TASK_COMM_LEN, prev->comm)
294 * tp_field(pid_t, prev_pid, prev->pid)
295 * tp_field(int, prev_prio, prev->prio)
296 * tp_array(char, next_comm, TASK_COMM_LEN, next->comm)
297 * tp_field(pid_t, next_pid, next->pid)
298 * tp_field(int, next_prio, next->prio)
22d72948 299 * )
22d72948 300 * );
22d72948
NC
301 */
302
81614639
MD
303#define TRACEPOINT_EVENT(name, proto, args, fields) \
304 _DECLARE_TRACEPOINT(name, TP_PARAMS(proto), TP_PARAMS(args))
0c0686ee 305
81614639
MD
306#define TRACEPOINT_EVENT_CLASS(name, proto, args, fields)
307#define TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
308 _DECLARE_TRACEPOINT(name, TP_PARAMS(proto), TP_PARAMS(args))
0c0686ee 309
81614639
MD
310/*
311 * Declaration of tracepoints that take 0 argument.
312 */
313#define TRACEPOINT_EVENT_NOARGS(name, fields) \
314 _DECLARE_TRACEPOINT_NOARGS(name)
0c0686ee 315
81614639
MD
316#define TRACEPOINT_EVENT_CLASS_NOARGS(name, fields)
317#define TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
318 _DECLARE_TRACEPOINT_NOARGS(name)
0c0686ee 319
0c0686ee 320
0c0686ee 321
8d71973c 322#define TRACEPOINT_EVENT_LIB \
fc1caebc 323 extern struct trace_event * const __start___trace_events_ptrs[] \
0c0686ee 324 __attribute__((weak, visibility("hidden"))); \
fc1caebc 325 extern struct trace_event * const __stop___trace_events_ptrs[] \
0c0686ee 326 __attribute__((weak, visibility("hidden"))); \
332b3a18
MD
327 static struct trace_event * __event_ptrs_dummy \
328 __attribute__((used, section("__trace_events_ptrs"))); \
0c0686ee
NC
329 static void __attribute__((constructor)) \
330 __trace_events__init(void) \
331 { \
fc1caebc
MD
332 trace_event_register_lib(__start___trace_events_ptrs, \
333 __stop___trace_events_ptrs - \
334 __start___trace_events_ptrs); \
0c0686ee
NC
335 } \
336 \
337 static void __attribute__((destructor)) \
338 __trace_event__destroy(void) \
339 { \
fc1caebc 340 trace_event_unregister_lib(__start___trace_events_ptrs);\
0c0686ee
NC
341 }
342
81614639
MD
343struct trace_event {
344 const char *name;
345};
22d72948 346
81614639
MD
347struct trace_event_lib {
348 struct trace_event * const *trace_events_start;
349 int trace_events_count;
350 struct cds_list_head list;
351};
22d72948 352
81614639
MD
353extern
354int trace_event_register_lib(struct trace_event * const *start_trace_events,
355 int trace_event_count);
356extern
357int trace_event_unregister_lib(struct trace_event * const *start_trace_events);
22d72948 358
81614639 359#endif /* #ifndef TRACEPOINT_EVENT */
22d72948 360
27b052e3 361#endif /* _UST_TRACEPOINT_H */
This page took 0.05504 seconds and 4 git commands to generate.