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