Implement enumeration type
[lttng-modules.git] / probes / lttng-tracepoint-event-impl.h
1 /*
2 * lttng-tracepoint-event-impl.h
3 *
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
5 * Copyright (C) 2009-2014 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
22 #include <linux/uaccess.h>
23 #include <linux/debugfs.h>
24 #include <linux/rculist.h>
25 #include <asm/byteorder.h>
26 #include <linux/swab.h>
27
28 #include <probes/lttng.h>
29 #include <probes/lttng-types.h>
30 #include <probes/lttng-probe-user.h>
31 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
32 #include <wrapper/ringbuffer/frontend_types.h>
33 #include <wrapper/ringbuffer/backend.h>
34 #include <wrapper/rcu.h>
35 #include <lttng-events.h>
36 #include <lttng-tracer-core.h>
37
38 /*
39 * Macro declarations used for all stages.
40 */
41
42 /*
43 * LTTng name mapping macros. LTTng remaps some of the kernel events to
44 * enforce name-spacing.
45 */
46 #undef LTTNG_TRACEPOINT_EVENT_MAP
47 #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
48 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
49 PARAMS(proto), \
50 PARAMS(args), \
51 PARAMS(fields)) \
52 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
53
54 #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
55 #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
56 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
57 PARAMS(fields)) \
58 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
59
60 #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
61 #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \
62 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
63 PARAMS(proto), \
64 PARAMS(args), \
65 PARAMS(_locvar), \
66 PARAMS(_code_pre), \
67 PARAMS(fields), \
68 PARAMS(_code_post)) \
69 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
70
71 #undef LTTNG_TRACEPOINT_EVENT_CODE
72 #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \
73 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
74 PARAMS(proto), \
75 PARAMS(args), \
76 PARAMS(_locvar), \
77 PARAMS(_code_pre), \
78 PARAMS(fields), \
79 PARAMS(_code_post))
80
81 /*
82 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
83 * handlers for events. That is, if all events have the same parameters
84 * and just have distinct trace points. Each tracepoint can be defined
85 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
86 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
87 *
88 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
89 * template.
90 */
91
92 #undef LTTNG_TRACEPOINT_EVENT
93 #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
94 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
95 PARAMS(proto), \
96 PARAMS(args), \
97 PARAMS(fields))
98
99 #undef LTTNG_TRACEPOINT_EVENT_NOARGS
100 #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
101 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
102
103 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE
104 #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
105 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
106
107 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
108 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
109 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
110
111 #undef LTTNG_TRACEPOINT_EVENT_CLASS
112 #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
113 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
114 PARAMS(_fields), )
115
116 #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
117 #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
118 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), )
119
120
121 /*
122 * Stage 1 of the trace events.
123 *
124 * Create dummy trace calls for each events, verifying that the LTTng module
125 * instrumentation headers match the kernel arguments. Will be optimized
126 * out by the compiler.
127 */
128
129 /* Reset all macros within TRACEPOINT_EVENT */
130 #include <probes/lttng-events-reset.h>
131
132 #undef TP_PROTO
133 #define TP_PROTO(...) __VA_ARGS__
134
135 #undef TP_ARGS
136 #define TP_ARGS(...) __VA_ARGS__
137
138 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
139 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
140 void trace_##_name(_proto);
141
142 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
143 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
144 void trace_##_name(void);
145
146 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
147
148 /*
149 * Stage 1.1 of the trace events.
150 *
151 * Create dummy trace prototypes for each event class, and for each used
152 * template. This will allow checking whether the prototypes from the
153 * class and the instance using the class actually match.
154 */
155
156 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
157
158 #undef TP_PROTO
159 #define TP_PROTO(...) __VA_ARGS__
160
161 #undef TP_ARGS
162 #define TP_ARGS(...) __VA_ARGS__
163
164 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
165 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
166 void __event_template_proto___##_template(_proto);
167
168 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
169 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
170 void __event_template_proto___##_template(void);
171
172 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
173 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
174 void __event_template_proto___##_name(_proto);
175
176 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
177 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
178 void __event_template_proto___##_name(void);
179
180 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
181
182 /*
183 * Stage 1.2 of tracepoint event generation
184 *
185 * Unfolding the enums
186 */
187 #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
188
189 /* Enumeration entry (single value) */
190 #undef ctf_enum_value
191 #define ctf_enum_value(_string, _value) \
192 { \
193 .start = { \
194 .signedness = lttng_is_signed_type(__typeof__(_value)), \
195 .value = lttng_is_signed_type(__typeof__(_value)) ? \
196 (long long) (_value) : (_value), \
197 }, \
198 .end = { \
199 .signedness = lttng_is_signed_type(__typeof__(_value)), \
200 .value = lttng_is_signed_type(__typeof__(_value)) ? \
201 (long long) (_value) : (_value), \
202 }, \
203 .string = (_string), \
204 },
205
206 /* Enumeration entry (range) */
207 #undef ctf_enum_range
208 #define ctf_enum_range(_string, _range_start, _range_end) \
209 { \
210 .start = { \
211 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
212 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
213 (long long) (_range_start) : (_range_start), \
214 }, \
215 .end = { \
216 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
217 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
218 (long long) (_range_end) : (_range_end), \
219 }, \
220 .string = (_string), \
221 },
222
223 #undef TP_ENUM_VALUES
224 #define TP_ENUM_VALUES(...) \
225 __VA_ARGS__
226
227 #undef LTTNG_TRACEPOINT_ENUM
228 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
229 const struct lttng_enum_entry __enum_values__##_name[] = { \
230 _values \
231 };
232
233 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
234
235 /*
236 * Stage 2 of the trace events.
237 *
238 * Create event field type metadata section.
239 * Each event produce an array of fields.
240 */
241
242 /* Reset all macros within TRACEPOINT_EVENT */
243 #include <probes/lttng-events-reset.h>
244 #include <probes/lttng-events-write.h>
245 #include <probes/lttng-events-nowrite.h>
246
247 #undef _ctf_integer_ext
248 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
249 { \
250 .name = #_item, \
251 .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\
252 .nowrite = _nowrite, \
253 .user = _user, \
254 },
255
256 #undef _ctf_array_encoded
257 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
258 { \
259 .name = #_item, \
260 .type = \
261 { \
262 .atype = atype_array, \
263 .u = \
264 { \
265 .array = \
266 { \
267 .elem_type = __type_integer(_type, 0, 0, 0, __BYTE_ORDER, 10, _encoding), \
268 .length = _length, \
269 } \
270 } \
271 }, \
272 .nowrite = _nowrite, \
273 .user = _user, \
274 },
275
276 #undef _ctf_array_bitfield
277 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
278 { \
279 .name = #_item, \
280 .type = \
281 { \
282 .atype = atype_array, \
283 .u = \
284 { \
285 .array = \
286 { \
287 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
288 .length = (_length) * sizeof(_type) * CHAR_BIT, \
289 .elem_alignment = lttng_alignof(_type), \
290 } \
291 } \
292 }, \
293 .nowrite = _nowrite, \
294 .user = _user, \
295 },
296
297
298 #undef _ctf_sequence_encoded
299 #define _ctf_sequence_encoded(_type, _item, _src, \
300 _length_type, _src_length, _encoding, \
301 _byte_order, _base, _user, _nowrite) \
302 { \
303 .name = #_item, \
304 .type = \
305 { \
306 .atype = atype_sequence, \
307 .u = \
308 { \
309 .sequence = \
310 { \
311 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
312 .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \
313 }, \
314 }, \
315 }, \
316 .nowrite = _nowrite, \
317 .user = _user, \
318 },
319
320 #undef _ctf_sequence_bitfield
321 #define _ctf_sequence_bitfield(_type, _item, _src, \
322 _length_type, _src_length, \
323 _user, _nowrite) \
324 { \
325 .name = #_item, \
326 .type = \
327 { \
328 .atype = atype_sequence, \
329 .u = \
330 { \
331 .sequence = \
332 { \
333 .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \
334 .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \
335 .elem_alignment = lttng_alignof(_type), \
336 }, \
337 }, \
338 }, \
339 .nowrite = _nowrite, \
340 .user = _user, \
341 },
342
343 #undef _ctf_string
344 #define _ctf_string(_item, _src, _user, _nowrite) \
345 { \
346 .name = #_item, \
347 .type = \
348 { \
349 .atype = atype_string, \
350 .u = \
351 { \
352 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
353 }, \
354 }, \
355 .nowrite = _nowrite, \
356 .user = _user, \
357 },
358
359 #undef _ctf_enum
360 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
361 { \
362 .name = #_item, \
363 .type = { \
364 .atype = atype_enum, \
365 .u = { \
366 .basic = { \
367 .enumeration = { \
368 .desc = &__enum_##_name, \
369 .container_type = { \
370 .size = sizeof(_type) * CHAR_BIT, \
371 .alignment = lttng_alignof(_type) * CHAR_BIT, \
372 .signedness = lttng_is_signed_type(_type), \
373 .reverse_byte_order = 0, \
374 .base = 10, \
375 .encoding = lttng_encode_none, \
376 }, \
377 }, \
378 }, \
379 }, \
380 }, \
381 .nowrite = _nowrite, \
382 .user = _user, \
383 },
384
385 #undef ctf_custom_field
386 #define ctf_custom_field(_type, _item, _code) \
387 { \
388 .name = #_item, \
389 .type = { _type }, \
390 .nowrite = 0, \
391 .user = 0, \
392 },
393
394 #undef ctf_custom_type
395 #define ctf_custom_type(...) __VA_ARGS__
396
397 #undef TP_FIELDS
398 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
399
400 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
401 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
402 static const struct lttng_event_field __event_fields___##_name[] = { \
403 _fields \
404 };
405
406 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
407 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
408 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post)
409
410 #undef LTTNG_TRACEPOINT_ENUM
411 #define LTTNG_TRACEPOINT_ENUM(_name, _values) \
412 static const struct lttng_enum_desc __enum_##_name = { \
413 .name = #_name, \
414 .entries = __enum_values__##_name, \
415 .nr_entries = ARRAY_SIZE(__enum_values__##_name), \
416 };
417
418 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
419
420 /*
421 * Stage 3 of the trace events.
422 *
423 * Create probe callback prototypes.
424 */
425
426 /* Reset all macros within TRACEPOINT_EVENT */
427 #include <probes/lttng-events-reset.h>
428
429 #undef TP_PROTO
430 #define TP_PROTO(...) __VA_ARGS__
431
432 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
433 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
434 static void __event_probe__##_name(void *__data, _proto);
435
436 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
437 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
438 static void __event_probe__##_name(void *__data);
439
440 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
441
442 /*
443 * Stage 4 of the trace events.
444 *
445 * Create static inline function that calculates event size.
446 */
447
448 /* Reset all macros within TRACEPOINT_EVENT */
449 #include <probes/lttng-events-reset.h>
450 #include <probes/lttng-events-write.h>
451
452 #undef _ctf_integer_ext
453 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
454 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
455 __event_len += sizeof(_type);
456
457 #undef _ctf_array_encoded
458 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
459 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
460 __event_len += sizeof(_type) * (_length);
461
462 #undef _ctf_array_bitfield
463 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
464 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
465
466 #undef _ctf_sequence_encoded
467 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
468 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
469 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
470 __event_len += sizeof(_length_type); \
471 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
472 { \
473 size_t __seqlen = (_src_length); \
474 \
475 if (unlikely(++this_cpu_ptr(&lttng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
476 goto error; \
477 barrier(); /* reserve before use. */ \
478 this_cpu_ptr(&lttng_dynamic_len_stack)->stack[this_cpu_ptr(&lttng_dynamic_len_stack)->offset - 1] = __seqlen; \
479 __event_len += sizeof(_type) * __seqlen; \
480 }
481
482 #undef _ctf_sequence_bitfield
483 #define _ctf_sequence_bitfield(_type, _item, _src, \
484 _length_type, _src_length, \
485 _user, _nowrite) \
486 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
487 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
488
489 /*
490 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
491 * 1 (\0 only).
492 */
493 #undef _ctf_string
494 #define _ctf_string(_item, _src, _user, _nowrite) \
495 if (unlikely(++this_cpu_ptr(&lttng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \
496 goto error; \
497 barrier(); /* reserve before use. */ \
498 if (_user) { \
499 __event_len += this_cpu_ptr(&lttng_dynamic_len_stack)->stack[this_cpu_ptr(&lttng_dynamic_len_stack)->offset - 1] = \
500 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
501 } else { \
502 __event_len += this_cpu_ptr(&lttng_dynamic_len_stack)->stack[this_cpu_ptr(&lttng_dynamic_len_stack)->offset - 1] = \
503 strlen(_src) + 1; \
504 }
505
506 #undef _ctf_enum
507 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
508 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
509
510 #undef ctf_align
511 #define ctf_align(_type) \
512 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type));
513
514 #undef ctf_custom_field
515 #define ctf_custom_field(_type, _item, _code) \
516 { \
517 _code \
518 }
519
520 #undef ctf_custom_code
521 #define ctf_custom_code(...) __VA_ARGS__
522
523 #undef TP_PROTO
524 #define TP_PROTO(...) __VA_ARGS__
525
526 #undef TP_FIELDS
527 #define TP_FIELDS(...) __VA_ARGS__
528
529 #undef TP_locvar
530 #define TP_locvar(...) __VA_ARGS__
531
532 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
533 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
534 static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \
535 { \
536 size_t __event_len = 0; \
537 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
538 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
539 \
540 _fields \
541 return __event_len; \
542 \
543 error: \
544 __attribute__((unused)); \
545 return -1; \
546 }
547
548 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
549 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
550 static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \
551 { \
552 size_t __event_len = 0; \
553 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
554 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
555 \
556 _fields \
557 return __event_len; \
558 \
559 error: \
560 __attribute__((unused)); \
561 return -1; \
562 }
563
564 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
565
566
567 /*
568 * Stage 4.1 of tracepoint event generation.
569 *
570 * Create static inline function that layout the filter stack data.
571 * We make both write and nowrite data available to the filter.
572 */
573
574 /* Reset all macros within TRACEPOINT_EVENT */
575 #include <probes/lttng-events-reset.h>
576 #include <probes/lttng-events-write.h>
577 #include <probes/lttng-events-nowrite.h>
578
579 #undef _ctf_integer_ext_fetched
580 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
581 if (lttng_is_signed_type(_type)) { \
582 int64_t __ctf_tmp_int64; \
583 switch (sizeof(_type)) { \
584 case 1: \
585 { \
586 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
587 __ctf_tmp_int64 = (int64_t) __tmp.v; \
588 break; \
589 } \
590 case 2: \
591 { \
592 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
593 if (_byte_order != __BYTE_ORDER) \
594 __swab16s(&__tmp.v); \
595 __ctf_tmp_int64 = (int64_t) __tmp.v; \
596 break; \
597 } \
598 case 4: \
599 { \
600 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
601 if (_byte_order != __BYTE_ORDER) \
602 __swab32s(&__tmp.v); \
603 __ctf_tmp_int64 = (int64_t) __tmp.v; \
604 break; \
605 } \
606 case 8: \
607 { \
608 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
609 if (_byte_order != __BYTE_ORDER) \
610 __swab64s(&__tmp.v); \
611 __ctf_tmp_int64 = (int64_t) __tmp.v; \
612 break; \
613 } \
614 default: \
615 BUG_ON(1); \
616 }; \
617 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
618 } else { \
619 uint64_t __ctf_tmp_uint64; \
620 switch (sizeof(_type)) { \
621 case 1: \
622 { \
623 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
624 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
625 break; \
626 } \
627 case 2: \
628 { \
629 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
630 if (_byte_order != __BYTE_ORDER) \
631 __swab16s(&__tmp.v); \
632 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
633 break; \
634 } \
635 case 4: \
636 { \
637 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
638 if (_byte_order != __BYTE_ORDER) \
639 __swab32s(&__tmp.v); \
640 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
641 break; \
642 } \
643 case 8: \
644 { \
645 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
646 if (_byte_order != __BYTE_ORDER) \
647 __swab64s(&__tmp.v); \
648 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
649 break; \
650 } \
651 default: \
652 BUG_ON(1); \
653 }; \
654 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
655 } \
656 __stack_data += sizeof(int64_t);
657
658 #undef _ctf_integer_ext_isuser0
659 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
660 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
661
662 #undef _ctf_integer_ext_isuser1
663 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
664 { \
665 union { \
666 char __array[sizeof(_user_src)]; \
667 __typeof__(_user_src) __v; \
668 } __tmp_fetch; \
669 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
670 &(_user_src), sizeof(_user_src))) \
671 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
672 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
673 }
674
675 #undef _ctf_integer_ext
676 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
677 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
678
679 #undef _ctf_array_encoded
680 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
681 { \
682 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
683 const void *__ctf_tmp_ptr = (_src); \
684 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
685 __stack_data += sizeof(unsigned long); \
686 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
687 __stack_data += sizeof(void *); \
688 }
689
690 #undef _ctf_array_bitfield
691 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
692 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
693
694 #undef _ctf_sequence_encoded
695 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
696 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
697 { \
698 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
699 const void *__ctf_tmp_ptr = (_src); \
700 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
701 __stack_data += sizeof(unsigned long); \
702 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
703 __stack_data += sizeof(void *); \
704 }
705
706 #undef _ctf_sequence_bitfield
707 #define _ctf_sequence_bitfield(_type, _item, _src, \
708 _length_type, _src_length, \
709 _user, _nowrite) \
710 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
711 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
712
713 #undef _ctf_string
714 #define _ctf_string(_item, _src, _user, _nowrite) \
715 { \
716 const void *__ctf_tmp_ptr = (_src); \
717 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
718 __stack_data += sizeof(void *); \
719 }
720
721 #undef _ctf_enum
722 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
723 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
724
725 #undef TP_PROTO
726 #define TP_PROTO(...) __VA_ARGS__
727
728 #undef TP_FIELDS
729 #define TP_FIELDS(...) __VA_ARGS__
730
731 #undef TP_locvar
732 #define TP_locvar(...) __VA_ARGS__
733
734 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
735 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
736 static inline \
737 void __event_prepare_filter_stack__##_name(char *__stack_data, \
738 void *__tp_locvar) \
739 { \
740 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
741 \
742 _fields \
743 }
744
745 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
746 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
747 static inline \
748 void __event_prepare_filter_stack__##_name(char *__stack_data, \
749 void *__tp_locvar, _proto) \
750 { \
751 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
752 \
753 _fields \
754 }
755
756 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
757
758 /*
759 * Stage 5 of the trace events.
760 *
761 * Create static inline function that calculates event payload alignment.
762 */
763
764 /* Reset all macros within TRACEPOINT_EVENT */
765 #include <probes/lttng-events-reset.h>
766 #include <probes/lttng-events-write.h>
767
768 #undef _ctf_integer_ext
769 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
770 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
771
772 #undef _ctf_array_encoded
773 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
774 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
775
776 #undef _ctf_array_bitfield
777 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
778 _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite)
779
780 #undef _ctf_sequence_encoded
781 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
782 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
783 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
784 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
785
786 #undef _ctf_sequence_bitfield
787 #define _ctf_sequence_bitfield(_type, _item, _src, \
788 _length_type, _src_length, \
789 _user, _nowrite) \
790 _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \
791 none, __LITTLE_ENDIAN, 10, _user, _nowrite)
792
793 #undef _ctf_string
794 #define _ctf_string(_item, _src, _user, _nowrite)
795
796 #undef _ctf_enum
797 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
798 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
799
800 #undef ctf_align
801 #define ctf_align(_type) \
802 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
803
804 #undef TP_PROTO
805 #define TP_PROTO(...) __VA_ARGS__
806
807 #undef TP_FIELDS
808 #define TP_FIELDS(...) __VA_ARGS__
809
810 #undef TP_locvar
811 #define TP_locvar(...) __VA_ARGS__
812
813 #undef ctf_custom_field
814 #define ctf_custom_field(_type, _item, _code) _code
815
816 #undef ctf_custom_code
817 #define ctf_custom_code(...) \
818 { \
819 __VA_ARGS__ \
820 }
821
822 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
823 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
824 static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
825 { \
826 size_t __event_align = 1; \
827 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
828 \
829 _fields \
830 return __event_align; \
831 }
832
833 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
834 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
835 static inline size_t __event_get_align__##_name(void *__tp_locvar) \
836 { \
837 size_t __event_align = 1; \
838 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
839 \
840 _fields \
841 return __event_align; \
842 }
843
844 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
845
846 /*
847 * Stage 6 of tracepoint event generation.
848 *
849 * Create the probe function. This function calls event size calculation
850 * and writes event data into the buffer.
851 */
852
853 /* Reset all macros within TRACEPOINT_EVENT */
854 #include <probes/lttng-events-reset.h>
855 #include <probes/lttng-events-write.h>
856
857 #undef _ctf_integer_ext_fetched
858 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
859 { \
860 _type __tmp = _src; \
861 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
862 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
863 }
864
865 #undef _ctf_integer_ext_isuser0
866 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
867 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
868
869 #undef _ctf_integer_ext_isuser1
870 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
871 { \
872 union { \
873 char __array[sizeof(_user_src)]; \
874 __typeof__(_user_src) __v; \
875 } __tmp_fetch; \
876 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
877 &(_user_src), sizeof(_user_src))) \
878 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
879 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
880 }
881
882 #undef _ctf_integer_ext
883 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
884 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
885
886 #undef _ctf_array_encoded
887 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
888 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
889 if (_user) { \
890 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
891 } else { \
892 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
893 }
894
895 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
896 #undef _ctf_array_bitfield
897 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
898 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
899 if (_user) { \
900 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
901 } else { \
902 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
903 }
904 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
905 /*
906 * For big endian, we need to byteswap into little endian.
907 */
908 #undef _ctf_array_bitfield
909 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
910 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
911 { \
912 size_t _i; \
913 \
914 for (_i = 0; _i < (_length); _i++) { \
915 _type _tmp; \
916 \
917 if (_user) { \
918 if (get_user(_tmp, (_type *) _src + _i)) \
919 _tmp = 0; \
920 } else { \
921 _tmp = ((_type *) _src)[_i]; \
922 } \
923 switch (sizeof(_type)) { \
924 case 1: \
925 break; \
926 case 2: \
927 _tmp = cpu_to_le16(_tmp); \
928 break; \
929 case 4: \
930 _tmp = cpu_to_le32(_tmp); \
931 break; \
932 case 8: \
933 _tmp = cpu_to_le64(_tmp); \
934 break; \
935 default: \
936 BUG_ON(1); \
937 } \
938 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
939 } \
940 }
941 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
942
943 #undef _ctf_sequence_encoded
944 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
945 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
946 { \
947 _length_type __tmpl = this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
948 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
949 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
950 } \
951 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
952 if (_user) { \
953 __chan->ops->event_write_from_user(&__ctx, _src, \
954 sizeof(_type) * __get_dynamic_len(dest)); \
955 } else { \
956 __chan->ops->event_write(&__ctx, _src, \
957 sizeof(_type) * __get_dynamic_len(dest)); \
958 }
959
960 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
961 #undef _ctf_sequence_bitfield
962 #define _ctf_sequence_bitfield(_type, _item, _src, \
963 _length_type, _src_length, \
964 _user, _nowrite) \
965 { \
966 _length_type __tmpl = this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
967 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
968 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
969 } \
970 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
971 if (_user) { \
972 __chan->ops->event_write_from_user(&__ctx, _src, \
973 sizeof(_type) * __get_dynamic_len(dest)); \
974 } else { \
975 __chan->ops->event_write(&__ctx, _src, \
976 sizeof(_type) * __get_dynamic_len(dest)); \
977 }
978 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
979 /*
980 * For big endian, we need to byteswap into little endian.
981 */
982 #undef _ctf_sequence_bitfield
983 #define _ctf_sequence_bitfield(_type, _item, _src, \
984 _length_type, _src_length, \
985 _user, _nowrite) \
986 { \
987 _length_type __tmpl = this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
988 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
989 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
990 } \
991 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
992 { \
993 size_t _i, _length; \
994 \
995 _length = __get_dynamic_len(dest); \
996 for (_i = 0; _i < _length; _i++) { \
997 _type _tmp; \
998 \
999 if (_user) { \
1000 if (get_user(_tmp, (_type *) _src + _i)) \
1001 _tmp = 0; \
1002 } else { \
1003 _tmp = ((_type *) _src)[_i]; \
1004 } \
1005 switch (sizeof(_type)) { \
1006 case 1: \
1007 break; \
1008 case 2: \
1009 _tmp = cpu_to_le16(_tmp); \
1010 break; \
1011 case 4: \
1012 _tmp = cpu_to_le32(_tmp); \
1013 break; \
1014 case 8: \
1015 _tmp = cpu_to_le64(_tmp); \
1016 break; \
1017 default: \
1018 BUG_ON(1); \
1019 } \
1020 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \
1021 } \
1022 }
1023 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
1024
1025 #undef _ctf_string
1026 #define _ctf_string(_item, _src, _user, _nowrite) \
1027 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
1028 if (_user) { \
1029 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
1030 __get_dynamic_len(dest)); \
1031 } else { \
1032 __chan->ops->event_strcpy(&__ctx, _src, \
1033 __get_dynamic_len(dest)); \
1034 }
1035
1036 #undef _ctf_enum
1037 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
1038 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
1039
1040 #undef ctf_align
1041 #define ctf_align(_type) \
1042 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type));
1043
1044 #undef ctf_custom_field
1045 #define ctf_custom_field(_type, _item, _code) _code
1046
1047 #undef ctf_custom_code
1048 #define ctf_custom_code(...) \
1049 { \
1050 __VA_ARGS__ \
1051 }
1052
1053 /* Beware: this get len actually consumes the len value */
1054 #undef __get_dynamic_len
1055 #define __get_dynamic_len(field) this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx++]
1056
1057 #undef TP_PROTO
1058 #define TP_PROTO(...) __VA_ARGS__
1059
1060 #undef TP_ARGS
1061 #define TP_ARGS(...) __VA_ARGS__
1062
1063 #undef TP_FIELDS
1064 #define TP_FIELDS(...) __VA_ARGS__
1065
1066 #undef TP_locvar
1067 #define TP_locvar(...) __VA_ARGS__
1068
1069 #undef TP_code_pre
1070 #define TP_code_pre(...) __VA_ARGS__
1071
1072 #undef TP_code_post
1073 #define TP_code_post(...) __VA_ARGS__
1074
1075 /*
1076 * For state dump, check that "session" argument (mandatory) matches the
1077 * session this event belongs to. Ensures that we write state dump data only
1078 * into the started session, not into all sessions.
1079 */
1080 #ifdef TP_SESSION_CHECK
1081 #define _TP_SESSION_CHECK(session, csession) (session == csession)
1082 #else /* TP_SESSION_CHECK */
1083 #define _TP_SESSION_CHECK(session, csession) 1
1084 #endif /* TP_SESSION_CHECK */
1085
1086 /*
1087 * Using twice size for filter stack data to hold size and pointer for
1088 * each field (worse case). For integers, max size required is 64-bit.
1089 * Same for double-precision floats. Those fit within
1090 * 2*sizeof(unsigned long) for all supported architectures.
1091 * Perform UNION (||) of filter runtime list.
1092 */
1093 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1094 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1095 static void __event_probe__##_name(void *__data, _proto) \
1096 { \
1097 struct probe_local_vars { _locvar }; \
1098 struct lttng_event *__event = __data; \
1099 struct lttng_probe_ctx __lttng_probe_ctx = { \
1100 .event = __event, \
1101 .interruptible = !irqs_disabled(), \
1102 }; \
1103 struct lttng_channel *__chan = __event->chan; \
1104 struct lttng_session *__session = __chan->session; \
1105 struct lib_ring_buffer_ctx __ctx; \
1106 ssize_t __event_len; \
1107 size_t __event_align; \
1108 size_t __orig_dynamic_len_offset, __dynamic_len_idx; \
1109 union { \
1110 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1111 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1112 } __stackvar; \
1113 int __ret; \
1114 struct probe_local_vars __tp_locvar; \
1115 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1116 &__tp_locvar; \
1117 struct lttng_pid_tracker *__lpf; \
1118 \
1119 if (!_TP_SESSION_CHECK(session, __session)) \
1120 return; \
1121 if (unlikely(!ACCESS_ONCE(__session->active))) \
1122 return; \
1123 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
1124 return; \
1125 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
1126 return; \
1127 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
1128 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
1129 return; \
1130 __orig_dynamic_len_offset = this_cpu_ptr(&lttng_dynamic_len_stack)->offset; \
1131 __dynamic_len_idx = __orig_dynamic_len_offset; \
1132 _code_pre \
1133 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1134 struct lttng_bytecode_runtime *bc_runtime; \
1135 int __filter_record = __event->has_enablers_without_bytecode; \
1136 \
1137 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1138 tp_locvar, _args); \
1139 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1140 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1141 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1142 __filter_record = 1; \
1143 } \
1144 if (likely(!__filter_record)) \
1145 goto __post; \
1146 } \
1147 __event_len = __event_get_size__##_name(tp_locvar, _args); \
1148 if (unlikely(__event_len < 0)) { \
1149 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1150 goto __post; \
1151 } \
1152 __event_align = __event_get_align__##_name(tp_locvar, _args); \
1153 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1154 __event_align, -1); \
1155 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1156 if (__ret < 0) \
1157 goto __post; \
1158 _fields \
1159 __chan->ops->event_commit(&__ctx); \
1160 __post: \
1161 _code_post \
1162 barrier(); /* use before un-reserve. */ \
1163 this_cpu_ptr(&lttng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1164 return; \
1165 }
1166
1167 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1168 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1169 static void __event_probe__##_name(void *__data) \
1170 { \
1171 struct probe_local_vars { _locvar }; \
1172 struct lttng_event *__event = __data; \
1173 struct lttng_probe_ctx __lttng_probe_ctx = { \
1174 .event = __event, \
1175 .interruptible = !irqs_disabled(), \
1176 }; \
1177 struct lttng_channel *__chan = __event->chan; \
1178 struct lttng_session *__session = __chan->session; \
1179 struct lib_ring_buffer_ctx __ctx; \
1180 ssize_t __event_len; \
1181 size_t __event_align; \
1182 size_t __orig_dynamic_len_offset, __dynamic_len_idx; \
1183 union { \
1184 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1185 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1186 } __stackvar; \
1187 int __ret; \
1188 struct probe_local_vars __tp_locvar; \
1189 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1190 &__tp_locvar; \
1191 struct lttng_pid_tracker *__lpf; \
1192 \
1193 if (!_TP_SESSION_CHECK(session, __session)) \
1194 return; \
1195 if (unlikely(!ACCESS_ONCE(__session->active))) \
1196 return; \
1197 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
1198 return; \
1199 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
1200 return; \
1201 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
1202 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
1203 return; \
1204 __orig_dynamic_len_offset = this_cpu_ptr(&lttng_dynamic_len_stack)->offset; \
1205 __dynamic_len_idx = __orig_dynamic_len_offset; \
1206 _code_pre \
1207 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
1208 struct lttng_bytecode_runtime *bc_runtime; \
1209 int __filter_record = __event->has_enablers_without_bytecode; \
1210 \
1211 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
1212 tp_locvar); \
1213 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
1214 if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
1215 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
1216 __filter_record = 1; \
1217 } \
1218 if (likely(!__filter_record)) \
1219 goto __post; \
1220 } \
1221 __event_len = __event_get_size__##_name(tp_locvar); \
1222 if (unlikely(__event_len < 0)) { \
1223 lib_ring_buffer_lost_event_too_big(__chan->chan); \
1224 goto __post; \
1225 } \
1226 __event_align = __event_get_align__##_name(tp_locvar); \
1227 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \
1228 __event_align, -1); \
1229 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
1230 if (__ret < 0) \
1231 goto __post; \
1232 _fields \
1233 __chan->ops->event_commit(&__ctx); \
1234 __post: \
1235 _code_post \
1236 barrier(); /* use before un-reserve. */ \
1237 this_cpu_ptr(&lttng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1238 return; \
1239 }
1240
1241 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1242
1243 #undef __get_dynamic_len
1244
1245 /*
1246 * Stage 7 of the trace events.
1247 *
1248 * Create event descriptions.
1249 */
1250
1251 /* Named field types must be defined in lttng-types.h */
1252
1253 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1254
1255 #ifndef TP_PROBE_CB
1256 #define TP_PROBE_CB(_template) &__event_probe__##_template
1257 #endif
1258
1259 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1260 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1261 static const struct lttng_event_desc __event_desc___##_map = { \
1262 .fields = __event_fields___##_template, \
1263 .name = #_map, \
1264 .kname = #_name, \
1265 .probe_callback = (void *) TP_PROBE_CB(_template), \
1266 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
1267 .owner = THIS_MODULE, \
1268 };
1269
1270 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1271 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1272 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1273
1274 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1275
1276 /*
1277 * Stage 8 of the trace events.
1278 *
1279 * Create an array of event description pointers.
1280 */
1281
1282 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1283
1284 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1285 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1286 &__event_desc___##_map,
1287
1288 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1289 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1290 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1291
1292 #define TP_ID1(_token, _system) _token##_system
1293 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1294
1295 static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
1296 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1297 };
1298
1299 #undef TP_ID1
1300 #undef TP_ID
1301
1302 /*
1303 * Stage 9 of the trace events.
1304 *
1305 * Create a toplevel descriptor for the whole probe.
1306 */
1307
1308 #define TP_ID1(_token, _system) _token##_system
1309 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1310
1311 /* non-const because list head will be modified when registered. */
1312 static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
1313 .provider = __stringify(TRACE_SYSTEM),
1314 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
1315 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
1316 .head = { NULL, NULL },
1317 .lazy_init_head = { NULL, NULL },
1318 .lazy = 0,
1319 };
1320
1321 #undef TP_ID1
1322 #undef TP_ID
1323
1324 /*
1325 * Stage 10 of the trace events.
1326 *
1327 * Register/unregister probes at module load/unload.
1328 */
1329
1330 #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1331
1332 #define TP_ID1(_token, _system) _token##_system
1333 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1334 #define module_init_eval1(_token, _system) module_init(_token##_system)
1335 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1336 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1337 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1338
1339 #ifndef TP_MODULE_NOINIT
1340 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
1341 {
1342 wrapper_vmalloc_sync_all();
1343 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
1344 }
1345
1346 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
1347 {
1348 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
1349 }
1350
1351 #ifndef TP_MODULE_NOAUTOLOAD
1352 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
1353 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
1354 #endif
1355
1356 #endif
1357
1358 #undef module_init_eval
1359 #undef module_exit_eval
1360 #undef TP_ID1
1361 #undef TP_ID
1362
1363 #undef TP_PROTO
1364 #undef TP_ARGS
This page took 0.081276 seconds and 5 git commands to generate.