Dump FD flags and mode on state dump
[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 TRACE_EVENT_MAP
40 #define TRACE_EVENT_MAP(name, map, proto, args, tstruct, assign, print) \
41 DECLARE_EVENT_CLASS(map, \
42 PARAMS(proto), \
43 PARAMS(args), \
44 PARAMS(tstruct), \
45 PARAMS(assign), \
46 PARAMS(print)) \
47 DEFINE_EVENT_MAP(map, name, map, PARAMS(proto), PARAMS(args))
48
49 #undef TRACE_EVENT_MAP_NOARGS
50 #define TRACE_EVENT_MAP_NOARGS(name, map, tstruct, assign, print) \
51 DECLARE_EVENT_CLASS_NOARGS(map, \
52 PARAMS(tstruct), \
53 PARAMS(assign), \
54 PARAMS(print)) \
55 DEFINE_EVENT_MAP_NOARGS(map, name, map)
56
57 #undef DEFINE_EVENT_PRINT_MAP
58 #define DEFINE_EVENT_PRINT_MAP(template, name, map, proto, args, print) \
59 DEFINE_EVENT_MAP(template, name, map, PARAMS(proto), PARAMS(args))
60
61 /* Callbacks are meaningless to LTTng. */
62 #undef TRACE_EVENT_FN_MAP
63 #define TRACE_EVENT_FN_MAP(name, map, proto, args, tstruct, \
64 assign, print, reg, unreg) \
65 TRACE_EVENT_MAP(name, map, PARAMS(proto), PARAMS(args), \
66 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
67
68 #undef TRACE_EVENT_CONDITION_MAP
69 #define TRACE_EVENT_CONDITION_MAP(name, map, proto, args, cond, tstruct, assign, print) \
70 TRACE_EVENT_MAP(name, map, \
71 PARAMS(proto), \
72 PARAMS(args), \
73 PARAMS(tstruct), \
74 PARAMS(assign), \
75 PARAMS(print))
76
77 /*
78 * DECLARE_EVENT_CLASS can be used to add a generic function
79 * handlers for events. That is, if all events have the same
80 * parameters and just have distinct trace points.
81 * Each tracepoint can be defined with DEFINE_EVENT and that
82 * will map the DECLARE_EVENT_CLASS to the tracepoint.
83 *
84 * TRACE_EVENT is a one to one mapping between tracepoint and template.
85 */
86
87 #undef TRACE_EVENT
88 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
89 TRACE_EVENT_MAP(name, name, \
90 PARAMS(proto), \
91 PARAMS(args), \
92 PARAMS(tstruct), \
93 PARAMS(assign), \
94 PARAMS(print))
95
96 #undef TRACE_EVENT_NOARGS
97 #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \
98 TRACE_EVENT_MAP_NOARGS(name, name, \
99 PARAMS(tstruct), \
100 PARAMS(assign), \
101 PARAMS(print))
102
103 #undef DEFINE_EVENT_PRINT
104 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
105 DEFINE_EVENT_PRINT_MAP(template, name, name, \
106 PARAMS(proto), PARAMS(args), PARAMS(print_))
107
108 #undef TRACE_EVENT_FN
109 #define TRACE_EVENT_FN(name, proto, args, tstruct, \
110 assign, print, reg, unreg) \
111 TRACE_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
112 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
113 PARAMS(reg), PARAMS(unreg)) \
114
115 #undef DEFINE_EVENT
116 #define DEFINE_EVENT(template, name, proto, args) \
117 DEFINE_EVENT_MAP(template, name, name, PARAMS(proto), PARAMS(args))
118
119 #undef DEFINE_EVENT_NOARGS
120 #define DEFINE_EVENT_NOARGS(template, name) \
121 DEFINE_EVENT_MAP_NOARGS(template, name, name)
122
123 #undef TRACE_EVENT_CONDITION
124 #define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
125 TRACE_EVENT_CONDITION_MAP(name, name, \
126 PARAMS(proto), \
127 PARAMS(args), \
128 PARAMS(cond), \
129 PARAMS(tstruct), \
130 PARAMS(assign), \
131 PARAMS(print))
132
133 /*
134 * Stage 1 of the trace events.
135 *
136 * Create dummy trace calls for each events, verifying that the LTTng module
137 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
138 * compiler.
139 */
140
141 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
142
143 #undef TP_PROTO
144 #define TP_PROTO(args...) args
145
146 #undef TP_ARGS
147 #define TP_ARGS(args...) args
148
149 #undef DEFINE_EVENT_MAP
150 #define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
151 void trace_##_name(_proto);
152
153 #undef DEFINE_EVENT_MAP_NOARGS
154 #define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
155 void trace_##_name(void *__data);
156
157 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
158
159 /*
160 * Stage 2 of the trace events.
161 *
162 * Create event field type metadata section.
163 * Each event produce an array of fields.
164 */
165
166 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
167
168 /* Named field types must be defined in lttng-types.h */
169
170 #undef __field_full
171 #define __field_full(_type, _item, _order, _base) \
172 { \
173 .name = #_item, \
174 .type = __type_integer(_type, _order, _base, none), \
175 },
176
177 #undef __field
178 #define __field(_type, _item) \
179 __field_full(_type, _item, __BYTE_ORDER, 10)
180
181 #undef __field_ext
182 #define __field_ext(_type, _item, _filter_type) \
183 __field(_type, _item)
184
185 #undef __field_hex
186 #define __field_hex(_type, _item) \
187 __field_full(_type, _item, __BYTE_ORDER, 16)
188
189 #undef __field_oct
190 #define __field_oct(_type, _item) \
191 __field_full(_type, _item, __BYTE_ORDER, 8)
192
193 #undef __field_network
194 #define __field_network(_type, _item) \
195 __field_full(_type, _item, __BIG_ENDIAN, 10)
196
197 #undef __field_network_hex
198 #define __field_network_hex(_type, _item) \
199 __field_full(_type, _item, __BIG_ENDIAN, 16)
200
201 #undef __array_enc_ext
202 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
203 { \
204 .name = #_item, \
205 .type = \
206 { \
207 .atype = atype_array, \
208 .u.array = \
209 { \
210 .length = _length, \
211 .elem_type = __type_integer(_type, _order, _base, _encoding), \
212 }, \
213 }, \
214 },
215
216 #undef __array
217 #define __array(_type, _item, _length) \
218 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
219
220 #undef __array_text
221 #define __array_text(_type, _item, _length) \
222 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
223
224 #undef __array_hex
225 #define __array_hex(_type, _item, _length) \
226 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
227
228 #undef __dynamic_array_enc_ext
229 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
230 { \
231 .name = #_item, \
232 .type = \
233 { \
234 .atype = atype_sequence, \
235 .u.sequence = \
236 { \
237 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
238 .elem_type = __type_integer(_type, _order, _base, _encoding), \
239 }, \
240 }, \
241 },
242
243 #undef __dynamic_array_enc_ext_2
244 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
245 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
246
247 #undef __dynamic_array
248 #define __dynamic_array(_type, _item, _length) \
249 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
250
251 #undef __dynamic_array_text
252 #define __dynamic_array_text(_type, _item, _length) \
253 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
254
255 #undef __dynamic_array_hex
256 #define __dynamic_array_hex(_type, _item, _length) \
257 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
258
259 #undef __dynamic_array_text_2
260 #define __dynamic_array_text_2(_type, _item, _length1, _length2) \
261 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
262
263 #undef __string
264 #define __string(_item, _src) \
265 { \
266 .name = #_item, \
267 .type = \
268 { \
269 .atype = atype_string, \
270 .u.basic.string.encoding = lttng_encode_UTF8, \
271 }, \
272 },
273
274 #undef __string_from_user
275 #define __string_from_user(_item, _src) \
276 __string(_item, _src)
277
278 #undef TP_STRUCT__entry
279 #define TP_STRUCT__entry(args...) args /* Only one used in this phase */
280
281 #undef DECLARE_EVENT_CLASS_NOARGS
282 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
283 static const struct lttng_event_field __event_fields___##_name[] = { \
284 _tstruct \
285 };
286
287 #undef DECLARE_EVENT_CLASS
288 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
289 DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \
290 PARAMS(_print))
291
292 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
293
294 /*
295 * Stage 3 of the trace events.
296 *
297 * Create probe callback prototypes.
298 */
299
300 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
301
302 #undef TP_PROTO
303 #define TP_PROTO(args...) args
304
305 #undef DECLARE_EVENT_CLASS
306 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
307 static void __event_probe__##_name(void *__data, _proto);
308
309 #undef DECLARE_EVENT_CLASS_NOARGS
310 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
311 static void __event_probe__##_name(void *__data);
312
313 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
314
315 /*
316 * Stage 3.9 of the trace events.
317 *
318 * Create event descriptions.
319 */
320
321 /* Named field types must be defined in lttng-types.h */
322
323 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
324
325 #ifndef TP_PROBE_CB
326 #define TP_PROBE_CB(_template) &__event_probe__##_template
327 #endif
328
329 #undef DEFINE_EVENT_MAP_NOARGS
330 #define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
331 static const struct lttng_event_desc __event_desc___##_map = { \
332 .fields = __event_fields___##_template, \
333 .name = #_map, \
334 .kname = #_name, \
335 .probe_callback = (void *) TP_PROBE_CB(_template), \
336 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
337 .owner = THIS_MODULE, \
338 };
339
340 #undef DEFINE_EVENT_MAP
341 #define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
342 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
343
344 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
345
346
347 /*
348 * Stage 4 of the trace events.
349 *
350 * Create an array of event description pointers.
351 */
352
353 /* Named field types must be defined in lttng-types.h */
354
355 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
356
357 #undef DEFINE_EVENT_MAP_NOARGS
358 #define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
359 &__event_desc___##_map,
360
361 #undef DEFINE_EVENT_MAP
362 #define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
363 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
364
365 #define TP_ID1(_token, _system) _token##_system
366 #define TP_ID(_token, _system) TP_ID1(_token, _system)
367
368 static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
369 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
370 };
371
372 #undef TP_ID1
373 #undef TP_ID
374
375
376 /*
377 * Stage 5 of the trace events.
378 *
379 * Create a toplevel descriptor for the whole probe.
380 */
381
382 #define TP_ID1(_token, _system) _token##_system
383 #define TP_ID(_token, _system) TP_ID1(_token, _system)
384
385 /* non-const because list head will be modified when registered. */
386 static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
387 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
388 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
389 };
390
391 #undef TP_ID1
392 #undef TP_ID
393
394 /*
395 * Stage 6 of the trace events.
396 *
397 * Create static inline function that calculates event size.
398 */
399
400 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
401
402 /* Named field types must be defined in lttng-types.h */
403
404 #undef __field_full
405 #define __field_full(_type, _item, _order, _base) \
406 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
407 __event_len += sizeof(_type);
408
409 #undef __array_enc_ext
410 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
411 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
412 __event_len += sizeof(_type) * (_length);
413
414 #undef __dynamic_array_enc_ext
415 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
416 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
417 __event_len += sizeof(u32); \
418 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
419 __dynamic_len[__dynamic_len_idx] = (_length); \
420 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
421 __dynamic_len_idx++;
422
423 #undef __dynamic_array_enc_ext_2
424 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
425 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
426 __event_len += sizeof(u32); \
427 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
428 __dynamic_len[__dynamic_len_idx] = (_length1); \
429 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
430 __dynamic_len_idx++; \
431 __dynamic_len[__dynamic_len_idx] = (_length2); \
432 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
433 __dynamic_len_idx++;
434
435 #undef __string
436 #define __string(_item, _src) \
437 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
438
439 /*
440 * strlen_user includes \0. If returns 0, it faulted, so we set size to
441 * 1 (\0 only).
442 */
443 #undef __string_from_user
444 #define __string_from_user(_item, _src) \
445 __event_len += __dynamic_len[__dynamic_len_idx++] = \
446 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
447
448 #undef TP_PROTO
449 #define TP_PROTO(args...) args
450
451 #undef TP_STRUCT__entry
452 #define TP_STRUCT__entry(args...) args
453
454 #undef DECLARE_EVENT_CLASS
455 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
456 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \
457 { \
458 size_t __event_len = 0; \
459 unsigned int __dynamic_len_idx = 0; \
460 \
461 if (0) \
462 (void) __dynamic_len_idx; /* don't warn if unused */ \
463 _tstruct \
464 return __event_len; \
465 }
466
467 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
468
469 /*
470 * Stage 7 of the trace events.
471 *
472 * Create static inline function that calculates event payload alignment.
473 */
474
475 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
476
477 /* Named field types must be defined in lttng-types.h */
478
479 #undef __field_full
480 #define __field_full(_type, _item, _order, _base) \
481 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
482
483 #undef __array_enc_ext
484 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
485 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
486
487 #undef __dynamic_array_enc_ext
488 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
489 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
490 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
491
492 #undef __dynamic_array_enc_ext_2
493 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
494 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
495
496 #undef __string
497 #define __string(_item, _src)
498
499 #undef __string_from_user
500 #define __string_from_user(_item, _src)
501
502 #undef TP_PROTO
503 #define TP_PROTO(args...) args
504
505 #undef TP_STRUCT__entry
506 #define TP_STRUCT__entry(args...) args
507
508 #undef DECLARE_EVENT_CLASS
509 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
510 static inline size_t __event_get_align__##_name(_proto) \
511 { \
512 size_t __event_align = 1; \
513 _tstruct \
514 return __event_align; \
515 }
516
517 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
518
519
520 /*
521 * Stage 8 of the trace events.
522 *
523 * Create structure declaration that allows the "assign" macros to access the
524 * field types.
525 */
526
527 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
528
529 /* Named field types must be defined in lttng-types.h */
530
531 #undef __field_full
532 #define __field_full(_type, _item, _order, _base) _type _item;
533
534 #undef __array_enc_ext
535 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
536 _type _item;
537
538 #undef __dynamic_array_enc_ext
539 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
540 _type _item;
541
542 #undef __dynamic_array_enc_ext_2
543 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
544 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
545
546 #undef __string
547 #define __string(_item, _src) char _item;
548
549 #undef __string_from_user
550 #define __string_from_user(_item, _src) \
551 __string(_item, _src)
552
553 #undef TP_STRUCT__entry
554 #define TP_STRUCT__entry(args...) args
555
556 #undef DECLARE_EVENT_CLASS
557 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
558 struct __event_typemap__##_name { \
559 _tstruct \
560 };
561
562 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
563
564
565 /*
566 * Stage 9 of the trace events.
567 *
568 * Create the probe function : call even size calculation and write event data
569 * into the buffer.
570 *
571 * We use both the field and assignment macros to write the fields in the order
572 * defined in the field declaration. The field declarations control the
573 * execution order, jumping to the appropriate assignment block.
574 */
575
576 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
577
578 #undef __field_full
579 #define __field_full(_type, _item, _order, _base) \
580 goto __assign_##_item; \
581 __end_field_##_item:
582
583 #undef __array_enc_ext
584 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
585 goto __assign_##_item; \
586 __end_field_##_item:
587
588 #undef __dynamic_array_enc_ext
589 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
590 goto __assign_##_item##_1; \
591 __end_field_##_item##_1: \
592 goto __assign_##_item##_2; \
593 __end_field_##_item##_2:
594
595 #undef __dynamic_array_enc_ext_2
596 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
597 goto __assign_##_item##_1; \
598 __end_field_##_item##_1: \
599 goto __assign_##_item##_2; \
600 __end_field_##_item##_2: \
601 goto __assign_##_item##_3; \
602 __end_field_##_item##_3:
603
604 #undef __string
605 #define __string(_item, _src) \
606 goto __assign_##_item; \
607 __end_field_##_item:
608
609 #undef __string_from_user
610 #define __string_from_user(_item, _src) \
611 __string(_item, _src)
612
613 /*
614 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
615 * strcpy().
616 */
617 #undef tp_assign
618 #define tp_assign(dest, src) \
619 __assign_##dest: \
620 { \
621 __typeof__(__typemap.dest) __tmp = (src); \
622 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
623 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
624 } \
625 goto __end_field_##dest;
626
627 /* fixed length array memcpy */
628 #undef tp_memcpy_gen
629 #define tp_memcpy_gen(write_ops, dest, src, len) \
630 __assign_##dest: \
631 if (0) \
632 (void) __typemap.dest; \
633 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
634 __chan->ops->write_ops(&__ctx, src, len); \
635 goto __end_field_##dest;
636
637 #undef tp_memcpy
638 #define tp_memcpy(dest, src, len) \
639 tp_memcpy_gen(event_write, dest, src, len)
640
641 #undef tp_memcpy_from_user
642 #define tp_memcpy_from_user(dest, src, len) \
643 tp_memcpy_gen(event_write_from_user, dest, src, len)
644
645 /* variable length sequence memcpy */
646 #undef tp_memcpy_dyn_gen
647 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
648 __assign_##dest##_1: \
649 { \
650 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
651 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
652 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
653 } \
654 goto __end_field_##dest##_1; \
655 __assign_##dest##_2: \
656 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
657 __chan->ops->write_ops(&__ctx, src, \
658 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
659 goto __end_field_##dest##_2;
660
661 #undef tp_memcpy_dyn_gen_2
662 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
663 __assign_##dest##_1: \
664 { \
665 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
666 + __dynamic_len[__dynamic_len_idx + 1]; \
667 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
668 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
669 } \
670 goto __end_field_##dest##_1; \
671 __assign_##dest##_2: \
672 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
673 __chan->ops->write_ops(&__ctx, src1, \
674 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
675 goto __end_field_##dest##_2; \
676 __assign_##dest##_3: \
677 __chan->ops->write_ops(&__ctx, src2, \
678 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
679 goto __end_field_##dest##_3;
680
681 #undef tp_memcpy_dyn
682 #define tp_memcpy_dyn(dest, src) \
683 tp_memcpy_dyn_gen(event_write, dest, src)
684
685 #undef tp_memcpy_dyn_2
686 #define tp_memcpy_dyn_2(dest, src1, src2) \
687 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
688
689 #undef tp_memcpy_dyn_from_user
690 #define tp_memcpy_dyn_from_user(dest, src) \
691 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
692
693 /*
694 * The string length including the final \0.
695 */
696 #undef tp_copy_string_from_user
697 #define tp_copy_string_from_user(dest, src) \
698 __assign_##dest: \
699 if (0) \
700 (void) __typemap.dest; \
701 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
702 __chan->ops->event_strcpy_from_user(&__ctx, src, \
703 __get_dynamic_array_len(dest)); \
704 goto __end_field_##dest;
705
706 #undef tp_strcpy
707 #define tp_strcpy(dest, src) \
708 __assign_##dest: \
709 if (0) \
710 (void) __typemap.dest; \
711 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
712 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
713 goto __end_field_##dest;
714
715 /* Named field types must be defined in lttng-types.h */
716
717 #undef __get_str
718 #define __get_str(field) field
719
720 #undef __get_dynamic_array
721 #define __get_dynamic_array(field) field
722
723 /* Beware: this get len actually consumes the len value */
724 #undef __get_dynamic_array_len
725 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
726
727 #undef TP_PROTO
728 #define TP_PROTO(args...) args
729
730 #undef TP_ARGS
731 #define TP_ARGS(args...) args
732
733 #undef TP_STRUCT__entry
734 #define TP_STRUCT__entry(args...) args
735
736 #undef TP_fast_assign
737 #define TP_fast_assign(args...) args
738
739 /*
740 * For state dump, check that "session" argument (mandatory) matches the
741 * session this event belongs to. Ensures that we write state dump data only
742 * into the started session, not into all sessions.
743 */
744 #ifdef TP_SESSION_CHECK
745 #define _TP_SESSION_CHECK(session, csession) (session == csession)
746 #else /* TP_SESSION_CHECK */
747 #define _TP_SESSION_CHECK(session, csession) 1
748 #endif /* TP_SESSION_CHECK */
749
750 /*
751 * __dynamic_len array length is twice the number of fields due to
752 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
753 * worse case, needing 2 entries per field.
754 */
755 #undef DECLARE_EVENT_CLASS
756 #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
757 static void __event_probe__##_name(void *__data, _proto) \
758 { \
759 struct lttng_event *__event = __data; \
760 struct lttng_channel *__chan = __event->chan; \
761 struct lib_ring_buffer_ctx __ctx; \
762 size_t __event_len, __event_align; \
763 size_t __dynamic_len_idx = 0; \
764 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)]; \
765 struct __event_typemap__##_name __typemap; \
766 int __ret; \
767 \
768 if (0) { \
769 (void) __dynamic_len_idx; /* don't warn if unused */ \
770 (void) __typemap; /* don't warn if unused */ \
771 } \
772 if (!_TP_SESSION_CHECK(session, __chan->session)) \
773 return; \
774 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
775 return; \
776 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
777 return; \
778 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
779 return; \
780 __event_len = __event_get_size__##_name(__dynamic_len, _args); \
781 __event_align = __event_get_align__##_name(_args); \
782 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
783 __event_align, -1); \
784 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
785 if (__ret < 0) \
786 return; \
787 /* Control code (field ordering) */ \
788 _tstruct \
789 __chan->ops->event_commit(&__ctx); \
790 return; \
791 /* Copy code, steered by control code */ \
792 _assign \
793 }
794
795 #undef DECLARE_EVENT_CLASS_NOARGS
796 #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
797 static void __event_probe__##_name(void *__data) \
798 { \
799 struct lttng_event *__event = __data; \
800 struct lttng_channel *__chan = __event->chan; \
801 struct lib_ring_buffer_ctx __ctx; \
802 size_t __event_len, __event_align; \
803 int __ret; \
804 \
805 if (!_TP_SESSION_CHECK(session, __chan->session)) \
806 return; \
807 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
808 return; \
809 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
810 return; \
811 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
812 return; \
813 __event_len = 0; \
814 __event_align = 1; \
815 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
816 __event_align, -1); \
817 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
818 if (__ret < 0) \
819 return; \
820 /* Control code (field ordering) */ \
821 _tstruct \
822 __chan->ops->event_commit(&__ctx); \
823 return; \
824 /* Copy code, steered by control code */ \
825 _assign \
826 }
827
828 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
829
830 /*
831 * Stage 10 of the trace events.
832 *
833 * Register/unregister probes at module load/unload.
834 */
835
836 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
837
838 #define TP_ID1(_token, _system) _token##_system
839 #define TP_ID(_token, _system) TP_ID1(_token, _system)
840 #define module_init_eval1(_token, _system) module_init(_token##_system)
841 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
842 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
843 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
844
845 #ifndef TP_MODULE_NOINIT
846 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
847 {
848 wrapper_vmalloc_sync_all();
849 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
850 }
851
852 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
853 {
854 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
855 }
856
857 #ifndef TP_MODULE_NOAUTOLOAD
858 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
859 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
860 #endif
861
862 #endif
863
864 #undef module_init_eval
865 #undef module_exit_eval
866 #undef TP_ID1
867 #undef TP_ID
868
869 #undef TP_PROTO
870 #undef TP_ARGS
871 #undef TRACE_EVENT_FLAGS
This page took 0.04672 seconds and 4 git commands to generate.