| 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
| 2 | * |
| 3 | * lttng/events.h |
| 4 | * |
| 5 | * Holds LTTng per-session event registry. |
| 6 | * |
| 7 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | */ |
| 9 | |
| 10 | #ifndef _LTTNG_EVENTS_H |
| 11 | #define _LTTNG_EVENTS_H |
| 12 | |
| 13 | #include <lttng/kernel-version.h> |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/kprobes.h> |
| 16 | #include <linux/kref.h> |
| 17 | #include <linux/uuid.h> |
| 18 | #include <linux/irq_work.h> |
| 19 | #include <wrapper/uprobes.h> |
| 20 | #include <lttng/cpuhotplug.h> |
| 21 | #include <lttng/tracer.h> |
| 22 | #include <lttng/abi.h> |
| 23 | #include <lttng/abi-old.h> |
| 24 | #include <lttng/endian.h> |
| 25 | |
| 26 | #define lttng_is_signed_type(type) (((type) -1) < (type) 1) |
| 27 | |
| 28 | struct lttng_channel; |
| 29 | struct lttng_session; |
| 30 | struct lttng_metadata_cache; |
| 31 | struct lib_ring_buffer_ctx; |
| 32 | struct perf_event; |
| 33 | struct perf_event_attr; |
| 34 | struct lib_ring_buffer_config; |
| 35 | |
| 36 | /* Type description */ |
| 37 | |
| 38 | enum lttng_kernel_type { |
| 39 | lttng_kernel_type_integer, |
| 40 | lttng_kernel_type_string, |
| 41 | lttng_kernel_type_enum, |
| 42 | lttng_kernel_type_array, |
| 43 | lttng_kernel_type_sequence, |
| 44 | lttng_kernel_type_struct, |
| 45 | lttng_kernel_type_variant, |
| 46 | NR_LTTNG_KERNEL_TYPES, |
| 47 | }; |
| 48 | |
| 49 | enum lttng_kernel_string_encoding { |
| 50 | lttng_kernel_string_encoding_none = 0, |
| 51 | lttng_kernel_string_encoding_UTF8 = 1, |
| 52 | lttng_kernel_string_encoding_ASCII = 2, |
| 53 | NR_LTTNG_KERNEL_STRING_ENCODING, |
| 54 | }; |
| 55 | |
| 56 | enum channel_type { |
| 57 | PER_CPU_CHANNEL, |
| 58 | METADATA_CHANNEL, |
| 59 | }; |
| 60 | |
| 61 | struct lttng_kernel_enum_value { |
| 62 | unsigned long long value; |
| 63 | unsigned int signedness:1; |
| 64 | }; |
| 65 | |
| 66 | struct lttng_kernel_enum_entry { |
| 67 | struct lttng_kernel_enum_value start, end; /* start and end are inclusive */ |
| 68 | const char *string; |
| 69 | struct { |
| 70 | unsigned int is_auto:1; |
| 71 | } options; |
| 72 | }; |
| 73 | |
| 74 | /* |
| 75 | * struct lttng_kernel_type_common is fixed-size. Its children inherits |
| 76 | * from it by embedding struct lttng_kernel_type_common as its first field. |
| 77 | */ |
| 78 | struct lttng_kernel_type_common { |
| 79 | enum lttng_kernel_type type; |
| 80 | }; |
| 81 | |
| 82 | struct lttng_kernel_type_integer { |
| 83 | struct lttng_kernel_type_common parent; |
| 84 | unsigned int size; /* in bits */ |
| 85 | unsigned short alignment; /* in bits */ |
| 86 | unsigned int signedness:1, |
| 87 | reverse_byte_order:1; |
| 88 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
| 89 | }; |
| 90 | |
| 91 | struct lttng_kernel_type_string { |
| 92 | struct lttng_kernel_type_common parent; |
| 93 | enum lttng_kernel_string_encoding encoding; |
| 94 | }; |
| 95 | |
| 96 | struct lttng_kernel_type_enum { |
| 97 | struct lttng_kernel_type_common parent; |
| 98 | const struct lttng_kernel_enum_desc *desc; /* Enumeration mapping */ |
| 99 | const struct lttng_kernel_type_common *container_type; |
| 100 | }; |
| 101 | |
| 102 | struct lttng_kernel_type_array { |
| 103 | struct lttng_kernel_type_common parent; |
| 104 | const struct lttng_kernel_type_common *elem_type; |
| 105 | unsigned int length; /* Num. elems. */ |
| 106 | unsigned int alignment; |
| 107 | enum lttng_kernel_string_encoding encoding; |
| 108 | }; |
| 109 | |
| 110 | struct lttng_kernel_type_sequence { |
| 111 | struct lttng_kernel_type_common parent; |
| 112 | const char *length_name; /* Length field name. If NULL, use previous field. */ |
| 113 | const struct lttng_kernel_type_common *elem_type; |
| 114 | unsigned int alignment; /* Alignment before elements. */ |
| 115 | enum lttng_kernel_string_encoding encoding; |
| 116 | }; |
| 117 | |
| 118 | struct lttng_kernel_type_struct { |
| 119 | struct lttng_kernel_type_common parent; |
| 120 | unsigned int nr_fields; |
| 121 | const struct lttng_kernel_event_field **fields; /* Array of pointers to fields. */ |
| 122 | unsigned int alignment; |
| 123 | }; |
| 124 | |
| 125 | struct lttng_kernel_type_variant { |
| 126 | struct lttng_kernel_type_common parent; |
| 127 | const char *tag_name; /* Tag field name. If NULL, use previous field. */ |
| 128 | const struct lttng_kernel_event_field **choices; /* Array of pointers to fields. */ |
| 129 | unsigned int nr_choices; |
| 130 | unsigned int alignment; |
| 131 | }; |
| 132 | |
| 133 | struct lttng_kernel_enum_desc { |
| 134 | const char *name; |
| 135 | const struct lttng_kernel_enum_entry **entries; |
| 136 | unsigned int nr_entries; |
| 137 | }; |
| 138 | |
| 139 | /* Event field description */ |
| 140 | |
| 141 | struct lttng_kernel_event_field { |
| 142 | const char *name; |
| 143 | const struct lttng_kernel_type_common *type; |
| 144 | unsigned int nowrite:1, /* do not write into trace */ |
| 145 | user:1, /* fetch from user-space */ |
| 146 | nofilter:1; /* do not consider for filter */ |
| 147 | }; |
| 148 | |
| 149 | #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \ |
| 150 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \ |
| 151 | .parent = { \ |
| 152 | .type = lttng_kernel_type_integer, \ |
| 153 | }, \ |
| 154 | .size = (_size), \ |
| 155 | .alignment = (_alignment), \ |
| 156 | .signedness = (_signedness), \ |
| 157 | .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \ |
| 158 | .base = (_base), \ |
| 159 | })) |
| 160 | |
| 161 | #define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \ |
| 162 | lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \ |
| 163 | lttng_alignof(_type) * CHAR_BIT, \ |
| 164 | lttng_is_signed_type(_type), \ |
| 165 | _byte_order, \ |
| 166 | _base) |
| 167 | |
| 168 | #define lttng_kernel_static_type_enum(_desc, _container_type) \ |
| 169 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \ |
| 170 | .parent = { \ |
| 171 | .type = lttng_kernel_type_enum, \ |
| 172 | }, \ |
| 173 | .desc = (_desc), \ |
| 174 | .container_type = (_container_type), \ |
| 175 | })) |
| 176 | |
| 177 | #define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \ |
| 178 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \ |
| 179 | .parent = { \ |
| 180 | .type = lttng_kernel_type_array, \ |
| 181 | }, \ |
| 182 | .length = (_length), \ |
| 183 | .alignment = (_alignment), \ |
| 184 | .encoding = lttng_kernel_string_encoding_##_encoding, \ |
| 185 | .elem_type = (_elem_type), \ |
| 186 | })) |
| 187 | |
| 188 | #define lttng_kernel_static_type_array_text(_length) \ |
| 189 | lttng_kernel_static_type_array(_length, \ |
| 190 | lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \ |
| 191 | lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \ |
| 192 | __BYTE_ORDER, 10), \ |
| 193 | 0, UTF8) |
| 194 | |
| 195 | #define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \ |
| 196 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \ |
| 197 | .parent = { \ |
| 198 | .type = lttng_kernel_type_sequence, \ |
| 199 | }, \ |
| 200 | .length_name = (_length_name), \ |
| 201 | .alignment = (_alignment), \ |
| 202 | .encoding = lttng_kernel_string_encoding_##_encoding, \ |
| 203 | .elem_type = (_elem_type), \ |
| 204 | })) |
| 205 | |
| 206 | #define lttng_kernel_static_type_string(_encoding) \ |
| 207 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \ |
| 208 | .parent = { \ |
| 209 | .type = lttng_kernel_type_string, \ |
| 210 | }, \ |
| 211 | .encoding = lttng_kernel_string_encoding_##_encoding, \ |
| 212 | })) |
| 213 | |
| 214 | #define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \ |
| 215 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, { \ |
| 216 | .parent = { \ |
| 217 | .type = lttng_kernel_type_struct, \ |
| 218 | }, \ |
| 219 | .nr_fields = (_nr_fields), \ |
| 220 | .fields = _fields, \ |
| 221 | .alignment = (_alignment), \ |
| 222 | })) |
| 223 | |
| 224 | #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \ |
| 225 | ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \ |
| 226 | .parent = { \ |
| 227 | .type = lttng_kernel_type_variant, \ |
| 228 | }, \ |
| 229 | .tag_name = (_tag_name), \ |
| 230 | .choices = _choices, \ |
| 231 | .nr_choices = (_nr_choices), \ |
| 232 | .alignment = (_alignment), \ |
| 233 | })) |
| 234 | |
| 235 | #define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \ |
| 236 | __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \ |
| 237 | .name = (_name), \ |
| 238 | .type = (_type), \ |
| 239 | .nowrite = (_nowrite), \ |
| 240 | .user = (_user), \ |
| 241 | .nofilter = (_nofilter), \ |
| 242 | }) |
| 243 | |
| 244 | #define lttng_kernel_static_event_field_array(_fields...) \ |
| 245 | __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \ |
| 246 | _fields \ |
| 247 | ) |
| 248 | |
| 249 | #define lttng_kernel_static_enum_entry_value(_string, _value) \ |
| 250 | __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \ |
| 251 | .start = { \ |
| 252 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ |
| 253 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ |
| 254 | (long long) (_value) : (_value), \ |
| 255 | }, \ |
| 256 | .end = { \ |
| 257 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ |
| 258 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ |
| 259 | (long long) (_value) : (_value), \ |
| 260 | }, \ |
| 261 | .string = (_string), \ |
| 262 | }), |
| 263 | |
| 264 | #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \ |
| 265 | __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \ |
| 266 | .start = { \ |
| 267 | .signedness = lttng_is_signed_type(__typeof__(_range_start)), \ |
| 268 | .value = lttng_is_signed_type(__typeof__(_range_start)) ? \ |
| 269 | (long long) (_range_start) : (_range_start), \ |
| 270 | }, \ |
| 271 | .end = { \ |
| 272 | .signedness = lttng_is_signed_type(__typeof__(_range_end)), \ |
| 273 | .value = lttng_is_signed_type(__typeof__(_range_end)) ? \ |
| 274 | (long long) (_range_end) : (_range_end), \ |
| 275 | }, \ |
| 276 | .string = (_string), \ |
| 277 | }), |
| 278 | |
| 279 | #define lttng_kernel_static_enum_entry_auto(_string) \ |
| 280 | __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \ |
| 281 | .start = { \ |
| 282 | .signedness = -1, \ |
| 283 | .value = -1, \ |
| 284 | }, \ |
| 285 | .end = { \ |
| 286 | .signedness = -1, \ |
| 287 | .value = -1, \ |
| 288 | }, \ |
| 289 | .string = (_string), \ |
| 290 | .options = { \ |
| 291 | .is_auto = 1, \ |
| 292 | } \ |
| 293 | }), |
| 294 | |
| 295 | struct lttng_kernel_probe_ctx { |
| 296 | struct lttng_kernel_event_common *event; |
| 297 | uint8_t interruptible; |
| 298 | }; |
| 299 | |
| 300 | struct lttng_kernel_event_desc { |
| 301 | const char *event_name; /* lttng-modules name */ |
| 302 | const char *event_kname; /* Linux kernel name (tracepoints) */ |
| 303 | const struct lttng_kernel_probe_desc *probe_desc; |
| 304 | void (*probe_callback)(void); |
| 305 | const struct lttng_kernel_event_field **fields; /* event payload */ |
| 306 | unsigned int nr_fields; |
| 307 | struct module *owner; |
| 308 | }; |
| 309 | |
| 310 | struct lttng_kernel_probe_desc { |
| 311 | const char *provider_name; |
| 312 | const struct lttng_kernel_event_desc **event_desc; |
| 313 | unsigned int nr_events; |
| 314 | struct list_head head; /* chain registered probes */ |
| 315 | struct list_head lazy_init_head; |
| 316 | int lazy; /* lazy registration */ |
| 317 | }; |
| 318 | |
| 319 | /* |
| 320 | * Result of the run_filter() callback. |
| 321 | */ |
| 322 | enum lttng_kernel_event_filter_result { |
| 323 | LTTNG_KERNEL_EVENT_FILTER_ACCEPT = 0, |
| 324 | LTTNG_KERNEL_EVENT_FILTER_REJECT = 1, |
| 325 | }; |
| 326 | |
| 327 | struct lttng_kernel_event_common_private; |
| 328 | |
| 329 | enum lttng_kernel_event_type { |
| 330 | LTTNG_KERNEL_EVENT_TYPE_RECORDER = 0, |
| 331 | LTTNG_KERNEL_EVENT_TYPE_NOTIFIER = 1, |
| 332 | }; |
| 333 | |
| 334 | struct lttng_kernel_event_common { |
| 335 | struct lttng_kernel_event_common_private *priv; /* Private event interface */ |
| 336 | |
| 337 | enum lttng_kernel_event_type type; |
| 338 | /* Get child with container_of(). */ |
| 339 | |
| 340 | int enabled; |
| 341 | int eval_filter; /* Need to evaluate filters */ |
| 342 | int (*run_filter)(const struct lttng_kernel_event_common *event, |
| 343 | const char *stack_data, |
| 344 | struct lttng_kernel_probe_ctx *probe_ctx, |
| 345 | void *filter_ctx); |
| 346 | }; |
| 347 | |
| 348 | struct lttng_kernel_event_recorder_private; |
| 349 | |
| 350 | struct lttng_kernel_event_recorder { |
| 351 | struct lttng_kernel_event_common parent; |
| 352 | struct lttng_kernel_event_recorder_private *priv; /* Private event record interface */ |
| 353 | |
| 354 | struct lttng_channel *chan; |
| 355 | }; |
| 356 | |
| 357 | struct lttng_kernel_notification_ctx { |
| 358 | int eval_capture; /* Capture evaluation available. */ |
| 359 | }; |
| 360 | |
| 361 | struct lttng_kernel_event_notifier_private; |
| 362 | |
| 363 | struct lttng_kernel_event_notifier { |
| 364 | struct lttng_kernel_event_common parent; |
| 365 | struct lttng_kernel_event_notifier_private *priv; /* Private event notifier interface */ |
| 366 | |
| 367 | int eval_capture; /* Need to evaluate capture */ |
| 368 | void (*notification_send)(struct lttng_kernel_event_notifier *event_notifier, |
| 369 | const char *stack_data, |
| 370 | struct lttng_kernel_probe_ctx *probe_ctx, |
| 371 | struct lttng_kernel_notification_ctx *notif_ctx); |
| 372 | }; |
| 373 | |
| 374 | struct lttng_channel_ops { |
| 375 | struct channel *(*channel_create)(const char *name, |
| 376 | void *priv, |
| 377 | void *buf_addr, |
| 378 | size_t subbuf_size, size_t num_subbuf, |
| 379 | unsigned int switch_timer_interval, |
| 380 | unsigned int read_timer_interval); |
| 381 | void (*channel_destroy)(struct channel *chan); |
| 382 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); |
| 383 | int (*buffer_has_read_closed_stream)(struct channel *chan); |
| 384 | void (*buffer_read_close)(struct lib_ring_buffer *buf); |
| 385 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx); |
| 386 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
| 387 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, |
| 388 | size_t len); |
| 389 | void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx, |
| 390 | const void *src, size_t len); |
| 391 | void (*event_memset)(struct lib_ring_buffer_ctx *ctx, |
| 392 | int c, size_t len); |
| 393 | void (*event_strcpy)(struct lib_ring_buffer_ctx *ctx, const char *src, |
| 394 | size_t len); |
| 395 | void (*event_strcpy_from_user)(struct lib_ring_buffer_ctx *ctx, |
| 396 | const char __user *src, size_t len); |
| 397 | /* |
| 398 | * packet_avail_size returns the available size in the current |
| 399 | * packet. Note that the size returned is only a hint, since it |
| 400 | * may change due to concurrent writes. |
| 401 | */ |
| 402 | size_t (*packet_avail_size)(struct channel *chan); |
| 403 | wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu); |
| 404 | wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); |
| 405 | int (*is_finalized)(struct channel *chan); |
| 406 | int (*is_disabled)(struct channel *chan); |
| 407 | int (*timestamp_begin) (const struct lib_ring_buffer_config *config, |
| 408 | struct lib_ring_buffer *bufb, |
| 409 | uint64_t *timestamp_begin); |
| 410 | int (*timestamp_end) (const struct lib_ring_buffer_config *config, |
| 411 | struct lib_ring_buffer *bufb, |
| 412 | uint64_t *timestamp_end); |
| 413 | int (*events_discarded) (const struct lib_ring_buffer_config *config, |
| 414 | struct lib_ring_buffer *bufb, |
| 415 | uint64_t *events_discarded); |
| 416 | int (*content_size) (const struct lib_ring_buffer_config *config, |
| 417 | struct lib_ring_buffer *bufb, |
| 418 | uint64_t *content_size); |
| 419 | int (*packet_size) (const struct lib_ring_buffer_config *config, |
| 420 | struct lib_ring_buffer *bufb, |
| 421 | uint64_t *packet_size); |
| 422 | int (*stream_id) (const struct lib_ring_buffer_config *config, |
| 423 | struct lib_ring_buffer *bufb, |
| 424 | uint64_t *stream_id); |
| 425 | int (*current_timestamp) (const struct lib_ring_buffer_config *config, |
| 426 | struct lib_ring_buffer *bufb, |
| 427 | uint64_t *ts); |
| 428 | int (*sequence_number) (const struct lib_ring_buffer_config *config, |
| 429 | struct lib_ring_buffer *bufb, |
| 430 | uint64_t *seq); |
| 431 | int (*instance_id) (const struct lib_ring_buffer_config *config, |
| 432 | struct lib_ring_buffer *bufb, |
| 433 | uint64_t *id); |
| 434 | }; |
| 435 | |
| 436 | struct lttng_counter_ops { |
| 437 | struct lib_counter *(*counter_create)(size_t nr_dimensions, |
| 438 | const size_t *max_nr_elem, /* for each dimension */ |
| 439 | int64_t global_sum_step); |
| 440 | void (*counter_destroy)(struct lib_counter *counter); |
| 441 | int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes, |
| 442 | int64_t v); |
| 443 | /* |
| 444 | * counter_read reads a specific cpu's counter if @cpu >= 0, or |
| 445 | * the global aggregation counter if @cpu == -1. |
| 446 | */ |
| 447 | int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu, |
| 448 | int64_t *value, bool *overflow, bool *underflow); |
| 449 | /* |
| 450 | * counter_aggregate returns the total sum of all per-cpu counters and |
| 451 | * the global aggregation counter. |
| 452 | */ |
| 453 | int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes, |
| 454 | int64_t *value, bool *overflow, bool *underflow); |
| 455 | int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes); |
| 456 | }; |
| 457 | |
| 458 | struct lttng_transport { |
| 459 | char *name; |
| 460 | struct module *owner; |
| 461 | struct list_head node; |
| 462 | struct lttng_channel_ops ops; |
| 463 | }; |
| 464 | |
| 465 | struct lttng_counter_transport { |
| 466 | char *name; |
| 467 | struct module *owner; |
| 468 | struct list_head node; |
| 469 | struct lttng_counter_ops ops; |
| 470 | }; |
| 471 | |
| 472 | struct lttng_syscall_filter; |
| 473 | |
| 474 | #define LTTNG_EVENT_HT_BITS 12 |
| 475 | #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS) |
| 476 | |
| 477 | struct lttng_event_ht { |
| 478 | struct hlist_head table[LTTNG_EVENT_HT_SIZE]; |
| 479 | }; |
| 480 | |
| 481 | #define LTTNG_EVENT_NOTIFIER_HT_BITS 12 |
| 482 | #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS) |
| 483 | |
| 484 | struct lttng_event_notifier_ht { |
| 485 | struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE]; |
| 486 | }; |
| 487 | |
| 488 | struct lttng_channel { |
| 489 | unsigned int id; |
| 490 | struct channel *chan; /* Channel buffers */ |
| 491 | int enabled; |
| 492 | struct lttng_kernel_ctx *ctx; |
| 493 | /* Event ID management */ |
| 494 | struct lttng_session *session; |
| 495 | struct file *file; /* File associated to channel */ |
| 496 | unsigned int free_event_id; /* Next event ID to allocate */ |
| 497 | struct list_head list; /* Channel list */ |
| 498 | struct lttng_channel_ops *ops; |
| 499 | struct lttng_transport *transport; |
| 500 | struct hlist_head *sc_table; /* for syscall tracing */ |
| 501 | struct hlist_head *compat_sc_table; |
| 502 | struct hlist_head *sc_exit_table; /* for syscall exit tracing */ |
| 503 | struct hlist_head *compat_sc_exit_table; |
| 504 | struct hlist_head sc_unknown; /* for unknown syscalls */ |
| 505 | struct hlist_head sc_compat_unknown; |
| 506 | struct hlist_head sc_exit_unknown; |
| 507 | struct hlist_head compat_sc_exit_unknown; |
| 508 | struct lttng_syscall_filter *sc_filter; |
| 509 | int header_type; /* 0: unset, 1: compact, 2: large */ |
| 510 | enum channel_type channel_type; |
| 511 | int syscall_all_entry; |
| 512 | int syscall_all_exit; |
| 513 | unsigned int metadata_dumped:1, |
| 514 | sys_enter_registered:1, |
| 515 | sys_exit_registered:1, |
| 516 | tstate:1; /* Transient enable state */ |
| 517 | }; |
| 518 | |
| 519 | struct lttng_metadata_stream { |
| 520 | void *priv; /* Ring buffer private data */ |
| 521 | struct lttng_metadata_cache *metadata_cache; |
| 522 | unsigned int metadata_in; /* Bytes read from the cache */ |
| 523 | unsigned int metadata_out; /* Bytes consumed from stream */ |
| 524 | int finalized; /* Has channel been finalized */ |
| 525 | wait_queue_head_t read_wait; /* Reader buffer-level wait queue */ |
| 526 | struct list_head list; /* Stream list */ |
| 527 | struct lttng_transport *transport; |
| 528 | uint64_t version; /* Current version of the metadata cache */ |
| 529 | bool coherent; /* Stream in a coherent state */ |
| 530 | }; |
| 531 | |
| 532 | #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128 |
| 533 | |
| 534 | struct lttng_dynamic_len_stack { |
| 535 | size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE]; |
| 536 | size_t offset; |
| 537 | }; |
| 538 | |
| 539 | DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack); |
| 540 | |
| 541 | /* |
| 542 | * struct lttng_id_tracker declared in header due to deferencing of *v |
| 543 | * in RCU_INITIALIZER(v). |
| 544 | */ |
| 545 | #define LTTNG_ID_HASH_BITS 6 |
| 546 | #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS) |
| 547 | |
| 548 | enum tracker_type { |
| 549 | TRACKER_PID, |
| 550 | TRACKER_VPID, |
| 551 | TRACKER_UID, |
| 552 | TRACKER_VUID, |
| 553 | TRACKER_GID, |
| 554 | TRACKER_VGID, |
| 555 | |
| 556 | TRACKER_UNKNOWN, |
| 557 | }; |
| 558 | |
| 559 | struct lttng_id_tracker_rcu { |
| 560 | struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE]; |
| 561 | }; |
| 562 | |
| 563 | struct lttng_id_tracker { |
| 564 | struct lttng_session *session; |
| 565 | enum tracker_type tracker_type; |
| 566 | struct lttng_id_tracker_rcu *p; /* RCU dereferenced. */ |
| 567 | }; |
| 568 | |
| 569 | struct lttng_id_hash_node { |
| 570 | struct hlist_node hlist; |
| 571 | int id; |
| 572 | }; |
| 573 | |
| 574 | struct lttng_session { |
| 575 | int active; /* Is trace session active ? */ |
| 576 | int been_active; /* Has trace session been active ? */ |
| 577 | struct file *file; /* File associated to session */ |
| 578 | struct list_head chan; /* Channel list head */ |
| 579 | struct list_head events; /* Event list head */ |
| 580 | struct list_head list; /* Session list */ |
| 581 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
| 582 | uuid_le uuid; /* Trace session unique ID */ |
| 583 | struct lttng_metadata_cache *metadata_cache; |
| 584 | struct lttng_id_tracker pid_tracker; |
| 585 | struct lttng_id_tracker vpid_tracker; |
| 586 | struct lttng_id_tracker uid_tracker; |
| 587 | struct lttng_id_tracker vuid_tracker; |
| 588 | struct lttng_id_tracker gid_tracker; |
| 589 | struct lttng_id_tracker vgid_tracker; |
| 590 | unsigned int metadata_dumped:1, |
| 591 | tstate:1; /* Transient enable state */ |
| 592 | /* List of event enablers */ |
| 593 | struct list_head enablers_head; |
| 594 | /* Hash table of events */ |
| 595 | struct lttng_event_ht events_ht; |
| 596 | char name[LTTNG_KERNEL_ABI_SESSION_NAME_LEN]; |
| 597 | char creation_time[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN]; |
| 598 | }; |
| 599 | |
| 600 | struct lttng_counter { |
| 601 | struct file *file; /* File associated to counter. */ |
| 602 | struct file *owner; |
| 603 | struct lttng_counter_transport *transport; |
| 604 | struct lib_counter *counter; |
| 605 | struct lttng_counter_ops *ops; |
| 606 | }; |
| 607 | |
| 608 | struct lttng_event_notifier_group { |
| 609 | struct file *file; /* File associated to event notifier group */ |
| 610 | struct file *notif_file; /* File used to expose notifications to userspace. */ |
| 611 | struct list_head node; /* event notifier group list */ |
| 612 | struct list_head enablers_head; /* List of enablers */ |
| 613 | struct list_head event_notifiers_head; /* List of event notifier */ |
| 614 | struct lttng_event_notifier_ht event_notifiers_ht; /* Hash table of event notifiers */ |
| 615 | struct lttng_channel_ops *ops; |
| 616 | struct lttng_transport *transport; |
| 617 | struct channel *chan; /* Ring buffer channel for event notifier group. */ |
| 618 | struct lib_ring_buffer *buf; /* Ring buffer for event notifier group. */ |
| 619 | wait_queue_head_t read_wait; |
| 620 | struct irq_work wakeup_pending; /* Pending wakeup irq work. */ |
| 621 | struct lttng_kernel_event_notifier *sc_unknown; /* for unknown syscalls */ |
| 622 | struct lttng_kernel_event_notifier *sc_compat_unknown; |
| 623 | |
| 624 | struct lttng_syscall_filter *sc_filter; |
| 625 | |
| 626 | struct hlist_head *event_notifier_syscall_dispatch; |
| 627 | struct hlist_head *event_notifier_compat_syscall_dispatch; |
| 628 | struct hlist_head *event_notifier_exit_syscall_dispatch; |
| 629 | struct hlist_head *event_notifier_exit_compat_syscall_dispatch; |
| 630 | |
| 631 | struct hlist_head event_notifier_unknown_syscall_dispatch; |
| 632 | struct hlist_head event_notifier_compat_unknown_syscall_dispatch; |
| 633 | struct hlist_head event_notifier_exit_unknown_syscall_dispatch; |
| 634 | struct hlist_head event_notifier_exit_compat_unknown_syscall_dispatch; |
| 635 | |
| 636 | int syscall_all_entry; |
| 637 | int syscall_all_exit; |
| 638 | |
| 639 | unsigned int sys_enter_registered:1, sys_exit_registered:1; |
| 640 | |
| 641 | struct lttng_counter *error_counter; |
| 642 | size_t error_counter_len; |
| 643 | }; |
| 644 | |
| 645 | struct lttng_metadata_cache { |
| 646 | char *data; /* Metadata cache */ |
| 647 | unsigned int cache_alloc; /* Metadata allocated size (bytes) */ |
| 648 | unsigned int metadata_written; /* Number of bytes written in metadata cache */ |
| 649 | atomic_t producing; /* Metadata being produced (incomplete) */ |
| 650 | struct kref refcount; /* Metadata cache usage */ |
| 651 | struct list_head metadata_stream; /* Metadata stream list */ |
| 652 | uuid_le uuid; /* Trace session unique ID (copy) */ |
| 653 | struct mutex lock; /* Produce/consume lock */ |
| 654 | uint64_t version; /* Current version of the metadata */ |
| 655 | }; |
| 656 | |
| 657 | void lttng_lock_sessions(void); |
| 658 | void lttng_unlock_sessions(void); |
| 659 | |
| 660 | struct list_head *lttng_get_probe_list_head(void); |
| 661 | |
| 662 | int lttng_fix_pending_events(void); |
| 663 | int lttng_fix_pending_event_notifiers(void); |
| 664 | int lttng_session_active(void); |
| 665 | bool lttng_event_notifier_active(void); |
| 666 | |
| 667 | struct lttng_session *lttng_session_create(void); |
| 668 | int lttng_session_enable(struct lttng_session *session); |
| 669 | int lttng_session_disable(struct lttng_session *session); |
| 670 | void lttng_session_destroy(struct lttng_session *session); |
| 671 | int lttng_session_metadata_regenerate(struct lttng_session *session); |
| 672 | int lttng_session_statedump(struct lttng_session *session); |
| 673 | void metadata_cache_destroy(struct kref *kref); |
| 674 | |
| 675 | struct lttng_counter *lttng_kernel_counter_create( |
| 676 | const char *counter_transport_name, size_t number_dimensions, |
| 677 | const size_t *dimensions_sizes); |
| 678 | int lttng_kernel_counter_read(struct lttng_counter *counter, |
| 679 | const size_t *dimension_indexes, int32_t cpu, |
| 680 | int64_t *val, bool *overflow, bool *underflow); |
| 681 | int lttng_kernel_counter_aggregate(struct lttng_counter *counter, |
| 682 | const size_t *dimension_indexes, int64_t *val, |
| 683 | bool *overflow, bool *underflow); |
| 684 | int lttng_kernel_counter_clear(struct lttng_counter *counter, |
| 685 | const size_t *dimension_indexes); |
| 686 | |
| 687 | |
| 688 | struct lttng_event_notifier_group *lttng_event_notifier_group_create(void); |
| 689 | int lttng_event_notifier_group_create_error_counter( |
| 690 | struct file *event_notifier_group_file, |
| 691 | const struct lttng_kernel_abi_counter_conf *error_counter_conf); |
| 692 | void lttng_event_notifier_group_destroy( |
| 693 | struct lttng_event_notifier_group *event_notifier_group); |
| 694 | |
| 695 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
| 696 | const char *transport_name, |
| 697 | void *buf_addr, |
| 698 | size_t subbuf_size, size_t num_subbuf, |
| 699 | unsigned int switch_timer_interval, |
| 700 | unsigned int read_timer_interval, |
| 701 | enum channel_type channel_type); |
| 702 | struct lttng_channel *lttng_global_channel_create(struct lttng_session *session, |
| 703 | int overwrite, void *buf_addr, |
| 704 | size_t subbuf_size, size_t num_subbuf, |
| 705 | unsigned int switch_timer_interval, |
| 706 | unsigned int read_timer_interval); |
| 707 | |
| 708 | void lttng_metadata_channel_destroy(struct lttng_channel *chan); |
| 709 | struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lttng_channel *chan, |
| 710 | struct lttng_kernel_abi_event *event_param, |
| 711 | const struct lttng_kernel_event_desc *event_desc, |
| 712 | enum lttng_kernel_abi_instrumentation itype); |
| 713 | struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_channel *chan, |
| 714 | struct lttng_kernel_abi_event *event_param, |
| 715 | const struct lttng_kernel_event_desc *event_desc, |
| 716 | enum lttng_kernel_abi_instrumentation itype); |
| 717 | struct lttng_kernel_event_recorder *lttng_event_compat_old_create(struct lttng_channel *chan, |
| 718 | struct lttng_kernel_abi_old_event *old_event_param, |
| 719 | const struct lttng_kernel_event_desc *internal_desc); |
| 720 | |
| 721 | struct lttng_kernel_event_notifier *lttng_event_notifier_create( |
| 722 | const struct lttng_kernel_event_desc *event_notifier_desc, |
| 723 | uint64_t id, |
| 724 | uint64_t error_counter_idx, |
| 725 | struct lttng_event_notifier_group *event_notifier_group, |
| 726 | struct lttng_kernel_abi_event_notifier *event_notifier_param, |
| 727 | enum lttng_kernel_abi_instrumentation itype); |
| 728 | struct lttng_kernel_event_notifier *_lttng_event_notifier_create( |
| 729 | const struct lttng_kernel_event_desc *event_notifier_desc, |
| 730 | uint64_t id, |
| 731 | uint64_t error_counter_idx, |
| 732 | struct lttng_event_notifier_group *event_notifier_group, |
| 733 | struct lttng_kernel_abi_event_notifier *event_notifier_param, |
| 734 | enum lttng_kernel_abi_instrumentation itype); |
| 735 | |
| 736 | int lttng_channel_enable(struct lttng_channel *channel); |
| 737 | int lttng_channel_disable(struct lttng_channel *channel); |
| 738 | int lttng_event_enable(struct lttng_kernel_event_common *event); |
| 739 | int lttng_event_disable(struct lttng_kernel_event_common *event); |
| 740 | |
| 741 | void lttng_transport_register(struct lttng_transport *transport); |
| 742 | void lttng_transport_unregister(struct lttng_transport *transport); |
| 743 | |
| 744 | void lttng_counter_transport_register(struct lttng_counter_transport *transport); |
| 745 | void lttng_counter_transport_unregister(struct lttng_counter_transport *transport); |
| 746 | |
| 747 | void synchronize_trace(void); |
| 748 | int lttng_abi_init(void); |
| 749 | int lttng_abi_compat_old_init(void); |
| 750 | void lttng_abi_exit(void); |
| 751 | void lttng_abi_compat_old_exit(void); |
| 752 | |
| 753 | int lttng_probe_register(struct lttng_kernel_probe_desc *desc); |
| 754 | void lttng_probe_unregister(struct lttng_kernel_probe_desc *desc); |
| 755 | const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name); |
| 756 | void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc); |
| 757 | int lttng_probes_init(void); |
| 758 | void lttng_probes_exit(void); |
| 759 | |
| 760 | int lttng_metadata_output_channel(struct lttng_metadata_stream *stream, |
| 761 | struct channel *chan, bool *coherent); |
| 762 | |
| 763 | int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node); |
| 764 | int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf); |
| 765 | void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu); |
| 766 | bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id); |
| 767 | int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id); |
| 768 | int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id); |
| 769 | |
| 770 | int lttng_session_track_id(struct lttng_session *session, |
| 771 | enum tracker_type tracker_type, int id); |
| 772 | int lttng_session_untrack_id(struct lttng_session *session, |
| 773 | enum tracker_type tracker_type, int id); |
| 774 | |
| 775 | int lttng_session_list_tracker_ids(struct lttng_session *session, |
| 776 | enum tracker_type tracker_type); |
| 777 | |
| 778 | void lttng_clock_ref(void); |
| 779 | void lttng_clock_unref(void); |
| 780 | |
| 781 | void lttng_free_event_filter_runtime(struct lttng_kernel_event_common *event); |
| 782 | |
| 783 | int lttng_probes_init(void); |
| 784 | |
| 785 | int lttng_logger_init(void); |
| 786 | void lttng_logger_exit(void); |
| 787 | |
| 788 | extern int lttng_statedump_start(struct lttng_session *session); |
| 789 | |
| 790 | int lttng_calibrate(struct lttng_kernel_abi_calibrate *calibrate); |
| 791 | |
| 792 | extern const struct file_operations lttng_tracepoint_list_fops; |
| 793 | extern const struct file_operations lttng_syscall_list_fops; |
| 794 | |
| 795 | #endif /* _LTTNG_EVENTS_H */ |