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