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