Fix ABI: add padding to structures shared between UST and consumer
[lttng-ust.git] / include / lttng / ust-events.h
CommitLineData
51489cad
MD
1#ifndef _LTTNG_UST_EVENTS_H
2#define _LTTNG_UST_EVENTS_H
8020ceb5
MD
3
4/*
51489cad 5 * lttng/ust-events.h
8020ceb5
MD
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
a60d70e6
MD
11 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
12 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
13 *
14 * Permission is hereby granted to use or copy this program
15 * for any purpose, provided the above notices are retained on all copies.
16 * Permission to modify the code and to distribute modified code is granted,
17 * provided the above notices are retained, and a notice that the code was
18 * modified is included with the above copyright notice.
8020ceb5
MD
19 */
20
9f3fdbc6 21#include <urcu/list.h>
1f18504e 22#include <urcu/hlist.h>
578ce73a 23#include <uuid/uuid.h>
9f3fdbc6 24#include <stdint.h>
4318ae1b
MD
25#include <lttng/ust-abi.h>
26#include <lttng/ust-tracer.h>
a7859af5 27#include <endian.h>
20f1eee7 28#include <float.h>
8020ceb5 29
8020ceb5
MD
30struct ltt_channel;
31struct ltt_session;
4cfec15c 32struct lttng_ust_lib_ring_buffer_ctx;
8020ceb5 33
37d5e202
MD
34/*
35 * Data structures used by tracepoint event declarations, and by the
36 * tracer. Those structures have padding for future extension.
37 */
38
c1fca457
MD
39/*
40 * LTTng client type enumeration. Used by the consumer to map the
41 * callbacks from its own address space.
42 */
43enum lttng_client_types {
44 LTTNG_CLIENT_METADATA = 0,
45 LTTNG_CLIENT_DISCARD = 1,
46 LTTNG_CLIENT_OVERWRITE = 2,
47 LTTNG_NR_CLIENT_TYPES,
48};
49
8020ceb5
MD
50/* Type description */
51
52/* Update the astract_types name table in lttng-types.c along with this enum */
53enum abstract_types {
54 atype_integer,
55 atype_enum,
56 atype_array,
57 atype_sequence,
58 atype_string,
20f1eee7 59 atype_float,
8020ceb5
MD
60 NR_ABSTRACT_TYPES,
61};
62
63/* Update the string_encodings name table in lttng-types.c along with this enum */
64enum lttng_string_encodings {
65 lttng_encode_none = 0,
66 lttng_encode_UTF8 = 1,
67 lttng_encode_ASCII = 2,
68 NR_STRING_ENCODINGS,
69};
70
37d5e202 71#define LTTNG_UST_ENUM_ENTRY_PADDING 16
8020ceb5
MD
72struct lttng_enum_entry {
73 unsigned long long start, end; /* start and end are inclusive */
74 const char *string;
37d5e202 75 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
8020ceb5
MD
76};
77
78#define __type_integer(_type, _byte_order, _base, _encoding) \
79 { \
80 .atype = atype_integer, \
81 .u.basic.integer = \
82 { \
83 .size = sizeof(_type) * CHAR_BIT, \
1dbfff0c
MD
84 .alignment = lttng_alignof(_type) * CHAR_BIT, \
85 .signedness = lttng_is_signed_type(_type), \
40af798b 86 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
8020ceb5
MD
87 .base = _base, \
88 .encoding = lttng_encode_##_encoding, \
89 }, \
90 } \
91
37d5e202 92#define LTTNG_UST_INTEGER_TYPE_PADDING 24
8020ceb5
MD
93struct lttng_integer_type {
94 unsigned int size; /* in bits */
95 unsigned short alignment; /* in bits */
96 unsigned int signedness:1;
97 unsigned int reverse_byte_order:1;
98 unsigned int base; /* 2, 8, 10, 16, for pretty print */
99 enum lttng_string_encodings encoding;
37d5e202 100 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
8020ceb5
MD
101};
102
d3ed854b
MD
103/*
104 * Only float and double are supported. long double is not supported at
105 * the moment.
106 */
20f1eee7
MD
107#define _float_mant_dig(_type) \
108 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
109 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
d3ed854b 110 : 0))
20f1eee7
MD
111
112#define __type_float(_type) \
113 { \
114 .atype = atype_float, \
115 .u.basic._float = \
116 { \
117 .exp_dig = sizeof(_type) * CHAR_BIT \
118 - _float_mant_dig(_type), \
119 .mant_dig = _float_mant_dig(_type), \
1dbfff0c 120 .alignment = lttng_alignof(_type) * CHAR_BIT, \
7d97fea8 121 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
20f1eee7
MD
122 }, \
123 } \
124
37d5e202 125#define LTTNG_UST_FLOAT_TYPE_PADDING 24
20f1eee7
MD
126struct lttng_float_type {
127 unsigned int exp_dig; /* exponent digits, in bits */
128 unsigned int mant_dig; /* mantissa digits, in bits */
129 unsigned short alignment; /* in bits */
130 unsigned int reverse_byte_order:1;
37d5e202 131 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
20f1eee7
MD
132};
133
37d5e202 134#define LTTNG_UST_BASIC_TYPE_PADDING 128
8020ceb5
MD
135union _lttng_basic_type {
136 struct lttng_integer_type integer;
137 struct {
138 const char *name;
139 } enumeration;
140 struct {
141 enum lttng_string_encodings encoding;
142 } string;
20f1eee7 143 struct lttng_float_type _float;
37d5e202 144 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
8020ceb5
MD
145};
146
147struct lttng_basic_type {
148 enum abstract_types atype;
149 union {
150 union _lttng_basic_type basic;
151 } u;
152};
153
37d5e202 154#define LTTNG_UST_TYPE_PADDING 128
8020ceb5
MD
155struct lttng_type {
156 enum abstract_types atype;
157 union {
158 union _lttng_basic_type basic;
159 struct {
160 struct lttng_basic_type elem_type;
161 unsigned int length; /* num. elems. */
162 } array;
163 struct {
164 struct lttng_basic_type length_type;
165 struct lttng_basic_type elem_type;
166 } sequence;
37d5e202 167 char padding[LTTNG_UST_TYPE_PADDING];
8020ceb5
MD
168 } u;
169};
170
37d5e202 171#define LTTNG_UST_ENUM_TYPE_PADDING 24
8020ceb5
MD
172struct lttng_enum {
173 const char *name;
174 struct lttng_type container_type;
175 const struct lttng_enum_entry *entries;
23c8854a 176 unsigned int len;
37d5e202 177 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
8020ceb5
MD
178};
179
180/* Event field description */
181
37d5e202 182#define LTTNG_UST_EVENT_FIELD_PADDING 32
8020ceb5
MD
183struct lttng_event_field {
184 const char *name;
185 struct lttng_type type;
37d5e202 186 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
8020ceb5
MD
187};
188
37d5e202 189#define LTTNG_UST_CTX_FIELD_PADDING 40
8020ceb5
MD
190struct lttng_ctx_field {
191 struct lttng_event_field event_field;
192 size_t (*get_size)(size_t offset);
193 void (*record)(struct lttng_ctx_field *field,
4cfec15c 194 struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5
MD
195 struct ltt_channel *chan);
196 union {
37d5e202 197 char padding[LTTNG_UST_CTX_FIELD_PADDING];
8020ceb5
MD
198 } u;
199 void (*destroy)(struct lttng_ctx_field *field);
200};
201
37d5e202 202#define LTTNG_UST_CTX_PADDING 24
8020ceb5
MD
203struct lttng_ctx {
204 struct lttng_ctx_field *fields;
205 unsigned int nr_fields;
206 unsigned int allocated_fields;
37d5e202
MD
207 char padding[LTTNG_UST_CTX_PADDING];
208};
209
210#define LTTNG_UST_EVENT_DESC_PADDING 40
211struct lttng_event_desc {
212 const char *name;
213 void *probe_callback;
214 const struct lttng_event_ctx *ctx; /* context */
215 const struct lttng_event_field *fields; /* event payload */
216 unsigned int nr_fields;
217 const int **loglevel;
218 char padding[LTTNG_UST_EVENT_DESC_PADDING];
219};
220
221#define LTTNG_UST_PROBE_DESC_PADDING 40
222struct lttng_probe_desc {
223 const char *provider;
224 const struct lttng_event_desc **event_desc;
225 unsigned int nr_events;
226 struct cds_list_head head; /* chain registered probes */
227 char padding[LTTNG_UST_PROBE_DESC_PADDING];
8020ceb5
MD
228};
229
37d5e202
MD
230/* Data structures used by the tracer. */
231
e6c12e3d
MD
232/*
233 * Entry describing a per-session active wildcard, along with the event
234 * attribute and channel information configuring the events that need to
235 * be enabled.
236 */
237struct session_wildcard {
238 struct ltt_channel *chan;
239 struct lttng_ctx *ctx; /* TODO */
240 struct lttng_ust_event event_param;
241 struct cds_list_head events; /* list of events enabled */
242 struct cds_list_head list; /* per-session list of wildcards */
51c5df09 243 struct cds_list_head session_list; /* node of session wildcard list */
e6c12e3d
MD
244 struct wildcard_entry *entry;
245 unsigned int enabled:1;
246};
247
248/*
249 * Entry describing an active wildcard (per name) for all sessions.
250 */
251struct wildcard_entry {
51c5df09 252 /* node of global wildcards list */
e6c12e3d 253 struct cds_list_head list;
51c5df09 254 /* head of session list to which this wildcard apply */
e6c12e3d 255 struct cds_list_head session_list;
457a6b58
MD
256 enum lttng_ust_loglevel_type loglevel_type;
257 int loglevel;
e6c12e3d
MD
258 char name[0];
259};
260
c8fcf224
MD
261struct tp_list_entry {
262 struct lttng_ust_tracepoint_iter tp;
263 struct cds_list_head head;
264};
265
266struct lttng_ust_tracepoint_list {
267 struct tp_list_entry *iter;
268 struct cds_list_head head;
8020ceb5
MD
269};
270
8165c8da
MD
271struct ust_pending_probe;
272
8020ceb5
MD
273/*
274 * ltt_event structure is referred to by the tracing fast path. It must be
275 * kept small.
276 */
277struct ltt_event {
278 unsigned int id;
279 struct ltt_channel *chan;
976fe9ea 280 int enabled;
8020ceb5
MD
281 const struct lttng_event_desc *desc;
282 void *filter;
283 struct lttng_ctx *ctx;
9f3fdbc6 284 enum lttng_ust_instrumentation instrumentation;
8020ceb5 285 union {
8020ceb5 286 } u;
9f3fdbc6 287 struct cds_list_head list; /* Event list */
e6c12e3d 288 struct cds_list_head wildcard_list; /* Event list for wildcard */
8165c8da 289 struct ust_pending_probe *pending_probe;
7c2caf2b 290 unsigned int metadata_dumped:1;
8020ceb5
MD
291};
292
8d8a24c8 293struct channel;
38fae1d3 294struct lttng_ust_shm_handle;
8d8a24c8 295
8020ceb5 296struct ltt_channel_ops {
1d498196 297 struct ltt_channel *(*channel_create)(const char *name,
8020ceb5
MD
298 void *buf_addr,
299 size_t subbuf_size, size_t num_subbuf,
300 unsigned int switch_timer_interval,
193183fb 301 unsigned int read_timer_interval,
ef9ff354
MD
302 int **shm_fd, int **wait_fd,
303 uint64_t **memory_map_size,
d028eddb 304 struct ltt_channel *chan_priv_init);
1d498196 305 void (*channel_destroy)(struct ltt_channel *ltt_chan);
4cfec15c 306 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
38fae1d3 307 struct lttng_ust_shm_handle *handle,
ef9ff354
MD
308 int **shm_fd, int **wait_fd,
309 uint64_t **memory_map_size);
4cfec15c 310 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
38fae1d3 311 struct lttng_ust_shm_handle *handle);
4cfec15c 312 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
8020ceb5 313 uint32_t event_id);
4cfec15c
MD
314 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
315 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
8020ceb5
MD
316 size_t len);
317 /*
318 * packet_avail_size returns the available size in the current
319 * packet. Note that the size returned is only a hint, since it
320 * may change due to concurrent writes.
321 */
1d498196 322 size_t (*packet_avail_size)(struct channel *chan,
38fae1d3 323 struct lttng_ust_shm_handle *handle);
9f3fdbc6
MD
324 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
325 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
8020ceb5
MD
326 int (*is_finalized)(struct channel *chan);
327 int (*is_disabled)(struct channel *chan);
38fae1d3 328 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
8020ceb5
MD
329};
330
331struct ltt_channel {
a3f61e7f
MD
332 /*
333 * The pointers located in this private data are NOT safe to be
334 * dereferenced by the consumer. The only operations the
335 * consumer process is designed to be allowed to do is to read
336 * and perform subbuffer flush.
337 */
8020ceb5 338 struct channel *chan; /* Channel buffers */
976fe9ea 339 int enabled;
8020ceb5
MD
340 struct lttng_ctx *ctx;
341 /* Event ID management */
342 struct ltt_session *session;
0a42beb6 343 int objd; /* Object associated to channel */
8020ceb5 344 unsigned int free_event_id; /* Next event ID to allocate */
8165c8da 345 unsigned int used_event_id; /* Max allocated event IDs */
9f3fdbc6 346 struct cds_list_head list; /* Channel list */
8020ceb5
MD
347 struct ltt_channel_ops *ops;
348 int header_type; /* 0: unset, 1: compact, 2: large */
38fae1d3 349 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
7c2caf2b 350 unsigned int metadata_dumped:1;
a3f61e7f
MD
351
352 /* Channel ID, available for consumer too */
353 unsigned int id;
354 /* Copy of session UUID for consumer (availability through shm) */
578ce73a 355 uuid_t uuid; /* Trace session unique ID */
8020ceb5
MD
356};
357
358struct ltt_session {
359 int active; /* Is trace session active ? */
360 int been_active; /* Has trace session been active ? */
0a42beb6 361 int objd; /* Object associated to session */
8020ceb5 362 struct ltt_channel *metadata; /* Metadata channel */
9f3fdbc6
MD
363 struct cds_list_head chan; /* Channel list head */
364 struct cds_list_head events; /* Event list head */
e6c12e3d 365 struct cds_list_head wildcards; /* Wildcard list head */
9f3fdbc6 366 struct cds_list_head list; /* Session list */
8020ceb5 367 unsigned int free_chan_id; /* Next chan ID to allocate */
578ce73a 368 uuid_t uuid; /* Trace session unique ID */
7c2caf2b 369 unsigned int metadata_dumped:1;
8020ceb5
MD
370};
371
372struct ltt_transport {
373 char *name;
9f3fdbc6 374 struct cds_list_head node;
8020ceb5
MD
375 struct ltt_channel_ops ops;
376};
377
378struct ltt_session *ltt_session_create(void);
976fe9ea
MD
379int ltt_session_enable(struct ltt_session *session);
380int ltt_session_disable(struct ltt_session *session);
8020ceb5
MD
381void ltt_session_destroy(struct ltt_session *session);
382
383struct ltt_channel *ltt_channel_create(struct ltt_session *session,
384 const char *transport_name,
385 void *buf_addr,
386 size_t subbuf_size, size_t num_subbuf,
387 unsigned int switch_timer_interval,
193183fb 388 unsigned int read_timer_interval,
ef9ff354
MD
389 int **shm_fd, int **wait_fd,
390 uint64_t **memory_map_size,
d028eddb 391 struct ltt_channel *chan_priv_init);
8020ceb5
MD
392struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
393 int overwrite, void *buf_addr,
394 size_t subbuf_size, size_t num_subbuf,
395 unsigned int switch_timer_interval,
193183fb 396 unsigned int read_timer_interval,
ef9ff354
MD
397 int **shm_fd, int **wait_fd,
398 uint64_t **memory_map_size);
8020ceb5 399
576599a0
MD
400int ltt_event_create(struct ltt_channel *chan,
401 struct lttng_ust_event *event_param,
402 void *filter,
403 struct ltt_event **event);
8020ceb5 404
976fe9ea
MD
405int ltt_channel_enable(struct ltt_channel *channel);
406int ltt_channel_disable(struct ltt_channel *channel);
407int ltt_event_enable(struct ltt_event *event);
408int ltt_event_disable(struct ltt_event *event);
409
8020ceb5
MD
410void ltt_transport_register(struct ltt_transport *transport);
411void ltt_transport_unregister(struct ltt_transport *transport);
412
4b4de73e 413void synchronize_trace(void);
8020ceb5
MD
414
415int ltt_probe_register(struct lttng_probe_desc *desc);
416void ltt_probe_unregister(struct lttng_probe_desc *desc);
8165c8da 417int pending_probe_fix_events(const struct lttng_event_desc *desc);
8020ceb5
MD
418const struct lttng_event_desc *ltt_event_get(const char *name);
419void ltt_event_put(const struct lttng_event_desc *desc);
420int ltt_probes_init(void);
421void ltt_probes_exit(void);
8173ec7c
MD
422int lttng_find_context(struct lttng_ctx *ctx, const char *name);
423struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
424void lttng_remove_context_field(struct lttng_ctx **ctx_p,
8020ceb5
MD
425 struct lttng_ctx_field *field);
426void lttng_destroy_context(struct lttng_ctx *ctx);
3b402b40 427int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
c1ef86f0 428int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
8173ec7c 429int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
4847e9bb 430int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
a93bfc45 431void lttng_context_vtid_reset(void);
c1ef86f0 432void lttng_context_vpid_reset(void);
9f3fdbc6 433
7a784989
MD
434const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
435const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
436const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
c1fca457 437
c1fca457
MD
438struct ltt_transport *ltt_transport_find(const char *name);
439
c8fcf224
MD
440int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
441void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
442struct lttng_ust_tracepoint_iter *
443 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
444
e6c12e3d
MD
445int ltt_wildcard_enable(struct session_wildcard *wildcard);
446int ltt_wildcard_disable(struct session_wildcard *wildcard);
447int ltt_wildcard_create(struct ltt_channel *chan,
448 struct lttng_ust_event *event_param,
449 struct session_wildcard **sl);
457a6b58
MD
450int ltt_loglevel_match(const struct lttng_event_desc *desc,
451 enum lttng_ust_loglevel_type req_type,
452 int req_loglevel);
453void ltt_probes_create_wildcard_events(struct wildcard_entry *entry,
454 struct session_wildcard *wildcard);
e6c12e3d 455
51489cad 456#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.048644 seconds and 4 git commands to generate.