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