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