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