Implement PID tracking
[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 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
425 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
426 };
427
428 #undef TP_ID1
429 #undef TP_ID
430
431 /*
432 * Stage 6 of the trace events.
433 *
434 * Create static inline function that calculates event size.
435 */
436
437 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
438
439 /* Named field types must be defined in lttng-types.h */
440
441 #undef __field_full
442 #define __field_full(_type, _item, _order, _base) \
443 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
444 __event_len += sizeof(_type);
445
446 #undef __array_enc_ext
447 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
448 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
449 __event_len += sizeof(_type) * (_length);
450
451 #undef __dynamic_array_enc_ext
452 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
453 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
454 __event_len += sizeof(u32); \
455 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
456 __dynamic_len[__dynamic_len_idx] = (_length); \
457 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
458 __dynamic_len_idx++;
459
460 #undef __dynamic_array_enc_ext_2
461 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
462 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
463 __event_len += sizeof(u32); \
464 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
465 __dynamic_len[__dynamic_len_idx] = (_length1); \
466 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
467 __dynamic_len_idx++; \
468 __dynamic_len[__dynamic_len_idx] = (_length2); \
469 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
470 __dynamic_len_idx++;
471
472 #undef __string
473 #define __string(_item, _src) \
474 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
475
476 /*
477 * strlen_user includes \0. If returns 0, it faulted, so we set size to
478 * 1 (\0 only).
479 */
480 #undef __string_from_user
481 #define __string_from_user(_item, _src) \
482 __event_len += __dynamic_len[__dynamic_len_idx++] = \
483 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
484
485 #undef TP_PROTO
486 #define TP_PROTO(args...) args
487
488 #undef TP_STRUCT__entry
489 #define TP_STRUCT__entry(args...) args
490
491 #undef TP_locvar
492 #define TP_locvar(...) __VA_ARGS__
493
494 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
495 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
496 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
497 void *__tp_locvar, _proto) \
498 { \
499 size_t __event_len = 0; \
500 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
501 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
502 \
503 _tstruct \
504 return __event_len; \
505 }
506
507 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
508 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
509 static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
510 void *__tp_locvar) \
511 { \
512 size_t __event_len = 0; \
513 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
514 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
515 \
516 _tstruct \
517 return __event_len; \
518 }
519
520 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
521
522 /*
523 * Stage 7 of the trace events.
524 *
525 * Create static inline function that calculates event payload alignment.
526 */
527
528 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
529
530 /* Named field types must be defined in lttng-types.h */
531
532 #undef __field_full
533 #define __field_full(_type, _item, _order, _base) \
534 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
535
536 #undef __array_enc_ext
537 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
538 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
539
540 #undef __dynamic_array_enc_ext
541 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
542 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
543 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
544
545 #undef __dynamic_array_enc_ext_2
546 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
547 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
548
549 #undef __string
550 #define __string(_item, _src)
551
552 #undef __string_from_user
553 #define __string_from_user(_item, _src)
554
555 #undef TP_PROTO
556 #define TP_PROTO(args...) args
557
558 #undef TP_STRUCT__entry
559 #define TP_STRUCT__entry(args...) args
560
561 #undef TP_locvar
562 #define TP_locvar(...) __VA_ARGS__
563
564 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
565 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
566 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
567 { \
568 size_t __event_align = 1; \
569 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
570 \
571 _tstruct \
572 return __event_align; \
573 }
574
575 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
576 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
577 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
578 { \
579 size_t __event_align = 1; \
580 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
581 \
582 _tstruct \
583 return __event_align; \
584 }
585
586 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
587
588 /*
589 * Stage 8 of the trace events.
590 *
591 * Create structure declaration that allows the "assign" macros to access the
592 * field types.
593 */
594
595 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
596
597 /* Named field types must be defined in lttng-types.h */
598
599 #undef __field_full
600 #define __field_full(_type, _item, _order, _base) _type _item;
601
602 #undef __array_enc_ext
603 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
604 _type _item;
605
606 #undef __dynamic_array_enc_ext
607 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
608 _type _item;
609
610 #undef __dynamic_array_enc_ext_2
611 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
612 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
613
614 #undef __string
615 #define __string(_item, _src) char _item;
616
617 #undef __string_from_user
618 #define __string_from_user(_item, _src) \
619 __string(_item, _src)
620
621 #undef TP_STRUCT__entry
622 #define TP_STRUCT__entry(args...) args
623
624 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
625 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
626 struct __event_typemap__##_name { \
627 _tstruct \
628 };
629
630 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
631 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
632 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
633
634 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
635
636
637 /*
638 * Stage 9 of the trace events.
639 *
640 * Create the probe function : call even size calculation and write event data
641 * into the buffer.
642 *
643 * We use both the field and assignment macros to write the fields in the order
644 * defined in the field declaration. The field declarations control the
645 * execution order, jumping to the appropriate assignment block.
646 */
647
648 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
649
650 #undef __field_full
651 #define __field_full(_type, _item, _order, _base) \
652 goto __assign_##_item; \
653 __end_field_##_item:
654
655 #undef __array_enc_ext
656 #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
657 goto __assign_##_item; \
658 __end_field_##_item:
659
660 #undef __dynamic_array_enc_ext
661 #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
662 goto __assign_##_item##_1; \
663 __end_field_##_item##_1: \
664 goto __assign_##_item##_2; \
665 __end_field_##_item##_2:
666
667 #undef __dynamic_array_enc_ext_2
668 #define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
669 goto __assign_##_item##_1; \
670 __end_field_##_item##_1: \
671 goto __assign_##_item##_2; \
672 __end_field_##_item##_2: \
673 goto __assign_##_item##_3; \
674 __end_field_##_item##_3:
675
676 #undef __string
677 #define __string(_item, _src) \
678 goto __assign_##_item; \
679 __end_field_##_item:
680
681 #undef __string_from_user
682 #define __string_from_user(_item, _src) \
683 __string(_item, _src)
684
685 /*
686 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
687 * strcpy().
688 */
689 #undef tp_assign
690 #define tp_assign(dest, src) \
691 __assign_##dest: \
692 { \
693 __typeof__(__typemap.dest) __tmp = (src); \
694 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
695 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
696 } \
697 goto __end_field_##dest;
698
699 /* fixed length array memcpy */
700 #undef tp_memcpy_gen
701 #define tp_memcpy_gen(write_ops, dest, src, len) \
702 __assign_##dest: \
703 if (0) \
704 (void) __typemap.dest; \
705 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
706 __chan->ops->write_ops(&__ctx, src, len); \
707 goto __end_field_##dest;
708
709 #undef tp_memcpy
710 #define tp_memcpy(dest, src, len) \
711 tp_memcpy_gen(event_write, dest, src, len)
712
713 #undef tp_memcpy_from_user
714 #define tp_memcpy_from_user(dest, src, len) \
715 tp_memcpy_gen(event_write_from_user, dest, src, len)
716
717 /* variable length sequence memcpy */
718 #undef tp_memcpy_dyn_gen
719 #define tp_memcpy_dyn_gen(write_ops, dest, src) \
720 __assign_##dest##_1: \
721 { \
722 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
723 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
724 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
725 } \
726 goto __end_field_##dest##_1; \
727 __assign_##dest##_2: \
728 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
729 __chan->ops->write_ops(&__ctx, src, \
730 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
731 goto __end_field_##dest##_2;
732
733 #undef tp_memcpy_dyn_gen_2
734 #define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
735 __assign_##dest##_1: \
736 { \
737 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
738 + __dynamic_len[__dynamic_len_idx + 1]; \
739 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
740 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
741 } \
742 goto __end_field_##dest##_1; \
743 __assign_##dest##_2: \
744 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
745 __chan->ops->write_ops(&__ctx, src1, \
746 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
747 goto __end_field_##dest##_2; \
748 __assign_##dest##_3: \
749 __chan->ops->write_ops(&__ctx, src2, \
750 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
751 goto __end_field_##dest##_3;
752
753 #undef tp_memcpy_dyn
754 #define tp_memcpy_dyn(dest, src) \
755 tp_memcpy_dyn_gen(event_write, dest, src)
756
757 #undef tp_memcpy_dyn_2
758 #define tp_memcpy_dyn_2(dest, src1, src2) \
759 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
760
761 #undef tp_memcpy_dyn_from_user
762 #define tp_memcpy_dyn_from_user(dest, src) \
763 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
764
765 /*
766 * The string length including the final \0.
767 */
768 #undef tp_copy_string_from_user
769 #define tp_copy_string_from_user(dest, src) \
770 __assign_##dest: \
771 if (0) \
772 (void) __typemap.dest; \
773 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
774 __chan->ops->event_strcpy_from_user(&__ctx, src, \
775 __get_dynamic_array_len(dest)); \
776 goto __end_field_##dest;
777
778 #undef tp_strcpy
779 #define tp_strcpy(dest, src) \
780 __assign_##dest: \
781 if (0) \
782 (void) __typemap.dest; \
783 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
784 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
785 goto __end_field_##dest;
786
787 /* Named field types must be defined in lttng-types.h */
788
789 #undef __get_str
790 #define __get_str(field) field
791
792 #undef __get_dynamic_array
793 #define __get_dynamic_array(field) field
794
795 /* Beware: this get len actually consumes the len value */
796 #undef __get_dynamic_array_len
797 #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
798
799 #undef TP_PROTO
800 #define TP_PROTO(args...) args
801
802 #undef TP_ARGS
803 #define TP_ARGS(args...) args
804
805 #undef TP_STRUCT__entry
806 #define TP_STRUCT__entry(args...) args
807
808 #undef TP_fast_assign
809 #define TP_fast_assign(args...) args
810
811 #undef TP_locvar
812 #define TP_locvar(...) __VA_ARGS__
813
814 #undef TP_code
815 #define TP_code(...) __VA_ARGS__
816
817 /*
818 * For state dump, check that "session" argument (mandatory) matches the
819 * session this event belongs to. Ensures that we write state dump data only
820 * into the started session, not into all sessions.
821 */
822 #ifdef TP_SESSION_CHECK
823 #define _TP_SESSION_CHECK(session, csession) (session == csession)
824 #else /* TP_SESSION_CHECK */
825 #define _TP_SESSION_CHECK(session, csession) 1
826 #endif /* TP_SESSION_CHECK */
827
828 /*
829 * __dynamic_len array length is twice the number of fields due to
830 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
831 * worse case, needing 2 entries per field.
832 */
833 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
834 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
835 static void __event_probe__##_name(void *__data, _proto) \
836 { \
837 struct probe_local_vars { _locvar }; \
838 struct lttng_event *__event = __data; \
839 struct lttng_channel *__chan = __event->chan; \
840 struct lttng_session *__session = __chan->session; \
841 struct lib_ring_buffer_ctx __ctx; \
842 size_t __event_len, __event_align; \
843 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
844 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
845 struct __event_typemap__##_name __typemap __attribute__((unused)); \
846 int __ret; \
847 struct probe_local_vars __tp_locvar; \
848 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
849 &__tp_locvar; \
850 struct lttng_pid_tracker *__lpf; \
851 \
852 if (!_TP_SESSION_CHECK(session, __session)) \
853 return; \
854 if (unlikely(!ACCESS_ONCE(__session->active))) \
855 return; \
856 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
857 return; \
858 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
859 return; \
860 __lpf = rcu_dereference(__session->pid_tracker); \
861 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
862 return; \
863 _code \
864 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
865 _args); \
866 __event_align = __event_get_align__##_name(tp_locvar, _args); \
867 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
868 __event_align, -1); \
869 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
870 if (__ret < 0) \
871 return; \
872 /* Control code (field ordering) */ \
873 _tstruct \
874 __chan->ops->event_commit(&__ctx); \
875 return; \
876 /* Copy code, steered by control code */ \
877 _assign \
878 }
879
880 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
881 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
882 static void __event_probe__##_name(void *__data) \
883 { \
884 struct probe_local_vars { _locvar }; \
885 struct lttng_event *__event = __data; \
886 struct lttng_channel *__chan = __event->chan; \
887 struct lttng_session *__session = __chan->session; \
888 struct lib_ring_buffer_ctx __ctx; \
889 size_t __event_len, __event_align; \
890 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
891 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
892 struct __event_typemap__##_name __typemap __attribute__((unused)); \
893 int __ret; \
894 struct probe_local_vars __tp_locvar; \
895 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
896 &__tp_locvar; \
897 struct lttng_pid_tracker *__lpf; \
898 \
899 if (!_TP_SESSION_CHECK(session, __session)) \
900 return; \
901 if (unlikely(!ACCESS_ONCE(__session->active))) \
902 return; \
903 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
904 return; \
905 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
906 return; \
907 __lpf = rcu_dereference(__session->pid_tracker); \
908 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
909 return; \
910 _code \
911 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
912 __event_align = __event_get_align__##_name(tp_locvar); \
913 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
914 __event_align, -1); \
915 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
916 if (__ret < 0) \
917 return; \
918 /* Control code (field ordering) */ \
919 _tstruct \
920 __chan->ops->event_commit(&__ctx); \
921 return; \
922 /* Copy code, steered by control code */ \
923 _assign \
924 }
925
926 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
927
928 /*
929 * Stage 10 of the trace events.
930 *
931 * Register/unregister probes at module load/unload.
932 */
933
934 #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
935
936 #define TP_ID1(_token, _system) _token##_system
937 #define TP_ID(_token, _system) TP_ID1(_token, _system)
938 #define module_init_eval1(_token, _system) module_init(_token##_system)
939 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
940 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
941 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
942
943 #ifndef TP_MODULE_NOINIT
944 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
945 {
946 wrapper_vmalloc_sync_all();
947 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
948 }
949
950 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
951 {
952 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
953 }
954
955 #ifndef TP_MODULE_NOAUTOLOAD
956 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
957 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
958 #endif
959
960 #endif
961
962 #undef module_init_eval
963 #undef module_exit_eval
964 #undef TP_ID1
965 #undef TP_ID
966
967 #undef TP_PROTO
968 #undef TP_ARGS
This page took 0.048665 seconds and 4 git commands to generate.