Move struct lttng_counter_ops to internal header
[lttng-ust.git] / liblttng-ust / ust-events-internal.h
CommitLineData
d871c65b 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
d871c65b 3 *
c0c0989a 4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
d871c65b
FD
5 */
6
c0c0989a
MJ
7#ifndef _LTTNG_UST_EVENTS_INTERNAL_H
8#define _LTTNG_UST_EVENTS_INTERNAL_H
9
d871c65b
FD
10#include <stdint.h>
11
12#include <urcu/list.h>
13#include <urcu/hlist.h>
14
864a1eda 15#include <ust-helper.h>
d871c65b
FD
16#include <lttng/ust-events.h>
17
fd17d7ce
MD
18
19struct lttng_ust_abi_obj;
20
21union 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
47struct 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
8665f6a4
MJ
53enum 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 */
62struct 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
fd17d7ce 70 struct lttng_ust_abi_event event_param;
8665f6a4
MJ
71 unsigned int enabled:1;
72};
73
d871c65b
FD
74struct 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
d8d2416d
FD
85struct lttng_event_notifier_enabler {
86 struct lttng_enabler base;
6566528b 87 uint64_t error_counter_index;
d37ecb3f
FD
88 struct cds_list_head node; /* per-app list of event_notifier enablers */
89 struct cds_list_head capture_bytecode_head;
d8d2416d
FD
90 struct lttng_event_notifier_group *group; /* weak ref */
91 uint64_t user_token; /* User-provided token */
d37ecb3f 92 uint64_t num_captures;
d8d2416d
FD
93};
94
ab249ecf
FD
95enum lttng_ust_bytecode_node_type {
96 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
d37ecb3f 97 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
ab249ecf
FD
98};
99
100struct lttng_ust_bytecode_node {
101 enum lttng_ust_bytecode_node_type type;
92495593
FD
102 struct cds_list_head node;
103 struct lttng_enabler *enabler;
ab249ecf
FD
104 struct {
105 uint32_t len;
106 uint32_t reloc_offset;
107 uint64_t seqnum;
108 char data[];
109 } bc;
92495593
FD
110};
111
112struct 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 */
fd17d7ce 119 struct lttng_ust_abi_event_exclusion excluder;
92495593
FD
120};
121
bb7ad29d
MJ
122/* Data structures used by the tracer. */
123
124struct tp_list_entry {
fd17d7ce 125 struct lttng_ust_abi_tracepoint_iter tp;
bb7ad29d
MJ
126 struct cds_list_head head;
127};
128
129struct lttng_ust_tracepoint_list {
130 struct tp_list_entry *iter;
131 struct cds_list_head head;
132};
133
134struct tp_field_list_entry {
fd17d7ce 135 struct lttng_ust_abi_field_iter field;
bb7ad29d
MJ
136 struct cds_list_head head;
137};
138
139struct 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 */
153struct 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
159struct 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
b5863ea7
MD
167struct lttng_counter_ops {
168 struct lib_counter *(*counter_create)(size_t nr_dimensions,
169 const struct lttng_counter_dimension *dimensions,
170 int64_t global_sum_step,
171 int global_counter_fd,
172 int nr_counter_cpu_fds,
173 const int *counter_cpu_fds,
174 bool is_daemon);
175 void (*counter_destroy)(struct lib_counter *counter);
176 int (*counter_add)(struct lib_counter *counter,
177 const size_t *dimension_indexes, int64_t v);
178 int (*counter_read)(struct lib_counter *counter,
179 const size_t *dimension_indexes, int cpu,
180 int64_t *value, bool *overflow, bool *underflow);
181 int (*counter_aggregate)(struct lib_counter *counter,
182 const size_t *dimension_indexes, int64_t *value,
183 bool *overflow, bool *underflow);
184 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
185};
186
bb7ad29d
MJ
187struct lttng_counter {
188 int objd;
189 struct lttng_event_notifier_group *event_notifier_group; /* owner */
190 struct lttng_counter_transport *transport;
191 struct lib_counter *counter;
192 struct lttng_counter_ops *ops;
193};
194
195struct lttng_event_notifier_group {
196 int objd;
197 void *owner;
198 int notification_fd;
199 struct cds_list_head node; /* Event notifier group handle list */
200 struct cds_list_head enablers_head;
201 struct cds_list_head event_notifiers_head; /* list of event_notifiers */
202 struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */
203 struct lttng_ctx *ctx; /* contexts for filters. */
204
205 struct lttng_counter *error_counter;
206 size_t error_counter_len;
207};
208
209struct lttng_transport {
210 char *name;
211 struct cds_list_head node;
49926dbd 212 struct lttng_ust_channel_ops ops;
bb7ad29d
MJ
213 const struct lttng_ust_lib_ring_buffer_config *client_config;
214};
215
216struct lttng_counter_transport {
217 char *name;
218 struct cds_list_head node;
219 struct lttng_counter_ops ops;
220 const struct lib_counter_config *client_config;
221};
222
80333dfa 223struct lttng_ust_event_common_private {
7ee76145 224 struct lttng_ust_event_common *pub; /* Public event interface */
68bb7559 225
dc11f93f 226 const struct lttng_ust_event_desc *desc;
68bb7559
MD
227 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
228 struct cds_list_head enablers_ref_head;
68bb7559 229 int registered; /* has reg'd tracepoint probe */
115db533 230 uint64_t user_token;
68bb7559
MD
231};
232
2e70391c 233struct lttng_ust_event_recorder_private {
80333dfa
MD
234 struct lttng_ust_event_common_private parent;
235
2e70391c 236 struct lttng_ust_event_recorder *pub; /* Public event interface */
ba99fbe2
MD
237 struct cds_list_head node; /* Event recorder list */
238 struct cds_hlist_node hlist; /* Hash table of event recorders */
80333dfa
MD
239};
240
115db533
MD
241struct lttng_ust_event_notifier_private {
242 struct lttng_ust_event_common_private parent;
243
d7d45c0d 244 struct lttng_ust_event_notifier *pub; /* Public event notifier interface */
115db533
MD
245 struct lttng_event_notifier_group *group; /* weak ref */
246 size_t num_captures; /* Needed to allocate the msgpack array. */
247 uint64_t error_counter_index;
ba99fbe2
MD
248 struct cds_list_head node; /* Event notifier list */
249 struct cds_hlist_node hlist; /* Hash table of event notifiers */
115db533
MD
250};
251
362a65de
MD
252struct lttng_ust_bytecode_runtime_private {
253 struct bytecode_runtime *pub; /* Public bytecode runtime interface */
254
255 struct lttng_ust_bytecode_node *bc;
256 int link_failed;
257 /*
258 * Pointer to a URCU-protected pointer owned by an `struct
259 * lttng_session`or `struct lttng_event_notifier_group`.
260 */
261 struct lttng_ctx **pctx;
262};
263
bdb12629
MD
264struct lttng_ust_session_private {
265 struct lttng_session *pub; /* Public session interface */
266
267 int been_active; /* Been active ? */
268 int objd; /* Object associated */
269 struct cds_list_head chan_head; /* Channel list head */
270 struct cds_list_head events_head; /* list of events */
271 struct cds_list_head node; /* Session list */
272
273 /* New UST 2.1 */
274 /* List of enablers */
275 struct cds_list_head enablers_head;
276 struct lttng_ust_event_ht events_ht; /* ht of events */
277 void *owner; /* object owner */
278 int tstate:1; /* Transient enable state */
279
280 /* New UST 2.4 */
281 int statedump_pending:1;
282
283 /* New UST 2.8 */
284 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
285 struct cds_list_head enums_head;
286 struct lttng_ctx *ctx; /* contexts for filters. */
287};
288
036d17fb
MD
289struct lttng_enum {
290 const struct lttng_ust_enum_desc *desc;
291 struct lttng_session *session;
292 struct cds_list_head node; /* Enum list in session */
293 struct cds_hlist_node hlist; /* Session ht of enums */
294 uint64_t id; /* Enumeration ID in sessiond */
295};
296
d871c65b
FD
297static inline
298struct lttng_enabler *lttng_event_enabler_as_enabler(
299 struct lttng_event_enabler *event_enabler)
300{
301 return &event_enabler->base;
302}
303
d8d2416d
FD
304static inline
305struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
306 struct lttng_event_notifier_enabler *event_notifier_enabler)
307{
308 return &event_notifier_enabler->base;
309}
d871c65b
FD
310
311/*
312 * Allocate and initialize a `struct lttng_event_enabler` object.
313 *
314 * On success, returns a `struct lttng_event_enabler`,
315 * On memory error, returns NULL.
316 */
317LTTNG_HIDDEN
318struct lttng_event_enabler *lttng_event_enabler_create(
319 enum lttng_enabler_format_type format_type,
fd17d7ce 320 struct lttng_ust_abi_event *event_param,
d871c65b
FD
321 struct lttng_channel *chan);
322
323/*
324 * Destroy a `struct lttng_event_enabler` object.
325 */
326LTTNG_HIDDEN
327void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
328
329/*
330 * Enable a `struct lttng_event_enabler` object and all events related to this
331 * enabler.
332 */
333LTTNG_HIDDEN
334int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
335
336/*
337 * Disable a `struct lttng_event_enabler` object and all events related to this
338 * enabler.
339 */
340LTTNG_HIDDEN
341int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
342
343/*
344 * Attach filter bytecode program to `struct lttng_event_enabler` and all
345 * events related to this enabler.
346 */
347LTTNG_HIDDEN
a56fd376
FD
348int lttng_event_enabler_attach_filter_bytecode(
349 struct lttng_event_enabler *enabler,
ab89263e 350 struct lttng_ust_bytecode_node **bytecode);
d871c65b
FD
351
352/*
353 * Attach an application context to an event enabler.
354 *
355 * Not implemented.
356 */
357LTTNG_HIDDEN
358int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
fd17d7ce 359 struct lttng_ust_abi_context *ctx);
d871c65b
FD
360
361/*
362 * Attach exclusion list to `struct lttng_event_enabler` and all
363 * events related to this enabler.
364 */
365LTTNG_HIDDEN
366int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
e9fe6aad 367 struct lttng_ust_excluder_node **excluder);
d871c65b
FD
368
369/*
d37ecb3f
FD
370 * Synchronize bytecodes for the enabler and the instance (event or
371 * event_notifier).
d871c65b 372 *
621c07fc 373 * This function goes over all bytecode programs of the enabler (event or
d37ecb3f 374 * event_notifier enabler) to ensure each is linked to the provided instance.
d871c65b
FD
375 */
376LTTNG_HIDDEN
dc11f93f 377void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc,
53b9d7db 378 struct lttng_ctx **ctx,
621c07fc
FD
379 struct cds_list_head *instance_bytecode_runtime_head,
380 struct cds_list_head *enabler_bytecode_runtime_head);
d871c65b 381
d8d2416d
FD
382/*
383 * Allocate and initialize a `struct lttng_event_notifier_group` object.
384 *
385 * On success, returns a `struct lttng_triggre_group`,
386 * on memory error, returns NULL.
387 */
388LTTNG_HIDDEN
389struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
390
391/*
392 * Destroy a `struct lttng_event_notifier_group` object.
393 */
394LTTNG_HIDDEN
395void lttng_event_notifier_group_destroy(
396 struct lttng_event_notifier_group *event_notifier_group);
397
398/*
399 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
400 *
401 * On success, returns a `struct lttng_event_notifier_enabler`,
402 * On memory error, returns NULL.
403 */
404LTTNG_HIDDEN
405struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
406 struct lttng_event_notifier_group *event_notifier_group,
407 enum lttng_enabler_format_type format_type,
fd17d7ce 408 struct lttng_ust_abi_event_notifier *event_notifier_param);
d8d2416d
FD
409
410/*
411 * Destroy a `struct lttng_event_notifier_enabler` object.
412 */
413LTTNG_HIDDEN
414void lttng_event_notifier_enabler_destroy(
415 struct lttng_event_notifier_enabler *event_notifier_enabler);
416
417/*
418 * Enable a `struct lttng_event_notifier_enabler` object and all event
419 * notifiers related to this enabler.
420 */
421LTTNG_HIDDEN
422int lttng_event_notifier_enabler_enable(
423 struct lttng_event_notifier_enabler *event_notifier_enabler);
424
425/*
426 * Disable a `struct lttng_event_notifier_enabler` object and all event
427 * notifiers related to this enabler.
428 */
429LTTNG_HIDDEN
430int lttng_event_notifier_enabler_disable(
431 struct lttng_event_notifier_enabler *event_notifier_enabler);
432
433/*
434 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
435 * all event notifiers related to this enabler.
436 */
437LTTNG_HIDDEN
a56fd376 438int lttng_event_notifier_enabler_attach_filter_bytecode(
d8d2416d 439 struct lttng_event_notifier_enabler *event_notifier_enabler,
ab89263e 440 struct lttng_ust_bytecode_node **bytecode);
d8d2416d 441
d37ecb3f
FD
442/*
443 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
444 * all event_notifiers related to this enabler.
445 */
446LTTNG_HIDDEN
447int lttng_event_notifier_enabler_attach_capture_bytecode(
448 struct lttng_event_notifier_enabler *event_notifier_enabler,
49cde654 449 struct lttng_ust_bytecode_node **bytecode);
d37ecb3f 450
d8d2416d
FD
451/*
452 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
453 * event notifiers related to this enabler.
454 */
455LTTNG_HIDDEN
456int lttng_event_notifier_enabler_attach_exclusion(
457 struct lttng_event_notifier_enabler *event_notifier_enabler,
e9fe6aad 458 struct lttng_ust_excluder_node **excluder);
d8d2416d 459
7753d283 460LTTNG_HIDDEN
b1f720f0 461void lttng_free_event_filter_runtime(struct lttng_ust_event_common *event);
d8d2416d
FD
462
463/*
464 * Connect the probe on all enablers matching this event description.
465 * Called on library load.
466 */
467LTTNG_HIDDEN
468int lttng_fix_pending_event_notifiers(void);
469
67d4e8f5
MJ
470LTTNG_HIDDEN
471struct lttng_counter *lttng_ust_counter_create(
472 const char *counter_transport_name,
473 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
474
bd8c1787
MJ
475#ifdef HAVE_PERF_EVENT
476
477LTTNG_HIDDEN
478int lttng_add_perf_counter_to_ctx(uint32_t type,
479 uint64_t config,
480 const char *name,
481 struct lttng_ctx **ctx);
482LTTNG_HIDDEN
483int lttng_perf_counter_init(void);
484LTTNG_HIDDEN
485void lttng_perf_counter_exit(void);
486
487#else /* #ifdef HAVE_PERF_EVENT */
488
489static inline
490int lttng_add_perf_counter_to_ctx(uint32_t type,
491 uint64_t config,
492 const char *name,
493 struct lttng_ctx **ctx)
494{
495 return -ENOSYS;
496}
497static inline
498int lttng_perf_counter_init(void)
499{
500 return 0;
501}
502static inline
503void lttng_perf_counter_exit(void)
504{
505}
506#endif /* #else #ifdef HAVE_PERF_EVENT */
507
7753d283
MJ
508LTTNG_HIDDEN
509int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
510LTTNG_HIDDEN
511void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
512
513LTTNG_HIDDEN
514int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
515LTTNG_HIDDEN
516void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
517
518LTTNG_HIDDEN
fd17d7ce 519struct lttng_ust_abi_tracepoint_iter *
7753d283
MJ
520 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
521LTTNG_HIDDEN
fd17d7ce 522struct lttng_ust_abi_field_iter *
7753d283
MJ
523 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
524
525LTTNG_HIDDEN
526struct lttng_session *lttng_session_create(void);
527LTTNG_HIDDEN
528int lttng_session_enable(struct lttng_session *session);
529LTTNG_HIDDEN
530int lttng_session_disable(struct lttng_session *session);
531LTTNG_HIDDEN
532int lttng_session_statedump(struct lttng_session *session);
533LTTNG_HIDDEN
534void lttng_session_destroy(struct lttng_session *session);
535
536LTTNG_HIDDEN
537struct cds_list_head *lttng_get_sessions(void);
538
539LTTNG_HIDDEN
540void lttng_handle_pending_statedump(void *owner);
541
542LTTNG_HIDDEN
543struct lttng_channel *lttng_channel_create(struct lttng_session *session,
544 const char *transport_name,
545 void *buf_addr,
546 size_t subbuf_size, size_t num_subbuf,
547 unsigned int switch_timer_interval,
548 unsigned int read_timer_interval,
549 int **shm_fd, int **wait_fd,
550 uint64_t **memory_map_size,
551 struct lttng_channel *chan_priv_init);
552
553LTTNG_HIDDEN
554int lttng_channel_enable(struct lttng_channel *channel);
555LTTNG_HIDDEN
556int lttng_channel_disable(struct lttng_channel *channel);
557
558LTTNG_HIDDEN
559void lttng_transport_register(struct lttng_transport *transport);
560LTTNG_HIDDEN
561void lttng_transport_unregister(struct lttng_transport *transport);
562
563LTTNG_HIDDEN
dc11f93f 564void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc);
7753d283
MJ
565
566LTTNG_HIDDEN
567int lttng_fix_pending_events(void);
568
569LTTNG_HIDDEN
570struct cds_list_head *lttng_get_probe_list_head(void);
571
572LTTNG_HIDDEN
573struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
891d6b55 574 const struct lttng_ust_enum_desc *enum_desc);
7753d283 575
fd17d7ce
MD
576LTTNG_HIDDEN
577int lttng_abi_create_root_handle(void);
578
579LTTNG_HIDDEN
580const struct lttng_ust_abi_objd_ops *lttng_ust_abi_objd_ops(int id);
581LTTNG_HIDDEN
582int lttng_ust_abi_objd_unref(int id, int is_owner);
583LTTNG_HIDDEN
584void lttng_ust_abi_exit(void);
585LTTNG_HIDDEN
586void lttng_ust_abi_events_exit(void);
587LTTNG_HIDDEN
588void lttng_ust_abi_objd_table_owner_cleanup(void *owner);
589
d871c65b 590#endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.048769 seconds and 4 git commands to generate.