Fix: missing Tracepoint prototype checking due to bogus merge
[lttng-modules.git] / probes / lttng-events.h
1 /*
2 * lttng-events.h
3 *
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; only
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 #include <linux/uaccess.h>
22 #include <linux/debugfs.h>
23 #include "lttng.h"
24 #include "lttng-types.h"
25 #include "lttng-probe-user.h"
26 #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
27 #include "../wrapper/ringbuffer/frontend_types.h"
28 #include "../lttng-events.h"
29 #include "../lttng-tracer-core.h"
30
31 /*
32 * Macro declarations used for all stages.
33 */
34
35 /*
36 * LTTng name mapping macros. LTTng remaps some of the kernel events to
37 * enforce name-spacing.
38 */
39 #undef LTTNG_TRACEPOINT_EVENT_MAP
40 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, tstruct, assign, print) \
41 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
42 PARAMS(proto), \
43 PARAMS(args), \
44 PARAMS(tstruct), \
45 PARAMS(assign), \
46 PARAMS(print)) \
47 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
48
49 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
50 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, tstruct, assign, print) \
51 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
52 PARAMS(tstruct), \
53 PARAMS(assign), \
54 PARAMS(print)) \
55 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
56
57 #undef LTTNG_TRACEPOINT_EVENT_CODE
58 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, tstruct, assign, print) \
59 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(name, \
60 PARAMS(proto), \
61 PARAMS(args), \
62 PARAMS(_locvar), \
63 PARAMS(_code), \
64 PARAMS(tstruct), \
65 PARAMS(assign), \
66 PARAMS(print)) \
67 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(name, name, name, PARAMS(proto), PARAMS(args))
68
69
70 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP
71 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, map, proto, args, print) \
72 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, map, PARAMS(proto), PARAMS(args))
73
74 /* Callbacks are meaningless to LTTng. */
75 #undef LTTNG_TRACEPOINT_EVENT_FN_MAP
76 #define LTTNG_TRACEPOINT_EVENT_FN_MAP(name, map, proto, args, tstruct, \
77 assign, print, reg, unreg) \
78 LTTNG_TRACEPOINT_EVENT_MAP(name, map, PARAMS(proto), PARAMS(args), \
79 PARAMS(tstruct), PARAMS(assign), PARAMS(print))
80
81 #undef LTTNG_TRACEPOINT_EVENT_CONDITION_MAP
82 #define LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, map, proto, args, cond, tstruct, assign, print) \
83 LTTNG_TRACEPOINT_EVENT_MAP(name, map, \
84 PARAMS(proto), \
85 PARAMS(args), \
86 PARAMS(tstruct), \
87 PARAMS(assign), \
88 PARAMS(print))
89
90 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP
91 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_CONDITION_MAP(template, name, map, proto, args, cond) \
92 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, map, PARAMS(proto), PARAMS(args))
93
94 /*
95 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
96 * handlers for events. That is, if all events have the same parameters
97 * and just have distinct trace points. Each tracepoint can be defined
98 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
99 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
100 *
101 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
102 * template.
103 */
104
105 #undef LTTNG_TRACEPOINT_EVENT
106 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, tstruct, assign, print) \
107 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
108 PARAMS(proto), \
109 PARAMS(args), \
110 PARAMS(tstruct), \
111 PARAMS(assign), \
112 PARAMS(print))
113
114 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
115 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, tstruct, assign, print) \
116 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, \
117 PARAMS(tstruct), \
118 PARAMS(assign), \
119 PARAMS(print))
120
121 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT
122 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT(template, name, proto, args, print) \
123 LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT_MAP(template, name, name, \
124 PARAMS(proto), PARAMS(args), PARAMS(print_))
125
126 #undef LTTNG_TRACEPOINT_EVENT_FN
127 #define LTTNG_TRACEPOINT_EVENT_FN(name, proto, args, tstruct, \
128 assign, print, reg, unreg) \
129 LTTNG_TRACEPOINT_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
130 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
131 PARAMS(reg), PARAMS(unreg)) \
132
133 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
134 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
135 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
136
137 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
138 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
139 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
140
141 #undef LTTNG_TRACEPOINT_EVENT_CONDITION
142 #define LTTNG_TRACEPOINT_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
143 LTTNG_TRACEPOINT_EVENT_CONDITION_MAP(name, name, \
144 PARAMS(proto), \
145 PARAMS(args), \
146 PARAMS(cond), \
147 PARAMS(tstruct), \
148 PARAMS(assign), \
149 PARAMS(print))
150
151 #undef LTTNG_TRACEPOINT_EVENT_CLASS
152 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
153 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
154 PARAMS(_tstruct), PARAMS(_assign), PARAMS(_print))
155
156 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
157 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
158 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_tstruct), \
159 PARAMS(_assign), PARAMS(_print))
160
161
162 /*
163 * Stage 1 of the trace events.
164 *
165 * Create dummy trace calls for each events, verifying that the LTTng module
166 * instrumentation headers match the kernel arguments. Will be optimized
167 * out by the compiler.
168 */
169
170 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
171
172 #undef TP_PROTO
173 #define TP_PROTO(args...) args
174
175 #undef TP_ARGS
176 #define TP_ARGS(args...) args
177
178 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
179 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
180 void trace_##_name(_proto);
181
182 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
183 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
184 void trace_##_name(void);
185
186 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
187
188 /*
189 * Stage 1.1 of the trace events.
190 *
191 * Create dummy trace prototypes for each event class, and for each used
192 * template. This will allow checking whether the prototypes from the
193 * class and the instance using the class actually match.
194 */
195
196 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
197
198 #undef TP_PROTO
199 #define TP_PROTO(args...) args
200
201 #undef TP_ARGS
202 #define TP_ARGS(args...) args
203
204 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
205 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
206 void __event_template_proto___##_template(_proto);
207
208 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
209 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
210 void __event_template_proto___##_template(void);
211
212 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
213 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
214 void __event_template_proto___##_name(_proto);
215
216 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
217 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
218 void __event_template_proto___##_name(void);
219
220 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
221
222 /*
223 * Stage 2 of the trace events.
224 *
225 * Create event field type metadata section.
226 * Each event produce an array of fields.
227 */
228
229 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
230
231 /* Named field types must be defined in lttng-types.h */
232
233 #undef __field_full
234 #define __field_full(_type, _item, _order, _base) \
235 { \
236 .name = #_item, \
237 .type = __type_integer(_type, _order, _base, none), \
238 },
239
240 #undef __field
241 #define __field(_type, _item) \
242 __field_full(_type, _item, __BYTE_ORDER, 10)
243
244 #undef __field_ext
245 #define __field_ext(_type, _item, _filter_type) \
246 __field(_type, _item)
247
248 #undef __field_hex
249 #define __field_hex(_type, _item) \
250 __field_full(_type, _item, __BYTE_ORDER, 16)
251
252 #undef __field_oct
253 #define __field_oct(_type, _item) \
254 __field_full(_type, _item, __BYTE_ORDER, 8)
255
256 #undef __field_network
257 #define __field_network(_type, _item) \
258 __field_full(_type, _item, __BIG_ENDIAN, 10)
259
260 #undef __field_network_hex
261 #define __field_network_hex(_type, _item) \
262 __field_full(_type, _item, __BIG_ENDIAN, 16)
263
264 #undef __array_enc_ext
265 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
266 { \
267 .name = #_item, \
268 .type = \
269 { \
270 .atype = atype_array, \
271 .u.array = \
272 { \
273 .length = _length, \
274 .elem_type = __type_integer(_type, _order, _base, _encoding), \
275 }, \
276 }, \
277 },
278
279 #undef __array
280 #define __array(_type, _item, _length) \
281 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
282
283 #undef __array_text
284 #define __array_text(_type, _item, _length) \
285 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
286
287 #undef __array_hex
288 #define __array_hex(_type, _item, _length) \
289 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
290
291 #undef __dynamic_array_enc_ext
292 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
293 { \
294 .name = #_item, \
295 .type = \
296 { \
297 .atype = atype_sequence, \
298 .u.sequence = \
299 { \
300 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
301 .elem_type = __type_integer(_type, _order, _base, _encoding), \
302 }, \
303 }, \
304 },
305
306 #undef __dynamic_array_enc_ext_2
307 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
308 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
309
310 #undef __dynamic_array
311 #define __dynamic_array(_type, _item, _length) \
312 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
313
314 #undef __dynamic_array_text
315 #define __dynamic_array_text(_type, _item, _length) \
316 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
317
318 #undef __dynamic_array_hex
319 #define __dynamic_array_hex(_type, _item, _length) \
320 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
321
322 #undef __dynamic_array_network_hex
323 #define __dynamic_array_network_hex(_type, _item, _length) \
324 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
325
326 #undef __dynamic_array_network
327 #define __dynamic_array_network(_type, _item, _length) \
328 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
329
330 #undef __dynamic_array_text_2
331 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
332 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
333
334 #undef __string
335 #define __string(_item, _src) \
336 { \
337 .name = #_item, \
338 .type = \
339 { \
340 .atype = atype_string, \
341 .u.basic.string.encoding = lttng_encode_UTF8, \
342 }, \
343 },
344
345 #undef __string_from_user
346 #define __string_from_user(_item, _src) \
347 __string(_item, _src)
348
349 #undef TP_STRUCT__entry
350 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
351
352 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
353 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
354 static const struct lttng_event_field __event_fields___##_name[] = { \
355 _tstruct \
356 };
357
358 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
359 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
360 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
361 PARAMS(_print))
362
363 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
364
365 /*
366 * Stage 3 of the trace events.
367 *
368 * Create probe callback prototypes.
369 */
370
371 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
372
373 #undef TP_PROTO
374 #define TP_PROTO(args...) args
375
376 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
377 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
378 static void __event_probe__##_name(void *__data, _proto);
379
380 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
381 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
382 static void __event_probe__##_name(void *__data);
383
384 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
385
386 /*
387 * Stage 3.9 of the trace events.
388 *
389 * Create event descriptions.
390 */
391
392 /* Named field types must be defined in lttng-types.h */
393
394 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
395
396 #ifndef TP_PROBE_CB
397 #define TP_PROBE_CB(_template) &__event_probe__##_template
398 #endif
399
400 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
401 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
402 static const struct lttng_event_desc __event_desc___##_map = { \
403 .fields = __event_fields___##_template, \
404 .name = #_map, \
405 .kname = #_name, \
406 .probe_callback = (void *) TP_PROBE_CB(_template), \
407 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
408 .owner = THIS_MODULE, \
409 };
410
411 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
412 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
413 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
414
415 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
416
417
418 /*
419 * Stage 4 of the trace events.
420 *
421 * Create an array of event description pointers.
422 */
423
424 /* Named field types must be defined in lttng-types.h */
425
426 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
427
428 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
429 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
430 &__event_desc___##_map,
431
432 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
433 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
434 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
435
436 #define TP_ID1(_token, _system) _token##_system
437 #define TP_ID(_token, _system) TP_ID1(_token, _system)
438
439 static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
440 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
441 };
442
443 #undef TP_ID1
444 #undef TP_ID
445
446
447 /*
448 * Stage 5 of the trace events.
449 *
450 * Create a toplevel descriptor for the whole probe.
451 */
452
453 #define TP_ID1(_token, _system) _token##_system
454 #define TP_ID(_token, _system) TP_ID1(_token, _system)
455
456 /* non-const because list head will be modified when registered. */
457 static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
458 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
459 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
460 };
461
462 #undef TP_ID1
463 #undef TP_ID
464
465 /*
466 * Stage 6 of the trace events.
467 *
468 * Create static inline function that calculates event size.
469 */
470
471 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
472
473 /* Named field types must be defined in lttng-types.h */
474
475 #undef __field_full
476 #define __field_full(_type, _item, _order, _base) \
477 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
478 __event_len += sizeof(_type);
479
480 #undef __array_enc_ext
481 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
482 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
483 __event_len += sizeof(_type) * (_length);
484
485 #undef __dynamic_array_enc_ext
486 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
487 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
488 __event_len += sizeof(u32); \
489 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
490 __dynamic_len[__dynamic_len_idx] = (_length); \
491 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
492 __dynamic_len_idx++;
493
494 #undef __dynamic_array_enc_ext_2
495 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
496 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
497 __event_len += sizeof(u32); \
498 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
499 __dynamic_len[__dynamic_len_idx] = (_length1); \
500 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
501 __dynamic_len_idx++; \
502 __dynamic_len[__dynamic_len_idx] = (_length2); \
503 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
504 __dynamic_len_idx++;
505
506 #undef __string
507 #define __string(_item, _src) \
508 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
509
510 /*
511 * strlen_user includes \0. If returns 0, it faulted, so we set size to
512 * 1 (\0 only).
513 */
514 #undef __string_from_user
515 #define __string_from_user(_item, _src) \
516 __event_len += __dynamic_len[__dynamic_len_idx++] = \
517 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
518
519 #undef TP_PROTO
520 #define TP_PROTO(args...) args
521
522 #undef TP_STRUCT__entry
523 #define TP_STRUCT__entry(args...) args
524
525 #undef TP_locvar
526 #define TP_locvar(...) __VA_ARGS__
527
528 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
529 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
530 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
531 void *__tp_locvar, _proto) \
532 { \
533 size_t __event_len = 0; \
534 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
535 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
536 \
537 _tstruct \
538 return __event_len; \
539 }
540
541 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
542 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
543 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
544 void *__tp_locvar) \
545 { \
546 size_t __event_len = 0; \
547 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
548 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
549 \
550 _tstruct \
551 return __event_len; \
552 }
553
554 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
555
556 /*
557 * Stage 7 of the trace events.
558 *
559 * Create static inline function that calculates event payload alignment.
560 */
561
562 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
563
564 /* Named field types must be defined in lttng-types.h */
565
566 #undef __field_full
567 #define __field_full(_type, _item, _order, _base) \
568 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
569
570 #undef __array_enc_ext
571 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
572 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
573
574 #undef __dynamic_array_enc_ext
575 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
576 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
577 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
578
579 #undef __dynamic_array_enc_ext_2
580 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
581 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
582
583 #undef __string
584 #define __string(_item, _src)
585
586 #undef __string_from_user
587 #define __string_from_user(_item, _src)
588
589 #undef TP_PROTO
590 #define TP_PROTO(args...) args
591
592 #undef TP_STRUCT__entry
593 #define TP_STRUCT__entry(args...) args
594
595 #undef TP_locvar
596 #define TP_locvar(...) __VA_ARGS__
597
598 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
599 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
600 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
601 { \
602 size_t __event_align = 1; \
603 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
604 \
605 _tstruct \
606 return __event_align; \
607 }
608
609 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
610 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
611 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
612 { \
613 size_t __event_align = 1; \
614 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
615 \
616 _tstruct \
617 return __event_align; \
618 }
619
620 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
621
622 /*
623 * Stage 8 of the trace events.
624 *
625 * Create structure declaration that allows the "assign" macros to access the
626 * field types.
627 */
628
629 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
630
631 /* Named field types must be defined in lttng-types.h */
632
633 #undef __field_full
634 #define __field_full(_type, _item, _order, _base) _type _item;
635
636 #undef __array_enc_ext
637 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
638 _type _item;
639
640 #undef __dynamic_array_enc_ext
641 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
642 _type _item;
643
644 #undef __dynamic_array_enc_ext_2
645 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
646 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
647
648 #undef __string
649 #define __string(_item, _src) char _item;
650
651 #undef __string_from_user
652 #define __string_from_user(_item, _src) \
653 __string(_item, _src)
654
655 #undef TP_STRUCT__entry
656 #define TP_STRUCT__entry(args...) args
657
658 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
659 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
660 struct __event_typemap__##_name { \
661 _tstruct \
662 };
663
664 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
665 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
666 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
667
668 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
669
670
671 /*
672 * Stage 9 of the trace events.
673 *
674 * Create the probe function : call even size calculation and write event data
675 * into the buffer.
676 *
677 * We use both the field and assignment macros to write the fields in the order
678 * defined in the field declaration. The field declarations control the
679 * execution order, jumping to the appropriate assignment block.
680 */
681
682 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
683
684 #undef __field_full
685 #define __field_full(_type, _item, _order, _base) \
686 goto __assign_##_item; \
687 __end_field_##_item:
688
689 #undef __array_enc_ext
690 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
691 goto __assign_##_item; \
692 __end_field_##_item:
693
694 #undef __dynamic_array_enc_ext
695 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
696 goto __assign_##_item##_1; \
697 __end_field_##_item##_1: \
698 goto __assign_##_item##_2; \
699 __end_field_##_item##_2:
700
701 #undef __dynamic_array_enc_ext_2
702 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
703 goto __assign_##_item##_1; \
704 __end_field_##_item##_1: \
705 goto __assign_##_item##_2; \
706 __end_field_##_item##_2: \
707 goto __assign_##_item##_3; \
708 __end_field_##_item##_3:
709
710 #undef __string
711 #define __string(_item, _src) \
712 goto __assign_##_item; \
713 __end_field_##_item:
714
715 #undef __string_from_user
716 #define __string_from_user(_item, _src) \
717 __string(_item, _src)
718
719 /*
720 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
721 * strcpy().
722 */
723 #undef tp_assign
724 #define tp_assign(dest, src) \
725 __assign_##dest: \
726 { \
727 __typeof__(__typemap.dest) __tmp = (src); \
728 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
729 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
730 } \
731 goto __end_field_##dest;
732
733 /* fixed length array memcpy */
734 #undef tp_memcpy_gen
735 #define tp_memcpy_gen(write_ops, dest, src, len) \
736 __assign_##dest: \
737 if (0) \
738 (void) __typemap.dest; \
739 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
740 __chan->ops->write_ops(&__ctx, src, len); \
741 goto __end_field_##dest;
742
743 #undef tp_memcpy
744 #define tp_memcpy(dest, src, len) \
745 tp_memcpy_gen(event_write, dest, src, len)
746
747 #undef tp_memcpy_from_user
748 #define tp_memcpy_from_user(dest, src, len) \
749 tp_memcpy_gen(event_write_from_user, dest, src, len)
750
751 /* variable length sequence memcpy */
752 #undef tp_memcpy_dyn_gen
753 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
754 __assign_##dest##_1: \
755 { \
756 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
757 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
758 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
759 } \
760 goto __end_field_##dest##_1; \
761 __assign_##dest##_2: \
762 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
763 __chan->ops->write_ops(&__ctx, src, \
764 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
765 goto __end_field_##dest##_2;
766
767 #undef tp_memcpy_dyn_gen_2
768 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
769 __assign_##dest##_1: \
770 { \
771 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
772 + __dynamic_len[__dynamic_len_idx + 1]; \
773 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
774 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
775 } \
776 goto __end_field_##dest##_1; \
777 __assign_##dest##_2: \
778 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
779 __chan->ops->write_ops(&__ctx, src1, \
780 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
781 goto __end_field_##dest##_2; \
782 __assign_##dest##_3: \
783 __chan->ops->write_ops(&__ctx, src2, \
784 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
785 goto __end_field_##dest##_3;
786
787 #undef tp_memcpy_dyn
788 #define tp_memcpy_dyn(dest, src) \
789 tp_memcpy_dyn_gen(event_write, dest, src)
790
791 #undef tp_memcpy_dyn_2
792 #define tp_memcpy_dyn_2(dest, src1, src2) \
793 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
794
795 #undef tp_memcpy_dyn_from_user
796 #define tp_memcpy_dyn_from_user(dest, src) \
797 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
798
799 /*
800 * The string length including the final \0.
801 */
802 #undef tp_copy_string_from_user
803 #define tp_copy_string_from_user(dest, src) \
804 __assign_##dest: \
805 if (0) \
806 (void) __typemap.dest; \
807 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
808 __chan->ops->event_strcpy_from_user(&__ctx, src, \
809 __get_dynamic_array_len(dest)); \
810 goto __end_field_##dest;
811
812 #undef tp_strcpy
813 #define tp_strcpy(dest, src) \
814 __assign_##dest: \
815 if (0) \
816 (void) __typemap.dest; \
817 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
818 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
819 goto __end_field_##dest;
820
821 /* Named field types must be defined in lttng-types.h */
822
823 #undef __get_str
824 #define __get_str(field) field
825
826 #undef __get_dynamic_array
827 #define __get_dynamic_array(field) field
828
829 /* Beware: this get len actually consumes the len value */
830 #undef __get_dynamic_array_len
831 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
832
833 #undef TP_PROTO
834 #define TP_PROTO(args...) args
835
836 #undef TP_ARGS
837 #define TP_ARGS(args...) args
838
839 #undef TP_STRUCT__entry
840 #define TP_STRUCT__entry(args...) args
841
842 #undef TP_fast_assign
843 #define TP_fast_assign(args...) args
844
845 #undef TP_locvar
846 #define TP_locvar(...) __VA_ARGS__
847
848 #undef TP_code
849 #define TP_code(...) __VA_ARGS__
850
851 /*
852 * For state dump, check that "session" argument (mandatory) matches the
853 * session this event belongs to. Ensures that we write state dump data only
854 * into the started session, not into all sessions.
855 */
856 #ifdef TP_SESSION_CHECK
857 #define _TP_SESSION_CHECK(session, csession) (session == csession)
858 #else /* TP_SESSION_CHECK */
859 #define _TP_SESSION_CHECK(session, csession) 1
860 #endif /* TP_SESSION_CHECK */
861
862 /*
863 * __dynamic_len array length is twice the number of fields due to
864 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
865 * worse case, needing 2 entries per field.
866 */
867 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
868 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
869 static void __event_probe__##_name(void *__data, _proto) \
870 { \
871 struct probe_local_vars { _locvar }; \
872 struct lttng_event *__event = __data; \
873 struct lttng_channel *__chan = __event->chan; \
874 struct lib_ring_buffer_ctx __ctx; \
875 size_t __event_len, __event_align; \
876 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
877 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
878 struct __event_typemap__##_name __typemap __attribute__((unused)); \
879 int __ret; \
880 struct probe_local_vars __tp_locvar; \
881 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
882 &__tp_locvar; \
883 \
884 if (!_TP_SESSION_CHECK(session, __chan->session)) \
885 return; \
886 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
887 return; \
888 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
889 return; \
890 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
891 return; \
892 _code \
893 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
894 _args); \
895 __event_align = __event_get_align__##_name(tp_locvar, _args); \
896 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
897 __event_align, -1); \
898 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
899 if (__ret < 0) \
900 return; \
901 /* Control code (field ordering) */ \
902 _tstruct \
903 __chan->ops->event_commit(&__ctx); \
904 return; \
905 /* Copy code, steered by control code */ \
906 _assign \
907 }
908
909 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
910 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
911 static void __event_probe__##_name(void *__data) \
912 { \
913 struct probe_local_vars { _locvar }; \
914 struct lttng_event *__event = __data; \
915 struct lttng_channel *__chan = __event->chan; \
916 struct lib_ring_buffer_ctx __ctx; \
917 size_t __event_len, __event_align; \
918 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
919 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
920 struct __event_typemap__##_name __typemap __attribute__((unused)); \
921 int __ret; \
922 struct probe_local_vars __tp_locvar; \
923 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
924 &__tp_locvar; \
925 \
926 if (!_TP_SESSION_CHECK(session, __chan->session)) \
927 return; \
928 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
929 return; \
930 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
931 return; \
932 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
933 return; \
934 _code \
935 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
936 __event_align = __event_get_align__##_name(tp_locvar); \
937 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
938 __event_align, -1); \
939 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
940 if (__ret < 0) \
941 return; \
942 /* Control code (field ordering) */ \
943 _tstruct \
944 __chan->ops->event_commit(&__ctx); \
945 return; \
946 /* Copy code, steered by control code */ \
947 _assign \
948 }
949
950 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
951
952 /*
953 * Stage 10 of the trace events.
954 *
955 * Register/unregister probes at module load/unload.
956 */
957
958 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
959
960 #define TP_ID1(_token, _system) _token##_system
961 #define TP_ID(_token, _system) TP_ID1(_token, _system)
962 #define module_init_eval1(_token, _system) module_init(_token##_system)
963 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
964 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
965 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
966
967 #ifndef TP_MODULE_NOINIT
968 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
969 {
970 wrapper_vmalloc_sync_all();
971 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
972 }
973
974 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
975 {
976 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
977 }
978
979 #ifndef TP_MODULE_NOAUTOLOAD
980 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
981 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
982 #endif
983
984 #endif
985
986 #undef module_init_eval
987 #undef module_exit_eval
988 #undef TP_ID1
989 #undef TP_ID
990
991 #undef TP_PROTO
992 #undef TP_ARGS
This page took 0.049875 seconds and 4 git commands to generate.