Support for linux kernels 2.6.32 through 2.6.37
[lttng-modules.git] / lttng-events.h
CommitLineData
a90917c3
MD
1#ifndef _LTTNG_EVENTS_H
2#define _LTTNG_EVENTS_H
11b5a3c2 3
4e3c1b9b 4/*
a90917c3 5 * lttng-events.h
4e3c1b9b 6 *
4e3c1b9b 7 * Holds LTTng per-session event registry.
17baffe2 8 *
886d51a3
MD
9 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4e3c1b9b
MD
24 */
25
3a523f5b 26#include <linux/version.h>
4e3c1b9b 27#include <linux/list.h>
d6d808f3 28#include <linux/kprobes.h>
a864fb02 29#include "wrapper/uuid.h"
e8951e63 30#include "lttng-abi.h"
4e3c1b9b 31
9e7e4892
MD
32#undef is_signed_type
33#define is_signed_type(type) (((type)(-1)) < 0)
34
a90917c3
MD
35struct lttng_channel;
36struct lttng_session;
1c25284c 37struct lib_ring_buffer_ctx;
ba1f5986 38struct perf_event;
833ad6a0 39struct perf_event_attr;
4e3c1b9b 40
c0edae1d
MD
41/* Type description */
42
43/* Update the astract_types name table in lttng-types.c along with this enum */
44enum abstract_types {
45 atype_integer,
46 atype_enum,
47 atype_array,
48 atype_sequence,
49 atype_string,
50 NR_ABSTRACT_TYPES,
51};
52
53/* Update the string_encodings name table in lttng-types.c along with this enum */
54enum lttng_string_encodings {
e0a7a7c4
MD
55 lttng_encode_none = 0,
56 lttng_encode_UTF8 = 1,
57 lttng_encode_ASCII = 2,
c0edae1d
MD
58 NR_STRING_ENCODINGS,
59};
60
61struct lttng_enum_entry {
62 unsigned long long start, end; /* start and end are inclusive */
63 const char *string;
64};
65
64c796d8 66#define __type_integer(_type, _byte_order, _base, _encoding) \
c099397a
MD
67 { \
68 .atype = atype_integer, \
69 .u.basic.integer = \
70 { \
30bdb6e4 71 .size = sizeof(_type) * CHAR_BIT, \
a90917c3 72 .alignment = lttng_alignof(_type) * CHAR_BIT, \
c099397a
MD
73 .signedness = is_signed_type(_type), \
74 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
e0a7a7c4 75 .base = _base, \
64c796d8 76 .encoding = lttng_encode_##_encoding, \
c099397a
MD
77 }, \
78 } \
79
80struct lttng_integer_type {
81 unsigned int size; /* in bits */
82 unsigned short alignment; /* in bits */
9cccf98a
MD
83 unsigned int signedness:1,
84 reverse_byte_order:1;
e0a7a7c4
MD
85 unsigned int base; /* 2, 8, 10, 16, for pretty print */
86 enum lttng_string_encodings encoding;
c099397a
MD
87};
88
89union _lttng_basic_type {
90 struct lttng_integer_type integer;
91 struct {
92 const char *name;
93 } enumeration;
94 struct {
95 enum lttng_string_encodings encoding;
96 } string;
97};
98
99struct lttng_basic_type {
100 enum abstract_types atype;
101 union {
102 union _lttng_basic_type basic;
103 } u;
c0edae1d
MD
104};
105
106struct lttng_type {
107 enum abstract_types atype;
c0edae1d 108 union {
c099397a 109 union _lttng_basic_type basic;
c0edae1d 110 struct {
c099397a 111 struct lttng_basic_type elem_type;
c0edae1d
MD
112 unsigned int length; /* num. elems. */
113 } array;
114 struct {
c099397a
MD
115 struct lttng_basic_type length_type;
116 struct lttng_basic_type elem_type;
c0edae1d 117 } sequence;
c0edae1d 118 } u;
c099397a
MD
119};
120
121struct lttng_enum {
122 const char *name;
123 struct lttng_type container_type;
124 const struct lttng_enum_entry *entries;
125 unsigned int len;
126};
c0edae1d
MD
127
128/* Event field description */
129
130struct lttng_event_field {
131 const char *name;
f17701fb 132 struct lttng_type type;
c0edae1d
MD
133};
134
2001023e
MD
135/*
136 * We need to keep this perf counter field separately from struct
137 * lttng_ctx_field because cpu hotplug needs fixed-location addresses.
138 */
139struct lttng_perf_counter_field {
140 struct notifier_block nb;
141 int hp_enable;
142 struct perf_event_attr *attr;
143 struct perf_event **e; /* per-cpu array */
144};
145
ba1f5986 146struct lttng_ctx_field {
8070f5c0 147 struct lttng_event_field event_field;
f1676205
MD
148 size_t (*get_size)(size_t offset);
149 void (*record)(struct lttng_ctx_field *field,
150 struct lib_ring_buffer_ctx *ctx,
a90917c3 151 struct lttng_channel *chan);
ba1f5986 152 union {
2001023e 153 struct lttng_perf_counter_field *perf_counter;
ba1f5986 154 } u;
2dccf128 155 void (*destroy)(struct lttng_ctx_field *field);
ba1f5986
MD
156};
157
158struct lttng_ctx {
833ad6a0 159 struct lttng_ctx_field *fields;
0d1a681e 160 unsigned int nr_fields;
ba1f5986 161 unsigned int allocated_fields;
0d1a681e
MD
162};
163
164struct lttng_event_desc {
c0edae1d
MD
165 const char *name;
166 void *probe_callback;
0d1a681e
MD
167 const struct lttng_event_ctx *ctx; /* context */
168 const struct lttng_event_field *fields; /* event payload */
c0edae1d 169 unsigned int nr_fields;
dc7f600a 170 struct module *owner;
c0edae1d
MD
171};
172
85a9ca7f 173struct lttng_probe_desc {
f7bdf4db 174 const struct lttng_event_desc **event_desc;
85a9ca7f
MD
175 unsigned int nr_events;
176 struct list_head head; /* chain registered probes */
177};
178
7371f44c
MD
179struct lttng_krp; /* Kretprobe handling */
180
85a9ca7f 181/*
a90917c3 182 * lttng_event structure is referred to by the tracing fast path. It must be
85a9ca7f
MD
183 * kept small.
184 */
a90917c3 185struct lttng_event {
85a9ca7f 186 unsigned int id;
a90917c3 187 struct lttng_channel *chan;
e64957da 188 int enabled;
d3dbe23c 189 const struct lttng_event_desc *desc;
85a9ca7f 190 void *filter;
f1676205 191 struct lttng_ctx *ctx;
38d024ae 192 enum lttng_kernel_instrumentation instrumentation;
d6d808f3
MD
193 union {
194 struct {
195 struct kprobe kp;
196 char *symbol_name;
197 } kprobe;
7371f44c
MD
198 struct {
199 struct lttng_krp *lttng_krp;
200 char *symbol_name;
201 } kretprobe;
e0a7a7c4
MD
202 struct {
203 char *symbol_name;
204 } ftrace;
d6d808f3 205 } u;
85a9ca7f 206 struct list_head list; /* Event list */
9cccf98a 207 unsigned int metadata_dumped:1;
85a9ca7f
MD
208};
209
a90917c3 210struct lttng_channel_ops {
85a9ca7f 211 struct channel *(*channel_create)(const char *name,
a90917c3 212 struct lttng_channel *lttng_chan,
85a9ca7f
MD
213 void *buf_addr,
214 size_t subbuf_size, size_t num_subbuf,
215 unsigned int switch_timer_interval,
216 unsigned int read_timer_interval);
217 void (*channel_destroy)(struct channel *chan);
218 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
f71ecafa 219 int (*buffer_has_read_closed_stream)(struct channel *chan);
85a9ca7f 220 void (*buffer_read_close)(struct lib_ring_buffer *buf);
4e1f08f4 221 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
64c796d8 222 uint32_t event_id);
85a9ca7f
MD
223 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
224 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
225 size_t len);
4ea00e4f
JD
226 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
227 const void *src, size_t len);
58aa5d24
MD
228 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
229 int c, size_t len);
1ec3f75a
MD
230 /*
231 * packet_avail_size returns the available size in the current
232 * packet. Note that the size returned is only a hint, since it
233 * may change due to concurrent writes.
234 */
235 size_t (*packet_avail_size)(struct channel *chan);
71c1d843 236 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
24cedcfe
MD
237 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
238 int (*is_finalized)(struct channel *chan);
254ec7bc 239 int (*is_disabled)(struct channel *chan);
85a9ca7f
MD
240};
241
a90917c3 242struct lttng_transport {
a33c9927
MD
243 char *name;
244 struct module *owner;
245 struct list_head node;
a90917c3 246 struct lttng_channel_ops ops;
a33c9927
MD
247};
248
a90917c3 249struct lttng_channel {
c099397a 250 unsigned int id;
85a9ca7f 251 struct channel *chan; /* Channel buffers */
e64957da 252 int enabled;
f1676205 253 struct lttng_ctx *ctx;
85a9ca7f 254 /* Event ID management */
a90917c3 255 struct lttng_session *session;
85a9ca7f
MD
256 struct file *file; /* File associated to channel */
257 unsigned int free_event_id; /* Next event ID to allocate */
258 struct list_head list; /* Channel list */
a90917c3
MD
259 struct lttng_channel_ops *ops;
260 struct lttng_transport *transport;
261 struct lttng_event **sc_table; /* for syscall tracing */
262 struct lttng_event **compat_sc_table;
263 struct lttng_event *sc_unknown; /* for unknown syscalls */
264 struct lttng_event *sc_compat_unknown;
265 struct lttng_event *sc_exit; /* for syscall exit */
9115fbdc 266 int header_type; /* 0: unset, 1: compact, 2: large */
9cccf98a 267 unsigned int metadata_dumped:1;
85a9ca7f
MD
268};
269
a90917c3 270struct lttng_session {
85a9ca7f 271 int active; /* Is trace session active ? */
8070f5c0 272 int been_active; /* Has trace session been active ? */
85a9ca7f 273 struct file *file; /* File associated to session */
a90917c3 274 struct lttng_channel *metadata; /* Metadata channel */
85a9ca7f
MD
275 struct list_head chan; /* Channel list head */
276 struct list_head events; /* Event list head */
277 struct list_head list; /* Session list */
c099397a 278 unsigned int free_chan_id; /* Next chan ID to allocate */
d793d5e1 279 uuid_le uuid; /* Trace session unique ID */
9cccf98a 280 unsigned int metadata_dumped:1;
85a9ca7f
MD
281};
282
a90917c3
MD
283struct lttng_session *lttng_session_create(void);
284int lttng_session_enable(struct lttng_session *session);
285int lttng_session_disable(struct lttng_session *session);
286void lttng_session_destroy(struct lttng_session *session);
4e3c1b9b 287
a90917c3 288struct lttng_channel *lttng_channel_create(struct lttng_session *session,
5dbbdb43
MD
289 const char *transport_name,
290 void *buf_addr,
291 size_t subbuf_size, size_t num_subbuf,
292 unsigned int switch_timer_interval,
293 unsigned int read_timer_interval);
a90917c3 294struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
4e3c1b9b
MD
295 int overwrite, void *buf_addr,
296 size_t subbuf_size, size_t num_subbuf,
297 unsigned int switch_timer_interval,
298 unsigned int read_timer_interval);
4e3c1b9b 299
a90917c3 300struct lttng_event *lttng_event_create(struct lttng_channel *chan,
d6d808f3 301 struct lttng_kernel_event *event_param,
259b6cb3
MD
302 void *filter,
303 const struct lttng_event_desc *internal_desc);
c0e31d2e 304
a90917c3
MD
305int lttng_channel_enable(struct lttng_channel *channel);
306int lttng_channel_disable(struct lttng_channel *channel);
307int lttng_event_enable(struct lttng_event *event);
308int lttng_event_disable(struct lttng_event *event);
e64957da 309
a90917c3
MD
310void lttng_transport_register(struct lttng_transport *transport);
311void lttng_transport_unregister(struct lttng_transport *transport);
11b5a3c2 312
360f38ea 313void synchronize_trace(void);
80996790
MD
314int lttng_abi_init(void);
315void lttng_abi_exit(void);
1c25284c 316
a90917c3
MD
317int lttng_probe_register(struct lttng_probe_desc *desc);
318void lttng_probe_unregister(struct lttng_probe_desc *desc);
319const struct lttng_event_desc *lttng_event_get(const char *name);
320void lttng_event_put(const struct lttng_event_desc *desc);
321int lttng_probes_init(void);
322void lttng_probes_exit(void);
1ec65de1 323
3a523f5b 324#if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
a90917c3
MD
325int lttng_syscalls_register(struct lttng_channel *chan, void *filter);
326int lttng_syscalls_unregister(struct lttng_channel *chan);
1ec65de1 327#else
a90917c3 328static inline int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
1ec65de1
MD
329{
330 return -ENOSYS;
331}
332
a90917c3 333static inline int lttng_syscalls_unregister(struct lttng_channel *chan)
1ec65de1
MD
334{
335 return 0;
336}
337#endif
338
2dccf128 339struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
44252f0f 340int lttng_find_context(struct lttng_ctx *ctx, const char *name);
8289661d
MD
341void lttng_remove_context_field(struct lttng_ctx **ctx,
342 struct lttng_ctx_field *field);
2dccf128 343void lttng_destroy_context(struct lttng_ctx *ctx);
8070f5c0 344int lttng_add_pid_to_ctx(struct lttng_ctx **ctx);
a2563e83 345int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
a8ad3613 346int lttng_add_prio_to_ctx(struct lttng_ctx **ctx);
53f1f0ca 347int lttng_add_nice_to_ctx(struct lttng_ctx **ctx);
b64bc438
MD
348int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
349int lttng_add_tid_to_ctx(struct lttng_ctx **ctx);
350int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
351int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx);
352int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx);
975da2c0 353int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx);
41c3c24e 354#if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
c24a0d71
MD
355int lttng_add_perf_counter_to_ctx(uint32_t type,
356 uint64_t config,
357 const char *name,
358 struct lttng_ctx **ctx);
1d443b34
MD
359#else
360static inline
361int lttng_add_perf_counter_to_ctx(uint32_t type,
362 uint64_t config,
363 const char *name,
364 struct lttng_ctx **ctx)
365{
366 return -ENOSYS;
367}
368#endif
02119ee5 369
c337ddc2
MD
370extern int lttng_statedump_start(struct lttng_session *session);
371
acd614cc 372#ifdef CONFIG_KPROBES
f17701fb
MD
373int lttng_kprobes_register(const char *name,
374 const char *symbol_name,
375 uint64_t offset,
376 uint64_t addr,
a90917c3
MD
377 struct lttng_event *event);
378void lttng_kprobes_unregister(struct lttng_event *event);
379void lttng_kprobes_destroy_private(struct lttng_event *event);
acd614cc
MD
380#else
381static inline
382int lttng_kprobes_register(const char *name,
383 const char *symbol_name,
384 uint64_t offset,
385 uint64_t addr,
a90917c3 386 struct lttng_event *event)
acd614cc
MD
387{
388 return -ENOSYS;
389}
390
25f53c39 391static inline
a90917c3 392void lttng_kprobes_unregister(struct lttng_event *event)
acd614cc
MD
393{
394}
edeb3137
MD
395
396static inline
a90917c3 397void lttng_kprobes_destroy_private(struct lttng_event *event)
edeb3137
MD
398{
399}
acd614cc 400#endif
d6d808f3 401
7371f44c
MD
402#ifdef CONFIG_KRETPROBES
403int lttng_kretprobes_register(const char *name,
404 const char *symbol_name,
405 uint64_t offset,
406 uint64_t addr,
a90917c3
MD
407 struct lttng_event *event_entry,
408 struct lttng_event *event_exit);
409void lttng_kretprobes_unregister(struct lttng_event *event);
410void lttng_kretprobes_destroy_private(struct lttng_event *event);
7371f44c
MD
411#else
412static inline
413int lttng_kretprobes_register(const char *name,
414 const char *symbol_name,
415 uint64_t offset,
416 uint64_t addr,
a90917c3
MD
417 struct lttng_event *event_entry,
418 struct lttng_event *event_exit)
7371f44c
MD
419{
420 return -ENOSYS;
421}
422
423static inline
a90917c3 424void lttng_kretprobes_unregister(struct lttng_event *event)
7371f44c
MD
425{
426}
427
428static inline
a90917c3 429void lttng_kretprobes_destroy_private(struct lttng_event *event)
7371f44c
MD
430{
431}
432#endif
433
e0a7a7c4
MD
434#ifdef CONFIG_DYNAMIC_FTRACE
435int lttng_ftrace_register(const char *name,
436 const char *symbol_name,
a90917c3
MD
437 struct lttng_event *event);
438void lttng_ftrace_unregister(struct lttng_event *event);
439void lttng_ftrace_destroy_private(struct lttng_event *event);
e0a7a7c4
MD
440#else
441static inline
442int lttng_ftrace_register(const char *name,
443 const char *symbol_name,
a90917c3 444 struct lttng_event *event)
e0a7a7c4 445{
acd614cc 446 return -ENOSYS;
e0a7a7c4
MD
447}
448
449static inline
a90917c3 450void lttng_ftrace_unregister(struct lttng_event *event)
e0a7a7c4
MD
451{
452}
edeb3137
MD
453
454static inline
a90917c3 455void lttng_ftrace_destroy_private(struct lttng_event *event)
edeb3137
MD
456{
457}
e0a7a7c4 458#endif
271b6681 459
3db41b2c 460int lttng_calibrate(struct lttng_kernel_calibrate *calibrate);
57105fc2 461
271b6681
MD
462extern const struct file_operations lttng_tracepoint_list_fops;
463
ef200626
MD
464#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
465#define TRACEPOINT_HAS_DATA_ARG
466#endif
467
a90917c3 468#endif /* _LTTNG_EVENTS_H */
This page took 0.050129 seconds and 4 git commands to generate.