Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
a90917c3 | 3 | * lttng-events.h |
4e3c1b9b | 4 | * |
4e3c1b9b | 5 | * Holds LTTng per-session event registry. |
17baffe2 | 6 | * |
886d51a3 | 7 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
4e3c1b9b MD |
8 | */ |
9 | ||
9f36eaed MJ |
10 | #ifndef _LTTNG_EVENTS_H |
11 | #define _LTTNG_EVENTS_H | |
12 | ||
3a523f5b | 13 | #include <linux/version.h> |
4e3c1b9b | 14 | #include <linux/list.h> |
d6d808f3 | 15 | #include <linux/kprobes.h> |
d83004aa | 16 | #include <linux/kref.h> |
1e367326 | 17 | #include <lttng-cpuhotplug.h> |
bbd023d6 | 18 | #include <wrapper/uuid.h> |
149b9a9d | 19 | #include <wrapper/uprobes.h> |
f64dd4be | 20 | #include <lttng-tracer.h> |
bbd023d6 MD |
21 | #include <lttng-abi.h> |
22 | #include <lttng-abi-old.h> | |
4e3c1b9b | 23 | |
06254b0f | 24 | #define lttng_is_signed_type(type) (((type)(-1)) < 0) |
9e7e4892 | 25 | |
a90917c3 MD |
26 | struct lttng_channel; |
27 | struct lttng_session; | |
d83004aa | 28 | struct lttng_metadata_cache; |
1c25284c | 29 | struct lib_ring_buffer_ctx; |
ba1f5986 | 30 | struct perf_event; |
833ad6a0 | 31 | struct perf_event_attr; |
3b731ab1 | 32 | struct lib_ring_buffer_config; |
4e3c1b9b | 33 | |
c0edae1d MD |
34 | /* Type description */ |
35 | ||
c0edae1d MD |
36 | enum abstract_types { |
37 | atype_integer, | |
38 | atype_enum, | |
39 | atype_array, | |
40 | atype_sequence, | |
41 | atype_string, | |
f513b2bf MD |
42 | atype_struct, |
43 | atype_array_compound, /* Array of compound types. */ | |
44 | atype_sequence_compound, /* Sequence of compound types. */ | |
65c85aa6 | 45 | atype_variant, |
3834b99f MD |
46 | atype_array_bitfield, |
47 | atype_sequence_bitfield, | |
c0edae1d MD |
48 | NR_ABSTRACT_TYPES, |
49 | }; | |
50 | ||
c0edae1d | 51 | enum lttng_string_encodings { |
e0a7a7c4 MD |
52 | lttng_encode_none = 0, |
53 | lttng_encode_UTF8 = 1, | |
54 | lttng_encode_ASCII = 2, | |
c0edae1d MD |
55 | NR_STRING_ENCODINGS, |
56 | }; | |
57 | ||
d83004aa JD |
58 | enum channel_type { |
59 | PER_CPU_CHANNEL, | |
60 | METADATA_CHANNEL, | |
61 | }; | |
62 | ||
141ddf28 MD |
63 | struct lttng_enum_value { |
64 | unsigned long long value; | |
65 | unsigned int signedness:1; | |
66 | }; | |
67 | ||
c0edae1d | 68 | struct lttng_enum_entry { |
141ddf28 | 69 | struct lttng_enum_value start, end; /* start and end are inclusive */ |
c0edae1d | 70 | const char *string; |
08ad1061 PP |
71 | struct { |
72 | unsigned int is_auto:1; | |
73 | } options; | |
c0edae1d MD |
74 | }; |
75 | ||
43803cf2 MD |
76 | #define __type_integer(_type, _size, _alignment, _signedness, \ |
77 | _byte_order, _base, _encoding) \ | |
c099397a MD |
78 | { \ |
79 | .atype = atype_integer, \ | |
80 | .u.basic.integer = \ | |
81 | { \ | |
43803cf2 MD |
82 | .size = (_size) ? : sizeof(_type) * CHAR_BIT, \ |
83 | .alignment = (_alignment) ? : lttng_alignof(_type) * CHAR_BIT, \ | |
84 | .signedness = (_signedness) >= 0 ? (_signedness) : lttng_is_signed_type(_type), \ | |
85 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ | |
e0a7a7c4 | 86 | .base = _base, \ |
64c796d8 | 87 | .encoding = lttng_encode_##_encoding, \ |
c099397a MD |
88 | }, \ |
89 | } \ | |
90 | ||
91 | struct lttng_integer_type { | |
92 | unsigned int size; /* in bits */ | |
93 | unsigned short alignment; /* in bits */ | |
9cccf98a MD |
94 | unsigned int signedness:1, |
95 | reverse_byte_order:1; | |
e0a7a7c4 MD |
96 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
97 | enum lttng_string_encodings encoding; | |
c099397a MD |
98 | }; |
99 | ||
100 | union _lttng_basic_type { | |
101 | struct lttng_integer_type integer; | |
102 | struct { | |
141ddf28 MD |
103 | const struct lttng_enum_desc *desc; /* Enumeration mapping */ |
104 | struct lttng_integer_type container_type; | |
c099397a MD |
105 | } enumeration; |
106 | struct { | |
107 | enum lttng_string_encodings encoding; | |
108 | } string; | |
109 | }; | |
110 | ||
111 | struct lttng_basic_type { | |
112 | enum abstract_types atype; | |
113 | union { | |
114 | union _lttng_basic_type basic; | |
115 | } u; | |
c0edae1d MD |
116 | }; |
117 | ||
118 | struct lttng_type { | |
119 | enum abstract_types atype; | |
c0edae1d | 120 | union { |
c099397a | 121 | union _lttng_basic_type basic; |
c0edae1d | 122 | struct { |
c099397a | 123 | struct lttng_basic_type elem_type; |
c0edae1d | 124 | unsigned int length; /* num. elems. */ |
43803cf2 | 125 | unsigned int elem_alignment; /* alignment override */ |
c0edae1d MD |
126 | } array; |
127 | struct { | |
c099397a MD |
128 | struct lttng_basic_type length_type; |
129 | struct lttng_basic_type elem_type; | |
43803cf2 | 130 | unsigned int elem_alignment; /* alignment override */ |
c0edae1d | 131 | } sequence; |
f513b2bf MD |
132 | struct { |
133 | uint32_t nr_fields; | |
134 | struct lttng_event_field *fields; /* Array of fields. */ | |
135 | } _struct; | |
136 | struct { | |
137 | struct lttng_type *elem_type; | |
138 | unsigned int length; /* num. elems. */ | |
139 | } array_compound; | |
140 | struct { | |
141 | struct lttng_type *elem_type; | |
142 | const char *length_name; | |
143 | } sequence_compound; | |
65c85aa6 MD |
144 | struct { |
145 | const char *tag_name; | |
146 | struct lttng_event_field *choices; /* Array of fields. */ | |
147 | uint32_t nr_choices; | |
148 | } variant; | |
c0edae1d | 149 | } u; |
c099397a MD |
150 | }; |
151 | ||
141ddf28 | 152 | struct lttng_enum_desc { |
c099397a | 153 | const char *name; |
c099397a | 154 | const struct lttng_enum_entry *entries; |
141ddf28 | 155 | unsigned int nr_entries; |
c099397a | 156 | }; |
c0edae1d MD |
157 | |
158 | /* Event field description */ | |
159 | ||
160 | struct lttng_event_field { | |
161 | const char *name; | |
f17701fb | 162 | struct lttng_type type; |
f127e61e MD |
163 | unsigned int nowrite:1, /* do not write into trace */ |
164 | user:1; /* fetch from user-space */ | |
c0edae1d MD |
165 | }; |
166 | ||
07dfc1d0 MD |
167 | union lttng_ctx_value { |
168 | int64_t s64; | |
169 | const char *str; | |
170 | double d; | |
171 | }; | |
172 | ||
2001023e MD |
173 | /* |
174 | * We need to keep this perf counter field separately from struct | |
175 | * lttng_ctx_field because cpu hotplug needs fixed-location addresses. | |
176 | */ | |
177 | struct lttng_perf_counter_field { | |
1e367326 MD |
178 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) |
179 | struct lttng_cpuhp_node cpuhp_prepare; | |
180 | struct lttng_cpuhp_node cpuhp_online; | |
181 | #else | |
2001023e MD |
182 | struct notifier_block nb; |
183 | int hp_enable; | |
1e367326 | 184 | #endif |
2001023e MD |
185 | struct perf_event_attr *attr; |
186 | struct perf_event **e; /* per-cpu array */ | |
187 | }; | |
188 | ||
79150a49 JD |
189 | struct lttng_probe_ctx { |
190 | struct lttng_event *event; | |
191 | uint8_t interruptible; | |
192 | }; | |
193 | ||
ba1f5986 | 194 | struct lttng_ctx_field { |
8070f5c0 | 195 | struct lttng_event_field event_field; |
f1676205 | 196 | size_t (*get_size)(size_t offset); |
1474c8e2 FG |
197 | size_t (*get_size_arg)(size_t offset, struct lttng_ctx_field *field, |
198 | struct lib_ring_buffer_ctx *ctx, | |
199 | struct lttng_channel *chan); | |
f1676205 MD |
200 | void (*record)(struct lttng_ctx_field *field, |
201 | struct lib_ring_buffer_ctx *ctx, | |
a90917c3 | 202 | struct lttng_channel *chan); |
07dfc1d0 | 203 | void (*get_value)(struct lttng_ctx_field *field, |
79150a49 | 204 | struct lttng_probe_ctx *lttng_probe_ctx, |
07dfc1d0 | 205 | union lttng_ctx_value *value); |
ba1f5986 | 206 | union { |
2001023e | 207 | struct lttng_perf_counter_field *perf_counter; |
ba1f5986 | 208 | } u; |
2dccf128 | 209 | void (*destroy)(struct lttng_ctx_field *field); |
3c1a57e8 MD |
210 | /* |
211 | * Private data to keep state between get_size and record. | |
212 | * User must perform its own synchronization to protect against | |
213 | * concurrent and reentrant contexts. | |
214 | */ | |
215 | void *priv; | |
ba1f5986 MD |
216 | }; |
217 | ||
218 | struct lttng_ctx { | |
833ad6a0 | 219 | struct lttng_ctx_field *fields; |
0d1a681e | 220 | unsigned int nr_fields; |
ba1f5986 | 221 | unsigned int allocated_fields; |
a9dd15da | 222 | size_t largest_align; /* in bytes */ |
0d1a681e MD |
223 | }; |
224 | ||
225 | struct lttng_event_desc { | |
a26a7e4f MD |
226 | const char *name; /* lttng-modules name */ |
227 | const char *kname; /* Linux kernel name (tracepoints) */ | |
c0edae1d | 228 | void *probe_callback; |
0d1a681e MD |
229 | const struct lttng_event_ctx *ctx; /* context */ |
230 | const struct lttng_event_field *fields; /* event payload */ | |
c0edae1d | 231 | unsigned int nr_fields; |
dc7f600a | 232 | struct module *owner; |
c0edae1d MD |
233 | }; |
234 | ||
85a9ca7f | 235 | struct lttng_probe_desc { |
3c997079 | 236 | const char *provider; |
f7bdf4db | 237 | const struct lttng_event_desc **event_desc; |
85a9ca7f MD |
238 | unsigned int nr_events; |
239 | struct list_head head; /* chain registered probes */ | |
3c997079 MD |
240 | struct list_head lazy_init_head; |
241 | int lazy; /* lazy registration */ | |
85a9ca7f MD |
242 | }; |
243 | ||
7371f44c MD |
244 | struct lttng_krp; /* Kretprobe handling */ |
245 | ||
3c997079 MD |
246 | enum lttng_event_type { |
247 | LTTNG_TYPE_EVENT = 0, | |
248 | LTTNG_TYPE_ENABLER = 1, | |
249 | }; | |
250 | ||
07dfc1d0 MD |
251 | struct lttng_filter_bytecode_node { |
252 | struct list_head node; | |
253 | struct lttng_enabler *enabler; | |
254 | /* | |
255 | * struct lttng_kernel_filter_bytecode has var. sized array, must be | |
256 | * last field. | |
257 | */ | |
258 | struct lttng_kernel_filter_bytecode bc; | |
259 | }; | |
260 | ||
261 | /* | |
262 | * Filter return value masks. | |
263 | */ | |
264 | enum lttng_filter_ret { | |
265 | LTTNG_FILTER_DISCARD = 0, | |
266 | LTTNG_FILTER_RECORD_FLAG = (1ULL << 0), | |
267 | /* Other bits are kept for future use. */ | |
268 | }; | |
269 | ||
270 | struct lttng_bytecode_runtime { | |
271 | /* Associated bytecode */ | |
272 | struct lttng_filter_bytecode_node *bc; | |
79150a49 JD |
273 | uint64_t (*filter)(void *filter_data, struct lttng_probe_ctx *lttng_probe_ctx, |
274 | const char *filter_stack_data); | |
07dfc1d0 MD |
275 | int link_failed; |
276 | struct list_head node; /* list of bytecode runtime in event */ | |
3834b99f | 277 | struct lttng_event *event; |
07dfc1d0 MD |
278 | }; |
279 | ||
3c997079 MD |
280 | /* |
281 | * Objects in a linked-list of enablers, owned by an event. | |
282 | */ | |
283 | struct lttng_enabler_ref { | |
284 | struct list_head node; /* enabler ref list */ | |
285 | struct lttng_enabler *ref; /* backward ref */ | |
286 | }; | |
287 | ||
3aed4dca FD |
288 | struct lttng_uprobe_handler { |
289 | struct lttng_event *event; | |
290 | loff_t offset; | |
291 | struct uprobe_consumer up_consumer; | |
292 | struct list_head node; | |
293 | }; | |
294 | ||
85a9ca7f | 295 | /* |
a90917c3 | 296 | * lttng_event structure is referred to by the tracing fast path. It must be |
85a9ca7f MD |
297 | * kept small. |
298 | */ | |
a90917c3 | 299 | struct lttng_event { |
3c997079 | 300 | enum lttng_event_type evtype; /* First field. */ |
85a9ca7f | 301 | unsigned int id; |
a90917c3 | 302 | struct lttng_channel *chan; |
e64957da | 303 | int enabled; |
d3dbe23c | 304 | const struct lttng_event_desc *desc; |
85a9ca7f | 305 | void *filter; |
f1676205 | 306 | struct lttng_ctx *ctx; |
38d024ae | 307 | enum lttng_kernel_instrumentation instrumentation; |
d6d808f3 MD |
308 | union { |
309 | struct { | |
310 | struct kprobe kp; | |
311 | char *symbol_name; | |
312 | } kprobe; | |
7371f44c MD |
313 | struct { |
314 | struct lttng_krp *lttng_krp; | |
315 | char *symbol_name; | |
316 | } kretprobe; | |
e0a7a7c4 MD |
317 | struct { |
318 | char *symbol_name; | |
319 | } ftrace; | |
149b9a9d | 320 | struct { |
149b9a9d | 321 | struct inode *inode; |
3aed4dca | 322 | struct list_head head; |
149b9a9d | 323 | } uprobe; |
d6d808f3 | 324 | } u; |
3c997079 | 325 | struct list_head list; /* Event list in session */ |
9cccf98a | 326 | unsigned int metadata_dumped:1; |
3c997079 MD |
327 | |
328 | /* Backward references: list of lttng_enabler_ref (ref to enablers) */ | |
329 | struct list_head enablers_ref_head; | |
330 | struct hlist_node hlist; /* session ht of events */ | |
331 | int registered; /* has reg'd tracepoint probe */ | |
07dfc1d0 MD |
332 | /* list of struct lttng_bytecode_runtime, sorted by seqnum */ |
333 | struct list_head bytecode_runtime_head; | |
334 | int has_enablers_without_bytecode; | |
3c997079 MD |
335 | }; |
336 | ||
337 | enum lttng_enabler_type { | |
4993071a | 338 | LTTNG_ENABLER_STAR_GLOB, |
3c997079 MD |
339 | LTTNG_ENABLER_NAME, |
340 | }; | |
341 | ||
342 | /* | |
343 | * Enabler field, within whatever object is enabling an event. Target of | |
344 | * backward reference. | |
345 | */ | |
346 | struct lttng_enabler { | |
347 | enum lttng_event_type evtype; /* First field. */ | |
348 | ||
349 | enum lttng_enabler_type type; | |
350 | ||
351 | struct list_head node; /* per-session list of enablers */ | |
07dfc1d0 MD |
352 | /* head list of struct lttng_ust_filter_bytecode_node */ |
353 | struct list_head filter_bytecode_head; | |
3c997079 MD |
354 | |
355 | struct lttng_kernel_event event_param; | |
356 | struct lttng_channel *chan; | |
357 | struct lttng_ctx *ctx; | |
358 | unsigned int enabled:1; | |
85a9ca7f MD |
359 | }; |
360 | ||
a90917c3 | 361 | struct lttng_channel_ops { |
85a9ca7f | 362 | struct channel *(*channel_create)(const char *name, |
a90917c3 | 363 | struct lttng_channel *lttng_chan, |
85a9ca7f MD |
364 | void *buf_addr, |
365 | size_t subbuf_size, size_t num_subbuf, | |
366 | unsigned int switch_timer_interval, | |
367 | unsigned int read_timer_interval); | |
368 | void (*channel_destroy)(struct channel *chan); | |
369 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); | |
f71ecafa | 370 | int (*buffer_has_read_closed_stream)(struct channel *chan); |
85a9ca7f | 371 | void (*buffer_read_close)(struct lib_ring_buffer *buf); |
4e1f08f4 | 372 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx, |
64c796d8 | 373 | uint32_t event_id); |
85a9ca7f MD |
374 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
375 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, | |
376 | size_t len); | |
4ea00e4f JD |
377 | void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx, |
378 | const void *src, size_t len); | |
58aa5d24 MD |
379 | void (*event_memset)(struct lib_ring_buffer_ctx *ctx, |
380 | int c, size_t len); | |
16f78f3a MD |
381 | void (*event_strcpy)(struct lib_ring_buffer_ctx *ctx, const char *src, |
382 | size_t len); | |
383 | void (*event_strcpy_from_user)(struct lib_ring_buffer_ctx *ctx, | |
384 | const char __user *src, size_t len); | |
1ec3f75a MD |
385 | /* |
386 | * packet_avail_size returns the available size in the current | |
387 | * packet. Note that the size returned is only a hint, since it | |
388 | * may change due to concurrent writes. | |
389 | */ | |
390 | size_t (*packet_avail_size)(struct channel *chan); | |
71c1d843 | 391 | wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu); |
24cedcfe MD |
392 | wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan); |
393 | int (*is_finalized)(struct channel *chan); | |
254ec7bc | 394 | int (*is_disabled)(struct channel *chan); |
3b731ab1 JD |
395 | int (*timestamp_begin) (const struct lib_ring_buffer_config *config, |
396 | struct lib_ring_buffer *bufb, | |
397 | uint64_t *timestamp_begin); | |
398 | int (*timestamp_end) (const struct lib_ring_buffer_config *config, | |
399 | struct lib_ring_buffer *bufb, | |
400 | uint64_t *timestamp_end); | |
401 | int (*events_discarded) (const struct lib_ring_buffer_config *config, | |
402 | struct lib_ring_buffer *bufb, | |
403 | uint64_t *events_discarded); | |
404 | int (*content_size) (const struct lib_ring_buffer_config *config, | |
405 | struct lib_ring_buffer *bufb, | |
406 | uint64_t *content_size); | |
407 | int (*packet_size) (const struct lib_ring_buffer_config *config, | |
408 | struct lib_ring_buffer *bufb, | |
409 | uint64_t *packet_size); | |
410 | int (*stream_id) (const struct lib_ring_buffer_config *config, | |
411 | struct lib_ring_buffer *bufb, | |
412 | uint64_t *stream_id); | |
2348ca17 JD |
413 | int (*current_timestamp) (const struct lib_ring_buffer_config *config, |
414 | struct lib_ring_buffer *bufb, | |
415 | uint64_t *ts); | |
5b3cf4f9 JD |
416 | int (*sequence_number) (const struct lib_ring_buffer_config *config, |
417 | struct lib_ring_buffer *bufb, | |
418 | uint64_t *seq); | |
5594698f JD |
419 | int (*instance_id) (const struct lib_ring_buffer_config *config, |
420 | struct lib_ring_buffer *bufb, | |
421 | uint64_t *id); | |
85a9ca7f MD |
422 | }; |
423 | ||
a90917c3 | 424 | struct lttng_transport { |
a33c9927 MD |
425 | char *name; |
426 | struct module *owner; | |
427 | struct list_head node; | |
a90917c3 | 428 | struct lttng_channel_ops ops; |
a33c9927 MD |
429 | }; |
430 | ||
80f87dd2 MD |
431 | struct lttng_syscall_filter; |
432 | ||
3c997079 MD |
433 | #define LTTNG_EVENT_HT_BITS 12 |
434 | #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS) | |
435 | ||
436 | struct lttng_event_ht { | |
437 | struct hlist_head table[LTTNG_EVENT_HT_SIZE]; | |
438 | }; | |
439 | ||
a90917c3 | 440 | struct lttng_channel { |
c099397a | 441 | unsigned int id; |
85a9ca7f | 442 | struct channel *chan; /* Channel buffers */ |
e64957da | 443 | int enabled; |
f1676205 | 444 | struct lttng_ctx *ctx; |
85a9ca7f | 445 | /* Event ID management */ |
a90917c3 | 446 | struct lttng_session *session; |
85a9ca7f MD |
447 | struct file *file; /* File associated to channel */ |
448 | unsigned int free_event_id; /* Next event ID to allocate */ | |
449 | struct list_head list; /* Channel list */ | |
a90917c3 MD |
450 | struct lttng_channel_ops *ops; |
451 | struct lttng_transport *transport; | |
452 | struct lttng_event **sc_table; /* for syscall tracing */ | |
453 | struct lttng_event **compat_sc_table; | |
5b7ac358 MD |
454 | struct lttng_event **sc_exit_table; /* for syscall exit tracing */ |
455 | struct lttng_event **compat_sc_exit_table; | |
a90917c3 MD |
456 | struct lttng_event *sc_unknown; /* for unknown syscalls */ |
457 | struct lttng_event *sc_compat_unknown; | |
5b7ac358 MD |
458 | struct lttng_event *sc_exit_unknown; |
459 | struct lttng_event *compat_sc_exit_unknown; | |
80f87dd2 | 460 | struct lttng_syscall_filter *sc_filter; |
9115fbdc | 461 | int header_type; /* 0: unset, 1: compact, 2: large */ |
d83004aa | 462 | enum channel_type channel_type; |
80f87dd2 MD |
463 | unsigned int metadata_dumped:1, |
464 | sys_enter_registered:1, | |
465 | sys_exit_registered:1, | |
3c997079 MD |
466 | syscall_all:1, |
467 | tstate:1; /* Transient enable state */ | |
85a9ca7f MD |
468 | }; |
469 | ||
d83004aa JD |
470 | struct lttng_metadata_stream { |
471 | void *priv; /* Ring buffer private data */ | |
472 | struct lttng_metadata_cache *metadata_cache; | |
f613e3e6 MD |
473 | unsigned int metadata_in; /* Bytes read from the cache */ |
474 | unsigned int metadata_out; /* Bytes consumed from stream */ | |
d83004aa JD |
475 | int finalized; /* Has channel been finalized */ |
476 | wait_queue_head_t read_wait; /* Reader buffer-level wait queue */ | |
477 | struct list_head list; /* Stream list */ | |
b3b8072b | 478 | struct lttng_transport *transport; |
9616f0bf | 479 | uint64_t version; /* Current version of the metadata cache */ |
d83004aa JD |
480 | }; |
481 | ||
114667d5 MD |
482 | #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128 |
483 | ||
484 | struct lttng_dynamic_len_stack { | |
485 | size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE]; | |
486 | size_t offset; | |
487 | }; | |
488 | ||
489 | DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack); | |
e0130fab MD |
490 | |
491 | /* | |
492 | * struct lttng_pid_tracker declared in header due to deferencing of *v | |
493 | * in RCU_INITIALIZER(v). | |
494 | */ | |
495 | #define LTTNG_PID_HASH_BITS 6 | |
496 | #define LTTNG_PID_TABLE_SIZE (1 << LTTNG_PID_HASH_BITS) | |
497 | ||
498 | struct lttng_pid_tracker { | |
499 | struct hlist_head pid_hash[LTTNG_PID_TABLE_SIZE]; | |
500 | }; | |
501 | ||
7e6f9ef6 MD |
502 | struct lttng_pid_hash_node { |
503 | struct hlist_node hlist; | |
504 | int pid; | |
505 | }; | |
506 | ||
a90917c3 | 507 | struct lttng_session { |
85a9ca7f | 508 | int active; /* Is trace session active ? */ |
8070f5c0 | 509 | int been_active; /* Has trace session been active ? */ |
85a9ca7f MD |
510 | struct file *file; /* File associated to session */ |
511 | struct list_head chan; /* Channel list head */ | |
512 | struct list_head events; /* Event list head */ | |
513 | struct list_head list; /* Session list */ | |
c099397a | 514 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
d793d5e1 | 515 | uuid_le uuid; /* Trace session unique ID */ |
d83004aa | 516 | struct lttng_metadata_cache *metadata_cache; |
e0130fab | 517 | struct lttng_pid_tracker *pid_tracker; |
3c997079 MD |
518 | unsigned int metadata_dumped:1, |
519 | tstate:1; /* Transient enable state */ | |
520 | /* List of enablers */ | |
521 | struct list_head enablers_head; | |
522 | /* Hash table of events */ | |
523 | struct lttng_event_ht events_ht; | |
e026f97d | 524 | char name[LTTNG_KERNEL_SESSION_NAME_LEN]; |
a9550ab5 | 525 | char creation_time[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN]; |
85a9ca7f MD |
526 | }; |
527 | ||
d83004aa JD |
528 | struct lttng_metadata_cache { |
529 | char *data; /* Metadata cache */ | |
530 | unsigned int cache_alloc; /* Metadata allocated size (bytes) */ | |
531 | unsigned int metadata_written; /* Number of bytes written in metadata cache */ | |
532 | struct kref refcount; /* Metadata cache usage */ | |
533 | struct list_head metadata_stream; /* Metadata stream list */ | |
a36580d5 | 534 | uuid_le uuid; /* Trace session unique ID (copy) */ |
9616f0bf JD |
535 | struct mutex lock; /* Produce/consume lock */ |
536 | uint64_t version; /* Current version of the metadata */ | |
d83004aa JD |
537 | }; |
538 | ||
3c997079 MD |
539 | void lttng_lock_sessions(void); |
540 | void lttng_unlock_sessions(void); | |
541 | ||
542 | struct list_head *lttng_get_probe_list_head(void); | |
543 | ||
544 | struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_type type, | |
545 | struct lttng_kernel_event *event_param, | |
546 | struct lttng_channel *chan); | |
547 | ||
548 | int lttng_enabler_enable(struct lttng_enabler *enabler); | |
549 | int lttng_enabler_disable(struct lttng_enabler *enabler); | |
550 | int lttng_fix_pending_events(void); | |
551 | int lttng_session_active(void); | |
552 | ||
a90917c3 MD |
553 | struct lttng_session *lttng_session_create(void); |
554 | int lttng_session_enable(struct lttng_session *session); | |
555 | int lttng_session_disable(struct lttng_session *session); | |
556 | void lttng_session_destroy(struct lttng_session *session); | |
9616f0bf | 557 | int lttng_session_metadata_regenerate(struct lttng_session *session); |
601252cf | 558 | int lttng_session_statedump(struct lttng_session *session); |
d83004aa | 559 | void metadata_cache_destroy(struct kref *kref); |
4e3c1b9b | 560 | |
a90917c3 | 561 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
5dbbdb43 MD |
562 | const char *transport_name, |
563 | void *buf_addr, | |
564 | size_t subbuf_size, size_t num_subbuf, | |
565 | unsigned int switch_timer_interval, | |
d83004aa JD |
566 | unsigned int read_timer_interval, |
567 | enum channel_type channel_type); | |
a90917c3 | 568 | struct lttng_channel *lttng_global_channel_create(struct lttng_session *session, |
4e3c1b9b MD |
569 | int overwrite, void *buf_addr, |
570 | size_t subbuf_size, size_t num_subbuf, | |
571 | unsigned int switch_timer_interval, | |
572 | unsigned int read_timer_interval); | |
4e3c1b9b | 573 | |
d83004aa | 574 | void lttng_metadata_channel_destroy(struct lttng_channel *chan); |
a90917c3 | 575 | struct lttng_event *lttng_event_create(struct lttng_channel *chan, |
3c997079 MD |
576 | struct lttng_kernel_event *event_param, |
577 | void *filter, | |
578 | const struct lttng_event_desc *event_desc, | |
579 | enum lttng_kernel_instrumentation itype); | |
33a39a3c MD |
580 | struct lttng_event *_lttng_event_create(struct lttng_channel *chan, |
581 | struct lttng_kernel_event *event_param, | |
582 | void *filter, | |
583 | const struct lttng_event_desc *event_desc, | |
584 | enum lttng_kernel_instrumentation itype); | |
6dccd6c1 JD |
585 | struct lttng_event *lttng_event_compat_old_create(struct lttng_channel *chan, |
586 | struct lttng_kernel_old_event *old_event_param, | |
587 | void *filter, | |
588 | const struct lttng_event_desc *internal_desc); | |
c0e31d2e | 589 | |
a90917c3 MD |
590 | int lttng_channel_enable(struct lttng_channel *channel); |
591 | int lttng_channel_disable(struct lttng_channel *channel); | |
592 | int lttng_event_enable(struct lttng_event *event); | |
593 | int lttng_event_disable(struct lttng_event *event); | |
e64957da | 594 | |
a90917c3 MD |
595 | void lttng_transport_register(struct lttng_transport *transport); |
596 | void lttng_transport_unregister(struct lttng_transport *transport); | |
11b5a3c2 | 597 | |
360f38ea | 598 | void synchronize_trace(void); |
80996790 | 599 | int lttng_abi_init(void); |
6dccd6c1 | 600 | int lttng_abi_compat_old_init(void); |
80996790 | 601 | void lttng_abi_exit(void); |
6dccd6c1 | 602 | void lttng_abi_compat_old_exit(void); |
1c25284c | 603 | |
a90917c3 MD |
604 | int lttng_probe_register(struct lttng_probe_desc *desc); |
605 | void lttng_probe_unregister(struct lttng_probe_desc *desc); | |
606 | const struct lttng_event_desc *lttng_event_get(const char *name); | |
607 | void lttng_event_put(const struct lttng_event_desc *desc); | |
608 | int lttng_probes_init(void); | |
609 | void lttng_probes_exit(void); | |
1ec65de1 | 610 | |
b3b8072b MD |
611 | int lttng_metadata_output_channel(struct lttng_metadata_stream *stream, |
612 | struct channel *chan); | |
d83004aa | 613 | |
7e6f9ef6 | 614 | int lttng_pid_tracker_get_node_pid(const struct lttng_pid_hash_node *node); |
e0130fab MD |
615 | struct lttng_pid_tracker *lttng_pid_tracker_create(void); |
616 | void lttng_pid_tracker_destroy(struct lttng_pid_tracker *lpf); | |
617 | bool lttng_pid_tracker_lookup(struct lttng_pid_tracker *lpf, int pid); | |
618 | int lttng_pid_tracker_add(struct lttng_pid_tracker *lpf, int pid); | |
619 | int lttng_pid_tracker_del(struct lttng_pid_tracker *lpf, int pid); | |
620 | ||
621 | int lttng_session_track_pid(struct lttng_session *session, int pid); | |
622 | int lttng_session_untrack_pid(struct lttng_session *session, int pid); | |
623 | ||
7e6f9ef6 MD |
624 | int lttng_session_list_tracker_pids(struct lttng_session *session); |
625 | ||
2754583e MD |
626 | void lttng_clock_ref(void); |
627 | void lttng_clock_unref(void); | |
628 | ||
3a523f5b | 629 | #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS) |
a90917c3 MD |
630 | int lttng_syscalls_register(struct lttng_channel *chan, void *filter); |
631 | int lttng_syscalls_unregister(struct lttng_channel *chan); | |
80f87dd2 MD |
632 | int lttng_syscall_filter_enable(struct lttng_channel *chan, |
633 | const char *name); | |
634 | int lttng_syscall_filter_disable(struct lttng_channel *chan, | |
635 | const char *name); | |
12e579db MD |
636 | long lttng_channel_syscall_mask(struct lttng_channel *channel, |
637 | struct lttng_kernel_syscall_mask __user *usyscall_mask); | |
1ec65de1 | 638 | #else |
a90917c3 | 639 | static inline int lttng_syscalls_register(struct lttng_channel *chan, void *filter) |
1ec65de1 MD |
640 | { |
641 | return -ENOSYS; | |
642 | } | |
643 | ||
a90917c3 | 644 | static inline int lttng_syscalls_unregister(struct lttng_channel *chan) |
1ec65de1 MD |
645 | { |
646 | return 0; | |
647 | } | |
80f87dd2 | 648 | |
f127e61e | 649 | static inline int lttng_syscall_filter_enable(struct lttng_channel *chan, |
80f87dd2 MD |
650 | const char *name) |
651 | { | |
652 | return -ENOSYS; | |
653 | } | |
654 | ||
f127e61e | 655 | static inline int lttng_syscall_filter_disable(struct lttng_channel *chan, |
80f87dd2 MD |
656 | const char *name) |
657 | { | |
658 | return -ENOSYS; | |
659 | } | |
12e579db | 660 | |
f127e61e | 661 | static inline long lttng_channel_syscall_mask(struct lttng_channel *channel, |
12e579db MD |
662 | struct lttng_kernel_syscall_mask __user *usyscall_mask) |
663 | { | |
664 | return -ENOSYS; | |
665 | } | |
1ec65de1 MD |
666 | #endif |
667 | ||
07dfc1d0 MD |
668 | void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime); |
669 | int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, | |
670 | struct lttng_kernel_filter_bytecode __user *bytecode); | |
f127e61e MD |
671 | void lttng_enabler_event_link_bytecode(struct lttng_event *event, |
672 | struct lttng_enabler *enabler); | |
07dfc1d0 | 673 | |
114667d5 MD |
674 | int lttng_probes_init(void); |
675 | ||
07dfc1d0 MD |
676 | extern struct lttng_ctx *lttng_static_ctx; |
677 | ||
678 | int lttng_context_init(void); | |
679 | void lttng_context_exit(void); | |
2dccf128 | 680 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); |
a9dd15da | 681 | void lttng_context_update(struct lttng_ctx *ctx); |
44252f0f | 682 | int lttng_find_context(struct lttng_ctx *ctx, const char *name); |
07dfc1d0 | 683 | int lttng_get_context_index(struct lttng_ctx *ctx, const char *name); |
8289661d MD |
684 | void lttng_remove_context_field(struct lttng_ctx **ctx, |
685 | struct lttng_ctx_field *field); | |
2dccf128 | 686 | void lttng_destroy_context(struct lttng_ctx *ctx); |
8070f5c0 | 687 | int lttng_add_pid_to_ctx(struct lttng_ctx **ctx); |
b3699d90 | 688 | int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx); |
a2563e83 | 689 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); |
a8ad3613 | 690 | int lttng_add_prio_to_ctx(struct lttng_ctx **ctx); |
53f1f0ca | 691 | int lttng_add_nice_to_ctx(struct lttng_ctx **ctx); |
b64bc438 MD |
692 | int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); |
693 | int lttng_add_tid_to_ctx(struct lttng_ctx **ctx); | |
694 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); | |
695 | int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx); | |
696 | int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx); | |
975da2c0 | 697 | int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx); |
79150a49 JD |
698 | int lttng_add_interruptible_to_ctx(struct lttng_ctx **ctx); |
699 | int lttng_add_need_reschedule_to_ctx(struct lttng_ctx **ctx); | |
700 | #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT) | |
701 | int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx); | |
702 | #else | |
703 | static inline | |
704 | int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx) | |
705 | { | |
706 | return -ENOSYS; | |
707 | } | |
708 | #endif | |
709 | #ifdef CONFIG_PREEMPT_RT_FULL | |
710 | int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx); | |
711 | #else | |
712 | static inline | |
713 | int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx) | |
714 | { | |
715 | return -ENOSYS; | |
716 | } | |
717 | #endif | |
2fa2d39a FG |
718 | |
719 | int lttng_add_callstack_to_ctx(struct lttng_ctx **ctx, int type); | |
720 | ||
41c3c24e | 721 | #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) |
c24a0d71 MD |
722 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
723 | uint64_t config, | |
724 | const char *name, | |
725 | struct lttng_ctx **ctx); | |
1e367326 MD |
726 | int lttng_cpuhp_perf_counter_online(unsigned int cpu, |
727 | struct lttng_cpuhp_node *node); | |
728 | int lttng_cpuhp_perf_counter_dead(unsigned int cpu, | |
729 | struct lttng_cpuhp_node *node); | |
1d443b34 MD |
730 | #else |
731 | static inline | |
732 | int lttng_add_perf_counter_to_ctx(uint32_t type, | |
733 | uint64_t config, | |
734 | const char *name, | |
735 | struct lttng_ctx **ctx) | |
736 | { | |
737 | return -ENOSYS; | |
738 | } | |
1e367326 MD |
739 | static inline |
740 | int lttng_cpuhp_perf_counter_online(unsigned int cpu, | |
741 | struct lttng_cpuhp_node *node) | |
742 | { | |
743 | return 0; | |
744 | } | |
745 | static inline | |
746 | int lttng_cpuhp_perf_counter_dead(unsigned int cpu, | |
747 | struct lttng_cpuhp_node *node) | |
748 | { | |
749 | return 0; | |
750 | } | |
1d443b34 | 751 | #endif |
02119ee5 | 752 | |
0c956676 MD |
753 | int lttng_logger_init(void); |
754 | void lttng_logger_exit(void); | |
755 | ||
c337ddc2 MD |
756 | extern int lttng_statedump_start(struct lttng_session *session); |
757 | ||
acd614cc | 758 | #ifdef CONFIG_KPROBES |
f17701fb MD |
759 | int lttng_kprobes_register(const char *name, |
760 | const char *symbol_name, | |
761 | uint64_t offset, | |
762 | uint64_t addr, | |
a90917c3 MD |
763 | struct lttng_event *event); |
764 | void lttng_kprobes_unregister(struct lttng_event *event); | |
765 | void lttng_kprobes_destroy_private(struct lttng_event *event); | |
acd614cc MD |
766 | #else |
767 | static inline | |
768 | int lttng_kprobes_register(const char *name, | |
769 | const char *symbol_name, | |
770 | uint64_t offset, | |
771 | uint64_t addr, | |
a90917c3 | 772 | struct lttng_event *event) |
acd614cc MD |
773 | { |
774 | return -ENOSYS; | |
775 | } | |
776 | ||
25f53c39 | 777 | static inline |
a90917c3 | 778 | void lttng_kprobes_unregister(struct lttng_event *event) |
acd614cc MD |
779 | { |
780 | } | |
edeb3137 MD |
781 | |
782 | static inline | |
a90917c3 | 783 | void lttng_kprobes_destroy_private(struct lttng_event *event) |
edeb3137 MD |
784 | { |
785 | } | |
acd614cc | 786 | #endif |
d6d808f3 | 787 | |
3aed4dca FD |
788 | int lttng_event_add_callsite(struct lttng_event *event, |
789 | struct lttng_kernel_event_callsite *callsite); | |
e33fc900 | 790 | |
149b9a9d YB |
791 | #ifdef CONFIG_UPROBES |
792 | int lttng_uprobes_register(const char *name, | |
3aed4dca FD |
793 | int fd, struct lttng_event *event); |
794 | int lttng_uprobes_add_callsite(struct lttng_event *event, | |
795 | struct lttng_kernel_event_callsite *callsite); | |
149b9a9d YB |
796 | void lttng_uprobes_unregister(struct lttng_event *event); |
797 | void lttng_uprobes_destroy_private(struct lttng_event *event); | |
798 | #else | |
799 | static inline | |
800 | int lttng_uprobes_register(const char *name, | |
3aed4dca FD |
801 | int fd, struct lttng_event *event) |
802 | { | |
803 | return -ENOSYS; | |
804 | } | |
805 | ||
806 | static inline | |
807 | int lttng_uprobes_add_callsite(struct lttng_event *event, | |
e33fc900 | 808 | struct lttng_kernel_event_callsite *callsite) |
149b9a9d YB |
809 | { |
810 | return -ENOSYS; | |
811 | } | |
812 | ||
813 | static inline | |
814 | void lttng_uprobes_unregister(struct lttng_event *event) | |
815 | { | |
816 | } | |
817 | ||
818 | static inline | |
819 | void lttng_uprobes_destroy_private(struct lttng_event *event) | |
820 | { | |
821 | } | |
822 | #endif | |
823 | ||
7371f44c MD |
824 | #ifdef CONFIG_KRETPROBES |
825 | int lttng_kretprobes_register(const char *name, | |
826 | const char *symbol_name, | |
827 | uint64_t offset, | |
828 | uint64_t addr, | |
a90917c3 MD |
829 | struct lttng_event *event_entry, |
830 | struct lttng_event *event_exit); | |
831 | void lttng_kretprobes_unregister(struct lttng_event *event); | |
832 | void lttng_kretprobes_destroy_private(struct lttng_event *event); | |
a0493bef MD |
833 | int lttng_kretprobes_event_enable_state(struct lttng_event *event, |
834 | int enable); | |
7371f44c MD |
835 | #else |
836 | static inline | |
837 | int lttng_kretprobes_register(const char *name, | |
838 | const char *symbol_name, | |
839 | uint64_t offset, | |
840 | uint64_t addr, | |
a90917c3 MD |
841 | struct lttng_event *event_entry, |
842 | struct lttng_event *event_exit) | |
7371f44c MD |
843 | { |
844 | return -ENOSYS; | |
845 | } | |
846 | ||
847 | static inline | |
a90917c3 | 848 | void lttng_kretprobes_unregister(struct lttng_event *event) |
7371f44c MD |
849 | { |
850 | } | |
851 | ||
852 | static inline | |
a90917c3 | 853 | void lttng_kretprobes_destroy_private(struct lttng_event *event) |
7371f44c MD |
854 | { |
855 | } | |
a0493bef MD |
856 | |
857 | static inline | |
858 | int lttng_kretprobes_event_enable_state(struct lttng_event *event, | |
859 | int enable) | |
860 | { | |
861 | return -ENOSYS; | |
862 | } | |
7371f44c MD |
863 | #endif |
864 | ||
f61d99f9 | 865 | #if defined(CONFIG_DYNAMIC_FTRACE) && !defined(LTTNG_FTRACE_MISSING_HEADER) |
e0a7a7c4 MD |
866 | int lttng_ftrace_register(const char *name, |
867 | const char *symbol_name, | |
a90917c3 MD |
868 | struct lttng_event *event); |
869 | void lttng_ftrace_unregister(struct lttng_event *event); | |
870 | void lttng_ftrace_destroy_private(struct lttng_event *event); | |
e0a7a7c4 MD |
871 | #else |
872 | static inline | |
873 | int lttng_ftrace_register(const char *name, | |
874 | const char *symbol_name, | |
a90917c3 | 875 | struct lttng_event *event) |
e0a7a7c4 | 876 | { |
acd614cc | 877 | return -ENOSYS; |
e0a7a7c4 MD |
878 | } |
879 | ||
880 | static inline | |
a90917c3 | 881 | void lttng_ftrace_unregister(struct lttng_event *event) |
e0a7a7c4 MD |
882 | { |
883 | } | |
edeb3137 MD |
884 | |
885 | static inline | |
a90917c3 | 886 | void lttng_ftrace_destroy_private(struct lttng_event *event) |
edeb3137 MD |
887 | { |
888 | } | |
e0a7a7c4 | 889 | #endif |
271b6681 | 890 | |
3db41b2c | 891 | int lttng_calibrate(struct lttng_kernel_calibrate *calibrate); |
57105fc2 | 892 | |
271b6681 | 893 | extern const struct file_operations lttng_tracepoint_list_fops; |
2d2464bd | 894 | extern const struct file_operations lttng_syscall_list_fops; |
271b6681 | 895 | |
ef200626 MD |
896 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
897 | #define TRACEPOINT_HAS_DATA_ARG | |
898 | #endif | |
899 | ||
a90917c3 | 900 | #endif /* _LTTNG_EVENTS_H */ |