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 <ust-helper.h>
16 #include <lttng/ust-events.h>
19 struct lttng_ust_abi_obj
;
21 union lttng_ust_abi_args
{
31 struct lttng_ust_abi_field_iter entry
;
37 int event_notifier_notif_fd
;
38 } event_notifier_handle
;
47 struct lttng_ust_abi_objd_ops
{
48 long (*cmd
)(int objd
, unsigned int cmd
, unsigned long arg
,
49 union lttng_ust_abi_args
*args
, void *owner
);
50 int (*release
)(int objd
);
53 enum lttng_enabler_format_type
{
54 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
55 LTTNG_ENABLER_FORMAT_EVENT
,
59 * Enabler field, within whatever object is enabling an event. Target of
62 struct lttng_enabler
{
63 enum lttng_enabler_format_type format_type
;
65 /* head list of struct lttng_ust_filter_bytecode_node */
66 struct cds_list_head filter_bytecode_head
;
67 /* head list of struct lttng_ust_excluder_node */
68 struct cds_list_head excluder_head
;
70 struct lttng_ust_abi_event event_param
;
71 unsigned int enabled
:1;
74 struct lttng_event_enabler
{
75 struct lttng_enabler base
;
76 struct cds_list_head node
; /* per-session list of enablers */
77 struct lttng_channel
*chan
;
79 * Unused, but kept around to make it explicit that the tracer can do
82 struct lttng_ctx
*ctx
;
85 struct lttng_event_notifier_enabler
{
86 struct lttng_enabler base
;
87 uint64_t error_counter_index
;
88 struct cds_list_head node
; /* per-app list of event_notifier enablers */
89 struct cds_list_head capture_bytecode_head
;
90 struct lttng_event_notifier_group
*group
; /* weak ref */
91 uint64_t user_token
; /* User-provided token */
92 uint64_t num_captures
;
95 enum lttng_ust_bytecode_node_type
{
96 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER
,
97 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE
,
100 struct lttng_ust_bytecode_node
{
101 enum lttng_ust_bytecode_node_type type
;
102 struct cds_list_head node
;
103 struct lttng_enabler
*enabler
;
106 uint32_t reloc_offset
;
112 struct lttng_ust_excluder_node
{
113 struct cds_list_head node
;
114 struct lttng_enabler
*enabler
;
116 * struct lttng_ust_event_exclusion had variable sized array,
117 * must be last field.
119 struct lttng_ust_abi_event_exclusion excluder
;
122 /* Data structures used by the tracer. */
124 struct tp_list_entry
{
125 struct lttng_ust_abi_tracepoint_iter tp
;
126 struct cds_list_head head
;
129 struct lttng_ust_tracepoint_list
{
130 struct tp_list_entry
*iter
;
131 struct cds_list_head head
;
134 struct tp_field_list_entry
{
135 struct lttng_ust_abi_field_iter field
;
136 struct cds_list_head head
;
139 struct lttng_ust_field_list
{
140 struct tp_field_list_entry
*iter
;
141 struct cds_list_head head
;
145 * Objects in a linked-list of enablers, owned by an event or event_notifier.
146 * This is used because an event (or a event_notifier) can be enabled by more
147 * than one enabler and we want a quick way to iterate over all enablers of an
150 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
151 * event with the name "my_app:abc".
153 struct lttng_enabler_ref
{
154 struct cds_list_head node
; /* enabler ref list */
155 struct lttng_enabler
*ref
; /* backward ref */
158 #define LTTNG_COUNTER_DIMENSION_MAX 8
159 struct lttng_counter_dimension
{
161 uint64_t underflow_index
;
162 uint64_t overflow_index
;
163 uint8_t has_underflow
;
164 uint8_t has_overflow
;
167 struct lttng_counter
{
169 struct lttng_event_notifier_group
*event_notifier_group
; /* owner */
170 struct lttng_counter_transport
*transport
;
171 struct lib_counter
*counter
;
172 struct lttng_counter_ops
*ops
;
175 struct lttng_event_notifier_group
{
179 struct cds_list_head node
; /* Event notifier group handle list */
180 struct cds_list_head enablers_head
;
181 struct cds_list_head event_notifiers_head
; /* list of event_notifiers */
182 struct lttng_ust_event_notifier_ht event_notifiers_ht
; /* hashtable of event_notifiers */
183 struct lttng_ctx
*ctx
; /* contexts for filters. */
185 struct lttng_counter
*error_counter
;
186 size_t error_counter_len
;
189 struct lttng_transport
{
191 struct cds_list_head node
;
192 struct lttng_ust_channel_ops ops
;
193 const struct lttng_ust_lib_ring_buffer_config
*client_config
;
196 struct lttng_counter_transport
{
198 struct cds_list_head node
;
199 struct lttng_counter_ops ops
;
200 const struct lib_counter_config
*client_config
;
203 struct lttng_ust_event_common_private
{
204 struct lttng_ust_event_common
*pub
; /* Public event interface */
206 const struct lttng_ust_event_desc
*desc
;
207 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
208 struct cds_list_head enablers_ref_head
;
209 int registered
; /* has reg'd tracepoint probe */
213 struct lttng_ust_event_recorder_private
{
214 struct lttng_ust_event_common_private parent
;
216 struct lttng_ust_event_recorder
*pub
; /* Public event interface */
217 struct cds_list_head node
; /* Event recorder list */
218 struct cds_hlist_node hlist
; /* Hash table of event recorders */
221 struct lttng_ust_event_notifier_private
{
222 struct lttng_ust_event_common_private parent
;
224 struct lttng_ust_event_notifier
*pub
; /* Public event notifier interface */
225 struct lttng_event_notifier_group
*group
; /* weak ref */
226 size_t num_captures
; /* Needed to allocate the msgpack array. */
227 uint64_t error_counter_index
;
228 struct cds_list_head node
; /* Event notifier list */
229 struct cds_hlist_node hlist
; /* Hash table of event notifiers */
232 struct lttng_ust_bytecode_runtime_private
{
233 struct bytecode_runtime
*pub
; /* Public bytecode runtime interface */
235 struct lttng_ust_bytecode_node
*bc
;
238 * Pointer to a URCU-protected pointer owned by an `struct
239 * lttng_session`or `struct lttng_event_notifier_group`.
241 struct lttng_ctx
**pctx
;
244 struct lttng_ust_session_private
{
245 struct lttng_session
*pub
; /* Public session interface */
247 int been_active
; /* Been active ? */
248 int objd
; /* Object associated */
249 struct cds_list_head chan_head
; /* Channel list head */
250 struct cds_list_head events_head
; /* list of events */
251 struct cds_list_head node
; /* Session list */
254 /* List of enablers */
255 struct cds_list_head enablers_head
;
256 struct lttng_ust_event_ht events_ht
; /* ht of events */
257 void *owner
; /* object owner */
258 int tstate
:1; /* Transient enable state */
261 int statedump_pending
:1;
264 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
265 struct cds_list_head enums_head
;
266 struct lttng_ctx
*ctx
; /* contexts for filters. */
270 const struct lttng_ust_enum_desc
*desc
;
271 struct lttng_session
*session
;
272 struct cds_list_head node
; /* Enum list in session */
273 struct cds_hlist_node hlist
; /* Session ht of enums */
274 uint64_t id
; /* Enumeration ID in sessiond */
278 struct lttng_enabler
*lttng_event_enabler_as_enabler(
279 struct lttng_event_enabler
*event_enabler
)
281 return &event_enabler
->base
;
285 struct lttng_enabler
*lttng_event_notifier_enabler_as_enabler(
286 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
288 return &event_notifier_enabler
->base
;
292 * Allocate and initialize a `struct lttng_event_enabler` object.
294 * On success, returns a `struct lttng_event_enabler`,
295 * On memory error, returns NULL.
298 struct lttng_event_enabler
*lttng_event_enabler_create(
299 enum lttng_enabler_format_type format_type
,
300 struct lttng_ust_abi_event
*event_param
,
301 struct lttng_channel
*chan
);
304 * Destroy a `struct lttng_event_enabler` object.
307 void lttng_event_enabler_destroy(struct lttng_event_enabler
*enabler
);
310 * Enable a `struct lttng_event_enabler` object and all events related to this
314 int lttng_event_enabler_enable(struct lttng_event_enabler
*enabler
);
317 * Disable a `struct lttng_event_enabler` object and all events related to this
321 int lttng_event_enabler_disable(struct lttng_event_enabler
*enabler
);
324 * Attach filter bytecode program to `struct lttng_event_enabler` and all
325 * events related to this enabler.
328 int lttng_event_enabler_attach_filter_bytecode(
329 struct lttng_event_enabler
*enabler
,
330 struct lttng_ust_bytecode_node
**bytecode
);
333 * Attach an application context to an event enabler.
338 int lttng_event_enabler_attach_context(struct lttng_event_enabler
*enabler
,
339 struct lttng_ust_abi_context
*ctx
);
342 * Attach exclusion list to `struct lttng_event_enabler` and all
343 * events related to this enabler.
346 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler
*enabler
,
347 struct lttng_ust_excluder_node
**excluder
);
350 * Synchronize bytecodes for the enabler and the instance (event or
353 * This function goes over all bytecode programs of the enabler (event or
354 * event_notifier enabler) to ensure each is linked to the provided instance.
357 void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc
*event_desc
,
358 struct lttng_ctx
**ctx
,
359 struct cds_list_head
*instance_bytecode_runtime_head
,
360 struct cds_list_head
*enabler_bytecode_runtime_head
);
363 * Allocate and initialize a `struct lttng_event_notifier_group` object.
365 * On success, returns a `struct lttng_triggre_group`,
366 * on memory error, returns NULL.
369 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void);
372 * Destroy a `struct lttng_event_notifier_group` object.
375 void lttng_event_notifier_group_destroy(
376 struct lttng_event_notifier_group
*event_notifier_group
);
379 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
381 * On success, returns a `struct lttng_event_notifier_enabler`,
382 * On memory error, returns NULL.
385 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
386 struct lttng_event_notifier_group
*event_notifier_group
,
387 enum lttng_enabler_format_type format_type
,
388 struct lttng_ust_abi_event_notifier
*event_notifier_param
);
391 * Destroy a `struct lttng_event_notifier_enabler` object.
394 void lttng_event_notifier_enabler_destroy(
395 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
398 * Enable a `struct lttng_event_notifier_enabler` object and all event
399 * notifiers related to this enabler.
402 int lttng_event_notifier_enabler_enable(
403 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
406 * Disable a `struct lttng_event_notifier_enabler` object and all event
407 * notifiers related to this enabler.
410 int lttng_event_notifier_enabler_disable(
411 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
414 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
415 * all event notifiers related to this enabler.
418 int lttng_event_notifier_enabler_attach_filter_bytecode(
419 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
420 struct lttng_ust_bytecode_node
**bytecode
);
423 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
424 * all event_notifiers related to this enabler.
427 int lttng_event_notifier_enabler_attach_capture_bytecode(
428 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
429 struct lttng_ust_bytecode_node
**bytecode
);
432 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
433 * event notifiers related to this enabler.
436 int lttng_event_notifier_enabler_attach_exclusion(
437 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
438 struct lttng_ust_excluder_node
**excluder
);
441 void lttng_free_event_filter_runtime(struct lttng_ust_event_common
*event
);
444 * Connect the probe on all enablers matching this event description.
445 * Called on library load.
448 int lttng_fix_pending_event_notifiers(void);
451 struct lttng_counter
*lttng_ust_counter_create(
452 const char *counter_transport_name
,
453 size_t number_dimensions
, const struct lttng_counter_dimension
*dimensions
);
455 #ifdef HAVE_PERF_EVENT
458 int lttng_add_perf_counter_to_ctx(uint32_t type
,
461 struct lttng_ctx
**ctx
);
463 int lttng_perf_counter_init(void);
465 void lttng_perf_counter_exit(void);
467 #else /* #ifdef HAVE_PERF_EVENT */
470 int lttng_add_perf_counter_to_ctx(uint32_t type
,
473 struct lttng_ctx
**ctx
)
478 int lttng_perf_counter_init(void)
483 void lttng_perf_counter_exit(void)
486 #endif /* #else #ifdef HAVE_PERF_EVENT */
489 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
491 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
494 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
496 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
499 struct lttng_ust_abi_tracepoint_iter
*
500 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
502 struct lttng_ust_abi_field_iter
*
503 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
506 struct lttng_session
*lttng_session_create(void);
508 int lttng_session_enable(struct lttng_session
*session
);
510 int lttng_session_disable(struct lttng_session
*session
);
512 int lttng_session_statedump(struct lttng_session
*session
);
514 void lttng_session_destroy(struct lttng_session
*session
);
517 struct cds_list_head
*lttng_get_sessions(void);
520 void lttng_handle_pending_statedump(void *owner
);
523 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
524 const char *transport_name
,
526 size_t subbuf_size
, size_t num_subbuf
,
527 unsigned int switch_timer_interval
,
528 unsigned int read_timer_interval
,
529 int **shm_fd
, int **wait_fd
,
530 uint64_t **memory_map_size
,
531 struct lttng_channel
*chan_priv_init
);
534 int lttng_channel_enable(struct lttng_channel
*channel
);
536 int lttng_channel_disable(struct lttng_channel
*channel
);
539 void lttng_transport_register(struct lttng_transport
*transport
);
541 void lttng_transport_unregister(struct lttng_transport
*transport
);
544 void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc
*desc
);
547 int lttng_fix_pending_events(void);
550 struct cds_list_head
*lttng_get_probe_list_head(void);
553 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_session
*session
,
554 const struct lttng_ust_enum_desc
*enum_desc
);
557 int lttng_abi_create_root_handle(void);
560 const struct lttng_ust_abi_objd_ops
*lttng_ust_abi_objd_ops(int id
);
562 int lttng_ust_abi_objd_unref(int id
, int is_owner
);
564 void lttng_ust_abi_exit(void);
566 void lttng_ust_abi_events_exit(void);
568 void lttng_ust_abi_objd_table_owner_cleanup(void *owner
);
570 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */