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