Commit | Line | Data |
---|---|---|
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 MD |
16 | |
17 | struct ltt_channel; | |
18 | struct ltt_session; | |
1c25284c | 19 | struct lib_ring_buffer_ctx; |
ba1f5986 | 20 | struct perf_event; |
4e3c1b9b | 21 | |
c0edae1d MD |
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 { | |
e0a7a7c4 MD |
36 | lttng_encode_none = 0, |
37 | lttng_encode_UTF8 = 1, | |
38 | lttng_encode_ASCII = 2, | |
c0edae1d MD |
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 | ||
e0a7a7c4 | 47 | #define __type_integer(_type, _byte_order, _base) \ |
c099397a MD |
48 | { \ |
49 | .atype = atype_integer, \ | |
50 | .u.basic.integer = \ | |
51 | { \ | |
52 | .size = sizeof(_type), \ | |
d793d5e1 | 53 | .alignment = ltt_alignof(_type) * CHAR_BIT, \ |
c099397a MD |
54 | .signedness = is_signed_type(_type), \ |
55 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ | |
e0a7a7c4 MD |
56 | .base = _base, \ |
57 | .encoding = lttng_encode_none, \ | |
c099397a MD |
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; | |
e0a7a7c4 MD |
66 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
67 | enum lttng_string_encodings encoding; | |
c099397a MD |
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; | |
c0edae1d MD |
85 | }; |
86 | ||
87 | struct lttng_type { | |
88 | enum abstract_types atype; | |
c0edae1d | 89 | union { |
c099397a | 90 | union _lttng_basic_type basic; |
c0edae1d | 91 | struct { |
c099397a | 92 | struct lttng_basic_type elem_type; |
c0edae1d MD |
93 | unsigned int length; /* num. elems. */ |
94 | } array; | |
95 | struct { | |
c099397a MD |
96 | struct lttng_basic_type length_type; |
97 | struct lttng_basic_type elem_type; | |
c0edae1d | 98 | } sequence; |
c0edae1d | 99 | } u; |
c099397a MD |
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 | }; | |
c0edae1d MD |
108 | |
109 | /* Event field description */ | |
110 | ||
111 | struct lttng_event_field { | |
112 | const char *name; | |
f17701fb | 113 | struct lttng_type type; |
c0edae1d MD |
114 | }; |
115 | ||
ba1f5986 MD |
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; | |
0d1a681e | 130 | unsigned int nr_fields; |
ba1f5986 | 131 | unsigned int allocated_fields; |
0d1a681e MD |
132 | }; |
133 | ||
134 | struct lttng_event_desc { | |
c0edae1d MD |
135 | const char *name; |
136 | void *probe_callback; | |
0d1a681e MD |
137 | const struct lttng_event_ctx *ctx; /* context */ |
138 | const struct lttng_event_field *fields; /* event payload */ | |
c0edae1d MD |
139 | unsigned int nr_fields; |
140 | }; | |
141 | ||
85a9ca7f MD |
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; | |
d3dbe23c | 155 | const struct lttng_event_desc *desc; |
85a9ca7f | 156 | void *filter; |
38d024ae | 157 | enum lttng_kernel_instrumentation instrumentation; |
d6d808f3 MD |
158 | union { |
159 | struct { | |
160 | struct kprobe kp; | |
161 | char *symbol_name; | |
162 | } kprobe; | |
e0a7a7c4 MD |
163 | struct { |
164 | char *symbol_name; | |
165 | } ftrace; | |
d6d808f3 | 166 | } u; |
85a9ca7f | 167 | struct list_head list; /* Event list */ |
c099397a | 168 | int metadata_dumped:1; |
85a9ca7f MD |
169 | }; |
170 | ||
171 | struct ltt_channel_ops { | |
172 | struct channel *(*channel_create)(const char *name, | |
9115fbdc | 173 | struct ltt_channel *ltt_chan, |
85a9ca7f MD |
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); | |
1ec3f75a MD |
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); | |
c099397a | 191 | wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan); |
85a9ca7f MD |
192 | }; |
193 | ||
194 | struct ltt_channel { | |
c099397a | 195 | unsigned int id; |
85a9ca7f MD |
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; | |
9115fbdc | 204 | int header_type; /* 0: unset, 1: compact, 2: large */ |
c099397a | 205 | int metadata_dumped:1; |
85a9ca7f MD |
206 | }; |
207 | ||
208 | struct ltt_session { | |
209 | int active; /* Is trace session active ? */ | |
210 | struct file *file; /* File associated to session */ | |
c099397a | 211 | struct ltt_channel *metadata; /* Metadata channel */ |
85a9ca7f MD |
212 | struct list_head chan; /* Channel list head */ |
213 | struct list_head events; /* Event list head */ | |
214 | struct list_head list; /* Session list */ | |
c099397a | 215 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
d793d5e1 | 216 | uuid_le uuid; /* Trace session unique ID */ |
c099397a | 217 | int metadata_dumped:1; |
85a9ca7f MD |
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 | ||
baf20995 | 227 | struct ltt_session *ltt_session_create(void); |
c0e31d2e MD |
228 | int ltt_session_start(struct ltt_session *session); |
229 | int ltt_session_stop(struct ltt_session *session); | |
11b5a3c2 | 230 | void ltt_session_destroy(struct ltt_session *session); |
4e3c1b9b | 231 | |
baf20995 | 232 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, |
5dbbdb43 MD |
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, | |
4e3c1b9b MD |
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); | |
11b5a3c2 | 243 | void _ltt_channel_destroy(struct ltt_channel *chan); |
4e3c1b9b | 244 | |
653fe716 | 245 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, |
653fe716 | 246 | char *name, |
d6d808f3 | 247 | struct lttng_kernel_event *event_param, |
85a9ca7f | 248 | void *filter); |
be066e6c | 249 | int ltt_event_unregister(struct ltt_event *event); |
c0e31d2e MD |
250 | |
251 | void ltt_transport_register(struct ltt_transport *transport); | |
252 | void ltt_transport_unregister(struct ltt_transport *transport); | |
11b5a3c2 | 253 | |
1c25284c MD |
254 | int ltt_debugfs_abi_init(void); |
255 | void ltt_debugfs_abi_exit(void); | |
256 | ||
85a9ca7f MD |
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); | |
cd4bd11f MD |
261 | int ltt_probes_init(void); |
262 | void ltt_probes_exit(void); | |
02119ee5 | 263 | |
acd614cc | 264 | #ifdef CONFIG_KPROBES |
f17701fb MD |
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); | |
acd614cc MD |
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 | |
d6d808f3 | 286 | |
e0a7a7c4 MD |
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 | { | |
acd614cc | 298 | return -ENOSYS; |
e0a7a7c4 MD |
299 | } |
300 | ||
301 | static inline | |
302 | void lttng_ftrace_unregister(struct ltt_event *event) | |
303 | { | |
304 | } | |
305 | #endif | |
11b5a3c2 | 306 | #endif /* _LTT_EVENTS_H */ |