Add PID context
[lttng-modules.git] / ltt-events.h
CommitLineData
11b5a3c2
MD
1#ifndef _LTT_EVENTS_H
2#define _LTT_EVENTS_H
3
4e3c1b9b
MD
4/*
5 * ltt-events.h
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 */
11
12#include <linux/list.h>
d793d5e1 13#include <linux/uuid.h>
d6d808f3 14#include <linux/kprobes.h>
11b5a3c2 15#include "ltt-debugfs-abi.h"
4e3c1b9b 16
9e7e4892
MD
17#undef is_signed_type
18#define is_signed_type(type) (((type)(-1)) < 0)
19
4e3c1b9b
MD
20struct ltt_channel;
21struct ltt_session;
1c25284c 22struct lib_ring_buffer_ctx;
ba1f5986 23struct perf_event;
833ad6a0 24struct perf_event_attr;
4e3c1b9b 25
c0edae1d
MD
26/* Type description */
27
28/* Update the astract_types name table in lttng-types.c along with this enum */
29enum abstract_types {
30 atype_integer,
31 atype_enum,
32 atype_array,
33 atype_sequence,
34 atype_string,
35 NR_ABSTRACT_TYPES,
36};
37
38/* Update the string_encodings name table in lttng-types.c along with this enum */
39enum lttng_string_encodings {
e0a7a7c4
MD
40 lttng_encode_none = 0,
41 lttng_encode_UTF8 = 1,
42 lttng_encode_ASCII = 2,
c0edae1d
MD
43 NR_STRING_ENCODINGS,
44};
45
46struct lttng_enum_entry {
47 unsigned long long start, end; /* start and end are inclusive */
48 const char *string;
49};
50
64c796d8 51#define __type_integer(_type, _byte_order, _base, _encoding) \
c099397a
MD
52 { \
53 .atype = atype_integer, \
54 .u.basic.integer = \
55 { \
30bdb6e4 56 .size = sizeof(_type) * CHAR_BIT, \
d793d5e1 57 .alignment = ltt_alignof(_type) * CHAR_BIT, \
c099397a
MD
58 .signedness = is_signed_type(_type), \
59 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
e0a7a7c4 60 .base = _base, \
64c796d8 61 .encoding = lttng_encode_##_encoding, \
c099397a
MD
62 }, \
63 } \
64
65struct lttng_integer_type {
66 unsigned int size; /* in bits */
67 unsigned short alignment; /* in bits */
68 unsigned int signedness:1;
69 unsigned int reverse_byte_order:1;
e0a7a7c4
MD
70 unsigned int base; /* 2, 8, 10, 16, for pretty print */
71 enum lttng_string_encodings encoding;
c099397a
MD
72};
73
74union _lttng_basic_type {
75 struct lttng_integer_type integer;
76 struct {
77 const char *name;
78 } enumeration;
79 struct {
80 enum lttng_string_encodings encoding;
81 } string;
82};
83
84struct lttng_basic_type {
85 enum abstract_types atype;
86 union {
87 union _lttng_basic_type basic;
88 } u;
c0edae1d
MD
89};
90
91struct lttng_type {
92 enum abstract_types atype;
c0edae1d 93 union {
c099397a 94 union _lttng_basic_type basic;
c0edae1d 95 struct {
c099397a 96 struct lttng_basic_type elem_type;
c0edae1d
MD
97 unsigned int length; /* num. elems. */
98 } array;
99 struct {
c099397a
MD
100 struct lttng_basic_type length_type;
101 struct lttng_basic_type elem_type;
c0edae1d 102 } sequence;
c0edae1d 103 } u;
c099397a
MD
104};
105
106struct lttng_enum {
107 const char *name;
108 struct lttng_type container_type;
109 const struct lttng_enum_entry *entries;
110 unsigned int len;
111};
c0edae1d
MD
112
113/* Event field description */
114
115struct lttng_event_field {
116 const char *name;
f17701fb 117 struct lttng_type type;
c0edae1d
MD
118};
119
ba1f5986
MD
120struct lttng_ctx_field {
121 const char *name;
122 struct lttng_type type;
833ad6a0 123 void *callback;
ba1f5986
MD
124 union {
125 struct {
126 struct perf_event **e; /* per-cpu array */
833ad6a0
MD
127 struct list_head head;
128 struct perf_event_attr *attr;
ba1f5986
MD
129 } perf_counter;
130 } u;
2dccf128 131 void (*destroy)(struct lttng_ctx_field *field);
ba1f5986
MD
132};
133
134struct lttng_ctx {
833ad6a0 135 struct lttng_ctx_field *fields;
0d1a681e 136 unsigned int nr_fields;
ba1f5986 137 unsigned int allocated_fields;
0d1a681e
MD
138};
139
140struct lttng_event_desc {
c0edae1d
MD
141 const char *name;
142 void *probe_callback;
0d1a681e
MD
143 const struct lttng_event_ctx *ctx; /* context */
144 const struct lttng_event_field *fields; /* event payload */
c0edae1d 145 unsigned int nr_fields;
dc7f600a 146 struct module *owner;
c0edae1d
MD
147};
148
85a9ca7f
MD
149struct lttng_probe_desc {
150 const struct lttng_event_desc *event_desc;
151 unsigned int nr_events;
152 struct list_head head; /* chain registered probes */
153};
154
155/*
156 * ltt_event structure is referred to by the tracing fast path. It must be
157 * kept small.
158 */
159struct ltt_event {
160 unsigned int id;
161 struct ltt_channel *chan;
d3dbe23c 162 const struct lttng_event_desc *desc;
85a9ca7f 163 void *filter;
38d024ae 164 enum lttng_kernel_instrumentation instrumentation;
d6d808f3
MD
165 union {
166 struct {
167 struct kprobe kp;
168 char *symbol_name;
169 } kprobe;
e0a7a7c4
MD
170 struct {
171 char *symbol_name;
172 } ftrace;
d6d808f3 173 } u;
85a9ca7f 174 struct list_head list; /* Event list */
c099397a 175 int metadata_dumped:1;
85a9ca7f
MD
176};
177
178struct ltt_channel_ops {
179 struct channel *(*channel_create)(const char *name,
9115fbdc 180 struct ltt_channel *ltt_chan,
85a9ca7f
MD
181 void *buf_addr,
182 size_t subbuf_size, size_t num_subbuf,
183 unsigned int switch_timer_interval,
184 unsigned int read_timer_interval);
185 void (*channel_destroy)(struct channel *chan);
186 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
187 void (*buffer_read_close)(struct lib_ring_buffer *buf);
4e1f08f4 188 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
64c796d8 189 uint32_t event_id);
85a9ca7f
MD
190 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
191 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
192 size_t len);
1ec3f75a
MD
193 /*
194 * packet_avail_size returns the available size in the current
195 * packet. Note that the size returned is only a hint, since it
196 * may change due to concurrent writes.
197 */
198 size_t (*packet_avail_size)(struct channel *chan);
c099397a 199 wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan);
85a9ca7f
MD
200};
201
202struct ltt_channel {
c099397a 203 unsigned int id;
85a9ca7f
MD
204 struct channel *chan; /* Channel buffers */
205 /* Event ID management */
206 struct ltt_session *session;
207 struct file *file; /* File associated to channel */
208 unsigned int free_event_id; /* Next event ID to allocate */
209 struct list_head list; /* Channel list */
210 wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */
211 struct ltt_channel_ops *ops;
9115fbdc 212 int header_type; /* 0: unset, 1: compact, 2: large */
c099397a 213 int metadata_dumped:1;
85a9ca7f
MD
214};
215
216struct ltt_session {
217 int active; /* Is trace session active ? */
218 struct file *file; /* File associated to session */
c099397a 219 struct ltt_channel *metadata; /* Metadata channel */
85a9ca7f
MD
220 struct list_head chan; /* Channel list head */
221 struct list_head events; /* Event list head */
222 struct list_head list; /* Session list */
c099397a 223 unsigned int free_chan_id; /* Next chan ID to allocate */
d793d5e1 224 uuid_le uuid; /* Trace session unique ID */
c099397a 225 int metadata_dumped:1;
85a9ca7f
MD
226};
227
228struct ltt_transport {
229 char *name;
230 struct module *owner;
231 struct list_head node;
232 struct ltt_channel_ops ops;
233};
234
baf20995 235struct ltt_session *ltt_session_create(void);
c0e31d2e
MD
236int ltt_session_start(struct ltt_session *session);
237int ltt_session_stop(struct ltt_session *session);
11b5a3c2 238void ltt_session_destroy(struct ltt_session *session);
4e3c1b9b 239
baf20995 240struct ltt_channel *ltt_channel_create(struct ltt_session *session,
5dbbdb43
MD
241 const char *transport_name,
242 void *buf_addr,
243 size_t subbuf_size, size_t num_subbuf,
244 unsigned int switch_timer_interval,
245 unsigned int read_timer_interval);
246struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
4e3c1b9b
MD
247 int overwrite, void *buf_addr,
248 size_t subbuf_size, size_t num_subbuf,
249 unsigned int switch_timer_interval,
250 unsigned int read_timer_interval);
4e3c1b9b 251
653fe716 252struct ltt_event *ltt_event_create(struct ltt_channel *chan,
d6d808f3 253 struct lttng_kernel_event *event_param,
85a9ca7f 254 void *filter);
c0e31d2e
MD
255
256void ltt_transport_register(struct ltt_transport *transport);
257void ltt_transport_unregister(struct ltt_transport *transport);
11b5a3c2 258
1c25284c
MD
259int ltt_debugfs_abi_init(void);
260void ltt_debugfs_abi_exit(void);
261
85a9ca7f
MD
262int ltt_probe_register(struct lttng_probe_desc *desc);
263void ltt_probe_unregister(struct lttng_probe_desc *desc);
264const struct lttng_event_desc *ltt_event_get(const char *name);
265void ltt_event_put(const struct lttng_event_desc *desc);
cd4bd11f
MD
266int ltt_probes_init(void);
267void ltt_probes_exit(void);
2dccf128
MD
268struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
269void lttng_destroy_context(struct lttng_ctx *ctx);
02119ee5 270
acd614cc 271#ifdef CONFIG_KPROBES
f17701fb
MD
272int lttng_kprobes_register(const char *name,
273 const char *symbol_name,
274 uint64_t offset,
275 uint64_t addr,
276 struct ltt_event *event);
277void lttng_kprobes_unregister(struct ltt_event *event);
edeb3137 278void lttng_kprobes_destroy_private(struct ltt_event *event);
acd614cc
MD
279#else
280static inline
281int lttng_kprobes_register(const char *name,
282 const char *symbol_name,
283 uint64_t offset,
284 uint64_t addr,
285 struct ltt_event *event)
286{
287 return -ENOSYS;
288}
289
25f53c39 290static inline
acd614cc
MD
291void lttng_kprobes_unregister(struct ltt_event *event)
292{
293}
edeb3137
MD
294
295static inline
296void lttng_kprobes_destroy_private(struct ltt_event *event)
297{
298}
acd614cc 299#endif
d6d808f3 300
e0a7a7c4
MD
301#ifdef CONFIG_DYNAMIC_FTRACE
302int lttng_ftrace_register(const char *name,
303 const char *symbol_name,
304 struct ltt_event *event);
305void lttng_ftrace_unregister(struct ltt_event *event);
edeb3137 306void lttng_ftrace_destroy_private(struct ltt_event *event);
e0a7a7c4
MD
307#else
308static inline
309int lttng_ftrace_register(const char *name,
310 const char *symbol_name,
311 struct ltt_event *event)
312{
acd614cc 313 return -ENOSYS;
e0a7a7c4
MD
314}
315
316static inline
317void lttng_ftrace_unregister(struct ltt_event *event)
318{
319}
edeb3137
MD
320
321static inline
322void lttng_ftrace_destroy_private(struct ltt_event *event)
323{
324}
e0a7a7c4 325#endif
271b6681
MD
326
327extern const struct file_operations lttng_tracepoint_list_fops;
328
11b5a3c2 329#endif /* _LTT_EVENTS_H */
This page took 0.037626 seconds and 4 git commands to generate.