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