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