2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
7 #ifndef _LTTNG_UST_EVENTS_INTERNAL_H
8 #define _LTTNG_UST_EVENTS_INTERNAL_H
12 #include <urcu/list.h>
13 #include <urcu/hlist.h>
15 #include <lttng/ust-events.h>
17 #include "ust-context-provider.h"
19 struct lttng_ust_abi_obj
;
20 struct lttng_event_notifier_group
;
22 union lttng_ust_abi_args
{
32 struct lttng_ust_abi_field_iter entry
;
38 int event_notifier_notif_fd
;
39 } event_notifier_handle
;
48 struct lttng_ust_abi_objd_ops
{
49 long (*cmd
)(int objd
, unsigned int cmd
, unsigned long arg
,
50 union lttng_ust_abi_args
*args
, void *owner
);
51 int (*release
)(int objd
);
54 enum lttng_enabler_format_type
{
55 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
56 LTTNG_ENABLER_FORMAT_EVENT
,
60 * Enabler field, within whatever object is enabling an event. Target of
63 struct lttng_enabler
{
64 enum lttng_enabler_format_type format_type
;
66 /* head list of struct lttng_ust_filter_bytecode_node */
67 struct cds_list_head filter_bytecode_head
;
68 /* head list of struct lttng_ust_excluder_node */
69 struct cds_list_head excluder_head
;
71 struct lttng_ust_abi_event event_param
;
72 unsigned int enabled
:1;
75 struct lttng_event_enabler
{
76 struct lttng_enabler base
;
77 struct cds_list_head node
; /* per-session list of enablers */
78 struct lttng_channel
*chan
;
80 * Unused, but kept around to make it explicit that the tracer can do
83 struct lttng_ust_ctx
*ctx
;
86 struct lttng_event_notifier_enabler
{
87 struct lttng_enabler base
;
88 uint64_t error_counter_index
;
89 struct cds_list_head node
; /* per-app list of event_notifier enablers */
90 struct cds_list_head capture_bytecode_head
;
91 struct lttng_event_notifier_group
*group
; /* weak ref */
92 uint64_t user_token
; /* User-provided token */
93 uint64_t num_captures
;
96 enum lttng_ust_bytecode_node_type
{
97 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER
,
98 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE
,
101 struct lttng_ust_bytecode_node
{
102 enum lttng_ust_bytecode_node_type type
;
103 struct cds_list_head node
;
104 struct lttng_enabler
*enabler
;
107 uint32_t reloc_offset
;
113 struct lttng_ust_excluder_node
{
114 struct cds_list_head node
;
115 struct lttng_enabler
*enabler
;
117 * struct lttng_ust_event_exclusion had variable sized array,
118 * must be last field.
120 struct lttng_ust_abi_event_exclusion excluder
;
123 /* Data structures used by the tracer. */
125 struct tp_list_entry
{
126 struct lttng_ust_abi_tracepoint_iter tp
;
127 struct cds_list_head head
;
130 struct lttng_ust_tracepoint_list
{
131 struct tp_list_entry
*iter
;
132 struct cds_list_head head
;
135 struct tp_field_list_entry
{
136 struct lttng_ust_abi_field_iter field
;
137 struct cds_list_head head
;
140 struct lttng_ust_field_list
{
141 struct tp_field_list_entry
*iter
;
142 struct cds_list_head head
;
146 * Objects in a linked-list of enablers, owned by an event or event_notifier.
147 * This is used because an event (or a event_notifier) can be enabled by more
148 * than one enabler and we want a quick way to iterate over all enablers of an
151 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
152 * event with the name "my_app:abc".
154 struct lttng_enabler_ref
{
155 struct cds_list_head node
; /* enabler ref list */
156 struct lttng_enabler
*ref
; /* backward ref */
159 #define LTTNG_COUNTER_DIMENSION_MAX 8
160 struct lttng_counter_dimension
{
162 uint64_t underflow_index
;
163 uint64_t overflow_index
;
164 uint8_t has_underflow
;
165 uint8_t has_overflow
;
168 struct lttng_counter_ops
{
169 struct lib_counter
*(*counter_create
)(size_t nr_dimensions
,
170 const struct lttng_counter_dimension
*dimensions
,
171 int64_t global_sum_step
,
172 int global_counter_fd
,
173 int nr_counter_cpu_fds
,
174 const int *counter_cpu_fds
,
176 void (*counter_destroy
)(struct lib_counter
*counter
);
177 int (*counter_add
)(struct lib_counter
*counter
,
178 const size_t *dimension_indexes
, int64_t v
);
179 int (*counter_read
)(struct lib_counter
*counter
,
180 const size_t *dimension_indexes
, int cpu
,
181 int64_t *value
, bool *overflow
, bool *underflow
);
182 int (*counter_aggregate
)(struct lib_counter
*counter
,
183 const size_t *dimension_indexes
, int64_t *value
,
184 bool *overflow
, bool *underflow
);
185 int (*counter_clear
)(struct lib_counter
*counter
, const size_t *dimension_indexes
);
188 struct lttng_counter
{
190 struct lttng_event_notifier_group
*event_notifier_group
; /* owner */
191 struct lttng_counter_transport
*transport
;
192 struct lib_counter
*counter
;
193 struct lttng_counter_ops
*ops
;
196 #define LTTNG_UST_EVENT_HT_BITS 12
197 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
199 struct lttng_ust_event_ht
{
200 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
203 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
204 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
205 struct lttng_ust_event_notifier_ht
{
206 struct cds_hlist_head table
[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
];
209 #define LTTNG_UST_ENUM_HT_BITS 12
210 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
212 struct lttng_ust_enum_ht
{
213 struct cds_hlist_head table
[LTTNG_UST_ENUM_HT_SIZE
];
216 struct lttng_event_notifier_group
{
220 struct cds_list_head node
; /* Event notifier group handle list */
221 struct cds_list_head enablers_head
;
222 struct cds_list_head event_notifiers_head
; /* list of event_notifiers */
223 struct lttng_ust_event_notifier_ht event_notifiers_ht
; /* hashtable of event_notifiers */
224 struct lttng_ust_ctx
*ctx
; /* contexts for filters. */
226 struct lttng_counter
*error_counter
;
227 size_t error_counter_len
;
230 struct lttng_transport
{
232 struct cds_list_head node
;
233 struct lttng_ust_channel_ops ops
;
234 const struct lttng_ust_lib_ring_buffer_config
*client_config
;
237 struct lttng_counter_transport
{
239 struct cds_list_head node
;
240 struct lttng_counter_ops ops
;
241 const struct lib_counter_config
*client_config
;
244 struct lttng_ust_event_common_private
{
245 struct lttng_ust_event_common
*pub
; /* Public event interface */
247 const struct lttng_ust_event_desc
*desc
;
248 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
249 struct cds_list_head enablers_ref_head
;
250 int registered
; /* has reg'd tracepoint probe */
254 struct lttng_ust_event_recorder_private
{
255 struct lttng_ust_event_common_private parent
;
257 struct lttng_ust_event_recorder
*pub
; /* Public event interface */
258 struct cds_list_head node
; /* Event recorder list */
259 struct cds_hlist_node hlist
; /* Hash table of event recorders */
262 struct lttng_ust_event_notifier_private
{
263 struct lttng_ust_event_common_private parent
;
265 struct lttng_ust_event_notifier
*pub
; /* Public event notifier interface */
266 struct lttng_event_notifier_group
*group
; /* weak ref */
267 size_t num_captures
; /* Needed to allocate the msgpack array. */
268 uint64_t error_counter_index
;
269 struct cds_list_head node
; /* Event notifier list */
270 struct cds_hlist_node hlist
; /* Hash table of event notifiers */
273 struct lttng_ust_bytecode_runtime_private
{
274 struct bytecode_runtime
*pub
; /* Public bytecode runtime interface */
276 struct lttng_ust_bytecode_node
*bc
;
279 * Pointer to a URCU-protected pointer owned by an `struct
280 * lttng_session`or `struct lttng_event_notifier_group`.
282 struct lttng_ust_ctx
**pctx
;
285 struct lttng_ust_session_private
{
286 struct lttng_ust_session
*pub
; /* Public session interface */
288 int been_active
; /* Been active ? */
289 int objd
; /* Object associated */
290 struct cds_list_head chan_head
; /* Channel list head */
291 struct cds_list_head events_head
; /* list of events */
292 struct cds_list_head node
; /* Session list */
295 /* List of enablers */
296 struct cds_list_head enablers_head
;
297 struct lttng_ust_event_ht events_ht
; /* ht of events */
298 void *owner
; /* object owner */
299 int tstate
:1; /* Transient enable state */
302 int statedump_pending
:1;
305 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
306 struct cds_list_head enums_head
;
307 struct lttng_ust_ctx
*ctx
; /* contexts for filters. */
311 const struct lttng_ust_enum_desc
*desc
;
312 struct lttng_ust_session
*session
;
313 struct cds_list_head node
; /* Enum list in session */
314 struct cds_hlist_node hlist
; /* Session ht of enums */
315 uint64_t id
; /* Enumeration ID in sessiond */
318 struct lttng_ust_channel_ops_private
{
319 struct lttng_ust_channel_ops
*pub
; /* Public channels ops interface */
321 struct lttng_channel
*(*channel_create
)(const char *name
,
323 size_t subbuf_size
, size_t num_subbuf
,
324 unsigned int switch_timer_interval
,
325 unsigned int read_timer_interval
,
328 const int *stream_fds
, int nr_stream_fds
,
329 int64_t blocking_timeout
);
330 void (*channel_destroy
)(struct lttng_channel
*chan
);
332 * packet_avail_size returns the available size in the current
333 * packet. Note that the size returned is only a hint, since it
334 * may change due to concurrent writes.
336 size_t (*packet_avail_size
)(struct lttng_ust_lib_ring_buffer_channel
*chan
,
337 struct lttng_ust_shm_handle
*handle
);
338 int (*is_finalized
)(struct lttng_ust_lib_ring_buffer_channel
*chan
);
339 int (*is_disabled
)(struct lttng_ust_lib_ring_buffer_channel
*chan
);
340 int (*flush_buffer
)(struct lttng_ust_lib_ring_buffer_channel
*chan
,
341 struct lttng_ust_shm_handle
*handle
);
345 struct lttng_enabler
*lttng_event_enabler_as_enabler(
346 struct lttng_event_enabler
*event_enabler
)
348 return &event_enabler
->base
;
352 struct lttng_enabler
*lttng_event_notifier_enabler_as_enabler(
353 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
355 return &event_notifier_enabler
->base
;
359 * Allocate and initialize a `struct lttng_event_enabler` object.
361 * On success, returns a `struct lttng_event_enabler`,
362 * On memory error, returns NULL.
364 __attribute__((visibility("hidden")))
365 struct lttng_event_enabler
*lttng_event_enabler_create(
366 enum lttng_enabler_format_type format_type
,
367 struct lttng_ust_abi_event
*event_param
,
368 struct lttng_channel
*chan
);
371 * Destroy a `struct lttng_event_enabler` object.
373 __attribute__((visibility("hidden")))
374 void lttng_event_enabler_destroy(struct lttng_event_enabler
*enabler
);
377 * Enable a `struct lttng_event_enabler` object and all events related to this
380 __attribute__((visibility("hidden")))
381 int lttng_event_enabler_enable(struct lttng_event_enabler
*enabler
);
384 * Disable a `struct lttng_event_enabler` object and all events related to this
387 __attribute__((visibility("hidden")))
388 int lttng_event_enabler_disable(struct lttng_event_enabler
*enabler
);
391 * Attach filter bytecode program to `struct lttng_event_enabler` and all
392 * events related to this enabler.
394 __attribute__((visibility("hidden")))
395 int lttng_event_enabler_attach_filter_bytecode(
396 struct lttng_event_enabler
*enabler
,
397 struct lttng_ust_bytecode_node
**bytecode
);
400 * Attach an application context to an event enabler.
404 __attribute__((visibility("hidden")))
405 int lttng_event_enabler_attach_context(struct lttng_event_enabler
*enabler
,
406 struct lttng_ust_abi_context
*ctx
);
409 * Attach exclusion list to `struct lttng_event_enabler` and all
410 * events related to this enabler.
412 __attribute__((visibility("hidden")))
413 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler
*enabler
,
414 struct lttng_ust_excluder_node
**excluder
);
417 * Synchronize bytecodes for the enabler and the instance (event or
420 * This function goes over all bytecode programs of the enabler (event or
421 * event_notifier enabler) to ensure each is linked to the provided instance.
423 __attribute__((visibility("hidden")))
424 void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc
*event_desc
,
425 struct lttng_ust_ctx
**ctx
,
426 struct cds_list_head
*instance_bytecode_runtime_head
,
427 struct cds_list_head
*enabler_bytecode_runtime_head
);
430 * Allocate and initialize a `struct lttng_event_notifier_group` object.
432 * On success, returns a `struct lttng_triggre_group`,
433 * on memory error, returns NULL.
435 __attribute__((visibility("hidden")))
436 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void);
439 * Destroy a `struct lttng_event_notifier_group` object.
441 __attribute__((visibility("hidden")))
442 void lttng_event_notifier_group_destroy(
443 struct lttng_event_notifier_group
*event_notifier_group
);
446 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
448 * On success, returns a `struct lttng_event_notifier_enabler`,
449 * On memory error, returns NULL.
451 __attribute__((visibility("hidden")))
452 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
453 struct lttng_event_notifier_group
*event_notifier_group
,
454 enum lttng_enabler_format_type format_type
,
455 struct lttng_ust_abi_event_notifier
*event_notifier_param
);
458 * Destroy a `struct lttng_event_notifier_enabler` object.
460 __attribute__((visibility("hidden")))
461 void lttng_event_notifier_enabler_destroy(
462 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
465 * Enable a `struct lttng_event_notifier_enabler` object and all event
466 * notifiers related to this enabler.
468 __attribute__((visibility("hidden")))
469 int lttng_event_notifier_enabler_enable(
470 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
473 * Disable a `struct lttng_event_notifier_enabler` object and all event
474 * notifiers related to this enabler.
476 __attribute__((visibility("hidden")))
477 int lttng_event_notifier_enabler_disable(
478 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
481 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
482 * all event notifiers related to this enabler.
484 __attribute__((visibility("hidden")))
485 int lttng_event_notifier_enabler_attach_filter_bytecode(
486 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
487 struct lttng_ust_bytecode_node
**bytecode
);
490 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
491 * all event_notifiers related to this enabler.
493 __attribute__((visibility("hidden")))
494 int lttng_event_notifier_enabler_attach_capture_bytecode(
495 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
496 struct lttng_ust_bytecode_node
**bytecode
);
499 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
500 * event notifiers related to this enabler.
502 __attribute__((visibility("hidden")))
503 int lttng_event_notifier_enabler_attach_exclusion(
504 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
505 struct lttng_ust_excluder_node
**excluder
);
507 __attribute__((visibility("hidden")))
508 void lttng_free_event_filter_runtime(struct lttng_ust_event_common
*event
);
511 * Connect the probe on all enablers matching this event description.
512 * Called on library load.
514 __attribute__((visibility("hidden")))
515 int lttng_fix_pending_event_notifiers(void);
517 __attribute__((visibility("hidden")))
518 struct lttng_counter
*lttng_ust_counter_create(
519 const char *counter_transport_name
,
520 size_t number_dimensions
, const struct lttng_counter_dimension
*dimensions
);
522 #ifdef HAVE_PERF_EVENT
524 __attribute__((visibility("hidden")))
525 int lttng_add_perf_counter_to_ctx(uint32_t type
,
528 struct lttng_ust_ctx
**ctx
);
530 __attribute__((visibility("hidden")))
531 int lttng_perf_counter_init(void);
533 __attribute__((visibility("hidden")))
534 void lttng_perf_counter_exit(void);
536 #else /* #ifdef HAVE_PERF_EVENT */
539 int lttng_add_perf_counter_to_ctx(uint32_t type
,
542 struct lttng_ust_ctx
**ctx
)
547 int lttng_perf_counter_init(void)
552 void lttng_perf_counter_exit(void)
555 #endif /* #else #ifdef HAVE_PERF_EVENT */
557 __attribute__((visibility("hidden")))
558 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
560 __attribute__((visibility("hidden")))
561 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
563 __attribute__((visibility("hidden")))
564 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
566 __attribute__((visibility("hidden")))
567 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
569 __attribute__((visibility("hidden")))
570 struct lttng_ust_abi_tracepoint_iter
*
571 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
573 __attribute__((visibility("hidden")))
574 struct lttng_ust_abi_field_iter
*
575 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
577 __attribute__((visibility("hidden")))
578 struct lttng_ust_session
*lttng_session_create(void);
580 __attribute__((visibility("hidden")))
581 int lttng_session_enable(struct lttng_ust_session
*session
);
583 __attribute__((visibility("hidden")))
584 int lttng_session_disable(struct lttng_ust_session
*session
);
586 __attribute__((visibility("hidden")))
587 int lttng_session_statedump(struct lttng_ust_session
*session
);
589 __attribute__((visibility("hidden")))
590 void lttng_session_destroy(struct lttng_ust_session
*session
);
593 * Called with ust lock held.
595 __attribute__((visibility("hidden")))
596 int lttng_session_active(void);
598 __attribute__((visibility("hidden")))
599 struct cds_list_head
*lttng_get_sessions(void);
601 __attribute__((visibility("hidden")))
602 void lttng_handle_pending_statedump(void *owner
);
604 __attribute__((visibility("hidden")))
605 struct lttng_channel
*lttng_channel_create(struct lttng_ust_session
*session
,
606 const char *transport_name
,
608 size_t subbuf_size
, size_t num_subbuf
,
609 unsigned int switch_timer_interval
,
610 unsigned int read_timer_interval
,
611 int **shm_fd
, int **wait_fd
,
612 uint64_t **memory_map_size
,
613 struct lttng_channel
*chan_priv_init
);
615 __attribute__((visibility("hidden")))
616 int lttng_channel_enable(struct lttng_channel
*channel
);
618 __attribute__((visibility("hidden")))
619 int lttng_channel_disable(struct lttng_channel
*channel
);
621 __attribute__((visibility("hidden")))
622 void lttng_transport_register(struct lttng_transport
*transport
);
624 __attribute__((visibility("hidden")))
625 void lttng_transport_unregister(struct lttng_transport
*transport
);
627 /* This is ABI between liblttng-ust and liblttng-ust-ctl */
628 struct lttng_transport
*lttng_ust_transport_find(const char *name
);
630 /* This is ABI between liblttng-ust and liblttng-ust-dl */
631 void lttng_ust_dl_update(void *ip
);
633 __attribute__((visibility("hidden")))
634 void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc
*desc
);
636 __attribute__((visibility("hidden")))
637 int lttng_fix_pending_events(void);
639 __attribute__((visibility("hidden")))
640 struct cds_list_head
*lttng_get_probe_list_head(void);
642 __attribute__((visibility("hidden")))
643 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_ust_session
*session
,
644 const struct lttng_ust_enum_desc
*enum_desc
);
646 __attribute__((visibility("hidden")))
647 int lttng_abi_create_root_handle(void);
649 __attribute__((visibility("hidden")))
650 const struct lttng_ust_abi_objd_ops
*lttng_ust_abi_objd_ops(int id
);
652 __attribute__((visibility("hidden")))
653 int lttng_ust_abi_objd_unref(int id
, int is_owner
);
655 __attribute__((visibility("hidden")))
656 void lttng_ust_abi_exit(void);
658 __attribute__((visibility("hidden")))
659 void lttng_ust_abi_events_exit(void);
661 __attribute__((visibility("hidden")))
662 void lttng_ust_abi_objd_table_owner_cleanup(void *owner
);
664 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */