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