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-config.h>
17 #include <lttng/ust-events.h>
19 #include "common/macros.h"
20 #include "common/ust-context-provider.h"
23 * The context procname length is part of the LTTng-UST ABI.
24 * TODO: At the next breaking protocol bump, all users of this macro
25 * should instead use LTTNG_UST_ABI_PROCNAME_LEN.
27 #define LTTNG_UST_CONTEXT_PROCNAME_LEN 17
29 struct lttng_ust_abi_obj
;
30 struct lttng_event_notifier_group
;
32 union lttng_ust_abi_args
{
42 struct lttng_ust_abi_field_iter entry
;
48 int event_notifier_notif_fd
;
49 } event_notifier_handle
;
58 struct lttng_ust_abi_objd_ops
{
59 long (*cmd
)(int objd
, unsigned int cmd
, unsigned long arg
,
60 union lttng_ust_abi_args
*args
, void *owner
);
61 int (*release
)(int objd
);
64 enum lttng_enabler_format_type
{
65 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
66 LTTNG_ENABLER_FORMAT_EVENT
,
70 * Enabler field, within whatever object is enabling an event. Target of
73 struct lttng_enabler
{
74 enum lttng_enabler_format_type format_type
;
76 /* head list of struct lttng_ust_filter_bytecode_node */
77 struct cds_list_head filter_bytecode_head
;
78 /* head list of struct lttng_ust_excluder_node */
79 struct cds_list_head excluder_head
;
81 struct lttng_ust_abi_event event_param
;
82 unsigned int enabled
:1;
85 struct lttng_event_enabler
{
86 struct lttng_enabler base
;
87 struct cds_list_head node
; /* per-session list of enablers */
88 struct lttng_ust_channel_buffer
*chan
;
90 * Unused, but kept around to make it explicit that the tracer can do
93 struct lttng_ust_ctx
*ctx
;
96 struct lttng_event_notifier_enabler
{
97 struct lttng_enabler base
;
98 uint64_t error_counter_index
;
99 struct cds_list_head node
; /* per-app list of event_notifier enablers */
100 struct cds_list_head capture_bytecode_head
;
101 struct lttng_event_notifier_group
*group
; /* weak ref */
102 uint64_t user_token
; /* User-provided token */
103 uint64_t num_captures
;
106 enum lttng_ust_bytecode_type
{
107 LTTNG_UST_BYTECODE_TYPE_FILTER
,
108 LTTNG_UST_BYTECODE_TYPE_CAPTURE
,
111 struct lttng_ust_bytecode_node
{
112 enum lttng_ust_bytecode_type type
;
113 struct cds_list_head node
;
114 struct lttng_enabler
*enabler
;
117 uint32_t reloc_offset
;
124 * Bytecode interpreter return value.
126 enum lttng_ust_bytecode_interpreter_ret
{
127 LTTNG_UST_BYTECODE_INTERPRETER_ERROR
= -1,
128 LTTNG_UST_BYTECODE_INTERPRETER_OK
= 0,
131 struct lttng_interpreter_output
;
132 struct lttng_ust_bytecode_runtime_private
;
134 enum lttng_ust_bytecode_filter_result
{
135 LTTNG_UST_BYTECODE_FILTER_ACCEPT
= 0,
136 LTTNG_UST_BYTECODE_FILTER_REJECT
= 1,
139 struct lttng_ust_bytecode_filter_ctx
{
140 enum lttng_ust_bytecode_filter_result result
;
143 struct lttng_ust_excluder_node
{
144 struct cds_list_head node
;
145 struct lttng_enabler
*enabler
;
147 * struct lttng_ust_event_exclusion had variable sized array,
148 * must be last field.
150 struct lttng_ust_abi_event_exclusion excluder
;
153 /* Data structures used by the tracer. */
155 struct tp_list_entry
{
156 struct lttng_ust_abi_tracepoint_iter tp
;
157 struct cds_list_head head
;
160 struct lttng_ust_tracepoint_list
{
161 struct tp_list_entry
*iter
;
162 struct cds_list_head head
;
165 struct tp_field_list_entry
{
166 struct lttng_ust_abi_field_iter field
;
167 struct cds_list_head head
;
170 struct lttng_ust_field_list
{
171 struct tp_field_list_entry
*iter
;
172 struct cds_list_head head
;
176 * Objects in a linked-list of enablers, owned by an event or event_notifier.
177 * This is used because an event (or a event_notifier) can be enabled by more
178 * than one enabler and we want a quick way to iterate over all enablers of an
181 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
182 * event with the name "my_app:abc".
184 struct lttng_enabler_ref
{
185 struct cds_list_head node
; /* enabler ref list */
186 struct lttng_enabler
*ref
; /* backward ref */
189 #define LTTNG_COUNTER_DIMENSION_MAX 8
190 struct lttng_counter_dimension
{
192 uint64_t underflow_index
;
193 uint64_t overflow_index
;
194 uint8_t has_underflow
;
195 uint8_t has_overflow
;
198 struct lttng_counter_ops
{
199 struct lib_counter
*(*counter_create
)(size_t nr_dimensions
,
200 const struct lttng_counter_dimension
*dimensions
,
201 int64_t global_sum_step
,
202 int global_counter_fd
,
203 int nr_counter_cpu_fds
,
204 const int *counter_cpu_fds
,
206 void (*counter_destroy
)(struct lib_counter
*counter
);
207 int (*counter_add
)(struct lib_counter
*counter
,
208 const size_t *dimension_indexes
, int64_t v
);
209 int (*counter_read
)(struct lib_counter
*counter
,
210 const size_t *dimension_indexes
, int cpu
,
211 int64_t *value
, bool *overflow
, bool *underflow
);
212 int (*counter_aggregate
)(struct lib_counter
*counter
,
213 const size_t *dimension_indexes
, int64_t *value
,
214 bool *overflow
, bool *underflow
);
215 int (*counter_clear
)(struct lib_counter
*counter
, const size_t *dimension_indexes
);
218 struct lttng_counter
{
220 struct lttng_event_notifier_group
*event_notifier_group
; /* owner */
221 struct lttng_counter_transport
*transport
;
222 struct lib_counter
*counter
;
223 struct lttng_counter_ops
*ops
;
226 #define LTTNG_UST_EVENT_HT_BITS 12
227 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
229 struct lttng_ust_event_ht
{
230 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
233 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
234 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
235 struct lttng_ust_event_notifier_ht
{
236 struct cds_hlist_head table
[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
];
239 #define LTTNG_UST_ENUM_HT_BITS 12
240 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
242 struct lttng_ust_enum_ht
{
243 struct cds_hlist_head table
[LTTNG_UST_ENUM_HT_SIZE
];
246 struct lttng_event_notifier_group
{
250 struct cds_list_head node
; /* Event notifier group handle list */
251 struct cds_list_head enablers_head
;
252 struct cds_list_head event_notifiers_head
; /* list of event_notifiers */
253 struct lttng_ust_event_notifier_ht event_notifiers_ht
; /* hashtable of event_notifiers */
254 struct lttng_ust_ctx
*ctx
; /* contexts for filters. */
256 struct lttng_counter
*error_counter
;
257 size_t error_counter_len
;
260 struct lttng_transport
{
262 struct cds_list_head node
;
263 struct lttng_ust_channel_buffer_ops ops
;
264 const struct lttng_ust_ring_buffer_config
*client_config
;
267 struct lttng_counter_transport
{
269 struct cds_list_head node
;
270 struct lttng_counter_ops ops
;
271 const struct lib_counter_config
*client_config
;
274 struct lttng_ust_event_common_private
{
275 struct lttng_ust_event_common
*pub
; /* Public event interface */
277 const struct lttng_ust_event_desc
*desc
;
278 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
279 struct cds_list_head enablers_ref_head
;
280 int registered
; /* has reg'd tracepoint probe */
283 int has_enablers_without_filter_bytecode
;
284 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
285 struct cds_list_head filter_bytecode_runtime_head
;
288 struct lttng_ust_event_recorder_private
{
289 struct lttng_ust_event_common_private parent
;
291 struct lttng_ust_event_recorder
*pub
; /* Public event interface */
292 struct cds_list_head node
; /* Event recorder list */
293 struct cds_hlist_node hlist
; /* Hash table of event recorders */
294 struct lttng_ust_ctx
*ctx
;
298 struct lttng_ust_event_notifier_private
{
299 struct lttng_ust_event_common_private parent
;
301 struct lttng_ust_event_notifier
*pub
; /* Public event notifier interface */
302 struct lttng_event_notifier_group
*group
; /* weak ref */
303 size_t num_captures
; /* Needed to allocate the msgpack array. */
304 uint64_t error_counter_index
;
305 struct cds_list_head node
; /* Event notifier list */
306 struct cds_hlist_node hlist
; /* Hash table of event notifiers */
307 struct cds_list_head capture_bytecode_runtime_head
;
310 struct lttng_ust_bytecode_runtime
{
311 enum lttng_ust_bytecode_type type
;
312 struct lttng_ust_bytecode_node
*bc
;
314 int (*interpreter_func
)(struct lttng_ust_bytecode_runtime
*bytecode_runtime
,
315 const char *interpreter_stack_data
,
316 struct lttng_ust_probe_ctx
*probe_ctx
,
318 struct cds_list_head node
; /* list of bytecode runtime in event */
320 * Pointer to a URCU-protected pointer owned by an `struct
321 * lttng_session`or `struct lttng_event_notifier_group`.
323 struct lttng_ust_ctx
**pctx
;
326 struct lttng_ust_session_private
{
327 struct lttng_ust_session
*pub
; /* Public session interface */
329 int been_active
; /* Been active ? */
330 int objd
; /* Object associated */
331 struct cds_list_head chan_head
; /* Channel list head */
332 struct cds_list_head events_head
; /* list of events */
333 struct cds_list_head node
; /* Session list */
335 /* List of enablers */
336 struct cds_list_head enablers_head
;
337 struct lttng_ust_event_ht events_ht
; /* ht of events */
338 void *owner
; /* object owner */
339 int tstate
:1; /* Transient enable state */
341 int statedump_pending
:1;
343 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
344 struct cds_list_head enums_head
;
345 struct lttng_ust_ctx
*ctx
; /* contexts for filters. */
347 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
348 bool uuid_set
; /* Is uuid set ? */
352 const struct lttng_ust_enum_desc
*desc
;
353 struct lttng_ust_session
*session
;
354 struct cds_list_head node
; /* Enum list in session */
355 struct cds_hlist_node hlist
; /* Session ht of enums */
356 uint64_t id
; /* Enumeration ID in sessiond */
359 struct lttng_ust_shm_handle
;
361 struct lttng_ust_channel_buffer_ops_private
{
362 struct lttng_ust_channel_buffer_ops
*pub
; /* Public channel buffer ops interface */
364 struct lttng_ust_channel_buffer
*(*channel_create
)(const char *name
,
366 size_t subbuf_size
, size_t num_subbuf
,
367 unsigned int switch_timer_interval
,
368 unsigned int read_timer_interval
,
371 const int *stream_fds
, int nr_stream_fds
,
372 int64_t blocking_timeout
);
373 void (*channel_destroy
)(struct lttng_ust_channel_buffer
*chan
);
375 * packet_avail_size returns the available size in the current
376 * packet. Note that the size returned is only a hint, since it
377 * may change due to concurrent writes.
379 size_t (*packet_avail_size
)(struct lttng_ust_channel_buffer
*chan
);
380 int (*is_finalized
)(struct lttng_ust_channel_buffer
*chan
);
381 int (*is_disabled
)(struct lttng_ust_channel_buffer
*chan
);
382 int (*flush_buffer
)(struct lttng_ust_channel_buffer
*chan
);
385 struct lttng_ust_channel_common_private
{
386 struct lttng_ust_channel_common
*pub
; /* Public channel interface */
388 int objd
; /* Object associated with channel. */
389 int tstate
:1; /* Transient enable state */
392 struct lttng_ust_channel_buffer_private
{
393 struct lttng_ust_channel_common_private parent
;
395 struct lttng_ust_channel_buffer
*pub
; /* Public channel buffer interface */
396 struct cds_list_head node
; /* Channel list in session */
397 int header_type
; /* 0: unset, 1: compact, 2: large */
398 unsigned int id
; /* Channel ID */
399 enum lttng_ust_abi_chan_type type
;
400 struct lttng_ust_ctx
*ctx
;
401 struct lttng_ust_ring_buffer_channel
*rb_chan
; /* Ring buffer channel */
402 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
406 * IMPORTANT: this structure is part of the ABI between the consumer
407 * daemon and the UST library within traced applications. Changing it
408 * breaks the UST communication protocol.
410 * TODO: remove unused fields on next UST communication protocol
413 struct lttng_ust_abi_channel_config
{
419 unsigned int _deprecated1
;
420 unsigned int _deprecated2
;
421 struct cds_list_head unused6
;
425 unsigned int _deprecated3
:1;
429 enum lttng_ust_abi_chan_type unused10
;
430 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
434 /* Global (filter), event and channel contexts. */
435 struct lttng_ust_ctx
{
436 struct lttng_ust_ctx_field
*fields
;
437 unsigned int nr_fields
;
438 unsigned int allocated_fields
;
439 unsigned int largest_align
;
442 struct lttng_ust_registered_probe
{
443 const struct lttng_ust_probe_desc
*desc
;
445 struct cds_list_head head
; /* chain registered probes */
446 struct cds_list_head lazy_init_head
;
447 int lazy
; /* lazy registration */
454 struct lttng_ust_ctx_field
{
455 const struct lttng_ust_event_field
*event_field
;
456 size_t (*get_size
)(void *priv
, struct lttng_ust_probe_ctx
*probe_ctx
,
458 void (*record
)(void *priv
, struct lttng_ust_probe_ctx
*probe_ctx
,
459 struct lttng_ust_ring_buffer_ctx
*ctx
,
460 struct lttng_ust_channel_buffer
*chan
);
461 void (*get_value
)(void *priv
, struct lttng_ust_probe_ctx
*probe_ctx
,
462 struct lttng_ust_ctx_value
*value
);
463 void (*destroy
)(void *priv
);
468 const struct lttng_ust_type_integer
*lttng_ust_get_type_integer(const struct lttng_ust_type_common
*type
)
470 if (type
->type
!= lttng_ust_type_integer
)
472 return caa_container_of(type
, const struct lttng_ust_type_integer
, parent
);
476 const struct lttng_ust_type_float
*lttng_ust_get_type_float(const struct lttng_ust_type_common
*type
)
478 if (type
->type
!= lttng_ust_type_float
)
480 return caa_container_of(type
, const struct lttng_ust_type_float
, parent
);
484 const struct lttng_ust_type_string
*lttng_ust_get_type_string(const struct lttng_ust_type_common
*type
)
486 if (type
->type
!= lttng_ust_type_string
)
488 return caa_container_of(type
, const struct lttng_ust_type_string
, parent
);
492 const struct lttng_ust_type_enum
*lttng_ust_get_type_enum(const struct lttng_ust_type_common
*type
)
494 if (type
->type
!= lttng_ust_type_enum
)
496 return caa_container_of(type
, const struct lttng_ust_type_enum
, parent
);
500 const struct lttng_ust_type_array
*lttng_ust_get_type_array(const struct lttng_ust_type_common
*type
)
502 if (type
->type
!= lttng_ust_type_array
)
504 return caa_container_of(type
, const struct lttng_ust_type_array
, parent
);
508 const struct lttng_ust_type_sequence
*lttng_ust_get_type_sequence(const struct lttng_ust_type_common
*type
)
510 if (type
->type
!= lttng_ust_type_sequence
)
512 return caa_container_of(type
, const struct lttng_ust_type_sequence
, parent
);
516 const struct lttng_ust_type_struct
*lttng_ust_get_type_struct(const struct lttng_ust_type_common
*type
)
518 if (type
->type
!= lttng_ust_type_struct
)
520 return caa_container_of(type
, const struct lttng_ust_type_struct
, parent
);
523 #define lttng_ust_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
524 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_integer, { \
526 .type = lttng_ust_type_integer, \
528 .struct_size = sizeof(struct lttng_ust_type_integer), \
530 .alignment = (_alignment), \
531 .signedness = (_signedness), \
532 .reverse_byte_order = (_byte_order) != LTTNG_UST_BYTE_ORDER, \
536 #define lttng_ust_static_type_array_text(_length) \
537 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
539 .type = lttng_ust_type_array, \
541 .struct_size = sizeof(struct lttng_ust_type_array), \
542 .length = (_length), \
544 .encoding = lttng_ust_string_encoding_UTF8, \
545 .elem_type = lttng_ust_static_type_integer(sizeof(char) * CHAR_BIT, \
546 lttng_ust_rb_alignof(char) * CHAR_BIT, lttng_ust_is_signed_type(char), \
547 LTTNG_UST_BYTE_ORDER, 10), \
550 #define lttng_ust_static_event_field(_name, _type, _nowrite, _nofilter) \
551 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
552 .struct_size = sizeof(struct lttng_ust_event_field), \
555 .nowrite = (_nowrite), \
556 .nofilter = (_nofilter), \
559 #define lttng_ust_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
560 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_ctx_field, { \
561 .event_field = (_event_field), \
562 .get_size = (_get_size), \
563 .record = (_record), \
564 .get_value = (_get_value), \
565 .destroy = (_destroy), \
570 struct lttng_enabler
*lttng_event_enabler_as_enabler(
571 struct lttng_event_enabler
*event_enabler
)
573 return &event_enabler
->base
;
577 struct lttng_enabler
*lttng_event_notifier_enabler_as_enabler(
578 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
580 return &event_notifier_enabler
->base
;
584 /* Custom upgrade 2.12 to 2.13 */
585 #ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS
586 #define lttng_ust_dl_update lttng_ust_dl_update1
589 /* This is ABI between liblttng-ust and liblttng-ust-dl */
590 void lttng_ust_dl_update(void *ip
);
592 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_ust_session
*session
,
593 const struct lttng_ust_enum_desc
*enum_desc
)
594 __attribute__((visibility("hidden")));
597 #endif /* _UST_COMMON_UST_EVENTS_H */