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