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