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