Refactor event notifier structure
[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 enum lttng_enabler_format_type {
19 LTTNG_ENABLER_FORMAT_STAR_GLOB,
20 LTTNG_ENABLER_FORMAT_EVENT,
21 };
22
23 /*
24 * Enabler field, within whatever object is enabling an event. Target of
25 * backward reference.
26 */
27 struct lttng_enabler {
28 enum lttng_enabler_format_type format_type;
29
30 /* head list of struct lttng_ust_filter_bytecode_node */
31 struct cds_list_head filter_bytecode_head;
32 /* head list of struct lttng_ust_excluder_node */
33 struct cds_list_head excluder_head;
34
35 struct lttng_ust_event event_param;
36 unsigned int enabled:1;
37 };
38
39 struct lttng_event_enabler {
40 struct lttng_enabler base;
41 struct cds_list_head node; /* per-session list of enablers */
42 struct lttng_channel *chan;
43 /*
44 * Unused, but kept around to make it explicit that the tracer can do
45 * it.
46 */
47 struct lttng_ctx *ctx;
48 };
49
50 struct lttng_event_notifier_enabler {
51 struct lttng_enabler base;
52 uint64_t error_counter_index;
53 struct cds_list_head node; /* per-app list of event_notifier enablers */
54 struct cds_list_head capture_bytecode_head;
55 struct lttng_event_notifier_group *group; /* weak ref */
56 uint64_t user_token; /* User-provided token */
57 uint64_t num_captures;
58 };
59
60 enum lttng_ust_bytecode_node_type {
61 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
62 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
63 };
64
65 struct lttng_ust_bytecode_node {
66 enum lttng_ust_bytecode_node_type type;
67 struct cds_list_head node;
68 struct lttng_enabler *enabler;
69 struct {
70 uint32_t len;
71 uint32_t reloc_offset;
72 uint64_t seqnum;
73 char data[];
74 } bc;
75 };
76
77 struct lttng_ust_excluder_node {
78 struct cds_list_head node;
79 struct lttng_enabler *enabler;
80 /*
81 * struct lttng_ust_event_exclusion had variable sized array,
82 * must be last field.
83 */
84 struct lttng_ust_event_exclusion excluder;
85 };
86
87 /* Data structures used by the tracer. */
88
89 struct tp_list_entry {
90 struct lttng_ust_tracepoint_iter tp;
91 struct cds_list_head head;
92 };
93
94 struct lttng_ust_tracepoint_list {
95 struct tp_list_entry *iter;
96 struct cds_list_head head;
97 };
98
99 struct tp_field_list_entry {
100 struct lttng_ust_field_iter field;
101 struct cds_list_head head;
102 };
103
104 struct lttng_ust_field_list {
105 struct tp_field_list_entry *iter;
106 struct cds_list_head head;
107 };
108
109 /*
110 * Objects in a linked-list of enablers, owned by an event or event_notifier.
111 * This is used because an event (or a event_notifier) can be enabled by more
112 * than one enabler and we want a quick way to iterate over all enablers of an
113 * object.
114 *
115 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
116 * event with the name "my_app:abc".
117 */
118 struct lttng_enabler_ref {
119 struct cds_list_head node; /* enabler ref list */
120 struct lttng_enabler *ref; /* backward ref */
121 };
122
123 #define LTTNG_COUNTER_DIMENSION_MAX 8
124 struct lttng_counter_dimension {
125 uint64_t size;
126 uint64_t underflow_index;
127 uint64_t overflow_index;
128 uint8_t has_underflow;
129 uint8_t has_overflow;
130 };
131
132 struct lttng_counter {
133 int objd;
134 struct lttng_event_notifier_group *event_notifier_group; /* owner */
135 struct lttng_counter_transport *transport;
136 struct lib_counter *counter;
137 struct lttng_counter_ops *ops;
138 };
139
140 struct lttng_event_notifier_group {
141 int objd;
142 void *owner;
143 int notification_fd;
144 struct cds_list_head node; /* Event notifier group handle list */
145 struct cds_list_head enablers_head;
146 struct cds_list_head event_notifiers_head; /* list of event_notifiers */
147 struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */
148 struct lttng_ctx *ctx; /* contexts for filters. */
149
150 struct lttng_counter *error_counter;
151 size_t error_counter_len;
152 };
153
154 struct lttng_transport {
155 char *name;
156 struct cds_list_head node;
157 struct lttng_channel_ops ops;
158 const struct lttng_ust_lib_ring_buffer_config *client_config;
159 };
160
161 struct lttng_counter_transport {
162 char *name;
163 struct cds_list_head node;
164 struct lttng_counter_ops ops;
165 const struct lib_counter_config *client_config;
166 };
167
168 struct lttng_ust_event_common_private {
169 struct lttng_ust_event_common *pub; /* Public event interface */
170
171 const struct lttng_event_desc *desc;
172 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
173 struct cds_list_head enablers_ref_head;
174 int registered; /* has reg'd tracepoint probe */
175 uint64_t user_token;
176 };
177
178 struct lttng_ust_event_recorder_private {
179 struct lttng_ust_event_common_private parent;
180
181 struct lttng_ust_event_recorder *pub; /* Public event interface */
182 struct cds_list_head node; /* Event list in session */
183 struct cds_hlist_node hlist; /* session ht of events */
184 };
185
186 struct lttng_ust_event_notifier_private {
187 struct lttng_ust_event_common_private parent;
188
189 struct lttng_event_notifier *pub; /* Public event notifier interface */
190 struct cds_hlist_node hlist; /* hashtable of event_notifiers */
191 struct cds_list_head node; /* event_notifier list in session */
192 struct lttng_event_notifier_group *group; /* weak ref */
193 size_t num_captures; /* Needed to allocate the msgpack array. */
194 uint64_t error_counter_index;
195 };
196
197 struct lttng_ust_bytecode_runtime_private {
198 struct bytecode_runtime *pub; /* Public bytecode runtime interface */
199
200 struct lttng_ust_bytecode_node *bc;
201 int link_failed;
202 /*
203 * Pointer to a URCU-protected pointer owned by an `struct
204 * lttng_session`or `struct lttng_event_notifier_group`.
205 */
206 struct lttng_ctx **pctx;
207 };
208
209 struct lttng_ust_session_private {
210 struct lttng_session *pub; /* Public session interface */
211
212 int been_active; /* Been active ? */
213 int objd; /* Object associated */
214 struct cds_list_head chan_head; /* Channel list head */
215 struct cds_list_head events_head; /* list of events */
216 struct cds_list_head node; /* Session list */
217
218 /* New UST 2.1 */
219 /* List of enablers */
220 struct cds_list_head enablers_head;
221 struct lttng_ust_event_ht events_ht; /* ht of events */
222 void *owner; /* object owner */
223 int tstate:1; /* Transient enable state */
224
225 /* New UST 2.4 */
226 int statedump_pending:1;
227
228 /* New UST 2.8 */
229 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
230 struct cds_list_head enums_head;
231 struct lttng_ctx *ctx; /* contexts for filters. */
232 };
233
234 static inline
235 struct lttng_enabler *lttng_event_enabler_as_enabler(
236 struct lttng_event_enabler *event_enabler)
237 {
238 return &event_enabler->base;
239 }
240
241 static inline
242 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
243 struct lttng_event_notifier_enabler *event_notifier_enabler)
244 {
245 return &event_notifier_enabler->base;
246 }
247
248 /*
249 * Allocate and initialize a `struct lttng_event_enabler` object.
250 *
251 * On success, returns a `struct lttng_event_enabler`,
252 * On memory error, returns NULL.
253 */
254 LTTNG_HIDDEN
255 struct lttng_event_enabler *lttng_event_enabler_create(
256 enum lttng_enabler_format_type format_type,
257 struct lttng_ust_event *event_param,
258 struct lttng_channel *chan);
259
260 /*
261 * Destroy a `struct lttng_event_enabler` object.
262 */
263 LTTNG_HIDDEN
264 void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
265
266 /*
267 * Enable a `struct lttng_event_enabler` object and all events related to this
268 * enabler.
269 */
270 LTTNG_HIDDEN
271 int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
272
273 /*
274 * Disable a `struct lttng_event_enabler` object and all events related to this
275 * enabler.
276 */
277 LTTNG_HIDDEN
278 int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
279
280 /*
281 * Attach filter bytecode program to `struct lttng_event_enabler` and all
282 * events related to this enabler.
283 */
284 LTTNG_HIDDEN
285 int lttng_event_enabler_attach_filter_bytecode(
286 struct lttng_event_enabler *enabler,
287 struct lttng_ust_bytecode_node **bytecode);
288
289 /*
290 * Attach an application context to an event enabler.
291 *
292 * Not implemented.
293 */
294 LTTNG_HIDDEN
295 int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
296 struct lttng_ust_context *ctx);
297
298 /*
299 * Attach exclusion list to `struct lttng_event_enabler` and all
300 * events related to this enabler.
301 */
302 LTTNG_HIDDEN
303 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
304 struct lttng_ust_excluder_node **excluder);
305
306 /*
307 * Synchronize bytecodes for the enabler and the instance (event or
308 * event_notifier).
309 *
310 * This function goes over all bytecode programs of the enabler (event or
311 * event_notifier enabler) to ensure each is linked to the provided instance.
312 */
313 LTTNG_HIDDEN
314 void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
315 struct lttng_ctx **ctx,
316 struct cds_list_head *instance_bytecode_runtime_head,
317 struct cds_list_head *enabler_bytecode_runtime_head);
318
319 /*
320 * Allocate and initialize a `struct lttng_event_notifier_group` object.
321 *
322 * On success, returns a `struct lttng_triggre_group`,
323 * on memory error, returns NULL.
324 */
325 LTTNG_HIDDEN
326 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
327
328 /*
329 * Destroy a `struct lttng_event_notifier_group` object.
330 */
331 LTTNG_HIDDEN
332 void lttng_event_notifier_group_destroy(
333 struct lttng_event_notifier_group *event_notifier_group);
334
335 /*
336 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
337 *
338 * On success, returns a `struct lttng_event_notifier_enabler`,
339 * On memory error, returns NULL.
340 */
341 LTTNG_HIDDEN
342 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
343 struct lttng_event_notifier_group *event_notifier_group,
344 enum lttng_enabler_format_type format_type,
345 struct lttng_ust_event_notifier *event_notifier_param);
346
347 /*
348 * Destroy a `struct lttng_event_notifier_enabler` object.
349 */
350 LTTNG_HIDDEN
351 void lttng_event_notifier_enabler_destroy(
352 struct lttng_event_notifier_enabler *event_notifier_enabler);
353
354 /*
355 * Enable a `struct lttng_event_notifier_enabler` object and all event
356 * notifiers related to this enabler.
357 */
358 LTTNG_HIDDEN
359 int lttng_event_notifier_enabler_enable(
360 struct lttng_event_notifier_enabler *event_notifier_enabler);
361
362 /*
363 * Disable a `struct lttng_event_notifier_enabler` object and all event
364 * notifiers related to this enabler.
365 */
366 LTTNG_HIDDEN
367 int lttng_event_notifier_enabler_disable(
368 struct lttng_event_notifier_enabler *event_notifier_enabler);
369
370 /*
371 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
372 * all event notifiers related to this enabler.
373 */
374 LTTNG_HIDDEN
375 int lttng_event_notifier_enabler_attach_filter_bytecode(
376 struct lttng_event_notifier_enabler *event_notifier_enabler,
377 struct lttng_ust_bytecode_node **bytecode);
378
379 /*
380 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
381 * all event_notifiers related to this enabler.
382 */
383 LTTNG_HIDDEN
384 int lttng_event_notifier_enabler_attach_capture_bytecode(
385 struct lttng_event_notifier_enabler *event_notifier_enabler,
386 struct lttng_ust_bytecode_node **bytecode);
387
388 /*
389 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
390 * event notifiers related to this enabler.
391 */
392 LTTNG_HIDDEN
393 int lttng_event_notifier_enabler_attach_exclusion(
394 struct lttng_event_notifier_enabler *event_notifier_enabler,
395 struct lttng_ust_excluder_node **excluder);
396
397 LTTNG_HIDDEN
398 void lttng_free_event_recorder_filter_runtime(struct lttng_ust_event_recorder *event_recorder);
399
400 LTTNG_HIDDEN
401 void lttng_free_event_notifier_filter_runtime(
402 struct lttng_event_notifier *event_notifier);
403
404 /*
405 * Connect the probe on all enablers matching this event description.
406 * Called on library load.
407 */
408 LTTNG_HIDDEN
409 int lttng_fix_pending_event_notifiers(void);
410
411 LTTNG_HIDDEN
412 struct lttng_counter *lttng_ust_counter_create(
413 const char *counter_transport_name,
414 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
415
416 #ifdef HAVE_PERF_EVENT
417
418 LTTNG_HIDDEN
419 int lttng_add_perf_counter_to_ctx(uint32_t type,
420 uint64_t config,
421 const char *name,
422 struct lttng_ctx **ctx);
423 LTTNG_HIDDEN
424 int lttng_perf_counter_init(void);
425 LTTNG_HIDDEN
426 void lttng_perf_counter_exit(void);
427
428 #else /* #ifdef HAVE_PERF_EVENT */
429
430 static inline
431 int lttng_add_perf_counter_to_ctx(uint32_t type,
432 uint64_t config,
433 const char *name,
434 struct lttng_ctx **ctx)
435 {
436 return -ENOSYS;
437 }
438 static inline
439 int lttng_perf_counter_init(void)
440 {
441 return 0;
442 }
443 static inline
444 void lttng_perf_counter_exit(void)
445 {
446 }
447 #endif /* #else #ifdef HAVE_PERF_EVENT */
448
449 LTTNG_HIDDEN
450 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
451 LTTNG_HIDDEN
452 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
453
454 LTTNG_HIDDEN
455 int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
456 LTTNG_HIDDEN
457 void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
458
459 LTTNG_HIDDEN
460 struct lttng_ust_tracepoint_iter *
461 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
462 LTTNG_HIDDEN
463 struct lttng_ust_field_iter *
464 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
465
466 LTTNG_HIDDEN
467 struct lttng_session *lttng_session_create(void);
468 LTTNG_HIDDEN
469 int lttng_session_enable(struct lttng_session *session);
470 LTTNG_HIDDEN
471 int lttng_session_disable(struct lttng_session *session);
472 LTTNG_HIDDEN
473 int lttng_session_statedump(struct lttng_session *session);
474 LTTNG_HIDDEN
475 void lttng_session_destroy(struct lttng_session *session);
476
477 LTTNG_HIDDEN
478 struct cds_list_head *lttng_get_sessions(void);
479
480 LTTNG_HIDDEN
481 void lttng_handle_pending_statedump(void *owner);
482
483 LTTNG_HIDDEN
484 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
485 const char *transport_name,
486 void *buf_addr,
487 size_t subbuf_size, size_t num_subbuf,
488 unsigned int switch_timer_interval,
489 unsigned int read_timer_interval,
490 int **shm_fd, int **wait_fd,
491 uint64_t **memory_map_size,
492 struct lttng_channel *chan_priv_init);
493
494 LTTNG_HIDDEN
495 int lttng_channel_enable(struct lttng_channel *channel);
496 LTTNG_HIDDEN
497 int lttng_channel_disable(struct lttng_channel *channel);
498
499 LTTNG_HIDDEN
500 void lttng_transport_register(struct lttng_transport *transport);
501 LTTNG_HIDDEN
502 void lttng_transport_unregister(struct lttng_transport *transport);
503
504 LTTNG_HIDDEN
505 void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc);
506
507 LTTNG_HIDDEN
508 int lttng_fix_pending_events(void);
509
510 LTTNG_HIDDEN
511 struct cds_list_head *lttng_get_probe_list_head(void);
512
513 LTTNG_HIDDEN
514 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
515 const struct lttng_enum_desc *enum_desc);
516
517 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.040659 seconds and 4 git commands to generate.