Add kprobes support
[deliverable/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
21 /* Type description */
22
23 /* Update the astract_types name table in lttng-types.c along with this enum */
24 enum abstract_types {
25 atype_integer,
26 atype_enum,
27 atype_array,
28 atype_sequence,
29 atype_string,
30 NR_ABSTRACT_TYPES,
31 };
32
33 /* Update the string_encodings name table in lttng-types.c along with this enum */
34 enum lttng_string_encodings {
35 lttng_encode_UTF8 = 0,
36 lttng_encode_ASCII = 1,
37 NR_STRING_ENCODINGS,
38 };
39
40 struct lttng_enum_entry {
41 unsigned long long start, end; /* start and end are inclusive */
42 const char *string;
43 };
44
45 #define __type_integer(_type, _byte_order) \
46 { \
47 .atype = atype_integer, \
48 .u.basic.integer = \
49 { \
50 .size = sizeof(_type), \
51 .alignment = ltt_alignof(_type) * CHAR_BIT, \
52 .signedness = is_signed_type(_type), \
53 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
54 }, \
55 } \
56
57 struct lttng_integer_type {
58 unsigned int size; /* in bits */
59 unsigned short alignment; /* in bits */
60 unsigned int signedness:1;
61 unsigned int reverse_byte_order:1;
62 };
63
64 union _lttng_basic_type {
65 struct lttng_integer_type integer;
66 struct {
67 const char *name;
68 } enumeration;
69 struct {
70 enum lttng_string_encodings encoding;
71 } string;
72 };
73
74 struct lttng_basic_type {
75 enum abstract_types atype;
76 union {
77 union _lttng_basic_type basic;
78 } u;
79 };
80
81 struct lttng_type {
82 enum abstract_types atype;
83 union {
84 union _lttng_basic_type basic;
85 struct {
86 struct lttng_basic_type elem_type;
87 unsigned int length; /* num. elems. */
88 } array;
89 struct {
90 struct lttng_basic_type length_type;
91 struct lttng_basic_type elem_type;
92 } sequence;
93 } u;
94 };
95
96 struct lttng_enum {
97 const char *name;
98 struct lttng_type container_type;
99 const struct lttng_enum_entry *entries;
100 unsigned int len;
101 };
102
103 /* Event field description */
104
105 struct lttng_event_field {
106 const char *name;
107 const struct lttng_type type;
108 };
109
110 struct lttng_event_desc {
111 const struct lttng_event_field *fields;
112 const char *name;
113 void *probe_callback;
114 unsigned int nr_fields;
115 };
116
117 struct lttng_probe_desc {
118 const struct lttng_event_desc *event_desc;
119 unsigned int nr_events;
120 struct list_head head; /* chain registered probes */
121 };
122
123 /*
124 * ltt_event structure is referred to by the tracing fast path. It must be
125 * kept small.
126 */
127 struct ltt_event {
128 unsigned int id;
129 struct ltt_channel *chan;
130 const struct lttng_event_desc *desc;
131 void *filter;
132 enum lttng_kernel_instrumentation instrumentation;
133 union {
134 struct {
135 struct kprobe kp;
136 char *symbol_name;
137 } kprobe;
138 } u;
139 struct list_head list; /* Event list */
140 int metadata_dumped:1;
141 };
142
143 struct ltt_channel_ops {
144 struct channel *(*channel_create)(const char *name,
145 struct ltt_channel *ltt_chan,
146 void *buf_addr,
147 size_t subbuf_size, size_t num_subbuf,
148 unsigned int switch_timer_interval,
149 unsigned int read_timer_interval);
150 void (*channel_destroy)(struct channel *chan);
151 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
152 void (*buffer_read_close)(struct lib_ring_buffer *buf);
153 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx);
154 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
155 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
156 size_t len);
157 /*
158 * packet_avail_size returns the available size in the current
159 * packet. Note that the size returned is only a hint, since it
160 * may change due to concurrent writes.
161 */
162 size_t (*packet_avail_size)(struct channel *chan);
163 wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan);
164 };
165
166 struct ltt_channel {
167 unsigned int id;
168 struct channel *chan; /* Channel buffers */
169 /* Event ID management */
170 struct ltt_session *session;
171 struct file *file; /* File associated to channel */
172 unsigned int free_event_id; /* Next event ID to allocate */
173 struct list_head list; /* Channel list */
174 wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */
175 struct ltt_channel_ops *ops;
176 int header_type; /* 0: unset, 1: compact, 2: large */
177 int metadata_dumped:1;
178 };
179
180 struct ltt_session {
181 int active; /* Is trace session active ? */
182 struct file *file; /* File associated to session */
183 struct ltt_channel *metadata; /* Metadata channel */
184 struct list_head chan; /* Channel list head */
185 struct list_head events; /* Event list head */
186 struct list_head list; /* Session list */
187 unsigned int free_chan_id; /* Next chan ID to allocate */
188 uuid_le uuid; /* Trace session unique ID */
189 int metadata_dumped:1;
190 };
191
192 struct ltt_transport {
193 char *name;
194 struct module *owner;
195 struct list_head node;
196 struct ltt_channel_ops ops;
197 };
198
199 struct ltt_session *ltt_session_create(void);
200 int ltt_session_start(struct ltt_session *session);
201 int ltt_session_stop(struct ltt_session *session);
202 void ltt_session_destroy(struct ltt_session *session);
203
204 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
205 const char *transport_name,
206 void *buf_addr,
207 size_t subbuf_size, size_t num_subbuf,
208 unsigned int switch_timer_interval,
209 unsigned int read_timer_interval);
210 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
211 int overwrite, void *buf_addr,
212 size_t subbuf_size, size_t num_subbuf,
213 unsigned int switch_timer_interval,
214 unsigned int read_timer_interval);
215 void _ltt_channel_destroy(struct ltt_channel *chan);
216
217 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
218 char *name,
219 struct lttng_kernel_event *event_param,
220 const struct lttng_event_desc *event_desc,
221 void *filter);
222 int ltt_event_unregister(struct ltt_event *event);
223
224 void ltt_transport_register(struct ltt_transport *transport);
225 void ltt_transport_unregister(struct ltt_transport *transport);
226
227 int ltt_debugfs_abi_init(void);
228 void ltt_debugfs_abi_exit(void);
229
230 int ltt_probe_register(struct lttng_probe_desc *desc);
231 void ltt_probe_unregister(struct lttng_probe_desc *desc);
232 const struct lttng_event_desc *ltt_event_get(const char *name);
233 void ltt_event_put(const struct lttng_event_desc *desc);
234 int ltt_probes_init(void);
235 void ltt_probes_exit(void);
236
237 void lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs);
238
239 #endif /* _LTT_EVENTS_H */
This page took 0.03787 seconds and 5 git commands to generate.