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