| 1 | /* |
| 2 | * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | */ |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <urcu/compiler.h> |
| 17 | #include <lttng/ust-events.h> |
| 18 | #include <lttng/ringbuffer-config.h> |
| 19 | #include <lttng/ust-compiler.h> |
| 20 | #include <string.h> |
| 21 | |
| 22 | /* |
| 23 | * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the |
| 24 | * same arguments and having the same field layout. |
| 25 | * |
| 26 | * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with |
| 27 | * its own provider and name. It refers to a class (template). |
| 28 | * |
| 29 | * TRACEPOINT_EVENT declared both a class and an instance and does a |
| 30 | * direct mapping from the instance to the class. |
| 31 | */ |
| 32 | |
| 33 | #undef TRACEPOINT_EVENT |
| 34 | #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \ |
| 35 | TRACEPOINT_EVENT_CLASS(_provider, _name, \ |
| 36 | _TP_PARAMS(_args), \ |
| 37 | _TP_PARAMS(_fields)) \ |
| 38 | TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \ |
| 39 | _TP_PARAMS(_args)) |
| 40 | |
| 41 | /* Helpers */ |
| 42 | #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 43 | |
| 44 | #define _tp_max_t(type, x, y) \ |
| 45 | ({ \ |
| 46 | type __max1 = (x); \ |
| 47 | type __max2 = (y); \ |
| 48 | __max1 > __max2 ? __max1: __max2; \ |
| 49 | }) |
| 50 | |
| 51 | /* |
| 52 | * Stage 0 of tracepoint event generation. |
| 53 | * |
| 54 | * Check that each TRACEPOINT_EVENT provider argument match the |
| 55 | * TRACEPOINT_PROVIDER by creating dummy callbacks. |
| 56 | */ |
| 57 | |
| 58 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 59 | #include <lttng/ust-tracepoint-event-reset.h> |
| 60 | |
| 61 | static inline |
| 62 | void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void) |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | #undef TRACEPOINT_EVENT_CLASS |
| 67 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 68 | __tracepoint_provider_mismatch_##_provider(); |
| 69 | |
| 70 | #undef TRACEPOINT_EVENT_INSTANCE |
| 71 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 72 | __tracepoint_provider_mismatch_##_provider(); |
| 73 | |
| 74 | static __attribute__((unused)) |
| 75 | void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void) |
| 76 | { |
| 77 | #include TRACEPOINT_INCLUDE |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Stage 0.1 of tracepoint event generation. |
| 82 | * |
| 83 | * Check that each TRACEPOINT_EVENT provider:name does not exceed the |
| 84 | * tracepoint name length limit. |
| 85 | */ |
| 86 | |
| 87 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 88 | #include <lttng/ust-tracepoint-event-reset.h> |
| 89 | |
| 90 | #undef TRACEPOINT_EVENT_INSTANCE |
| 91 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 92 | static const char \ |
| 93 | __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \ |
| 94 | __attribute__((unused)) = \ |
| 95 | #_provider ":" #_name; |
| 96 | |
| 97 | #include TRACEPOINT_INCLUDE |
| 98 | |
| 99 | /* |
| 100 | * Stage 1 of tracepoint event generation. |
| 101 | * |
| 102 | * Create event field type metadata section. |
| 103 | * Each event produce an array of fields. |
| 104 | */ |
| 105 | |
| 106 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 107 | #include <lttng/ust-tracepoint-event-reset.h> |
| 108 | #include <lttng/ust-tracepoint-event-write.h> |
| 109 | #include <lttng/ust-tracepoint-event-nowrite.h> |
| 110 | |
| 111 | #undef _ctf_integer_ext |
| 112 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 113 | { \ |
| 114 | .name = #_item, \ |
| 115 | .type = __type_integer(_type, _byte_order, _base, none),\ |
| 116 | .nowrite = _nowrite, \ |
| 117 | }, |
| 118 | |
| 119 | #undef _ctf_float |
| 120 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 121 | { \ |
| 122 | .name = #_item, \ |
| 123 | .type = __type_float(_type), \ |
| 124 | .nowrite = _nowrite, \ |
| 125 | }, |
| 126 | |
| 127 | #undef _ctf_array_encoded |
| 128 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 129 | { \ |
| 130 | .name = #_item, \ |
| 131 | .type = \ |
| 132 | { \ |
| 133 | .atype = atype_array, \ |
| 134 | .u.array = \ |
| 135 | { \ |
| 136 | .length = _length, \ |
| 137 | .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ |
| 138 | }, \ |
| 139 | }, \ |
| 140 | .nowrite = _nowrite, \ |
| 141 | }, |
| 142 | |
| 143 | #undef _ctf_sequence_encoded |
| 144 | #define _ctf_sequence_encoded(_type, _item, _src, \ |
| 145 | _length_type, _src_length, _encoding, _nowrite) \ |
| 146 | { \ |
| 147 | .name = #_item, \ |
| 148 | .type = \ |
| 149 | { \ |
| 150 | .atype = atype_sequence, \ |
| 151 | .u.sequence = \ |
| 152 | { \ |
| 153 | .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \ |
| 154 | .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ |
| 155 | }, \ |
| 156 | }, \ |
| 157 | .nowrite = _nowrite, \ |
| 158 | }, |
| 159 | |
| 160 | #undef _ctf_string |
| 161 | #define _ctf_string(_item, _src, _nowrite) \ |
| 162 | { \ |
| 163 | .name = #_item, \ |
| 164 | .type = \ |
| 165 | { \ |
| 166 | .atype = atype_string, \ |
| 167 | .u.basic.string.encoding = lttng_encode_UTF8, \ |
| 168 | }, \ |
| 169 | .nowrite = _nowrite, \ |
| 170 | }, |
| 171 | |
| 172 | #undef TP_FIELDS |
| 173 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ |
| 174 | |
| 175 | #undef TRACEPOINT_EVENT_CLASS |
| 176 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 177 | static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \ |
| 178 | _fields \ |
| 179 | }; |
| 180 | |
| 181 | #include TRACEPOINT_INCLUDE |
| 182 | |
| 183 | /* |
| 184 | * Stage 2 of tracepoint event generation. |
| 185 | * |
| 186 | * Create probe callback prototypes. |
| 187 | */ |
| 188 | |
| 189 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 190 | #include <lttng/ust-tracepoint-event-reset.h> |
| 191 | |
| 192 | #undef TP_ARGS |
| 193 | #define TP_ARGS(...) __VA_ARGS__ |
| 194 | |
| 195 | #undef TRACEPOINT_EVENT_CLASS |
| 196 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 197 | static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); |
| 198 | |
| 199 | #include TRACEPOINT_INCLUDE |
| 200 | |
| 201 | /* |
| 202 | * Stage 3 of tracepoint event generation. |
| 203 | * |
| 204 | * Create static inline function that calculates event size. |
| 205 | */ |
| 206 | |
| 207 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 208 | #include <lttng/ust-tracepoint-event-reset.h> |
| 209 | #include <lttng/ust-tracepoint-event-write.h> |
| 210 | |
| 211 | #undef _ctf_integer_ext |
| 212 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 213 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 214 | __event_len += sizeof(_type); |
| 215 | |
| 216 | #undef _ctf_float |
| 217 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 218 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 219 | __event_len += sizeof(_type); |
| 220 | |
| 221 | #undef _ctf_array_encoded |
| 222 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 223 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 224 | __event_len += sizeof(_type) * (_length); |
| 225 | |
| 226 | #undef _ctf_sequence_encoded |
| 227 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 228 | _src_length, _encoding, _nowrite) \ |
| 229 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \ |
| 230 | __event_len += sizeof(_length_type); \ |
| 231 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 232 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ |
| 233 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ |
| 234 | __dynamic_len_idx++; |
| 235 | |
| 236 | #undef _ctf_string |
| 237 | #define _ctf_string(_item, _src, _nowrite) \ |
| 238 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
| 239 | |
| 240 | #undef TP_ARGS |
| 241 | #define TP_ARGS(...) __VA_ARGS__ |
| 242 | |
| 243 | #undef TP_FIELDS |
| 244 | #define TP_FIELDS(...) __VA_ARGS__ |
| 245 | |
| 246 | #undef TRACEPOINT_EVENT_CLASS |
| 247 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 248 | static inline lttng_ust_notrace \ |
| 249 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \ |
| 250 | static inline \ |
| 251 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ |
| 252 | { \ |
| 253 | size_t __event_len = 0; \ |
| 254 | unsigned int __dynamic_len_idx = 0; \ |
| 255 | \ |
| 256 | if (0) \ |
| 257 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 258 | _fields \ |
| 259 | return __event_len; \ |
| 260 | } |
| 261 | |
| 262 | #include TRACEPOINT_INCLUDE |
| 263 | |
| 264 | /* |
| 265 | * Stage 3.1 of tracepoint event generation. |
| 266 | * |
| 267 | * Create static inline function that layout the filter stack data. |
| 268 | * We make both write and nowrite data available to the filter. |
| 269 | */ |
| 270 | |
| 271 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 272 | #include <lttng/ust-tracepoint-event-reset.h> |
| 273 | #include <lttng/ust-tracepoint-event-write.h> |
| 274 | #include <lttng/ust-tracepoint-event-nowrite.h> |
| 275 | |
| 276 | #undef _ctf_integer_ext |
| 277 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 278 | if (lttng_is_signed_type(_type)) { \ |
| 279 | int64_t __ctf_tmp_int64 = (int64_t) (_type) (_src); \ |
| 280 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ |
| 281 | } else { \ |
| 282 | uint64_t __ctf_tmp_uint64 = (uint64_t) (_type) (_src); \ |
| 283 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ |
| 284 | } \ |
| 285 | __stack_data += sizeof(int64_t); |
| 286 | |
| 287 | #undef _ctf_float |
| 288 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 289 | { \ |
| 290 | double __ctf_tmp_double = (double) (_type) (_src); \ |
| 291 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ |
| 292 | __stack_data += sizeof(double); \ |
| 293 | } |
| 294 | |
| 295 | #undef _ctf_array_encoded |
| 296 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 297 | { \ |
| 298 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ |
| 299 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
| 300 | __stack_data += sizeof(unsigned long); \ |
| 301 | memcpy(__stack_data, &(_src), sizeof(void **)); \ |
| 302 | __stack_data += sizeof(void **); \ |
| 303 | } |
| 304 | |
| 305 | #undef _ctf_sequence_encoded |
| 306 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 307 | _src_length, _encoding, _nowrite) \ |
| 308 | { \ |
| 309 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ |
| 310 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
| 311 | __stack_data += sizeof(unsigned long); \ |
| 312 | memcpy(__stack_data, &(_src), sizeof(void **)); \ |
| 313 | __stack_data += sizeof(void **); \ |
| 314 | } |
| 315 | |
| 316 | #undef _ctf_string |
| 317 | #define _ctf_string(_item, _src, _nowrite) \ |
| 318 | { \ |
| 319 | memcpy(__stack_data, &(_src), sizeof(void **)); \ |
| 320 | __stack_data += sizeof(void **); \ |
| 321 | } |
| 322 | |
| 323 | #undef TP_ARGS |
| 324 | #define TP_ARGS(...) __VA_ARGS__ |
| 325 | |
| 326 | #undef TP_FIELDS |
| 327 | #define TP_FIELDS(...) __VA_ARGS__ |
| 328 | |
| 329 | #undef TRACEPOINT_EVENT_CLASS |
| 330 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 331 | static inline \ |
| 332 | void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\ |
| 333 | _TP_ARGS_DATA_PROTO(_args)) \ |
| 334 | { \ |
| 335 | _fields \ |
| 336 | } |
| 337 | |
| 338 | #include TRACEPOINT_INCLUDE |
| 339 | |
| 340 | |
| 341 | |
| 342 | /* |
| 343 | * Stage 4 of tracepoint event generation. |
| 344 | * |
| 345 | * Create static inline function that calculates event payload alignment. |
| 346 | */ |
| 347 | |
| 348 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 349 | #include <lttng/ust-tracepoint-event-reset.h> |
| 350 | #include <lttng/ust-tracepoint-event-write.h> |
| 351 | |
| 352 | #undef _ctf_integer_ext |
| 353 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 354 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 355 | |
| 356 | #undef _ctf_float |
| 357 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 358 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 359 | |
| 360 | #undef _ctf_array_encoded |
| 361 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 362 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 363 | |
| 364 | #undef _ctf_sequence_encoded |
| 365 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 366 | _src_length, _encoding, _nowrite) \ |
| 367 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \ |
| 368 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 369 | |
| 370 | #undef _ctf_string |
| 371 | #define _ctf_string(_item, _src, _nowrite) |
| 372 | |
| 373 | #undef TP_ARGS |
| 374 | #define TP_ARGS(...) __VA_ARGS__ |
| 375 | |
| 376 | #undef TP_FIELDS |
| 377 | #define TP_FIELDS(...) __VA_ARGS__ |
| 378 | |
| 379 | #undef TRACEPOINT_EVENT_CLASS |
| 380 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 381 | static inline lttng_ust_notrace \ |
| 382 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \ |
| 383 | static inline \ |
| 384 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \ |
| 385 | { \ |
| 386 | size_t __event_align = 1; \ |
| 387 | _fields \ |
| 388 | return __event_align; \ |
| 389 | } |
| 390 | |
| 391 | #include TRACEPOINT_INCLUDE |
| 392 | |
| 393 | |
| 394 | /* |
| 395 | * Stage 5 of tracepoint event generation. |
| 396 | * |
| 397 | * Create the probe function. This function calls event size calculation |
| 398 | * and writes event data into the buffer. |
| 399 | */ |
| 400 | |
| 401 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 402 | #include <lttng/ust-tracepoint-event-reset.h> |
| 403 | #include <lttng/ust-tracepoint-event-write.h> |
| 404 | |
| 405 | #undef _ctf_integer_ext |
| 406 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 407 | { \ |
| 408 | _type __tmp = (_src); \ |
| 409 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ |
| 410 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
| 411 | } |
| 412 | |
| 413 | #undef _ctf_float |
| 414 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 415 | { \ |
| 416 | _type __tmp = (_src); \ |
| 417 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ |
| 418 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
| 419 | } |
| 420 | |
| 421 | #undef _ctf_array_encoded |
| 422 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 423 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
| 424 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); |
| 425 | |
| 426 | #undef _ctf_sequence_encoded |
| 427 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 428 | _src_length, _encoding, _nowrite) \ |
| 429 | { \ |
| 430 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
| 431 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
| 432 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ |
| 433 | } \ |
| 434 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
| 435 | __chan->ops->event_write(&__ctx, _src, \ |
| 436 | sizeof(_type) * __get_dynamic_len(dest)); |
| 437 | |
| 438 | #undef _ctf_string |
| 439 | #define _ctf_string(_item, _src, _nowrite) \ |
| 440 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ |
| 441 | __chan->ops->event_write(&__ctx, _src, __get_dynamic_len(dest)); |
| 442 | |
| 443 | /* Beware: this get len actually consumes the len value */ |
| 444 | #undef __get_dynamic_len |
| 445 | #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] |
| 446 | |
| 447 | #undef TP_ARGS |
| 448 | #define TP_ARGS(...) __VA_ARGS__ |
| 449 | |
| 450 | #undef TP_FIELDS |
| 451 | #define TP_FIELDS(...) __VA_ARGS__ |
| 452 | |
| 453 | /* |
| 454 | * Using twice size for filter stack data to hold size and pointer for |
| 455 | * each field (worse case). For integers, max size required is 64-bit. |
| 456 | * Same for double-precision floats. Those fit within |
| 457 | * 2*sizeof(unsigned long) for all supported architectures. |
| 458 | */ |
| 459 | #undef TRACEPOINT_EVENT_CLASS |
| 460 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 461 | static lttng_ust_notrace \ |
| 462 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ |
| 463 | static \ |
| 464 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ |
| 465 | { \ |
| 466 | struct ltt_event *__event = __tp_data; \ |
| 467 | struct ltt_channel *__chan = __event->chan; \ |
| 468 | struct lttng_ust_lib_ring_buffer_ctx __ctx; \ |
| 469 | size_t __event_len, __event_align; \ |
| 470 | size_t __dynamic_len_idx = 0; \ |
| 471 | union { \ |
| 472 | size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \ |
| 473 | char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \ |
| 474 | } __stackvar; \ |
| 475 | int __ret; \ |
| 476 | \ |
| 477 | if (0) \ |
| 478 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 479 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \ |
| 480 | return; \ |
| 481 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \ |
| 482 | return; \ |
| 483 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ |
| 484 | return; \ |
| 485 | if (caa_unlikely(__event->filter)) { \ |
| 486 | __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \ |
| 487 | _TP_ARGS_DATA_VAR(_args)); \ |
| 488 | if (caa_likely(!__event->filter(__event->filter_data, __stackvar.__filter_stack_data))) \ |
| 489 | return; \ |
| 490 | } \ |
| 491 | __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ |
| 492 | _TP_ARGS_DATA_VAR(_args)); \ |
| 493 | __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ |
| 494 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
| 495 | __event_align, -1, __chan->handle); \ |
| 496 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
| 497 | if (__ret < 0) \ |
| 498 | return; \ |
| 499 | _fields \ |
| 500 | __chan->ops->event_commit(&__ctx); \ |
| 501 | } |
| 502 | |
| 503 | #include TRACEPOINT_INCLUDE |
| 504 | |
| 505 | #undef __get_dynamic_len |
| 506 | |
| 507 | /* |
| 508 | * Stage 5.1 of tracepoint event generation. |
| 509 | * |
| 510 | * Create probe signature |
| 511 | */ |
| 512 | |
| 513 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 514 | #include <lttng/ust-tracepoint-event-reset.h> |
| 515 | |
| 516 | #undef TP_ARGS |
| 517 | #define TP_ARGS(...) __VA_ARGS__ |
| 518 | |
| 519 | #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__ |
| 520 | |
| 521 | #undef TRACEPOINT_EVENT_CLASS |
| 522 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 523 | const char __tp_event_signature___##_provider##___##_name[] = \ |
| 524 | _TP_EXTRACT_STRING2(_args); |
| 525 | |
| 526 | #include TRACEPOINT_INCLUDE |
| 527 | |
| 528 | #undef _TP_EXTRACT_STRING2 |
| 529 | |
| 530 | /* |
| 531 | * Stage 6 of tracepoint event generation. |
| 532 | * |
| 533 | * Tracepoint loglevel mapping definition generation. We generate a |
| 534 | * symbol for each mapping for a provider/event to ensure at most a 1 to |
| 535 | * 1 mapping between events and loglevels. If the symbol is repeated, |
| 536 | * the compiler will complain. |
| 537 | */ |
| 538 | |
| 539 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 540 | #include <lttng/ust-tracepoint-event-reset.h> |
| 541 | |
| 542 | #undef TRACEPOINT_LOGLEVEL |
| 543 | #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ |
| 544 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ |
| 545 | static const int *_loglevel___##__provider##___##__name = \ |
| 546 | &_loglevel_value___##__provider##___##__name; |
| 547 | |
| 548 | #include TRACEPOINT_INCLUDE |
| 549 | |
| 550 | /* |
| 551 | * Stage 7.1 of tracepoint event generation. |
| 552 | * |
| 553 | * Create events description structures. We use a weakref because |
| 554 | * loglevels are optional. If not declared, the event will point to the |
| 555 | * a loglevel that contains NULL. |
| 556 | */ |
| 557 | |
| 558 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 559 | #include <lttng/ust-tracepoint-event-reset.h> |
| 560 | |
| 561 | #undef TRACEPOINT_EVENT_INSTANCE |
| 562 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 563 | static const int * \ |
| 564 | __ref_loglevel___##_provider##___##_name \ |
| 565 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ |
| 566 | const struct lttng_event_desc __event_desc___##_provider##_##_name = { \ |
| 567 | .fields = __event_fields___##_provider##___##_template, \ |
| 568 | .name = #_provider ":" #_name, \ |
| 569 | .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\ |
| 570 | .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \ |
| 571 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
| 572 | .signature = __tp_event_signature___##_provider##___##_template, \ |
| 573 | }; |
| 574 | |
| 575 | #include TRACEPOINT_INCLUDE |
| 576 | |
| 577 | /* |
| 578 | * Stage 7.2 of tracepoint event generation. |
| 579 | * |
| 580 | * Create array of events. |
| 581 | */ |
| 582 | |
| 583 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 584 | #include <lttng/ust-tracepoint-event-reset.h> |
| 585 | |
| 586 | #undef TRACEPOINT_EVENT_INSTANCE |
| 587 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 588 | &__event_desc___##_provider##_##_name, |
| 589 | |
| 590 | static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { |
| 591 | #include TRACEPOINT_INCLUDE |
| 592 | }; |
| 593 | |
| 594 | |
| 595 | /* |
| 596 | * Stage 8 of tracepoint event generation. |
| 597 | * |
| 598 | * Create a toplevel descriptor for the whole probe. |
| 599 | */ |
| 600 | |
| 601 | /* non-const because list head will be modified when registered. */ |
| 602 | static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { |
| 603 | .provider = __tp_stringify(TRACEPOINT_PROVIDER), |
| 604 | .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER), |
| 605 | .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)), |
| 606 | }; |
| 607 | |
| 608 | /* |
| 609 | * Stage 9 of tracepoint event generation. |
| 610 | * |
| 611 | * Register/unregister probes at module load/unload. |
| 612 | * |
| 613 | * Generate the constructor as an externally visible symbol for use when |
| 614 | * linking the probe statically. |
| 615 | */ |
| 616 | |
| 617 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 618 | #include <lttng/ust-tracepoint-event-reset.h> |
| 619 | static void lttng_ust_notrace __attribute__((constructor)) |
| 620 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void); |
| 621 | static void |
| 622 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) |
| 623 | { |
| 624 | int ret; |
| 625 | |
| 626 | ret = ltt_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
| 627 | assert(!ret); |
| 628 | } |
| 629 | |
| 630 | static void lttng_ust_notrace __attribute__((destructor)) |
| 631 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); |
| 632 | static void |
| 633 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) |
| 634 | { |
| 635 | ltt_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
| 636 | } |
| 637 | |
| 638 | int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER); |