e6064275fd9efcdbbd68334b6230117c8588daa3
[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
18 struct lttng_ust_abi_obj;
19
20 union lttng_ust_abi_args {
21 struct {
22 void *chan_data;
23 int wakeup_fd;
24 } channel;
25 struct {
26 int shm_fd;
27 int wakeup_fd;
28 } stream;
29 struct {
30 struct lttng_ust_abi_field_iter entry;
31 } field_list;
32 struct {
33 char *ctxname;
34 } app_context;
35 struct {
36 int event_notifier_notif_fd;
37 } event_notifier_handle;
38 struct {
39 void *counter_data;
40 } counter;
41 struct {
42 int shm_fd;
43 } counter_shm;
44 };
45
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);
50 };
51
52 enum lttng_enabler_format_type {
53 LTTNG_ENABLER_FORMAT_STAR_GLOB,
54 LTTNG_ENABLER_FORMAT_EVENT,
55 };
56
57 /*
58 * Enabler field, within whatever object is enabling an event. Target of
59 * backward reference.
60 */
61 struct lttng_enabler {
62 enum lttng_enabler_format_type format_type;
63
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;
68
69 struct lttng_ust_abi_event event_param;
70 unsigned int enabled:1;
71 };
72
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;
77 /*
78 * Unused, but kept around to make it explicit that the tracer can do
79 * it.
80 */
81 struct lttng_ctx *ctx;
82 };
83
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;
92 };
93
94 enum lttng_ust_bytecode_node_type {
95 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
96 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
97 };
98
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;
103 struct {
104 uint32_t len;
105 uint32_t reloc_offset;
106 uint64_t seqnum;
107 char data[];
108 } bc;
109 };
110
111 struct lttng_ust_excluder_node {
112 struct cds_list_head node;
113 struct lttng_enabler *enabler;
114 /*
115 * struct lttng_ust_event_exclusion had variable sized array,
116 * must be last field.
117 */
118 struct lttng_ust_abi_event_exclusion excluder;
119 };
120
121 /* Data structures used by the tracer. */
122
123 struct tp_list_entry {
124 struct lttng_ust_abi_tracepoint_iter tp;
125 struct cds_list_head head;
126 };
127
128 struct lttng_ust_tracepoint_list {
129 struct tp_list_entry *iter;
130 struct cds_list_head head;
131 };
132
133 struct tp_field_list_entry {
134 struct lttng_ust_abi_field_iter field;
135 struct cds_list_head head;
136 };
137
138 struct lttng_ust_field_list {
139 struct tp_field_list_entry *iter;
140 struct cds_list_head head;
141 };
142
143 /*
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
147 * object.
148 *
149 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
150 * event with the name "my_app:abc".
151 */
152 struct lttng_enabler_ref {
153 struct cds_list_head node; /* enabler ref list */
154 struct lttng_enabler *ref; /* backward ref */
155 };
156
157 #define LTTNG_COUNTER_DIMENSION_MAX 8
158 struct lttng_counter_dimension {
159 uint64_t size;
160 uint64_t underflow_index;
161 uint64_t overflow_index;
162 uint8_t has_underflow;
163 uint8_t has_overflow;
164 };
165
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,
173 bool is_daemon);
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);
184 };
185
186 struct lttng_counter {
187 int objd;
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;
192 };
193
194 #define LTTNG_UST_EVENT_HT_BITS 12
195 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
196
197 struct lttng_ust_event_ht {
198 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
199 };
200
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];
205 };
206
207 #define LTTNG_UST_ENUM_HT_BITS 12
208 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
209
210 struct lttng_ust_enum_ht {
211 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
212 };
213
214 struct lttng_event_notifier_group {
215 int objd;
216 void *owner;
217 int notification_fd;
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. */
223
224 struct lttng_counter *error_counter;
225 size_t error_counter_len;
226 };
227
228 struct lttng_transport {
229 char *name;
230 struct cds_list_head node;
231 struct lttng_ust_channel_ops ops;
232 const struct lttng_ust_lib_ring_buffer_config *client_config;
233 };
234
235 struct lttng_counter_transport {
236 char *name;
237 struct cds_list_head node;
238 struct lttng_counter_ops ops;
239 const struct lib_counter_config *client_config;
240 };
241
242 struct lttng_ust_event_common_private {
243 struct lttng_ust_event_common *pub; /* Public event interface */
244
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 */
249 uint64_t user_token;
250 };
251
252 struct lttng_ust_event_recorder_private {
253 struct lttng_ust_event_common_private parent;
254
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 */
258 };
259
260 struct lttng_ust_event_notifier_private {
261 struct lttng_ust_event_common_private parent;
262
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 */
269 };
270
271 struct lttng_ust_bytecode_runtime_private {
272 struct bytecode_runtime *pub; /* Public bytecode runtime interface */
273
274 struct lttng_ust_bytecode_node *bc;
275 int link_failed;
276 /*
277 * Pointer to a URCU-protected pointer owned by an `struct
278 * lttng_session`or `struct lttng_event_notifier_group`.
279 */
280 struct lttng_ctx **pctx;
281 };
282
283 struct lttng_ust_session_private {
284 struct lttng_session *pub; /* Public session interface */
285
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 */
291
292 /* New UST 2.1 */
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 */
298
299 /* New UST 2.4 */
300 int statedump_pending:1;
301
302 /* New UST 2.8 */
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. */
306 };
307
308 struct lttng_enum {
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 */
314 };
315
316 static inline
317 struct lttng_enabler *lttng_event_enabler_as_enabler(
318 struct lttng_event_enabler *event_enabler)
319 {
320 return &event_enabler->base;
321 }
322
323 static inline
324 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
325 struct lttng_event_notifier_enabler *event_notifier_enabler)
326 {
327 return &event_notifier_enabler->base;
328 }
329
330 /*
331 * Allocate and initialize a `struct lttng_event_enabler` object.
332 *
333 * On success, returns a `struct lttng_event_enabler`,
334 * On memory error, returns NULL.
335 */
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);
341
342 /*
343 * Destroy a `struct lttng_event_enabler` object.
344 */
345 __attribute__((visibility("hidden")))
346 void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
347
348 /*
349 * Enable a `struct lttng_event_enabler` object and all events related to this
350 * enabler.
351 */
352 __attribute__((visibility("hidden")))
353 int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
354
355 /*
356 * Disable a `struct lttng_event_enabler` object and all events related to this
357 * enabler.
358 */
359 __attribute__((visibility("hidden")))
360 int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
361
362 /*
363 * Attach filter bytecode program to `struct lttng_event_enabler` and all
364 * events related to this enabler.
365 */
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);
370
371 /*
372 * Attach an application context to an event enabler.
373 *
374 * Not implemented.
375 */
376 __attribute__((visibility("hidden")))
377 int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
378 struct lttng_ust_abi_context *ctx);
379
380 /*
381 * Attach exclusion list to `struct lttng_event_enabler` and all
382 * events related to this enabler.
383 */
384 __attribute__((visibility("hidden")))
385 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
386 struct lttng_ust_excluder_node **excluder);
387
388 /*
389 * Synchronize bytecodes for the enabler and the instance (event or
390 * event_notifier).
391 *
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.
394 */
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);
400
401 /*
402 * Allocate and initialize a `struct lttng_event_notifier_group` object.
403 *
404 * On success, returns a `struct lttng_triggre_group`,
405 * on memory error, returns NULL.
406 */
407 __attribute__((visibility("hidden")))
408 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
409
410 /*
411 * Destroy a `struct lttng_event_notifier_group` object.
412 */
413 __attribute__((visibility("hidden")))
414 void lttng_event_notifier_group_destroy(
415 struct lttng_event_notifier_group *event_notifier_group);
416
417 /*
418 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
419 *
420 * On success, returns a `struct lttng_event_notifier_enabler`,
421 * On memory error, returns NULL.
422 */
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);
428
429 /*
430 * Destroy a `struct lttng_event_notifier_enabler` object.
431 */
432 __attribute__((visibility("hidden")))
433 void lttng_event_notifier_enabler_destroy(
434 struct lttng_event_notifier_enabler *event_notifier_enabler);
435
436 /*
437 * Enable a `struct lttng_event_notifier_enabler` object and all event
438 * notifiers related to this enabler.
439 */
440 __attribute__((visibility("hidden")))
441 int lttng_event_notifier_enabler_enable(
442 struct lttng_event_notifier_enabler *event_notifier_enabler);
443
444 /*
445 * Disable a `struct lttng_event_notifier_enabler` object and all event
446 * notifiers related to this enabler.
447 */
448 __attribute__((visibility("hidden")))
449 int lttng_event_notifier_enabler_disable(
450 struct lttng_event_notifier_enabler *event_notifier_enabler);
451
452 /*
453 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
454 * all event notifiers related to this enabler.
455 */
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);
460
461 /*
462 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
463 * all event_notifiers related to this enabler.
464 */
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);
469
470 /*
471 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
472 * event notifiers related to this enabler.
473 */
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);
478
479 __attribute__((visibility("hidden")))
480 void lttng_free_event_filter_runtime(struct lttng_ust_event_common *event);
481
482 /*
483 * Connect the probe on all enablers matching this event description.
484 * Called on library load.
485 */
486 __attribute__((visibility("hidden")))
487 int lttng_fix_pending_event_notifiers(void);
488
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);
493
494 #ifdef HAVE_PERF_EVENT
495
496 __attribute__((visibility("hidden")))
497 int lttng_add_perf_counter_to_ctx(uint32_t type,
498 uint64_t config,
499 const char *name,
500 struct lttng_ctx **ctx);
501
502 __attribute__((visibility("hidden")))
503 int lttng_perf_counter_init(void);
504
505 __attribute__((visibility("hidden")))
506 void lttng_perf_counter_exit(void);
507
508 #else /* #ifdef HAVE_PERF_EVENT */
509
510 static inline
511 int lttng_add_perf_counter_to_ctx(uint32_t type,
512 uint64_t config,
513 const char *name,
514 struct lttng_ctx **ctx)
515 {
516 return -ENOSYS;
517 }
518 static inline
519 int lttng_perf_counter_init(void)
520 {
521 return 0;
522 }
523 static inline
524 void lttng_perf_counter_exit(void)
525 {
526 }
527 #endif /* #else #ifdef HAVE_PERF_EVENT */
528
529 __attribute__((visibility("hidden")))
530 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
531
532 __attribute__((visibility("hidden")))
533 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
534
535 __attribute__((visibility("hidden")))
536 int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
537
538 __attribute__((visibility("hidden")))
539 void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
540
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);
544
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);
548
549 __attribute__((visibility("hidden")))
550 struct lttng_session *lttng_session_create(void);
551
552 __attribute__((visibility("hidden")))
553 int lttng_session_enable(struct lttng_session *session);
554
555 __attribute__((visibility("hidden")))
556 int lttng_session_disable(struct lttng_session *session);
557
558 __attribute__((visibility("hidden")))
559 int lttng_session_statedump(struct lttng_session *session);
560
561 __attribute__((visibility("hidden")))
562 void lttng_session_destroy(struct lttng_session *session);
563
564 /*
565 * Called with ust lock held.
566 */
567 __attribute__((visibility("hidden")))
568 int lttng_session_active(void);
569
570 __attribute__((visibility("hidden")))
571 struct cds_list_head *lttng_get_sessions(void);
572
573 __attribute__((visibility("hidden")))
574 void lttng_handle_pending_statedump(void *owner);
575
576 __attribute__((visibility("hidden")))
577 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
578 const char *transport_name,
579 void *buf_addr,
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);
586
587 __attribute__((visibility("hidden")))
588 int lttng_channel_enable(struct lttng_channel *channel);
589
590 __attribute__((visibility("hidden")))
591 int lttng_channel_disable(struct lttng_channel *channel);
592
593 __attribute__((visibility("hidden")))
594 void lttng_transport_register(struct lttng_transport *transport);
595
596 __attribute__((visibility("hidden")))
597 void lttng_transport_unregister(struct lttng_transport *transport);
598
599 __attribute__((visibility("hidden")))
600 void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc);
601
602 __attribute__((visibility("hidden")))
603 int lttng_fix_pending_events(void);
604
605 __attribute__((visibility("hidden")))
606 struct cds_list_head *lttng_get_probe_list_head(void);
607
608 __attribute__((visibility("hidden")))
609 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
610 const struct lttng_ust_enum_desc *enum_desc);
611
612 __attribute__((visibility("hidden")))
613 int lttng_abi_create_root_handle(void);
614
615 __attribute__((visibility("hidden")))
616 const struct lttng_ust_abi_objd_ops *lttng_ust_abi_objd_ops(int id);
617
618 __attribute__((visibility("hidden")))
619 int lttng_ust_abi_objd_unref(int id, int is_owner);
620
621 __attribute__((visibility("hidden")))
622 void lttng_ust_abi_exit(void);
623
624 __attribute__((visibility("hidden")))
625 void lttng_ust_abi_events_exit(void);
626
627 __attribute__((visibility("hidden")))
628 void lttng_ust_abi_objd_table_owner_cleanup(void *owner);
629
630 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.042363 seconds and 3 git commands to generate.