Commit | Line | Data |
---|---|---|
a90917c3 MD |
1 | #ifndef _LTTNG_EVENTS_H |
2 | #define _LTTNG_EVENTS_H | |
11b5a3c2 | 3 | |
4e3c1b9b | 4 | /* |
a90917c3 | 5 | * lttng-events.h |
4e3c1b9b | 6 | * |
4e3c1b9b | 7 | * Holds LTTng per-session event registry. |
17baffe2 | 8 | * |
886d51a3 MD |
9 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
10 | * | |
11 | * This library is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License as published by the Free Software Foundation; only | |
14 | * version 2.1 of the License. | |
15 | * | |
16 | * This library is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * Lesser General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Lesser General Public | |
22 | * License along with this library; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
4e3c1b9b MD |
24 | */ |
25 | ||
3a523f5b | 26 | #include <linux/version.h> |
4e3c1b9b | 27 | #include <linux/list.h> |
d6d808f3 | 28 | #include <linux/kprobes.h> |
a864fb02 | 29 | #include "wrapper/uuid.h" |
e8951e63 | 30 | #include "lttng-abi.h" |
6dccd6c1 | 31 | #include "lttng-abi-old.h" |
4e3c1b9b | 32 | |
9e7e4892 MD |
33 | #undef is_signed_type |
34 | #define is_signed_type(type) (((type)(-1)) < 0) | |
35 | ||
a90917c3 MD |
36 | struct lttng_channel; |
37 | struct lttng_session; | |
1c25284c | 38 | struct lib_ring_buffer_ctx; |
ba1f5986 | 39 | struct perf_event; |
833ad6a0 | 40 | struct perf_event_attr; |
4e3c1b9b | 41 | |
c0edae1d MD |
42 | /* Type description */ |
43 | ||
44 | /* Update the astract_types name table in lttng-types.c along with this enum */ | |
45 | enum abstract_types { | |
46 | atype_integer, | |
47 | atype_enum, | |
48 | atype_array, | |
49 | atype_sequence, | |
50 | atype_string, | |
51 | NR_ABSTRACT_TYPES, | |
52 | }; | |
53 | ||
54 | /* Update the string_encodings name table in lttng-types.c along with this enum */ | |
55 | enum lttng_string_encodings { | |
e0a7a7c4 MD |
56 | lttng_encode_none = 0, |
57 | lttng_encode_UTF8 = 1, | |
58 | lttng_encode_ASCII = 2, | |
c0edae1d MD |
59 | NR_STRING_ENCODINGS, |
60 | }; | |
61 | ||
62 | struct lttng_enum_entry { | |
63 | unsigned long long start, end; /* start and end are inclusive */ | |
64 | const char *string; | |
65 | }; | |
66 | ||
64c796d8 | 67 | #define __type_integer(_type, _byte_order, _base, _encoding) \ |
c099397a MD |
68 | { \ |
69 | .atype = atype_integer, \ | |
70 | .u.basic.integer = \ | |
71 | { \ | |
30bdb6e4 | 72 | .size = sizeof(_type) * CHAR_BIT, \ |
a90917c3 | 73 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
c099397a MD |
74 | .signedness = is_signed_type(_type), \ |
75 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ | |
e0a7a7c4 | 76 | .base = _base, \ |
64c796d8 | 77 | .encoding = lttng_encode_##_encoding, \ |
c099397a MD |
78 | }, \ |
79 | } \ | |
80 | ||
81 | struct lttng_integer_type { | |
82 | unsigned int size; /* in bits */ | |
83 | unsigned short alignment; /* in bits */ | |
9cccf98a MD |
84 | unsigned int signedness:1, |
85 | reverse_byte_order:1; | |
e0a7a7c4 MD |
86 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
87 | enum lttng_string_encodings encoding; | |
c099397a MD |
88 | }; |
89 | ||
90 | union _lttng_basic_type { | |
91 | struct lttng_integer_type integer; | |
92 | struct { | |
93 | const char *name; | |
94 | } enumeration; | |
95 | struct { | |
96 | enum lttng_string_encodings encoding; | |
97 | } string; | |
98 | }; | |
99 | ||
100 | struct lttng_basic_type { | |
101 | enum abstract_types atype; | |
102 | union { | |
103 | union _lttng_basic_type basic; | |
104 | } u; | |
c0edae1d MD |
105 | }; |
106 | ||
107 | struct lttng_type { | |
108 | enum abstract_types atype; | |
c0edae1d | 109 | union { |
c099397a | 110 | union _lttng_basic_type basic; |
c0edae1d | 111 | struct { |
c099397a | 112 | struct lttng_basic_type elem_type; |
c0edae1d MD |
113 | unsigned int length; /* num. elems. */ |
114 | } array; | |
115 | struct { | |
c099397a MD |
116 | struct lttng_basic_type length_type; |
117 | struct lttng_basic_type elem_type; | |
c0edae1d | 118 | } sequence; |
c0edae1d | 119 | } u; |
c099397a MD |
120 | }; |
121 | ||
122 | struct lttng_enum { | |
123 | const char *name; | |
124 | struct lttng_type container_type; | |
125 | const struct lttng_enum_entry *entries; | |
126 | unsigned int len; | |
127 | }; | |
c0edae1d MD |
128 | |
129 | /* Event field description */ | |
130 | ||
131 | struct lttng_event_field { | |
132 | const char *name; | |
f17701fb | 133 | struct lttng_type type; |
c0edae1d MD |
134 | }; |
135 | ||
2001023e MD |
136 | /* |
137 | * We need to keep this perf counter field separately from struct | |
138 | * lttng_ctx_field because cpu hotplug needs fixed-location addresses. | |
139 | */ | |
140 | struct lttng_perf_counter_field { | |
141 | struct notifier_block nb; | |
142 | int hp_enable; | |
143 | struct perf_event_attr *attr; | |
144 | struct perf_event **e; /* per-cpu array */ | |
145 | }; | |
146 | ||
ba1f5986 | 147 | struct lttng_ctx_field { |
8070f5c0 | 148 | struct lttng_event_field event_field; |
f1676205 MD |
149 | size_t (*get_size)(size_t offset); |
150 | void (*record)(struct lttng_ctx_field *field, | |
151 | struct lib_ring_buffer_ctx *ctx, | |
a90917c3 | 152 | struct lttng_channel *chan); |
ba1f5986 | 153 | union { |
2001023e | 154 | struct lttng_perf_counter_field *perf_counter; |
ba1f5986 | 155 | } u; |
2dccf128 | 156 | void (*destroy)(struct lttng_ctx_field *field); |
ba1f5986 MD |
157 | }; |
158 | ||
159 | struct lttng_ctx { | |
833ad6a0 | 160 | struct lttng_ctx_field *fields; |
0d1a681e | 161 | unsigned int nr_fields; |
ba1f5986 | 162 | unsigned int allocated_fields; |
0d1a681e MD |
163 | }; |
164 | ||
165 | struct lttng_event_desc { | |
c0edae1d MD |
166 | const char *name; |
167 | void *probe_callback; | |
0d1a681e MD |
168 | const struct lttng_event_ctx *ctx; /* context */ |
169 | const struct lttng_event_field *fields; /* event payload */ | |
c0edae1d | 170 | unsigned int nr_fields; |
dc7f600a | 171 | struct module *owner; |
c0edae1d MD |
172 | }; |
173 | ||
85a9ca7f | 174 | struct lttng_probe_desc { |
f7bdf4db | 175 | const struct lttng_event_desc **event_desc; |
85a9ca7f MD |
176 | unsigned int nr_events; |
177 | struct list_head head; /* chain registered probes */ | |
178 | }; | |
179 | ||
7371f44c MD |
180 | struct lttng_krp; /* Kretprobe handling */ |
181 | ||
85a9ca7f | 182 | /* |
a90917c3 | 183 | * lttng_event structure is referred to by the tracing fast path. It must be |
85a9ca7f MD |
184 | * kept small. |
185 | */ | |
a90917c3 | 186 | struct lttng_event { |
85a9ca7f | 187 | unsigned int id; |
a90917c3 | 188 | struct lttng_channel *chan; |
e64957da | 189 | int enabled; |
d3dbe23c | 190 | const struct lttng_event_desc *desc; |
85a9ca7f | 191 | void *filter; |
f1676205 | 192 | struct lttng_ctx *ctx; |
38d024ae | 193 | enum lttng_kernel_instrumentation instrumentation; |
d6d808f3 MD |
194 | union { |
195 | struct { | |
196 | struct kprobe kp; | |
197 | char *symbol_name; | |
198 | } kprobe; | |
7371f44c MD |
199 | struct { |
200 | struct lttng_krp *lttng_krp; | |
201 | char *symbol_name; | |
202 | } kretprobe; | |
e0a7a7c4 MD |
203 | struct { |
204 | char *symbol_name; | |
205 | } ftrace; | |
d6d808f3 | 206 | } u; |
85a9ca7f | 207 | struct list_head list; /* Event list */ |
9cccf98a | 208 | unsigned int metadata_dumped:1; |
85a9ca7f MD |
209 | }; |
210 | ||
a90917c3 | 211 | struct lttng_channel_ops { |
85a9ca7f | 212 | struct channel *(*channel_create)(const char *name, |
a90917c3 | 213 | struct lttng_channel *lttng_chan, |
85a9ca7f MD |
214 | void *buf_addr, |
215 | size_t subbuf_size, size_t num_subbuf, | |
216 | unsigned int switch_timer_interval, | |
217 | unsigned int read_timer_interval); | |
218 | void (*channel_destroy)(struct channel *chan); | |
219 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); | |
f71ecafa | 220 | int (*buffer_has_read_closed_stream)(struct channel *chan); |
85a9ca7f | 221 | void (*buffer_read_close)(struct lib_ring_buffer *buf); |
4e1f08f4 | 222 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx, |
64c796d8 | 223 | uint32_t event_id); |
85a9ca7f MD |
224 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
225 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, | |
226 | size_t len); | |
4ea00e4f JD |
227 | void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx, |
228 | const void *src, size_t len); | |
58aa5d24 MD |
229 | void (*event_memset)(struct lib_ring_buffer_ctx *ctx, |
230 | int c, size_t len); | |
1ec3f75a MD |
231 | /* |
232 | * packet_avail_size returns the available size in the current | |
233 | * packet. Note that the size returned is only a hint, since it | |
234 | * may change due to concurrent writes. | |
235 | */ | |
236 | size_t (*packet_avail_size)(struct channel *chan); | |
71c1d843 | 237 | wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu); |
24cedcfe MD |
238 | wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); |
239 | int (*is_finalized)(struct channel *chan); | |
254ec7bc | 240 | int (*is_disabled)(struct channel *chan); |
85a9ca7f MD |
241 | }; |
242 | ||
a90917c3 | 243 | struct lttng_transport { |
a33c9927 MD |
244 | char *name; |
245 | struct module *owner; | |
246 | struct list_head node; | |
a90917c3 | 247 | struct lttng_channel_ops ops; |
a33c9927 MD |
248 | }; |
249 | ||
a90917c3 | 250 | struct lttng_channel { |
c099397a | 251 | unsigned int id; |
85a9ca7f | 252 | struct channel *chan; /* Channel buffers */ |
e64957da | 253 | int enabled; |
f1676205 | 254 | struct lttng_ctx *ctx; |
85a9ca7f | 255 | /* Event ID management */ |
a90917c3 | 256 | struct lttng_session *session; |
85a9ca7f MD |
257 | struct file *file; /* File associated to channel */ |
258 | unsigned int free_event_id; /* Next event ID to allocate */ | |
259 | struct list_head list; /* Channel list */ | |
a90917c3 MD |
260 | struct lttng_channel_ops *ops; |
261 | struct lttng_transport *transport; | |
262 | struct lttng_event **sc_table; /* for syscall tracing */ | |
263 | struct lttng_event **compat_sc_table; | |
264 | struct lttng_event *sc_unknown; /* for unknown syscalls */ | |
265 | struct lttng_event *sc_compat_unknown; | |
266 | struct lttng_event *sc_exit; /* for syscall exit */ | |
9115fbdc | 267 | int header_type; /* 0: unset, 1: compact, 2: large */ |
9cccf98a | 268 | unsigned int metadata_dumped:1; |
85a9ca7f MD |
269 | }; |
270 | ||
a90917c3 | 271 | struct lttng_session { |
85a9ca7f | 272 | int active; /* Is trace session active ? */ |
8070f5c0 | 273 | int been_active; /* Has trace session been active ? */ |
85a9ca7f | 274 | struct file *file; /* File associated to session */ |
a90917c3 | 275 | struct lttng_channel *metadata; /* Metadata channel */ |
85a9ca7f MD |
276 | struct list_head chan; /* Channel list head */ |
277 | struct list_head events; /* Event list head */ | |
278 | struct list_head list; /* Session list */ | |
c099397a | 279 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
d793d5e1 | 280 | uuid_le uuid; /* Trace session unique ID */ |
9cccf98a | 281 | unsigned int metadata_dumped:1; |
85a9ca7f MD |
282 | }; |
283 | ||
a90917c3 MD |
284 | struct lttng_session *lttng_session_create(void); |
285 | int lttng_session_enable(struct lttng_session *session); | |
286 | int lttng_session_disable(struct lttng_session *session); | |
287 | void lttng_session_destroy(struct lttng_session *session); | |
4e3c1b9b | 288 | |
a90917c3 | 289 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
5dbbdb43 MD |
290 | const char *transport_name, |
291 | void *buf_addr, | |
292 | size_t subbuf_size, size_t num_subbuf, | |
293 | unsigned int switch_timer_interval, | |
294 | unsigned int read_timer_interval); | |
a90917c3 | 295 | struct lttng_channel *lttng_global_channel_create(struct lttng_session *session, |
4e3c1b9b MD |
296 | int overwrite, void *buf_addr, |
297 | size_t subbuf_size, size_t num_subbuf, | |
298 | unsigned int switch_timer_interval, | |
299 | unsigned int read_timer_interval); | |
4e3c1b9b | 300 | |
a90917c3 | 301 | struct lttng_event *lttng_event_create(struct lttng_channel *chan, |
d6d808f3 | 302 | struct lttng_kernel_event *event_param, |
259b6cb3 MD |
303 | void *filter, |
304 | const struct lttng_event_desc *internal_desc); | |
6dccd6c1 JD |
305 | struct lttng_event *lttng_event_compat_old_create(struct lttng_channel *chan, |
306 | struct lttng_kernel_old_event *old_event_param, | |
307 | void *filter, | |
308 | const struct lttng_event_desc *internal_desc); | |
c0e31d2e | 309 | |
a90917c3 MD |
310 | int lttng_channel_enable(struct lttng_channel *channel); |
311 | int lttng_channel_disable(struct lttng_channel *channel); | |
312 | int lttng_event_enable(struct lttng_event *event); | |
313 | int lttng_event_disable(struct lttng_event *event); | |
e64957da | 314 | |
a90917c3 MD |
315 | void lttng_transport_register(struct lttng_transport *transport); |
316 | void lttng_transport_unregister(struct lttng_transport *transport); | |
11b5a3c2 | 317 | |
360f38ea | 318 | void synchronize_trace(void); |
80996790 | 319 | int lttng_abi_init(void); |
6dccd6c1 | 320 | int lttng_abi_compat_old_init(void); |
80996790 | 321 | void lttng_abi_exit(void); |
6dccd6c1 | 322 | void lttng_abi_compat_old_exit(void); |
1c25284c | 323 | |
a90917c3 MD |
324 | int lttng_probe_register(struct lttng_probe_desc *desc); |
325 | void lttng_probe_unregister(struct lttng_probe_desc *desc); | |
326 | const struct lttng_event_desc *lttng_event_get(const char *name); | |
327 | void lttng_event_put(const struct lttng_event_desc *desc); | |
328 | int lttng_probes_init(void); | |
329 | void lttng_probes_exit(void); | |
1ec65de1 | 330 | |
3a523f5b | 331 | #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS) |
a90917c3 MD |
332 | int lttng_syscalls_register(struct lttng_channel *chan, void *filter); |
333 | int lttng_syscalls_unregister(struct lttng_channel *chan); | |
1ec65de1 | 334 | #else |
a90917c3 | 335 | static inline int lttng_syscalls_register(struct lttng_channel *chan, void *filter) |
1ec65de1 MD |
336 | { |
337 | return -ENOSYS; | |
338 | } | |
339 | ||
a90917c3 | 340 | static inline int lttng_syscalls_unregister(struct lttng_channel *chan) |
1ec65de1 MD |
341 | { |
342 | return 0; | |
343 | } | |
344 | #endif | |
345 | ||
2dccf128 | 346 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); |
44252f0f | 347 | int lttng_find_context(struct lttng_ctx *ctx, const char *name); |
8289661d MD |
348 | void lttng_remove_context_field(struct lttng_ctx **ctx, |
349 | struct lttng_ctx_field *field); | |
2dccf128 | 350 | void lttng_destroy_context(struct lttng_ctx *ctx); |
8070f5c0 | 351 | int lttng_add_pid_to_ctx(struct lttng_ctx **ctx); |
a2563e83 | 352 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); |
a8ad3613 | 353 | int lttng_add_prio_to_ctx(struct lttng_ctx **ctx); |
53f1f0ca | 354 | int lttng_add_nice_to_ctx(struct lttng_ctx **ctx); |
b64bc438 MD |
355 | int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); |
356 | int lttng_add_tid_to_ctx(struct lttng_ctx **ctx); | |
357 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); | |
358 | int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx); | |
359 | int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx); | |
975da2c0 | 360 | int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx); |
41c3c24e | 361 | #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) |
c24a0d71 MD |
362 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
363 | uint64_t config, | |
364 | const char *name, | |
365 | struct lttng_ctx **ctx); | |
1d443b34 MD |
366 | #else |
367 | static inline | |
368 | int lttng_add_perf_counter_to_ctx(uint32_t type, | |
369 | uint64_t config, | |
370 | const char *name, | |
371 | struct lttng_ctx **ctx) | |
372 | { | |
373 | return -ENOSYS; | |
374 | } | |
375 | #endif | |
02119ee5 | 376 | |
c337ddc2 MD |
377 | extern int lttng_statedump_start(struct lttng_session *session); |
378 | ||
acd614cc | 379 | #ifdef CONFIG_KPROBES |
f17701fb MD |
380 | int lttng_kprobes_register(const char *name, |
381 | const char *symbol_name, | |
382 | uint64_t offset, | |
383 | uint64_t addr, | |
a90917c3 MD |
384 | struct lttng_event *event); |
385 | void lttng_kprobes_unregister(struct lttng_event *event); | |
386 | void lttng_kprobes_destroy_private(struct lttng_event *event); | |
acd614cc MD |
387 | #else |
388 | static inline | |
389 | int lttng_kprobes_register(const char *name, | |
390 | const char *symbol_name, | |
391 | uint64_t offset, | |
392 | uint64_t addr, | |
a90917c3 | 393 | struct lttng_event *event) |
acd614cc MD |
394 | { |
395 | return -ENOSYS; | |
396 | } | |
397 | ||
25f53c39 | 398 | static inline |
a90917c3 | 399 | void lttng_kprobes_unregister(struct lttng_event *event) |
acd614cc MD |
400 | { |
401 | } | |
edeb3137 MD |
402 | |
403 | static inline | |
a90917c3 | 404 | void lttng_kprobes_destroy_private(struct lttng_event *event) |
edeb3137 MD |
405 | { |
406 | } | |
acd614cc | 407 | #endif |
d6d808f3 | 408 | |
7371f44c MD |
409 | #ifdef CONFIG_KRETPROBES |
410 | int lttng_kretprobes_register(const char *name, | |
411 | const char *symbol_name, | |
412 | uint64_t offset, | |
413 | uint64_t addr, | |
a90917c3 MD |
414 | struct lttng_event *event_entry, |
415 | struct lttng_event *event_exit); | |
416 | void lttng_kretprobes_unregister(struct lttng_event *event); | |
417 | void lttng_kretprobes_destroy_private(struct lttng_event *event); | |
7371f44c MD |
418 | #else |
419 | static inline | |
420 | int lttng_kretprobes_register(const char *name, | |
421 | const char *symbol_name, | |
422 | uint64_t offset, | |
423 | uint64_t addr, | |
a90917c3 MD |
424 | struct lttng_event *event_entry, |
425 | struct lttng_event *event_exit) | |
7371f44c MD |
426 | { |
427 | return -ENOSYS; | |
428 | } | |
429 | ||
430 | static inline | |
a90917c3 | 431 | void lttng_kretprobes_unregister(struct lttng_event *event) |
7371f44c MD |
432 | { |
433 | } | |
434 | ||
435 | static inline | |
a90917c3 | 436 | void lttng_kretprobes_destroy_private(struct lttng_event *event) |
7371f44c MD |
437 | { |
438 | } | |
439 | #endif | |
440 | ||
e0a7a7c4 MD |
441 | #ifdef CONFIG_DYNAMIC_FTRACE |
442 | int lttng_ftrace_register(const char *name, | |
443 | const char *symbol_name, | |
a90917c3 MD |
444 | struct lttng_event *event); |
445 | void lttng_ftrace_unregister(struct lttng_event *event); | |
446 | void lttng_ftrace_destroy_private(struct lttng_event *event); | |
e0a7a7c4 MD |
447 | #else |
448 | static inline | |
449 | int lttng_ftrace_register(const char *name, | |
450 | const char *symbol_name, | |
a90917c3 | 451 | struct lttng_event *event) |
e0a7a7c4 | 452 | { |
acd614cc | 453 | return -ENOSYS; |
e0a7a7c4 MD |
454 | } |
455 | ||
456 | static inline | |
a90917c3 | 457 | void lttng_ftrace_unregister(struct lttng_event *event) |
e0a7a7c4 MD |
458 | { |
459 | } | |
edeb3137 MD |
460 | |
461 | static inline | |
a90917c3 | 462 | void lttng_ftrace_destroy_private(struct lttng_event *event) |
edeb3137 MD |
463 | { |
464 | } | |
e0a7a7c4 | 465 | #endif |
271b6681 | 466 | |
3db41b2c | 467 | int lttng_calibrate(struct lttng_kernel_calibrate *calibrate); |
57105fc2 | 468 | |
271b6681 MD |
469 | extern const struct file_operations lttng_tracepoint_list_fops; |
470 | ||
ef200626 MD |
471 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
472 | #define TRACEPOINT_HAS_DATA_ARG | |
473 | #endif | |
474 | ||
a90917c3 | 475 | #endif /* _LTTNG_EVENTS_H */ |