Fix: check that class and instance prototype match
[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 /*
187 * Stage 1.1 of the trace events.
188 *
189 * Create dummy trace prototypes for each event class, and for each used
190 * template. This will allow checking whether the prototypes from the
191 * class and the instance using the class actually match.
192 */
193
194 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
195
196 #undef TP_PROTO
197 #define TP_PROTO(args...) args
198
199 #undef TP_ARGS
200 #define TP_ARGS(args...) args
201
202 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
203 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
204 void __event_template_proto___##_template(_proto);
205
206 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
207 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
208 void __event_template_proto___##_template(void);
209
210 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
211 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
212 void __event_template_proto___##_name(_proto);
213
214 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
215 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
216 void __event_template_proto___##_name(void);
217
218 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
219
220 /*
221 * Stage 2 of the trace events.
222 *
223 * Create event field type metadata section.
224 * Each event produce an array of fields.
225 */
226
227 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
228
229 /* Named field types must be defined in lttng-types.h */
230
231 #undef __field_full
232 #define __field_full(_type, _item, _order, _base) \
233 { \
234 .name = #_item, \
235 .type = __type_integer(_type, _order, _base, none), \
236 },
237
238 #undef __field
239 #define __field(_type, _item) \
240 __field_full(_type, _item, __BYTE_ORDER, 10)
241
242 #undef __field_ext
243 #define __field_ext(_type, _item, _filter_type) \
244 __field(_type, _item)
245
246 #undef __field_hex
247 #define __field_hex(_type, _item) \
248 __field_full(_type, _item, __BYTE_ORDER, 16)
249
250 #undef __field_oct
251 #define __field_oct(_type, _item) \
252 __field_full(_type, _item, __BYTE_ORDER, 8)
253
254 #undef __field_network
255 #define __field_network(_type, _item) \
256 __field_full(_type, _item, __BIG_ENDIAN, 10)
257
258 #undef __field_network_hex
259 #define __field_network_hex(_type, _item) \
260 __field_full(_type, _item, __BIG_ENDIAN, 16)
261
262 #undef __array_enc_ext
263 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
264 { \
265 .name = #_item, \
266 .type = \
267 { \
268 .atype = atype_array, \
269 .u.array = \
270 { \
271 .length = _length, \
272 .elem_type = __type_integer(_type, _order, _base, _encoding), \
273 }, \
274 }, \
275 },
276
277 #undef __array
278 #define __array(_type, _item, _length) \
279 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
280
281 #undef __array_text
282 #define __array_text(_type, _item, _length) \
283 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
284
285 #undef __array_hex
286 #define __array_hex(_type, _item, _length) \
287 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
288
289 #undef __dynamic_array_enc_ext
290 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
291 { \
292 .name = #_item, \
293 .type = \
294 { \
295 .atype = atype_sequence, \
296 .u.sequence = \
297 { \
298 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
299 .elem_type = __type_integer(_type, _order, _base, _encoding), \
300 }, \
301 }, \
302 },
303
304 #undef __dynamic_array_enc_ext_2
305 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
306 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
307
308 #undef __dynamic_array
309 #define __dynamic_array(_type, _item, _length) \
310 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
311
312 #undef __dynamic_array_text
313 #define __dynamic_array_text(_type, _item, _length) \
314 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
315
316 #undef __dynamic_array_hex
317 #define __dynamic_array_hex(_type, _item, _length) \
318 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
319
320 #undef __dynamic_array_network_hex
321 #define __dynamic_array_network_hex(_type, _item, _length) \
322 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
323
324 #undef __dynamic_array_network
325 #define __dynamic_array_network(_type, _item, _length) \
326 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
327
328 #undef __dynamic_array_text_2
329 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
330 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
331
332 #undef __string
333 #define __string(_item, _src) \
334 { \
335 .name = #_item, \
336 .type = \
337 { \
338 .atype = atype_string, \
339 .u.basic.string.encoding = lttng_encode_UTF8, \
340 }, \
341 },
342
343 #undef __string_from_user
344 #define __string_from_user(_item, _src) \
345 __string(_item, _src)
346
347 #undef TP_STRUCT__entry
348 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
349
350 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
351 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
352 static const struct lttng_event_field __event_fields___##_name[] = { \
353 _tstruct \
354 };
355
356 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
357 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
358 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
359 PARAMS(_print))
360
361 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
362
363 /*
364 * Stage 3 of the trace events.
365 *
366 * Create probe callback prototypes.
367 */
368
369 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
370
371 #undef TP_PROTO
372 #define TP_PROTO(args...) args
373
374 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
375 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
376 static void __event_probe__##_name(void *__data, _proto);
377
378 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
379 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
380 static void __event_probe__##_name(void *__data);
381
382 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
383
384 /*
385 * Stage 3.9 of the trace events.
386 *
387 * Create event descriptions.
388 */
389
390 /* Named field types must be defined in lttng-types.h */
391
392 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
393
394 #ifndef TP_PROBE_CB
395 #define TP_PROBE_CB(_template) &__event_probe__##_template
396 #endif
397
398 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
399 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
400 static const struct lttng_event_desc __event_desc___##_map = { \
401 .fields = __event_fields___##_template, \
402 .name = #_map, \
403 .kname = #_name, \
404 .probe_callback = (void *) TP_PROBE_CB(_template), \
405 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
406 .owner = THIS_MODULE, \
407 };
408
409 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
410 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
411 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
412
413 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
414
415
416 /*
417 * Stage 4 of the trace events.
418 *
419 * Create an array of event description pointers.
420 */
421
422 /* Named field types must be defined in lttng-types.h */
423
424 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
425
426 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
427 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
428 &__event_desc___##_map,
429
430 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
431 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
432 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
433
434 #define TP_ID1(_token, _system) _token##_system
435 #define TP_ID(_token, _system) TP_ID1(_token, _system)
436
437 static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
438 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
439 };
440
441 #undef TP_ID1
442 #undef TP_ID
443
444
445 /*
446 * Stage 5 of the trace events.
447 *
448 * Create a toplevel descriptor for the whole probe.
449 */
450
451 #define TP_ID1(_token, _system) _token##_system
452 #define TP_ID(_token, _system) TP_ID1(_token, _system)
453
454 /* non-const because list head will be modified when registered. */
455 static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
456 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
457 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
458 };
459
460 #undef TP_ID1
461 #undef TP_ID
462
463 /*
464 * Stage 6 of the trace events.
465 *
466 * Create static inline function that calculates event size.
467 */
468
469 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
470
471 /* Named field types must be defined in lttng-types.h */
472
473 #undef __field_full
474 #define __field_full(_type, _item, _order, _base) \
475 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
476 __event_len += sizeof(_type);
477
478 #undef __array_enc_ext
479 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
480 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
481 __event_len += sizeof(_type) * (_length);
482
483 #undef __dynamic_array_enc_ext
484 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
485 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
486 __event_len += sizeof(u32); \
487 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
488 __dynamic_len[__dynamic_len_idx] = (_length); \
489 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
490 __dynamic_len_idx++;
491
492 #undef __dynamic_array_enc_ext_2
493 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
494 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
495 __event_len += sizeof(u32); \
496 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
497 __dynamic_len[__dynamic_len_idx] = (_length1); \
498 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
499 __dynamic_len_idx++; \
500 __dynamic_len[__dynamic_len_idx] = (_length2); \
501 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
502 __dynamic_len_idx++;
503
504 #undef __string
505 #define __string(_item, _src) \
506 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
507
508 /*
509 * strlen_user includes \0. If returns 0, it faulted, so we set size to
510 * 1 (\0 only).
511 */
512 #undef __string_from_user
513 #define __string_from_user(_item, _src) \
514 __event_len += __dynamic_len[__dynamic_len_idx++] = \
515 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
516
517 #undef TP_PROTO
518 #define TP_PROTO(args...) args
519
520 #undef TP_STRUCT__entry
521 #define TP_STRUCT__entry(args...) args
522
523 #undef TP_locvar
524 #define TP_locvar(...) __VA_ARGS__
525
526 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
527 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
528 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
529 void *__tp_locvar, _proto) \
530 { \
531 size_t __event_len = 0; \
532 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
533 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
534 \
535 _tstruct \
536 return __event_len; \
537 }
538
539 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
540 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
541 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
542 void *__tp_locvar) \
543 { \
544 size_t __event_len = 0; \
545 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
546 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
547 \
548 _tstruct \
549 return __event_len; \
550 }
551
552 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
553
554 /*
555 * Stage 7 of the trace events.
556 *
557 * Create static inline function that calculates event payload alignment.
558 */
559
560 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
561
562 /* Named field types must be defined in lttng-types.h */
563
564 #undef __field_full
565 #define __field_full(_type, _item, _order, _base) \
566 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
567
568 #undef __array_enc_ext
569 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
570 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
571
572 #undef __dynamic_array_enc_ext
573 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
574 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
575 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
576
577 #undef __dynamic_array_enc_ext_2
578 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
579 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
580
581 #undef __string
582 #define __string(_item, _src)
583
584 #undef __string_from_user
585 #define __string_from_user(_item, _src)
586
587 #undef TP_PROTO
588 #define TP_PROTO(args...) args
589
590 #undef TP_STRUCT__entry
591 #define TP_STRUCT__entry(args...) args
592
593 #undef TP_locvar
594 #define TP_locvar(...) __VA_ARGS__
595
596 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
597 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
598 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
599 { \
600 size_t __event_align = 1; \
601 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
602 \
603 _tstruct \
604 return __event_align; \
605 }
606
607 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
608 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
609 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
610 { \
611 size_t __event_align = 1; \
612 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
613 \
614 _tstruct \
615 return __event_align; \
616 }
617
618 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
619
620 /*
621 * Stage 8 of the trace events.
622 *
623 * Create structure declaration that allows the "assign" macros to access the
624 * field types.
625 */
626
627 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
628
629 /* Named field types must be defined in lttng-types.h */
630
631 #undef __field_full
632 #define __field_full(_type, _item, _order, _base) _type _item;
633
634 #undef __array_enc_ext
635 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
636 _type _item;
637
638 #undef __dynamic_array_enc_ext
639 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
640 _type _item;
641
642 #undef __dynamic_array_enc_ext_2
643 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
644 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
645
646 #undef __string
647 #define __string(_item, _src) char _item;
648
649 #undef __string_from_user
650 #define __string_from_user(_item, _src) \
651 __string(_item, _src)
652
653 #undef TP_STRUCT__entry
654 #define TP_STRUCT__entry(args...) args
655
656 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
657 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
658 struct __event_typemap__##_name { \
659 _tstruct \
660 };
661
662 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
663 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
664 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
665
666 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
667
668
669 /*
670 * Stage 9 of the trace events.
671 *
672 * Create the probe function : call even size calculation and write event data
673 * into the buffer.
674 *
675 * We use both the field and assignment macros to write the fields in the order
676 * defined in the field declaration. The field declarations control the
677 * execution order, jumping to the appropriate assignment block.
678 */
679
680 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
681
682 #undef __field_full
683 #define __field_full(_type, _item, _order, _base) \
684 goto __assign_##_item; \
685 __end_field_##_item:
686
687 #undef __array_enc_ext
688 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
689 goto __assign_##_item; \
690 __end_field_##_item:
691
692 #undef __dynamic_array_enc_ext
693 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
694 goto __assign_##_item##_1; \
695 __end_field_##_item##_1: \
696 goto __assign_##_item##_2; \
697 __end_field_##_item##_2:
698
699 #undef __dynamic_array_enc_ext_2
700 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
701 goto __assign_##_item##_1; \
702 __end_field_##_item##_1: \
703 goto __assign_##_item##_2; \
704 __end_field_##_item##_2: \
705 goto __assign_##_item##_3; \
706 __end_field_##_item##_3:
707
708 #undef __string
709 #define __string(_item, _src) \
710 goto __assign_##_item; \
711 __end_field_##_item:
712
713 #undef __string_from_user
714 #define __string_from_user(_item, _src) \
715 __string(_item, _src)
716
717 /*
718 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
719 * strcpy().
720 */
721 #undef tp_assign
722 #define tp_assign(dest, src) \
723 __assign_##dest: \
724 { \
725 __typeof__(__typemap.dest) __tmp = (src); \
726 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
727 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
728 } \
729 goto __end_field_##dest;
730
731 /* fixed length array memcpy */
732 #undef tp_memcpy_gen
733 #define tp_memcpy_gen(write_ops, dest, src, len) \
734 __assign_##dest: \
735 if (0) \
736 (void) __typemap.dest; \
737 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
738 __chan->ops->write_ops(&__ctx, src, len); \
739 goto __end_field_##dest;
740
741 #undef tp_memcpy
742 #define tp_memcpy(dest, src, len) \
743 tp_memcpy_gen(event_write, dest, src, len)
744
745 #undef tp_memcpy_from_user
746 #define tp_memcpy_from_user(dest, src, len) \
747 tp_memcpy_gen(event_write_from_user, dest, src, len)
748
749 /* variable length sequence memcpy */
750 #undef tp_memcpy_dyn_gen
751 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
752 __assign_##dest##_1: \
753 { \
754 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
755 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
756 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
757 } \
758 goto __end_field_##dest##_1; \
759 __assign_##dest##_2: \
760 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
761 __chan->ops->write_ops(&__ctx, src, \
762 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
763 goto __end_field_##dest##_2;
764
765 #undef tp_memcpy_dyn_gen_2
766 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
767 __assign_##dest##_1: \
768 { \
769 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
770 + __dynamic_len[__dynamic_len_idx + 1]; \
771 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
772 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
773 } \
774 goto __end_field_##dest##_1; \
775 __assign_##dest##_2: \
776 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
777 __chan->ops->write_ops(&__ctx, src1, \
778 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
779 goto __end_field_##dest##_2; \
780 __assign_##dest##_3: \
781 __chan->ops->write_ops(&__ctx, src2, \
782 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
783 goto __end_field_##dest##_3;
784
785 #undef tp_memcpy_dyn
786 #define tp_memcpy_dyn(dest, src) \
787 tp_memcpy_dyn_gen(event_write, dest, src)
788
789 #undef tp_memcpy_dyn_2
790 #define tp_memcpy_dyn_2(dest, src1, src2) \
791 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
792
793 #undef tp_memcpy_dyn_from_user
794 #define tp_memcpy_dyn_from_user(dest, src) \
795 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
796
797 /*
798 * The string length including the final \0.
799 */
800 #undef tp_copy_string_from_user
801 #define tp_copy_string_from_user(dest, src) \
802 __assign_##dest: \
803 if (0) \
804 (void) __typemap.dest; \
805 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
806 __chan->ops->event_strcpy_from_user(&__ctx, src, \
807 __get_dynamic_array_len(dest)); \
808 goto __end_field_##dest;
809
810 #undef tp_strcpy
811 #define tp_strcpy(dest, src) \
812 __assign_##dest: \
813 if (0) \
814 (void) __typemap.dest; \
815 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
816 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
817 goto __end_field_##dest;
818
819 /* Named field types must be defined in lttng-types.h */
820
821 #undef __get_str
822 #define __get_str(field) field
823
824 #undef __get_dynamic_array
825 #define __get_dynamic_array(field) field
826
827 /* Beware: this get len actually consumes the len value */
828 #undef __get_dynamic_array_len
829 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
830
831 #undef TP_PROTO
832 #define TP_PROTO(args...) args
833
834 #undef TP_ARGS
835 #define TP_ARGS(args...) args
836
837 #undef TP_STRUCT__entry
838 #define TP_STRUCT__entry(args...) args
839
840 #undef TP_fast_assign
841 #define TP_fast_assign(args...) args
842
843 #undef TP_locvar
844 #define TP_locvar(...) __VA_ARGS__
845
846 #undef TP_code
847 #define TP_code(...) __VA_ARGS__
848
849 /*
850 * For state dump, check that "session" argument (mandatory) matches the
851 * session this event belongs to. Ensures that we write state dump data only
852 * into the started session, not into all sessions.
853 */
854 #ifdef TP_SESSION_CHECK
855 #define _TP_SESSION_CHECK(session, csession) (session == csession)
856 #else /* TP_SESSION_CHECK */
857 #define _TP_SESSION_CHECK(session, csession) 1
858 #endif /* TP_SESSION_CHECK */
859
860 /*
861 * __dynamic_len array length is twice the number of fields due to
862 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
863 * worse case, needing 2 entries per field.
864 */
865 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
866 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
867 static void __event_probe__##_name(void *__data, _proto) \
868 { \
869 struct probe_local_vars { _locvar }; \
870 struct lttng_event *__event = __data; \
871 struct lttng_channel *__chan = __event->chan; \
872 struct lib_ring_buffer_ctx __ctx; \
873 size_t __event_len, __event_align; \
874 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
875 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
876 struct __event_typemap__##_name __typemap __attribute__((unused)); \
877 int __ret; \
878 struct probe_local_vars __tp_locvar; \
879 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
880 &__tp_locvar; \
881 \
882 if (!_TP_SESSION_CHECK(session, __chan->session)) \
883 return; \
884 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
885 return; \
886 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
887 return; \
888 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
889 return; \
890 _code \
891 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
892 _args); \
893 __event_align = __event_get_align__##_name(tp_locvar, _args); \
894 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
895 __event_align, -1); \
896 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
897 if (__ret < 0) \
898 return; \
899 /* Control code (field ordering) */ \
900 _tstruct \
901 __chan->ops->event_commit(&__ctx); \
902 return; \
903 /* Copy code, steered by control code */ \
904 _assign \
905 }
906
907 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
908 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
909 static void __event_probe__##_name(void *__data) \
910 { \
911 struct probe_local_vars { _locvar }; \
912 struct lttng_event *__event = __data; \
913 struct lttng_channel *__chan = __event->chan; \
914 struct lib_ring_buffer_ctx __ctx; \
915 size_t __event_len, __event_align; \
916 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
917 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
918 struct __event_typemap__##_name __typemap __attribute__((unused)); \
919 int __ret; \
920 struct probe_local_vars __tp_locvar; \
921 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
922 &__tp_locvar; \
923 \
924 if (!_TP_SESSION_CHECK(session, __chan->session)) \
925 return; \
926 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
927 return; \
928 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
929 return; \
930 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
931 return; \
932 _code \
933 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
934 __event_align = __event_get_align__##_name(tp_locvar); \
935 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
936 __event_align, -1); \
937 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
938 if (__ret < 0) \
939 return; \
940 /* Control code (field ordering) */ \
941 _tstruct \
942 __chan->ops->event_commit(&__ctx); \
943 return; \
944 /* Copy code, steered by control code */ \
945 _assign \
946 }
947
948 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
949
950 /*
951 * Stage 10 of the trace events.
952 *
953 * Register/unregister probes at module load/unload.
954 */
955
956 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
957
958 #define TP_ID1(_token, _system) _token##_system
959 #define TP_ID(_token, _system) TP_ID1(_token, _system)
960 #define module_init_eval1(_token, _system) module_init(_token##_system)
961 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
962 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
963 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
964
965 #ifndef TP_MODULE_NOINIT
966 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
967 {
968 wrapper_vmalloc_sync_all();
969 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
970 }
971
972 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
973 {
974 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
975 }
976
977 #ifndef TP_MODULE_NOAUTOLOAD
978 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
979 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
980 #endif
981
982 #endif
983
984 #undef module_init_eval
985 #undef module_exit_eval
986 #undef TP_ID1
987 #undef TP_ID
988
989 #undef TP_PROTO
990 #undef TP_ARGS
This page took 0.04958 seconds and 4 git commands to generate.