| 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 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | * SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <urcu/compiler.h> |
| 26 | #include <urcu/rculist.h> |
| 27 | #include <lttng/ust-events.h> |
| 28 | #include <lttng/ringbuffer-config.h> |
| 29 | #include <lttng/ust-compiler.h> |
| 30 | #include <lttng/tracepoint.h> |
| 31 | #include <byteswap.h> |
| 32 | #include <string.h> |
| 33 | |
| 34 | #undef tp_list_for_each_entry_rcu |
| 35 | #define tp_list_for_each_entry_rcu(pos, head, member) \ |
| 36 | for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \ |
| 37 | &pos->member != (head); \ |
| 38 | pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member)) |
| 39 | |
| 40 | /* |
| 41 | * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the |
| 42 | * same arguments and having the same field layout. |
| 43 | * |
| 44 | * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with |
| 45 | * its own provider and name. It refers to a class (template). |
| 46 | * |
| 47 | * TRACEPOINT_EVENT declared both a class and an instance and does a |
| 48 | * direct mapping from the instance to the class. |
| 49 | */ |
| 50 | |
| 51 | #undef TRACEPOINT_EVENT |
| 52 | #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \ |
| 53 | TRACEPOINT_EVENT_CLASS(_provider, _name, \ |
| 54 | _TP_PARAMS(_args), \ |
| 55 | _TP_PARAMS(_fields)) \ |
| 56 | TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \ |
| 57 | _TP_PARAMS(_args)) |
| 58 | |
| 59 | /* Helpers */ |
| 60 | #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 61 | |
| 62 | #define _tp_max_t(type, x, y) \ |
| 63 | ({ \ |
| 64 | type __max1 = (x); \ |
| 65 | type __max2 = (y); \ |
| 66 | __max1 > __max2 ? __max1: __max2; \ |
| 67 | }) |
| 68 | |
| 69 | /* |
| 70 | * Stage 0 of tracepoint event generation. |
| 71 | * |
| 72 | * Check that each TRACEPOINT_EVENT provider argument match the |
| 73 | * TRACEPOINT_PROVIDER by creating dummy callbacks. |
| 74 | */ |
| 75 | |
| 76 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 77 | #include <lttng/ust-tracepoint-event-reset.h> |
| 78 | |
| 79 | static inline lttng_ust_notrace |
| 80 | void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void); |
| 81 | static inline |
| 82 | void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | #undef TRACEPOINT_EVENT_CLASS |
| 87 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 88 | __tracepoint_provider_mismatch_##_provider(); |
| 89 | |
| 90 | #undef TRACEPOINT_EVENT_INSTANCE |
| 91 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 92 | __tracepoint_provider_mismatch_##_provider(); |
| 93 | |
| 94 | static inline lttng_ust_notrace |
| 95 | void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void); |
| 96 | static inline |
| 97 | void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void) |
| 98 | { |
| 99 | #include TRACEPOINT_INCLUDE |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | * Stage 0.1 of tracepoint event generation. |
| 104 | * |
| 105 | * Check that each TRACEPOINT_EVENT provider:name does not exceed the |
| 106 | * tracepoint name length limit. |
| 107 | */ |
| 108 | |
| 109 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 110 | #include <lttng/ust-tracepoint-event-reset.h> |
| 111 | |
| 112 | #undef TRACEPOINT_EVENT_INSTANCE |
| 113 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 114 | static const char \ |
| 115 | __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \ |
| 116 | __attribute__((unused)) = \ |
| 117 | #_provider ":" #_name; |
| 118 | |
| 119 | #include TRACEPOINT_INCLUDE |
| 120 | |
| 121 | /* |
| 122 | * Stage 1 of tracepoint event generation. |
| 123 | * |
| 124 | * Create event field type metadata section. |
| 125 | * Each event produce an array of fields. |
| 126 | */ |
| 127 | |
| 128 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 129 | #include <lttng/ust-tracepoint-event-reset.h> |
| 130 | #include <lttng/ust-tracepoint-event-write.h> |
| 131 | #include <lttng/ust-tracepoint-event-nowrite.h> |
| 132 | |
| 133 | #undef _ctf_integer_ext |
| 134 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 135 | { \ |
| 136 | .name = #_item, \ |
| 137 | .type = __type_integer(_type, _byte_order, _base, none),\ |
| 138 | .nowrite = _nowrite, \ |
| 139 | }, |
| 140 | |
| 141 | #undef _ctf_float |
| 142 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 143 | { \ |
| 144 | .name = #_item, \ |
| 145 | .type = __type_float(_type), \ |
| 146 | .nowrite = _nowrite, \ |
| 147 | }, |
| 148 | |
| 149 | #undef _ctf_array_encoded |
| 150 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 151 | { \ |
| 152 | .name = #_item, \ |
| 153 | .type = \ |
| 154 | { \ |
| 155 | .atype = atype_array, \ |
| 156 | .u = \ |
| 157 | { \ |
| 158 | .array = \ |
| 159 | { \ |
| 160 | .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ |
| 161 | .length = _length, \ |
| 162 | } \ |
| 163 | } \ |
| 164 | }, \ |
| 165 | .nowrite = _nowrite, \ |
| 166 | }, |
| 167 | |
| 168 | #undef _ctf_sequence_encoded |
| 169 | #define _ctf_sequence_encoded(_type, _item, _src, \ |
| 170 | _length_type, _src_length, _encoding, _nowrite, \ |
| 171 | _elem_type_base) \ |
| 172 | { \ |
| 173 | .name = #_item, \ |
| 174 | .type = \ |
| 175 | { \ |
| 176 | .atype = atype_sequence, \ |
| 177 | .u = \ |
| 178 | { \ |
| 179 | .sequence = \ |
| 180 | { \ |
| 181 | .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \ |
| 182 | .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \ |
| 183 | }, \ |
| 184 | }, \ |
| 185 | }, \ |
| 186 | .nowrite = _nowrite, \ |
| 187 | }, |
| 188 | |
| 189 | #undef _ctf_string |
| 190 | #define _ctf_string(_item, _src, _nowrite) \ |
| 191 | { \ |
| 192 | .name = #_item, \ |
| 193 | .type = \ |
| 194 | { \ |
| 195 | .atype = atype_string, \ |
| 196 | .u = \ |
| 197 | { \ |
| 198 | .basic = { .string = { .encoding = lttng_encode_UTF8 } } \ |
| 199 | }, \ |
| 200 | }, \ |
| 201 | .nowrite = _nowrite, \ |
| 202 | }, |
| 203 | |
| 204 | #undef TP_FIELDS |
| 205 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ |
| 206 | |
| 207 | #undef TRACEPOINT_EVENT_CLASS |
| 208 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 209 | static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \ |
| 210 | _fields \ |
| 211 | ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \ |
| 212 | }; |
| 213 | |
| 214 | #include TRACEPOINT_INCLUDE |
| 215 | |
| 216 | /* |
| 217 | * Stage 2 of tracepoint event generation. |
| 218 | * |
| 219 | * Create probe callback prototypes. |
| 220 | */ |
| 221 | |
| 222 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 223 | #include <lttng/ust-tracepoint-event-reset.h> |
| 224 | |
| 225 | #undef TP_ARGS |
| 226 | #define TP_ARGS(...) __VA_ARGS__ |
| 227 | |
| 228 | #undef TRACEPOINT_EVENT_CLASS |
| 229 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 230 | static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); |
| 231 | |
| 232 | #include TRACEPOINT_INCLUDE |
| 233 | |
| 234 | /* |
| 235 | * Stage 3 of tracepoint event generation. |
| 236 | * |
| 237 | * Create static inline function that calculates event size. |
| 238 | */ |
| 239 | |
| 240 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 241 | #include <lttng/ust-tracepoint-event-reset.h> |
| 242 | #include <lttng/ust-tracepoint-event-write.h> |
| 243 | |
| 244 | #undef _ctf_integer_ext |
| 245 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 246 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 247 | __event_len += sizeof(_type); |
| 248 | |
| 249 | #undef _ctf_float |
| 250 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 251 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 252 | __event_len += sizeof(_type); |
| 253 | |
| 254 | #undef _ctf_array_encoded |
| 255 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 256 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 257 | __event_len += sizeof(_type) * (_length); |
| 258 | |
| 259 | #undef _ctf_sequence_encoded |
| 260 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 261 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
| 262 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \ |
| 263 | __event_len += sizeof(_length_type); \ |
| 264 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 265 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ |
| 266 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ |
| 267 | __dynamic_len_idx++; |
| 268 | |
| 269 | #undef _ctf_string |
| 270 | #define _ctf_string(_item, _src, _nowrite) \ |
| 271 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
| 272 | |
| 273 | #undef TP_ARGS |
| 274 | #define TP_ARGS(...) __VA_ARGS__ |
| 275 | |
| 276 | #undef TP_FIELDS |
| 277 | #define TP_FIELDS(...) __VA_ARGS__ |
| 278 | |
| 279 | #undef TRACEPOINT_EVENT_CLASS |
| 280 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 281 | static inline lttng_ust_notrace \ |
| 282 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \ |
| 283 | static inline \ |
| 284 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ |
| 285 | { \ |
| 286 | size_t __event_len = 0; \ |
| 287 | unsigned int __dynamic_len_idx = 0; \ |
| 288 | \ |
| 289 | if (0) \ |
| 290 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 291 | _fields \ |
| 292 | return __event_len; \ |
| 293 | } |
| 294 | |
| 295 | #include TRACEPOINT_INCLUDE |
| 296 | |
| 297 | /* |
| 298 | * Stage 3.1 of tracepoint event generation. |
| 299 | * |
| 300 | * Create static inline function that layout the filter stack data. |
| 301 | * We make both write and nowrite data available to the filter. |
| 302 | */ |
| 303 | |
| 304 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 305 | #include <lttng/ust-tracepoint-event-reset.h> |
| 306 | #include <lttng/ust-tracepoint-event-write.h> |
| 307 | #include <lttng/ust-tracepoint-event-nowrite.h> |
| 308 | |
| 309 | #undef _ctf_integer_ext |
| 310 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 311 | if (lttng_is_signed_type(_type)) { \ |
| 312 | int64_t __ctf_tmp_int64; \ |
| 313 | switch (sizeof(_type)) { \ |
| 314 | case 1: \ |
| 315 | { \ |
| 316 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ |
| 317 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
| 318 | break; \ |
| 319 | } \ |
| 320 | case 2: \ |
| 321 | { \ |
| 322 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ |
| 323 | if (_byte_order != BYTE_ORDER) \ |
| 324 | __tmp.v = bswap_16(__tmp.v); \ |
| 325 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
| 326 | break; \ |
| 327 | } \ |
| 328 | case 4: \ |
| 329 | { \ |
| 330 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ |
| 331 | if (_byte_order != BYTE_ORDER) \ |
| 332 | __tmp.v = bswap_32(__tmp.v); \ |
| 333 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
| 334 | break; \ |
| 335 | } \ |
| 336 | case 8: \ |
| 337 | { \ |
| 338 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ |
| 339 | if (_byte_order != BYTE_ORDER) \ |
| 340 | __tmp.v = bswap_64(__tmp.v); \ |
| 341 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
| 342 | break; \ |
| 343 | } \ |
| 344 | default: \ |
| 345 | abort(); \ |
| 346 | }; \ |
| 347 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ |
| 348 | } else { \ |
| 349 | uint64_t __ctf_tmp_uint64; \ |
| 350 | switch (sizeof(_type)) { \ |
| 351 | case 1: \ |
| 352 | { \ |
| 353 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ |
| 354 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
| 355 | break; \ |
| 356 | } \ |
| 357 | case 2: \ |
| 358 | { \ |
| 359 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ |
| 360 | if (_byte_order != BYTE_ORDER) \ |
| 361 | __tmp.v = bswap_16(__tmp.v); \ |
| 362 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
| 363 | break; \ |
| 364 | } \ |
| 365 | case 4: \ |
| 366 | { \ |
| 367 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ |
| 368 | if (_byte_order != BYTE_ORDER) \ |
| 369 | __tmp.v = bswap_32(__tmp.v); \ |
| 370 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
| 371 | break; \ |
| 372 | } \ |
| 373 | case 8: \ |
| 374 | { \ |
| 375 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ |
| 376 | if (_byte_order != BYTE_ORDER) \ |
| 377 | __tmp.v = bswap_64(__tmp.v); \ |
| 378 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
| 379 | break; \ |
| 380 | } \ |
| 381 | default: \ |
| 382 | abort(); \ |
| 383 | }; \ |
| 384 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ |
| 385 | } \ |
| 386 | __stack_data += sizeof(int64_t); |
| 387 | |
| 388 | #undef _ctf_float |
| 389 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 390 | { \ |
| 391 | double __ctf_tmp_double = (double) (_type) (_src); \ |
| 392 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ |
| 393 | __stack_data += sizeof(double); \ |
| 394 | } |
| 395 | |
| 396 | #undef _ctf_array_encoded |
| 397 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 398 | { \ |
| 399 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ |
| 400 | const void *__ctf_tmp_ptr = (_src); \ |
| 401 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
| 402 | __stack_data += sizeof(unsigned long); \ |
| 403 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
| 404 | __stack_data += sizeof(void *); \ |
| 405 | } |
| 406 | |
| 407 | #undef _ctf_sequence_encoded |
| 408 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 409 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
| 410 | { \ |
| 411 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ |
| 412 | const void *__ctf_tmp_ptr = (_src); \ |
| 413 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
| 414 | __stack_data += sizeof(unsigned long); \ |
| 415 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
| 416 | __stack_data += sizeof(void *); \ |
| 417 | } |
| 418 | |
| 419 | #undef _ctf_string |
| 420 | #define _ctf_string(_item, _src, _nowrite) \ |
| 421 | { \ |
| 422 | const void *__ctf_tmp_ptr = (_src); \ |
| 423 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
| 424 | __stack_data += sizeof(void *); \ |
| 425 | } |
| 426 | |
| 427 | #undef TP_ARGS |
| 428 | #define TP_ARGS(...) __VA_ARGS__ |
| 429 | |
| 430 | #undef TP_FIELDS |
| 431 | #define TP_FIELDS(...) __VA_ARGS__ |
| 432 | |
| 433 | #undef TRACEPOINT_EVENT_CLASS |
| 434 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 435 | static inline \ |
| 436 | void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\ |
| 437 | _TP_ARGS_DATA_PROTO(_args)) \ |
| 438 | { \ |
| 439 | _fields \ |
| 440 | } |
| 441 | |
| 442 | #include TRACEPOINT_INCLUDE |
| 443 | |
| 444 | |
| 445 | |
| 446 | /* |
| 447 | * Stage 4 of tracepoint event generation. |
| 448 | * |
| 449 | * Create static inline function that calculates event payload alignment. |
| 450 | */ |
| 451 | |
| 452 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 453 | #include <lttng/ust-tracepoint-event-reset.h> |
| 454 | #include <lttng/ust-tracepoint-event-write.h> |
| 455 | |
| 456 | #undef _ctf_integer_ext |
| 457 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 458 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 459 | |
| 460 | #undef _ctf_float |
| 461 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 462 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 463 | |
| 464 | #undef _ctf_array_encoded |
| 465 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 466 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 467 | |
| 468 | #undef _ctf_sequence_encoded |
| 469 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 470 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
| 471 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \ |
| 472 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
| 473 | |
| 474 | #undef _ctf_string |
| 475 | #define _ctf_string(_item, _src, _nowrite) |
| 476 | |
| 477 | #undef TP_ARGS |
| 478 | #define TP_ARGS(...) __VA_ARGS__ |
| 479 | |
| 480 | #undef TP_FIELDS |
| 481 | #define TP_FIELDS(...) __VA_ARGS__ |
| 482 | |
| 483 | #undef TRACEPOINT_EVENT_CLASS |
| 484 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 485 | static inline lttng_ust_notrace \ |
| 486 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \ |
| 487 | static inline \ |
| 488 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \ |
| 489 | { \ |
| 490 | size_t __event_align = 1; \ |
| 491 | _fields \ |
| 492 | return __event_align; \ |
| 493 | } |
| 494 | |
| 495 | #include TRACEPOINT_INCLUDE |
| 496 | |
| 497 | |
| 498 | /* |
| 499 | * Stage 5 of tracepoint event generation. |
| 500 | * |
| 501 | * Create the probe function. This function calls event size calculation |
| 502 | * and writes event data into the buffer. |
| 503 | */ |
| 504 | |
| 505 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 506 | #include <lttng/ust-tracepoint-event-reset.h> |
| 507 | #include <lttng/ust-tracepoint-event-write.h> |
| 508 | |
| 509 | #undef _ctf_integer_ext |
| 510 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
| 511 | { \ |
| 512 | _type __tmp = (_src); \ |
| 513 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ |
| 514 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
| 515 | } |
| 516 | |
| 517 | #undef _ctf_float |
| 518 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
| 519 | { \ |
| 520 | _type __tmp = (_src); \ |
| 521 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ |
| 522 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
| 523 | } |
| 524 | |
| 525 | #undef _ctf_array_encoded |
| 526 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
| 527 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
| 528 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); |
| 529 | |
| 530 | #undef _ctf_sequence_encoded |
| 531 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ |
| 532 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
| 533 | { \ |
| 534 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
| 535 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
| 536 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ |
| 537 | } \ |
| 538 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
| 539 | __chan->ops->event_write(&__ctx, _src, \ |
| 540 | sizeof(_type) * __get_dynamic_len(dest)); |
| 541 | |
| 542 | /* |
| 543 | * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST |
| 544 | * tracepoint provider ABI implements event_strcpy. This dynamic check |
| 545 | * can be removed when the tracepoint provider ABI moves to 2. |
| 546 | */ |
| 547 | #if (LTTNG_UST_PROVIDER_MAJOR > 1) |
| 548 | #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy." |
| 549 | #endif |
| 550 | |
| 551 | #undef _ctf_string |
| 552 | #define _ctf_string(_item, _src, _nowrite) \ |
| 553 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ |
| 554 | if (__chan->ops->u.has_strcpy) \ |
| 555 | __chan->ops->event_strcpy(&__ctx, _src, \ |
| 556 | __get_dynamic_len(dest)); \ |
| 557 | else \ |
| 558 | __chan->ops->event_write(&__ctx, _src, \ |
| 559 | __get_dynamic_len(dest)); |
| 560 | |
| 561 | /* Beware: this get len actually consumes the len value */ |
| 562 | #undef __get_dynamic_len |
| 563 | #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] |
| 564 | |
| 565 | #undef TP_ARGS |
| 566 | #define TP_ARGS(...) __VA_ARGS__ |
| 567 | |
| 568 | #undef TP_FIELDS |
| 569 | #define TP_FIELDS(...) __VA_ARGS__ |
| 570 | |
| 571 | /* |
| 572 | * For state dump, check that "session" argument (mandatory) matches the |
| 573 | * session this event belongs to. Ensures that we write state dump data only |
| 574 | * into the started session, not into all sessions. |
| 575 | */ |
| 576 | #undef _TP_SESSION_CHECK |
| 577 | #ifdef TP_SESSION_CHECK |
| 578 | #define _TP_SESSION_CHECK(session, csession) (session == csession) |
| 579 | #else /* TP_SESSION_CHECK */ |
| 580 | #define _TP_SESSION_CHECK(session, csession) 1 |
| 581 | #endif /* TP_SESSION_CHECK */ |
| 582 | |
| 583 | /* |
| 584 | * Use of __builtin_return_address(0) sometimes seems to cause stack |
| 585 | * corruption on 32-bit PowerPC. Disable this feature on that |
| 586 | * architecture for now by always using the NULL value for the ip |
| 587 | * context. |
| 588 | */ |
| 589 | #undef _TP_IP_PARAM |
| 590 | #ifdef TP_IP_PARAM |
| 591 | #define _TP_IP_PARAM(x) (x) |
| 592 | #else /* TP_IP_PARAM */ |
| 593 | |
| 594 | #if defined(__PPC__) && !defined(__PPC64__) |
| 595 | #define _TP_IP_PARAM(x) NULL |
| 596 | #else /* #if defined(__PPC__) && !defined(__PPC64__) */ |
| 597 | #define _TP_IP_PARAM(x) __builtin_return_address(0) |
| 598 | #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */ |
| 599 | |
| 600 | #endif /* TP_IP_PARAM */ |
| 601 | |
| 602 | /* |
| 603 | * Using twice size for filter stack data to hold size and pointer for |
| 604 | * each field (worse case). For integers, max size required is 64-bit. |
| 605 | * Same for double-precision floats. Those fit within |
| 606 | * 2*sizeof(unsigned long) for all supported architectures. |
| 607 | * Perform UNION (||) of filter runtime list. |
| 608 | */ |
| 609 | #undef TRACEPOINT_EVENT_CLASS |
| 610 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 611 | static lttng_ust_notrace \ |
| 612 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ |
| 613 | static \ |
| 614 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ |
| 615 | { \ |
| 616 | struct lttng_event *__event = (struct lttng_event *) __tp_data; \ |
| 617 | struct lttng_channel *__chan = __event->chan; \ |
| 618 | struct lttng_ust_lib_ring_buffer_ctx __ctx; \ |
| 619 | size_t __event_len, __event_align; \ |
| 620 | size_t __dynamic_len_idx = 0; \ |
| 621 | union { \ |
| 622 | size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \ |
| 623 | char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \ |
| 624 | } __stackvar; \ |
| 625 | int __ret; \ |
| 626 | \ |
| 627 | if (0) \ |
| 628 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 629 | if (!_TP_SESSION_CHECK(session, __chan->session)) \ |
| 630 | return; \ |
| 631 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \ |
| 632 | return; \ |
| 633 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \ |
| 634 | return; \ |
| 635 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ |
| 636 | return; \ |
| 637 | if (caa_unlikely(!TP_RCU_LINK_TEST())) \ |
| 638 | return; \ |
| 639 | if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \ |
| 640 | struct lttng_bytecode_runtime *bc_runtime; \ |
| 641 | int __filter_record = __event->has_enablers_without_bytecode; \ |
| 642 | \ |
| 643 | __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \ |
| 644 | _TP_ARGS_DATA_VAR(_args)); \ |
| 645 | tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ |
| 646 | if (caa_unlikely(bc_runtime->filter(bc_runtime, \ |
| 647 | __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \ |
| 648 | __filter_record = 1; \ |
| 649 | } \ |
| 650 | if (caa_likely(!__filter_record)) \ |
| 651 | return; \ |
| 652 | } \ |
| 653 | __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ |
| 654 | _TP_ARGS_DATA_VAR(_args)); \ |
| 655 | __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ |
| 656 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
| 657 | __event_align, -1, __chan->handle); \ |
| 658 | __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \ |
| 659 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
| 660 | if (__ret < 0) \ |
| 661 | return; \ |
| 662 | _fields \ |
| 663 | __chan->ops->event_commit(&__ctx); \ |
| 664 | } |
| 665 | |
| 666 | #include TRACEPOINT_INCLUDE |
| 667 | |
| 668 | #undef __get_dynamic_len |
| 669 | |
| 670 | /* |
| 671 | * Stage 5.1 of tracepoint event generation. |
| 672 | * |
| 673 | * Create probe signature |
| 674 | */ |
| 675 | |
| 676 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 677 | #include <lttng/ust-tracepoint-event-reset.h> |
| 678 | |
| 679 | #undef TP_ARGS |
| 680 | #define TP_ARGS(...) __VA_ARGS__ |
| 681 | |
| 682 | #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__ |
| 683 | |
| 684 | #undef TRACEPOINT_EVENT_CLASS |
| 685 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
| 686 | const char __tp_event_signature___##_provider##___##_name[] = \ |
| 687 | _TP_EXTRACT_STRING2(_args); |
| 688 | |
| 689 | #include TRACEPOINT_INCLUDE |
| 690 | |
| 691 | #undef _TP_EXTRACT_STRING2 |
| 692 | |
| 693 | /* |
| 694 | * Stage 6 of tracepoint event generation. |
| 695 | * |
| 696 | * Tracepoint loglevel mapping definition generation. We generate a |
| 697 | * symbol for each mapping for a provider/event to ensure at most a 1 to |
| 698 | * 1 mapping between events and loglevels. If the symbol is repeated, |
| 699 | * the compiler will complain. |
| 700 | */ |
| 701 | |
| 702 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 703 | #include <lttng/ust-tracepoint-event-reset.h> |
| 704 | |
| 705 | /* |
| 706 | * Declare _loglevel___##__provider##___##__name as non-static, with |
| 707 | * hidden visibility for c++ handling of weakref. We do a weakref to the |
| 708 | * symbol in a later stage, which requires that the symbol is not |
| 709 | * mangled. |
| 710 | */ |
| 711 | #ifdef __cplusplus |
| 712 | #define LTTNG_TP_EXTERN_C extern "C" |
| 713 | #else |
| 714 | #define LTTNG_TP_EXTERN_C |
| 715 | #endif |
| 716 | |
| 717 | #undef TRACEPOINT_LOGLEVEL |
| 718 | #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ |
| 719 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ |
| 720 | LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \ |
| 721 | __attribute__((visibility("hidden"))) = \ |
| 722 | &_loglevel_value___##__provider##___##__name; |
| 723 | |
| 724 | #include TRACEPOINT_INCLUDE |
| 725 | |
| 726 | #undef LTTNG_TP_EXTERN_C |
| 727 | |
| 728 | /* |
| 729 | * Stage 6.1 of tracepoint event generation. |
| 730 | * |
| 731 | * Tracepoint UML URI info. |
| 732 | */ |
| 733 | |
| 734 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 735 | #include <lttng/ust-tracepoint-event-reset.h> |
| 736 | |
| 737 | /* |
| 738 | * Declare _model_emf_uri___##__provider##___##__name as non-static, |
| 739 | * with hidden visibility for c++ handling of weakref. We do a weakref |
| 740 | * to the symbol in a later stage, which requires that the symbol is not |
| 741 | * mangled. |
| 742 | */ |
| 743 | #ifdef __cplusplus |
| 744 | #define LTTNG_TP_EXTERN_C extern "C" |
| 745 | #else |
| 746 | #define LTTNG_TP_EXTERN_C |
| 747 | #endif |
| 748 | |
| 749 | #undef TRACEPOINT_MODEL_EMF_URI |
| 750 | #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \ |
| 751 | LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \ |
| 752 | __attribute__((visibility("hidden"))) = __uri; \ |
| 753 | |
| 754 | #include TRACEPOINT_INCLUDE |
| 755 | |
| 756 | #undef LTTNG_TP_EXTERN_C |
| 757 | |
| 758 | /* |
| 759 | * Stage 7.1 of tracepoint event generation. |
| 760 | * |
| 761 | * Create events description structures. We use a weakref because |
| 762 | * loglevels are optional. If not declared, the event will point to the |
| 763 | * a loglevel that contains NULL. |
| 764 | */ |
| 765 | |
| 766 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 767 | #include <lttng/ust-tracepoint-event-reset.h> |
| 768 | |
| 769 | #undef TRACEPOINT_EVENT_INSTANCE |
| 770 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 771 | static const int * \ |
| 772 | __ref_loglevel___##_provider##___##_name \ |
| 773 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ |
| 774 | static const char * \ |
| 775 | __ref_model_emf_uri___##_provider##___##_name \ |
| 776 | __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ |
| 777 | const struct lttng_event_desc __event_desc___##_provider##_##_name = { \ |
| 778 | .name = #_provider ":" #_name, \ |
| 779 | .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\ |
| 780 | .ctx = NULL, \ |
| 781 | .fields = __event_fields___##_provider##___##_template, \ |
| 782 | .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \ |
| 783 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
| 784 | .signature = __tp_event_signature___##_provider##___##_template, \ |
| 785 | .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \ |
| 786 | }; |
| 787 | |
| 788 | #include TRACEPOINT_INCLUDE |
| 789 | |
| 790 | /* |
| 791 | * Stage 7.2 of tracepoint event generation. |
| 792 | * |
| 793 | * Create array of events. |
| 794 | */ |
| 795 | |
| 796 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 797 | #include <lttng/ust-tracepoint-event-reset.h> |
| 798 | |
| 799 | #undef TRACEPOINT_EVENT_INSTANCE |
| 800 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ |
| 801 | &__event_desc___##_provider##_##_name, |
| 802 | |
| 803 | static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { |
| 804 | #include TRACEPOINT_INCLUDE |
| 805 | NULL, /* Dummy, C99 forbids 0-len array. */ |
| 806 | }; |
| 807 | |
| 808 | |
| 809 | /* |
| 810 | * Stage 8 of tracepoint event generation. |
| 811 | * |
| 812 | * Create a toplevel descriptor for the whole probe. |
| 813 | */ |
| 814 | |
| 815 | /* non-const because list head will be modified when registered. */ |
| 816 | static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { |
| 817 | .provider = __tp_stringify(TRACEPOINT_PROVIDER), |
| 818 | .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER), |
| 819 | .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1, |
| 820 | .head = { NULL, NULL }, |
| 821 | .lazy_init_head = { NULL, NULL }, |
| 822 | .lazy = 0, |
| 823 | .major = LTTNG_UST_PROVIDER_MAJOR, |
| 824 | .minor = LTTNG_UST_PROVIDER_MINOR, |
| 825 | }; |
| 826 | |
| 827 | static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER); |
| 828 | |
| 829 | /* |
| 830 | * Stage 9 of tracepoint event generation. |
| 831 | * |
| 832 | * Register/unregister probes at module load/unload. |
| 833 | * |
| 834 | * Generate the constructor as an externally visible symbol for use when |
| 835 | * linking the probe statically. |
| 836 | * |
| 837 | * Register refcount is protected by libc dynamic loader mutex. |
| 838 | */ |
| 839 | |
| 840 | /* Reset all macros within TRACEPOINT_EVENT */ |
| 841 | #include <lttng/ust-tracepoint-event-reset.h> |
| 842 | static void lttng_ust_notrace __attribute__((constructor)) |
| 843 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void); |
| 844 | static void |
| 845 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) |
| 846 | { |
| 847 | int ret; |
| 848 | |
| 849 | if (_TP_COMBINE_TOKENS(__probe_register_refcount___, |
| 850 | TRACEPOINT_PROVIDER)++) { |
| 851 | return; |
| 852 | } |
| 853 | /* |
| 854 | * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a |
| 855 | * static inline function that ensures every probe PROVIDER |
| 856 | * argument match the provider within which they appear. It |
| 857 | * calls empty static inline functions, and therefore has no |
| 858 | * runtime effect. However, if it detects an error, a linker |
| 859 | * error will appear. |
| 860 | */ |
| 861 | _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(); |
| 862 | ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
| 863 | if (ret) { |
| 864 | fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret); |
| 865 | abort(); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | static void lttng_ust_notrace __attribute__((destructor)) |
| 870 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); |
| 871 | static void |
| 872 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) |
| 873 | { |
| 874 | if (--_TP_COMBINE_TOKENS(__probe_register_refcount___, |
| 875 | TRACEPOINT_PROVIDER)) { |
| 876 | return; |
| 877 | } |
| 878 | lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
| 879 | } |
| 880 | |
| 881 | int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER); |