Cleanup: Add whitelines after struct_size fields
[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>
4318ae1b
MD
16#include <lttng/ust-abi.h>
17#include <lttng/ust-tracer.h>
2ae57758 18#include <lttng/ust-endian.h>
20f1eee7 19#include <float.h>
d58d1454
MD
20#include <errno.h>
21#include <urcu/ref.h>
22#include <pthread.h>
8020ceb5 23
db56acaf
MD
24#ifndef LTTNG_PACKED
25#error "LTTNG_PACKED should be defined"
26#endif
27
6453d237
MD
28#ifdef __cplusplus
29extern "C" {
30#endif
31
19d8b1b3
MD
32#define LTTNG_UST_UUID_LEN 16
33
71d31690
MD
34/*
35 * Tracepoint provider version. Compatibility based on the major number.
36 * Older tracepoint providers can always register to newer lttng-ust
37 * library, but the opposite is rejected: a newer tracepoint provider is
38 * rejected by an older lttng-ust library.
39 */
04f0b55a 40#define LTTNG_UST_PROVIDER_MAJOR 2
71d31690
MD
41#define LTTNG_UST_PROVIDER_MINOR 0
42
7dd08bec
MD
43struct lttng_channel;
44struct lttng_session;
4cfec15c 45struct lttng_ust_lib_ring_buffer_ctx;
25cff019 46struct lttng_ust_event_field;
ebabbf58 47struct lttng_event_notifier_group;
8020ceb5 48
37d5e202
MD
49/*
50 * Data structures used by tracepoint event declarations, and by the
51 * tracer. Those structures have padding for future extension.
52 */
53
8020ceb5
MD
54/* Type description */
55
56/* Update the astract_types name table in lttng-types.c along with this enum */
7dd08bec 57enum lttng_abstract_types {
8020ceb5 58 atype_integer,
8020ceb5 59 atype_string,
20f1eee7 60 atype_float,
53569322 61 atype_dynamic,
218deb69
MD
62 atype_enum_nestable,
63 atype_array_nestable,
64 atype_sequence_nestable,
65 atype_struct_nestable,
8020ceb5
MD
66 NR_ABSTRACT_TYPES,
67};
68
69/* Update the string_encodings name table in lttng-types.c along with this enum */
70enum lttng_string_encodings {
71 lttng_encode_none = 0,
72 lttng_encode_UTF8 = 1,
73 lttng_encode_ASCII = 2,
74 NR_STRING_ENCODINGS,
75};
76
a6f80644
MD
77struct lttng_enum_value {
78 unsigned long long value;
79 unsigned int signedness:1;
80};
81
3e762260
PP
82enum lttng_enum_entry_options {
83 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
84};
85
891d6b55
MD
86/*
87 * Enumeration entry description
88 *
89 * IMPORTANT: this structure is part of the ABI between the probe and
90 * UST. Fields need to be only added at the end, never reordered, never
91 * removed.
92 *
93 * The field @struct_size should be used to determine the size of the
94 * structure. It should be queried before using additional fields added
95 * at the end of the structure.
96 */
97
98struct lttng_ust_enum_entry {
99 uint32_t struct_size;
100
a6f80644 101 struct lttng_enum_value start, end; /* start and end are inclusive */
8020ceb5 102 const char *string;
891d6b55
MD
103 unsigned int options;
104
105 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
106};
107
108#define __type_integer(_type, _byte_order, _base, _encoding) \
109 { \
46d52200
ZT
110 .atype = atype_integer, \
111 .u = \
8020ceb5 112 { \
218deb69 113 .integer = \
46d52200 114 { \
218deb69
MD
115 .size = sizeof(_type) * CHAR_BIT, \
116 .alignment = lttng_alignof(_type) * CHAR_BIT, \
117 .signedness = lttng_is_signed_type(_type), \
118 .reverse_byte_order = _byte_order != BYTE_ORDER, \
119 .base = _base, \
120 .encoding = lttng_encode_##_encoding, \
46d52200 121 } \
8020ceb5
MD
122 }, \
123 } \
124
37d5e202 125#define LTTNG_UST_INTEGER_TYPE_PADDING 24
8020ceb5
MD
126struct lttng_integer_type {
127 unsigned int size; /* in bits */
128 unsigned short alignment; /* in bits */
129 unsigned int signedness:1;
130 unsigned int reverse_byte_order:1;
131 unsigned int base; /* 2, 8, 10, 16, for pretty print */
132 enum lttng_string_encodings encoding;
37d5e202 133 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
8020ceb5
MD
134};
135
d3ed854b
MD
136/*
137 * Only float and double are supported. long double is not supported at
138 * the moment.
139 */
20f1eee7
MD
140#define _float_mant_dig(_type) \
141 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
142 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
d3ed854b 143 : 0))
20f1eee7
MD
144
145#define __type_float(_type) \
146 { \
46d52200
ZT
147 .atype = atype_float, \
148 .u = \
20f1eee7 149 { \
218deb69 150 ._float = \
46d52200 151 { \
218deb69
MD
152 .exp_dig = sizeof(_type) * CHAR_BIT \
153 - _float_mant_dig(_type), \
154 .mant_dig = _float_mant_dig(_type), \
155 .alignment = lttng_alignof(_type) * CHAR_BIT, \
156 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
46d52200 157 } \
218deb69 158 } \
20f1eee7
MD
159 } \
160
37d5e202 161#define LTTNG_UST_FLOAT_TYPE_PADDING 24
20f1eee7
MD
162struct lttng_float_type {
163 unsigned int exp_dig; /* exponent digits, in bits */
164 unsigned int mant_dig; /* mantissa digits, in bits */
165 unsigned short alignment; /* in bits */
166 unsigned int reverse_byte_order:1;
37d5e202 167 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
20f1eee7
MD
168};
169
37d5e202 170#define LTTNG_UST_TYPE_PADDING 128
8020ceb5 171struct lttng_type {
7dd08bec 172 enum lttng_abstract_types atype;
8020ceb5 173 union {
218deb69
MD
174 /* provider ABI 2.0 */
175 struct lttng_integer_type integer;
176 struct lttng_float_type _float;
177 struct {
178 enum lttng_string_encodings encoding;
179 } string;
180 struct {
891d6b55 181 const struct lttng_ust_enum_desc *desc; /* Enumeration mapping */
218deb69
MD
182 struct lttng_type *container_type;
183 } enum_nestable;
8020ceb5 184 struct {
218deb69
MD
185 const struct lttng_type *elem_type;
186 unsigned int length; /* Num. elems. */
187 unsigned int alignment;
188 } array_nestable;
8020ceb5 189 struct {
218deb69
MD
190 const char *length_name; /* Length field name. */
191 const struct lttng_type *elem_type;
192 unsigned int alignment; /* Alignment before elements. */
193 } sequence_nestable;
53569322 194 struct {
218deb69 195 unsigned int nr_fields;
25cff019 196 const struct lttng_ust_event_field **fields; /* Array of pointers to fields. */
218deb69
MD
197 unsigned int alignment;
198 } struct_nestable;
199
37d5e202 200 char padding[LTTNG_UST_TYPE_PADDING];
8020ceb5
MD
201 } u;
202};
203
891d6b55
MD
204/*
205 * Enumeration description
206 *
207 * IMPORTANT: this structure is part of the ABI between the probe and
208 * UST. Fields need to be only added at the end, never reordered, never
209 * removed.
210 *
211 * The field @struct_size should be used to determine the size of the
212 * structure. It should be queried before using additional fields added
213 * at the end of the structure.
214 */
215
216struct lttng_ust_enum_desc {
217 uint32_t struct_size;
218
8020ceb5 219 const char *name;
891d6b55 220 const struct lttng_ust_enum_entry **entries;
c785c634 221 unsigned int nr_entries;
891d6b55
MD
222
223 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
224};
225
180901e6
MD
226/*
227 * Event field description
228 *
229 * IMPORTANT: this structure is part of the ABI between the probe and
230 * UST. Fields need to be only added at the end, never reordered, never
231 * removed.
25cff019
MD
232 *
233 * The field @struct_size should be used to determine the size of the
234 * structure. It should be queried before using additional fields added
235 * at the end of the structure.
180901e6 236 */
8020ceb5 237
25cff019
MD
238struct lttng_ust_event_field {
239 uint32_t struct_size;
240
8020ceb5
MD
241 const char *name;
242 struct lttng_type type;
25cff019
MD
243 unsigned int nowrite:1, /* do not write into trace */
244 nofilter:1; /* do not consider for filter */
245
246 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
247};
248
37d5e202 249
dc11f93f
MD
250/*
251 * IMPORTANT: this structure is part of the ABI between the probe and
252 * UST. Fields need to be only added at the end, never reordered, never
253 * removed.
254 *
255 * The field @struct_size should be used to determine the size of the
256 * structure. It should be queried before using additional fields added
257 * at the end of the structure.
258 */
259struct lttng_ust_event_desc {
260 uint32_t struct_size; /* Size of this structure. */
dc177d11 261
37d5e202 262 const char *name;
fbdeb5ec 263 void (*probe_callback)(void);
37d5e202 264 const struct lttng_event_ctx *ctx; /* context */
25cff019 265 const struct lttng_ust_event_field **fields; /* event payload */
37d5e202
MD
266 unsigned int nr_fields;
267 const int **loglevel;
dc11f93f
MD
268 const char *signature; /* Argument types/names received */
269 const char **model_emf_uri;
270
271 /* End of base ABI. Fields below should be used after checking struct_size. */
37d5e202
MD
272};
273
dc11f93f
MD
274/*
275 * IMPORTANT: this structure is part of the ABI between the probe and
276 * UST. Fields need to be only added at the end, never reordered, never
277 * removed.
278 *
279 * The field @struct_size should be used to determine the size of the
280 * structure. It should be queried before using additional fields added
281 * at the end of the structure.
282 */
283struct lttng_ust_probe_desc {
284 uint32_t struct_size; /* Size of this structure. */
285
37d5e202 286 const char *provider;
dc11f93f 287 const struct lttng_ust_event_desc **event_desc;
37d5e202
MD
288 unsigned int nr_events;
289 struct cds_list_head head; /* chain registered probes */
6715d7d1
MD
290 struct cds_list_head lazy_init_head;
291 int lazy; /* lazy registration */
71d31690
MD
292 uint32_t major;
293 uint32_t minor;
dc11f93f
MD
294
295 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
296};
297
37d5e202
MD
298/* Data structures used by the tracer. */
299
8a92ed2a 300/*
04aa13f8 301 * Bytecode interpreter return value masks.
8a92ed2a 302 */
04aa13f8
FD
303enum lttng_bytecode_interpreter_ret {
304 LTTNG_INTERPRETER_DISCARD = 0,
305 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
8a92ed2a
MD
306 /* Other bits are kept for future use. */
307};
308
d37ecb3f 309struct lttng_interpreter_output;
362a65de 310struct lttng_ust_bytecode_runtime_private;
d37ecb3f 311
73d37531 312/*
5469a374
MD
313 * IMPORTANT: this structure is part of the ABI between the probe and
314 * UST. Fields need to be only added at the end, never reordered, never
315 * removed.
316 *
317 * The field @struct_size should be used to determine the size of the
318 * structure. It should be queried before using additional fields added
319 * at the end of the structure.
73d37531 320 */
5469a374
MD
321struct lttng_ust_bytecode_runtime {
322 uint32_t struct_size; /* Size of this structure. */
362a65de 323
5469a374 324 struct lttng_ust_bytecode_runtime_private *priv;
f488575f 325 /* Associated bytecode */
c42416df
FD
326 union {
327 uint64_t (*filter)(void *interpreter_data,
328 const char *interpreter_stack_data);
d37ecb3f
FD
329 uint64_t (*capture)(void *interpreter_data,
330 const char *interpreter_stack_data,
331 struct lttng_interpreter_output *interpreter_output);
c42416df 332 } interpreter_funcs;
e58095ef 333 struct cds_list_head node; /* list of bytecode runtime in event */
5469a374
MD
334
335 /* End of base ABI. Fields below should be used after checking struct_size. */
e58095ef
MD
336};
337
8020ceb5 338/*
7dd08bec
MD
339 * lttng_event structure is referred to by the tracing fast path. It
340 * must be kept small.
180901e6
MD
341 *
342 * IMPORTANT: this structure is part of the ABI between the probe and
343 * UST. Fields need to be only added at the end, never reordered, never
344 * removed.
8020ceb5 345 */
68bb7559 346
daacdbfc 347struct lttng_ust_ctx;
80333dfa
MD
348struct lttng_ust_event_common_private;
349
808edfc8
MD
350enum lttng_ust_event_type {
351 LTTNG_UST_EVENT_TYPE_RECORDER = 0,
352 LTTNG_UST_EVENT_TYPE_NOTIFIER = 1,
353};
354
93cfd247 355/*
6d35572a
MD
356 * IMPORTANT: this structure is part of the ABI between the probe and
357 * UST. Fields need to be only added at the end, never reordered, never
358 * removed.
359 *
93cfd247
MD
360 * struct lttng_ust_event_common is the common ancestor of the various
361 * public event actions. Inheritance is done by composition: The parent
362 * has a pointer to its child, and the child has a pointer to its
363 * parent. Inheritance of those public structures is done by composition
364 * to ensure both parent and child structures can be extended.
365 *
366 * The field @struct_size should be used to determine the size of the
367 * structure. It should be queried before using additional fields added
368 * at the end of the structure.
369 */
7ee76145 370struct lttng_ust_event_common {
80333dfa 371 uint32_t struct_size; /* Size of this structure. */
dc177d11 372
80333dfa
MD
373 struct lttng_ust_event_common_private *priv; /* Private event interface */
374
808edfc8 375 enum lttng_ust_event_type type;
ba99fbe2
MD
376 void *child; /* Pointer to child, for inheritance by aggregation. */
377
80333dfa
MD
378 int enabled;
379 int has_enablers_without_bytecode;
5469a374 380 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
80333dfa 381 struct cds_list_head filter_bytecode_runtime_head;
93cfd247
MD
382
383 /* End of base ABI. Fields below should be used after checking struct_size. */
80333dfa
MD
384};
385
2e70391c 386struct lttng_ust_event_recorder_private;
68bb7559 387
93cfd247 388/*
6d35572a
MD
389 * IMPORTANT: this structure is part of the ABI between the probe and
390 * UST. Fields need to be only added at the end, never reordered, never
391 * removed.
392 *
93cfd247
MD
393 * struct lttng_ust_event_recorder is the action for recording events
394 * into a ring buffer. It inherits from struct lttng_ust_event_common
395 * by composition to ensure both parent and child structure are
396 * extensible.
397 *
398 * The field @struct_size should be used to determine the size of the
399 * structure. It should be queried before using additional fields added
400 * at the end of the structure.
401 */
2e70391c
MD
402struct lttng_ust_event_recorder {
403 uint32_t struct_size; /* Size of this structure. */
dc177d11 404
ba99fbe2 405 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
2e70391c 406 struct lttng_ust_event_recorder_private *priv; /* Private event record interface */
68bb7559 407
8020ceb5 408 unsigned int id;
68bb7559 409 struct lttng_channel *chan;
daacdbfc 410 struct lttng_ust_ctx *ctx;
93cfd247
MD
411
412 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
413};
414
115db533
MD
415struct lttng_ust_event_notifier_private;
416
93cfd247 417/*
6d35572a
MD
418 * IMPORTANT: this structure is part of the ABI between the probe and
419 * UST. Fields need to be only added at the end, never reordered, never
420 * removed.
421 *
93cfd247
MD
422 * struct lttng_ust_event_notifier is the action for sending
423 * notifications. It inherits from struct lttng_ust_event_common
424 * by composition to ensure both parent and child structure are
425 * extensible.
426 *
427 * The field @struct_size should be used to determine the size of the
428 * structure. It should be queried before using additional fields added
429 * at the end of the structure.
430 */
d7d45c0d 431struct lttng_ust_event_notifier {
115db533 432 uint32_t struct_size; /* Size of this structure. */
105cf2eb 433
ba99fbe2 434 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
115db533
MD
435 struct lttng_ust_event_notifier_private *priv; /* Private event notifier interface */
436
d7d45c0d 437 void (*notification_send)(struct lttng_ust_event_notifier *event_notifier,
cab88ff8 438 const char *stack_data);
d37ecb3f 439 struct cds_list_head capture_bytecode_runtime_head;
93cfd247
MD
440
441 /* End of base ABI. Fields below should be used after checking struct_size. */
d8d2416d
FD
442};
443
5198080d 444struct lttng_ust_lib_ring_buffer_channel;
38fae1d3 445struct lttng_ust_shm_handle;
8d8a24c8 446
180901e6
MD
447/*
448 * IMPORTANT: this structure is part of the ABI between the probe and
449 * UST. Fields need to be only added at the end, never reordered, never
450 * removed.
49926dbd
MD
451 *
452 * The field @struct_size should be used to determine the size of the
453 * structure. It should be queried before using additional fields added
454 * at the end of the structure.
180901e6 455 */
49926dbd
MD
456struct lttng_ust_channel_ops {
457 uint32_t struct_size;
458
7dd08bec 459 struct lttng_channel *(*channel_create)(const char *name,
74d81a6c
MD
460 void *buf_addr,
461 size_t subbuf_size, size_t num_subbuf,
462 unsigned int switch_timer_interval,
463 unsigned int read_timer_interval,
6ca18e66 464 unsigned char *uuid,
a9ff648c 465 uint32_t chan_id,
b2c5f61a
MD
466 const int *stream_fds, int nr_stream_fds,
467 int64_t blocking_timeout);
74d81a6c 468 void (*channel_destroy)(struct lttng_channel *chan);
4cfec15c 469 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5 470 uint32_t event_id);
4cfec15c 471 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
74d81a6c
MD
472 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
473 const void *src, size_t len);
8020ceb5
MD
474 /*
475 * packet_avail_size returns the available size in the current
476 * packet. Note that the size returned is only a hint, since it
477 * may change due to concurrent writes.
478 */
5198080d 479 size_t (*packet_avail_size)(struct lttng_ust_lib_ring_buffer_channel *chan,
38fae1d3 480 struct lttng_ust_shm_handle *handle);
5198080d
MJ
481 int (*is_finalized)(struct lttng_ust_lib_ring_buffer_channel *chan);
482 int (*is_disabled)(struct lttng_ust_lib_ring_buffer_channel *chan);
483 int (*flush_buffer)(struct lttng_ust_lib_ring_buffer_channel *chan,
484 struct lttng_ust_shm_handle *handle);
a44c74d9
MD
485 void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
486 const char *src, size_t len);
49926dbd
MD
487
488 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
489};
490
180901e6
MD
491/*
492 * IMPORTANT: this structure is part of the ABI between the probe and
493 * UST. Fields need to be only added at the end, never reordered, never
494 * removed.
495 */
7dd08bec 496struct lttng_channel {
a3f61e7f
MD
497 /*
498 * The pointers located in this private data are NOT safe to be
499 * dereferenced by the consumer. The only operations the
500 * consumer process is designed to be allowed to do is to read
501 * and perform subbuffer flush.
502 */
5198080d 503 struct lttng_ust_lib_ring_buffer_channel *chan; /* Channel buffers */
976fe9ea 504 int enabled;
daacdbfc 505 struct lttng_ust_ctx *ctx;
8020ceb5 506 /* Event ID management */
7dd08bec 507 struct lttng_session *session;
0a42beb6 508 int objd; /* Object associated to channel */
e58095ef 509 struct cds_list_head node; /* Channel list in session */
49926dbd 510 const struct lttng_ust_channel_ops *ops;
8020ceb5 511 int header_type; /* 0: unset, 1: compact, 2: large */
38fae1d3 512 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
a3f61e7f 513
74d81a6c 514 /* Channel ID */
a3f61e7f 515 unsigned int id;
fd17d7ce 516 enum lttng_ust_abi_chan_type type;
19d8b1b3 517 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
ac6b4ac6 518 int tstate:1; /* Transient enable state */
8020ceb5
MD
519};
520
2a9d9339
MD
521/*
522 * IMPORTANT: this structure is part of the ABI between the probe and
523 * UST. Fields need to be only added at the end, never reordered, never
524 * removed.
525 *
526 * The field @struct_size should be used to determine the size of the
527 * structure. It should be queried before using additional fields added
528 * at the end of the structure.
529 */
530struct lttng_ust_stack_ctx {
531 uint32_t struct_size; /* Size of this structure */
532
2e70391c 533 struct lttng_ust_event_recorder *event_recorder;
daacdbfc
MD
534 struct lttng_ust_ctx *chan_ctx; /* RCU dereferenced. */
535 struct lttng_ust_ctx *event_ctx; /* RCU dereferenced. */
2a9d9339
MD
536
537 /* End of base ABI. Fields below should be used after checking struct_size. */
53569322
MD
538};
539
bdb12629
MD
540struct lttng_ust_session_private;
541
180901e6
MD
542/*
543 * IMPORTANT: this structure is part of the ABI between the probe and
544 * UST. Fields need to be only added at the end, never reordered, never
545 * removed.
6d35572a
MD
546 *
547 * The field @struct_size should be used to determine the size of the
548 * structure. It should be queried before using additional fields added
549 * at the end of the structure.
180901e6 550 */
7dd08bec 551struct lttng_session {
bd640d74 552 uint32_t struct_size; /* Size of this structure */
dc177d11 553
bdb12629
MD
554 struct lttng_ust_session_private *priv; /* Private session interface */
555
e58095ef 556 int active; /* Is trace session active ? */
6d35572a
MD
557
558 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
559};
560
dc11f93f
MD
561int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc);
562void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc);
9f3fdbc6 563
fc80554e 564/*
0af0bdb2
MJ
565 * Applications that change their procname and need the new value to be
566 * reflected in the procname event context have to call this function to clear
567 * the internally cached value. This should not be called from a signal
568 * handler.
fc80554e 569 */
0af0bdb2 570void lttng_ust_context_procname_reset(void);
d58d1454 571
6453d237
MD
572#ifdef __cplusplus
573}
574#endif
575
51489cad 576#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.072069 seconds and 4 git commands to generate.