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