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