Move struct lttng_enum to internal header
[lttng-ust.git] / liblttng-ust / ust-events-internal.h
CommitLineData
d871c65b 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
d871c65b 3 *
c0c0989a 4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
d871c65b
FD
5 */
6
c0c0989a
MJ
7#ifndef _LTTNG_UST_EVENTS_INTERNAL_H
8#define _LTTNG_UST_EVENTS_INTERNAL_H
9
d871c65b
FD
10#include <stdint.h>
11
12#include <urcu/list.h>
13#include <urcu/hlist.h>
14
864a1eda 15#include <ust-helper.h>
d871c65b
FD
16#include <lttng/ust-events.h>
17
fd17d7ce
MD
18
19struct lttng_ust_abi_obj;
20
21union lttng_ust_abi_args {
22 struct {
23 void *chan_data;
24 int wakeup_fd;
25 } channel;
26 struct {
27 int shm_fd;
28 int wakeup_fd;
29 } stream;
30 struct {
31 struct lttng_ust_abi_field_iter entry;
32 } field_list;
33 struct {
34 char *ctxname;
35 } app_context;
36 struct {
37 int event_notifier_notif_fd;
38 } event_notifier_handle;
39 struct {
40 void *counter_data;
41 } counter;
42 struct {
43 int shm_fd;
44 } counter_shm;
45};
46
47struct 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);
51};
52
8665f6a4
MJ
53enum lttng_enabler_format_type {
54 LTTNG_ENABLER_FORMAT_STAR_GLOB,
55 LTTNG_ENABLER_FORMAT_EVENT,
56};
57
58/*
59 * Enabler field, within whatever object is enabling an event. Target of
60 * backward reference.
61 */
62struct lttng_enabler {
63 enum lttng_enabler_format_type format_type;
64
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;
69
fd17d7ce 70 struct lttng_ust_abi_event event_param;
8665f6a4
MJ
71 unsigned int enabled:1;
72};
73
d871c65b
FD
74struct lttng_event_enabler {
75 struct lttng_enabler base;
76 struct cds_list_head node; /* per-session list of enablers */
77 struct lttng_channel *chan;
78 /*
79 * Unused, but kept around to make it explicit that the tracer can do
80 * it.
81 */
82 struct lttng_ctx *ctx;
83};
84
d8d2416d
FD
85struct lttng_event_notifier_enabler {
86 struct lttng_enabler base;
6566528b 87 uint64_t error_counter_index;
d37ecb3f
FD
88 struct cds_list_head node; /* per-app list of event_notifier enablers */
89 struct cds_list_head capture_bytecode_head;
d8d2416d
FD
90 struct lttng_event_notifier_group *group; /* weak ref */
91 uint64_t user_token; /* User-provided token */
d37ecb3f 92 uint64_t num_captures;
d8d2416d
FD
93};
94
ab249ecf
FD
95enum lttng_ust_bytecode_node_type {
96 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
d37ecb3f 97 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
ab249ecf
FD
98};
99
100struct lttng_ust_bytecode_node {
101 enum lttng_ust_bytecode_node_type type;
92495593
FD
102 struct cds_list_head node;
103 struct lttng_enabler *enabler;
ab249ecf
FD
104 struct {
105 uint32_t len;
106 uint32_t reloc_offset;
107 uint64_t seqnum;
108 char data[];
109 } bc;
92495593
FD
110};
111
112struct lttng_ust_excluder_node {
113 struct cds_list_head node;
114 struct lttng_enabler *enabler;
115 /*
116 * struct lttng_ust_event_exclusion had variable sized array,
117 * must be last field.
118 */
fd17d7ce 119 struct lttng_ust_abi_event_exclusion excluder;
92495593
FD
120};
121
bb7ad29d
MJ
122/* Data structures used by the tracer. */
123
124struct tp_list_entry {
fd17d7ce 125 struct lttng_ust_abi_tracepoint_iter tp;
bb7ad29d
MJ
126 struct cds_list_head head;
127};
128
129struct lttng_ust_tracepoint_list {
130 struct tp_list_entry *iter;
131 struct cds_list_head head;
132};
133
134struct tp_field_list_entry {
fd17d7ce 135 struct lttng_ust_abi_field_iter field;
bb7ad29d
MJ
136 struct cds_list_head head;
137};
138
139struct lttng_ust_field_list {
140 struct tp_field_list_entry *iter;
141 struct cds_list_head head;
142};
143
144/*
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
148 * object.
149 *
150 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
151 * event with the name "my_app:abc".
152 */
153struct lttng_enabler_ref {
154 struct cds_list_head node; /* enabler ref list */
155 struct lttng_enabler *ref; /* backward ref */
156};
157
158#define LTTNG_COUNTER_DIMENSION_MAX 8
159struct lttng_counter_dimension {
160 uint64_t size;
161 uint64_t underflow_index;
162 uint64_t overflow_index;
163 uint8_t has_underflow;
164 uint8_t has_overflow;
165};
166
167struct lttng_counter {
168 int objd;
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;
173};
174
175struct lttng_event_notifier_group {
176 int objd;
177 void *owner;
178 int notification_fd;
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. */
184
185 struct lttng_counter *error_counter;
186 size_t error_counter_len;
187};
188
189struct lttng_transport {
190 char *name;
191 struct cds_list_head node;
49926dbd 192 struct lttng_ust_channel_ops ops;
bb7ad29d
MJ
193 const struct lttng_ust_lib_ring_buffer_config *client_config;
194};
195
196struct lttng_counter_transport {
197 char *name;
198 struct cds_list_head node;
199 struct lttng_counter_ops ops;
200 const struct lib_counter_config *client_config;
201};
202
80333dfa 203struct lttng_ust_event_common_private {
7ee76145 204 struct lttng_ust_event_common *pub; /* Public event interface */
68bb7559 205
dc11f93f 206 const struct lttng_ust_event_desc *desc;
68bb7559
MD
207 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
208 struct cds_list_head enablers_ref_head;
68bb7559 209 int registered; /* has reg'd tracepoint probe */
115db533 210 uint64_t user_token;
68bb7559
MD
211};
212
2e70391c 213struct lttng_ust_event_recorder_private {
80333dfa
MD
214 struct lttng_ust_event_common_private parent;
215
2e70391c 216 struct lttng_ust_event_recorder *pub; /* Public event interface */
ba99fbe2
MD
217 struct cds_list_head node; /* Event recorder list */
218 struct cds_hlist_node hlist; /* Hash table of event recorders */
80333dfa
MD
219};
220
115db533
MD
221struct lttng_ust_event_notifier_private {
222 struct lttng_ust_event_common_private parent;
223
d7d45c0d 224 struct lttng_ust_event_notifier *pub; /* Public event notifier interface */
115db533
MD
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;
ba99fbe2
MD
228 struct cds_list_head node; /* Event notifier list */
229 struct cds_hlist_node hlist; /* Hash table of event notifiers */
115db533
MD
230};
231
362a65de
MD
232struct lttng_ust_bytecode_runtime_private {
233 struct bytecode_runtime *pub; /* Public bytecode runtime interface */
234
235 struct lttng_ust_bytecode_node *bc;
236 int link_failed;
237 /*
238 * Pointer to a URCU-protected pointer owned by an `struct
239 * lttng_session`or `struct lttng_event_notifier_group`.
240 */
241 struct lttng_ctx **pctx;
242};
243
bdb12629
MD
244struct lttng_ust_session_private {
245 struct lttng_session *pub; /* Public session interface */
246
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 */
252
253 /* New UST 2.1 */
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 */
259
260 /* New UST 2.4 */
261 int statedump_pending:1;
262
263 /* New UST 2.8 */
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. */
267};
268
036d17fb
MD
269struct lttng_enum {
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 */
275};
276
d871c65b
FD
277static inline
278struct lttng_enabler *lttng_event_enabler_as_enabler(
279 struct lttng_event_enabler *event_enabler)
280{
281 return &event_enabler->base;
282}
283
d8d2416d
FD
284static inline
285struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
286 struct lttng_event_notifier_enabler *event_notifier_enabler)
287{
288 return &event_notifier_enabler->base;
289}
d871c65b
FD
290
291/*
292 * Allocate and initialize a `struct lttng_event_enabler` object.
293 *
294 * On success, returns a `struct lttng_event_enabler`,
295 * On memory error, returns NULL.
296 */
297LTTNG_HIDDEN
298struct lttng_event_enabler *lttng_event_enabler_create(
299 enum lttng_enabler_format_type format_type,
fd17d7ce 300 struct lttng_ust_abi_event *event_param,
d871c65b
FD
301 struct lttng_channel *chan);
302
303/*
304 * Destroy a `struct lttng_event_enabler` object.
305 */
306LTTNG_HIDDEN
307void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
308
309/*
310 * Enable a `struct lttng_event_enabler` object and all events related to this
311 * enabler.
312 */
313LTTNG_HIDDEN
314int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
315
316/*
317 * Disable a `struct lttng_event_enabler` object and all events related to this
318 * enabler.
319 */
320LTTNG_HIDDEN
321int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
322
323/*
324 * Attach filter bytecode program to `struct lttng_event_enabler` and all
325 * events related to this enabler.
326 */
327LTTNG_HIDDEN
a56fd376
FD
328int lttng_event_enabler_attach_filter_bytecode(
329 struct lttng_event_enabler *enabler,
ab89263e 330 struct lttng_ust_bytecode_node **bytecode);
d871c65b
FD
331
332/*
333 * Attach an application context to an event enabler.
334 *
335 * Not implemented.
336 */
337LTTNG_HIDDEN
338int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
fd17d7ce 339 struct lttng_ust_abi_context *ctx);
d871c65b
FD
340
341/*
342 * Attach exclusion list to `struct lttng_event_enabler` and all
343 * events related to this enabler.
344 */
345LTTNG_HIDDEN
346int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
e9fe6aad 347 struct lttng_ust_excluder_node **excluder);
d871c65b
FD
348
349/*
d37ecb3f
FD
350 * Synchronize bytecodes for the enabler and the instance (event or
351 * event_notifier).
d871c65b 352 *
621c07fc 353 * This function goes over all bytecode programs of the enabler (event or
d37ecb3f 354 * event_notifier enabler) to ensure each is linked to the provided instance.
d871c65b
FD
355 */
356LTTNG_HIDDEN
dc11f93f 357void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc,
53b9d7db 358 struct lttng_ctx **ctx,
621c07fc
FD
359 struct cds_list_head *instance_bytecode_runtime_head,
360 struct cds_list_head *enabler_bytecode_runtime_head);
d871c65b 361
d8d2416d
FD
362/*
363 * Allocate and initialize a `struct lttng_event_notifier_group` object.
364 *
365 * On success, returns a `struct lttng_triggre_group`,
366 * on memory error, returns NULL.
367 */
368LTTNG_HIDDEN
369struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
370
371/*
372 * Destroy a `struct lttng_event_notifier_group` object.
373 */
374LTTNG_HIDDEN
375void lttng_event_notifier_group_destroy(
376 struct lttng_event_notifier_group *event_notifier_group);
377
378/*
379 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
380 *
381 * On success, returns a `struct lttng_event_notifier_enabler`,
382 * On memory error, returns NULL.
383 */
384LTTNG_HIDDEN
385struct 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,
fd17d7ce 388 struct lttng_ust_abi_event_notifier *event_notifier_param);
d8d2416d
FD
389
390/*
391 * Destroy a `struct lttng_event_notifier_enabler` object.
392 */
393LTTNG_HIDDEN
394void lttng_event_notifier_enabler_destroy(
395 struct lttng_event_notifier_enabler *event_notifier_enabler);
396
397/*
398 * Enable a `struct lttng_event_notifier_enabler` object and all event
399 * notifiers related to this enabler.
400 */
401LTTNG_HIDDEN
402int lttng_event_notifier_enabler_enable(
403 struct lttng_event_notifier_enabler *event_notifier_enabler);
404
405/*
406 * Disable a `struct lttng_event_notifier_enabler` object and all event
407 * notifiers related to this enabler.
408 */
409LTTNG_HIDDEN
410int lttng_event_notifier_enabler_disable(
411 struct lttng_event_notifier_enabler *event_notifier_enabler);
412
413/*
414 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
415 * all event notifiers related to this enabler.
416 */
417LTTNG_HIDDEN
a56fd376 418int lttng_event_notifier_enabler_attach_filter_bytecode(
d8d2416d 419 struct lttng_event_notifier_enabler *event_notifier_enabler,
ab89263e 420 struct lttng_ust_bytecode_node **bytecode);
d8d2416d 421
d37ecb3f
FD
422/*
423 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
424 * all event_notifiers related to this enabler.
425 */
426LTTNG_HIDDEN
427int lttng_event_notifier_enabler_attach_capture_bytecode(
428 struct lttng_event_notifier_enabler *event_notifier_enabler,
49cde654 429 struct lttng_ust_bytecode_node **bytecode);
d37ecb3f 430
d8d2416d
FD
431/*
432 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
433 * event notifiers related to this enabler.
434 */
435LTTNG_HIDDEN
436int lttng_event_notifier_enabler_attach_exclusion(
437 struct lttng_event_notifier_enabler *event_notifier_enabler,
e9fe6aad 438 struct lttng_ust_excluder_node **excluder);
d8d2416d 439
7753d283 440LTTNG_HIDDEN
b1f720f0 441void lttng_free_event_filter_runtime(struct lttng_ust_event_common *event);
d8d2416d
FD
442
443/*
444 * Connect the probe on all enablers matching this event description.
445 * Called on library load.
446 */
447LTTNG_HIDDEN
448int lttng_fix_pending_event_notifiers(void);
449
67d4e8f5
MJ
450LTTNG_HIDDEN
451struct lttng_counter *lttng_ust_counter_create(
452 const char *counter_transport_name,
453 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
454
bd8c1787
MJ
455#ifdef HAVE_PERF_EVENT
456
457LTTNG_HIDDEN
458int lttng_add_perf_counter_to_ctx(uint32_t type,
459 uint64_t config,
460 const char *name,
461 struct lttng_ctx **ctx);
462LTTNG_HIDDEN
463int lttng_perf_counter_init(void);
464LTTNG_HIDDEN
465void lttng_perf_counter_exit(void);
466
467#else /* #ifdef HAVE_PERF_EVENT */
468
469static inline
470int lttng_add_perf_counter_to_ctx(uint32_t type,
471 uint64_t config,
472 const char *name,
473 struct lttng_ctx **ctx)
474{
475 return -ENOSYS;
476}
477static inline
478int lttng_perf_counter_init(void)
479{
480 return 0;
481}
482static inline
483void lttng_perf_counter_exit(void)
484{
485}
486#endif /* #else #ifdef HAVE_PERF_EVENT */
487
7753d283
MJ
488LTTNG_HIDDEN
489int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
490LTTNG_HIDDEN
491void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
492
493LTTNG_HIDDEN
494int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
495LTTNG_HIDDEN
496void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
497
498LTTNG_HIDDEN
fd17d7ce 499struct lttng_ust_abi_tracepoint_iter *
7753d283
MJ
500 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
501LTTNG_HIDDEN
fd17d7ce 502struct lttng_ust_abi_field_iter *
7753d283
MJ
503 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
504
505LTTNG_HIDDEN
506struct lttng_session *lttng_session_create(void);
507LTTNG_HIDDEN
508int lttng_session_enable(struct lttng_session *session);
509LTTNG_HIDDEN
510int lttng_session_disable(struct lttng_session *session);
511LTTNG_HIDDEN
512int lttng_session_statedump(struct lttng_session *session);
513LTTNG_HIDDEN
514void lttng_session_destroy(struct lttng_session *session);
515
516LTTNG_HIDDEN
517struct cds_list_head *lttng_get_sessions(void);
518
519LTTNG_HIDDEN
520void lttng_handle_pending_statedump(void *owner);
521
522LTTNG_HIDDEN
523struct lttng_channel *lttng_channel_create(struct lttng_session *session,
524 const char *transport_name,
525 void *buf_addr,
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);
532
533LTTNG_HIDDEN
534int lttng_channel_enable(struct lttng_channel *channel);
535LTTNG_HIDDEN
536int lttng_channel_disable(struct lttng_channel *channel);
537
538LTTNG_HIDDEN
539void lttng_transport_register(struct lttng_transport *transport);
540LTTNG_HIDDEN
541void lttng_transport_unregister(struct lttng_transport *transport);
542
543LTTNG_HIDDEN
dc11f93f 544void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc);
7753d283
MJ
545
546LTTNG_HIDDEN
547int lttng_fix_pending_events(void);
548
549LTTNG_HIDDEN
550struct cds_list_head *lttng_get_probe_list_head(void);
551
552LTTNG_HIDDEN
553struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
891d6b55 554 const struct lttng_ust_enum_desc *enum_desc);
7753d283 555
fd17d7ce
MD
556LTTNG_HIDDEN
557int lttng_abi_create_root_handle(void);
558
559LTTNG_HIDDEN
560const struct lttng_ust_abi_objd_ops *lttng_ust_abi_objd_ops(int id);
561LTTNG_HIDDEN
562int lttng_ust_abi_objd_unref(int id, int is_owner);
563LTTNG_HIDDEN
564void lttng_ust_abi_exit(void);
565LTTNG_HIDDEN
566void lttng_ust_abi_events_exit(void);
567LTTNG_HIDDEN
568void lttng_ust_abi_objd_table_owner_cleanup(void *owner);
569
d871c65b 570#endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.058566 seconds and 4 git commands to generate.