f351e954767f0fe0e8c19a6f92fa82e15a507383
[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 <ust-helper.h>
16 #include <lttng/ust-events.h>
17
18
19 struct lttng_ust_abi_obj;
20
21 union 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
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);
51 };
52
53 enum 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 */
62 struct 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
70 struct lttng_ust_abi_event event_param;
71 unsigned int enabled:1;
72 };
73
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;
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
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;
93 };
94
95 enum lttng_ust_bytecode_node_type {
96 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
97 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
98 };
99
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;
104 struct {
105 uint32_t len;
106 uint32_t reloc_offset;
107 uint64_t seqnum;
108 char data[];
109 } bc;
110 };
111
112 struct 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 */
119 struct lttng_ust_abi_event_exclusion excluder;
120 };
121
122 /* Data structures used by the tracer. */
123
124 struct tp_list_entry {
125 struct lttng_ust_abi_tracepoint_iter tp;
126 struct cds_list_head head;
127 };
128
129 struct lttng_ust_tracepoint_list {
130 struct tp_list_entry *iter;
131 struct cds_list_head head;
132 };
133
134 struct tp_field_list_entry {
135 struct lttng_ust_abi_field_iter field;
136 struct cds_list_head head;
137 };
138
139 struct 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 */
153 struct 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
159 struct 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
167 struct 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
175 struct 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
189 struct lttng_transport {
190 char *name;
191 struct cds_list_head node;
192 struct lttng_channel_ops ops;
193 const struct lttng_ust_lib_ring_buffer_config *client_config;
194 };
195
196 struct 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
203 struct lttng_ust_event_common_private {
204 struct lttng_ust_event_common *pub; /* Public event interface */
205
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 */
210 uint64_t user_token;
211 };
212
213 struct lttng_ust_event_recorder_private {
214 struct lttng_ust_event_common_private parent;
215
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 */
219 };
220
221 struct lttng_ust_event_notifier_private {
222 struct lttng_ust_event_common_private parent;
223
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 */
230 };
231
232 struct 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
244 struct 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
269 static inline
270 struct lttng_enabler *lttng_event_enabler_as_enabler(
271 struct lttng_event_enabler *event_enabler)
272 {
273 return &event_enabler->base;
274 }
275
276 static inline
277 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
278 struct lttng_event_notifier_enabler *event_notifier_enabler)
279 {
280 return &event_notifier_enabler->base;
281 }
282
283 /*
284 * Allocate and initialize a `struct lttng_event_enabler` object.
285 *
286 * On success, returns a `struct lttng_event_enabler`,
287 * On memory error, returns NULL.
288 */
289 LTTNG_HIDDEN
290 struct lttng_event_enabler *lttng_event_enabler_create(
291 enum lttng_enabler_format_type format_type,
292 struct lttng_ust_abi_event *event_param,
293 struct lttng_channel *chan);
294
295 /*
296 * Destroy a `struct lttng_event_enabler` object.
297 */
298 LTTNG_HIDDEN
299 void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
300
301 /*
302 * Enable a `struct lttng_event_enabler` object and all events related to this
303 * enabler.
304 */
305 LTTNG_HIDDEN
306 int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
307
308 /*
309 * Disable a `struct lttng_event_enabler` object and all events related to this
310 * enabler.
311 */
312 LTTNG_HIDDEN
313 int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
314
315 /*
316 * Attach filter bytecode program to `struct lttng_event_enabler` and all
317 * events related to this enabler.
318 */
319 LTTNG_HIDDEN
320 int lttng_event_enabler_attach_filter_bytecode(
321 struct lttng_event_enabler *enabler,
322 struct lttng_ust_bytecode_node **bytecode);
323
324 /*
325 * Attach an application context to an event enabler.
326 *
327 * Not implemented.
328 */
329 LTTNG_HIDDEN
330 int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
331 struct lttng_ust_abi_context *ctx);
332
333 /*
334 * Attach exclusion list to `struct lttng_event_enabler` and all
335 * events related to this enabler.
336 */
337 LTTNG_HIDDEN
338 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
339 struct lttng_ust_excluder_node **excluder);
340
341 /*
342 * Synchronize bytecodes for the enabler and the instance (event or
343 * event_notifier).
344 *
345 * This function goes over all bytecode programs of the enabler (event or
346 * event_notifier enabler) to ensure each is linked to the provided instance.
347 */
348 LTTNG_HIDDEN
349 void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc,
350 struct lttng_ctx **ctx,
351 struct cds_list_head *instance_bytecode_runtime_head,
352 struct cds_list_head *enabler_bytecode_runtime_head);
353
354 /*
355 * Allocate and initialize a `struct lttng_event_notifier_group` object.
356 *
357 * On success, returns a `struct lttng_triggre_group`,
358 * on memory error, returns NULL.
359 */
360 LTTNG_HIDDEN
361 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
362
363 /*
364 * Destroy a `struct lttng_event_notifier_group` object.
365 */
366 LTTNG_HIDDEN
367 void lttng_event_notifier_group_destroy(
368 struct lttng_event_notifier_group *event_notifier_group);
369
370 /*
371 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
372 *
373 * On success, returns a `struct lttng_event_notifier_enabler`,
374 * On memory error, returns NULL.
375 */
376 LTTNG_HIDDEN
377 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
378 struct lttng_event_notifier_group *event_notifier_group,
379 enum lttng_enabler_format_type format_type,
380 struct lttng_ust_abi_event_notifier *event_notifier_param);
381
382 /*
383 * Destroy a `struct lttng_event_notifier_enabler` object.
384 */
385 LTTNG_HIDDEN
386 void lttng_event_notifier_enabler_destroy(
387 struct lttng_event_notifier_enabler *event_notifier_enabler);
388
389 /*
390 * Enable a `struct lttng_event_notifier_enabler` object and all event
391 * notifiers related to this enabler.
392 */
393 LTTNG_HIDDEN
394 int lttng_event_notifier_enabler_enable(
395 struct lttng_event_notifier_enabler *event_notifier_enabler);
396
397 /*
398 * Disable a `struct lttng_event_notifier_enabler` object and all event
399 * notifiers related to this enabler.
400 */
401 LTTNG_HIDDEN
402 int lttng_event_notifier_enabler_disable(
403 struct lttng_event_notifier_enabler *event_notifier_enabler);
404
405 /*
406 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
407 * all event notifiers related to this enabler.
408 */
409 LTTNG_HIDDEN
410 int lttng_event_notifier_enabler_attach_filter_bytecode(
411 struct lttng_event_notifier_enabler *event_notifier_enabler,
412 struct lttng_ust_bytecode_node **bytecode);
413
414 /*
415 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
416 * all event_notifiers related to this enabler.
417 */
418 LTTNG_HIDDEN
419 int lttng_event_notifier_enabler_attach_capture_bytecode(
420 struct lttng_event_notifier_enabler *event_notifier_enabler,
421 struct lttng_ust_bytecode_node **bytecode);
422
423 /*
424 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
425 * event notifiers related to this enabler.
426 */
427 LTTNG_HIDDEN
428 int lttng_event_notifier_enabler_attach_exclusion(
429 struct lttng_event_notifier_enabler *event_notifier_enabler,
430 struct lttng_ust_excluder_node **excluder);
431
432 LTTNG_HIDDEN
433 void lttng_free_event_filter_runtime(struct lttng_ust_event_common *event);
434
435 /*
436 * Connect the probe on all enablers matching this event description.
437 * Called on library load.
438 */
439 LTTNG_HIDDEN
440 int lttng_fix_pending_event_notifiers(void);
441
442 LTTNG_HIDDEN
443 struct lttng_counter *lttng_ust_counter_create(
444 const char *counter_transport_name,
445 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
446
447 #ifdef HAVE_PERF_EVENT
448
449 LTTNG_HIDDEN
450 int lttng_add_perf_counter_to_ctx(uint32_t type,
451 uint64_t config,
452 const char *name,
453 struct lttng_ctx **ctx);
454 LTTNG_HIDDEN
455 int lttng_perf_counter_init(void);
456 LTTNG_HIDDEN
457 void lttng_perf_counter_exit(void);
458
459 #else /* #ifdef HAVE_PERF_EVENT */
460
461 static inline
462 int lttng_add_perf_counter_to_ctx(uint32_t type,
463 uint64_t config,
464 const char *name,
465 struct lttng_ctx **ctx)
466 {
467 return -ENOSYS;
468 }
469 static inline
470 int lttng_perf_counter_init(void)
471 {
472 return 0;
473 }
474 static inline
475 void lttng_perf_counter_exit(void)
476 {
477 }
478 #endif /* #else #ifdef HAVE_PERF_EVENT */
479
480 LTTNG_HIDDEN
481 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
482 LTTNG_HIDDEN
483 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
484
485 LTTNG_HIDDEN
486 int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
487 LTTNG_HIDDEN
488 void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
489
490 LTTNG_HIDDEN
491 struct lttng_ust_abi_tracepoint_iter *
492 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
493 LTTNG_HIDDEN
494 struct lttng_ust_abi_field_iter *
495 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
496
497 LTTNG_HIDDEN
498 struct lttng_session *lttng_session_create(void);
499 LTTNG_HIDDEN
500 int lttng_session_enable(struct lttng_session *session);
501 LTTNG_HIDDEN
502 int lttng_session_disable(struct lttng_session *session);
503 LTTNG_HIDDEN
504 int lttng_session_statedump(struct lttng_session *session);
505 LTTNG_HIDDEN
506 void lttng_session_destroy(struct lttng_session *session);
507
508 LTTNG_HIDDEN
509 struct cds_list_head *lttng_get_sessions(void);
510
511 LTTNG_HIDDEN
512 void lttng_handle_pending_statedump(void *owner);
513
514 LTTNG_HIDDEN
515 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
516 const char *transport_name,
517 void *buf_addr,
518 size_t subbuf_size, size_t num_subbuf,
519 unsigned int switch_timer_interval,
520 unsigned int read_timer_interval,
521 int **shm_fd, int **wait_fd,
522 uint64_t **memory_map_size,
523 struct lttng_channel *chan_priv_init);
524
525 LTTNG_HIDDEN
526 int lttng_channel_enable(struct lttng_channel *channel);
527 LTTNG_HIDDEN
528 int lttng_channel_disable(struct lttng_channel *channel);
529
530 LTTNG_HIDDEN
531 void lttng_transport_register(struct lttng_transport *transport);
532 LTTNG_HIDDEN
533 void lttng_transport_unregister(struct lttng_transport *transport);
534
535 LTTNG_HIDDEN
536 void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc);
537
538 LTTNG_HIDDEN
539 int lttng_fix_pending_events(void);
540
541 LTTNG_HIDDEN
542 struct cds_list_head *lttng_get_probe_list_head(void);
543
544 LTTNG_HIDDEN
545 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
546 const struct lttng_ust_enum_desc *enum_desc);
547
548 LTTNG_HIDDEN
549 int lttng_abi_create_root_handle(void);
550
551 LTTNG_HIDDEN
552 const struct lttng_ust_abi_objd_ops *lttng_ust_abi_objd_ops(int id);
553 LTTNG_HIDDEN
554 int lttng_ust_abi_objd_unref(int id, int is_owner);
555 LTTNG_HIDDEN
556 void lttng_ust_abi_exit(void);
557 LTTNG_HIDDEN
558 void lttng_ust_abi_events_exit(void);
559 LTTNG_HIDDEN
560 void lttng_ust_abi_objd_table_owner_cleanup(void *owner);
561
562 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.039843 seconds and 3 git commands to generate.