Custom upgrade: suffix lttng_ust_dl_update with 1
[lttng-ust.git] / src / common / events.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
5 */
6
7 #ifndef _UST_COMMON_UST_EVENTS_H
8 #define _UST_COMMON_UST_EVENTS_H
9
10 #include <limits.h>
11 #include <stdint.h>
12
13 #include <urcu/list.h>
14 #include <urcu/hlist.h>
15
16 #include <lttng/ust-config.h>
17 #include <lttng/ust-events.h>
18
19 #include "common/macros.h"
20 #include "common/ust-context-provider.h"
21
22 /*
23 * The context procname length is part of the LTTng-UST ABI.
24 * TODO: At the next breaking protocol bump, all users of this macro
25 * should instead use LTTNG_UST_ABI_PROCNAME_LEN.
26 */
27 #define LTTNG_UST_CONTEXT_PROCNAME_LEN 17
28
29 struct lttng_ust_abi_obj;
30 struct lttng_event_notifier_group;
31
32 union lttng_ust_abi_args {
33 struct {
34 void *chan_data;
35 int wakeup_fd;
36 } channel;
37 struct {
38 int shm_fd;
39 int wakeup_fd;
40 } stream;
41 struct {
42 struct lttng_ust_abi_field_iter entry;
43 } field_list;
44 struct {
45 char *ctxname;
46 } app_context;
47 struct {
48 int event_notifier_notif_fd;
49 } event_notifier_handle;
50 struct {
51 void *counter_data;
52 } counter;
53 struct {
54 int shm_fd;
55 } counter_shm;
56 };
57
58 struct lttng_ust_abi_objd_ops {
59 long (*cmd)(int objd, unsigned int cmd, unsigned long arg,
60 union lttng_ust_abi_args *args, void *owner);
61 int (*release)(int objd);
62 };
63
64 enum lttng_enabler_format_type {
65 LTTNG_ENABLER_FORMAT_STAR_GLOB,
66 LTTNG_ENABLER_FORMAT_EVENT,
67 };
68
69 /*
70 * Enabler field, within whatever object is enabling an event. Target of
71 * backward reference.
72 */
73 struct lttng_enabler {
74 enum lttng_enabler_format_type format_type;
75
76 /* head list of struct lttng_ust_filter_bytecode_node */
77 struct cds_list_head filter_bytecode_head;
78 /* head list of struct lttng_ust_excluder_node */
79 struct cds_list_head excluder_head;
80
81 struct lttng_ust_abi_event event_param;
82 unsigned int enabled:1;
83 };
84
85 struct lttng_event_enabler {
86 struct lttng_enabler base;
87 struct cds_list_head node; /* per-session list of enablers */
88 struct lttng_ust_channel_buffer *chan;
89 /*
90 * Unused, but kept around to make it explicit that the tracer can do
91 * it.
92 */
93 struct lttng_ust_ctx *ctx;
94 };
95
96 struct lttng_event_notifier_enabler {
97 struct lttng_enabler base;
98 uint64_t error_counter_index;
99 struct cds_list_head node; /* per-app list of event_notifier enablers */
100 struct cds_list_head capture_bytecode_head;
101 struct lttng_event_notifier_group *group; /* weak ref */
102 uint64_t user_token; /* User-provided token */
103 uint64_t num_captures;
104 };
105
106 enum lttng_ust_bytecode_type {
107 LTTNG_UST_BYTECODE_TYPE_FILTER,
108 LTTNG_UST_BYTECODE_TYPE_CAPTURE,
109 };
110
111 struct lttng_ust_bytecode_node {
112 enum lttng_ust_bytecode_type type;
113 struct cds_list_head node;
114 struct lttng_enabler *enabler;
115 struct {
116 uint32_t len;
117 uint32_t reloc_offset;
118 uint64_t seqnum;
119 char data[];
120 } bc;
121 };
122
123 /*
124 * Bytecode interpreter return value.
125 */
126 enum lttng_ust_bytecode_interpreter_ret {
127 LTTNG_UST_BYTECODE_INTERPRETER_ERROR = -1,
128 LTTNG_UST_BYTECODE_INTERPRETER_OK = 0,
129 };
130
131 struct lttng_interpreter_output;
132 struct lttng_ust_bytecode_runtime_private;
133
134 enum lttng_ust_bytecode_filter_result {
135 LTTNG_UST_BYTECODE_FILTER_ACCEPT = 0,
136 LTTNG_UST_BYTECODE_FILTER_REJECT = 1,
137 };
138
139 struct lttng_ust_bytecode_filter_ctx {
140 enum lttng_ust_bytecode_filter_result result;
141 };
142
143 struct lttng_ust_excluder_node {
144 struct cds_list_head node;
145 struct lttng_enabler *enabler;
146 /*
147 * struct lttng_ust_event_exclusion had variable sized array,
148 * must be last field.
149 */
150 struct lttng_ust_abi_event_exclusion excluder;
151 };
152
153 /* Data structures used by the tracer. */
154
155 struct tp_list_entry {
156 struct lttng_ust_abi_tracepoint_iter tp;
157 struct cds_list_head head;
158 };
159
160 struct lttng_ust_tracepoint_list {
161 struct tp_list_entry *iter;
162 struct cds_list_head head;
163 };
164
165 struct tp_field_list_entry {
166 struct lttng_ust_abi_field_iter field;
167 struct cds_list_head head;
168 };
169
170 struct lttng_ust_field_list {
171 struct tp_field_list_entry *iter;
172 struct cds_list_head head;
173 };
174
175 /*
176 * Objects in a linked-list of enablers, owned by an event or event_notifier.
177 * This is used because an event (or a event_notifier) can be enabled by more
178 * than one enabler and we want a quick way to iterate over all enablers of an
179 * object.
180 *
181 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
182 * event with the name "my_app:abc".
183 */
184 struct lttng_enabler_ref {
185 struct cds_list_head node; /* enabler ref list */
186 struct lttng_enabler *ref; /* backward ref */
187 };
188
189 #define LTTNG_COUNTER_DIMENSION_MAX 8
190 struct lttng_counter_dimension {
191 uint64_t size;
192 uint64_t underflow_index;
193 uint64_t overflow_index;
194 uint8_t has_underflow;
195 uint8_t has_overflow;
196 };
197
198 struct lttng_counter_ops {
199 struct lib_counter *(*counter_create)(size_t nr_dimensions,
200 const struct lttng_counter_dimension *dimensions,
201 int64_t global_sum_step,
202 int global_counter_fd,
203 int nr_counter_cpu_fds,
204 const int *counter_cpu_fds,
205 bool is_daemon);
206 void (*counter_destroy)(struct lib_counter *counter);
207 int (*counter_add)(struct lib_counter *counter,
208 const size_t *dimension_indexes, int64_t v);
209 int (*counter_read)(struct lib_counter *counter,
210 const size_t *dimension_indexes, int cpu,
211 int64_t *value, bool *overflow, bool *underflow);
212 int (*counter_aggregate)(struct lib_counter *counter,
213 const size_t *dimension_indexes, int64_t *value,
214 bool *overflow, bool *underflow);
215 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
216 };
217
218 struct lttng_counter {
219 int objd;
220 struct lttng_event_notifier_group *event_notifier_group; /* owner */
221 struct lttng_counter_transport *transport;
222 struct lib_counter *counter;
223 struct lttng_counter_ops *ops;
224 };
225
226 #define LTTNG_UST_EVENT_HT_BITS 12
227 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
228
229 struct lttng_ust_event_ht {
230 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
231 };
232
233 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
234 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
235 struct lttng_ust_event_notifier_ht {
236 struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE];
237 };
238
239 #define LTTNG_UST_ENUM_HT_BITS 12
240 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
241
242 struct lttng_ust_enum_ht {
243 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
244 };
245
246 struct lttng_event_notifier_group {
247 int objd;
248 void *owner;
249 int notification_fd;
250 struct cds_list_head node; /* Event notifier group handle list */
251 struct cds_list_head enablers_head;
252 struct cds_list_head event_notifiers_head; /* list of event_notifiers */
253 struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */
254 struct lttng_ust_ctx *ctx; /* contexts for filters. */
255
256 struct lttng_counter *error_counter;
257 size_t error_counter_len;
258 };
259
260 struct lttng_transport {
261 const char *name;
262 struct cds_list_head node;
263 struct lttng_ust_channel_buffer_ops ops;
264 const struct lttng_ust_ring_buffer_config *client_config;
265 };
266
267 struct lttng_counter_transport {
268 const char *name;
269 struct cds_list_head node;
270 struct lttng_counter_ops ops;
271 const struct lib_counter_config *client_config;
272 };
273
274 struct lttng_ust_event_common_private {
275 struct lttng_ust_event_common *pub; /* Public event interface */
276
277 const struct lttng_ust_event_desc *desc;
278 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
279 struct cds_list_head enablers_ref_head;
280 int registered; /* has reg'd tracepoint probe */
281 uint64_t user_token;
282
283 int has_enablers_without_filter_bytecode;
284 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
285 struct cds_list_head filter_bytecode_runtime_head;
286 };
287
288 struct lttng_ust_event_recorder_private {
289 struct lttng_ust_event_common_private parent;
290
291 struct lttng_ust_event_recorder *pub; /* Public event interface */
292 struct cds_list_head node; /* Event recorder list */
293 struct cds_hlist_node hlist; /* Hash table of event recorders */
294 struct lttng_ust_ctx *ctx;
295 unsigned int id;
296 };
297
298 struct lttng_ust_event_notifier_private {
299 struct lttng_ust_event_common_private parent;
300
301 struct lttng_ust_event_notifier *pub; /* Public event notifier interface */
302 struct lttng_event_notifier_group *group; /* weak ref */
303 size_t num_captures; /* Needed to allocate the msgpack array. */
304 uint64_t error_counter_index;
305 struct cds_list_head node; /* Event notifier list */
306 struct cds_hlist_node hlist; /* Hash table of event notifiers */
307 struct cds_list_head capture_bytecode_runtime_head;
308 };
309
310 struct lttng_ust_bytecode_runtime {
311 enum lttng_ust_bytecode_type type;
312 struct lttng_ust_bytecode_node *bc;
313 int link_failed;
314 int (*interpreter_func)(struct lttng_ust_bytecode_runtime *bytecode_runtime,
315 const char *interpreter_stack_data,
316 struct lttng_ust_probe_ctx *probe_ctx,
317 void *ctx);
318 struct cds_list_head node; /* list of bytecode runtime in event */
319 /*
320 * Pointer to a URCU-protected pointer owned by an `struct
321 * lttng_session`or `struct lttng_event_notifier_group`.
322 */
323 struct lttng_ust_ctx **pctx;
324 };
325
326 struct lttng_ust_session_private {
327 struct lttng_ust_session *pub; /* Public session interface */
328
329 int been_active; /* Been active ? */
330 int objd; /* Object associated */
331 struct cds_list_head chan_head; /* Channel list head */
332 struct cds_list_head events_head; /* list of events */
333 struct cds_list_head node; /* Session list */
334
335 /* List of enablers */
336 struct cds_list_head enablers_head;
337 struct lttng_ust_event_ht events_ht; /* ht of events */
338 void *owner; /* object owner */
339 int tstate:1; /* Transient enable state */
340
341 int statedump_pending:1;
342
343 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
344 struct cds_list_head enums_head;
345 struct lttng_ust_ctx *ctx; /* contexts for filters. */
346
347 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
348 bool uuid_set; /* Is uuid set ? */
349 };
350
351 struct lttng_enum {
352 const struct lttng_ust_enum_desc *desc;
353 struct lttng_ust_session *session;
354 struct cds_list_head node; /* Enum list in session */
355 struct cds_hlist_node hlist; /* Session ht of enums */
356 uint64_t id; /* Enumeration ID in sessiond */
357 };
358
359 struct lttng_ust_shm_handle;
360
361 struct lttng_ust_channel_buffer_ops_private {
362 struct lttng_ust_channel_buffer_ops *pub; /* Public channel buffer ops interface */
363
364 struct lttng_ust_channel_buffer *(*channel_create)(const char *name,
365 void *buf_addr,
366 size_t subbuf_size, size_t num_subbuf,
367 unsigned int switch_timer_interval,
368 unsigned int read_timer_interval,
369 unsigned char *uuid,
370 uint32_t chan_id,
371 const int *stream_fds, int nr_stream_fds,
372 int64_t blocking_timeout);
373 void (*channel_destroy)(struct lttng_ust_channel_buffer *chan);
374 /*
375 * packet_avail_size returns the available size in the current
376 * packet. Note that the size returned is only a hint, since it
377 * may change due to concurrent writes.
378 */
379 size_t (*packet_avail_size)(struct lttng_ust_channel_buffer *chan);
380 int (*is_finalized)(struct lttng_ust_channel_buffer *chan);
381 int (*is_disabled)(struct lttng_ust_channel_buffer *chan);
382 int (*flush_buffer)(struct lttng_ust_channel_buffer *chan);
383 };
384
385 struct lttng_ust_channel_common_private {
386 struct lttng_ust_channel_common *pub; /* Public channel interface */
387
388 int objd; /* Object associated with channel. */
389 int tstate:1; /* Transient enable state */
390 };
391
392 struct lttng_ust_channel_buffer_private {
393 struct lttng_ust_channel_common_private parent;
394
395 struct lttng_ust_channel_buffer *pub; /* Public channel buffer interface */
396 struct cds_list_head node; /* Channel list in session */
397 int header_type; /* 0: unset, 1: compact, 2: large */
398 unsigned int id; /* Channel ID */
399 enum lttng_ust_abi_chan_type type;
400 struct lttng_ust_ctx *ctx;
401 struct lttng_ust_ring_buffer_channel *rb_chan; /* Ring buffer channel */
402 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
403 };
404
405 /*
406 * IMPORTANT: this structure is part of the ABI between the consumer
407 * daemon and the UST library within traced applications. Changing it
408 * breaks the UST communication protocol.
409 *
410 * TODO: remove unused fields on next UST communication protocol
411 * breaking update.
412 */
413 struct lttng_ust_abi_channel_config {
414 void *unused1;
415 int unused2;
416 void *unused3;
417 void *unused4;
418 int unused5;
419 unsigned int _deprecated1;
420 unsigned int _deprecated2;
421 struct cds_list_head unused6;
422 void *unused7;
423 int unused8;
424 void *unused9;
425 unsigned int _deprecated3:1;
426
427 /* Channel ID */
428 unsigned int id;
429 enum lttng_ust_abi_chan_type unused10;
430 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
431 int unused11:1;
432 };
433
434 /* Global (filter), event and channel contexts. */
435 struct lttng_ust_ctx {
436 struct lttng_ust_ctx_field *fields;
437 unsigned int nr_fields;
438 unsigned int allocated_fields;
439 unsigned int largest_align;
440 };
441
442 struct lttng_ust_registered_probe {
443 const struct lttng_ust_probe_desc *desc;
444
445 struct cds_list_head head; /* chain registered probes */
446 struct cds_list_head lazy_init_head;
447 int lazy; /* lazy registration */
448 };
449
450 /*
451 * Context field
452 */
453
454 struct lttng_ust_ctx_field {
455 const struct lttng_ust_event_field *event_field;
456 size_t (*get_size)(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
457 size_t offset);
458 void (*record)(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
459 struct lttng_ust_ring_buffer_ctx *ctx,
460 struct lttng_ust_channel_buffer *chan);
461 void (*get_value)(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
462 struct lttng_ust_ctx_value *value);
463 void (*destroy)(void *priv);
464 void *priv;
465 };
466
467 static inline
468 const struct lttng_ust_type_integer *lttng_ust_get_type_integer(const struct lttng_ust_type_common *type)
469 {
470 if (type->type != lttng_ust_type_integer)
471 return NULL;
472 return caa_container_of(type, const struct lttng_ust_type_integer, parent);
473 }
474
475 static inline
476 const struct lttng_ust_type_float *lttng_ust_get_type_float(const struct lttng_ust_type_common *type)
477 {
478 if (type->type != lttng_ust_type_float)
479 return NULL;
480 return caa_container_of(type, const struct lttng_ust_type_float, parent);
481 }
482
483 static inline
484 const struct lttng_ust_type_string *lttng_ust_get_type_string(const struct lttng_ust_type_common *type)
485 {
486 if (type->type != lttng_ust_type_string)
487 return NULL;
488 return caa_container_of(type, const struct lttng_ust_type_string, parent);
489 }
490
491 static inline
492 const struct lttng_ust_type_enum *lttng_ust_get_type_enum(const struct lttng_ust_type_common *type)
493 {
494 if (type->type != lttng_ust_type_enum)
495 return NULL;
496 return caa_container_of(type, const struct lttng_ust_type_enum, parent);
497 }
498
499 static inline
500 const struct lttng_ust_type_array *lttng_ust_get_type_array(const struct lttng_ust_type_common *type)
501 {
502 if (type->type != lttng_ust_type_array)
503 return NULL;
504 return caa_container_of(type, const struct lttng_ust_type_array, parent);
505 }
506
507 static inline
508 const struct lttng_ust_type_sequence *lttng_ust_get_type_sequence(const struct lttng_ust_type_common *type)
509 {
510 if (type->type != lttng_ust_type_sequence)
511 return NULL;
512 return caa_container_of(type, const struct lttng_ust_type_sequence, parent);
513 }
514
515 static inline
516 const struct lttng_ust_type_struct *lttng_ust_get_type_struct(const struct lttng_ust_type_common *type)
517 {
518 if (type->type != lttng_ust_type_struct)
519 return NULL;
520 return caa_container_of(type, const struct lttng_ust_type_struct, parent);
521 }
522
523 #define lttng_ust_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
524 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_integer, { \
525 .parent = { \
526 .type = lttng_ust_type_integer, \
527 }, \
528 .struct_size = sizeof(struct lttng_ust_type_integer), \
529 .size = (_size), \
530 .alignment = (_alignment), \
531 .signedness = (_signedness), \
532 .reverse_byte_order = (_byte_order) != LTTNG_UST_BYTE_ORDER, \
533 .base = (_base), \
534 }))
535
536 #define lttng_ust_static_type_array_text(_length) \
537 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
538 .parent = { \
539 .type = lttng_ust_type_array, \
540 }, \
541 .struct_size = sizeof(struct lttng_ust_type_array), \
542 .length = (_length), \
543 .alignment = 0, \
544 .encoding = lttng_ust_string_encoding_UTF8, \
545 .elem_type = lttng_ust_static_type_integer(sizeof(char) * CHAR_BIT, \
546 lttng_ust_rb_alignof(char) * CHAR_BIT, lttng_ust_is_signed_type(char), \
547 LTTNG_UST_BYTE_ORDER, 10), \
548 }))
549
550 #define lttng_ust_static_event_field(_name, _type, _nowrite, _nofilter) \
551 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
552 .struct_size = sizeof(struct lttng_ust_event_field), \
553 .name = (_name), \
554 .type = (_type), \
555 .nowrite = (_nowrite), \
556 .nofilter = (_nofilter), \
557 })
558
559 #define lttng_ust_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
560 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_ctx_field, { \
561 .event_field = (_event_field), \
562 .get_size = (_get_size), \
563 .record = (_record), \
564 .get_value = (_get_value), \
565 .destroy = (_destroy), \
566 .priv = (_priv), \
567 })
568
569 static inline
570 struct lttng_enabler *lttng_event_enabler_as_enabler(
571 struct lttng_event_enabler *event_enabler)
572 {
573 return &event_enabler->base;
574 }
575
576 static inline
577 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
578 struct lttng_event_notifier_enabler *event_notifier_enabler)
579 {
580 return &event_notifier_enabler->base;
581 }
582
583
584 /* Custom upgrade 2.12 to 2.13 */
585 #ifndef LTTNG_UST_CUSTOM_UPGRADE_CONFLICTING_SYMBOLS
586 #define lttng_ust_dl_update lttng_ust_dl_update1
587 #endif
588
589 /* This is ABI between liblttng-ust and liblttng-ust-dl */
590 void lttng_ust_dl_update(void *ip);
591
592 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session,
593 const struct lttng_ust_enum_desc *enum_desc)
594 __attribute__((visibility("hidden")));
595
596
597 #endif /* _UST_COMMON_UST_EVENTS_H */
This page took 0.042942 seconds and 5 git commands to generate.