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>
18 struct lttng_ust_abi_obj
;
20 union lttng_ust_abi_args
{
30 struct lttng_ust_abi_field_iter entry
;
36 int event_notifier_notif_fd
;
37 } event_notifier_handle
;
46 struct lttng_ust_abi_objd_ops
{
47 long (*cmd
)(int objd
, unsigned int cmd
, unsigned long arg
,
48 union lttng_ust_abi_args
*args
, void *owner
);
49 int (*release
)(int objd
);
52 enum lttng_enabler_format_type
{
53 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
54 LTTNG_ENABLER_FORMAT_EVENT
,
58 * Enabler field, within whatever object is enabling an event. Target of
61 struct lttng_enabler
{
62 enum lttng_enabler_format_type format_type
;
64 /* head list of struct lttng_ust_filter_bytecode_node */
65 struct cds_list_head filter_bytecode_head
;
66 /* head list of struct lttng_ust_excluder_node */
67 struct cds_list_head excluder_head
;
69 struct lttng_ust_abi_event event_param
;
70 unsigned int enabled
:1;
73 struct lttng_event_enabler
{
74 struct lttng_enabler base
;
75 struct cds_list_head node
; /* per-session list of enablers */
76 struct lttng_channel
*chan
;
78 * Unused, but kept around to make it explicit that the tracer can do
81 struct lttng_ctx
*ctx
;
84 struct lttng_event_notifier_enabler
{
85 struct lttng_enabler base
;
86 uint64_t error_counter_index
;
87 struct cds_list_head node
; /* per-app list of event_notifier enablers */
88 struct cds_list_head capture_bytecode_head
;
89 struct lttng_event_notifier_group
*group
; /* weak ref */
90 uint64_t user_token
; /* User-provided token */
91 uint64_t num_captures
;
94 enum lttng_ust_bytecode_node_type
{
95 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER
,
96 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE
,
99 struct lttng_ust_bytecode_node
{
100 enum lttng_ust_bytecode_node_type type
;
101 struct cds_list_head node
;
102 struct lttng_enabler
*enabler
;
105 uint32_t reloc_offset
;
111 struct lttng_ust_excluder_node
{
112 struct cds_list_head node
;
113 struct lttng_enabler
*enabler
;
115 * struct lttng_ust_event_exclusion had variable sized array,
116 * must be last field.
118 struct lttng_ust_abi_event_exclusion excluder
;
121 /* Data structures used by the tracer. */
123 struct tp_list_entry
{
124 struct lttng_ust_abi_tracepoint_iter tp
;
125 struct cds_list_head head
;
128 struct lttng_ust_tracepoint_list
{
129 struct tp_list_entry
*iter
;
130 struct cds_list_head head
;
133 struct tp_field_list_entry
{
134 struct lttng_ust_abi_field_iter field
;
135 struct cds_list_head head
;
138 struct lttng_ust_field_list
{
139 struct tp_field_list_entry
*iter
;
140 struct cds_list_head head
;
144 * Objects in a linked-list of enablers, owned by an event or event_notifier.
145 * This is used because an event (or a event_notifier) can be enabled by more
146 * than one enabler and we want a quick way to iterate over all enablers of an
149 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
150 * event with the name "my_app:abc".
152 struct lttng_enabler_ref
{
153 struct cds_list_head node
; /* enabler ref list */
154 struct lttng_enabler
*ref
; /* backward ref */
157 #define LTTNG_COUNTER_DIMENSION_MAX 8
158 struct lttng_counter_dimension
{
160 uint64_t underflow_index
;
161 uint64_t overflow_index
;
162 uint8_t has_underflow
;
163 uint8_t has_overflow
;
166 struct lttng_counter_ops
{
167 struct lib_counter
*(*counter_create
)(size_t nr_dimensions
,
168 const struct lttng_counter_dimension
*dimensions
,
169 int64_t global_sum_step
,
170 int global_counter_fd
,
171 int nr_counter_cpu_fds
,
172 const int *counter_cpu_fds
,
174 void (*counter_destroy
)(struct lib_counter
*counter
);
175 int (*counter_add
)(struct lib_counter
*counter
,
176 const size_t *dimension_indexes
, int64_t v
);
177 int (*counter_read
)(struct lib_counter
*counter
,
178 const size_t *dimension_indexes
, int cpu
,
179 int64_t *value
, bool *overflow
, bool *underflow
);
180 int (*counter_aggregate
)(struct lib_counter
*counter
,
181 const size_t *dimension_indexes
, int64_t *value
,
182 bool *overflow
, bool *underflow
);
183 int (*counter_clear
)(struct lib_counter
*counter
, const size_t *dimension_indexes
);
186 struct lttng_counter
{
188 struct lttng_event_notifier_group
*event_notifier_group
; /* owner */
189 struct lttng_counter_transport
*transport
;
190 struct lib_counter
*counter
;
191 struct lttng_counter_ops
*ops
;
194 #define LTTNG_UST_EVENT_HT_BITS 12
195 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
197 struct lttng_ust_event_ht
{
198 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
201 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
202 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
203 struct lttng_ust_event_notifier_ht
{
204 struct cds_hlist_head table
[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
];
207 #define LTTNG_UST_ENUM_HT_BITS 12
208 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
210 struct lttng_ust_enum_ht
{
211 struct cds_hlist_head table
[LTTNG_UST_ENUM_HT_SIZE
];
214 struct lttng_event_notifier_group
{
218 struct cds_list_head node
; /* Event notifier group handle list */
219 struct cds_list_head enablers_head
;
220 struct cds_list_head event_notifiers_head
; /* list of event_notifiers */
221 struct lttng_ust_event_notifier_ht event_notifiers_ht
; /* hashtable of event_notifiers */
222 struct lttng_ctx
*ctx
; /* contexts for filters. */
224 struct lttng_counter
*error_counter
;
225 size_t error_counter_len
;
228 struct lttng_transport
{
230 struct cds_list_head node
;
231 struct lttng_ust_channel_ops ops
;
232 const struct lttng_ust_lib_ring_buffer_config
*client_config
;
235 struct lttng_counter_transport
{
237 struct cds_list_head node
;
238 struct lttng_counter_ops ops
;
239 const struct lib_counter_config
*client_config
;
242 struct lttng_ust_event_common_private
{
243 struct lttng_ust_event_common
*pub
; /* Public event interface */
245 const struct lttng_ust_event_desc
*desc
;
246 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
247 struct cds_list_head enablers_ref_head
;
248 int registered
; /* has reg'd tracepoint probe */
252 struct lttng_ust_event_recorder_private
{
253 struct lttng_ust_event_common_private parent
;
255 struct lttng_ust_event_recorder
*pub
; /* Public event interface */
256 struct cds_list_head node
; /* Event recorder list */
257 struct cds_hlist_node hlist
; /* Hash table of event recorders */
260 struct lttng_ust_event_notifier_private
{
261 struct lttng_ust_event_common_private parent
;
263 struct lttng_ust_event_notifier
*pub
; /* Public event notifier interface */
264 struct lttng_event_notifier_group
*group
; /* weak ref */
265 size_t num_captures
; /* Needed to allocate the msgpack array. */
266 uint64_t error_counter_index
;
267 struct cds_list_head node
; /* Event notifier list */
268 struct cds_hlist_node hlist
; /* Hash table of event notifiers */
271 struct lttng_ust_bytecode_runtime_private
{
272 struct bytecode_runtime
*pub
; /* Public bytecode runtime interface */
274 struct lttng_ust_bytecode_node
*bc
;
277 * Pointer to a URCU-protected pointer owned by an `struct
278 * lttng_session`or `struct lttng_event_notifier_group`.
280 struct lttng_ctx
**pctx
;
283 struct lttng_ust_session_private
{
284 struct lttng_session
*pub
; /* Public session interface */
286 int been_active
; /* Been active ? */
287 int objd
; /* Object associated */
288 struct cds_list_head chan_head
; /* Channel list head */
289 struct cds_list_head events_head
; /* list of events */
290 struct cds_list_head node
; /* Session list */
293 /* List of enablers */
294 struct cds_list_head enablers_head
;
295 struct lttng_ust_event_ht events_ht
; /* ht of events */
296 void *owner
; /* object owner */
297 int tstate
:1; /* Transient enable state */
300 int statedump_pending
:1;
303 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
304 struct cds_list_head enums_head
;
305 struct lttng_ctx
*ctx
; /* contexts for filters. */
309 const struct lttng_ust_enum_desc
*desc
;
310 struct lttng_session
*session
;
311 struct cds_list_head node
; /* Enum list in session */
312 struct cds_hlist_node hlist
; /* Session ht of enums */
313 uint64_t id
; /* Enumeration ID in sessiond */
317 struct lttng_enabler
*lttng_event_enabler_as_enabler(
318 struct lttng_event_enabler
*event_enabler
)
320 return &event_enabler
->base
;
324 struct lttng_enabler
*lttng_event_notifier_enabler_as_enabler(
325 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
327 return &event_notifier_enabler
->base
;
331 * Allocate and initialize a `struct lttng_event_enabler` object.
333 * On success, returns a `struct lttng_event_enabler`,
334 * On memory error, returns NULL.
336 __attribute__((visibility("hidden")))
337 struct lttng_event_enabler
*lttng_event_enabler_create(
338 enum lttng_enabler_format_type format_type
,
339 struct lttng_ust_abi_event
*event_param
,
340 struct lttng_channel
*chan
);
343 * Destroy a `struct lttng_event_enabler` object.
345 __attribute__((visibility("hidden")))
346 void lttng_event_enabler_destroy(struct lttng_event_enabler
*enabler
);
349 * Enable a `struct lttng_event_enabler` object and all events related to this
352 __attribute__((visibility("hidden")))
353 int lttng_event_enabler_enable(struct lttng_event_enabler
*enabler
);
356 * Disable a `struct lttng_event_enabler` object and all events related to this
359 __attribute__((visibility("hidden")))
360 int lttng_event_enabler_disable(struct lttng_event_enabler
*enabler
);
363 * Attach filter bytecode program to `struct lttng_event_enabler` and all
364 * events related to this enabler.
366 __attribute__((visibility("hidden")))
367 int lttng_event_enabler_attach_filter_bytecode(
368 struct lttng_event_enabler
*enabler
,
369 struct lttng_ust_bytecode_node
**bytecode
);
372 * Attach an application context to an event enabler.
376 __attribute__((visibility("hidden")))
377 int lttng_event_enabler_attach_context(struct lttng_event_enabler
*enabler
,
378 struct lttng_ust_abi_context
*ctx
);
381 * Attach exclusion list to `struct lttng_event_enabler` and all
382 * events related to this enabler.
384 __attribute__((visibility("hidden")))
385 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler
*enabler
,
386 struct lttng_ust_excluder_node
**excluder
);
389 * Synchronize bytecodes for the enabler and the instance (event or
392 * This function goes over all bytecode programs of the enabler (event or
393 * event_notifier enabler) to ensure each is linked to the provided instance.
395 __attribute__((visibility("hidden")))
396 void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc
*event_desc
,
397 struct lttng_ctx
**ctx
,
398 struct cds_list_head
*instance_bytecode_runtime_head
,
399 struct cds_list_head
*enabler_bytecode_runtime_head
);
402 * Allocate and initialize a `struct lttng_event_notifier_group` object.
404 * On success, returns a `struct lttng_triggre_group`,
405 * on memory error, returns NULL.
407 __attribute__((visibility("hidden")))
408 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void);
411 * Destroy a `struct lttng_event_notifier_group` object.
413 __attribute__((visibility("hidden")))
414 void lttng_event_notifier_group_destroy(
415 struct lttng_event_notifier_group
*event_notifier_group
);
418 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
420 * On success, returns a `struct lttng_event_notifier_enabler`,
421 * On memory error, returns NULL.
423 __attribute__((visibility("hidden")))
424 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
425 struct lttng_event_notifier_group
*event_notifier_group
,
426 enum lttng_enabler_format_type format_type
,
427 struct lttng_ust_abi_event_notifier
*event_notifier_param
);
430 * Destroy a `struct lttng_event_notifier_enabler` object.
432 __attribute__((visibility("hidden")))
433 void lttng_event_notifier_enabler_destroy(
434 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
437 * Enable a `struct lttng_event_notifier_enabler` object and all event
438 * notifiers related to this enabler.
440 __attribute__((visibility("hidden")))
441 int lttng_event_notifier_enabler_enable(
442 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
445 * Disable a `struct lttng_event_notifier_enabler` object and all event
446 * notifiers related to this enabler.
448 __attribute__((visibility("hidden")))
449 int lttng_event_notifier_enabler_disable(
450 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
453 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
454 * all event notifiers related to this enabler.
456 __attribute__((visibility("hidden")))
457 int lttng_event_notifier_enabler_attach_filter_bytecode(
458 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
459 struct lttng_ust_bytecode_node
**bytecode
);
462 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
463 * all event_notifiers related to this enabler.
465 __attribute__((visibility("hidden")))
466 int lttng_event_notifier_enabler_attach_capture_bytecode(
467 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
468 struct lttng_ust_bytecode_node
**bytecode
);
471 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
472 * event notifiers related to this enabler.
474 __attribute__((visibility("hidden")))
475 int lttng_event_notifier_enabler_attach_exclusion(
476 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
477 struct lttng_ust_excluder_node
**excluder
);
479 __attribute__((visibility("hidden")))
480 void lttng_free_event_filter_runtime(struct lttng_ust_event_common
*event
);
483 * Connect the probe on all enablers matching this event description.
484 * Called on library load.
486 __attribute__((visibility("hidden")))
487 int lttng_fix_pending_event_notifiers(void);
489 __attribute__((visibility("hidden")))
490 struct lttng_counter
*lttng_ust_counter_create(
491 const char *counter_transport_name
,
492 size_t number_dimensions
, const struct lttng_counter_dimension
*dimensions
);
494 #ifdef HAVE_PERF_EVENT
496 __attribute__((visibility("hidden")))
497 int lttng_add_perf_counter_to_ctx(uint32_t type
,
500 struct lttng_ctx
**ctx
);
502 __attribute__((visibility("hidden")))
503 int lttng_perf_counter_init(void);
505 __attribute__((visibility("hidden")))
506 void lttng_perf_counter_exit(void);
508 #else /* #ifdef HAVE_PERF_EVENT */
511 int lttng_add_perf_counter_to_ctx(uint32_t type
,
514 struct lttng_ctx
**ctx
)
519 int lttng_perf_counter_init(void)
524 void lttng_perf_counter_exit(void)
527 #endif /* #else #ifdef HAVE_PERF_EVENT */
529 __attribute__((visibility("hidden")))
530 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
532 __attribute__((visibility("hidden")))
533 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
535 __attribute__((visibility("hidden")))
536 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
538 __attribute__((visibility("hidden")))
539 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
541 __attribute__((visibility("hidden")))
542 struct lttng_ust_abi_tracepoint_iter
*
543 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
545 __attribute__((visibility("hidden")))
546 struct lttng_ust_abi_field_iter
*
547 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
549 __attribute__((visibility("hidden")))
550 struct lttng_session
*lttng_session_create(void);
552 __attribute__((visibility("hidden")))
553 int lttng_session_enable(struct lttng_session
*session
);
555 __attribute__((visibility("hidden")))
556 int lttng_session_disable(struct lttng_session
*session
);
558 __attribute__((visibility("hidden")))
559 int lttng_session_statedump(struct lttng_session
*session
);
561 __attribute__((visibility("hidden")))
562 void lttng_session_destroy(struct lttng_session
*session
);
565 * Called with ust lock held.
567 __attribute__((visibility("hidden")))
568 int lttng_session_active(void);
570 __attribute__((visibility("hidden")))
571 struct cds_list_head
*lttng_get_sessions(void);
573 __attribute__((visibility("hidden")))
574 void lttng_handle_pending_statedump(void *owner
);
576 __attribute__((visibility("hidden")))
577 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
578 const char *transport_name
,
580 size_t subbuf_size
, size_t num_subbuf
,
581 unsigned int switch_timer_interval
,
582 unsigned int read_timer_interval
,
583 int **shm_fd
, int **wait_fd
,
584 uint64_t **memory_map_size
,
585 struct lttng_channel
*chan_priv_init
);
587 __attribute__((visibility("hidden")))
588 int lttng_channel_enable(struct lttng_channel
*channel
);
590 __attribute__((visibility("hidden")))
591 int lttng_channel_disable(struct lttng_channel
*channel
);
593 __attribute__((visibility("hidden")))
594 void lttng_transport_register(struct lttng_transport
*transport
);
596 __attribute__((visibility("hidden")))
597 void lttng_transport_unregister(struct lttng_transport
*transport
);
599 /* This is ABI between liblttng-ust and liblttng-ust-ctl */
600 struct lttng_transport
*lttng_ust_transport_find(const char *name
);
602 /* This is ABI between liblttng-ust and liblttng-ust-dl */
603 void lttng_ust_dl_update(void *ip
);
605 __attribute__((visibility("hidden")))
606 void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc
*desc
);
608 __attribute__((visibility("hidden")))
609 int lttng_fix_pending_events(void);
611 __attribute__((visibility("hidden")))
612 struct cds_list_head
*lttng_get_probe_list_head(void);
614 __attribute__((visibility("hidden")))
615 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_session
*session
,
616 const struct lttng_ust_enum_desc
*enum_desc
);
618 __attribute__((visibility("hidden")))
619 int lttng_abi_create_root_handle(void);
621 __attribute__((visibility("hidden")))
622 const struct lttng_ust_abi_objd_ops
*lttng_ust_abi_objd_ops(int id
);
624 __attribute__((visibility("hidden")))
625 int lttng_ust_abi_objd_unref(int id
, int is_owner
);
627 __attribute__((visibility("hidden")))
628 void lttng_ust_abi_exit(void);
630 __attribute__((visibility("hidden")))
631 void lttng_ust_abi_events_exit(void);
633 __attribute__((visibility("hidden")))
634 void lttng_ust_abi_objd_table_owner_cleanup(void *owner
);
636 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */