Fix ABI: add padding to structures shared between UST and consumer
[lttng-ust.git] / include / lttng / ust-events.h
... / ...
CommitLineData
1#ifndef _LTTNG_UST_EVENTS_H
2#define _LTTNG_UST_EVENTS_H
3
4/*
5 * lttng/ust-events.h
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
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.
19 */
20
21#include <urcu/list.h>
22#include <urcu/hlist.h>
23#include <uuid/uuid.h>
24#include <stdint.h>
25#include <lttng/ust-abi.h>
26#include <lttng/ust-tracer.h>
27#include <endian.h>
28#include <float.h>
29
30struct ltt_channel;
31struct ltt_session;
32struct lttng_ust_lib_ring_buffer_ctx;
33
34/*
35 * Data structures used by tracepoint event declarations, and by the
36 * tracer. Those structures have padding for future extension.
37 */
38
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
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,
59 atype_float,
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
71#define LTTNG_UST_ENUM_ENTRY_PADDING 16
72struct lttng_enum_entry {
73 unsigned long long start, end; /* start and end are inclusive */
74 const char *string;
75 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
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, \
84 .alignment = lttng_alignof(_type) * CHAR_BIT, \
85 .signedness = lttng_is_signed_type(_type), \
86 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
87 .base = _base, \
88 .encoding = lttng_encode_##_encoding, \
89 }, \
90 } \
91
92#define LTTNG_UST_INTEGER_TYPE_PADDING 24
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;
100 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
101};
102
103/*
104 * Only float and double are supported. long double is not supported at
105 * the moment.
106 */
107#define _float_mant_dig(_type) \
108 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
109 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
110 : 0))
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), \
120 .alignment = lttng_alignof(_type) * CHAR_BIT, \
121 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
122 }, \
123 } \
124
125#define LTTNG_UST_FLOAT_TYPE_PADDING 24
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;
131 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
132};
133
134#define LTTNG_UST_BASIC_TYPE_PADDING 128
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;
143 struct lttng_float_type _float;
144 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
145};
146
147struct lttng_basic_type {
148 enum abstract_types atype;
149 union {
150 union _lttng_basic_type basic;
151 } u;
152};
153
154#define LTTNG_UST_TYPE_PADDING 128
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;
167 char padding[LTTNG_UST_TYPE_PADDING];
168 } u;
169};
170
171#define LTTNG_UST_ENUM_TYPE_PADDING 24
172struct lttng_enum {
173 const char *name;
174 struct lttng_type container_type;
175 const struct lttng_enum_entry *entries;
176 unsigned int len;
177 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
178};
179
180/* Event field description */
181
182#define LTTNG_UST_EVENT_FIELD_PADDING 32
183struct lttng_event_field {
184 const char *name;
185 struct lttng_type type;
186 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
187};
188
189#define LTTNG_UST_CTX_FIELD_PADDING 40
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,
194 struct lttng_ust_lib_ring_buffer_ctx *ctx,
195 struct ltt_channel *chan);
196 union {
197 char padding[LTTNG_UST_CTX_FIELD_PADDING];
198 } u;
199 void (*destroy)(struct lttng_ctx_field *field);
200};
201
202#define LTTNG_UST_CTX_PADDING 24
203struct lttng_ctx {
204 struct lttng_ctx_field *fields;
205 unsigned int nr_fields;
206 unsigned int allocated_fields;
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];
228};
229
230/* Data structures used by the tracer. */
231
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 */
243 struct cds_list_head session_list; /* node of session wildcard list */
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 {
252 /* node of global wildcards list */
253 struct cds_list_head list;
254 /* head of session list to which this wildcard apply */
255 struct cds_list_head session_list;
256 enum lttng_ust_loglevel_type loglevel_type;
257 int loglevel;
258 char name[0];
259};
260
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;
269};
270
271struct ust_pending_probe;
272
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;
280 int enabled;
281 const struct lttng_event_desc *desc;
282 void *filter;
283 struct lttng_ctx *ctx;
284 enum lttng_ust_instrumentation instrumentation;
285 union {
286 } u;
287 struct cds_list_head list; /* Event list */
288 struct cds_list_head wildcard_list; /* Event list for wildcard */
289 struct ust_pending_probe *pending_probe;
290 unsigned int metadata_dumped:1;
291};
292
293struct channel;
294struct lttng_ust_shm_handle;
295
296struct ltt_channel_ops {
297 struct ltt_channel *(*channel_create)(const char *name,
298 void *buf_addr,
299 size_t subbuf_size, size_t num_subbuf,
300 unsigned int switch_timer_interval,
301 unsigned int read_timer_interval,
302 int **shm_fd, int **wait_fd,
303 uint64_t **memory_map_size,
304 struct ltt_channel *chan_priv_init);
305 void (*channel_destroy)(struct ltt_channel *ltt_chan);
306 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
307 struct lttng_ust_shm_handle *handle,
308 int **shm_fd, int **wait_fd,
309 uint64_t **memory_map_size);
310 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
311 struct lttng_ust_shm_handle *handle);
312 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
313 uint32_t event_id);
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,
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 */
322 size_t (*packet_avail_size)(struct channel *chan,
323 struct lttng_ust_shm_handle *handle);
324 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
325 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
326 int (*is_finalized)(struct channel *chan);
327 int (*is_disabled)(struct channel *chan);
328 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
329};
330
331struct ltt_channel {
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 */
338 struct channel *chan; /* Channel buffers */
339 int enabled;
340 struct lttng_ctx *ctx;
341 /* Event ID management */
342 struct ltt_session *session;
343 int objd; /* Object associated to channel */
344 unsigned int free_event_id; /* Next event ID to allocate */
345 unsigned int used_event_id; /* Max allocated event IDs */
346 struct cds_list_head list; /* Channel list */
347 struct ltt_channel_ops *ops;
348 int header_type; /* 0: unset, 1: compact, 2: large */
349 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
350 unsigned int metadata_dumped:1;
351
352 /* Channel ID, available for consumer too */
353 unsigned int id;
354 /* Copy of session UUID for consumer (availability through shm) */
355 uuid_t uuid; /* Trace session unique ID */
356};
357
358struct ltt_session {
359 int active; /* Is trace session active ? */
360 int been_active; /* Has trace session been active ? */
361 int objd; /* Object associated to session */
362 struct ltt_channel *metadata; /* Metadata channel */
363 struct cds_list_head chan; /* Channel list head */
364 struct cds_list_head events; /* Event list head */
365 struct cds_list_head wildcards; /* Wildcard list head */
366 struct cds_list_head list; /* Session list */
367 unsigned int free_chan_id; /* Next chan ID to allocate */
368 uuid_t uuid; /* Trace session unique ID */
369 unsigned int metadata_dumped:1;
370};
371
372struct ltt_transport {
373 char *name;
374 struct cds_list_head node;
375 struct ltt_channel_ops ops;
376};
377
378struct ltt_session *ltt_session_create(void);
379int ltt_session_enable(struct ltt_session *session);
380int ltt_session_disable(struct ltt_session *session);
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,
388 unsigned int read_timer_interval,
389 int **shm_fd, int **wait_fd,
390 uint64_t **memory_map_size,
391 struct ltt_channel *chan_priv_init);
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,
396 unsigned int read_timer_interval,
397 int **shm_fd, int **wait_fd,
398 uint64_t **memory_map_size);
399
400int ltt_event_create(struct ltt_channel *chan,
401 struct lttng_ust_event *event_param,
402 void *filter,
403 struct ltt_event **event);
404
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
410void ltt_transport_register(struct ltt_transport *transport);
411void ltt_transport_unregister(struct ltt_transport *transport);
412
413void synchronize_trace(void);
414
415int ltt_probe_register(struct lttng_probe_desc *desc);
416void ltt_probe_unregister(struct lttng_probe_desc *desc);
417int pending_probe_fix_events(const struct lttng_event_desc *desc);
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);
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,
425 struct lttng_ctx_field *field);
426void lttng_destroy_context(struct lttng_ctx *ctx);
427int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
428int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
429int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
430int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
431void lttng_context_vtid_reset(void);
432void lttng_context_vpid_reset(void);
433
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;
437
438struct ltt_transport *ltt_transport_find(const char *name);
439
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
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);
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);
455
456#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.024511 seconds and 4 git commands to generate.