| 1 | /* |
| 2 | * lttng-events.h |
| 3 | * |
| 4 | * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org> |
| 5 | * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 6 | * |
| 7 | * Dual LGPL v2.1/GPL v2 license. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/debugfs.h> |
| 11 | #include "lttng.h" |
| 12 | #include "lttng-types.h" |
| 13 | #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ |
| 14 | #include "../wrapper/ringbuffer/frontend_types.h" |
| 15 | #include "../ltt-events.h" |
| 16 | #include "../ltt-tracer-core.h" |
| 17 | |
| 18 | /* |
| 19 | * Macro declarations used for all stages. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * DECLARE_EVENT_CLASS can be used to add a generic function |
| 24 | * handlers for events. That is, if all events have the same |
| 25 | * parameters and just have distinct trace points. |
| 26 | * Each tracepoint can be defined with DEFINE_EVENT and that |
| 27 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
| 28 | * |
| 29 | * TRACE_EVENT is a one to one mapping between tracepoint and template. |
| 30 | */ |
| 31 | |
| 32 | #undef TRACE_EVENT |
| 33 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
| 34 | DECLARE_EVENT_CLASS(name, \ |
| 35 | PARAMS(proto), \ |
| 36 | PARAMS(args), \ |
| 37 | PARAMS(tstruct), \ |
| 38 | PARAMS(assign), \ |
| 39 | PARAMS(print)) \ |
| 40 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)) |
| 41 | |
| 42 | #undef TRACE_EVENT_NOARGS |
| 43 | #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \ |
| 44 | DECLARE_EVENT_CLASS_NOARGS(name, \ |
| 45 | PARAMS(tstruct), \ |
| 46 | PARAMS(assign), \ |
| 47 | PARAMS(print)) \ |
| 48 | DEFINE_EVENT_NOARGS(name, name) |
| 49 | |
| 50 | |
| 51 | #undef DEFINE_EVENT_PRINT |
| 52 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 53 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 54 | |
| 55 | /* Callbacks are meaningless to LTTng. */ |
| 56 | #undef TRACE_EVENT_FN |
| 57 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
| 58 | assign, print, reg, unreg) \ |
| 59 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ |
| 60 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ |
| 61 | |
| 62 | /* |
| 63 | * Stage 1 of the trace events. |
| 64 | * |
| 65 | * Create dummy trace calls for each events, verifying that the LTTng module |
| 66 | * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the |
| 67 | * compiler. |
| 68 | */ |
| 69 | |
| 70 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 71 | |
| 72 | #undef TP_PROTO |
| 73 | #define TP_PROTO(args...) args |
| 74 | |
| 75 | #undef TP_ARGS |
| 76 | #define TP_ARGS(args...) args |
| 77 | |
| 78 | #undef DEFINE_EVENT |
| 79 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 80 | void trace_##_name(_proto); |
| 81 | |
| 82 | #undef DEFINE_EVENT_NOARGS |
| 83 | #define DEFINE_EVENT_NOARGS(_template, _name) \ |
| 84 | void trace_##_name(void *__data); |
| 85 | |
| 86 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 87 | |
| 88 | /* |
| 89 | * Stage 2 of the trace events. |
| 90 | * |
| 91 | * Create event field type metadata section. |
| 92 | * Each event produce an array of fields. |
| 93 | */ |
| 94 | |
| 95 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 96 | |
| 97 | /* Named field types must be defined in lttng-types.h */ |
| 98 | |
| 99 | #undef __field_full |
| 100 | #define __field_full(_type, _item, _order, _base) \ |
| 101 | { \ |
| 102 | .name = #_item, \ |
| 103 | .type = __type_integer(_type, _order, _base, none), \ |
| 104 | }, |
| 105 | |
| 106 | #undef __field |
| 107 | #define __field(_type, _item) \ |
| 108 | __field_full(_type, _item, __BYTE_ORDER, 10) |
| 109 | |
| 110 | #undef __field_ext |
| 111 | #define __field_ext(_type, _item, _filter_type) \ |
| 112 | __field(_type, _item) |
| 113 | |
| 114 | #undef __field_hex |
| 115 | #define __field_hex(_type, _item) \ |
| 116 | __field_full(_type, _item, __BYTE_ORDER, 16) |
| 117 | |
| 118 | #undef __field_network |
| 119 | #define __field_network(_type, _item) \ |
| 120 | __field_full(_type, _item, __BIG_ENDIAN, 10) |
| 121 | |
| 122 | #undef __field_network_hex |
| 123 | #define __field_network_hex(_type, _item) \ |
| 124 | __field_full(_type, _item, __BIG_ENDIAN, 16) |
| 125 | |
| 126 | #undef __array_enc_ext |
| 127 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 128 | { \ |
| 129 | .name = #_item, \ |
| 130 | .type = \ |
| 131 | { \ |
| 132 | .atype = atype_array, \ |
| 133 | .u.array = \ |
| 134 | { \ |
| 135 | .length = _length, \ |
| 136 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
| 137 | }, \ |
| 138 | }, \ |
| 139 | }, |
| 140 | |
| 141 | #undef __array |
| 142 | #define __array(_type, _item, _length) \ |
| 143 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
| 144 | |
| 145 | #undef __array_text |
| 146 | #define __array_text(_type, _item, _length) \ |
| 147 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
| 148 | |
| 149 | #undef __array_hex |
| 150 | #define __array_hex(_type, _item, _length) \ |
| 151 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) |
| 152 | |
| 153 | #undef __dynamic_array_enc_ext |
| 154 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 155 | { \ |
| 156 | .name = #_item, \ |
| 157 | .type = \ |
| 158 | { \ |
| 159 | .atype = atype_sequence, \ |
| 160 | .u.sequence = \ |
| 161 | { \ |
| 162 | .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \ |
| 163 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
| 164 | }, \ |
| 165 | }, \ |
| 166 | }, |
| 167 | |
| 168 | #undef __dynamic_array |
| 169 | #define __dynamic_array(_type, _item, _length) \ |
| 170 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
| 171 | |
| 172 | #undef __dynamic_array_text |
| 173 | #define __dynamic_array_text(_type, _item, _length) \ |
| 174 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
| 175 | |
| 176 | #undef __dynamic_array_hex |
| 177 | #define __dynamic_array_hex(_type, _item, _length) \ |
| 178 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) |
| 179 | |
| 180 | #undef __string |
| 181 | #define __string(_item, _src) \ |
| 182 | { \ |
| 183 | .name = #_item, \ |
| 184 | .type = \ |
| 185 | { \ |
| 186 | .atype = atype_string, \ |
| 187 | .u.basic.string.encoding = lttng_encode_UTF8, \ |
| 188 | }, \ |
| 189 | }, |
| 190 | |
| 191 | #undef TP_STRUCT__entry |
| 192 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
| 193 | |
| 194 | #undef DECLARE_EVENT_CLASS_NOARGS |
| 195 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ |
| 196 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
| 197 | _tstruct \ |
| 198 | }; |
| 199 | |
| 200 | #undef DECLARE_EVENT_CLASS |
| 201 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 202 | DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \ |
| 203 | PARAMS(_print)) |
| 204 | |
| 205 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 206 | |
| 207 | /* |
| 208 | * Stage 3 of the trace events. |
| 209 | * |
| 210 | * Create probe callback prototypes. |
| 211 | */ |
| 212 | |
| 213 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 214 | |
| 215 | #undef TP_PROTO |
| 216 | #define TP_PROTO(args...) args |
| 217 | |
| 218 | #undef DECLARE_EVENT_CLASS |
| 219 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 220 | static void __event_probe__##_name(void *__data, _proto); |
| 221 | |
| 222 | #undef DECLARE_EVENT_CLASS_NOARGS |
| 223 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ |
| 224 | static void __event_probe__##_name(void *__data); |
| 225 | |
| 226 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 227 | |
| 228 | /* |
| 229 | * Stage 3.9 of the trace events. |
| 230 | * |
| 231 | * Create event descriptions. |
| 232 | */ |
| 233 | |
| 234 | /* Named field types must be defined in lttng-types.h */ |
| 235 | |
| 236 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 237 | |
| 238 | #ifndef TP_PROBE_CB |
| 239 | #define TP_PROBE_CB(_template) &__event_probe__##_template |
| 240 | #endif |
| 241 | |
| 242 | #undef DEFINE_EVENT_NOARGS |
| 243 | #define DEFINE_EVENT_NOARGS(_template, _name) \ |
| 244 | static const struct lttng_event_desc __event_desc___##_name = { \ |
| 245 | .fields = __event_fields___##_template, \ |
| 246 | .name = #_name, \ |
| 247 | .probe_callback = (void *) TP_PROBE_CB(_template), \ |
| 248 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ |
| 249 | .owner = THIS_MODULE, \ |
| 250 | }; |
| 251 | |
| 252 | #undef DEFINE_EVENT |
| 253 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 254 | DEFINE_EVENT_NOARGS(_template, _name) |
| 255 | |
| 256 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 257 | |
| 258 | |
| 259 | /* |
| 260 | * Stage 4 of the trace events. |
| 261 | * |
| 262 | * Create an array of event description pointers. |
| 263 | */ |
| 264 | |
| 265 | /* Named field types must be defined in lttng-types.h */ |
| 266 | |
| 267 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 268 | |
| 269 | #undef DEFINE_EVENT_NOARGS |
| 270 | #define DEFINE_EVENT_NOARGS(_template, _name) \ |
| 271 | &__event_desc___##_name, |
| 272 | |
| 273 | #undef DEFINE_EVENT |
| 274 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 275 | DEFINE_EVENT_NOARGS(_template, _name) |
| 276 | |
| 277 | #define TP_ID1(_token, _system) _token##_system |
| 278 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 279 | |
| 280 | static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = { |
| 281 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 282 | }; |
| 283 | |
| 284 | #undef TP_ID1 |
| 285 | #undef TP_ID |
| 286 | |
| 287 | |
| 288 | /* |
| 289 | * Stage 5 of the trace events. |
| 290 | * |
| 291 | * Create a toplevel descriptor for the whole probe. |
| 292 | */ |
| 293 | |
| 294 | #define TP_ID1(_token, _system) _token##_system |
| 295 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 296 | |
| 297 | /* non-const because list head will be modified when registered. */ |
| 298 | static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { |
| 299 | .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM), |
| 300 | .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)), |
| 301 | }; |
| 302 | |
| 303 | #undef TP_ID1 |
| 304 | #undef TP_ID |
| 305 | |
| 306 | /* |
| 307 | * Stage 6 of the trace events. |
| 308 | * |
| 309 | * Create static inline function that calculates event size. |
| 310 | */ |
| 311 | |
| 312 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 313 | |
| 314 | /* Named field types must be defined in lttng-types.h */ |
| 315 | |
| 316 | #undef __field_full |
| 317 | #define __field_full(_type, _item, _order, _base) \ |
| 318 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
| 319 | __event_len += sizeof(_type); |
| 320 | |
| 321 | #undef __array_enc_ext |
| 322 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 323 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
| 324 | __event_len += sizeof(_type) * (_length); |
| 325 | |
| 326 | #undef __dynamic_array_enc_ext |
| 327 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 328 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(u32)); \ |
| 329 | __event_len += sizeof(u32); \ |
| 330 | __event_len += lib_ring_buffer_align(__event_len, ltt_alignof(_type)); \ |
| 331 | __dynamic_len[__dynamic_len_idx] = (_length); \ |
| 332 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ |
| 333 | __dynamic_len_idx++; |
| 334 | |
| 335 | #undef __string |
| 336 | #define __string(_item, _src) \ |
| 337 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
| 338 | |
| 339 | #undef TP_PROTO |
| 340 | #define TP_PROTO(args...) args |
| 341 | |
| 342 | #undef TP_STRUCT__entry |
| 343 | #define TP_STRUCT__entry(args...) args |
| 344 | |
| 345 | #undef DECLARE_EVENT_CLASS |
| 346 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 347 | static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ |
| 348 | { \ |
| 349 | size_t __event_len = 0; \ |
| 350 | unsigned int __dynamic_len_idx = 0; \ |
| 351 | \ |
| 352 | if (0) \ |
| 353 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 354 | _tstruct \ |
| 355 | return __event_len; \ |
| 356 | } |
| 357 | |
| 358 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 359 | |
| 360 | /* |
| 361 | * Stage 7 of the trace events. |
| 362 | * |
| 363 | * Create static inline function that calculates event payload alignment. |
| 364 | */ |
| 365 | |
| 366 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 367 | |
| 368 | /* Named field types must be defined in lttng-types.h */ |
| 369 | |
| 370 | #undef __field_full |
| 371 | #define __field_full(_type, _item, _order, _base) \ |
| 372 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
| 373 | |
| 374 | #undef __array_enc_ext |
| 375 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 376 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
| 377 | |
| 378 | #undef __dynamic_array_enc_ext |
| 379 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 380 | __event_align = max_t(size_t, __event_align, ltt_alignof(u32)); \ |
| 381 | __event_align = max_t(size_t, __event_align, ltt_alignof(_type)); |
| 382 | |
| 383 | #undef __string |
| 384 | #define __string(_item, _src) |
| 385 | |
| 386 | #undef TP_PROTO |
| 387 | #define TP_PROTO(args...) args |
| 388 | |
| 389 | #undef TP_STRUCT__entry |
| 390 | #define TP_STRUCT__entry(args...) args |
| 391 | |
| 392 | #undef DECLARE_EVENT_CLASS |
| 393 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 394 | static inline size_t __event_get_align__##_name(_proto) \ |
| 395 | { \ |
| 396 | size_t __event_align = 1; \ |
| 397 | _tstruct \ |
| 398 | return __event_align; \ |
| 399 | } |
| 400 | |
| 401 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 402 | |
| 403 | |
| 404 | /* |
| 405 | * Stage 8 of the trace events. |
| 406 | * |
| 407 | * Create structure declaration that allows the "assign" macros to access the |
| 408 | * field types. |
| 409 | */ |
| 410 | |
| 411 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 412 | |
| 413 | /* Named field types must be defined in lttng-types.h */ |
| 414 | |
| 415 | #undef __field_full |
| 416 | #define __field_full(_type, _item, _order, _base) _type _item; |
| 417 | |
| 418 | #undef __array_enc_ext |
| 419 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 420 | _type _item; |
| 421 | |
| 422 | #undef __dynamic_array_enc_ext |
| 423 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 424 | _type _item; |
| 425 | |
| 426 | #undef __string |
| 427 | #define __string(_item, _src) char _item; |
| 428 | |
| 429 | #undef TP_STRUCT__entry |
| 430 | #define TP_STRUCT__entry(args...) args |
| 431 | |
| 432 | #undef DECLARE_EVENT_CLASS |
| 433 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 434 | struct __event_typemap__##_name { \ |
| 435 | _tstruct \ |
| 436 | }; |
| 437 | |
| 438 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 439 | |
| 440 | |
| 441 | /* |
| 442 | * Stage 9 of the trace events. |
| 443 | * |
| 444 | * Create the probe function : call even size calculation and write event data |
| 445 | * into the buffer. |
| 446 | * |
| 447 | * We use both the field and assignment macros to write the fields in the order |
| 448 | * defined in the field declaration. The field declarations control the |
| 449 | * execution order, jumping to the appropriate assignment block. |
| 450 | */ |
| 451 | |
| 452 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 453 | |
| 454 | #undef __field_full |
| 455 | #define __field_full(_type, _item, _order, _base) \ |
| 456 | goto __assign_##_item; \ |
| 457 | __end_field_##_item: |
| 458 | |
| 459 | #undef __array_enc_ext |
| 460 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 461 | goto __assign_##_item; \ |
| 462 | __end_field_##_item: |
| 463 | |
| 464 | #undef __dynamic_array_enc_ext |
| 465 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 466 | goto __assign_##_item##_1; \ |
| 467 | __end_field_##_item##_1: \ |
| 468 | goto __assign_##_item##_2; \ |
| 469 | __end_field_##_item##_2: |
| 470 | |
| 471 | #undef __string |
| 472 | #define __string(_item, _src) \ |
| 473 | goto __assign_##_item; \ |
| 474 | __end_field_##_item: |
| 475 | |
| 476 | /* |
| 477 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to |
| 478 | * strcpy(). |
| 479 | */ |
| 480 | #undef tp_assign |
| 481 | #define tp_assign(dest, src) \ |
| 482 | __assign_##dest: \ |
| 483 | { \ |
| 484 | __typeof__(__typemap.dest) __tmp = (src); \ |
| 485 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__tmp)); \ |
| 486 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
| 487 | } \ |
| 488 | goto __end_field_##dest; |
| 489 | |
| 490 | #undef tp_memcpy |
| 491 | #define tp_memcpy(dest, src, len) \ |
| 492 | __assign_##dest: \ |
| 493 | if (0) \ |
| 494 | (void) __typemap.dest; \ |
| 495 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ |
| 496 | __chan->ops->event_write(&__ctx, src, len); \ |
| 497 | goto __end_field_##dest; |
| 498 | |
| 499 | #undef tp_memcpy_dyn |
| 500 | #define tp_memcpy_dyn(dest, src) \ |
| 501 | __assign_##dest##_1: \ |
| 502 | { \ |
| 503 | u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \ |
| 504 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(u32)); \ |
| 505 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \ |
| 506 | } \ |
| 507 | goto __end_field_##dest##_1; \ |
| 508 | __assign_##dest##_2: \ |
| 509 | lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ |
| 510 | __chan->ops->event_write(&__ctx, src, \ |
| 511 | sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\ |
| 512 | goto __end_field_##dest##_2; |
| 513 | |
| 514 | #undef tp_strcpy |
| 515 | #define tp_strcpy(dest, src) \ |
| 516 | tp_memcpy(dest, src, __get_dynamic_array_len(dest)) |
| 517 | |
| 518 | /* Named field types must be defined in lttng-types.h */ |
| 519 | |
| 520 | #undef __get_str |
| 521 | #define __get_str(field) field |
| 522 | |
| 523 | #undef __get_dynamic_array |
| 524 | #define __get_dynamic_array(field) field |
| 525 | |
| 526 | /* Beware: this get len actually consumes the len value */ |
| 527 | #undef __get_dynamic_array_len |
| 528 | #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++] |
| 529 | |
| 530 | #undef TP_PROTO |
| 531 | #define TP_PROTO(args...) args |
| 532 | |
| 533 | #undef TP_ARGS |
| 534 | #define TP_ARGS(args...) args |
| 535 | |
| 536 | #undef TP_STRUCT__entry |
| 537 | #define TP_STRUCT__entry(args...) args |
| 538 | |
| 539 | #undef TP_fast_assign |
| 540 | #define TP_fast_assign(args...) args |
| 541 | |
| 542 | #undef DECLARE_EVENT_CLASS |
| 543 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 544 | static void __event_probe__##_name(void *__data, _proto) \ |
| 545 | { \ |
| 546 | struct ltt_event *__event = __data; \ |
| 547 | struct ltt_channel *__chan = __event->chan; \ |
| 548 | struct lib_ring_buffer_ctx __ctx; \ |
| 549 | size_t __event_len, __event_align; \ |
| 550 | size_t __dynamic_len_idx = 0; \ |
| 551 | size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ |
| 552 | struct __event_typemap__##_name __typemap; \ |
| 553 | int __ret; \ |
| 554 | \ |
| 555 | if (0) \ |
| 556 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 557 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ |
| 558 | return; \ |
| 559 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ |
| 560 | return; \ |
| 561 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ |
| 562 | return; \ |
| 563 | __event_len = __event_get_size__##_name(__dynamic_len, _args); \ |
| 564 | __event_align = __event_get_align__##_name(_args); \ |
| 565 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
| 566 | __event_align, -1); \ |
| 567 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
| 568 | if (__ret < 0) \ |
| 569 | return; \ |
| 570 | /* Control code (field ordering) */ \ |
| 571 | _tstruct \ |
| 572 | __chan->ops->event_commit(&__ctx); \ |
| 573 | return; \ |
| 574 | /* Copy code, steered by control code */ \ |
| 575 | _assign \ |
| 576 | } |
| 577 | |
| 578 | #undef DECLARE_EVENT_CLASS_NOARGS |
| 579 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ |
| 580 | static void __event_probe__##_name(void *__data) \ |
| 581 | { \ |
| 582 | struct ltt_event *__event = __data; \ |
| 583 | struct ltt_channel *__chan = __event->chan; \ |
| 584 | struct lib_ring_buffer_ctx __ctx; \ |
| 585 | size_t __event_len, __event_align; \ |
| 586 | int __ret; \ |
| 587 | \ |
| 588 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ |
| 589 | return; \ |
| 590 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ |
| 591 | return; \ |
| 592 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ |
| 593 | return; \ |
| 594 | __event_len = 0; \ |
| 595 | __event_align = 1; \ |
| 596 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
| 597 | __event_align, -1); \ |
| 598 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
| 599 | if (__ret < 0) \ |
| 600 | return; \ |
| 601 | /* Control code (field ordering) */ \ |
| 602 | _tstruct \ |
| 603 | __chan->ops->event_commit(&__ctx); \ |
| 604 | return; \ |
| 605 | /* Copy code, steered by control code */ \ |
| 606 | _assign \ |
| 607 | } |
| 608 | |
| 609 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 610 | |
| 611 | /* |
| 612 | * Stage 10 of the trace events. |
| 613 | * |
| 614 | * Register/unregister probes at module load/unload. |
| 615 | */ |
| 616 | |
| 617 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 618 | |
| 619 | #define TP_ID1(_token, _system) _token##_system |
| 620 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 621 | #define module_init_eval1(_token, _system) module_init(_token##_system) |
| 622 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) |
| 623 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) |
| 624 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) |
| 625 | |
| 626 | #ifndef TP_MODULE_OVERRIDE |
| 627 | static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) |
| 628 | { |
| 629 | wrapper_vmalloc_sync_all(); |
| 630 | return ltt_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
| 631 | } |
| 632 | |
| 633 | module_init_eval(__lttng_events_init__, TRACE_SYSTEM); |
| 634 | |
| 635 | static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) |
| 636 | { |
| 637 | ltt_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
| 638 | } |
| 639 | |
| 640 | module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM); |
| 641 | #endif |
| 642 | |
| 643 | #undef module_init_eval |
| 644 | #undef module_exit_eval |
| 645 | #undef TP_ID1 |
| 646 | #undef TP_ID |
| 647 | |
| 648 | #undef TP_PROTO |
| 649 | #undef TP_ARGS |
| 650 | #undef TRACE_EVENT_FLAGS |