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