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