Fix: add modules target to base Makefile
[lttng-modules.git] / probes / lttng-events.h
... / ...
CommitLineData
1/*
2 * lttng-events.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 "lttng.h"
26#include "lttng-types.h"
27#include "lttng-probe-user.h"
28#include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
29#include "../wrapper/ringbuffer/frontend_types.h"
30#include "../wrapper/ringbuffer/backend.h"
31#include "../wrapper/rcu.h"
32#include "../lttng-events.h"
33#include "../lttng-tracer-core.h"
34#include <asm/byteorder.h>
35#include <linux/swab.h>
36
37/*
38 * Macro declarations used for all stages.
39 */
40
41/*
42 * LTTng name mapping macros. LTTng remaps some of the kernel events to
43 * enforce name-spacing.
44 */
45#undef LTTNG_TRACEPOINT_EVENT_MAP
46#define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
47 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
48 PARAMS(proto), \
49 PARAMS(args), \
50 PARAMS(fields)) \
51 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
52
53#undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
54#define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
55 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
56 PARAMS(fields)) \
57 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
58
59#undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
60#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
61 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
62 PARAMS(proto), \
63 PARAMS(args), \
64 PARAMS(_locvar), \
65 PARAMS(_code), \
66 PARAMS(fields)) \
67 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
68
69#undef LTTNG_TRACEPOINT_EVENT_CODE
70#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
71 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
72 PARAMS(proto), \
73 PARAMS(args), \
74 PARAMS(_locvar), \
75 PARAMS(_code), \
76 PARAMS(fields))
77
78/*
79 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
80 * handlers for events. That is, if all events have the same parameters
81 * and just have distinct trace points. Each tracepoint can be defined
82 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
83 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
84 *
85 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
86 * template.
87 */
88
89#undef LTTNG_TRACEPOINT_EVENT
90#define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
91 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
92 PARAMS(proto), \
93 PARAMS(args), \
94 PARAMS(fields))
95
96#undef LTTNG_TRACEPOINT_EVENT_NOARGS
97#define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
98 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
99
100#undef LTTNG_TRACEPOINT_EVENT_INSTANCE
101#define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
102 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
103
104#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
105#define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
106 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
107
108#undef LTTNG_TRACEPOINT_EVENT_CLASS
109#define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
110 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
111 PARAMS(_fields))
112
113#undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
114#define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
115 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
116
117
118/*
119 * Stage 1 of the trace events.
120 *
121 * Create dummy trace calls for each events, verifying that the LTTng module
122 * instrumentation headers match the kernel arguments. Will be optimized
123 * out by the compiler.
124 */
125
126/* Reset all macros within TRACEPOINT_EVENT */
127#include "lttng-events-reset.h"
128
129#undef TP_PROTO
130#define TP_PROTO(...) __VA_ARGS__
131
132#undef TP_ARGS
133#define TP_ARGS(...) __VA_ARGS__
134
135#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
136#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
137void trace_##_name(_proto);
138
139#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
140#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
141void trace_##_name(void);
142
143#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
144
145/*
146 * Stage 1.1 of the trace events.
147 *
148 * Create dummy trace prototypes for each event class, and for each used
149 * template. This will allow checking whether the prototypes from the
150 * class and the instance using the class actually match.
151 */
152
153#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
154
155#undef TP_PROTO
156#define TP_PROTO(...) __VA_ARGS__
157
158#undef TP_ARGS
159#define TP_ARGS(...) __VA_ARGS__
160
161#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
162#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
163void __event_template_proto___##_template(_proto);
164
165#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
166#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
167void __event_template_proto___##_template(void);
168
169#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
170#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
171void __event_template_proto___##_name(_proto);
172
173#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
174#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
175void __event_template_proto___##_name(void);
176
177#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
178
179/*
180 * Stage 2 of the trace events.
181 *
182 * Create event field type metadata section.
183 * Each event produce an array of fields.
184 */
185
186/* Reset all macros within TRACEPOINT_EVENT */
187#include "lttng-events-reset.h"
188#include "lttng-events-write.h"
189#include "lttng-events-nowrite.h"
190
191#undef _ctf_integer_ext
192#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
193 { \
194 .name = #_item, \
195 .type = __type_integer(_type, _byte_order, _base, none),\
196 .nowrite = _nowrite, \
197 .user = _user, \
198 },
199
200#undef _ctf_array_encoded
201#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
202 { \
203 .name = #_item, \
204 .type = \
205 { \
206 .atype = atype_array, \
207 .u = \
208 { \
209 .array = \
210 { \
211 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
212 .length = _length, \
213 } \
214 } \
215 }, \
216 .nowrite = _nowrite, \
217 .user = _user, \
218 },
219
220#undef _ctf_sequence_encoded
221#define _ctf_sequence_encoded(_type, _item, _src, \
222 _length_type, _src_length, _encoding, \
223 _byte_order, _base, _user, _nowrite) \
224 { \
225 .name = #_item, \
226 .type = \
227 { \
228 .atype = atype_sequence, \
229 .u = \
230 { \
231 .sequence = \
232 { \
233 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
234 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
235 }, \
236 }, \
237 }, \
238 .nowrite = _nowrite, \
239 .user = _user, \
240 },
241
242#undef _ctf_string
243#define _ctf_string(_item, _src, _user, _nowrite) \
244 { \
245 .name = #_item, \
246 .type = \
247 { \
248 .atype = atype_string, \
249 .u = \
250 { \
251 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
252 }, \
253 }, \
254 .nowrite = _nowrite, \
255 .user = _user, \
256 },
257
258#undef TP_FIELDS
259#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
260
261#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
262#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
263 static const struct lttng_event_field __event_fields___##_name[] = { \
264 _fields \
265 };
266
267#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
268#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
269 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
270
271#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
272
273/*
274 * Stage 3 of the trace events.
275 *
276 * Create probe callback prototypes.
277 */
278
279/* Reset all macros within TRACEPOINT_EVENT */
280#include "lttng-events-reset.h"
281
282#undef TP_PROTO
283#define TP_PROTO(...) __VA_ARGS__
284
285#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
286#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
287static void __event_probe__##_name(void *__data, _proto);
288
289#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
290#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
291static void __event_probe__##_name(void *__data);
292
293#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
294
295/*
296 * Stage 4 of the trace events.
297 *
298 * Create static inline function that calculates event size.
299 */
300
301/* Reset all macros within TRACEPOINT_EVENT */
302#include "lttng-events-reset.h"
303#include "lttng-events-write.h"
304
305#undef _ctf_integer_ext
306#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
307 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
308 __event_len += sizeof(_type);
309
310#undef _ctf_array_encoded
311#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
312 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
313 __event_len += sizeof(_type) * (_length);
314
315#undef _ctf_sequence_encoded
316#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
317 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
318 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
319 __event_len += sizeof(_length_type); \
320 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
321 __dynamic_len[__dynamic_len_idx] = (_src_length); \
322 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
323 __dynamic_len_idx++;
324
325/*
326 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
327 * 1 (\0 only).
328 */
329#undef _ctf_string
330#define _ctf_string(_item, _src, _user, _nowrite) \
331 if (_user) \
332 __event_len += __dynamic_len[__dynamic_len_idx++] = \
333 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
334 else \
335 __event_len += __dynamic_len[__dynamic_len_idx++] = \
336 strlen(_src) + 1;
337
338#undef TP_PROTO
339#define TP_PROTO(...) __VA_ARGS__
340
341#undef TP_FIELDS
342#define TP_FIELDS(...) __VA_ARGS__
343
344#undef TP_locvar
345#define TP_locvar(...) __VA_ARGS__
346
347#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
348#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
349static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
350 void *__tp_locvar, _proto) \
351{ \
352 size_t __event_len = 0; \
353 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
354 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
355 \
356 _fields \
357 return __event_len; \
358}
359
360#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
361#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
362static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
363 void *__tp_locvar) \
364{ \
365 size_t __event_len = 0; \
366 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
367 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
368 \
369 _fields \
370 return __event_len; \
371}
372
373#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
374
375
376/*
377 * Stage 4.1 of tracepoint event generation.
378 *
379 * Create static inline function that layout the filter stack data.
380 * We make both write and nowrite data available to the filter.
381 */
382
383/* Reset all macros within TRACEPOINT_EVENT */
384#include "lttng-events-reset.h"
385#include "lttng-events-write.h"
386#include "lttng-events-nowrite.h"
387
388#undef _ctf_integer_ext_fetched
389#define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
390 if (lttng_is_signed_type(_type)) { \
391 int64_t __ctf_tmp_int64; \
392 switch (sizeof(_type)) { \
393 case 1: \
394 { \
395 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
396 __ctf_tmp_int64 = (int64_t) __tmp.v; \
397 break; \
398 } \
399 case 2: \
400 { \
401 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
402 if (_byte_order != __BYTE_ORDER) \
403 __swab16s(&__tmp.v); \
404 __ctf_tmp_int64 = (int64_t) __tmp.v; \
405 break; \
406 } \
407 case 4: \
408 { \
409 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
410 if (_byte_order != __BYTE_ORDER) \
411 __swab32s(&__tmp.v); \
412 __ctf_tmp_int64 = (int64_t) __tmp.v; \
413 break; \
414 } \
415 case 8: \
416 { \
417 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
418 if (_byte_order != __BYTE_ORDER) \
419 __swab64s(&__tmp.v); \
420 __ctf_tmp_int64 = (int64_t) __tmp.v; \
421 break; \
422 } \
423 default: \
424 BUG_ON(1); \
425 }; \
426 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
427 } else { \
428 uint64_t __ctf_tmp_uint64; \
429 switch (sizeof(_type)) { \
430 case 1: \
431 { \
432 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
433 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
434 break; \
435 } \
436 case 2: \
437 { \
438 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
439 if (_byte_order != __BYTE_ORDER) \
440 __swab16s(&__tmp.v); \
441 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
442 break; \
443 } \
444 case 4: \
445 { \
446 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
447 if (_byte_order != __BYTE_ORDER) \
448 __swab32s(&__tmp.v); \
449 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
450 break; \
451 } \
452 case 8: \
453 { \
454 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
455 if (_byte_order != __BYTE_ORDER) \
456 __swab64s(&__tmp.v); \
457 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
458 break; \
459 } \
460 default: \
461 BUG_ON(1); \
462 }; \
463 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
464 } \
465 __stack_data += sizeof(int64_t);
466
467#undef _ctf_integer_ext_isuser0
468#define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
469 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
470
471#undef _ctf_integer_ext_isuser1
472#define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
473{ \
474 union { \
475 char __array[sizeof(_user_src)]; \
476 __typeof__(_user_src) __v; \
477 } __tmp_fetch; \
478 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
479 &(_user_src), sizeof(_user_src))) \
480 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
481 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
482}
483
484#undef _ctf_integer_ext
485#define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
486 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
487
488#undef _ctf_array_encoded
489#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
490 { \
491 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
492 const void *__ctf_tmp_ptr = (_src); \
493 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
494 __stack_data += sizeof(unsigned long); \
495 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
496 __stack_data += sizeof(void *); \
497 }
498
499#undef _ctf_sequence_encoded
500#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
501 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
502 { \
503 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
504 const void *__ctf_tmp_ptr = (_src); \
505 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
506 __stack_data += sizeof(unsigned long); \
507 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
508 __stack_data += sizeof(void *); \
509 }
510
511#undef _ctf_string
512#define _ctf_string(_item, _src, _user, _nowrite) \
513 { \
514 const void *__ctf_tmp_ptr = (_src); \
515 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
516 __stack_data += sizeof(void *); \
517 }
518
519#undef TP_PROTO
520#define TP_PROTO(...) __VA_ARGS__
521
522#undef TP_FIELDS
523#define TP_FIELDS(...) __VA_ARGS__
524
525#undef TP_locvar
526#define TP_locvar(...) __VA_ARGS__
527
528#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
529#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
530static inline \
531void __event_prepare_filter_stack__##_name(char *__stack_data, \
532 void *__tp_locvar) \
533{ \
534 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
535 \
536 _fields \
537}
538
539#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
540#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
541static inline \
542void __event_prepare_filter_stack__##_name(char *__stack_data, \
543 void *__tp_locvar, _proto) \
544{ \
545 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
546 \
547 _fields \
548}
549
550#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
551
552/*
553 * Stage 5 of the trace events.
554 *
555 * Create static inline function that calculates event payload alignment.
556 */
557
558/* Reset all macros within TRACEPOINT_EVENT */
559#include "lttng-events-reset.h"
560#include "lttng-events-write.h"
561
562#undef _ctf_integer_ext
563#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
564 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
565
566#undef _ctf_array_encoded
567#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
568 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
569
570#undef _ctf_sequence_encoded
571#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
572 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
573 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
574 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
575
576#undef _ctf_string
577#define _ctf_string(_item, _src, _user, _nowrite)
578
579#undef TP_PROTO
580#define TP_PROTO(...) __VA_ARGS__
581
582#undef TP_FIELDS
583#define TP_FIELDS(...) __VA_ARGS__
584
585#undef TP_locvar
586#define TP_locvar(...) __VA_ARGS__
587
588#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
589#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
590static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
591{ \
592 size_t __event_align = 1; \
593 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
594 \
595 _fields \
596 return __event_align; \
597}
598
599#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
600#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
601static inline size_t __event_get_align__##_name(void *__tp_locvar) \
602{ \
603 size_t __event_align = 1; \
604 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
605 \
606 _fields \
607 return __event_align; \
608}
609
610#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
611
612/*
613 * Stage 6 of tracepoint event generation.
614 *
615 * Create the probe function. This function calls event size calculation
616 * and writes event data into the buffer.
617 */
618
619/* Reset all macros within TRACEPOINT_EVENT */
620#include "lttng-events-reset.h"
621#include "lttng-events-write.h"
622
623#undef _ctf_integer_ext_fetched
624#define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
625 { \
626 _type __tmp = _src; \
627 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
628 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
629 }
630
631#undef _ctf_integer_ext_isuser0
632#define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
633 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
634
635#undef _ctf_integer_ext_isuser1
636#define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
637{ \
638 union { \
639 char __array[sizeof(_user_src)]; \
640 __typeof__(_user_src) __v; \
641 } __tmp_fetch; \
642 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
643 &(_user_src), sizeof(_user_src))) \
644 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
645 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
646}
647
648#undef _ctf_integer_ext
649#define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
650 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
651
652#undef _ctf_array_encoded
653#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
654 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
655 if (_user) { \
656 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
657 } else { \
658 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
659 }
660
661#undef _ctf_sequence_encoded
662#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
663 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
664 { \
665 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
666 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
667 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
668 } \
669 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
670 if (_user) { \
671 __chan->ops->event_write_from_user(&__ctx, _src, \
672 sizeof(_type) * __get_dynamic_len(dest)); \
673 } else { \
674 __chan->ops->event_write(&__ctx, _src, \
675 sizeof(_type) * __get_dynamic_len(dest)); \
676 }
677
678#undef _ctf_string
679#define _ctf_string(_item, _src, _user, _nowrite) \
680 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
681 if (_user) { \
682 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
683 __get_dynamic_len(dest)); \
684 } else { \
685 __chan->ops->event_strcpy(&__ctx, _src, \
686 __get_dynamic_len(dest)); \
687 }
688
689/* Beware: this get len actually consumes the len value */
690#undef __get_dynamic_len
691#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
692
693#undef TP_PROTO
694#define TP_PROTO(...) __VA_ARGS__
695
696#undef TP_ARGS
697#define TP_ARGS(...) __VA_ARGS__
698
699#undef TP_FIELDS
700#define TP_FIELDS(...) __VA_ARGS__
701
702#undef TP_locvar
703#define TP_locvar(...) __VA_ARGS__
704
705#undef TP_code
706#define TP_code(...) __VA_ARGS__
707
708/*
709 * For state dump, check that "session" argument (mandatory) matches the
710 * session this event belongs to. Ensures that we write state dump data only
711 * into the started session, not into all sessions.
712 */
713#ifdef TP_SESSION_CHECK
714#define _TP_SESSION_CHECK(session, csession) (session == csession)
715#else /* TP_SESSION_CHECK */
716#define _TP_SESSION_CHECK(session, csession) 1
717#endif /* TP_SESSION_CHECK */
718
719/*
720 * Using twice size for filter stack data to hold size and pointer for
721 * each field (worse case). For integers, max size required is 64-bit.
722 * Same for double-precision floats. Those fit within
723 * 2*sizeof(unsigned long) for all supported architectures.
724 * Perform UNION (||) of filter runtime list.
725 */
726#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
727#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
728static void __event_probe__##_name(void *__data, _proto) \
729{ \
730 struct probe_local_vars { _locvar }; \
731 struct lttng_event *__event = __data; \
732 struct lttng_channel *__chan = __event->chan; \
733 struct lttng_session *__session = __chan->session; \
734 struct lib_ring_buffer_ctx __ctx; \
735 size_t __event_len, __event_align; \
736 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
737 union { \
738 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
739 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
740 } __stackvar; \
741 int __ret; \
742 struct probe_local_vars __tp_locvar; \
743 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
744 &__tp_locvar; \
745 struct lttng_pid_tracker *__lpf; \
746 \
747 if (!_TP_SESSION_CHECK(session, __session)) \
748 return; \
749 if (unlikely(!ACCESS_ONCE(__session->active))) \
750 return; \
751 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
752 return; \
753 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
754 return; \
755 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
756 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
757 return; \
758 _code \
759 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
760 struct lttng_bytecode_runtime *bc_runtime; \
761 int __filter_record = __event->has_enablers_without_bytecode; \
762 \
763 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
764 tp_locvar, _args); \
765 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
766 if (unlikely(bc_runtime->filter(bc_runtime, \
767 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
768 __filter_record = 1; \
769 } \
770 if (likely(!__filter_record)) \
771 return; \
772 } \
773 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
774 tp_locvar, _args); \
775 __event_align = __event_get_align__##_name(tp_locvar, _args); \
776 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
777 __event_align, -1); \
778 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
779 if (__ret < 0) \
780 return; \
781 _fields \
782 __chan->ops->event_commit(&__ctx); \
783}
784
785#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
786#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
787static void __event_probe__##_name(void *__data) \
788{ \
789 struct probe_local_vars { _locvar }; \
790 struct lttng_event *__event = __data; \
791 struct lttng_channel *__chan = __event->chan; \
792 struct lttng_session *__session = __chan->session; \
793 struct lib_ring_buffer_ctx __ctx; \
794 size_t __event_len, __event_align; \
795 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
796 union { \
797 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
798 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
799 } __stackvar; \
800 int __ret; \
801 struct probe_local_vars __tp_locvar; \
802 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
803 &__tp_locvar; \
804 struct lttng_pid_tracker *__lpf; \
805 \
806 if (!_TP_SESSION_CHECK(session, __session)) \
807 return; \
808 if (unlikely(!ACCESS_ONCE(__session->active))) \
809 return; \
810 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
811 return; \
812 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
813 return; \
814 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
815 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
816 return; \
817 _code \
818 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
819 struct lttng_bytecode_runtime *bc_runtime; \
820 int __filter_record = __event->has_enablers_without_bytecode; \
821 \
822 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
823 tp_locvar); \
824 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
825 if (unlikely(bc_runtime->filter(bc_runtime, \
826 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
827 __filter_record = 1; \
828 } \
829 if (likely(!__filter_record)) \
830 return; \
831 } \
832 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
833 __event_align = __event_get_align__##_name(tp_locvar); \
834 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
835 __event_align, -1); \
836 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
837 if (__ret < 0) \
838 return; \
839 _fields \
840 __chan->ops->event_commit(&__ctx); \
841}
842
843#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
844
845#undef __get_dynamic_len
846
847/*
848 * Stage 7 of the trace events.
849 *
850 * Create event descriptions.
851 */
852
853/* Named field types must be defined in lttng-types.h */
854
855#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
856
857#ifndef TP_PROBE_CB
858#define TP_PROBE_CB(_template) &__event_probe__##_template
859#endif
860
861#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
862#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
863static const struct lttng_event_desc __event_desc___##_map = { \
864 .fields = __event_fields___##_template, \
865 .name = #_map, \
866 .kname = #_name, \
867 .probe_callback = (void *) TP_PROBE_CB(_template), \
868 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
869 .owner = THIS_MODULE, \
870};
871
872#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
873#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
874 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
875
876#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
877
878/*
879 * Stage 8 of the trace events.
880 *
881 * Create an array of event description pointers.
882 */
883
884#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
885
886#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
887#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
888 &__event_desc___##_map,
889
890#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
891#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
892 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
893
894#define TP_ID1(_token, _system) _token##_system
895#define TP_ID(_token, _system) TP_ID1(_token, _system)
896
897static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
898#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
899};
900
901#undef TP_ID1
902#undef TP_ID
903
904/*
905 * Stage 9 of the trace events.
906 *
907 * Create a toplevel descriptor for the whole probe.
908 */
909
910#define TP_ID1(_token, _system) _token##_system
911#define TP_ID(_token, _system) TP_ID1(_token, _system)
912
913/* non-const because list head will be modified when registered. */
914static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
915 .provider = __stringify(TRACE_SYSTEM),
916 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
917 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
918 .head = { NULL, NULL },
919 .lazy_init_head = { NULL, NULL },
920 .lazy = 0,
921};
922
923#undef TP_ID1
924#undef TP_ID
925
926/*
927 * Stage 10 of the trace events.
928 *
929 * Register/unregister probes at module load/unload.
930 */
931
932#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
933
934#define TP_ID1(_token, _system) _token##_system
935#define TP_ID(_token, _system) TP_ID1(_token, _system)
936#define module_init_eval1(_token, _system) module_init(_token##_system)
937#define module_init_eval(_token, _system) module_init_eval1(_token, _system)
938#define module_exit_eval1(_token, _system) module_exit(_token##_system)
939#define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
940
941#ifndef TP_MODULE_NOINIT
942static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
943{
944 wrapper_vmalloc_sync_all();
945 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
946}
947
948static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
949{
950 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
951}
952
953#ifndef TP_MODULE_NOAUTOLOAD
954module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
955module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
956#endif
957
958#endif
959
960#undef module_init_eval
961#undef module_exit_eval
962#undef TP_ID1
963#undef TP_ID
964
965#undef TP_PROTO
966#undef TP_ARGS
This page took 0.02616 seconds and 4 git commands to generate.