Hide forward declaration of struct lttng_event_notifier_group
[lttng-ust.git] / liblttng-ust / ust-events-internal.h
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
5 */
6
7#ifndef _LTTNG_UST_EVENTS_INTERNAL_H
8#define _LTTNG_UST_EVENTS_INTERNAL_H
9
10#include <stdint.h>
11
12#include <urcu/list.h>
13#include <urcu/hlist.h>
14
15#include <lttng/ust-events.h>
16
17#include "ust-context-provider.h"
18
19struct lttng_ust_abi_obj;
20struct lttng_event_notifier_group;
21
22union lttng_ust_abi_args {
23 struct {
24 void *chan_data;
25 int wakeup_fd;
26 } channel;
27 struct {
28 int shm_fd;
29 int wakeup_fd;
30 } stream;
31 struct {
32 struct lttng_ust_abi_field_iter entry;
33 } field_list;
34 struct {
35 char *ctxname;
36 } app_context;
37 struct {
38 int event_notifier_notif_fd;
39 } event_notifier_handle;
40 struct {
41 void *counter_data;
42 } counter;
43 struct {
44 int shm_fd;
45 } counter_shm;
46};
47
48struct 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);
52};
53
54enum lttng_enabler_format_type {
55 LTTNG_ENABLER_FORMAT_STAR_GLOB,
56 LTTNG_ENABLER_FORMAT_EVENT,
57};
58
59/*
60 * Enabler field, within whatever object is enabling an event. Target of
61 * backward reference.
62 */
63struct lttng_enabler {
64 enum lttng_enabler_format_type format_type;
65
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;
70
71 struct lttng_ust_abi_event event_param;
72 unsigned int enabled:1;
73};
74
75struct lttng_event_enabler {
76 struct lttng_enabler base;
77 struct cds_list_head node; /* per-session list of enablers */
78 struct lttng_channel *chan;
79 /*
80 * Unused, but kept around to make it explicit that the tracer can do
81 * it.
82 */
83 struct lttng_ust_ctx *ctx;
84};
85
86struct 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;
94};
95
96enum lttng_ust_bytecode_node_type {
97 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
98 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
99};
100
101struct lttng_ust_bytecode_node {
102 enum lttng_ust_bytecode_node_type type;
103 struct cds_list_head node;
104 struct lttng_enabler *enabler;
105 struct {
106 uint32_t len;
107 uint32_t reloc_offset;
108 uint64_t seqnum;
109 char data[];
110 } bc;
111};
112
113struct lttng_ust_excluder_node {
114 struct cds_list_head node;
115 struct lttng_enabler *enabler;
116 /*
117 * struct lttng_ust_event_exclusion had variable sized array,
118 * must be last field.
119 */
120 struct lttng_ust_abi_event_exclusion excluder;
121};
122
123/* Data structures used by the tracer. */
124
125struct tp_list_entry {
126 struct lttng_ust_abi_tracepoint_iter tp;
127 struct cds_list_head head;
128};
129
130struct lttng_ust_tracepoint_list {
131 struct tp_list_entry *iter;
132 struct cds_list_head head;
133};
134
135struct tp_field_list_entry {
136 struct lttng_ust_abi_field_iter field;
137 struct cds_list_head head;
138};
139
140struct lttng_ust_field_list {
141 struct tp_field_list_entry *iter;
142 struct cds_list_head head;
143};
144
145/*
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
149 * object.
150 *
151 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
152 * event with the name "my_app:abc".
153 */
154struct lttng_enabler_ref {
155 struct cds_list_head node; /* enabler ref list */
156 struct lttng_enabler *ref; /* backward ref */
157};
158
159#define LTTNG_COUNTER_DIMENSION_MAX 8
160struct lttng_counter_dimension {
161 uint64_t size;
162 uint64_t underflow_index;
163 uint64_t overflow_index;
164 uint8_t has_underflow;
165 uint8_t has_overflow;
166};
167
168struct 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,
175 bool is_daemon);
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);
186};
187
188struct lttng_counter {
189 int objd;
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;
194};
195
196#define LTTNG_UST_EVENT_HT_BITS 12
197#define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
198
199struct lttng_ust_event_ht {
200 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
201};
202
203#define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
204#define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
205struct lttng_ust_event_notifier_ht {
206 struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE];
207};
208
209#define LTTNG_UST_ENUM_HT_BITS 12
210#define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
211
212struct lttng_ust_enum_ht {
213 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
214};
215
216struct lttng_event_notifier_group {
217 int objd;
218 void *owner;
219 int notification_fd;
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. */
225
226 struct lttng_counter *error_counter;
227 size_t error_counter_len;
228};
229
230struct lttng_transport {
231 char *name;
232 struct cds_list_head node;
233 struct lttng_ust_channel_ops ops;
234 const struct lttng_ust_lib_ring_buffer_config *client_config;
235};
236
237struct lttng_counter_transport {
238 char *name;
239 struct cds_list_head node;
240 struct lttng_counter_ops ops;
241 const struct lib_counter_config *client_config;
242};
243
244struct lttng_ust_event_common_private {
245 struct lttng_ust_event_common *pub; /* Public event interface */
246
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 */
251 uint64_t user_token;
252};
253
254struct lttng_ust_event_recorder_private {
255 struct lttng_ust_event_common_private parent;
256
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 */
260};
261
262struct lttng_ust_event_notifier_private {
263 struct lttng_ust_event_common_private parent;
264
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 */
271};
272
273struct lttng_ust_bytecode_runtime_private {
274 struct bytecode_runtime *pub; /* Public bytecode runtime interface */
275
276 struct lttng_ust_bytecode_node *bc;
277 int link_failed;
278 /*
279 * Pointer to a URCU-protected pointer owned by an `struct
280 * lttng_session`or `struct lttng_event_notifier_group`.
281 */
282 struct lttng_ust_ctx **pctx;
283};
284
285struct lttng_ust_session_private {
286 struct lttng_ust_session *pub; /* Public session interface */
287
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 */
293
294 /* New UST 2.1 */
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 */
300
301 /* New UST 2.4 */
302 int statedump_pending:1;
303
304 /* New UST 2.8 */
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. */
308};
309
310struct lttng_enum {
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 */
316};
317
318static inline
319struct lttng_enabler *lttng_event_enabler_as_enabler(
320 struct lttng_event_enabler *event_enabler)
321{
322 return &event_enabler->base;
323}
324
325static inline
326struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
327 struct lttng_event_notifier_enabler *event_notifier_enabler)
328{
329 return &event_notifier_enabler->base;
330}
331
332/*
333 * Allocate and initialize a `struct lttng_event_enabler` object.
334 *
335 * On success, returns a `struct lttng_event_enabler`,
336 * On memory error, returns NULL.
337 */
338__attribute__((visibility("hidden")))
339struct lttng_event_enabler *lttng_event_enabler_create(
340 enum lttng_enabler_format_type format_type,
341 struct lttng_ust_abi_event *event_param,
342 struct lttng_channel *chan);
343
344/*
345 * Destroy a `struct lttng_event_enabler` object.
346 */
347__attribute__((visibility("hidden")))
348void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
349
350/*
351 * Enable a `struct lttng_event_enabler` object and all events related to this
352 * enabler.
353 */
354__attribute__((visibility("hidden")))
355int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
356
357/*
358 * Disable a `struct lttng_event_enabler` object and all events related to this
359 * enabler.
360 */
361__attribute__((visibility("hidden")))
362int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
363
364/*
365 * Attach filter bytecode program to `struct lttng_event_enabler` and all
366 * events related to this enabler.
367 */
368__attribute__((visibility("hidden")))
369int lttng_event_enabler_attach_filter_bytecode(
370 struct lttng_event_enabler *enabler,
371 struct lttng_ust_bytecode_node **bytecode);
372
373/*
374 * Attach an application context to an event enabler.
375 *
376 * Not implemented.
377 */
378__attribute__((visibility("hidden")))
379int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
380 struct lttng_ust_abi_context *ctx);
381
382/*
383 * Attach exclusion list to `struct lttng_event_enabler` and all
384 * events related to this enabler.
385 */
386__attribute__((visibility("hidden")))
387int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
388 struct lttng_ust_excluder_node **excluder);
389
390/*
391 * Synchronize bytecodes for the enabler and the instance (event or
392 * event_notifier).
393 *
394 * This function goes over all bytecode programs of the enabler (event or
395 * event_notifier enabler) to ensure each is linked to the provided instance.
396 */
397__attribute__((visibility("hidden")))
398void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc,
399 struct lttng_ust_ctx **ctx,
400 struct cds_list_head *instance_bytecode_runtime_head,
401 struct cds_list_head *enabler_bytecode_runtime_head);
402
403/*
404 * Allocate and initialize a `struct lttng_event_notifier_group` object.
405 *
406 * On success, returns a `struct lttng_triggre_group`,
407 * on memory error, returns NULL.
408 */
409__attribute__((visibility("hidden")))
410struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
411
412/*
413 * Destroy a `struct lttng_event_notifier_group` object.
414 */
415__attribute__((visibility("hidden")))
416void lttng_event_notifier_group_destroy(
417 struct lttng_event_notifier_group *event_notifier_group);
418
419/*
420 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
421 *
422 * On success, returns a `struct lttng_event_notifier_enabler`,
423 * On memory error, returns NULL.
424 */
425__attribute__((visibility("hidden")))
426struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
427 struct lttng_event_notifier_group *event_notifier_group,
428 enum lttng_enabler_format_type format_type,
429 struct lttng_ust_abi_event_notifier *event_notifier_param);
430
431/*
432 * Destroy a `struct lttng_event_notifier_enabler` object.
433 */
434__attribute__((visibility("hidden")))
435void lttng_event_notifier_enabler_destroy(
436 struct lttng_event_notifier_enabler *event_notifier_enabler);
437
438/*
439 * Enable a `struct lttng_event_notifier_enabler` object and all event
440 * notifiers related to this enabler.
441 */
442__attribute__((visibility("hidden")))
443int lttng_event_notifier_enabler_enable(
444 struct lttng_event_notifier_enabler *event_notifier_enabler);
445
446/*
447 * Disable a `struct lttng_event_notifier_enabler` object and all event
448 * notifiers related to this enabler.
449 */
450__attribute__((visibility("hidden")))
451int lttng_event_notifier_enabler_disable(
452 struct lttng_event_notifier_enabler *event_notifier_enabler);
453
454/*
455 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
456 * all event notifiers related to this enabler.
457 */
458__attribute__((visibility("hidden")))
459int lttng_event_notifier_enabler_attach_filter_bytecode(
460 struct lttng_event_notifier_enabler *event_notifier_enabler,
461 struct lttng_ust_bytecode_node **bytecode);
462
463/*
464 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
465 * all event_notifiers related to this enabler.
466 */
467__attribute__((visibility("hidden")))
468int lttng_event_notifier_enabler_attach_capture_bytecode(
469 struct lttng_event_notifier_enabler *event_notifier_enabler,
470 struct lttng_ust_bytecode_node **bytecode);
471
472/*
473 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
474 * event notifiers related to this enabler.
475 */
476__attribute__((visibility("hidden")))
477int lttng_event_notifier_enabler_attach_exclusion(
478 struct lttng_event_notifier_enabler *event_notifier_enabler,
479 struct lttng_ust_excluder_node **excluder);
480
481__attribute__((visibility("hidden")))
482void lttng_free_event_filter_runtime(struct lttng_ust_event_common *event);
483
484/*
485 * Connect the probe on all enablers matching this event description.
486 * Called on library load.
487 */
488__attribute__((visibility("hidden")))
489int lttng_fix_pending_event_notifiers(void);
490
491__attribute__((visibility("hidden")))
492struct lttng_counter *lttng_ust_counter_create(
493 const char *counter_transport_name,
494 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
495
496#ifdef HAVE_PERF_EVENT
497
498__attribute__((visibility("hidden")))
499int lttng_add_perf_counter_to_ctx(uint32_t type,
500 uint64_t config,
501 const char *name,
502 struct lttng_ust_ctx **ctx);
503
504__attribute__((visibility("hidden")))
505int lttng_perf_counter_init(void);
506
507__attribute__((visibility("hidden")))
508void lttng_perf_counter_exit(void);
509
510#else /* #ifdef HAVE_PERF_EVENT */
511
512static inline
513int lttng_add_perf_counter_to_ctx(uint32_t type,
514 uint64_t config,
515 const char *name,
516 struct lttng_ust_ctx **ctx)
517{
518 return -ENOSYS;
519}
520static inline
521int lttng_perf_counter_init(void)
522{
523 return 0;
524}
525static inline
526void lttng_perf_counter_exit(void)
527{
528}
529#endif /* #else #ifdef HAVE_PERF_EVENT */
530
531__attribute__((visibility("hidden")))
532int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
533
534__attribute__((visibility("hidden")))
535void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
536
537__attribute__((visibility("hidden")))
538int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
539
540__attribute__((visibility("hidden")))
541void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
542
543__attribute__((visibility("hidden")))
544struct lttng_ust_abi_tracepoint_iter *
545 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
546
547__attribute__((visibility("hidden")))
548struct lttng_ust_abi_field_iter *
549 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
550
551__attribute__((visibility("hidden")))
552struct lttng_ust_session *lttng_session_create(void);
553
554__attribute__((visibility("hidden")))
555int lttng_session_enable(struct lttng_ust_session *session);
556
557__attribute__((visibility("hidden")))
558int lttng_session_disable(struct lttng_ust_session *session);
559
560__attribute__((visibility("hidden")))
561int lttng_session_statedump(struct lttng_ust_session *session);
562
563__attribute__((visibility("hidden")))
564void lttng_session_destroy(struct lttng_ust_session *session);
565
566/*
567 * Called with ust lock held.
568 */
569__attribute__((visibility("hidden")))
570int lttng_session_active(void);
571
572__attribute__((visibility("hidden")))
573struct cds_list_head *lttng_get_sessions(void);
574
575__attribute__((visibility("hidden")))
576void lttng_handle_pending_statedump(void *owner);
577
578__attribute__((visibility("hidden")))
579struct lttng_channel *lttng_channel_create(struct lttng_ust_session *session,
580 const char *transport_name,
581 void *buf_addr,
582 size_t subbuf_size, size_t num_subbuf,
583 unsigned int switch_timer_interval,
584 unsigned int read_timer_interval,
585 int **shm_fd, int **wait_fd,
586 uint64_t **memory_map_size,
587 struct lttng_channel *chan_priv_init);
588
589__attribute__((visibility("hidden")))
590int lttng_channel_enable(struct lttng_channel *channel);
591
592__attribute__((visibility("hidden")))
593int lttng_channel_disable(struct lttng_channel *channel);
594
595__attribute__((visibility("hidden")))
596void lttng_transport_register(struct lttng_transport *transport);
597
598__attribute__((visibility("hidden")))
599void lttng_transport_unregister(struct lttng_transport *transport);
600
601/* This is ABI between liblttng-ust and liblttng-ust-ctl */
602struct lttng_transport *lttng_ust_transport_find(const char *name);
603
604/* This is ABI between liblttng-ust and liblttng-ust-dl */
605void lttng_ust_dl_update(void *ip);
606
607__attribute__((visibility("hidden")))
608void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc);
609
610__attribute__((visibility("hidden")))
611int lttng_fix_pending_events(void);
612
613__attribute__((visibility("hidden")))
614struct cds_list_head *lttng_get_probe_list_head(void);
615
616__attribute__((visibility("hidden")))
617struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session,
618 const struct lttng_ust_enum_desc *enum_desc);
619
620__attribute__((visibility("hidden")))
621int lttng_abi_create_root_handle(void);
622
623__attribute__((visibility("hidden")))
624const struct lttng_ust_abi_objd_ops *lttng_ust_abi_objd_ops(int id);
625
626__attribute__((visibility("hidden")))
627int lttng_ust_abi_objd_unref(int id, int is_owner);
628
629__attribute__((visibility("hidden")))
630void lttng_ust_abi_exit(void);
631
632__attribute__((visibility("hidden")))
633void lttng_ust_abi_events_exit(void);
634
635__attribute__((visibility("hidden")))
636void lttng_ust_abi_objd_table_owner_cleanup(void *owner);
637
638#endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.024672 seconds and 4 git commands to generate.