Refactoring: introduce session private 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_private {
169 struct lttng_event *pub; /* Public event interface */
170
171 const struct lttng_event_desc *desc;
172 enum lttng_ust_instrumentation instrumentation;
173 struct cds_list_head node; /* Event list in session */
174
175 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
176 struct cds_list_head enablers_ref_head;
177 struct cds_hlist_node hlist; /* session ht of events */
178 int registered; /* has reg'd tracepoint probe */
179 };
180
181 struct lttng_ust_bytecode_runtime_private {
182 struct bytecode_runtime *pub; /* Public bytecode runtime interface */
183
184 struct lttng_ust_bytecode_node *bc;
185 int link_failed;
186 /*
187 * Pointer to a URCU-protected pointer owned by an `struct
188 * lttng_session`or `struct lttng_event_notifier_group`.
189 */
190 struct lttng_ctx **pctx;
191 };
192
193 struct lttng_ust_session_private {
194 struct lttng_session *pub; /* Public session interface */
195
196 int been_active; /* Been active ? */
197 int objd; /* Object associated */
198 struct cds_list_head chan_head; /* Channel list head */
199 struct cds_list_head events_head; /* list of events */
200 struct cds_list_head node; /* Session list */
201
202 /* New UST 2.1 */
203 /* List of enablers */
204 struct cds_list_head enablers_head;
205 struct lttng_ust_event_ht events_ht; /* ht of events */
206 void *owner; /* object owner */
207 int tstate:1; /* Transient enable state */
208
209 /* New UST 2.4 */
210 int statedump_pending:1;
211
212 /* New UST 2.8 */
213 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
214 struct cds_list_head enums_head;
215 struct lttng_ctx *ctx; /* contexts for filters. */
216 };
217
218 static inline
219 struct lttng_enabler *lttng_event_enabler_as_enabler(
220 struct lttng_event_enabler *event_enabler)
221 {
222 return &event_enabler->base;
223 }
224
225 static inline
226 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
227 struct lttng_event_notifier_enabler *event_notifier_enabler)
228 {
229 return &event_notifier_enabler->base;
230 }
231
232 /*
233 * Allocate and initialize a `struct lttng_event_enabler` object.
234 *
235 * On success, returns a `struct lttng_event_enabler`,
236 * On memory error, returns NULL.
237 */
238 LTTNG_HIDDEN
239 struct lttng_event_enabler *lttng_event_enabler_create(
240 enum lttng_enabler_format_type format_type,
241 struct lttng_ust_event *event_param,
242 struct lttng_channel *chan);
243
244 /*
245 * Destroy a `struct lttng_event_enabler` object.
246 */
247 LTTNG_HIDDEN
248 void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
249
250 /*
251 * Enable a `struct lttng_event_enabler` object and all events related to this
252 * enabler.
253 */
254 LTTNG_HIDDEN
255 int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
256
257 /*
258 * Disable a `struct lttng_event_enabler` object and all events related to this
259 * enabler.
260 */
261 LTTNG_HIDDEN
262 int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
263
264 /*
265 * Attach filter bytecode program to `struct lttng_event_enabler` and all
266 * events related to this enabler.
267 */
268 LTTNG_HIDDEN
269 int lttng_event_enabler_attach_filter_bytecode(
270 struct lttng_event_enabler *enabler,
271 struct lttng_ust_bytecode_node **bytecode);
272
273 /*
274 * Attach an application context to an event enabler.
275 *
276 * Not implemented.
277 */
278 LTTNG_HIDDEN
279 int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
280 struct lttng_ust_context *ctx);
281
282 /*
283 * Attach exclusion list to `struct lttng_event_enabler` and all
284 * events related to this enabler.
285 */
286 LTTNG_HIDDEN
287 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
288 struct lttng_ust_excluder_node **excluder);
289
290 /*
291 * Synchronize bytecodes for the enabler and the instance (event or
292 * event_notifier).
293 *
294 * This function goes over all bytecode programs of the enabler (event or
295 * event_notifier enabler) to ensure each is linked to the provided instance.
296 */
297 LTTNG_HIDDEN
298 void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
299 struct lttng_ctx **ctx,
300 struct cds_list_head *instance_bytecode_runtime_head,
301 struct cds_list_head *enabler_bytecode_runtime_head);
302
303 /*
304 * Allocate and initialize a `struct lttng_event_notifier_group` object.
305 *
306 * On success, returns a `struct lttng_triggre_group`,
307 * on memory error, returns NULL.
308 */
309 LTTNG_HIDDEN
310 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
311
312 /*
313 * Destroy a `struct lttng_event_notifier_group` object.
314 */
315 LTTNG_HIDDEN
316 void lttng_event_notifier_group_destroy(
317 struct lttng_event_notifier_group *event_notifier_group);
318
319 /*
320 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
321 *
322 * On success, returns a `struct lttng_event_notifier_enabler`,
323 * On memory error, returns NULL.
324 */
325 LTTNG_HIDDEN
326 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
327 struct lttng_event_notifier_group *event_notifier_group,
328 enum lttng_enabler_format_type format_type,
329 struct lttng_ust_event_notifier *event_notifier_param);
330
331 /*
332 * Destroy a `struct lttng_event_notifier_enabler` object.
333 */
334 LTTNG_HIDDEN
335 void lttng_event_notifier_enabler_destroy(
336 struct lttng_event_notifier_enabler *event_notifier_enabler);
337
338 /*
339 * Enable a `struct lttng_event_notifier_enabler` object and all event
340 * notifiers related to this enabler.
341 */
342 LTTNG_HIDDEN
343 int lttng_event_notifier_enabler_enable(
344 struct lttng_event_notifier_enabler *event_notifier_enabler);
345
346 /*
347 * Disable a `struct lttng_event_notifier_enabler` object and all event
348 * notifiers related to this enabler.
349 */
350 LTTNG_HIDDEN
351 int lttng_event_notifier_enabler_disable(
352 struct lttng_event_notifier_enabler *event_notifier_enabler);
353
354 /*
355 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
356 * all event notifiers related to this enabler.
357 */
358 LTTNG_HIDDEN
359 int lttng_event_notifier_enabler_attach_filter_bytecode(
360 struct lttng_event_notifier_enabler *event_notifier_enabler,
361 struct lttng_ust_bytecode_node **bytecode);
362
363 /*
364 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
365 * all event_notifiers related to this enabler.
366 */
367 LTTNG_HIDDEN
368 int lttng_event_notifier_enabler_attach_capture_bytecode(
369 struct lttng_event_notifier_enabler *event_notifier_enabler,
370 struct lttng_ust_bytecode_node **bytecode);
371
372 /*
373 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
374 * event notifiers related to this enabler.
375 */
376 LTTNG_HIDDEN
377 int lttng_event_notifier_enabler_attach_exclusion(
378 struct lttng_event_notifier_enabler *event_notifier_enabler,
379 struct lttng_ust_excluder_node **excluder);
380
381 LTTNG_HIDDEN
382 void lttng_free_event_filter_runtime(struct lttng_event *event);
383
384 LTTNG_HIDDEN
385 void lttng_free_event_notifier_filter_runtime(
386 struct lttng_event_notifier *event_notifier);
387
388 /*
389 * Connect the probe on all enablers matching this event description.
390 * Called on library load.
391 */
392 LTTNG_HIDDEN
393 int lttng_fix_pending_event_notifiers(void);
394
395 LTTNG_HIDDEN
396 struct lttng_counter *lttng_ust_counter_create(
397 const char *counter_transport_name,
398 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
399
400 #ifdef HAVE_PERF_EVENT
401
402 LTTNG_HIDDEN
403 int lttng_add_perf_counter_to_ctx(uint32_t type,
404 uint64_t config,
405 const char *name,
406 struct lttng_ctx **ctx);
407 LTTNG_HIDDEN
408 int lttng_perf_counter_init(void);
409 LTTNG_HIDDEN
410 void lttng_perf_counter_exit(void);
411
412 #else /* #ifdef HAVE_PERF_EVENT */
413
414 static inline
415 int lttng_add_perf_counter_to_ctx(uint32_t type,
416 uint64_t config,
417 const char *name,
418 struct lttng_ctx **ctx)
419 {
420 return -ENOSYS;
421 }
422 static inline
423 int lttng_perf_counter_init(void)
424 {
425 return 0;
426 }
427 static inline
428 void lttng_perf_counter_exit(void)
429 {
430 }
431 #endif /* #else #ifdef HAVE_PERF_EVENT */
432
433 LTTNG_HIDDEN
434 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
435 LTTNG_HIDDEN
436 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
437
438 LTTNG_HIDDEN
439 int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
440 LTTNG_HIDDEN
441 void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
442
443 LTTNG_HIDDEN
444 struct lttng_ust_tracepoint_iter *
445 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
446 LTTNG_HIDDEN
447 struct lttng_ust_field_iter *
448 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
449
450 LTTNG_HIDDEN
451 struct lttng_session *lttng_session_create(void);
452 LTTNG_HIDDEN
453 int lttng_session_enable(struct lttng_session *session);
454 LTTNG_HIDDEN
455 int lttng_session_disable(struct lttng_session *session);
456 LTTNG_HIDDEN
457 int lttng_session_statedump(struct lttng_session *session);
458 LTTNG_HIDDEN
459 void lttng_session_destroy(struct lttng_session *session);
460
461 LTTNG_HIDDEN
462 struct cds_list_head *lttng_get_sessions(void);
463
464 LTTNG_HIDDEN
465 void lttng_handle_pending_statedump(void *owner);
466
467 LTTNG_HIDDEN
468 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
469 const char *transport_name,
470 void *buf_addr,
471 size_t subbuf_size, size_t num_subbuf,
472 unsigned int switch_timer_interval,
473 unsigned int read_timer_interval,
474 int **shm_fd, int **wait_fd,
475 uint64_t **memory_map_size,
476 struct lttng_channel *chan_priv_init);
477
478 LTTNG_HIDDEN
479 int lttng_channel_enable(struct lttng_channel *channel);
480 LTTNG_HIDDEN
481 int lttng_channel_disable(struct lttng_channel *channel);
482
483 LTTNG_HIDDEN
484 void lttng_transport_register(struct lttng_transport *transport);
485 LTTNG_HIDDEN
486 void lttng_transport_unregister(struct lttng_transport *transport);
487
488 LTTNG_HIDDEN
489 void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc);
490
491 LTTNG_HIDDEN
492 int lttng_fix_pending_events(void);
493
494 LTTNG_HIDDEN
495 struct cds_list_head *lttng_get_probe_list_head(void);
496
497 LTTNG_HIDDEN
498 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
499 const struct lttng_enum_desc *enum_desc);
500
501 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.03888 seconds and 4 git commands to generate.