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
44 struct lttng_ust_session
;
45 struct lttng_ust_lib_ring_buffer_ctx
;
46 struct lttng_ust_event_field
;
49 * Data structures used by tracepoint event declarations, and by the
50 * tracer. Those structures have padding for future extension.
53 /* Type description */
55 /* Update the astract_types name table in lttng-types.c along with this enum */
56 enum lttng_abstract_types
{
63 atype_sequence_nestable
,
64 atype_struct_nestable
,
68 /* Update the string_encodings name table in lttng-types.c along with this enum */
69 enum lttng_string_encodings
{
70 lttng_encode_none
= 0,
71 lttng_encode_UTF8
= 1,
72 lttng_encode_ASCII
= 2,
76 struct lttng_enum_value
{
77 unsigned long long value
;
78 unsigned int signedness
:1;
81 enum lttng_enum_entry_options
{
82 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
86 * Enumeration entry description
88 * IMPORTANT: this structure is part of the ABI between the probe and
89 * UST. Fields need to be only added at the end, never reordered, never
92 * The field @struct_size should be used to determine the size of the
93 * structure. It should be queried before using additional fields added
94 * at the end of the structure.
97 struct lttng_ust_enum_entry
{
100 struct lttng_enum_value start
, end
; /* start and end are inclusive */
102 unsigned int options
;
104 /* End of base ABI. Fields below should be used after checking struct_size. */
107 #define __type_integer(_type, _byte_order, _base, _encoding) \
109 .atype = atype_integer, \
112 .size = sizeof(_type) * CHAR_BIT, \
113 .alignment = lttng_alignof(_type) * CHAR_BIT, \
114 .signedness = lttng_is_signed_type(_type), \
115 .reverse_byte_order = _byte_order != BYTE_ORDER, \
117 .encoding = lttng_encode_##_encoding, \
122 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
123 struct lttng_integer_type
{
124 unsigned int size
; /* in bits */
125 unsigned short alignment
; /* in bits */
126 unsigned int signedness
:1;
127 unsigned int reverse_byte_order
:1;
128 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
129 enum lttng_string_encodings encoding
;
130 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
134 * Only float and double are supported. long double is not supported at
137 #define _float_mant_dig(_type) \
138 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
139 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
142 #define __type_float(_type) \
144 .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
];
165 #define LTTNG_UST_TYPE_PADDING 128
167 enum lttng_abstract_types atype
;
169 /* provider ABI 2.0 */
170 struct lttng_integer_type integer
;
171 struct lttng_float_type _float
;
173 enum lttng_string_encodings encoding
;
176 const struct lttng_ust_enum_desc
*desc
; /* Enumeration mapping */
177 struct lttng_type
*container_type
;
180 const struct lttng_type
*elem_type
;
181 unsigned int length
; /* Num. elems. */
182 unsigned int alignment
;
185 const char *length_name
; /* Length field name. */
186 const struct lttng_type
*elem_type
;
187 unsigned int alignment
; /* Alignment before elements. */
190 unsigned int nr_fields
;
191 const struct lttng_ust_event_field
**fields
; /* Array of pointers to fields. */
192 unsigned int alignment
;
195 char padding
[LTTNG_UST_TYPE_PADDING
];
200 * Enumeration description
202 * IMPORTANT: this structure is part of the ABI between the probe and
203 * UST. Fields need to be only added at the end, never reordered, never
206 * The field @struct_size should be used to determine the size of the
207 * structure. It should be queried before using additional fields added
208 * at the end of the structure.
211 struct lttng_ust_enum_desc
{
212 uint32_t struct_size
;
215 const struct lttng_ust_enum_entry
**entries
;
216 unsigned int nr_entries
;
218 /* End of base ABI. Fields below should be used after checking struct_size. */
222 * Event field description
224 * IMPORTANT: this structure is part of the ABI between the probe and
225 * UST. Fields need to be only added at the end, never reordered, never
228 * The field @struct_size should be used to determine the size of the
229 * structure. It should be queried before using additional fields added
230 * at the end of the structure.
233 struct lttng_ust_event_field
{
234 uint32_t struct_size
;
237 struct lttng_type type
;
238 unsigned int nowrite
:1, /* do not write into trace */
239 nofilter
:1; /* do not consider for filter */
241 /* End of base ABI. Fields below should be used after checking struct_size. */
246 * IMPORTANT: this structure is part of the ABI between the probe and
247 * UST. Fields need to be only added at the end, never reordered, never
250 * The field @struct_size should be used to determine the size of the
251 * structure. It should be queried before using additional fields added
252 * at the end of the structure.
254 struct lttng_ust_event_desc
{
255 uint32_t struct_size
; /* Size of this structure. */
258 void (*probe_callback
)(void);
259 const struct lttng_event_ctx
*ctx
; /* context */
260 const struct lttng_ust_event_field
**fields
; /* event payload */
261 unsigned int nr_fields
;
262 const int **loglevel
;
263 const char *signature
; /* Argument types/names received */
264 const char **model_emf_uri
;
266 /* End of base ABI. Fields below should be used after checking struct_size. */
270 * IMPORTANT: this structure is part of the ABI between the probe and
271 * UST. Fields need to be only added at the end, never reordered, never
274 * The field @struct_size should be used to determine the size of the
275 * structure. It should be queried before using additional fields added
276 * at the end of the structure.
278 struct lttng_ust_probe_desc
{
279 uint32_t struct_size
; /* Size of this structure. */
281 const char *provider
;
282 const struct lttng_ust_event_desc
**event_desc
;
283 unsigned int nr_events
;
284 struct cds_list_head head
; /* chain registered probes */
285 struct cds_list_head lazy_init_head
;
286 int lazy
; /* lazy registration */
290 /* End of base ABI. Fields below should be used after checking struct_size. */
293 /* Data structures used by the tracer. */
296 * Bytecode interpreter return value masks.
298 enum lttng_bytecode_interpreter_ret
{
299 LTTNG_INTERPRETER_DISCARD
= 0,
300 LTTNG_INTERPRETER_RECORD_FLAG
= (1ULL << 0),
301 /* Other bits are kept for future use. */
304 struct lttng_interpreter_output
;
305 struct lttng_ust_bytecode_runtime_private
;
308 * IMPORTANT: this structure is part of the ABI between the probe and
309 * UST. Fields need to be only added at the end, never reordered, never
312 * The field @struct_size should be used to determine the size of the
313 * structure. It should be queried before using additional fields added
314 * at the end of the structure.
316 struct lttng_ust_bytecode_runtime
{
317 uint32_t struct_size
; /* Size of this structure. */
319 struct lttng_ust_bytecode_runtime_private
*priv
;
320 /* Associated bytecode */
322 uint64_t (*filter
)(void *interpreter_data
,
323 const char *interpreter_stack_data
);
324 uint64_t (*capture
)(void *interpreter_data
,
325 const char *interpreter_stack_data
,
326 struct lttng_interpreter_output
*interpreter_output
);
328 struct cds_list_head node
; /* list of bytecode runtime in event */
330 /* End of base ABI. Fields below should be used after checking struct_size. */
334 * lttng_event structure is referred to by the tracing fast path. It
335 * must be kept small.
337 * IMPORTANT: this structure is part of the ABI between the probe and
338 * UST. Fields need to be only added at the end, never reordered, never
342 struct lttng_ust_ctx
;
343 struct lttng_ust_event_common_private
;
345 enum lttng_ust_event_type
{
346 LTTNG_UST_EVENT_TYPE_RECORDER
= 0,
347 LTTNG_UST_EVENT_TYPE_NOTIFIER
= 1,
351 * IMPORTANT: this structure is part of the ABI between the probe and
352 * UST. Fields need to be only added at the end, never reordered, never
355 * struct lttng_ust_event_common is the common ancestor of the various
356 * public event actions. Inheritance is done by composition: The parent
357 * has a pointer to its child, and the child has a pointer to its
358 * parent. Inheritance of those public structures is done by composition
359 * to ensure both parent and child structures can be extended.
361 * The field @struct_size should be used to determine the size of the
362 * structure. It should be queried before using additional fields added
363 * at the end of the structure.
365 struct lttng_ust_event_common
{
366 uint32_t struct_size
; /* Size of this structure. */
368 struct lttng_ust_event_common_private
*priv
; /* Private event interface */
370 enum lttng_ust_event_type type
;
371 void *child
; /* Pointer to child, for inheritance by aggregation. */
374 int has_enablers_without_bytecode
;
375 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
376 struct cds_list_head filter_bytecode_runtime_head
;
378 /* End of base ABI. Fields below should be used after checking struct_size. */
381 struct lttng_ust_event_recorder_private
;
384 * IMPORTANT: this structure is part of the ABI between the probe and
385 * UST. Fields need to be only added at the end, never reordered, never
388 * struct lttng_ust_event_recorder is the action for recording events
389 * into a ring buffer. It inherits from struct lttng_ust_event_common
390 * by composition to ensure both parent and child structure are
393 * The field @struct_size should be used to determine the size of the
394 * structure. It should be queried before using additional fields added
395 * at the end of the structure.
397 struct lttng_ust_event_recorder
{
398 uint32_t struct_size
; /* Size of this structure. */
400 struct lttng_ust_event_common
*parent
; /* Inheritance by aggregation. */
401 struct lttng_ust_event_recorder_private
*priv
; /* Private event record interface */
404 struct lttng_channel
*chan
;
405 struct lttng_ust_ctx
*ctx
;
407 /* End of base ABI. Fields below should be used after checking struct_size. */
410 struct lttng_ust_event_notifier_private
;
413 * IMPORTANT: this structure is part of the ABI between the probe and
414 * UST. Fields need to be only added at the end, never reordered, never
417 * struct lttng_ust_event_notifier is the action for sending
418 * notifications. It inherits from struct lttng_ust_event_common
419 * by composition to ensure both parent and child structure are
422 * The field @struct_size should be used to determine the size of the
423 * structure. It should be queried before using additional fields added
424 * at the end of the structure.
426 struct lttng_ust_event_notifier
{
427 uint32_t struct_size
; /* Size of this structure. */
429 struct lttng_ust_event_common
*parent
; /* Inheritance by aggregation. */
430 struct lttng_ust_event_notifier_private
*priv
; /* Private event notifier interface */
432 void (*notification_send
)(struct lttng_ust_event_notifier
*event_notifier
,
433 const char *stack_data
);
434 struct cds_list_head capture_bytecode_runtime_head
;
436 /* End of base ABI. Fields below should be used after checking struct_size. */
439 struct lttng_ust_lib_ring_buffer_channel
;
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 * The field @struct_size should be used to determine the size of the
448 * structure. It should be queried before using additional fields added
449 * at the end of the structure.
451 struct lttng_ust_channel_ops
{
452 uint32_t struct_size
;
454 struct lttng_channel
*(*channel_create
)(const char *name
,
456 size_t subbuf_size
, size_t num_subbuf
,
457 unsigned int switch_timer_interval
,
458 unsigned int read_timer_interval
,
461 const int *stream_fds
, int nr_stream_fds
,
462 int64_t blocking_timeout
);
463 void (*channel_destroy
)(struct lttng_channel
*chan
);
464 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
466 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
467 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
468 const void *src
, size_t len
);
470 * packet_avail_size returns the available size in the current
471 * packet. Note that the size returned is only a hint, since it
472 * may change due to concurrent writes.
474 size_t (*packet_avail_size
)(struct lttng_ust_lib_ring_buffer_channel
*chan
,
475 struct lttng_ust_shm_handle
*handle
);
476 int (*is_finalized
)(struct lttng_ust_lib_ring_buffer_channel
*chan
);
477 int (*is_disabled
)(struct lttng_ust_lib_ring_buffer_channel
*chan
);
478 int (*flush_buffer
)(struct lttng_ust_lib_ring_buffer_channel
*chan
,
479 struct lttng_ust_shm_handle
*handle
);
480 void (*event_strcpy
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
481 const char *src
, size_t len
);
483 /* End of base ABI. Fields below should be used after checking struct_size. */
487 * IMPORTANT: this structure is part of the ABI between the probe and
488 * UST. Fields need to be only added at the end, never reordered, never
491 struct lttng_channel
{
493 * The pointers located in this private data are NOT safe to be
494 * dereferenced by the consumer. The only operations the
495 * consumer process is designed to be allowed to do is to read
496 * and perform subbuffer flush.
498 struct lttng_ust_lib_ring_buffer_channel
*chan
; /* Channel buffers */
500 struct lttng_ust_ctx
*ctx
;
501 /* Event ID management */
502 struct lttng_ust_session
*session
;
503 int objd
; /* Object associated to channel */
504 struct cds_list_head node
; /* Channel list in session */
505 const struct lttng_ust_channel_ops
*ops
;
506 int header_type
; /* 0: unset, 1: compact, 2: large */
507 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
511 enum lttng_ust_abi_chan_type type
;
512 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
513 int tstate
:1; /* Transient enable state */
517 * IMPORTANT: this structure is part of the ABI between the probe and
518 * UST. Fields need to be only added at the end, never reordered, never
521 * The field @struct_size should be used to determine the size of the
522 * structure. It should be queried before using additional fields added
523 * at the end of the structure.
525 struct lttng_ust_stack_ctx
{
526 uint32_t struct_size
; /* Size of this structure */
528 struct lttng_ust_event_recorder
*event_recorder
;
529 struct lttng_ust_ctx
*chan_ctx
; /* RCU dereferenced. */
530 struct lttng_ust_ctx
*event_ctx
; /* RCU dereferenced. */
532 /* End of base ABI. Fields below should be used after checking struct_size. */
535 struct lttng_ust_session_private
;
538 * IMPORTANT: this structure is part of the ABI between the probe and
539 * UST. Fields need to be only added at the end, never reordered, never
542 * The field @struct_size should be used to determine the size of the
543 * structure. It should be queried before using additional fields added
544 * at the end of the structure.
546 struct lttng_ust_session
{
547 uint32_t struct_size
; /* Size of this structure */
549 struct lttng_ust_session_private
*priv
; /* Private session interface */
551 int active
; /* Is trace session active ? */
553 /* End of base ABI. Fields below should be used after checking struct_size. */
556 int lttng_ust_probe_register(struct lttng_ust_probe_desc
*desc
);
557 void lttng_ust_probe_unregister(struct lttng_ust_probe_desc
*desc
);
560 * Applications that change their procname and need the new value to be
561 * reflected in the procname event context have to call this function to clear
562 * the internally cached value. This should not be called from a signal
565 void lttng_ust_context_procname_reset(void);
571 #endif /* _LTTNG_UST_EVENTS_H */