SoW-2020-0002: Trace Hit Counters
[deliverable/lttng-ust.git] / include / lttng / ust-events.h
CommitLineData
8020ceb5 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
8020ceb5 3 *
c0c0989a 4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8020ceb5
MD
5 *
6 * Holds LTTng per-session event registry.
8020ceb5
MD
7 */
8
c0c0989a
MJ
9#ifndef _LTTNG_UST_EVENTS_H
10#define _LTTNG_UST_EVENTS_H
11
9f3fdbc6 12#include <urcu/list.h>
1f18504e 13#include <urcu/hlist.h>
b4051ad8 14#include <stddef.h>
9f3fdbc6 15#include <stdint.h>
d58d1454 16#include <lttng/ust-config.h>
4318ae1b
MD
17#include <lttng/ust-abi.h>
18#include <lttng/ust-tracer.h>
2ae57758 19#include <lttng/ust-endian.h>
20f1eee7 20#include <float.h>
d58d1454
MD
21#include <errno.h>
22#include <urcu/ref.h>
23#include <pthread.h>
8020ceb5 24
db56acaf
MD
25#ifndef LTTNG_PACKED
26#error "LTTNG_PACKED should be defined"
27#endif
28
6453d237
MD
29#ifdef __cplusplus
30extern "C" {
31#endif
32
19d8b1b3
MD
33#define LTTNG_UST_UUID_LEN 16
34
71d31690
MD
35/*
36 * Tracepoint provider version. Compatibility based on the major number.
37 * Older tracepoint providers can always register to newer lttng-ust
38 * library, but the opposite is rejected: a newer tracepoint provider is
39 * rejected by an older lttng-ust library.
40 */
bb84a1ec 41#define LTTNG_UST_PROVIDER_MAJOR 3
71d31690
MD
42#define LTTNG_UST_PROVIDER_MINOR 0
43
7dd08bec
MD
44struct lttng_channel;
45struct lttng_session;
4cfec15c 46struct lttng_ust_lib_ring_buffer_ctx;
53569322
MD
47struct lttng_ust_context_app;
48struct lttng_event_field;
cab88ff8 49struct lttng_event_notifier;
ebabbf58 50struct lttng_event_notifier_group;
8020ceb5 51
37d5e202
MD
52/*
53 * Data structures used by tracepoint event declarations, and by the
54 * tracer. Those structures have padding for future extension.
55 */
56
c1fca457
MD
57/*
58 * LTTng client type enumeration. Used by the consumer to map the
59 * callbacks from its own address space.
60 */
61enum lttng_client_types {
62 LTTNG_CLIENT_METADATA = 0,
63 LTTNG_CLIENT_DISCARD = 1,
64 LTTNG_CLIENT_OVERWRITE = 2,
34a91bdb
MD
65 LTTNG_CLIENT_DISCARD_RT = 3,
66 LTTNG_CLIENT_OVERWRITE_RT = 4,
c1fca457
MD
67 LTTNG_NR_CLIENT_TYPES,
68};
69
8020ceb5
MD
70/* Type description */
71
72/* Update the astract_types name table in lttng-types.c along with this enum */
7dd08bec 73enum lttng_abstract_types {
8020ceb5 74 atype_integer,
218deb69
MD
75 atype_enum, /* legacy */
76 atype_array, /* legacy */
77 atype_sequence, /* legacy */
8020ceb5 78 atype_string,
20f1eee7 79 atype_float,
53569322 80 atype_dynamic,
218deb69
MD
81 atype_struct, /* legacy */
82 atype_enum_nestable,
83 atype_array_nestable,
84 atype_sequence_nestable,
85 atype_struct_nestable,
8020ceb5
MD
86 NR_ABSTRACT_TYPES,
87};
88
89/* Update the string_encodings name table in lttng-types.c along with this enum */
90enum lttng_string_encodings {
91 lttng_encode_none = 0,
92 lttng_encode_UTF8 = 1,
93 lttng_encode_ASCII = 2,
94 NR_STRING_ENCODINGS,
95};
96
a6f80644
MD
97struct lttng_enum_value {
98 unsigned long long value;
99 unsigned int signedness:1;
100};
101
3e762260
PP
102enum lttng_enum_entry_options {
103 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
104};
105
37d5e202 106#define LTTNG_UST_ENUM_ENTRY_PADDING 16
8020ceb5 107struct lttng_enum_entry {
a6f80644 108 struct lttng_enum_value start, end; /* start and end are inclusive */
8020ceb5 109 const char *string;
3e762260
PP
110 union {
111 struct {
112 unsigned int options;
113 } LTTNG_PACKED extra;
114 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
115 } u;
8020ceb5
MD
116};
117
118#define __type_integer(_type, _byte_order, _base, _encoding) \
119 { \
46d52200
ZT
120 .atype = atype_integer, \
121 .u = \
8020ceb5 122 { \
218deb69 123 .integer = \
46d52200 124 { \
218deb69
MD
125 .size = sizeof(_type) * CHAR_BIT, \
126 .alignment = lttng_alignof(_type) * CHAR_BIT, \
127 .signedness = lttng_is_signed_type(_type), \
128 .reverse_byte_order = _byte_order != BYTE_ORDER, \
129 .base = _base, \
130 .encoding = lttng_encode_##_encoding, \
46d52200 131 } \
8020ceb5
MD
132 }, \
133 } \
134
37d5e202 135#define LTTNG_UST_INTEGER_TYPE_PADDING 24
8020ceb5
MD
136struct lttng_integer_type {
137 unsigned int size; /* in bits */
138 unsigned short alignment; /* in bits */
139 unsigned int signedness:1;
140 unsigned int reverse_byte_order:1;
141 unsigned int base; /* 2, 8, 10, 16, for pretty print */
142 enum lttng_string_encodings encoding;
37d5e202 143 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
8020ceb5
MD
144};
145
d3ed854b
MD
146/*
147 * Only float and double are supported. long double is not supported at
148 * the moment.
149 */
20f1eee7
MD
150#define _float_mant_dig(_type) \
151 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
152 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
d3ed854b 153 : 0))
20f1eee7
MD
154
155#define __type_float(_type) \
156 { \
46d52200
ZT
157 .atype = atype_float, \
158 .u = \
20f1eee7 159 { \
218deb69 160 ._float = \
46d52200 161 { \
218deb69
MD
162 .exp_dig = sizeof(_type) * CHAR_BIT \
163 - _float_mant_dig(_type), \
164 .mant_dig = _float_mant_dig(_type), \
165 .alignment = lttng_alignof(_type) * CHAR_BIT, \
166 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
46d52200 167 } \
218deb69 168 } \
20f1eee7
MD
169 } \
170
37d5e202 171#define LTTNG_UST_FLOAT_TYPE_PADDING 24
20f1eee7
MD
172struct lttng_float_type {
173 unsigned int exp_dig; /* exponent digits, in bits */
174 unsigned int mant_dig; /* mantissa digits, in bits */
175 unsigned short alignment; /* in bits */
176 unsigned int reverse_byte_order:1;
37d5e202 177 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
20f1eee7
MD
178};
179
218deb69 180/* legacy */
37d5e202 181#define LTTNG_UST_BASIC_TYPE_PADDING 128
8020ceb5 182union _lttng_basic_type {
218deb69 183 struct lttng_integer_type integer; /* legacy */
8020ceb5 184 struct {
c785c634
MD
185 const struct lttng_enum_desc *desc; /* Enumeration mapping */
186 struct lttng_integer_type container_type;
218deb69 187 } enumeration; /* legacy */
8020ceb5
MD
188 struct {
189 enum lttng_string_encodings encoding;
218deb69
MD
190 } string; /* legacy */
191 struct lttng_float_type _float; /* legacy */
37d5e202 192 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
8020ceb5
MD
193};
194
218deb69 195/* legacy */
8020ceb5 196struct lttng_basic_type {
7dd08bec 197 enum lttng_abstract_types atype;
8020ceb5
MD
198 union {
199 union _lttng_basic_type basic;
200 } u;
201};
202
37d5e202 203#define LTTNG_UST_TYPE_PADDING 128
8020ceb5 204struct lttng_type {
7dd08bec 205 enum lttng_abstract_types atype;
8020ceb5 206 union {
218deb69
MD
207 /* provider ABI 2.0 */
208 struct lttng_integer_type integer;
209 struct lttng_float_type _float;
210 struct {
211 enum lttng_string_encodings encoding;
212 } string;
213 struct {
214 const struct lttng_enum_desc *desc; /* Enumeration mapping */
215 struct lttng_type *container_type;
216 } enum_nestable;
8020ceb5 217 struct {
218deb69
MD
218 const struct lttng_type *elem_type;
219 unsigned int length; /* Num. elems. */
220 unsigned int alignment;
221 } array_nestable;
8020ceb5 222 struct {
218deb69
MD
223 const char *length_name; /* Length field name. */
224 const struct lttng_type *elem_type;
225 unsigned int alignment; /* Alignment before elements. */
226 } sequence_nestable;
53569322 227 struct {
218deb69
MD
228 unsigned int nr_fields;
229 const struct lttng_event_field *fields; /* Array of fields. */
230 unsigned int alignment;
231 } struct_nestable;
232
233 union {
234 /* legacy provider ABI 1.0 */
235 union _lttng_basic_type basic; /* legacy */
236 struct {
237 struct lttng_basic_type elem_type;
238 unsigned int length; /* Num. elems. */
239 } array; /* legacy */
240 struct {
241 struct lttng_basic_type length_type;
242 struct lttng_basic_type elem_type;
243 } sequence; /* legacy */
244 struct {
245 unsigned int nr_fields;
246 struct lttng_event_field *fields; /* Array of fields. */
247 } _struct; /* legacy */
248 } legacy;
37d5e202 249 char padding[LTTNG_UST_TYPE_PADDING];
8020ceb5
MD
250 } u;
251};
252
37d5e202 253#define LTTNG_UST_ENUM_TYPE_PADDING 24
c785c634 254struct lttng_enum_desc {
8020ceb5 255 const char *name;
8020ceb5 256 const struct lttng_enum_entry *entries;
c785c634 257 unsigned int nr_entries;
37d5e202 258 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
8020ceb5
MD
259};
260
180901e6
MD
261/*
262 * Event field description
263 *
264 * IMPORTANT: this structure is part of the ABI between the probe and
265 * UST. Fields need to be only added at the end, never reordered, never
266 * removed.
267 */
8020ceb5 268
4774c8f3 269#define LTTNG_UST_EVENT_FIELD_PADDING 28
8020ceb5
MD
270struct lttng_event_field {
271 const char *name;
272 struct lttng_type type;
180901e6 273 unsigned int nowrite; /* do not write into trace */
218deb69
MD
274 union {
275 struct {
276 unsigned int nofilter:1; /* do not consider for filter */
277 } ext;
278 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
279 } u;
8020ceb5
MD
280};
281
53569322
MD
282enum lttng_ust_dynamic_type {
283 LTTNG_UST_DYNAMIC_TYPE_NONE,
284 LTTNG_UST_DYNAMIC_TYPE_S8,
285 LTTNG_UST_DYNAMIC_TYPE_S16,
286 LTTNG_UST_DYNAMIC_TYPE_S32,
287 LTTNG_UST_DYNAMIC_TYPE_S64,
288 LTTNG_UST_DYNAMIC_TYPE_U8,
289 LTTNG_UST_DYNAMIC_TYPE_U16,
290 LTTNG_UST_DYNAMIC_TYPE_U32,
291 LTTNG_UST_DYNAMIC_TYPE_U64,
292 LTTNG_UST_DYNAMIC_TYPE_FLOAT,
293 LTTNG_UST_DYNAMIC_TYPE_DOUBLE,
294 LTTNG_UST_DYNAMIC_TYPE_STRING,
295 _NR_LTTNG_UST_DYNAMIC_TYPES,
296};
297
298struct lttng_ctx_value {
299 enum lttng_ust_dynamic_type sel;
300 union {
301 int64_t s64;
86133caf 302 uint64_t u64;
53569322
MD
303 const char *str;
304 double d;
305 } u;
77aa5901
MD
306};
307
d58d1454
MD
308struct lttng_perf_counter_field;
309
37d5e202 310#define LTTNG_UST_CTX_FIELD_PADDING 40
8020ceb5
MD
311struct lttng_ctx_field {
312 struct lttng_event_field event_field;
53569322 313 size_t (*get_size)(struct lttng_ctx_field *field, size_t offset);
8020ceb5 314 void (*record)(struct lttng_ctx_field *field,
4cfec15c 315 struct lttng_ust_lib_ring_buffer_ctx *ctx,
7dd08bec 316 struct lttng_channel *chan);
77aa5901 317 void (*get_value)(struct lttng_ctx_field *field,
53569322 318 struct lttng_ctx_value *value);
8020ceb5 319 union {
d58d1454 320 struct lttng_perf_counter_field *perf_counter;
37d5e202 321 char padding[LTTNG_UST_CTX_FIELD_PADDING];
8020ceb5
MD
322 } u;
323 void (*destroy)(struct lttng_ctx_field *field);
53569322 324 char *field_name; /* Has ownership, dynamically allocated. */
8020ceb5
MD
325};
326
b2cc986a 327#define LTTNG_UST_CTX_PADDING 20
8020ceb5
MD
328struct lttng_ctx {
329 struct lttng_ctx_field *fields;
330 unsigned int nr_fields;
331 unsigned int allocated_fields;
b2cc986a 332 unsigned int largest_align;
37d5e202
MD
333 char padding[LTTNG_UST_CTX_PADDING];
334};
335
336#define LTTNG_UST_EVENT_DESC_PADDING 40
337struct lttng_event_desc {
338 const char *name;
bb84a1ec 339 void (*probe_callback)(void); /* store-event and count-event probe */
37d5e202
MD
340 const struct lttng_event_ctx *ctx; /* context */
341 const struct lttng_event_field *fields; /* event payload */
342 unsigned int nr_fields;
343 const int **loglevel;
68755429 344 const char *signature; /* Argument types/names received */
6ddc916d
MD
345 union {
346 struct {
347 const char **model_emf_uri;
d8d2416d 348 void (*event_notifier_callback)(void);
6ddc916d
MD
349 } ext;
350 char padding[LTTNG_UST_EVENT_DESC_PADDING];
351 } u;
37d5e202
MD
352};
353
71d31690 354#define LTTNG_UST_PROBE_DESC_PADDING 12
37d5e202
MD
355struct lttng_probe_desc {
356 const char *provider;
357 const struct lttng_event_desc **event_desc;
358 unsigned int nr_events;
359 struct cds_list_head head; /* chain registered probes */
6715d7d1
MD
360 struct cds_list_head lazy_init_head;
361 int lazy; /* lazy registration */
71d31690
MD
362 uint32_t major;
363 uint32_t minor;
37d5e202 364 char padding[LTTNG_UST_PROBE_DESC_PADDING];
8020ceb5
MD
365};
366
37d5e202
MD
367/* Data structures used by the tracer. */
368
e450e339
FD
369enum lttng_enabler_format_type {
370 LTTNG_ENABLER_FORMAT_STAR_GLOB,
371 LTTNG_ENABLER_FORMAT_EVENT,
e6c12e3d
MD
372};
373
c8fcf224
MD
374struct tp_list_entry {
375 struct lttng_ust_tracepoint_iter tp;
376 struct cds_list_head head;
377};
378
379struct lttng_ust_tracepoint_list {
380 struct tp_list_entry *iter;
381 struct cds_list_head head;
8020ceb5
MD
382};
383
06d4f27e
MD
384struct tp_field_list_entry {
385 struct lttng_ust_field_iter field;
386 struct cds_list_head head;
387};
388
389struct lttng_ust_field_list {
390 struct tp_field_list_entry *iter;
391 struct cds_list_head head;
392};
393
8165c8da 394struct ust_pending_probe;
7dd08bec 395struct lttng_event;
f488575f 396
8a92ed2a 397/*
04aa13f8 398 * Bytecode interpreter return value masks.
8a92ed2a 399 */
04aa13f8
FD
400enum lttng_bytecode_interpreter_ret {
401 LTTNG_INTERPRETER_DISCARD = 0,
402 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
8a92ed2a
MD
403 /* Other bits are kept for future use. */
404};
405
d37ecb3f
FD
406struct lttng_interpreter_output;
407
73d37531
FD
408/*
409 * This structure is used in the probes. More specifically, the `filter` and
410 * `node` fields are explicity used in the probes. When modifying this
411 * structure we must not change the layout of these two fields as it is
412 * considered ABI.
413 */
f488575f
MD
414struct lttng_bytecode_runtime {
415 /* Associated bytecode */
ab249ecf 416 struct lttng_ust_bytecode_node *bc;
c42416df
FD
417 union {
418 uint64_t (*filter)(void *interpreter_data,
419 const char *interpreter_stack_data);
d37ecb3f
FD
420 uint64_t (*capture)(void *interpreter_data,
421 const char *interpreter_stack_data,
422 struct lttng_interpreter_output *interpreter_output);
c42416df 423 } interpreter_funcs;
21af05a9 424 int link_failed;
e58095ef 425 struct cds_list_head node; /* list of bytecode runtime in event */
b77aaa1b 426 /*
d8d2416d
FD
427 * Pointer to a URCU-protected pointer owned by an `struct
428 * lttng_session`or `struct lttng_event_notifier_group`.
b77aaa1b
FD
429 */
430 struct lttng_ctx **pctx;
e58095ef
MD
431};
432
433/*
d8d2416d
FD
434 * Objects in a linked-list of enablers, owned by an event or event_notifier.
435 * This is used because an event (or a event_notifier) can be enabled by more
436 * than one enabler and we want a quick way to iterate over all enablers of an
437 * object.
438 *
439 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
440 * event with the name "my_app:abc".
e58095ef
MD
441 */
442struct lttng_enabler_ref {
443 struct cds_list_head node; /* enabler ref list */
444 struct lttng_enabler *ref; /* backward ref */
f488575f 445};
8165c8da 446
bb84a1ec
MD
447enum lttng_event_container_type {
448 LTTNG_EVENT_CONTAINER_CHANNEL,
449 LTTNG_EVENT_CONTAINER_COUNTER,
450};
451
452enum lttng_key_token_type {
453 LTTNG_KEY_TOKEN_STRING = 0,
454 LTTNG_KEY_TOKEN_EVENT_NAME = 1,
455 LTTNG_KEY_TOKEN_PROVIDER_NAME = 2,
456};
457
458#define LTTNG_KEY_TOKEN_STRING_LEN_MAX LTTNG_UST_KEY_TOKEN_STRING_LEN_MAX
459struct lttng_key_token {
460 enum lttng_key_token_type type;
461 union {
462 char string[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
463 } arg;
464};
465
466#define LTTNG_NR_KEY_TOKEN LTTNG_UST_NR_KEY_TOKEN
467struct lttng_counter_key_dimension {
468 size_t nr_key_tokens;
469 struct lttng_key_token key_tokens[LTTNG_UST_NR_KEY_TOKEN];
470};
471
472#define LTTNG_COUNTER_DIMENSION_MAX LTTNG_UST_COUNTER_DIMENSION_MAX
473struct lttng_counter_key {
474 size_t nr_dimensions;
475 struct lttng_counter_key_dimension key_dimensions[LTTNG_COUNTER_DIMENSION_MAX];
476};
477
8020ceb5 478/*
7dd08bec
MD
479 * lttng_event structure is referred to by the tracing fast path. It
480 * must be kept small.
180901e6
MD
481 *
482 * IMPORTANT: this structure is part of the ABI between the probe and
483 * UST. Fields need to be only added at the end, never reordered, never
484 * removed.
8020ceb5 485 */
7dd08bec 486struct lttng_event {
8020ceb5 487 unsigned int id;
bb84a1ec 488 struct lttng_channel *chan; /* for backward compatibility */
976fe9ea 489 int enabled;
8020ceb5 490 const struct lttng_event_desc *desc;
8020ceb5 491 struct lttng_ctx *ctx;
9f3fdbc6 492 enum lttng_ust_instrumentation instrumentation;
e58095ef 493 struct cds_list_head node; /* Event list in session */
e58095ef 494
e58095ef 495 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
a56fd376 496 struct cds_list_head filter_bytecode_runtime_head;
dcdeaff0 497 int has_enablers_without_bytecode;
e58095ef
MD
498 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
499 struct cds_list_head enablers_ref_head;
bb84a1ec
MD
500 struct cds_hlist_node name_hlist; /* session ht of events, per event name */
501 int registered; /* has reg'd tracepoint probe */
502
503 /* LTTng-UST 2.14 starts here */
504 uint64_t counter_index; /* counter index */
505 struct lttng_event_container *container;
506 struct cds_hlist_node key_hlist; /* session ht of events, per key */
507 char key[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
508 /*
509 * For non-coalesce-hit event containers, each events is
510 * associated with a single event enabler token.
511 */
512 uint64_t user_token;
8020ceb5
MD
513};
514
d8d2416d
FD
515struct lttng_event_notifier {
516 uint64_t user_token;
6566528b 517 uint64_t error_counter_index;
d8d2416d
FD
518 int enabled;
519 int registered; /* has reg'd tracepoint probe */
d37ecb3f 520 size_t num_captures; /* Needed to allocate the msgpack array. */
cab88ff8
MD
521 void (*notification_send)(struct lttng_event_notifier *event_notifier,
522 const char *stack_data);
d8d2416d 523 struct cds_list_head filter_bytecode_runtime_head;
d37ecb3f 524 struct cds_list_head capture_bytecode_runtime_head;
d8d2416d
FD
525 int has_enablers_without_bytecode;
526 struct cds_list_head enablers_ref_head;
527 const struct lttng_event_desc *desc;
528 struct cds_hlist_node hlist; /* hashtable of event_notifiers */
529 struct cds_list_head node; /* event_notifier list in session */
530 struct lttng_event_notifier_group *group; /* weak ref */
531};
532
c785c634
MD
533struct lttng_enum {
534 const struct lttng_enum_desc *desc;
535 struct lttng_session *session;
536 struct cds_list_head node; /* Enum list in session */
537 struct cds_hlist_node hlist; /* Session ht of enums */
538 uint64_t id; /* Enumeration ID in sessiond */
539};
540
8d8a24c8 541struct channel;
38fae1d3 542struct lttng_ust_shm_handle;
8d8a24c8 543
180901e6
MD
544/*
545 * IMPORTANT: this structure is part of the ABI between the probe and
546 * UST. Fields need to be only added at the end, never reordered, never
547 * removed.
548 */
7dd08bec
MD
549struct lttng_channel_ops {
550 struct lttng_channel *(*channel_create)(const char *name,
74d81a6c
MD
551 void *buf_addr,
552 size_t subbuf_size, size_t num_subbuf,
553 unsigned int switch_timer_interval,
554 unsigned int read_timer_interval,
6ca18e66 555 unsigned char *uuid,
a9ff648c 556 uint32_t chan_id,
b2c5f61a
MD
557 const int *stream_fds, int nr_stream_fds,
558 int64_t blocking_timeout);
74d81a6c 559 void (*channel_destroy)(struct lttng_channel *chan);
4cfec15c 560 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5 561 uint32_t event_id);
4cfec15c 562 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
74d81a6c
MD
563 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
564 const void *src, size_t len);
8020ceb5
MD
565 /*
566 * packet_avail_size returns the available size in the current
567 * packet. Note that the size returned is only a hint, since it
568 * may change due to concurrent writes.
569 */
1d498196 570 size_t (*packet_avail_size)(struct channel *chan,
38fae1d3 571 struct lttng_ust_shm_handle *handle);
8020ceb5
MD
572 int (*is_finalized)(struct channel *chan);
573 int (*is_disabled)(struct channel *chan);
38fae1d3 574 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
a44c74d9
MD
575 void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
576 const char *src, size_t len);
8020ceb5
MD
577};
578
bb84a1ec
MD
579/*
580 * This structure is ABI with the tracepoint probes, and must preserve
581 * backward compatibility. Fields can only be added at the end, and
582 * never removed nor reordered.
583 */
584struct lttng_event_container {
585 enum lttng_event_container_type type;
586 int objd;
587 struct lttng_session *session; /* Session containing the container */
588 int enabled;
589 unsigned int tstate:1; /* Transient enable state */
590 bool coalesce_hits;
591};
592
180901e6
MD
593/*
594 * IMPORTANT: this structure is part of the ABI between the probe and
595 * UST. Fields need to be only added at the end, never reordered, never
596 * removed.
597 */
7dd08bec 598struct lttng_channel {
a3f61e7f
MD
599 /*
600 * The pointers located in this private data are NOT safe to be
601 * dereferenced by the consumer. The only operations the
602 * consumer process is designed to be allowed to do is to read
603 * and perform subbuffer flush.
604 */
8020ceb5 605 struct channel *chan; /* Channel buffers */
bb84a1ec 606 int enabled; /* For backward compatibility */
8020ceb5
MD
607 struct lttng_ctx *ctx;
608 /* Event ID management */
bb84a1ec 609 struct lttng_session *session; /* For backward compatibility */
0a42beb6 610 int objd; /* Object associated to channel */
e58095ef 611 struct cds_list_head node; /* Channel list in session */
74d81a6c 612 const struct lttng_channel_ops *ops;
8020ceb5 613 int header_type; /* 0: unset, 1: compact, 2: large */
38fae1d3 614 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
a3f61e7f 615
74d81a6c 616 /* Channel ID */
a3f61e7f 617 unsigned int id;
74d81a6c 618 enum lttng_ust_chan_type type;
19d8b1b3 619 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
bb84a1ec 620 int _deprecated:1;
8020ceb5 621
bb84a1ec 622 struct lttng_event_container parent;
ebabbf58
MD
623};
624
625struct lttng_counter_ops {
626 struct lib_counter *(*counter_create)(size_t nr_dimensions,
bb84a1ec 627 const size_t *dimensions,
ebabbf58
MD
628 int64_t global_sum_step,
629 int global_counter_fd,
630 int nr_counter_cpu_fds,
631 const int *counter_cpu_fds,
632 bool is_daemon);
633 void (*counter_destroy)(struct lib_counter *counter);
634 int (*counter_add)(struct lib_counter *counter,
635 const size_t *dimension_indexes, int64_t v);
636 int (*counter_read)(struct lib_counter *counter,
637 const size_t *dimension_indexes, int cpu,
638 int64_t *value, bool *overflow, bool *underflow);
639 int (*counter_aggregate)(struct lib_counter *counter,
640 const size_t *dimension_indexes, int64_t *value,
641 bool *overflow, bool *underflow);
642 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
643};
644
53569322
MD
645#define LTTNG_UST_STACK_CTX_PADDING 32
646struct lttng_stack_ctx {
647 struct lttng_event *event;
648 struct lttng_ctx *chan_ctx; /* RCU dereferenced. */
649 struct lttng_ctx *event_ctx; /* RCU dereferenced. */
650 char padding[LTTNG_UST_STACK_CTX_PADDING];
651};
652
71a9d034 653#define LTTNG_UST_EVENT_HT_BITS 12
e58095ef
MD
654#define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
655
656struct lttng_ust_event_ht {
657 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
658};
659
d8d2416d
FD
660#define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
661#define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
662struct lttng_ust_event_notifier_ht {
663 struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE];
664};
665
c785c634
MD
666#define LTTNG_UST_ENUM_HT_BITS 12
667#define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
668
669struct lttng_ust_enum_ht {
670 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
671};
672
180901e6
MD
673/*
674 * IMPORTANT: this structure is part of the ABI between the probe and
675 * UST. Fields need to be only added at the end, never reordered, never
676 * removed.
677 */
7dd08bec 678struct lttng_session {
e58095ef
MD
679 int active; /* Is trace session active ? */
680 int been_active; /* Been active ? */
681 int objd; /* Object associated */
e58095ef
MD
682 struct cds_list_head chan_head; /* Channel list head */
683 struct cds_list_head events_head; /* list of events */
e58095ef 684 struct cds_list_head node; /* Session list */
e58095ef
MD
685
686 /* New UST 2.1 */
687 /* List of enablers */
688 struct cds_list_head enablers_head;
bb84a1ec
MD
689 /* hash table of events, indexed by name */
690 struct lttng_ust_event_ht events_name_ht;
32ce8569 691 void *owner; /* object owner */
ac6b4ac6 692 int tstate:1; /* Transient enable state */
246be17e
PW
693
694 /* New UST 2.4 */
695 int statedump_pending:1;
c785c634
MD
696
697 /* New UST 2.8 */
698 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
699 struct cds_list_head enums_head;
53569322 700 struct lttng_ctx *ctx; /* contexts for filters. */
bb84a1ec
MD
701
702 /* New UST 2.14 */
703 struct cds_list_head counters; /* Counters list */
704 /* hash table of events, indexed by key */
705 struct lttng_ust_event_ht events_key_ht;
8020ceb5
MD
706};
707
ebabbf58 708struct lttng_counter {
bb84a1ec
MD
709 struct lttng_event_container parent;
710 union {
711 struct lttng_event_notifier_group *event_notifier_group;
712 struct lttng_session *session;
713 } owner;
ebabbf58
MD
714 struct lttng_counter_transport *transport;
715 struct lib_counter *counter;
716 struct lttng_counter_ops *ops;
bb84a1ec
MD
717 struct cds_list_head node; /* Counter list (in session) */
718 size_t free_index; /* Next index to allocate */
ebabbf58
MD
719};
720
d8d2416d
FD
721struct lttng_event_notifier_group {
722 int objd;
723 void *owner;
724 int notification_fd;
725 struct cds_list_head node; /* Event notifier group handle list */
726 struct cds_list_head enablers_head;
727 struct cds_list_head event_notifiers_head; /* list of event_notifiers */
728 struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */
729 struct lttng_ctx *ctx; /* contexts for filters. */
ebabbf58
MD
730
731 struct lttng_counter *error_counter;
732 size_t error_counter_len;
d8d2416d
FD
733};
734
7dd08bec 735struct lttng_transport {
8020ceb5 736 char *name;
9f3fdbc6 737 struct cds_list_head node;
7dd08bec 738 struct lttng_channel_ops ops;
74d81a6c 739 const struct lttng_ust_lib_ring_buffer_config *client_config;
8020ceb5
MD
740};
741
ebabbf58
MD
742struct lttng_counter_transport {
743 char *name;
744 struct cds_list_head node;
745 struct lttng_counter_ops ops;
746 const struct lib_counter_config *client_config;
747};
748
7dd08bec
MD
749struct lttng_session *lttng_session_create(void);
750int lttng_session_enable(struct lttng_session *session);
751int lttng_session_disable(struct lttng_session *session);
710b8ee3 752int lttng_session_statedump(struct lttng_session *session);
7dd08bec 753void lttng_session_destroy(struct lttng_session *session);
8020ceb5 754
bb84a1ec
MD
755int lttng_event_container_enable(struct lttng_event_container *container);
756int lttng_event_container_disable(struct lttng_event_container *container);
e58095ef 757
e58095ef 758int lttng_attach_context(struct lttng_ust_context *context_param,
8e696cfa 759 union ust_args *uargs,
e58095ef 760 struct lttng_ctx **ctx, struct lttng_session *session);
7dd08bec
MD
761void lttng_transport_register(struct lttng_transport *transport);
762void lttng_transport_unregister(struct lttng_transport *transport);
8020ceb5 763
bb84a1ec
MD
764void lttng_counter_transport_register(struct lttng_counter_transport *transport);
765void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
766
7dd08bec
MD
767int lttng_probe_register(struct lttng_probe_desc *desc);
768void lttng_probe_unregister(struct lttng_probe_desc *desc);
35ac38cb 769void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc);
5f733922 770int lttng_fix_pending_events(void);
7dd08bec
MD
771int lttng_probes_init(void);
772void lttng_probes_exit(void);
8173ec7c 773int lttng_find_context(struct lttng_ctx *ctx, const char *name);
77aa5901 774int lttng_get_context_index(struct lttng_ctx *ctx, const char *name);
8173ec7c 775struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
b2cc986a 776void lttng_context_update(struct lttng_ctx *ctx);
8173ec7c 777void lttng_remove_context_field(struct lttng_ctx **ctx_p,
8020ceb5
MD
778 struct lttng_ctx_field *field);
779void lttng_destroy_context(struct lttng_ctx *ctx);
3b402b40 780int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
c1ef86f0 781int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
8173ec7c 782int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
4847e9bb 783int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
96f85541 784int lttng_add_ip_to_ctx(struct lttng_ctx **ctx);
c7ea8487 785int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx);
53569322 786int lttng_add_dyntest_to_ctx(struct lttng_ctx **ctx);
735bef47
MJ
787int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx);
788int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx);
789int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx);
790int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx);
791int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx);
792int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx);
793int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx);
fca2f191
MJ
794int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx);
795int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx);
796int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx);
797int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx);
798int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx);
799int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx);
a93bfc45 800void lttng_context_vtid_reset(void);
c1ef86f0 801void lttng_context_vpid_reset(void);
46228a6f 802void lttng_context_procname_reset(void);
735bef47
MJ
803void lttng_context_cgroup_ns_reset(void);
804void lttng_context_ipc_ns_reset(void);
805void lttng_context_mnt_ns_reset(void);
806void lttng_context_net_ns_reset(void);
807void lttng_context_pid_ns_reset(void);
808void lttng_context_user_ns_reset(void);
809void lttng_context_uts_ns_reset(void);
fca2f191
MJ
810void lttng_context_vuid_reset(void);
811void lttng_context_veuid_reset(void);
812void lttng_context_vsuid_reset(void);
813void lttng_context_vgid_reset(void);
814void lttng_context_vegid_reset(void);
815void lttng_context_vsgid_reset(void);
9f3fdbc6 816
d58d1454
MD
817#ifdef LTTNG_UST_HAVE_PERF_EVENT
818int lttng_add_perf_counter_to_ctx(uint32_t type,
819 uint64_t config,
820 const char *name,
821 struct lttng_ctx **ctx);
822int lttng_perf_counter_init(void);
823void lttng_perf_counter_exit(void);
824#else /* #ifdef LTTNG_UST_HAVE_PERF_EVENT */
825static inline
826int lttng_add_perf_counter_to_ctx(uint32_t type,
827 uint64_t config,
828 const char *name,
829 struct lttng_ctx **ctx)
830{
831 return -ENOSYS;
832}
833static inline
834int lttng_perf_counter_init(void)
835{
836 return 0;
837}
838static inline
839void lttng_perf_counter_exit(void)
840{
841}
842#endif /* #else #ifdef LTTNG_UST_HAVE_PERF_EVENT */
843
82b9bde8
JD
844extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
845extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
846extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
c1fca457 847
7dd08bec 848struct lttng_transport *lttng_transport_find(const char *name);
c1fca457 849
7dd08bec
MD
850int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
851void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
c8fcf224
MD
852struct lttng_ust_tracepoint_iter *
853 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
7dd08bec
MD
854int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
855void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
06d4f27e
MD
856struct lttng_ust_field_iter *
857 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
c8fcf224 858
7dd08bec 859void lttng_free_event_filter_runtime(struct lttng_event *event);
e58095ef
MD
860
861struct cds_list_head *lttng_get_probe_list_head(void);
6715d7d1 862int lttng_session_active(void);
e6c12e3d 863
246be17e 864typedef int (*t_statedump_func_ptr)(struct lttng_session *session);
3327ac33 865void lttng_handle_pending_statedump(void *owner);
37dddb65 866struct cds_list_head *_lttng_get_sessions(void);
b33b46f7
FD
867
868struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
869 const struct lttng_enum_desc *enum_desc);
246be17e 870
97c7c238 871void lttng_ust_dl_update(void *ip);
6548fca4 872void lttng_ust_fixup_fd_tracker_tls(void);
97c7c238 873
bb84a1ec
MD
874static inline
875struct lttng_event_container *lttng_channel_get_event_container(struct lttng_channel *channel)
876{
877 return &channel->parent;
878}
879
880static inline
881struct lttng_event_container *lttng_counter_get_event_container(struct lttng_counter *counter)
882{
883 return &counter->parent;
884}
885
886static inline
887struct lttng_channel *lttng_event_container_get_channel(struct lttng_event_container *container)
888{
889 if (container->type != LTTNG_EVENT_CONTAINER_CHANNEL)
890 return NULL;
891 return caa_container_of(container, struct lttng_channel, parent);
892}
893
894static inline
895struct lttng_counter *lttng_event_container_get_counter(struct lttng_event_container *container)
896{
897 if (container->type != LTTNG_EVENT_CONTAINER_COUNTER)
898 return NULL;
899 return caa_container_of(container, struct lttng_counter, parent);
900}
901
6453d237
MD
902#ifdef __cplusplus
903}
904#endif
905
51489cad 906#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.09474 seconds and 5 git commands to generate.