2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
9 #ifndef _LTTNG_UST_EVENTS_H
10 #define _LTTNG_UST_EVENTS_H
12 #include <urcu/list.h>
13 #include <urcu/hlist.h>
16 #include <lttng/ust-abi.h>
17 #include <lttng/ust-tracer.h>
18 #include <lttng/ust-endian.h>
25 #error "LTTNG_PACKED should be defined"
32 #define LTTNG_UST_UUID_LEN 16
35 * Tracepoint provider version. Compatibility based on the major number.
36 * Older tracepoint providers can always register to newer lttng-ust
37 * library, but the opposite is rejected: a newer tracepoint provider is
38 * rejected by an older lttng-ust library.
40 #define LTTNG_UST_PROVIDER_MAJOR 2
41 #define LTTNG_UST_PROVIDER_MINOR 0
45 struct lttng_ust_lib_ring_buffer_ctx
;
46 struct lttng_event_field
;
47 struct lttng_event_notifier
;
48 struct lttng_event_notifier_group
;
51 * Data structures used by tracepoint event declarations, and by the
52 * tracer. Those structures have padding for future extension.
55 /* Type description */
57 /* Update the astract_types name table in lttng-types.c along with this enum */
58 enum lttng_abstract_types
{
60 atype_enum
, /* legacy */
61 atype_array
, /* legacy */
62 atype_sequence
, /* legacy */
66 atype_struct
, /* legacy */
69 atype_sequence_nestable
,
70 atype_struct_nestable
,
74 /* Update the string_encodings name table in lttng-types.c along with this enum */
75 enum lttng_string_encodings
{
76 lttng_encode_none
= 0,
77 lttng_encode_UTF8
= 1,
78 lttng_encode_ASCII
= 2,
82 struct lttng_enum_value
{
83 unsigned long long value
;
84 unsigned int signedness
:1;
87 enum lttng_enum_entry_options
{
88 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
91 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
92 struct lttng_enum_entry
{
93 struct lttng_enum_value start
, end
; /* start and end are inclusive */
99 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
103 #define __type_integer(_type, _byte_order, _base, _encoding) \
105 .atype = atype_integer, \
110 .size = sizeof(_type) * CHAR_BIT, \
111 .alignment = lttng_alignof(_type) * CHAR_BIT, \
112 .signedness = lttng_is_signed_type(_type), \
113 .reverse_byte_order = _byte_order != BYTE_ORDER, \
115 .encoding = lttng_encode_##_encoding, \
120 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
121 struct lttng_integer_type
{
122 unsigned int size
; /* in bits */
123 unsigned short alignment
; /* in bits */
124 unsigned int signedness
:1;
125 unsigned int reverse_byte_order
:1;
126 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
127 enum lttng_string_encodings encoding
;
128 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
132 * Only float and double are supported. long double is not supported at
135 #define _float_mant_dig(_type) \
136 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
137 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
140 #define __type_float(_type) \
142 .atype = atype_float, \
147 .exp_dig = sizeof(_type) * CHAR_BIT \
148 - _float_mant_dig(_type), \
149 .mant_dig = _float_mant_dig(_type), \
150 .alignment = lttng_alignof(_type) * CHAR_BIT, \
151 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
156 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
157 struct lttng_float_type
{
158 unsigned int exp_dig
; /* exponent digits, in bits */
159 unsigned int mant_dig
; /* mantissa digits, in bits */
160 unsigned short alignment
; /* in bits */
161 unsigned int reverse_byte_order
:1;
162 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
166 #define LTTNG_UST_BASIC_TYPE_PADDING 128
167 union _lttng_basic_type
{
168 struct lttng_integer_type integer
; /* legacy */
170 const struct lttng_enum_desc
*desc
; /* Enumeration mapping */
171 struct lttng_integer_type container_type
;
172 } enumeration
; /* legacy */
174 enum lttng_string_encodings encoding
;
175 } string
; /* legacy */
176 struct lttng_float_type _float
; /* legacy */
177 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
181 struct lttng_basic_type
{
182 enum lttng_abstract_types atype
;
184 union _lttng_basic_type basic
;
188 #define LTTNG_UST_TYPE_PADDING 128
190 enum lttng_abstract_types atype
;
192 /* provider ABI 2.0 */
193 struct lttng_integer_type integer
;
194 struct lttng_float_type _float
;
196 enum lttng_string_encodings encoding
;
199 const struct lttng_enum_desc
*desc
; /* Enumeration mapping */
200 struct lttng_type
*container_type
;
203 const struct lttng_type
*elem_type
;
204 unsigned int length
; /* Num. elems. */
205 unsigned int alignment
;
208 const char *length_name
; /* Length field name. */
209 const struct lttng_type
*elem_type
;
210 unsigned int alignment
; /* Alignment before elements. */
213 unsigned int nr_fields
;
214 const struct lttng_event_field
*fields
; /* Array of fields. */
215 unsigned int alignment
;
219 /* legacy provider ABI 1.0 */
220 union _lttng_basic_type basic
; /* legacy */
222 struct lttng_basic_type elem_type
;
223 unsigned int length
; /* Num. elems. */
224 } array
; /* legacy */
226 struct lttng_basic_type length_type
;
227 struct lttng_basic_type elem_type
;
228 } sequence
; /* legacy */
230 unsigned int nr_fields
;
231 struct lttng_event_field
*fields
; /* Array of fields. */
232 } _struct
; /* legacy */
234 char padding
[LTTNG_UST_TYPE_PADDING
];
238 #define LTTNG_UST_ENUM_TYPE_PADDING 24
239 struct lttng_enum_desc
{
241 const struct lttng_enum_entry
*entries
;
242 unsigned int nr_entries
;
243 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
247 * Event field description
249 * IMPORTANT: this structure is part of the ABI between the probe and
250 * UST. Fields need to be only added at the end, never reordered, never
254 #define LTTNG_UST_EVENT_FIELD_PADDING 28
255 struct lttng_event_field
{
257 struct lttng_type type
;
258 unsigned int nowrite
; /* do not write into trace */
261 unsigned int nofilter
:1; /* do not consider for filter */
263 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
267 enum lttng_ust_dynamic_type
{
268 LTTNG_UST_DYNAMIC_TYPE_NONE
,
269 LTTNG_UST_DYNAMIC_TYPE_S8
,
270 LTTNG_UST_DYNAMIC_TYPE_S16
,
271 LTTNG_UST_DYNAMIC_TYPE_S32
,
272 LTTNG_UST_DYNAMIC_TYPE_S64
,
273 LTTNG_UST_DYNAMIC_TYPE_U8
,
274 LTTNG_UST_DYNAMIC_TYPE_U16
,
275 LTTNG_UST_DYNAMIC_TYPE_U32
,
276 LTTNG_UST_DYNAMIC_TYPE_U64
,
277 LTTNG_UST_DYNAMIC_TYPE_FLOAT
,
278 LTTNG_UST_DYNAMIC_TYPE_DOUBLE
,
279 LTTNG_UST_DYNAMIC_TYPE_STRING
,
280 _NR_LTTNG_UST_DYNAMIC_TYPES
,
283 struct lttng_ctx_value
{
284 enum lttng_ust_dynamic_type sel
;
293 struct lttng_perf_counter_field
;
295 #define LTTNG_UST_CTX_FIELD_PADDING 40
296 struct lttng_ctx_field
{
297 struct lttng_event_field event_field
;
298 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
);
299 void (*record
)(struct lttng_ctx_field
*field
,
300 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
301 struct lttng_channel
*chan
);
302 void (*get_value
)(struct lttng_ctx_field
*field
,
303 struct lttng_ctx_value
*value
);
305 struct lttng_perf_counter_field
*perf_counter
;
306 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
308 void (*destroy
)(struct lttng_ctx_field
*field
);
309 char *field_name
; /* Has ownership, dynamically allocated. */
312 #define LTTNG_UST_CTX_PADDING 20
314 struct lttng_ctx_field
*fields
;
315 unsigned int nr_fields
;
316 unsigned int allocated_fields
;
317 unsigned int largest_align
;
318 char padding
[LTTNG_UST_CTX_PADDING
];
321 #define LTTNG_UST_EVENT_DESC_PADDING 40
322 struct lttng_event_desc
{
324 void (*probe_callback
)(void);
325 const struct lttng_event_ctx
*ctx
; /* context */
326 const struct lttng_event_field
*fields
; /* event payload */
327 unsigned int nr_fields
;
328 const int **loglevel
;
329 const char *signature
; /* Argument types/names received */
332 const char **model_emf_uri
;
333 void (*event_notifier_callback
)(void);
335 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
339 #define LTTNG_UST_PROBE_DESC_PADDING 12
340 struct lttng_probe_desc
{
341 const char *provider
;
342 const struct lttng_event_desc
**event_desc
;
343 unsigned int nr_events
;
344 struct cds_list_head head
; /* chain registered probes */
345 struct cds_list_head lazy_init_head
;
346 int lazy
; /* lazy registration */
349 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
352 /* Data structures used by the tracer. */
355 * Bytecode interpreter return value masks.
357 enum lttng_bytecode_interpreter_ret
{
358 LTTNG_INTERPRETER_DISCARD
= 0,
359 LTTNG_INTERPRETER_RECORD_FLAG
= (1ULL << 0),
360 /* Other bits are kept for future use. */
363 struct lttng_interpreter_output
;
366 * This structure is used in the probes. More specifically, the `filter` and
367 * `node` fields are explicity used in the probes. When modifying this
368 * structure we must not change the layout of these two fields as it is
371 struct lttng_bytecode_runtime
{
372 /* Associated bytecode */
373 struct lttng_ust_bytecode_node
*bc
;
375 uint64_t (*filter
)(void *interpreter_data
,
376 const char *interpreter_stack_data
);
377 uint64_t (*capture
)(void *interpreter_data
,
378 const char *interpreter_stack_data
,
379 struct lttng_interpreter_output
*interpreter_output
);
382 struct cds_list_head node
; /* list of bytecode runtime in event */
384 * Pointer to a URCU-protected pointer owned by an `struct
385 * lttng_session`or `struct lttng_event_notifier_group`.
387 struct lttng_ctx
**pctx
;
391 * lttng_event structure is referred to by the tracing fast path. It
392 * must be kept small.
394 * IMPORTANT: this structure is part of the ABI between the probe and
395 * UST. Fields need to be only added at the end, never reordered, never
399 struct lttng_ust_event_private
;
402 struct lttng_ust_event_private
*priv
; /* Private event interface */
406 int has_enablers_without_bytecode
;
407 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
408 struct cds_list_head filter_bytecode_runtime_head
;
409 struct lttng_channel
*chan
;
410 struct lttng_ctx
*ctx
;
413 struct lttng_event_notifier
{
415 uint64_t error_counter_index
;
417 int registered
; /* has reg'd tracepoint probe */
418 size_t num_captures
; /* Needed to allocate the msgpack array. */
419 void (*notification_send
)(struct lttng_event_notifier
*event_notifier
,
420 const char *stack_data
);
421 struct cds_list_head filter_bytecode_runtime_head
;
422 struct cds_list_head capture_bytecode_runtime_head
;
423 int has_enablers_without_bytecode
;
424 struct cds_list_head enablers_ref_head
;
425 const struct lttng_event_desc
*desc
;
426 struct cds_hlist_node hlist
; /* hashtable of event_notifiers */
427 struct cds_list_head node
; /* event_notifier list in session */
428 struct lttng_event_notifier_group
*group
; /* weak ref */
432 const struct lttng_enum_desc
*desc
;
433 struct lttng_session
*session
;
434 struct cds_list_head node
; /* Enum list in session */
435 struct cds_hlist_node hlist
; /* Session ht of enums */
436 uint64_t id
; /* Enumeration ID in sessiond */
440 struct lttng_ust_shm_handle
;
443 * IMPORTANT: this structure is part of the ABI between the probe and
444 * UST. Fields need to be only added at the end, never reordered, never
447 struct lttng_channel_ops
{
448 struct lttng_channel
*(*channel_create
)(const char *name
,
450 size_t subbuf_size
, size_t num_subbuf
,
451 unsigned int switch_timer_interval
,
452 unsigned int read_timer_interval
,
455 const int *stream_fds
, int nr_stream_fds
,
456 int64_t blocking_timeout
);
457 void (*channel_destroy
)(struct lttng_channel
*chan
);
458 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
460 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
461 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
462 const void *src
, size_t len
);
464 * packet_avail_size returns the available size in the current
465 * packet. Note that the size returned is only a hint, since it
466 * may change due to concurrent writes.
468 size_t (*packet_avail_size
)(struct channel
*chan
,
469 struct lttng_ust_shm_handle
*handle
);
470 int (*is_finalized
)(struct channel
*chan
);
471 int (*is_disabled
)(struct channel
*chan
);
472 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
473 void (*event_strcpy
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
474 const char *src
, size_t len
);
478 * IMPORTANT: this structure is part of the ABI between the probe and
479 * UST. Fields need to be only added at the end, never reordered, never
482 struct lttng_channel
{
484 * The pointers located in this private data are NOT safe to be
485 * dereferenced by the consumer. The only operations the
486 * consumer process is designed to be allowed to do is to read
487 * and perform subbuffer flush.
489 struct channel
*chan
; /* Channel buffers */
491 struct lttng_ctx
*ctx
;
492 /* Event ID management */
493 struct lttng_session
*session
;
494 int objd
; /* Object associated to channel */
495 struct cds_list_head node
; /* Channel list in session */
496 const struct lttng_channel_ops
*ops
;
497 int header_type
; /* 0: unset, 1: compact, 2: large */
498 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
502 enum lttng_ust_chan_type type
;
503 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
504 int tstate
:1; /* Transient enable state */
507 struct lttng_counter_dimension
;
509 struct lttng_counter_ops
{
510 struct lib_counter
*(*counter_create
)(size_t nr_dimensions
,
511 const struct lttng_counter_dimension
*dimensions
,
512 int64_t global_sum_step
,
513 int global_counter_fd
,
514 int nr_counter_cpu_fds
,
515 const int *counter_cpu_fds
,
517 void (*counter_destroy
)(struct lib_counter
*counter
);
518 int (*counter_add
)(struct lib_counter
*counter
,
519 const size_t *dimension_indexes
, int64_t v
);
520 int (*counter_read
)(struct lib_counter
*counter
,
521 const size_t *dimension_indexes
, int cpu
,
522 int64_t *value
, bool *overflow
, bool *underflow
);
523 int (*counter_aggregate
)(struct lib_counter
*counter
,
524 const size_t *dimension_indexes
, int64_t *value
,
525 bool *overflow
, bool *underflow
);
526 int (*counter_clear
)(struct lib_counter
*counter
, const size_t *dimension_indexes
);
529 #define LTTNG_UST_STACK_CTX_PADDING 32
530 struct lttng_stack_ctx
{
531 struct lttng_event
*event
;
532 struct lttng_ctx
*chan_ctx
; /* RCU dereferenced. */
533 struct lttng_ctx
*event_ctx
; /* RCU dereferenced. */
534 char padding
[LTTNG_UST_STACK_CTX_PADDING
];
537 #define LTTNG_UST_EVENT_HT_BITS 12
538 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
540 struct lttng_ust_event_ht
{
541 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
544 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
545 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
546 struct lttng_ust_event_notifier_ht
{
547 struct cds_hlist_head table
[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
];
550 #define LTTNG_UST_ENUM_HT_BITS 12
551 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
553 struct lttng_ust_enum_ht
{
554 struct cds_hlist_head table
[LTTNG_UST_ENUM_HT_SIZE
];
558 * IMPORTANT: this structure is part of the ABI between the probe and
559 * UST. Fields need to be only added at the end, never reordered, never
562 struct lttng_session
{
563 int active
; /* Is trace session active ? */
564 int been_active
; /* Been active ? */
565 int objd
; /* Object associated */
566 struct cds_list_head chan_head
; /* Channel list head */
567 struct cds_list_head events_head
; /* list of events */
568 struct cds_list_head node
; /* Session list */
571 /* List of enablers */
572 struct cds_list_head enablers_head
;
573 struct lttng_ust_event_ht events_ht
; /* ht of events */
574 void *owner
; /* object owner */
575 int tstate
:1; /* Transient enable state */
578 int statedump_pending
:1;
581 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
582 struct cds_list_head enums_head
;
583 struct lttng_ctx
*ctx
; /* contexts for filters. */
586 int lttng_probe_register(struct lttng_probe_desc
*desc
);
587 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
590 * Can be used by applications that change their procname to clear the ust cached value.
592 void lttng_context_procname_reset(void);
594 struct lttng_transport
*lttng_transport_find(const char *name
);
596 int lttng_session_active(void);
598 void lttng_ust_dl_update(void *ip
);
604 #endif /* _LTTNG_UST_EVENTS_H */