2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
7 #ifndef _UST_COMMON_UST_EVENTS_H
8 #define _UST_COMMON_UST_EVENTS_H
13 #include <urcu/list.h>
14 #include <urcu/hlist.h>
16 #include <lttng/ust-events.h>
18 #include "common/macros.h"
19 #include "common/ust-context-provider.h"
22 * The context procname length is part of the LTTng-UST ABI.
23 * TODO: At the next breaking protocol bump, all users of this macro
24 * should instead use LTTNG_UST_ABI_PROCNAME_LEN.
26 #define LTTNG_UST_CONTEXT_PROCNAME_LEN 17
28 struct lttng_ust_abi_obj
;
29 struct lttng_event_notifier_group
;
31 union lttng_ust_abi_args
{
41 struct lttng_ust_abi_field_iter entry
;
47 int event_notifier_notif_fd
;
48 } event_notifier_handle
;
64 struct lttng_ust_abi_objd_ops
{
65 long (*cmd
)(int objd
, unsigned int cmd
, unsigned long arg
,
66 union lttng_ust_abi_args
*args
, void *owner
);
67 int (*release
)(int objd
);
70 enum lttng_enabler_format_type
{
71 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
72 LTTNG_ENABLER_FORMAT_EVENT
,
75 enum lttng_key_token_type
{
76 LTTNG_KEY_TOKEN_STRING
= 0,
77 LTTNG_KEY_TOKEN_EVENT_NAME
= 1,
78 LTTNG_KEY_TOKEN_PROVIDER_NAME
= 2,
81 #define LTTNG_KEY_TOKEN_STRING_LEN_MAX 4096
82 struct lttng_key_token
{
83 enum lttng_key_token_type type
;
85 char string
[LTTNG_KEY_TOKEN_STRING_LEN_MAX
];
90 LTTNG_KEY_TYPE_TOKENS
= 0,
91 LTTNG_KEY_TYPE_INTEGER
= 1,
94 #define LTTNG_NR_KEY_TOKEN 8
95 struct lttng_counter_key_dimension
{
96 enum lttng_key_type key_type
;
100 size_t nr_key_tokens
;
101 struct lttng_key_token key_tokens
[LTTNG_NR_KEY_TOKEN
];
106 #define LTTNG_COUNTER_DIMENSION_MAX 4
107 struct lttng_counter_key
{
108 size_t nr_dimensions
;
109 struct lttng_counter_key_dimension key_dimensions
[LTTNG_COUNTER_DIMENSION_MAX
];
112 struct lttng_counter_dimension
{
114 uint64_t underflow_index
;
115 uint64_t overflow_index
;
116 enum lttng_key_type key_type
;
117 uint8_t has_underflow
;
118 uint8_t has_overflow
;
121 enum lttng_event_enabler_type
{
122 LTTNG_EVENT_ENABLER_TYPE_RECORDER
,
123 LTTNG_EVENT_ENABLER_TYPE_NOTIFIER
,
124 LTTNG_EVENT_ENABLER_TYPE_COUNTER
,
128 * Enabler field, within whatever object is enabling an event. Target of
129 * backward reference.
131 struct lttng_event_enabler_common
{
132 enum lttng_event_enabler_type enabler_type
;
134 enum lttng_enabler_format_type format_type
;
136 /* head list of struct lttng_ust_filter_bytecode_node */
137 struct cds_list_head filter_bytecode_head
;
138 /* head list of struct lttng_ust_excluder_node */
139 struct cds_list_head excluder_head
;
141 struct lttng_ust_abi_event event_param
;
142 unsigned int enabled
:1;
144 struct cds_list_head node
; /* list of enablers */
145 uint64_t user_token
; /* User-provided token */
148 struct lttng_event_enabler_session_common
{
149 struct lttng_event_enabler_common parent
;
150 struct lttng_ust_channel_common
*chan
;
153 struct lttng_event_recorder_enabler
{
154 struct lttng_event_enabler_session_common parent
;
155 struct lttng_ust_channel_buffer
*chan
;
158 enum lttng_event_counter_action
{
159 LTTNG_EVENT_COUNTER_ACTION_INCREMENT
= 0,
162 struct lttng_event_counter_enabler
{
163 struct lttng_event_enabler_session_common parent
;
164 struct lttng_ust_channel_counter
*chan
;
165 struct lttng_counter_key key
;
167 enum lttng_event_counter_action action
;
170 struct lttng_event_notifier_enabler
{
171 struct lttng_event_enabler_common parent
;
172 uint64_t error_counter_index
;
173 struct cds_list_head capture_bytecode_head
;
174 struct lttng_event_notifier_group
*group
; /* weak ref */
175 uint64_t num_captures
;
178 enum lttng_ust_bytecode_type
{
179 LTTNG_UST_BYTECODE_TYPE_FILTER
,
180 LTTNG_UST_BYTECODE_TYPE_CAPTURE
,
183 struct lttng_ust_bytecode_node
{
184 enum lttng_ust_bytecode_type type
;
185 struct cds_list_head node
;
186 struct lttng_event_enabler_common
*enabler
;
189 uint32_t reloc_offset
;
196 * Bytecode interpreter return value.
198 enum lttng_ust_bytecode_interpreter_ret
{
199 LTTNG_UST_BYTECODE_INTERPRETER_ERROR
= -1,
200 LTTNG_UST_BYTECODE_INTERPRETER_OK
= 0,
203 struct lttng_interpreter_output
;
204 struct lttng_ust_bytecode_runtime_private
;
206 enum lttng_ust_bytecode_filter_result
{
207 LTTNG_UST_BYTECODE_FILTER_ACCEPT
= 0,
208 LTTNG_UST_BYTECODE_FILTER_REJECT
= 1,
211 struct lttng_ust_bytecode_filter_ctx
{
212 enum lttng_ust_bytecode_filter_result result
;
215 struct lttng_ust_excluder_node
{
216 struct cds_list_head node
;
217 struct lttng_event_enabler_common
*enabler
;
219 * struct lttng_ust_event_exclusion had variable sized array,
220 * must be last field.
222 struct lttng_ust_abi_event_exclusion excluder
;
225 /* Data structures used by the tracer. */
227 struct tp_list_entry
{
228 struct lttng_ust_abi_tracepoint_iter tp
;
229 struct cds_list_head head
;
232 struct lttng_ust_tracepoint_list
{
233 struct tp_list_entry
*iter
;
234 struct cds_list_head head
;
237 struct tp_field_list_entry
{
238 struct lttng_ust_abi_field_iter field
;
239 struct cds_list_head head
;
242 struct lttng_ust_field_list
{
243 struct tp_field_list_entry
*iter
;
244 struct cds_list_head head
;
248 * Objects in a linked-list of enablers, owned by an event or event_notifier.
249 * This is used because an event (or a event_notifier) can be enabled by more
250 * than one enabler and we want a quick way to iterate over all enablers of an
253 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
254 * event with the name "my_app:abc".
256 struct lttng_enabler_ref
{
257 struct cds_list_head node
; /* enabler ref list */
258 struct lttng_event_enabler_common
*ref
; /* backward ref */
261 #define LTTNG_UST_EVENT_HT_BITS 12
262 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
264 struct lttng_ust_event_ht
{
265 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
268 #define LTTNG_UST_ENUM_HT_BITS 12
269 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
271 struct lttng_ust_enum_ht
{
272 struct cds_hlist_head table
[LTTNG_UST_ENUM_HT_SIZE
];
275 struct lttng_event_notifier_group
{
279 struct cds_list_head node
; /* Event notifier group handle list */
281 /* List of non-synchronized enablers */
282 struct cds_list_head unsync_enablers_head
;
283 /* List of synchronized enablers */
284 struct cds_list_head sync_enablers_head
;
286 struct cds_list_head event_notifiers_head
; /* list of event_notifiers */
287 struct lttng_ust_event_ht event_notifiers_ht
; /* hashtable of event notifiers */
288 struct lttng_ust_ctx
*ctx
; /* contexts for filters. */
290 struct lttng_ust_channel_counter
*error_counter
;
291 size_t error_counter_len
;
294 struct lttng_transport
{
296 struct cds_list_head node
;
297 struct lttng_ust_channel_buffer_ops ops
;
298 const struct lttng_ust_ring_buffer_config
*client_config
;
301 struct lttng_counter_transport
{
303 struct cds_list_head node
;
304 struct lttng_ust_channel_counter_ops ops
;
305 const struct lib_counter_config
*client_config
;
308 struct lttng_ust_event_common_private
{
309 struct lttng_ust_event_common
*pub
; /* Public event interface */
311 const struct lttng_ust_event_desc
*desc
;
312 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
313 struct cds_list_head enablers_ref_head
;
314 int registered
; /* has reg'd tracepoint probe */
317 int has_enablers_without_filter_bytecode
;
318 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
319 struct cds_list_head filter_bytecode_runtime_head
;
321 struct cds_hlist_node name_hlist_node
; /* node in events-by-name hash table */
322 struct cds_list_head node
; /* node in event list */
325 struct lttng_ust_event_session_common_private
{
326 struct lttng_ust_event_common_private parent
;
328 struct lttng_ust_channel_common
*chan
;
330 uint64_t id
; /* Event id */
333 struct lttng_ust_event_recorder_private
{
334 struct lttng_ust_event_session_common_private parent
;
336 struct lttng_ust_event_recorder
*pub
; /* Public event interface */
339 struct lttng_ust_event_counter_private
{
340 struct lttng_ust_event_session_common_private parent
;
342 struct lttng_ust_event_counter
*pub
; /* Public event interface */
343 enum lttng_event_counter_action action
;
344 char key
[LTTNG_KEY_TOKEN_STRING_LEN_MAX
];
347 struct lttng_ust_event_notifier_private
{
348 struct lttng_ust_event_common_private parent
;
350 struct lttng_ust_event_notifier
*pub
; /* Public event notifier interface */
351 struct lttng_event_notifier_group
*group
; /* weak ref */
352 size_t num_captures
; /* Needed to allocate the msgpack array. */
353 uint64_t error_counter_index
;
354 struct cds_list_head capture_bytecode_runtime_head
;
357 struct lttng_ust_bytecode_runtime
{
358 enum lttng_ust_bytecode_type type
;
359 struct lttng_ust_bytecode_node
*bc
;
361 int (*interpreter_func
)(struct lttng_ust_bytecode_runtime
*bytecode_runtime
,
362 const char *interpreter_stack_data
,
363 struct lttng_ust_probe_ctx
*probe_ctx
,
365 struct cds_list_head node
; /* list of bytecode runtime in event */
367 * Pointer to a URCU-protected pointer owned by an `struct
368 * lttng_session`or `struct lttng_event_notifier_group`.
370 struct lttng_ust_ctx
**pctx
;
373 struct lttng_ust_session_private
{
374 struct lttng_ust_session
*pub
; /* Public session interface */
376 int been_active
; /* Been active ? */
377 int objd
; /* Object associated */
378 struct cds_list_head chan_head
; /* Channel list head */
379 struct cds_list_head counters_head
; /* Counter list head */
380 struct cds_list_head events_head
; /* list of events */
381 struct cds_list_head node
; /* Session list */
383 /* List of non-synchronized enablers */
384 struct cds_list_head unsync_enablers_head
;
385 /* List of synchronized enablers */
386 struct cds_list_head sync_enablers_head
;
388 struct cds_list_head enums_head
;
390 struct lttng_ust_event_ht events_name_ht
; /* ht of events, indexed by name */
391 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
393 void *owner
; /* object owner */
394 unsigned int tstate
:1; /* Transient enable state */
395 unsigned int statedump_pending
:1;
396 struct lttng_ust_ctx
*ctx
; /* contexts for filters. */
397 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
398 bool uuid_set
; /* Is uuid set ? */
402 const struct lttng_ust_enum_desc
*desc
;
403 struct lttng_ust_session
*session
;
404 struct cds_list_head node
; /* Enum list in session */
405 struct cds_hlist_node hlist
; /* Session ht of enums */
406 uint64_t id
; /* Enumeration ID in sessiond */
409 struct lttng_ust_shm_handle
;
411 struct lttng_ust_channel_buffer_ops_private
{
412 struct lttng_ust_channel_buffer_ops
*pub
; /* Public channel buffer ops interface */
414 struct lttng_ust_channel_buffer
*(*channel_create
)(const char *name
,
416 size_t subbuf_size
, size_t num_subbuf
,
417 unsigned int switch_timer_interval
,
418 unsigned int read_timer_interval
,
421 const int *stream_fds
, int nr_stream_fds
,
422 int64_t blocking_timeout
);
423 void (*channel_destroy
)(struct lttng_ust_channel_buffer
*chan
);
425 * packet_avail_size returns the available size in the current
426 * packet. Note that the size returned is only a hint, since it
427 * may change due to concurrent writes.
429 size_t (*packet_avail_size
)(struct lttng_ust_channel_buffer
*chan
);
430 int (*is_finalized
)(struct lttng_ust_channel_buffer
*chan
);
431 int (*is_disabled
)(struct lttng_ust_channel_buffer
*chan
);
432 int (*flush_buffer
)(struct lttng_ust_channel_buffer
*chan
);
435 struct lttng_ust_channel_common_private
{
436 struct lttng_ust_channel_common
*pub
; /* Public channel interface */
438 int objd
; /* Object associated with channel. */
439 unsigned int tstate
:1; /* Transient enable state */
443 struct lttng_ust_channel_buffer_private
{
444 struct lttng_ust_channel_common_private parent
;
446 struct lttng_ust_channel_buffer
*pub
; /* Public channel buffer interface */
447 struct cds_list_head node
; /* Channel list in session */
448 int header_type
; /* 0: unset, 1: compact, 2: large */
449 unsigned int id
; /* Channel ID */
450 enum lttng_ust_abi_chan_type type
;
451 struct lttng_ust_ctx
*ctx
;
452 struct lttng_ust_ring_buffer_channel
*rb_chan
; /* Ring buffer channel */
453 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
456 struct lttng_ust_channel_counter_ops_private
{
457 struct lttng_ust_channel_counter_ops
*pub
; /* Public channel counter ops interface */
459 struct lttng_ust_channel_counter
*(*counter_create
)(size_t nr_dimensions
,
460 const struct lttng_counter_dimension
*dimensions
,
461 int64_t global_sum_step
,
462 int global_counter_fd
,
463 int nr_counter_cpu_fds
,
464 const int *counter_cpu_fds
,
466 void (*counter_destroy
)(struct lttng_ust_channel_counter
*counter
);
467 int (*counter_add
)(struct lttng_ust_channel_counter
*counter
,
468 const size_t *dimension_indexes
, int64_t v
);
469 int (*counter_read
)(struct lttng_ust_channel_counter
*counter
,
470 const size_t *dimension_indexes
, int cpu
,
471 int64_t *value
, bool *overflow
, bool *underflow
);
472 int (*counter_aggregate
)(struct lttng_ust_channel_counter
*counter
,
473 const size_t *dimension_indexes
, int64_t *value
,
474 bool *overflow
, bool *underflow
);
475 int (*counter_clear
)(struct lttng_ust_channel_counter
*counter
,
476 const size_t *dimension_indexes
);
479 struct lttng_ust_channel_counter_private
{
480 struct lttng_ust_channel_common_private parent
;
482 struct lttng_ust_channel_counter
*pub
; /* Public channel counter interface */
483 struct lib_counter
*counter
;
484 struct lttng_ust_channel_counter_ops
*ops
;
486 /* Event notifier group owner. */
487 struct lttng_event_notifier_group
*event_notifier_group
;
490 struct lttng_session
*session
;
491 struct cds_list_head node
; /* Counter list (in session) */
492 size_t free_index
; /* Next index to allocate */
493 enum lttng_key_type dimension_key_types
[LTTNG_COUNTER_DIMENSION_MAX
];
497 * IMPORTANT: this structure is part of the ABI between the consumer
498 * daemon and the UST library within traced applications. Changing it
499 * breaks the UST communication protocol.
501 * TODO: remove unused fields on next UST communication protocol
504 struct lttng_ust_abi_channel_config
{
510 unsigned int _deprecated1
;
511 unsigned int _deprecated2
;
512 struct cds_list_head unused6
;
516 unsigned int _deprecated3
:1;
520 enum lttng_ust_abi_chan_type unused10
;
521 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
525 /* Global (filter), event and channel contexts. */
526 struct lttng_ust_ctx
{
527 struct lttng_ust_ctx_field
*fields
;
528 unsigned int nr_fields
;
529 unsigned int allocated_fields
;
530 unsigned int largest_align
;
533 struct lttng_ust_registered_probe
{
534 const struct lttng_ust_probe_desc
*desc
;
536 struct cds_list_head head
; /* chain registered probes */
537 struct cds_list_head lazy_init_head
;
538 int lazy
; /* lazy registration */
545 struct lttng_ust_ctx_field
{
546 const struct lttng_ust_event_field
*event_field
;
547 size_t (*get_size
)(void *priv
, struct lttng_ust_probe_ctx
*probe_ctx
,
549 void (*record
)(void *priv
, struct lttng_ust_probe_ctx
*probe_ctx
,
550 struct lttng_ust_ring_buffer_ctx
*ctx
,
551 struct lttng_ust_channel_buffer
*chan
);
552 void (*get_value
)(void *priv
, struct lttng_ust_probe_ctx
*probe_ctx
,
553 struct lttng_ust_ctx_value
*value
);
554 void (*destroy
)(void *priv
);
559 const struct lttng_ust_type_integer
*lttng_ust_get_type_integer(const struct lttng_ust_type_common
*type
)
561 if (type
->type
!= lttng_ust_type_integer
)
563 return caa_container_of(type
, const struct lttng_ust_type_integer
, parent
);
567 const struct lttng_ust_type_float
*lttng_ust_get_type_float(const struct lttng_ust_type_common
*type
)
569 if (type
->type
!= lttng_ust_type_float
)
571 return caa_container_of(type
, const struct lttng_ust_type_float
, parent
);
575 const struct lttng_ust_type_string
*lttng_ust_get_type_string(const struct lttng_ust_type_common
*type
)
577 if (type
->type
!= lttng_ust_type_string
)
579 return caa_container_of(type
, const struct lttng_ust_type_string
, parent
);
583 const struct lttng_ust_type_enum
*lttng_ust_get_type_enum(const struct lttng_ust_type_common
*type
)
585 if (type
->type
!= lttng_ust_type_enum
)
587 return caa_container_of(type
, const struct lttng_ust_type_enum
, parent
);
591 const struct lttng_ust_type_array
*lttng_ust_get_type_array(const struct lttng_ust_type_common
*type
)
593 if (type
->type
!= lttng_ust_type_array
)
595 return caa_container_of(type
, const struct lttng_ust_type_array
, parent
);
599 const struct lttng_ust_type_sequence
*lttng_ust_get_type_sequence(const struct lttng_ust_type_common
*type
)
601 if (type
->type
!= lttng_ust_type_sequence
)
603 return caa_container_of(type
, const struct lttng_ust_type_sequence
, parent
);
607 const struct lttng_ust_type_struct
*lttng_ust_get_type_struct(const struct lttng_ust_type_common
*type
)
609 if (type
->type
!= lttng_ust_type_struct
)
611 return caa_container_of(type
, const struct lttng_ust_type_struct
, parent
);
614 #define lttng_ust_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
615 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_integer, { \
617 .type = lttng_ust_type_integer, \
619 .struct_size = sizeof(struct lttng_ust_type_integer), \
621 .alignment = (_alignment), \
622 .signedness = (_signedness), \
623 .reverse_byte_order = (_byte_order) != LTTNG_UST_BYTE_ORDER, \
627 #define lttng_ust_static_type_array_text(_length) \
628 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
630 .type = lttng_ust_type_array, \
632 .struct_size = sizeof(struct lttng_ust_type_array), \
633 .length = (_length), \
635 .encoding = lttng_ust_string_encoding_UTF8, \
636 .elem_type = lttng_ust_static_type_integer(sizeof(char) * CHAR_BIT, \
637 lttng_ust_rb_alignof(char) * CHAR_BIT, lttng_ust_is_signed_type(char), \
638 LTTNG_UST_BYTE_ORDER, 10), \
641 #define lttng_ust_static_event_field(_name, _type, _nowrite, _nofilter) \
642 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
643 .struct_size = sizeof(struct lttng_ust_event_field), \
646 .nowrite = (_nowrite), \
647 .nofilter = (_nofilter), \
650 #define lttng_ust_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
651 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_ctx_field, { \
652 .event_field = (_event_field), \
653 .get_size = (_get_size), \
654 .record = (_record), \
655 .get_value = (_get_value), \
656 .destroy = (_destroy), \
661 struct lttng_event_enabler_common
*lttng_event_notifier_enabler_as_enabler(
662 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
664 return &event_notifier_enabler
->parent
;
668 struct lttng_ust_event_ht
*lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common
*event_enabler
)
670 switch (event_enabler
->enabler_type
) {
671 case LTTNG_EVENT_ENABLER_TYPE_RECORDER
: /* Fall-through */
672 case LTTNG_EVENT_ENABLER_TYPE_COUNTER
:
674 struct lttng_event_enabler_session_common
*event_enabler_session
=
675 caa_container_of(event_enabler
, struct lttng_event_enabler_session_common
, parent
);
676 return &event_enabler_session
->chan
->session
->priv
->events_name_ht
;
678 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER
:
680 struct lttng_event_notifier_enabler
*event_notifier_enabler
=
681 caa_container_of(event_enabler
, struct lttng_event_notifier_enabler
, parent
);
682 return &event_notifier_enabler
->group
->event_notifiers_ht
;
690 struct cds_list_head
*lttng_get_event_list_head_from_enabler(struct lttng_event_enabler_common
*event_enabler
)
692 switch (event_enabler
->enabler_type
) {
693 case LTTNG_EVENT_ENABLER_TYPE_RECORDER
: /* Fall-through */
694 case LTTNG_EVENT_ENABLER_TYPE_COUNTER
:
696 struct lttng_event_enabler_session_common
*event_enabler_session
=
697 caa_container_of(event_enabler
, struct lttng_event_enabler_session_common
, parent
);
698 return &event_enabler_session
->chan
->session
->priv
->events_head
;
700 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER
:
702 struct lttng_event_notifier_enabler
*event_notifier_enabler
=
703 caa_container_of(event_enabler
, struct lttng_event_notifier_enabler
, parent
);
704 return &event_notifier_enabler
->group
->event_notifiers_head
;
711 /* This is ABI between liblttng-ust and liblttng-ust-dl */
712 void lttng_ust_dl_update(void *ip
);
714 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_ust_session
*session
,
715 const struct lttng_ust_enum_desc
*enum_desc
)
716 __attribute__((visibility("hidden")));
719 #endif /* _UST_COMMON_UST_EVENTS_H */