| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | * |
| 6 | * Holds LTTng per-session event registry. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _LTTNG_UST_EVENTS_H |
| 10 | #define _LTTNG_UST_EVENTS_H |
| 11 | |
| 12 | #include <urcu/list.h> |
| 13 | #include <urcu/hlist.h> |
| 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
| 16 | #include <lttng/ust-config.h> |
| 17 | #include <lttng/ust-abi.h> |
| 18 | #include <lttng/ust-tracer.h> |
| 19 | #include <lttng/ust-endian.h> |
| 20 | #include <float.h> |
| 21 | #include <errno.h> |
| 22 | #include <urcu/ref.h> |
| 23 | #include <pthread.h> |
| 24 | |
| 25 | #ifndef LTTNG_PACKED |
| 26 | #error "LTTNG_PACKED should be defined" |
| 27 | #endif |
| 28 | |
| 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | |
| 33 | #define LTTNG_UST_UUID_LEN 16 |
| 34 | |
| 35 | /* |
| 36 | * Tracepoint provider version. Compatibility based on the major number. |
| 37 | * Older tracepoint providers can always register to newer lttng-ust |
| 38 | * library, but the opposite is rejected: a newer tracepoint provider is |
| 39 | * rejected by an older lttng-ust library. |
| 40 | */ |
| 41 | #define LTTNG_UST_PROVIDER_MAJOR 2 |
| 42 | #define LTTNG_UST_PROVIDER_MINOR 0 |
| 43 | |
| 44 | struct lttng_channel; |
| 45 | struct lttng_session; |
| 46 | struct lttng_ust_lib_ring_buffer_ctx; |
| 47 | struct lttng_ust_context_app; |
| 48 | struct lttng_event_field; |
| 49 | struct lttng_event_notifier; |
| 50 | struct lttng_event_notifier_group; |
| 51 | |
| 52 | /* |
| 53 | * Data structures used by tracepoint event declarations, and by the |
| 54 | * tracer. Those structures have padding for future extension. |
| 55 | */ |
| 56 | |
| 57 | /* |
| 58 | * LTTng client type enumeration. Used by the consumer to map the |
| 59 | * callbacks from its own address space. |
| 60 | */ |
| 61 | enum lttng_client_types { |
| 62 | LTTNG_CLIENT_METADATA = 0, |
| 63 | LTTNG_CLIENT_DISCARD = 1, |
| 64 | LTTNG_CLIENT_OVERWRITE = 2, |
| 65 | LTTNG_CLIENT_DISCARD_RT = 3, |
| 66 | LTTNG_CLIENT_OVERWRITE_RT = 4, |
| 67 | LTTNG_NR_CLIENT_TYPES, |
| 68 | }; |
| 69 | |
| 70 | /* Type description */ |
| 71 | |
| 72 | /* Update the astract_types name table in lttng-types.c along with this enum */ |
| 73 | enum lttng_abstract_types { |
| 74 | atype_integer, |
| 75 | atype_enum, /* legacy */ |
| 76 | atype_array, /* legacy */ |
| 77 | atype_sequence, /* legacy */ |
| 78 | atype_string, |
| 79 | atype_float, |
| 80 | atype_dynamic, |
| 81 | atype_struct, /* legacy */ |
| 82 | atype_enum_nestable, |
| 83 | atype_array_nestable, |
| 84 | atype_sequence_nestable, |
| 85 | atype_struct_nestable, |
| 86 | NR_ABSTRACT_TYPES, |
| 87 | }; |
| 88 | |
| 89 | /* Update the string_encodings name table in lttng-types.c along with this enum */ |
| 90 | enum lttng_string_encodings { |
| 91 | lttng_encode_none = 0, |
| 92 | lttng_encode_UTF8 = 1, |
| 93 | lttng_encode_ASCII = 2, |
| 94 | NR_STRING_ENCODINGS, |
| 95 | }; |
| 96 | |
| 97 | struct lttng_enum_value { |
| 98 | unsigned long long value; |
| 99 | unsigned int signedness:1; |
| 100 | }; |
| 101 | |
| 102 | enum lttng_enum_entry_options { |
| 103 | LTTNG_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0, |
| 104 | }; |
| 105 | |
| 106 | #define LTTNG_UST_ENUM_ENTRY_PADDING 16 |
| 107 | struct lttng_enum_entry { |
| 108 | struct lttng_enum_value start, end; /* start and end are inclusive */ |
| 109 | const char *string; |
| 110 | union { |
| 111 | struct { |
| 112 | unsigned int options; |
| 113 | } LTTNG_PACKED extra; |
| 114 | char padding[LTTNG_UST_ENUM_ENTRY_PADDING]; |
| 115 | } u; |
| 116 | }; |
| 117 | |
| 118 | #define __type_integer(_type, _byte_order, _base, _encoding) \ |
| 119 | { \ |
| 120 | .atype = atype_integer, \ |
| 121 | .u = \ |
| 122 | { \ |
| 123 | .integer = \ |
| 124 | { \ |
| 125 | .size = sizeof(_type) * CHAR_BIT, \ |
| 126 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
| 127 | .signedness = lttng_is_signed_type(_type), \ |
| 128 | .reverse_byte_order = _byte_order != BYTE_ORDER, \ |
| 129 | .base = _base, \ |
| 130 | .encoding = lttng_encode_##_encoding, \ |
| 131 | } \ |
| 132 | }, \ |
| 133 | } \ |
| 134 | |
| 135 | #define LTTNG_UST_INTEGER_TYPE_PADDING 24 |
| 136 | struct lttng_integer_type { |
| 137 | unsigned int size; /* in bits */ |
| 138 | unsigned short alignment; /* in bits */ |
| 139 | unsigned int signedness:1; |
| 140 | unsigned int reverse_byte_order:1; |
| 141 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
| 142 | enum lttng_string_encodings encoding; |
| 143 | char padding[LTTNG_UST_INTEGER_TYPE_PADDING]; |
| 144 | }; |
| 145 | |
| 146 | /* |
| 147 | * Only float and double are supported. long double is not supported at |
| 148 | * the moment. |
| 149 | */ |
| 150 | #define _float_mant_dig(_type) \ |
| 151 | (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \ |
| 152 | : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \ |
| 153 | : 0)) |
| 154 | |
| 155 | #define __type_float(_type) \ |
| 156 | { \ |
| 157 | .atype = atype_float, \ |
| 158 | .u = \ |
| 159 | { \ |
| 160 | ._float = \ |
| 161 | { \ |
| 162 | .exp_dig = sizeof(_type) * CHAR_BIT \ |
| 163 | - _float_mant_dig(_type), \ |
| 164 | .mant_dig = _float_mant_dig(_type), \ |
| 165 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
| 166 | .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \ |
| 167 | } \ |
| 168 | } \ |
| 169 | } \ |
| 170 | |
| 171 | #define LTTNG_UST_FLOAT_TYPE_PADDING 24 |
| 172 | struct lttng_float_type { |
| 173 | unsigned int exp_dig; /* exponent digits, in bits */ |
| 174 | unsigned int mant_dig; /* mantissa digits, in bits */ |
| 175 | unsigned short alignment; /* in bits */ |
| 176 | unsigned int reverse_byte_order:1; |
| 177 | char padding[LTTNG_UST_FLOAT_TYPE_PADDING]; |
| 178 | }; |
| 179 | |
| 180 | /* legacy */ |
| 181 | #define LTTNG_UST_BASIC_TYPE_PADDING 128 |
| 182 | union _lttng_basic_type { |
| 183 | struct lttng_integer_type integer; /* legacy */ |
| 184 | struct { |
| 185 | const struct lttng_enum_desc *desc; /* Enumeration mapping */ |
| 186 | struct lttng_integer_type container_type; |
| 187 | } enumeration; /* legacy */ |
| 188 | struct { |
| 189 | enum lttng_string_encodings encoding; |
| 190 | } string; /* legacy */ |
| 191 | struct lttng_float_type _float; /* legacy */ |
| 192 | char padding[LTTNG_UST_BASIC_TYPE_PADDING]; |
| 193 | }; |
| 194 | |
| 195 | /* legacy */ |
| 196 | struct lttng_basic_type { |
| 197 | enum lttng_abstract_types atype; |
| 198 | union { |
| 199 | union _lttng_basic_type basic; |
| 200 | } u; |
| 201 | }; |
| 202 | |
| 203 | #define LTTNG_UST_TYPE_PADDING 128 |
| 204 | struct lttng_type { |
| 205 | enum lttng_abstract_types atype; |
| 206 | union { |
| 207 | /* provider ABI 2.0 */ |
| 208 | struct lttng_integer_type integer; |
| 209 | struct lttng_float_type _float; |
| 210 | struct { |
| 211 | enum lttng_string_encodings encoding; |
| 212 | } string; |
| 213 | struct { |
| 214 | const struct lttng_enum_desc *desc; /* Enumeration mapping */ |
| 215 | struct lttng_type *container_type; |
| 216 | } enum_nestable; |
| 217 | struct { |
| 218 | const struct lttng_type *elem_type; |
| 219 | unsigned int length; /* Num. elems. */ |
| 220 | unsigned int alignment; |
| 221 | } array_nestable; |
| 222 | struct { |
| 223 | const char *length_name; /* Length field name. */ |
| 224 | const struct lttng_type *elem_type; |
| 225 | unsigned int alignment; /* Alignment before elements. */ |
| 226 | } sequence_nestable; |
| 227 | struct { |
| 228 | unsigned int nr_fields; |
| 229 | const struct lttng_event_field *fields; /* Array of fields. */ |
| 230 | unsigned int alignment; |
| 231 | } struct_nestable; |
| 232 | |
| 233 | union { |
| 234 | /* legacy provider ABI 1.0 */ |
| 235 | union _lttng_basic_type basic; /* legacy */ |
| 236 | struct { |
| 237 | struct lttng_basic_type elem_type; |
| 238 | unsigned int length; /* Num. elems. */ |
| 239 | } array; /* legacy */ |
| 240 | struct { |
| 241 | struct lttng_basic_type length_type; |
| 242 | struct lttng_basic_type elem_type; |
| 243 | } sequence; /* legacy */ |
| 244 | struct { |
| 245 | unsigned int nr_fields; |
| 246 | struct lttng_event_field *fields; /* Array of fields. */ |
| 247 | } _struct; /* legacy */ |
| 248 | } legacy; |
| 249 | char padding[LTTNG_UST_TYPE_PADDING]; |
| 250 | } u; |
| 251 | }; |
| 252 | |
| 253 | #define LTTNG_UST_ENUM_TYPE_PADDING 24 |
| 254 | struct lttng_enum_desc { |
| 255 | const char *name; |
| 256 | const struct lttng_enum_entry *entries; |
| 257 | unsigned int nr_entries; |
| 258 | char padding[LTTNG_UST_ENUM_TYPE_PADDING]; |
| 259 | }; |
| 260 | |
| 261 | /* |
| 262 | * Event field description |
| 263 | * |
| 264 | * IMPORTANT: this structure is part of the ABI between the probe and |
| 265 | * UST. Fields need to be only added at the end, never reordered, never |
| 266 | * removed. |
| 267 | */ |
| 268 | |
| 269 | #define LTTNG_UST_EVENT_FIELD_PADDING 28 |
| 270 | struct lttng_event_field { |
| 271 | const char *name; |
| 272 | struct lttng_type type; |
| 273 | unsigned int nowrite; /* do not write into trace */ |
| 274 | union { |
| 275 | struct { |
| 276 | unsigned int nofilter:1; /* do not consider for filter */ |
| 277 | } ext; |
| 278 | char padding[LTTNG_UST_EVENT_FIELD_PADDING]; |
| 279 | } u; |
| 280 | }; |
| 281 | |
| 282 | enum lttng_ust_dynamic_type { |
| 283 | LTTNG_UST_DYNAMIC_TYPE_NONE, |
| 284 | LTTNG_UST_DYNAMIC_TYPE_S8, |
| 285 | LTTNG_UST_DYNAMIC_TYPE_S16, |
| 286 | LTTNG_UST_DYNAMIC_TYPE_S32, |
| 287 | LTTNG_UST_DYNAMIC_TYPE_S64, |
| 288 | LTTNG_UST_DYNAMIC_TYPE_U8, |
| 289 | LTTNG_UST_DYNAMIC_TYPE_U16, |
| 290 | LTTNG_UST_DYNAMIC_TYPE_U32, |
| 291 | LTTNG_UST_DYNAMIC_TYPE_U64, |
| 292 | LTTNG_UST_DYNAMIC_TYPE_FLOAT, |
| 293 | LTTNG_UST_DYNAMIC_TYPE_DOUBLE, |
| 294 | LTTNG_UST_DYNAMIC_TYPE_STRING, |
| 295 | _NR_LTTNG_UST_DYNAMIC_TYPES, |
| 296 | }; |
| 297 | |
| 298 | struct lttng_ctx_value { |
| 299 | enum lttng_ust_dynamic_type sel; |
| 300 | union { |
| 301 | int64_t s64; |
| 302 | uint64_t u64; |
| 303 | const char *str; |
| 304 | double d; |
| 305 | } u; |
| 306 | }; |
| 307 | |
| 308 | struct lttng_perf_counter_field; |
| 309 | |
| 310 | #define LTTNG_UST_CTX_FIELD_PADDING 40 |
| 311 | struct lttng_ctx_field { |
| 312 | struct lttng_event_field event_field; |
| 313 | size_t (*get_size)(struct lttng_ctx_field *field, size_t offset); |
| 314 | void (*record)(struct lttng_ctx_field *field, |
| 315 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
| 316 | struct lttng_channel *chan); |
| 317 | void (*get_value)(struct lttng_ctx_field *field, |
| 318 | struct lttng_ctx_value *value); |
| 319 | union { |
| 320 | struct lttng_perf_counter_field *perf_counter; |
| 321 | char padding[LTTNG_UST_CTX_FIELD_PADDING]; |
| 322 | } u; |
| 323 | void (*destroy)(struct lttng_ctx_field *field); |
| 324 | char *field_name; /* Has ownership, dynamically allocated. */ |
| 325 | }; |
| 326 | |
| 327 | #define LTTNG_UST_CTX_PADDING 20 |
| 328 | struct lttng_ctx { |
| 329 | struct lttng_ctx_field *fields; |
| 330 | unsigned int nr_fields; |
| 331 | unsigned int allocated_fields; |
| 332 | unsigned int largest_align; |
| 333 | char padding[LTTNG_UST_CTX_PADDING]; |
| 334 | }; |
| 335 | |
| 336 | #define LTTNG_UST_EVENT_DESC_PADDING 40 |
| 337 | struct lttng_event_desc { |
| 338 | const char *name; |
| 339 | void (*probe_callback)(void); |
| 340 | const struct lttng_event_ctx *ctx; /* context */ |
| 341 | const struct lttng_event_field *fields; /* event payload */ |
| 342 | unsigned int nr_fields; |
| 343 | const int **loglevel; |
| 344 | const char *signature; /* Argument types/names received */ |
| 345 | union { |
| 346 | struct { |
| 347 | const char **model_emf_uri; |
| 348 | void (*event_notifier_callback)(void); |
| 349 | } ext; |
| 350 | char padding[LTTNG_UST_EVENT_DESC_PADDING]; |
| 351 | } u; |
| 352 | }; |
| 353 | |
| 354 | #define LTTNG_UST_PROBE_DESC_PADDING 12 |
| 355 | struct lttng_probe_desc { |
| 356 | const char *provider; |
| 357 | const struct lttng_event_desc **event_desc; |
| 358 | unsigned int nr_events; |
| 359 | struct cds_list_head head; /* chain registered probes */ |
| 360 | struct cds_list_head lazy_init_head; |
| 361 | int lazy; /* lazy registration */ |
| 362 | uint32_t major; |
| 363 | uint32_t minor; |
| 364 | char padding[LTTNG_UST_PROBE_DESC_PADDING]; |
| 365 | }; |
| 366 | |
| 367 | /* Data structures used by the tracer. */ |
| 368 | |
| 369 | enum lttng_enabler_format_type { |
| 370 | LTTNG_ENABLER_FORMAT_STAR_GLOB, |
| 371 | LTTNG_ENABLER_FORMAT_EVENT, |
| 372 | }; |
| 373 | |
| 374 | /* |
| 375 | * Enabler field, within whatever object is enabling an event. Target of |
| 376 | * backward reference. |
| 377 | */ |
| 378 | struct lttng_enabler { |
| 379 | enum lttng_enabler_format_type format_type; |
| 380 | |
| 381 | /* head list of struct lttng_ust_filter_bytecode_node */ |
| 382 | struct cds_list_head filter_bytecode_head; |
| 383 | /* head list of struct lttng_ust_excluder_node */ |
| 384 | struct cds_list_head excluder_head; |
| 385 | |
| 386 | struct lttng_ust_event event_param; |
| 387 | unsigned int enabled:1; |
| 388 | }; |
| 389 | |
| 390 | struct tp_list_entry { |
| 391 | struct lttng_ust_tracepoint_iter tp; |
| 392 | struct cds_list_head head; |
| 393 | }; |
| 394 | |
| 395 | struct lttng_ust_tracepoint_list { |
| 396 | struct tp_list_entry *iter; |
| 397 | struct cds_list_head head; |
| 398 | }; |
| 399 | |
| 400 | struct tp_field_list_entry { |
| 401 | struct lttng_ust_field_iter field; |
| 402 | struct cds_list_head head; |
| 403 | }; |
| 404 | |
| 405 | struct lttng_ust_field_list { |
| 406 | struct tp_field_list_entry *iter; |
| 407 | struct cds_list_head head; |
| 408 | }; |
| 409 | |
| 410 | struct ust_pending_probe; |
| 411 | struct lttng_event; |
| 412 | |
| 413 | /* |
| 414 | * Bytecode interpreter return value masks. |
| 415 | */ |
| 416 | enum lttng_bytecode_interpreter_ret { |
| 417 | LTTNG_INTERPRETER_DISCARD = 0, |
| 418 | LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0), |
| 419 | /* Other bits are kept for future use. */ |
| 420 | }; |
| 421 | |
| 422 | struct lttng_interpreter_output; |
| 423 | |
| 424 | /* |
| 425 | * This structure is used in the probes. More specifically, the `filter` and |
| 426 | * `node` fields are explicity used in the probes. When modifying this |
| 427 | * structure we must not change the layout of these two fields as it is |
| 428 | * considered ABI. |
| 429 | */ |
| 430 | struct lttng_bytecode_runtime { |
| 431 | /* Associated bytecode */ |
| 432 | struct lttng_ust_bytecode_node *bc; |
| 433 | union { |
| 434 | uint64_t (*filter)(void *interpreter_data, |
| 435 | const char *interpreter_stack_data); |
| 436 | uint64_t (*capture)(void *interpreter_data, |
| 437 | const char *interpreter_stack_data, |
| 438 | struct lttng_interpreter_output *interpreter_output); |
| 439 | } interpreter_funcs; |
| 440 | int link_failed; |
| 441 | struct cds_list_head node; /* list of bytecode runtime in event */ |
| 442 | /* |
| 443 | * Pointer to a URCU-protected pointer owned by an `struct |
| 444 | * lttng_session`or `struct lttng_event_notifier_group`. |
| 445 | */ |
| 446 | struct lttng_ctx **pctx; |
| 447 | }; |
| 448 | |
| 449 | /* |
| 450 | * Objects in a linked-list of enablers, owned by an event or event_notifier. |
| 451 | * This is used because an event (or a event_notifier) can be enabled by more |
| 452 | * than one enabler and we want a quick way to iterate over all enablers of an |
| 453 | * object. |
| 454 | * |
| 455 | * For example, event rules "my_app:a*" and "my_app:ab*" will both match the |
| 456 | * event with the name "my_app:abc". |
| 457 | */ |
| 458 | struct lttng_enabler_ref { |
| 459 | struct cds_list_head node; /* enabler ref list */ |
| 460 | struct lttng_enabler *ref; /* backward ref */ |
| 461 | }; |
| 462 | |
| 463 | /* |
| 464 | * lttng_event structure is referred to by the tracing fast path. It |
| 465 | * must be kept small. |
| 466 | * |
| 467 | * IMPORTANT: this structure is part of the ABI between the probe and |
| 468 | * UST. Fields need to be only added at the end, never reordered, never |
| 469 | * removed. |
| 470 | */ |
| 471 | struct lttng_event { |
| 472 | unsigned int id; |
| 473 | struct lttng_channel *chan; |
| 474 | int enabled; |
| 475 | const struct lttng_event_desc *desc; |
| 476 | struct lttng_ctx *ctx; |
| 477 | enum lttng_ust_instrumentation instrumentation; |
| 478 | struct cds_list_head node; /* Event list in session */ |
| 479 | |
| 480 | /* list of struct lttng_bytecode_runtime, sorted by seqnum */ |
| 481 | struct cds_list_head filter_bytecode_runtime_head; |
| 482 | int has_enablers_without_bytecode; |
| 483 | /* Backward references: list of lttng_enabler_ref (ref to enablers) */ |
| 484 | struct cds_list_head enablers_ref_head; |
| 485 | struct cds_hlist_node hlist; /* session ht of events */ |
| 486 | int registered; /* has reg'd tracepoint probe */ |
| 487 | }; |
| 488 | |
| 489 | struct lttng_event_notifier { |
| 490 | uint64_t user_token; |
| 491 | uint64_t error_counter_index; |
| 492 | int enabled; |
| 493 | int registered; /* has reg'd tracepoint probe */ |
| 494 | size_t num_captures; /* Needed to allocate the msgpack array. */ |
| 495 | void (*notification_send)(struct lttng_event_notifier *event_notifier, |
| 496 | const char *stack_data); |
| 497 | struct cds_list_head filter_bytecode_runtime_head; |
| 498 | struct cds_list_head capture_bytecode_runtime_head; |
| 499 | int has_enablers_without_bytecode; |
| 500 | struct cds_list_head enablers_ref_head; |
| 501 | const struct lttng_event_desc *desc; |
| 502 | struct cds_hlist_node hlist; /* hashtable of event_notifiers */ |
| 503 | struct cds_list_head node; /* event_notifier list in session */ |
| 504 | struct lttng_event_notifier_group *group; /* weak ref */ |
| 505 | }; |
| 506 | |
| 507 | struct lttng_enum { |
| 508 | const struct lttng_enum_desc *desc; |
| 509 | struct lttng_session *session; |
| 510 | struct cds_list_head node; /* Enum list in session */ |
| 511 | struct cds_hlist_node hlist; /* Session ht of enums */ |
| 512 | uint64_t id; /* Enumeration ID in sessiond */ |
| 513 | }; |
| 514 | |
| 515 | struct channel; |
| 516 | struct lttng_ust_shm_handle; |
| 517 | |
| 518 | /* |
| 519 | * IMPORTANT: this structure is part of the ABI between the probe and |
| 520 | * UST. Fields need to be only added at the end, never reordered, never |
| 521 | * removed. |
| 522 | */ |
| 523 | struct lttng_channel_ops { |
| 524 | struct lttng_channel *(*channel_create)(const char *name, |
| 525 | void *buf_addr, |
| 526 | size_t subbuf_size, size_t num_subbuf, |
| 527 | unsigned int switch_timer_interval, |
| 528 | unsigned int read_timer_interval, |
| 529 | unsigned char *uuid, |
| 530 | uint32_t chan_id, |
| 531 | const int *stream_fds, int nr_stream_fds, |
| 532 | int64_t blocking_timeout); |
| 533 | void (*channel_destroy)(struct lttng_channel *chan); |
| 534 | int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx, |
| 535 | uint32_t event_id); |
| 536 | void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx); |
| 537 | void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, |
| 538 | const void *src, size_t len); |
| 539 | /* |
| 540 | * packet_avail_size returns the available size in the current |
| 541 | * packet. Note that the size returned is only a hint, since it |
| 542 | * may change due to concurrent writes. |
| 543 | */ |
| 544 | size_t (*packet_avail_size)(struct channel *chan, |
| 545 | struct lttng_ust_shm_handle *handle); |
| 546 | int (*is_finalized)(struct channel *chan); |
| 547 | int (*is_disabled)(struct channel *chan); |
| 548 | int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle); |
| 549 | void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx, |
| 550 | const char *src, size_t len); |
| 551 | }; |
| 552 | |
| 553 | /* |
| 554 | * IMPORTANT: this structure is part of the ABI between the probe and |
| 555 | * UST. Fields need to be only added at the end, never reordered, never |
| 556 | * removed. |
| 557 | */ |
| 558 | struct lttng_channel { |
| 559 | /* |
| 560 | * The pointers located in this private data are NOT safe to be |
| 561 | * dereferenced by the consumer. The only operations the |
| 562 | * consumer process is designed to be allowed to do is to read |
| 563 | * and perform subbuffer flush. |
| 564 | */ |
| 565 | struct channel *chan; /* Channel buffers */ |
| 566 | int enabled; |
| 567 | struct lttng_ctx *ctx; |
| 568 | /* Event ID management */ |
| 569 | struct lttng_session *session; |
| 570 | int objd; /* Object associated to channel */ |
| 571 | struct cds_list_head node; /* Channel list in session */ |
| 572 | const struct lttng_channel_ops *ops; |
| 573 | int header_type; /* 0: unset, 1: compact, 2: large */ |
| 574 | struct lttng_ust_shm_handle *handle; /* shared-memory handle */ |
| 575 | |
| 576 | /* Channel ID */ |
| 577 | unsigned int id; |
| 578 | enum lttng_ust_chan_type type; |
| 579 | unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ |
| 580 | int tstate:1; /* Transient enable state */ |
| 581 | }; |
| 582 | |
| 583 | #define LTTNG_COUNTER_DIMENSION_MAX 8 |
| 584 | |
| 585 | struct lttng_counter_dimension { |
| 586 | uint64_t size; |
| 587 | uint64_t underflow_index; |
| 588 | uint64_t overflow_index; |
| 589 | uint8_t has_underflow; |
| 590 | uint8_t has_overflow; |
| 591 | }; |
| 592 | |
| 593 | struct lttng_counter_ops { |
| 594 | struct lib_counter *(*counter_create)(size_t nr_dimensions, |
| 595 | const struct lttng_counter_dimension *dimensions, |
| 596 | int64_t global_sum_step, |
| 597 | int global_counter_fd, |
| 598 | int nr_counter_cpu_fds, |
| 599 | const int *counter_cpu_fds, |
| 600 | bool is_daemon); |
| 601 | void (*counter_destroy)(struct lib_counter *counter); |
| 602 | int (*counter_add)(struct lib_counter *counter, |
| 603 | const size_t *dimension_indexes, int64_t v); |
| 604 | int (*counter_read)(struct lib_counter *counter, |
| 605 | const size_t *dimension_indexes, int cpu, |
| 606 | int64_t *value, bool *overflow, bool *underflow); |
| 607 | int (*counter_aggregate)(struct lib_counter *counter, |
| 608 | const size_t *dimension_indexes, int64_t *value, |
| 609 | bool *overflow, bool *underflow); |
| 610 | int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes); |
| 611 | }; |
| 612 | |
| 613 | #define LTTNG_UST_STACK_CTX_PADDING 32 |
| 614 | struct lttng_stack_ctx { |
| 615 | struct lttng_event *event; |
| 616 | struct lttng_ctx *chan_ctx; /* RCU dereferenced. */ |
| 617 | struct lttng_ctx *event_ctx; /* RCU dereferenced. */ |
| 618 | char padding[LTTNG_UST_STACK_CTX_PADDING]; |
| 619 | }; |
| 620 | |
| 621 | #define LTTNG_UST_EVENT_HT_BITS 12 |
| 622 | #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS) |
| 623 | |
| 624 | struct lttng_ust_event_ht { |
| 625 | struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE]; |
| 626 | }; |
| 627 | |
| 628 | #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12 |
| 629 | #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS) |
| 630 | struct lttng_ust_event_notifier_ht { |
| 631 | struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE]; |
| 632 | }; |
| 633 | |
| 634 | #define LTTNG_UST_ENUM_HT_BITS 12 |
| 635 | #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS) |
| 636 | |
| 637 | struct lttng_ust_enum_ht { |
| 638 | struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE]; |
| 639 | }; |
| 640 | |
| 641 | /* |
| 642 | * IMPORTANT: this structure is part of the ABI between the probe and |
| 643 | * UST. Fields need to be only added at the end, never reordered, never |
| 644 | * removed. |
| 645 | */ |
| 646 | struct lttng_session { |
| 647 | int active; /* Is trace session active ? */ |
| 648 | int been_active; /* Been active ? */ |
| 649 | int objd; /* Object associated */ |
| 650 | struct cds_list_head chan_head; /* Channel list head */ |
| 651 | struct cds_list_head events_head; /* list of events */ |
| 652 | struct cds_list_head node; /* Session list */ |
| 653 | |
| 654 | /* New UST 2.1 */ |
| 655 | /* List of enablers */ |
| 656 | struct cds_list_head enablers_head; |
| 657 | struct lttng_ust_event_ht events_ht; /* ht of events */ |
| 658 | void *owner; /* object owner */ |
| 659 | int tstate:1; /* Transient enable state */ |
| 660 | |
| 661 | /* New UST 2.4 */ |
| 662 | int statedump_pending:1; |
| 663 | |
| 664 | /* New UST 2.8 */ |
| 665 | struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */ |
| 666 | struct cds_list_head enums_head; |
| 667 | struct lttng_ctx *ctx; /* contexts for filters. */ |
| 668 | }; |
| 669 | |
| 670 | struct lttng_counter { |
| 671 | int objd; |
| 672 | struct lttng_event_notifier_group *event_notifier_group; /* owner */ |
| 673 | struct lttng_counter_transport *transport; |
| 674 | struct lib_counter *counter; |
| 675 | struct lttng_counter_ops *ops; |
| 676 | }; |
| 677 | |
| 678 | struct lttng_event_notifier_group { |
| 679 | int objd; |
| 680 | void *owner; |
| 681 | int notification_fd; |
| 682 | struct cds_list_head node; /* Event notifier group handle list */ |
| 683 | struct cds_list_head enablers_head; |
| 684 | struct cds_list_head event_notifiers_head; /* list of event_notifiers */ |
| 685 | struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */ |
| 686 | struct lttng_ctx *ctx; /* contexts for filters. */ |
| 687 | |
| 688 | struct lttng_counter *error_counter; |
| 689 | size_t error_counter_len; |
| 690 | }; |
| 691 | |
| 692 | struct lttng_transport { |
| 693 | char *name; |
| 694 | struct cds_list_head node; |
| 695 | struct lttng_channel_ops ops; |
| 696 | const struct lttng_ust_lib_ring_buffer_config *client_config; |
| 697 | }; |
| 698 | |
| 699 | struct lttng_counter_transport { |
| 700 | char *name; |
| 701 | struct cds_list_head node; |
| 702 | struct lttng_counter_ops ops; |
| 703 | const struct lib_counter_config *client_config; |
| 704 | }; |
| 705 | |
| 706 | struct lttng_session *lttng_session_create(void); |
| 707 | int lttng_session_enable(struct lttng_session *session); |
| 708 | int lttng_session_disable(struct lttng_session *session); |
| 709 | int lttng_session_statedump(struct lttng_session *session); |
| 710 | void lttng_session_destroy(struct lttng_session *session); |
| 711 | |
| 712 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
| 713 | const char *transport_name, |
| 714 | void *buf_addr, |
| 715 | size_t subbuf_size, size_t num_subbuf, |
| 716 | unsigned int switch_timer_interval, |
| 717 | unsigned int read_timer_interval, |
| 718 | int **shm_fd, int **wait_fd, |
| 719 | uint64_t **memory_map_size, |
| 720 | struct lttng_channel *chan_priv_init); |
| 721 | |
| 722 | int lttng_channel_enable(struct lttng_channel *channel); |
| 723 | int lttng_channel_disable(struct lttng_channel *channel); |
| 724 | |
| 725 | int lttng_attach_context(struct lttng_ust_context *context_param, |
| 726 | union ust_args *uargs, |
| 727 | struct lttng_ctx **ctx, struct lttng_session *session); |
| 728 | void lttng_transport_register(struct lttng_transport *transport); |
| 729 | void lttng_transport_unregister(struct lttng_transport *transport); |
| 730 | |
| 731 | int lttng_probe_register(struct lttng_probe_desc *desc); |
| 732 | void lttng_probe_unregister(struct lttng_probe_desc *desc); |
| 733 | void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc); |
| 734 | int lttng_fix_pending_events(void); |
| 735 | int lttng_probes_init(void); |
| 736 | void lttng_probes_exit(void); |
| 737 | int lttng_find_context(struct lttng_ctx *ctx, const char *name); |
| 738 | int lttng_get_context_index(struct lttng_ctx *ctx, const char *name); |
| 739 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p); |
| 740 | void lttng_context_update(struct lttng_ctx *ctx); |
| 741 | void lttng_remove_context_field(struct lttng_ctx **ctx_p, |
| 742 | struct lttng_ctx_field *field); |
| 743 | void lttng_destroy_context(struct lttng_ctx *ctx); |
| 744 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
| 745 | int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); |
| 746 | int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); |
| 747 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); |
| 748 | int lttng_add_ip_to_ctx(struct lttng_ctx **ctx); |
| 749 | int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx); |
| 750 | int lttng_add_dyntest_to_ctx(struct lttng_ctx **ctx); |
| 751 | int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx); |
| 752 | int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx); |
| 753 | int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx); |
| 754 | int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx); |
| 755 | int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx); |
| 756 | int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx); |
| 757 | int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx); |
| 758 | int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx); |
| 759 | int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx); |
| 760 | int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx); |
| 761 | int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx); |
| 762 | int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx); |
| 763 | int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx); |
| 764 | void lttng_context_vtid_reset(void); |
| 765 | void lttng_context_vpid_reset(void); |
| 766 | void lttng_context_procname_reset(void); |
| 767 | void lttng_context_cgroup_ns_reset(void); |
| 768 | void lttng_context_ipc_ns_reset(void); |
| 769 | void lttng_context_mnt_ns_reset(void); |
| 770 | void lttng_context_net_ns_reset(void); |
| 771 | void lttng_context_pid_ns_reset(void); |
| 772 | void lttng_context_user_ns_reset(void); |
| 773 | void lttng_context_uts_ns_reset(void); |
| 774 | void lttng_context_vuid_reset(void); |
| 775 | void lttng_context_veuid_reset(void); |
| 776 | void lttng_context_vsuid_reset(void); |
| 777 | void lttng_context_vgid_reset(void); |
| 778 | void lttng_context_vegid_reset(void); |
| 779 | void lttng_context_vsgid_reset(void); |
| 780 | |
| 781 | #ifdef LTTNG_UST_HAVE_PERF_EVENT |
| 782 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
| 783 | uint64_t config, |
| 784 | const char *name, |
| 785 | struct lttng_ctx **ctx); |
| 786 | int lttng_perf_counter_init(void); |
| 787 | void lttng_perf_counter_exit(void); |
| 788 | #else /* #ifdef LTTNG_UST_HAVE_PERF_EVENT */ |
| 789 | static inline |
| 790 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
| 791 | uint64_t config, |
| 792 | const char *name, |
| 793 | struct lttng_ctx **ctx) |
| 794 | { |
| 795 | return -ENOSYS; |
| 796 | } |
| 797 | static inline |
| 798 | int lttng_perf_counter_init(void) |
| 799 | { |
| 800 | return 0; |
| 801 | } |
| 802 | static inline |
| 803 | void lttng_perf_counter_exit(void) |
| 804 | { |
| 805 | } |
| 806 | #endif /* #else #ifdef LTTNG_UST_HAVE_PERF_EVENT */ |
| 807 | |
| 808 | extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata; |
| 809 | extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_discard; |
| 810 | extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite; |
| 811 | |
| 812 | struct lttng_transport *lttng_transport_find(const char *name); |
| 813 | |
| 814 | int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list); |
| 815 | void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list); |
| 816 | struct lttng_ust_tracepoint_iter * |
| 817 | lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list); |
| 818 | int lttng_probes_get_field_list(struct lttng_ust_field_list *list); |
| 819 | void lttng_probes_prune_field_list(struct lttng_ust_field_list *list); |
| 820 | struct lttng_ust_field_iter * |
| 821 | lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list); |
| 822 | |
| 823 | void lttng_free_event_filter_runtime(struct lttng_event *event); |
| 824 | |
| 825 | struct cds_list_head *lttng_get_probe_list_head(void); |
| 826 | int lttng_session_active(void); |
| 827 | |
| 828 | typedef int (*t_statedump_func_ptr)(struct lttng_session *session); |
| 829 | void lttng_handle_pending_statedump(void *owner); |
| 830 | struct cds_list_head *_lttng_get_sessions(void); |
| 831 | |
| 832 | struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session, |
| 833 | const struct lttng_enum_desc *enum_desc); |
| 834 | |
| 835 | void lttng_ust_dl_update(void *ip); |
| 836 | void lttng_ust_fixup_fd_tracker_tls(void); |
| 837 | |
| 838 | #ifdef __cplusplus |
| 839 | } |
| 840 | #endif |
| 841 | |
| 842 | #endif /* _LTTNG_UST_EVENTS_H */ |