Refactoring: struct lttng_ust_channel_ops
[lttng-ust.git] / liblttng-ust / ust-events-internal.h
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
19 struct lttng_ust_abi_obj;
20 struct lttng_event_notifier_group;
21
22 union 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
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);
52 };
53
54 enum 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 */
63 struct 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
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;
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
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;
94 };
95
96 enum lttng_ust_bytecode_node_type {
97 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
98 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
99 };
100
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;
105 struct {
106 uint32_t len;
107 uint32_t reloc_offset;
108 uint64_t seqnum;
109 char data[];
110 } bc;
111 };
112
113 struct 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
125 struct tp_list_entry {
126 struct lttng_ust_abi_tracepoint_iter tp;
127 struct cds_list_head head;
128 };
129
130 struct lttng_ust_tracepoint_list {
131 struct tp_list_entry *iter;
132 struct cds_list_head head;
133 };
134
135 struct tp_field_list_entry {
136 struct lttng_ust_abi_field_iter field;
137 struct cds_list_head head;
138 };
139
140 struct 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 */
154 struct 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
160 struct 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
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,
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
188 struct 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
199 struct 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)
205 struct 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
212 struct lttng_ust_enum_ht {
213 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
214 };
215
216 struct 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
230 struct 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
237 struct 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
244 struct 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
254 struct 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
262 struct 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
273 struct 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
285 struct 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
310 struct 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
318 struct lttng_ust_channel_ops_private {
319 struct lttng_ust_channel_ops *pub; /* Public channels ops interface */
320
321 struct lttng_channel *(*channel_create)(const char *name,
322 void *buf_addr,
323 size_t subbuf_size, size_t num_subbuf,
324 unsigned int switch_timer_interval,
325 unsigned int read_timer_interval,
326 unsigned char *uuid,
327 uint32_t chan_id,
328 const int *stream_fds, int nr_stream_fds,
329 int64_t blocking_timeout);
330 void (*channel_destroy)(struct lttng_channel *chan);
331 /*
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.
335 */
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);
342 };
343
344 static inline
345 struct lttng_enabler *lttng_event_enabler_as_enabler(
346 struct lttng_event_enabler *event_enabler)
347 {
348 return &event_enabler->base;
349 }
350
351 static inline
352 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
353 struct lttng_event_notifier_enabler *event_notifier_enabler)
354 {
355 return &event_notifier_enabler->base;
356 }
357
358 /*
359 * Allocate and initialize a `struct lttng_event_enabler` object.
360 *
361 * On success, returns a `struct lttng_event_enabler`,
362 * On memory error, returns NULL.
363 */
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);
369
370 /*
371 * Destroy a `struct lttng_event_enabler` object.
372 */
373 __attribute__((visibility("hidden")))
374 void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
375
376 /*
377 * Enable a `struct lttng_event_enabler` object and all events related to this
378 * enabler.
379 */
380 __attribute__((visibility("hidden")))
381 int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
382
383 /*
384 * Disable a `struct lttng_event_enabler` object and all events related to this
385 * enabler.
386 */
387 __attribute__((visibility("hidden")))
388 int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
389
390 /*
391 * Attach filter bytecode program to `struct lttng_event_enabler` and all
392 * events related to this enabler.
393 */
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);
398
399 /*
400 * Attach an application context to an event enabler.
401 *
402 * Not implemented.
403 */
404 __attribute__((visibility("hidden")))
405 int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
406 struct lttng_ust_abi_context *ctx);
407
408 /*
409 * Attach exclusion list to `struct lttng_event_enabler` and all
410 * events related to this enabler.
411 */
412 __attribute__((visibility("hidden")))
413 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
414 struct lttng_ust_excluder_node **excluder);
415
416 /*
417 * Synchronize bytecodes for the enabler and the instance (event or
418 * event_notifier).
419 *
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.
422 */
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);
428
429 /*
430 * Allocate and initialize a `struct lttng_event_notifier_group` object.
431 *
432 * On success, returns a `struct lttng_triggre_group`,
433 * on memory error, returns NULL.
434 */
435 __attribute__((visibility("hidden")))
436 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
437
438 /*
439 * Destroy a `struct lttng_event_notifier_group` object.
440 */
441 __attribute__((visibility("hidden")))
442 void lttng_event_notifier_group_destroy(
443 struct lttng_event_notifier_group *event_notifier_group);
444
445 /*
446 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
447 *
448 * On success, returns a `struct lttng_event_notifier_enabler`,
449 * On memory error, returns NULL.
450 */
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);
456
457 /*
458 * Destroy a `struct lttng_event_notifier_enabler` object.
459 */
460 __attribute__((visibility("hidden")))
461 void lttng_event_notifier_enabler_destroy(
462 struct lttng_event_notifier_enabler *event_notifier_enabler);
463
464 /*
465 * Enable a `struct lttng_event_notifier_enabler` object and all event
466 * notifiers related to this enabler.
467 */
468 __attribute__((visibility("hidden")))
469 int lttng_event_notifier_enabler_enable(
470 struct lttng_event_notifier_enabler *event_notifier_enabler);
471
472 /*
473 * Disable a `struct lttng_event_notifier_enabler` object and all event
474 * notifiers related to this enabler.
475 */
476 __attribute__((visibility("hidden")))
477 int lttng_event_notifier_enabler_disable(
478 struct lttng_event_notifier_enabler *event_notifier_enabler);
479
480 /*
481 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
482 * all event notifiers related to this enabler.
483 */
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);
488
489 /*
490 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
491 * all event_notifiers related to this enabler.
492 */
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);
497
498 /*
499 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
500 * event notifiers related to this enabler.
501 */
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);
506
507 __attribute__((visibility("hidden")))
508 void lttng_free_event_filter_runtime(struct lttng_ust_event_common *event);
509
510 /*
511 * Connect the probe on all enablers matching this event description.
512 * Called on library load.
513 */
514 __attribute__((visibility("hidden")))
515 int lttng_fix_pending_event_notifiers(void);
516
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);
521
522 #ifdef HAVE_PERF_EVENT
523
524 __attribute__((visibility("hidden")))
525 int lttng_add_perf_counter_to_ctx(uint32_t type,
526 uint64_t config,
527 const char *name,
528 struct lttng_ust_ctx **ctx);
529
530 __attribute__((visibility("hidden")))
531 int lttng_perf_counter_init(void);
532
533 __attribute__((visibility("hidden")))
534 void lttng_perf_counter_exit(void);
535
536 #else /* #ifdef HAVE_PERF_EVENT */
537
538 static inline
539 int lttng_add_perf_counter_to_ctx(uint32_t type,
540 uint64_t config,
541 const char *name,
542 struct lttng_ust_ctx **ctx)
543 {
544 return -ENOSYS;
545 }
546 static inline
547 int lttng_perf_counter_init(void)
548 {
549 return 0;
550 }
551 static inline
552 void lttng_perf_counter_exit(void)
553 {
554 }
555 #endif /* #else #ifdef HAVE_PERF_EVENT */
556
557 __attribute__((visibility("hidden")))
558 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
559
560 __attribute__((visibility("hidden")))
561 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
562
563 __attribute__((visibility("hidden")))
564 int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
565
566 __attribute__((visibility("hidden")))
567 void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
568
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);
572
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);
576
577 __attribute__((visibility("hidden")))
578 struct lttng_ust_session *lttng_session_create(void);
579
580 __attribute__((visibility("hidden")))
581 int lttng_session_enable(struct lttng_ust_session *session);
582
583 __attribute__((visibility("hidden")))
584 int lttng_session_disable(struct lttng_ust_session *session);
585
586 __attribute__((visibility("hidden")))
587 int lttng_session_statedump(struct lttng_ust_session *session);
588
589 __attribute__((visibility("hidden")))
590 void lttng_session_destroy(struct lttng_ust_session *session);
591
592 /*
593 * Called with ust lock held.
594 */
595 __attribute__((visibility("hidden")))
596 int lttng_session_active(void);
597
598 __attribute__((visibility("hidden")))
599 struct cds_list_head *lttng_get_sessions(void);
600
601 __attribute__((visibility("hidden")))
602 void lttng_handle_pending_statedump(void *owner);
603
604 __attribute__((visibility("hidden")))
605 struct lttng_channel *lttng_channel_create(struct lttng_ust_session *session,
606 const char *transport_name,
607 void *buf_addr,
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);
614
615 __attribute__((visibility("hidden")))
616 int lttng_channel_enable(struct lttng_channel *channel);
617
618 __attribute__((visibility("hidden")))
619 int lttng_channel_disable(struct lttng_channel *channel);
620
621 __attribute__((visibility("hidden")))
622 void lttng_transport_register(struct lttng_transport *transport);
623
624 __attribute__((visibility("hidden")))
625 void lttng_transport_unregister(struct lttng_transport *transport);
626
627 /* This is ABI between liblttng-ust and liblttng-ust-ctl */
628 struct lttng_transport *lttng_ust_transport_find(const char *name);
629
630 /* This is ABI between liblttng-ust and liblttng-ust-dl */
631 void lttng_ust_dl_update(void *ip);
632
633 __attribute__((visibility("hidden")))
634 void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc);
635
636 __attribute__((visibility("hidden")))
637 int lttng_fix_pending_events(void);
638
639 __attribute__((visibility("hidden")))
640 struct cds_list_head *lttng_get_probe_list_head(void);
641
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);
645
646 __attribute__((visibility("hidden")))
647 int lttng_abi_create_root_handle(void);
648
649 __attribute__((visibility("hidden")))
650 const struct lttng_ust_abi_objd_ops *lttng_ust_abi_objd_ops(int id);
651
652 __attribute__((visibility("hidden")))
653 int lttng_ust_abi_objd_unref(int id, int is_owner);
654
655 __attribute__((visibility("hidden")))
656 void lttng_ust_abi_exit(void);
657
658 __attribute__((visibility("hidden")))
659 void lttng_ust_abi_events_exit(void);
660
661 __attribute__((visibility("hidden")))
662 void lttng_ust_abi_objd_table_owner_cleanup(void *owner);
663
664 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.04186 seconds and 4 git commands to generate.