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_group
;
50 * Data structures used by tracepoint event declarations, and by the
51 * tracer. Those structures have padding for future extension.
54 /* Type description */
56 /* Update the astract_types name table in lttng-types.c along with this enum */
57 enum lttng_abstract_types
{
64 atype_sequence_nestable
,
65 atype_struct_nestable
,
69 /* Update the string_encodings name table in lttng-types.c along with this enum */
70 enum lttng_string_encodings
{
71 lttng_encode_none
= 0,
72 lttng_encode_UTF8
= 1,
73 lttng_encode_ASCII
= 2,
77 struct lttng_enum_value
{
78 unsigned long long value
;
79 unsigned int signedness
:1;
82 enum lttng_enum_entry_options
{
83 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
86 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
87 struct lttng_enum_entry
{
88 struct lttng_enum_value start
, end
; /* start and end are inclusive */
94 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
98 #define __type_integer(_type, _byte_order, _base, _encoding) \
100 .atype = atype_integer, \
105 .size = sizeof(_type) * CHAR_BIT, \
106 .alignment = lttng_alignof(_type) * CHAR_BIT, \
107 .signedness = lttng_is_signed_type(_type), \
108 .reverse_byte_order = _byte_order != BYTE_ORDER, \
110 .encoding = lttng_encode_##_encoding, \
115 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
116 struct lttng_integer_type
{
117 unsigned int size
; /* in bits */
118 unsigned short alignment
; /* in bits */
119 unsigned int signedness
:1;
120 unsigned int reverse_byte_order
:1;
121 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
122 enum lttng_string_encodings encoding
;
123 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
127 * Only float and double are supported. long double is not supported at
130 #define _float_mant_dig(_type) \
131 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
132 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
135 #define __type_float(_type) \
137 .atype = atype_float, \
142 .exp_dig = sizeof(_type) * CHAR_BIT \
143 - _float_mant_dig(_type), \
144 .mant_dig = _float_mant_dig(_type), \
145 .alignment = lttng_alignof(_type) * CHAR_BIT, \
146 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
151 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
152 struct lttng_float_type
{
153 unsigned int exp_dig
; /* exponent digits, in bits */
154 unsigned int mant_dig
; /* mantissa digits, in bits */
155 unsigned short alignment
; /* in bits */
156 unsigned int reverse_byte_order
:1;
157 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
160 #define LTTNG_UST_TYPE_PADDING 128
162 enum lttng_abstract_types atype
;
164 /* provider ABI 2.0 */
165 struct lttng_integer_type integer
;
166 struct lttng_float_type _float
;
168 enum lttng_string_encodings encoding
;
171 const struct lttng_enum_desc
*desc
; /* Enumeration mapping */
172 struct lttng_type
*container_type
;
175 const struct lttng_type
*elem_type
;
176 unsigned int length
; /* Num. elems. */
177 unsigned int alignment
;
180 const char *length_name
; /* Length field name. */
181 const struct lttng_type
*elem_type
;
182 unsigned int alignment
; /* Alignment before elements. */
185 unsigned int nr_fields
;
186 const struct lttng_event_field
*fields
; /* Array of fields. */
187 unsigned int alignment
;
190 char padding
[LTTNG_UST_TYPE_PADDING
];
194 #define LTTNG_UST_ENUM_TYPE_PADDING 24
195 struct lttng_enum_desc
{
197 const struct lttng_enum_entry
*entries
;
198 unsigned int nr_entries
;
199 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
203 * Event field description
205 * IMPORTANT: this structure is part of the ABI between the probe and
206 * UST. Fields need to be only added at the end, never reordered, never
210 #define LTTNG_UST_EVENT_FIELD_PADDING 28
211 struct lttng_event_field
{
213 struct lttng_type type
;
214 unsigned int nowrite
; /* do not write into trace */
217 unsigned int nofilter
:1; /* do not consider for filter */
219 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
223 enum lttng_ust_dynamic_type
{
224 LTTNG_UST_DYNAMIC_TYPE_NONE
,
225 LTTNG_UST_DYNAMIC_TYPE_S8
,
226 LTTNG_UST_DYNAMIC_TYPE_S16
,
227 LTTNG_UST_DYNAMIC_TYPE_S32
,
228 LTTNG_UST_DYNAMIC_TYPE_S64
,
229 LTTNG_UST_DYNAMIC_TYPE_U8
,
230 LTTNG_UST_DYNAMIC_TYPE_U16
,
231 LTTNG_UST_DYNAMIC_TYPE_U32
,
232 LTTNG_UST_DYNAMIC_TYPE_U64
,
233 LTTNG_UST_DYNAMIC_TYPE_FLOAT
,
234 LTTNG_UST_DYNAMIC_TYPE_DOUBLE
,
235 LTTNG_UST_DYNAMIC_TYPE_STRING
,
236 _NR_LTTNG_UST_DYNAMIC_TYPES
,
239 struct lttng_ctx_value
{
240 enum lttng_ust_dynamic_type sel
;
249 struct lttng_perf_counter_field
;
251 #define LTTNG_UST_CTX_FIELD_PADDING 40
252 struct lttng_ctx_field
{
253 struct lttng_event_field event_field
;
254 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
);
255 void (*record
)(struct lttng_ctx_field
*field
,
256 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
257 struct lttng_channel
*chan
);
258 void (*get_value
)(struct lttng_ctx_field
*field
,
259 struct lttng_ctx_value
*value
);
261 struct lttng_perf_counter_field
*perf_counter
;
262 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
264 void (*destroy
)(struct lttng_ctx_field
*field
);
265 char *field_name
; /* Has ownership, dynamically allocated. */
268 #define LTTNG_UST_CTX_PADDING 20
270 struct lttng_ctx_field
*fields
;
271 unsigned int nr_fields
;
272 unsigned int allocated_fields
;
273 unsigned int largest_align
;
274 char padding
[LTTNG_UST_CTX_PADDING
];
277 #define LTTNG_UST_EVENT_DESC_PADDING 40
278 struct lttng_event_desc
{
280 void (*probe_callback
)(void);
281 const struct lttng_event_ctx
*ctx
; /* context */
282 const struct lttng_event_field
*fields
; /* event payload */
283 unsigned int nr_fields
;
284 const int **loglevel
;
285 const char *signature
; /* Argument types/names received */
288 const char **model_emf_uri
;
290 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
294 #define LTTNG_UST_PROBE_DESC_PADDING 12
295 struct lttng_probe_desc
{
296 const char *provider
;
297 const struct lttng_event_desc
**event_desc
;
298 unsigned int nr_events
;
299 struct cds_list_head head
; /* chain registered probes */
300 struct cds_list_head lazy_init_head
;
301 int lazy
; /* lazy registration */
304 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
307 /* Data structures used by the tracer. */
310 * Bytecode interpreter return value masks.
312 enum lttng_bytecode_interpreter_ret
{
313 LTTNG_INTERPRETER_DISCARD
= 0,
314 LTTNG_INTERPRETER_RECORD_FLAG
= (1ULL << 0),
315 /* Other bits are kept for future use. */
318 struct lttng_interpreter_output
;
319 struct lttng_ust_bytecode_runtime_private
;
322 * This structure is used in the probes. More specifically, the
323 * `interpreter_funcs` and `node` fields are explicity used in the
324 * probes. When modifying this structure we must not change the layout
325 * of these two fields as it is considered ABI.
327 struct lttng_bytecode_runtime
{
328 struct lttng_ust_bytecode_runtime_private
*priv
;
330 /* Associated bytecode */
332 uint64_t (*filter
)(void *interpreter_data
,
333 const char *interpreter_stack_data
);
334 uint64_t (*capture
)(void *interpreter_data
,
335 const char *interpreter_stack_data
,
336 struct lttng_interpreter_output
*interpreter_output
);
338 struct cds_list_head node
; /* list of bytecode runtime in event */
342 * lttng_event structure is referred to by the tracing fast path. It
343 * must be kept small.
345 * IMPORTANT: this structure is part of the ABI between the probe and
346 * UST. Fields need to be only added at the end, never reordered, never
350 struct lttng_ust_event_common_private
;
352 enum lttng_ust_event_type
{
353 LTTNG_UST_EVENT_TYPE_RECORDER
= 0,
354 LTTNG_UST_EVENT_TYPE_NOTIFIER
= 1,
358 * IMPORTANT: this structure is part of the ABI between the probe and
359 * UST. Fields need to be only added at the end, never reordered, never
362 * struct lttng_ust_event_common is the common ancestor of the various
363 * public event actions. Inheritance is done by composition: The parent
364 * has a pointer to its child, and the child has a pointer to its
365 * parent. Inheritance of those public structures is done by composition
366 * to ensure both parent and child structures can be extended.
368 * The field @struct_size should be used to determine the size of the
369 * structure. It should be queried before using additional fields added
370 * at the end of the structure.
372 struct lttng_ust_event_common
{
373 uint32_t struct_size
; /* Size of this structure. */
374 struct lttng_ust_event_common_private
*priv
; /* Private event interface */
376 enum lttng_ust_event_type type
;
377 void *child
; /* Pointer to child, for inheritance by aggregation. */
380 int has_enablers_without_bytecode
;
381 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
382 struct cds_list_head filter_bytecode_runtime_head
;
384 /* End of base ABI. Fields below should be used after checking struct_size. */
387 struct lttng_ust_event_recorder_private
;
390 * IMPORTANT: this structure is part of the ABI between the probe and
391 * UST. Fields need to be only added at the end, never reordered, never
394 * struct lttng_ust_event_recorder is the action for recording events
395 * into a ring buffer. It inherits from struct lttng_ust_event_common
396 * by composition to ensure both parent and child structure are
399 * The field @struct_size should be used to determine the size of the
400 * structure. It should be queried before using additional fields added
401 * at the end of the structure.
403 struct lttng_ust_event_recorder
{
404 uint32_t struct_size
; /* Size of this structure. */
405 struct lttng_ust_event_common
*parent
; /* Inheritance by aggregation. */
406 struct lttng_ust_event_recorder_private
*priv
; /* Private event record interface */
409 struct lttng_channel
*chan
;
410 struct lttng_ctx
*ctx
;
412 /* End of base ABI. Fields below should be used after checking struct_size. */
415 struct lttng_ust_event_notifier_private
;
418 * IMPORTANT: this structure is part of the ABI between the probe and
419 * UST. Fields need to be only added at the end, never reordered, never
422 * struct lttng_ust_event_notifier is the action for sending
423 * notifications. It inherits from struct lttng_ust_event_common
424 * by composition to ensure both parent and child structure are
427 * The field @struct_size should be used to determine the size of the
428 * structure. It should be queried before using additional fields added
429 * at the end of the structure.
431 struct lttng_ust_event_notifier
{
432 uint32_t struct_size
; /* Size of this structure. */
433 struct lttng_ust_event_common
*parent
; /* Inheritance by aggregation. */
434 struct lttng_ust_event_notifier_private
*priv
; /* Private event notifier interface */
436 void (*notification_send
)(struct lttng_ust_event_notifier
*event_notifier
,
437 const char *stack_data
);
438 struct cds_list_head capture_bytecode_runtime_head
;
440 /* End of base ABI. Fields below should be used after checking struct_size. */
444 const struct lttng_enum_desc
*desc
;
445 struct lttng_session
*session
;
446 struct cds_list_head node
; /* Enum list in session */
447 struct cds_hlist_node hlist
; /* Session ht of enums */
448 uint64_t id
; /* Enumeration ID in sessiond */
452 struct lttng_ust_shm_handle
;
455 * IMPORTANT: this structure is part of the ABI between the probe and
456 * UST. Fields need to be only added at the end, never reordered, never
459 struct lttng_channel_ops
{
460 struct lttng_channel
*(*channel_create
)(const char *name
,
462 size_t subbuf_size
, size_t num_subbuf
,
463 unsigned int switch_timer_interval
,
464 unsigned int read_timer_interval
,
467 const int *stream_fds
, int nr_stream_fds
,
468 int64_t blocking_timeout
);
469 void (*channel_destroy
)(struct lttng_channel
*chan
);
470 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
472 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
473 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
474 const void *src
, size_t len
);
476 * packet_avail_size returns the available size in the current
477 * packet. Note that the size returned is only a hint, since it
478 * may change due to concurrent writes.
480 size_t (*packet_avail_size
)(struct channel
*chan
,
481 struct lttng_ust_shm_handle
*handle
);
482 int (*is_finalized
)(struct channel
*chan
);
483 int (*is_disabled
)(struct channel
*chan
);
484 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
485 void (*event_strcpy
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
486 const char *src
, size_t len
);
490 * IMPORTANT: this structure is part of the ABI between the probe and
491 * UST. Fields need to be only added at the end, never reordered, never
494 struct lttng_channel
{
496 * The pointers located in this private data are NOT safe to be
497 * dereferenced by the consumer. The only operations the
498 * consumer process is designed to be allowed to do is to read
499 * and perform subbuffer flush.
501 struct channel
*chan
; /* Channel buffers */
503 struct lttng_ctx
*ctx
;
504 /* Event ID management */
505 struct lttng_session
*session
;
506 int objd
; /* Object associated to channel */
507 struct cds_list_head node
; /* Channel list in session */
508 const struct lttng_channel_ops
*ops
;
509 int header_type
; /* 0: unset, 1: compact, 2: large */
510 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
514 enum lttng_ust_abi_chan_type type
;
515 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
516 int tstate
:1; /* Transient enable state */
519 struct lttng_counter_dimension
;
521 struct lttng_counter_ops
{
522 struct lib_counter
*(*counter_create
)(size_t nr_dimensions
,
523 const struct lttng_counter_dimension
*dimensions
,
524 int64_t global_sum_step
,
525 int global_counter_fd
,
526 int nr_counter_cpu_fds
,
527 const int *counter_cpu_fds
,
529 void (*counter_destroy
)(struct lib_counter
*counter
);
530 int (*counter_add
)(struct lib_counter
*counter
,
531 const size_t *dimension_indexes
, int64_t v
);
532 int (*counter_read
)(struct lib_counter
*counter
,
533 const size_t *dimension_indexes
, int cpu
,
534 int64_t *value
, bool *overflow
, bool *underflow
);
535 int (*counter_aggregate
)(struct lib_counter
*counter
,
536 const size_t *dimension_indexes
, int64_t *value
,
537 bool *overflow
, bool *underflow
);
538 int (*counter_clear
)(struct lib_counter
*counter
, const size_t *dimension_indexes
);
541 #define LTTNG_UST_STACK_CTX_PADDING 32
542 struct lttng_stack_ctx
{
543 struct lttng_ust_event_recorder
*event_recorder
;
544 struct lttng_ctx
*chan_ctx
; /* RCU dereferenced. */
545 struct lttng_ctx
*event_ctx
; /* RCU dereferenced. */
546 char padding
[LTTNG_UST_STACK_CTX_PADDING
];
549 #define LTTNG_UST_EVENT_HT_BITS 12
550 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
552 struct lttng_ust_event_ht
{
553 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
556 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
557 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
558 struct lttng_ust_event_notifier_ht
{
559 struct cds_hlist_head table
[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
];
562 #define LTTNG_UST_ENUM_HT_BITS 12
563 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
565 struct lttng_ust_enum_ht
{
566 struct cds_hlist_head table
[LTTNG_UST_ENUM_HT_SIZE
];
569 struct lttng_ust_session_private
;
572 * IMPORTANT: this structure is part of the ABI between the probe and
573 * UST. Fields need to be only added at the end, never reordered, never
576 * The field @struct_size should be used to determine the size of the
577 * structure. It should be queried before using additional fields added
578 * at the end of the structure.
580 struct lttng_session
{
581 uint32_t struct_size
; /* Size of this structure */
582 struct lttng_ust_session_private
*priv
; /* Private session interface */
584 int active
; /* Is trace session active ? */
586 /* End of base ABI. Fields below should be used after checking struct_size. */
589 int lttng_probe_register(struct lttng_probe_desc
*desc
);
590 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
593 * Can be used by applications that change their procname to clear the ust cached value.
595 void lttng_context_procname_reset(void);
597 struct lttng_transport
*lttng_transport_find(const char *name
);
599 int lttng_session_active(void);
601 void lttng_ust_dl_update(void *ip
);
607 #endif /* _LTTNG_UST_EVENTS_H */