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