Cleanup: implement dedicated file operations for events and enablers
[lttng-modules.git] / include / lttng / events.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng/events.h
4 *
5 * Holds LTTng per-session event registry.
6 *
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #ifndef _LTTNG_EVENTS_H
11 #define _LTTNG_EVENTS_H
12
13 #include <lttng/kernel-version.h>
14 #include <linux/list.h>
15 #include <linux/kprobes.h>
16 #include <linux/kref.h>
17 #include <linux/uuid.h>
18 #include <linux/irq_work.h>
19 #include <wrapper/uprobes.h>
20 #include <lttng/cpuhotplug.h>
21 #include <lttng/tracer.h>
22 #include <lttng/abi.h>
23 #include <lttng/abi-old.h>
24 #include <lttng/endian.h>
25
26 #define lttng_is_signed_type(type) (((type) -1) < (type) 1)
27
28 struct lttng_channel;
29 struct lttng_session;
30 struct lttng_metadata_cache;
31 struct lib_ring_buffer_ctx;
32 struct perf_event;
33 struct perf_event_attr;
34 struct lib_ring_buffer_config;
35
36 /* Type description */
37
38 enum lttng_kernel_type {
39 lttng_kernel_type_integer,
40 lttng_kernel_type_string,
41 lttng_kernel_type_enum,
42 lttng_kernel_type_array,
43 lttng_kernel_type_sequence,
44 lttng_kernel_type_struct,
45 lttng_kernel_type_variant,
46 NR_LTTNG_KERNEL_TYPES,
47 };
48
49 enum lttng_kernel_string_encoding {
50 lttng_kernel_string_encoding_none = 0,
51 lttng_kernel_string_encoding_UTF8 = 1,
52 lttng_kernel_string_encoding_ASCII = 2,
53 NR_LTTNG_KERNEL_STRING_ENCODING,
54 };
55
56 enum channel_type {
57 PER_CPU_CHANNEL,
58 METADATA_CHANNEL,
59 };
60
61 struct lttng_kernel_enum_value {
62 unsigned long long value;
63 unsigned int signedness:1;
64 };
65
66 struct lttng_kernel_enum_entry {
67 struct lttng_kernel_enum_value start, end; /* start and end are inclusive */
68 const char *string;
69 struct {
70 unsigned int is_auto:1;
71 } options;
72 };
73
74 /*
75 * struct lttng_kernel_type_common is fixed-size. Its children inherits
76 * from it by embedding struct lttng_kernel_type_common as its first field.
77 */
78 struct lttng_kernel_type_common {
79 enum lttng_kernel_type type;
80 };
81
82 struct lttng_kernel_type_integer {
83 struct lttng_kernel_type_common parent;
84 unsigned int size; /* in bits */
85 unsigned short alignment; /* in bits */
86 unsigned int signedness:1,
87 reverse_byte_order:1;
88 unsigned int base; /* 2, 8, 10, 16, for pretty print */
89 };
90
91 struct lttng_kernel_type_string {
92 struct lttng_kernel_type_common parent;
93 enum lttng_kernel_string_encoding encoding;
94 };
95
96 struct lttng_kernel_type_enum {
97 struct lttng_kernel_type_common parent;
98 const struct lttng_kernel_enum_desc *desc; /* Enumeration mapping */
99 const struct lttng_kernel_type_common *container_type;
100 };
101
102 struct lttng_kernel_type_array {
103 struct lttng_kernel_type_common parent;
104 const struct lttng_kernel_type_common *elem_type;
105 unsigned int length; /* Num. elems. */
106 unsigned int alignment;
107 enum lttng_kernel_string_encoding encoding;
108 };
109
110 struct lttng_kernel_type_sequence {
111 struct lttng_kernel_type_common parent;
112 const char *length_name; /* Length field name. */
113 const struct lttng_kernel_type_common *elem_type;
114 unsigned int alignment; /* Alignment before elements. */
115 enum lttng_kernel_string_encoding encoding;
116 };
117
118 struct lttng_kernel_type_struct {
119 struct lttng_kernel_type_common parent;
120 unsigned int nr_fields;
121 const struct lttng_kernel_event_field **fields; /* Array of pointers to fields. */
122 unsigned int alignment;
123 };
124
125 struct lttng_kernel_type_variant {
126 struct lttng_kernel_type_common parent;
127 const char *tag_name;
128 const struct lttng_kernel_event_field **choices; /* Array of pointers to fields. */
129 unsigned int nr_choices;
130 unsigned int alignment;
131 };
132
133 struct lttng_kernel_enum_desc {
134 const char *name;
135 const struct lttng_kernel_enum_entry **entries;
136 unsigned int nr_entries;
137 };
138
139 /* Event field description */
140
141 struct lttng_kernel_event_field {
142 const char *name;
143 const struct lttng_kernel_type_common *type;
144 unsigned int nowrite:1, /* do not write into trace */
145 user:1, /* fetch from user-space */
146 nofilter:1; /* do not consider for filter */
147 };
148
149 #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
150 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
151 .parent = { \
152 .type = lttng_kernel_type_integer, \
153 }, \
154 .size = (_size), \
155 .alignment = (_alignment), \
156 .signedness = (_signedness), \
157 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
158 .base = (_base), \
159 }))
160
161 #define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
162 lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
163 lttng_alignof(_type) * CHAR_BIT, \
164 lttng_is_signed_type(_type), \
165 _byte_order, \
166 _base)
167
168 #define lttng_kernel_static_type_enum(_desc, _container_type) \
169 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
170 .parent = { \
171 .type = lttng_kernel_type_enum, \
172 }, \
173 .desc = (_desc), \
174 .container_type = (_container_type), \
175 }))
176
177 #define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
178 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
179 .parent = { \
180 .type = lttng_kernel_type_array, \
181 }, \
182 .length = (_length), \
183 .alignment = (_alignment), \
184 .encoding = lttng_kernel_string_encoding_##_encoding, \
185 .elem_type = (_elem_type), \
186 }))
187
188 #define lttng_kernel_static_type_array_text(_length) \
189 lttng_kernel_static_type_array(_length, \
190 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
191 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
192 __BYTE_ORDER, 10), \
193 0, UTF8)
194
195 #define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
196 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
197 .parent = { \
198 .type = lttng_kernel_type_sequence, \
199 }, \
200 .length_name = (_length_name), \
201 .alignment = (_alignment), \
202 .encoding = lttng_kernel_string_encoding_##_encoding, \
203 .elem_type = (_elem_type), \
204 }))
205
206 #define lttng_kernel_static_type_string(_encoding) \
207 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
208 .parent = { \
209 .type = lttng_kernel_type_string, \
210 }, \
211 .encoding = lttng_kernel_string_encoding_##_encoding, \
212 }))
213
214 #define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
215 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, { \
216 .parent = { \
217 .type = lttng_kernel_type_struct, \
218 }, \
219 .nr_fields = (_nr_fields), \
220 .fields = _fields, \
221 .alignment = (_alignment), \
222 }))
223
224 #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
225 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
226 .parent = { \
227 .type = lttng_kernel_type_variant, \
228 }, \
229 .tag_name = (_tag_name), \
230 .choices = _choices, \
231 .nr_choices = (_nr_choices), \
232 .alignment = (_alignment), \
233 }))
234
235 #define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \
236 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
237 .name = (_name), \
238 .type = (_type), \
239 .nowrite = (_nowrite), \
240 .user = (_user), \
241 .nofilter = (_nofilter), \
242 })
243
244 #define lttng_kernel_static_event_field_array(_fields...) \
245 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
246 _fields \
247 )
248
249 #define lttng_kernel_static_ctx_field(_event_field, _get_size, _get_size_arg, _record, _get_value, _destroy, _priv) \
250 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
251 .event_field = (_event_field), \
252 .get_size = (_get_size), \
253 .get_size_arg = (_get_size_arg), \
254 .record = (_record), \
255 .get_value = (_get_value), \
256 .destroy = (_destroy), \
257 .priv = (_priv), \
258 })
259
260 #define lttng_kernel_static_enum_entry_value(_string, _value) \
261 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
262 .start = { \
263 .signedness = lttng_is_signed_type(__typeof__(_value)), \
264 .value = lttng_is_signed_type(__typeof__(_value)) ? \
265 (long long) (_value) : (_value), \
266 }, \
267 .end = { \
268 .signedness = lttng_is_signed_type(__typeof__(_value)), \
269 .value = lttng_is_signed_type(__typeof__(_value)) ? \
270 (long long) (_value) : (_value), \
271 }, \
272 .string = (_string), \
273 }),
274
275 #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
276 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
277 .start = { \
278 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
279 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
280 (long long) (_range_start) : (_range_start), \
281 }, \
282 .end = { \
283 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
284 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
285 (long long) (_range_end) : (_range_end), \
286 }, \
287 .string = (_string), \
288 }),
289
290 #define lttng_kernel_static_enum_entry_auto(_string) \
291 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
292 .start = { \
293 .signedness = -1, \
294 .value = -1, \
295 }, \
296 .end = { \
297 .signedness = -1, \
298 .value = -1, \
299 }, \
300 .string = (_string), \
301 .options = { \
302 .is_auto = 1, \
303 } \
304 }),
305
306 union lttng_ctx_value {
307 int64_t s64;
308 const char *str;
309 double d;
310 };
311
312 /*
313 * We need to keep this perf counter field separately from struct
314 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
315 */
316 struct lttng_perf_counter_field {
317 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
318 struct lttng_cpuhp_node cpuhp_prepare;
319 struct lttng_cpuhp_node cpuhp_online;
320 #else
321 struct notifier_block nb;
322 int hp_enable;
323 #endif
324 struct perf_event_attr *attr;
325 struct perf_event **e; /* per-cpu array */
326 char *name;
327 struct lttng_kernel_event_field *event_field;
328 };
329
330 struct lttng_probe_ctx {
331 struct lttng_event *event;
332 struct lttng_event_notifier *event_notifier; // Not sure if we will ever need it.
333 uint8_t interruptible;
334 };
335
336 struct lttng_kernel_ctx_field {
337 const struct lttng_kernel_event_field *event_field;
338 size_t (*get_size)(size_t offset);
339 size_t (*get_size_arg)(size_t offset, struct lttng_kernel_ctx_field *field,
340 struct lib_ring_buffer_ctx *ctx,
341 struct lttng_channel *chan);
342 void (*record)(struct lttng_kernel_ctx_field *field,
343 struct lib_ring_buffer_ctx *ctx,
344 struct lttng_channel *chan);
345 void (*get_value)(struct lttng_kernel_ctx_field *field,
346 struct lttng_probe_ctx *lttng_probe_ctx,
347 union lttng_ctx_value *value);
348 void (*destroy)(struct lttng_kernel_ctx_field *field);
349 void *priv;
350 };
351
352 struct lttng_kernel_ctx {
353 struct lttng_kernel_ctx_field *fields;
354 unsigned int nr_fields;
355 unsigned int allocated_fields;
356 size_t largest_align; /* in bytes */
357 };
358
359 struct lttng_kernel_event_desc {
360 const char *event_name; /* lttng-modules name */
361 const char *event_kname; /* Linux kernel name (tracepoints) */
362 const struct lttng_kernel_probe_desc *probe_desc;
363 void (*probe_callback)(void);
364 const struct lttng_kernel_event_field **fields; /* event payload */
365 unsigned int nr_fields;
366 struct module *owner;
367 void *event_notifier_callback;
368 };
369
370 struct lttng_kernel_probe_desc {
371 const char *provider_name;
372 const struct lttng_kernel_event_desc **event_desc;
373 unsigned int nr_events;
374 struct list_head head; /* chain registered probes */
375 struct list_head lazy_init_head;
376 int lazy; /* lazy registration */
377 };
378
379 struct lttng_krp; /* Kretprobe handling */
380
381 enum lttng_bytecode_node_type {
382 LTTNG_BYTECODE_NODE_TYPE_FILTER,
383 LTTNG_BYTECODE_NODE_TYPE_CAPTURE,
384 };
385
386 struct lttng_bytecode_node {
387 enum lttng_bytecode_node_type type;
388 struct list_head node;
389 struct lttng_enabler *enabler;
390 struct {
391 uint32_t len;
392 uint32_t reloc_offset;
393 uint64_t seqnum;
394 char data[];
395 } bc;
396 };
397
398 /*
399 * Bytecode interpreter return value masks.
400 */
401 enum lttng_bytecode_interpreter_ret {
402 LTTNG_INTERPRETER_DISCARD = 0,
403 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
404 /* Other bits are kept for future use. */
405 };
406
407 struct lttng_interpreter_output;
408
409 struct lttng_bytecode_runtime {
410 /* Associated bytecode */
411 struct lttng_bytecode_node *bc;
412 union {
413 uint64_t (*filter)(void *filter_data,
414 struct lttng_probe_ctx *lttng_probe_ctx,
415 const char *filter_stack_data);
416 uint64_t (*capture)(void *filter_data,
417 struct lttng_probe_ctx *lttng_probe_ctx,
418 const char *capture_stack_data,
419 struct lttng_interpreter_output *output);
420 } interpreter_funcs;
421 int link_failed;
422 struct list_head node; /* list of bytecode runtime in event */
423 struct lttng_kernel_ctx *ctx;
424 };
425
426 /*
427 * Objects in a linked-list of enablers, owned by an event.
428 */
429 struct lttng_enabler_ref {
430 struct list_head node; /* enabler ref list */
431 struct lttng_enabler *ref; /* backward ref */
432 };
433
434 struct lttng_uprobe_handler {
435 union {
436 struct lttng_event *event;
437 struct lttng_event_notifier *event_notifier;
438 } u;
439 loff_t offset;
440 struct uprobe_consumer up_consumer;
441 struct list_head node;
442 };
443
444 struct lttng_kprobe {
445 struct kprobe kp;
446 char *symbol_name;
447 };
448
449 struct lttng_uprobe {
450 struct inode *inode;
451 struct list_head head;
452 };
453
454 enum lttng_syscall_entryexit {
455 LTTNG_SYSCALL_ENTRY,
456 LTTNG_SYSCALL_EXIT,
457 };
458
459 enum lttng_syscall_abi {
460 LTTNG_SYSCALL_ABI_NATIVE,
461 LTTNG_SYSCALL_ABI_COMPAT,
462 };
463
464 /*
465 * lttng_event structure is referred to by the tracing fast path. It must be
466 * kept small.
467 */
468 struct lttng_event {
469 unsigned int id;
470 struct lttng_channel *chan;
471 int enabled;
472 const struct lttng_kernel_event_desc *desc;
473 void *filter;
474 struct lttng_kernel_ctx *ctx;
475 enum lttng_kernel_abi_instrumentation instrumentation;
476 union {
477 struct lttng_kprobe kprobe;
478 struct {
479 struct lttng_krp *lttng_krp;
480 char *symbol_name;
481 } kretprobe;
482 struct lttng_uprobe uprobe;
483 struct {
484 enum lttng_syscall_entryexit entryexit;
485 enum lttng_syscall_abi abi;
486 struct hlist_node node; /* chain registered syscall event */
487 } syscall;
488 } u;
489 struct list_head list; /* Event list in session */
490 unsigned int metadata_dumped:1;
491
492 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
493 struct list_head enablers_ref_head;
494 struct hlist_node hlist; /* session ht of events */
495 int registered; /* has reg'd tracepoint probe */
496 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
497 struct list_head filter_bytecode_runtime_head;
498 int has_enablers_without_bytecode;
499 };
500
501 struct lttng_kernel_notifier_ctx {
502 int eval_capture;
503 };
504
505 // FIXME: Really similar to lttng_event above. Could those be merged ?
506 struct lttng_event_notifier {
507 uint64_t user_token;
508 uint64_t error_counter_index;
509 int enabled;
510 int registered; /* has reg'd tracepoint probe */
511 const struct lttng_kernel_event_desc *desc;
512 void *filter;
513 struct list_head list; /* event_notifier list in event_notifier group */
514
515 enum lttng_kernel_abi_instrumentation instrumentation;
516 union {
517 struct lttng_kprobe kprobe;
518 struct lttng_uprobe uprobe;
519 struct {
520 enum lttng_syscall_entryexit entryexit;
521 enum lttng_syscall_abi abi;
522 struct hlist_node node; /* chain registered syscall event_notifier */
523 unsigned int syscall_id;
524 } syscall;
525
526 } u;
527
528 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
529 struct list_head enablers_ref_head;
530 struct hlist_node hlist; /* session ht of event_notifiers */
531 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
532 struct list_head filter_bytecode_runtime_head;
533 size_t num_captures;
534 struct list_head capture_bytecode_runtime_head;
535 int has_enablers_without_bytecode;
536 int eval_capture; /* Should evaluate capture */
537
538 void (*send_notification)(struct lttng_event_notifier *event_notifier,
539 struct lttng_probe_ctx *lttng_probe_ctx,
540 const char *interpreter_stack_data,
541 struct lttng_kernel_notifier_ctx *notif_ctx);
542 struct lttng_event_notifier_group *group; /* Weak ref */
543 };
544
545 enum lttng_enabler_format_type {
546 LTTNG_ENABLER_FORMAT_STAR_GLOB,
547 LTTNG_ENABLER_FORMAT_NAME,
548 };
549
550 /*
551 * Enabler field, within whatever object is enabling an event. Target of
552 * backward reference.
553 */
554 struct lttng_enabler {
555 enum lttng_enabler_format_type format_type;
556
557 /* head list of struct lttng_bytecode_node */
558 struct list_head filter_bytecode_head;
559
560 struct lttng_kernel_abi_event event_param;
561 unsigned int enabled:1;
562
563 uint64_t user_token; /* User-provided token. */
564 };
565
566 struct lttng_event_enabler {
567 struct lttng_enabler base;
568 struct list_head node; /* per-session list of enablers */
569 struct lttng_channel *chan;
570 /*
571 * Unused, but kept around to make it explicit that the tracer can do
572 * it.
573 */
574 struct lttng_kernel_ctx *ctx;
575 };
576
577 struct lttng_event_notifier_enabler {
578 struct lttng_enabler base;
579 uint64_t error_counter_index;
580 struct list_head node; /* List of event_notifier enablers */
581 struct lttng_event_notifier_group *group;
582
583 /* head list of struct lttng_bytecode_node */
584 struct list_head capture_bytecode_head;
585 uint64_t num_captures;
586 };
587
588
589 static inline
590 struct lttng_enabler *lttng_event_enabler_as_enabler(
591 struct lttng_event_enabler *event_enabler)
592 {
593 return &event_enabler->base;
594 }
595
596 static inline
597 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
598 struct lttng_event_notifier_enabler *event_notifier_enabler)
599 {
600 return &event_notifier_enabler->base;
601 }
602
603 struct lttng_channel_ops {
604 struct channel *(*channel_create)(const char *name,
605 void *priv,
606 void *buf_addr,
607 size_t subbuf_size, size_t num_subbuf,
608 unsigned int switch_timer_interval,
609 unsigned int read_timer_interval);
610 void (*channel_destroy)(struct channel *chan);
611 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
612 int (*buffer_has_read_closed_stream)(struct channel *chan);
613 void (*buffer_read_close)(struct lib_ring_buffer *buf);
614 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
615 uint32_t event_id);
616 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
617 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
618 size_t len);
619 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
620 const void *src, size_t len);
621 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
622 int c, size_t len);
623 void (*event_strcpy)(struct lib_ring_buffer_ctx *ctx, const char *src,
624 size_t len);
625 void (*event_strcpy_from_user)(struct lib_ring_buffer_ctx *ctx,
626 const char __user *src, size_t len);
627 /*
628 * packet_avail_size returns the available size in the current
629 * packet. Note that the size returned is only a hint, since it
630 * may change due to concurrent writes.
631 */
632 size_t (*packet_avail_size)(struct channel *chan);
633 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
634 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
635 int (*is_finalized)(struct channel *chan);
636 int (*is_disabled)(struct channel *chan);
637 int (*timestamp_begin) (const struct lib_ring_buffer_config *config,
638 struct lib_ring_buffer *bufb,
639 uint64_t *timestamp_begin);
640 int (*timestamp_end) (const struct lib_ring_buffer_config *config,
641 struct lib_ring_buffer *bufb,
642 uint64_t *timestamp_end);
643 int (*events_discarded) (const struct lib_ring_buffer_config *config,
644 struct lib_ring_buffer *bufb,
645 uint64_t *events_discarded);
646 int (*content_size) (const struct lib_ring_buffer_config *config,
647 struct lib_ring_buffer *bufb,
648 uint64_t *content_size);
649 int (*packet_size) (const struct lib_ring_buffer_config *config,
650 struct lib_ring_buffer *bufb,
651 uint64_t *packet_size);
652 int (*stream_id) (const struct lib_ring_buffer_config *config,
653 struct lib_ring_buffer *bufb,
654 uint64_t *stream_id);
655 int (*current_timestamp) (const struct lib_ring_buffer_config *config,
656 struct lib_ring_buffer *bufb,
657 uint64_t *ts);
658 int (*sequence_number) (const struct lib_ring_buffer_config *config,
659 struct lib_ring_buffer *bufb,
660 uint64_t *seq);
661 int (*instance_id) (const struct lib_ring_buffer_config *config,
662 struct lib_ring_buffer *bufb,
663 uint64_t *id);
664 };
665
666 struct lttng_counter_ops {
667 struct lib_counter *(*counter_create)(size_t nr_dimensions,
668 const size_t *max_nr_elem, /* for each dimension */
669 int64_t global_sum_step);
670 void (*counter_destroy)(struct lib_counter *counter);
671 int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes,
672 int64_t v);
673 /*
674 * counter_read reads a specific cpu's counter if @cpu >= 0, or
675 * the global aggregation counter if @cpu == -1.
676 */
677 int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
678 int64_t *value, bool *overflow, bool *underflow);
679 /*
680 * counter_aggregate returns the total sum of all per-cpu counters and
681 * the global aggregation counter.
682 */
683 int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes,
684 int64_t *value, bool *overflow, bool *underflow);
685 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
686 };
687
688 struct lttng_transport {
689 char *name;
690 struct module *owner;
691 struct list_head node;
692 struct lttng_channel_ops ops;
693 };
694
695 struct lttng_counter_transport {
696 char *name;
697 struct module *owner;
698 struct list_head node;
699 struct lttng_counter_ops ops;
700 };
701
702 struct lttng_syscall_filter;
703
704 #define LTTNG_EVENT_HT_BITS 12
705 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
706
707 struct lttng_event_ht {
708 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
709 };
710
711 #define LTTNG_EVENT_NOTIFIER_HT_BITS 12
712 #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
713
714 struct lttng_event_notifier_ht {
715 struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE];
716 };
717
718 struct lttng_channel {
719 unsigned int id;
720 struct channel *chan; /* Channel buffers */
721 int enabled;
722 struct lttng_kernel_ctx *ctx;
723 /* Event ID management */
724 struct lttng_session *session;
725 struct file *file; /* File associated to channel */
726 unsigned int free_event_id; /* Next event ID to allocate */
727 struct list_head list; /* Channel list */
728 struct lttng_channel_ops *ops;
729 struct lttng_transport *transport;
730 struct hlist_head *sc_table; /* for syscall tracing */
731 struct hlist_head *compat_sc_table;
732 struct hlist_head *sc_exit_table; /* for syscall exit tracing */
733 struct hlist_head *compat_sc_exit_table;
734 struct hlist_head sc_unknown; /* for unknown syscalls */
735 struct hlist_head sc_compat_unknown;
736 struct hlist_head sc_exit_unknown;
737 struct hlist_head compat_sc_exit_unknown;
738 struct lttng_syscall_filter *sc_filter;
739 int header_type; /* 0: unset, 1: compact, 2: large */
740 enum channel_type channel_type;
741 int syscall_all_entry;
742 int syscall_all_exit;
743 unsigned int metadata_dumped:1,
744 sys_enter_registered:1,
745 sys_exit_registered:1,
746 tstate:1; /* Transient enable state */
747 };
748
749 struct lttng_metadata_stream {
750 void *priv; /* Ring buffer private data */
751 struct lttng_metadata_cache *metadata_cache;
752 unsigned int metadata_in; /* Bytes read from the cache */
753 unsigned int metadata_out; /* Bytes consumed from stream */
754 int finalized; /* Has channel been finalized */
755 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
756 struct list_head list; /* Stream list */
757 struct lttng_transport *transport;
758 uint64_t version; /* Current version of the metadata cache */
759 bool coherent; /* Stream in a coherent state */
760 };
761
762 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
763
764 struct lttng_dynamic_len_stack {
765 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
766 size_t offset;
767 };
768
769 DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
770
771 /*
772 * struct lttng_id_tracker declared in header due to deferencing of *v
773 * in RCU_INITIALIZER(v).
774 */
775 #define LTTNG_ID_HASH_BITS 6
776 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
777
778 enum tracker_type {
779 TRACKER_PID,
780 TRACKER_VPID,
781 TRACKER_UID,
782 TRACKER_VUID,
783 TRACKER_GID,
784 TRACKER_VGID,
785
786 TRACKER_UNKNOWN,
787 };
788
789 struct lttng_id_tracker_rcu {
790 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
791 };
792
793 struct lttng_id_tracker {
794 struct lttng_session *session;
795 enum tracker_type tracker_type;
796 struct lttng_id_tracker_rcu *p; /* RCU dereferenced. */
797 };
798
799 struct lttng_id_hash_node {
800 struct hlist_node hlist;
801 int id;
802 };
803
804 struct lttng_session {
805 int active; /* Is trace session active ? */
806 int been_active; /* Has trace session been active ? */
807 struct file *file; /* File associated to session */
808 struct list_head chan; /* Channel list head */
809 struct list_head events; /* Event list head */
810 struct list_head list; /* Session list */
811 unsigned int free_chan_id; /* Next chan ID to allocate */
812 uuid_le uuid; /* Trace session unique ID */
813 struct lttng_metadata_cache *metadata_cache;
814 struct lttng_id_tracker pid_tracker;
815 struct lttng_id_tracker vpid_tracker;
816 struct lttng_id_tracker uid_tracker;
817 struct lttng_id_tracker vuid_tracker;
818 struct lttng_id_tracker gid_tracker;
819 struct lttng_id_tracker vgid_tracker;
820 unsigned int metadata_dumped:1,
821 tstate:1; /* Transient enable state */
822 /* List of event enablers */
823 struct list_head enablers_head;
824 /* Hash table of events */
825 struct lttng_event_ht events_ht;
826 char name[LTTNG_KERNEL_ABI_SESSION_NAME_LEN];
827 char creation_time[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN];
828 };
829
830 struct lttng_counter {
831 struct file *file; /* File associated to counter. */
832 struct file *owner;
833 struct lttng_counter_transport *transport;
834 struct lib_counter *counter;
835 struct lttng_counter_ops *ops;
836 };
837
838 struct lttng_event_notifier_group {
839 struct file *file; /* File associated to event notifier group */
840 struct file *notif_file; /* File used to expose notifications to userspace. */
841 struct list_head node; /* event notifier group list */
842 struct list_head enablers_head; /* List of enablers */
843 struct list_head event_notifiers_head; /* List of event notifier */
844 struct lttng_event_notifier_ht event_notifiers_ht; /* Hash table of event notifiers */
845 struct lttng_channel_ops *ops;
846 struct lttng_transport *transport;
847 struct channel *chan; /* Ring buffer channel for event notifier group. */
848 struct lib_ring_buffer *buf; /* Ring buffer for event notifier group. */
849 wait_queue_head_t read_wait;
850 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
851 struct lttng_event_notifier *sc_unknown; /* for unknown syscalls */
852 struct lttng_event_notifier *sc_compat_unknown;
853
854 struct lttng_syscall_filter *sc_filter;
855
856 struct hlist_head *event_notifier_syscall_dispatch;
857 struct hlist_head *event_notifier_compat_syscall_dispatch;
858 struct hlist_head *event_notifier_exit_syscall_dispatch;
859 struct hlist_head *event_notifier_exit_compat_syscall_dispatch;
860
861 struct hlist_head event_notifier_unknown_syscall_dispatch;
862 struct hlist_head event_notifier_compat_unknown_syscall_dispatch;
863 struct hlist_head event_notifier_exit_unknown_syscall_dispatch;
864 struct hlist_head event_notifier_exit_compat_unknown_syscall_dispatch;
865
866 int syscall_all_entry;
867 int syscall_all_exit;
868
869 unsigned int sys_enter_registered:1, sys_exit_registered:1;
870
871 struct lttng_counter *error_counter;
872 size_t error_counter_len;
873 };
874
875 struct lttng_metadata_cache {
876 char *data; /* Metadata cache */
877 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
878 unsigned int metadata_written; /* Number of bytes written in metadata cache */
879 atomic_t producing; /* Metadata being produced (incomplete) */
880 struct kref refcount; /* Metadata cache usage */
881 struct list_head metadata_stream; /* Metadata stream list */
882 uuid_le uuid; /* Trace session unique ID (copy) */
883 struct mutex lock; /* Produce/consume lock */
884 uint64_t version; /* Current version of the metadata */
885 };
886
887 void lttng_lock_sessions(void);
888 void lttng_unlock_sessions(void);
889
890 struct list_head *lttng_get_probe_list_head(void);
891
892 struct lttng_event_enabler *lttng_event_enabler_create(
893 enum lttng_enabler_format_type format_type,
894 struct lttng_kernel_abi_event *event_param,
895 struct lttng_channel *chan);
896
897 int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler);
898 int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler);
899 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
900 struct lttng_event_notifier_group *event_notifier_group,
901 enum lttng_enabler_format_type format_type,
902 struct lttng_kernel_abi_event_notifier *event_notifier_param);
903
904 int lttng_event_notifier_enabler_enable(
905 struct lttng_event_notifier_enabler *event_notifier_enabler);
906 int lttng_event_notifier_enabler_disable(
907 struct lttng_event_notifier_enabler *event_notifier_enabler);
908 int lttng_fix_pending_events(void);
909 int lttng_fix_pending_event_notifiers(void);
910 int lttng_session_active(void);
911 bool lttng_event_notifier_active(void);
912
913 struct lttng_session *lttng_session_create(void);
914 int lttng_session_enable(struct lttng_session *session);
915 int lttng_session_disable(struct lttng_session *session);
916 void lttng_session_destroy(struct lttng_session *session);
917 int lttng_session_metadata_regenerate(struct lttng_session *session);
918 int lttng_session_statedump(struct lttng_session *session);
919 void metadata_cache_destroy(struct kref *kref);
920
921 struct lttng_counter *lttng_kernel_counter_create(
922 const char *counter_transport_name, size_t number_dimensions,
923 const size_t *dimensions_sizes);
924 int lttng_kernel_counter_read(struct lttng_counter *counter,
925 const size_t *dimension_indexes, int32_t cpu,
926 int64_t *val, bool *overflow, bool *underflow);
927 int lttng_kernel_counter_aggregate(struct lttng_counter *counter,
928 const size_t *dimension_indexes, int64_t *val,
929 bool *overflow, bool *underflow);
930 int lttng_kernel_counter_clear(struct lttng_counter *counter,
931 const size_t *dimension_indexes);
932
933
934 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
935 int lttng_event_notifier_group_create_error_counter(
936 struct file *event_notifier_group_file,
937 const struct lttng_kernel_abi_counter_conf *error_counter_conf);
938 void lttng_event_notifier_group_destroy(
939 struct lttng_event_notifier_group *event_notifier_group);
940
941 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
942 const char *transport_name,
943 void *buf_addr,
944 size_t subbuf_size, size_t num_subbuf,
945 unsigned int switch_timer_interval,
946 unsigned int read_timer_interval,
947 enum channel_type channel_type);
948 struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
949 int overwrite, void *buf_addr,
950 size_t subbuf_size, size_t num_subbuf,
951 unsigned int switch_timer_interval,
952 unsigned int read_timer_interval);
953
954 void lttng_metadata_channel_destroy(struct lttng_channel *chan);
955 struct lttng_event *lttng_event_create(struct lttng_channel *chan,
956 struct lttng_kernel_abi_event *event_param,
957 void *filter,
958 const struct lttng_kernel_event_desc *event_desc,
959 enum lttng_kernel_abi_instrumentation itype);
960 struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
961 struct lttng_kernel_abi_event *event_param,
962 void *filter,
963 const struct lttng_kernel_event_desc *event_desc,
964 enum lttng_kernel_abi_instrumentation itype);
965 struct lttng_event *lttng_event_compat_old_create(struct lttng_channel *chan,
966 struct lttng_kernel_abi_old_event *old_event_param,
967 void *filter,
968 const struct lttng_kernel_event_desc *internal_desc);
969
970 struct lttng_event_notifier *lttng_event_notifier_create(
971 const struct lttng_kernel_event_desc *event_notifier_desc,
972 uint64_t id,
973 uint64_t error_counter_idx,
974 struct lttng_event_notifier_group *event_notifier_group,
975 struct lttng_kernel_abi_event_notifier *event_notifier_param,
976 void *filter,
977 enum lttng_kernel_abi_instrumentation itype);
978 struct lttng_event_notifier *_lttng_event_notifier_create(
979 const struct lttng_kernel_event_desc *event_notifier_desc,
980 uint64_t id,
981 uint64_t error_counter_idx,
982 struct lttng_event_notifier_group *event_notifier_group,
983 struct lttng_kernel_abi_event_notifier *event_notifier_param,
984 void *filter,
985 enum lttng_kernel_abi_instrumentation itype);
986
987 int lttng_channel_enable(struct lttng_channel *channel);
988 int lttng_channel_disable(struct lttng_channel *channel);
989 int lttng_event_enable(struct lttng_event *event);
990 int lttng_event_disable(struct lttng_event *event);
991
992 int lttng_event_notifier_enable(struct lttng_event_notifier *event_notifier);
993 int lttng_event_notifier_disable(struct lttng_event_notifier *event_notifier);
994
995 void lttng_transport_register(struct lttng_transport *transport);
996 void lttng_transport_unregister(struct lttng_transport *transport);
997
998 void lttng_counter_transport_register(struct lttng_counter_transport *transport);
999 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
1000
1001 void synchronize_trace(void);
1002 int lttng_abi_init(void);
1003 int lttng_abi_compat_old_init(void);
1004 void lttng_abi_exit(void);
1005 void lttng_abi_compat_old_exit(void);
1006
1007 int lttng_probe_register(struct lttng_kernel_probe_desc *desc);
1008 void lttng_probe_unregister(struct lttng_kernel_probe_desc *desc);
1009 const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name);
1010 void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc);
1011 int lttng_probes_init(void);
1012 void lttng_probes_exit(void);
1013
1014 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
1015 struct channel *chan, bool *coherent);
1016
1017 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
1018 int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf);
1019 void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu);
1020 bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id);
1021 int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id);
1022 int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id);
1023
1024 int lttng_session_track_id(struct lttng_session *session,
1025 enum tracker_type tracker_type, int id);
1026 int lttng_session_untrack_id(struct lttng_session *session,
1027 enum tracker_type tracker_type, int id);
1028
1029 int lttng_session_list_tracker_ids(struct lttng_session *session,
1030 enum tracker_type tracker_type);
1031
1032 void lttng_clock_ref(void);
1033 void lttng_clock_unref(void);
1034
1035 int lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc,
1036 struct lttng_enabler *enabler);
1037
1038 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
1039 int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, void *filter);
1040 int lttng_syscalls_unregister_channel(struct lttng_channel *chan);
1041 int lttng_syscalls_destroy_event(struct lttng_channel *chan);
1042 int lttng_syscall_filter_enable_event(
1043 struct lttng_channel *chan,
1044 struct lttng_event *event);
1045 int lttng_syscall_filter_disable_event(
1046 struct lttng_channel *chan,
1047 struct lttng_event *event);
1048
1049 long lttng_channel_syscall_mask(struct lttng_channel *channel,
1050 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask);
1051
1052 int lttng_syscalls_register_event_notifier(
1053 struct lttng_event_notifier_enabler *event_notifier_enabler,
1054 void *filter);
1055 int lttng_syscals_create_matching_event_notifiers(
1056 struct lttng_event_notifier_enabler *event_notifier_enabler, void *filter);
1057 int lttng_syscalls_unregister_event_notifier_group(struct lttng_event_notifier_group *group);
1058 int lttng_syscall_filter_enable_event_notifier(struct lttng_event_notifier *event_notifier);
1059 int lttng_syscall_filter_disable_event_notifier(struct lttng_event_notifier *event_notifier);
1060 #else
1061 static inline int lttng_syscalls_register_event(
1062 struct lttng_event_enabler *event_enabler, void *filter)
1063 {
1064 return -ENOSYS;
1065 }
1066
1067 static inline int lttng_syscalls_unregister_channel(struct lttng_channel *chan)
1068 {
1069 return 0;
1070 }
1071
1072 static inline int lttng_syscalls_destroy(struct lttng_channel *chan)
1073 {
1074 return 0;
1075 }
1076
1077 static inline int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
1078 struct lttng_event *event);
1079 {
1080 return -ENOSYS;
1081 }
1082
1083 static inline int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
1084 struct lttng_event *event);
1085 {
1086 return -ENOSYS;
1087 }
1088
1089 static inline long lttng_channel_syscall_mask(struct lttng_channel *channel,
1090 struct lttng_kernel_syscall_mask __user *usyscall_mask)
1091 {
1092 return -ENOSYS;
1093 }
1094
1095 static inline int lttng_syscalls_register_event_notifier(
1096 struct lttng_event_notifier_group *group, void *filter)
1097 {
1098 return -ENOSYS;
1099 }
1100
1101 static inline int lttng_syscalls_unregister_event_notifier_group(
1102 struct lttng_event_notifier_group *group)
1103 {
1104 return 0;
1105 }
1106
1107 static inline int lttng_syscall_filter_enable_event_notifier(
1108 struct lttng_event_notifier_group *group,
1109 const char *name)
1110 {
1111 return -ENOSYS;
1112 }
1113
1114 static inline int lttng_syscall_filter_disable_event_notifier(
1115 struct lttng_event_notifier_group *group,
1116 const char *name)
1117 {
1118 return -ENOSYS;
1119 }
1120
1121 #endif
1122
1123 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event_enabler,
1124 struct lttng_kernel_abi_filter_bytecode __user *bytecode);
1125 int lttng_event_notifier_enabler_attach_filter_bytecode(
1126 struct lttng_event_notifier_enabler *event_notifier_enabler,
1127 struct lttng_kernel_abi_filter_bytecode __user *bytecode);
1128 int lttng_event_notifier_enabler_attach_capture_bytecode(
1129 struct lttng_event_notifier_enabler *event_notifier_enabler,
1130 struct lttng_kernel_abi_capture_bytecode __user *bytecode);
1131
1132 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_desc,
1133 struct lttng_kernel_ctx *ctx,
1134 struct list_head *instance_bytecode_runtime_head,
1135 struct list_head *enabler_bytecode_runtime_head);
1136 void lttng_free_event_filter_runtime(struct lttng_event *event);
1137 void lttng_free_event_notifier_filter_runtime(struct lttng_event_notifier *event_notifier);
1138
1139 int lttng_probes_init(void);
1140
1141 extern struct lttng_kernel_ctx *lttng_static_ctx;
1142
1143 int lttng_context_init(void);
1144 void lttng_context_exit(void);
1145 int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
1146 const struct lttng_kernel_ctx_field *f);
1147 void lttng_kernel_context_remove_last(struct lttng_kernel_ctx **ctx_p);
1148 struct lttng_kernel_ctx_field *lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx *ctx,
1149 size_t index);
1150 int lttng_kernel_find_context(struct lttng_kernel_ctx *ctx, const char *name);
1151 int lttng_kernel_get_context_index(struct lttng_kernel_ctx *ctx, const char *name);
1152 void lttng_kernel_destroy_context(struct lttng_kernel_ctx *ctx);
1153 int lttng_add_pid_to_ctx(struct lttng_kernel_ctx **ctx);
1154 int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx **ctx);
1155 int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx);
1156 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx);
1157 int lttng_add_nice_to_ctx(struct lttng_kernel_ctx **ctx);
1158 int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx **ctx);
1159 int lttng_add_tid_to_ctx(struct lttng_kernel_ctx **ctx);
1160 int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx **ctx);
1161 int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx **ctx);
1162 int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx);
1163 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx **ctx);
1164 int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx **ctx);
1165 int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx **ctx);
1166 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
1167 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx);
1168 #else
1169 static inline
1170 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
1171 {
1172 return -ENOSYS;
1173 }
1174 #endif
1175 #ifdef CONFIG_PREEMPT_RT_FULL
1176 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx);
1177 #else
1178 static inline
1179 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx)
1180 {
1181 return -ENOSYS;
1182 }
1183 #endif
1184
1185 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx **ctx, int type);
1186
1187 #if defined(CONFIG_CGROUPS) && \
1188 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
1189 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
1190 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1191 #else
1192 static inline
1193 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1194 {
1195 return -ENOSYS;
1196 }
1197 #endif
1198
1199 #if defined(CONFIG_IPC_NS) && \
1200 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1201 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1202 #else
1203 static inline
1204 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1205 {
1206 return -ENOSYS;
1207 }
1208 #endif
1209
1210 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
1211 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1212 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1213 #else
1214 static inline
1215 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1216 {
1217 return -ENOSYS;
1218 }
1219 #endif
1220
1221 #if defined(CONFIG_NET_NS) && \
1222 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1223 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1224 #else
1225 static inline
1226 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1227 {
1228 return -ENOSYS;
1229 }
1230 #endif
1231
1232 #if defined(CONFIG_PID_NS) && \
1233 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1234 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1235 #else
1236 static inline
1237 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1238 {
1239 return -ENOSYS;
1240 }
1241 #endif
1242
1243 #if defined(CONFIG_USER_NS) && \
1244 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1245 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1246 #else
1247 static inline
1248 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1249 {
1250 return -ENOSYS;
1251 }
1252 #endif
1253
1254 #if defined(CONFIG_UTS_NS) && \
1255 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1256 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1257 #else
1258 static inline
1259 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1260 {
1261 return -ENOSYS;
1262 }
1263 #endif
1264
1265 #if defined(CONFIG_TIME_NS) && \
1266 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
1267 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1268 #else
1269 static inline
1270 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1271 {
1272 return -ENOSYS;
1273 }
1274 #endif
1275
1276 int lttng_add_uid_to_ctx(struct lttng_kernel_ctx **ctx);
1277 int lttng_add_euid_to_ctx(struct lttng_kernel_ctx **ctx);
1278 int lttng_add_suid_to_ctx(struct lttng_kernel_ctx **ctx);
1279 int lttng_add_gid_to_ctx(struct lttng_kernel_ctx **ctx);
1280 int lttng_add_egid_to_ctx(struct lttng_kernel_ctx **ctx);
1281 int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx **ctx);
1282 int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx **ctx);
1283 int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx **ctx);
1284 int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx **ctx);
1285 int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx **ctx);
1286 int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx **ctx);
1287 int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx **ctx);
1288
1289 #if defined(CONFIG_PERF_EVENTS)
1290 int lttng_add_perf_counter_to_ctx(uint32_t type,
1291 uint64_t config,
1292 const char *name,
1293 struct lttng_kernel_ctx **ctx);
1294 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
1295 struct lttng_cpuhp_node *node);
1296 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
1297 struct lttng_cpuhp_node *node);
1298 #else
1299 static inline
1300 int lttng_add_perf_counter_to_ctx(uint32_t type,
1301 uint64_t config,
1302 const char *name,
1303 struct lttng_kernel_ctx **ctx)
1304 {
1305 return -ENOSYS;
1306 }
1307 static inline
1308 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
1309 struct lttng_cpuhp_node *node)
1310 {
1311 return 0;
1312 }
1313 static inline
1314 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
1315 struct lttng_cpuhp_node *node)
1316 {
1317 return 0;
1318 }
1319 #endif
1320
1321 int lttng_logger_init(void);
1322 void lttng_logger_exit(void);
1323
1324 extern int lttng_statedump_start(struct lttng_session *session);
1325
1326 #ifdef CONFIG_KPROBES
1327 int lttng_kprobes_register_event(const char *name,
1328 const char *symbol_name,
1329 uint64_t offset,
1330 uint64_t addr,
1331 struct lttng_event *event);
1332 void lttng_kprobes_unregister_event(struct lttng_event *event);
1333 void lttng_kprobes_destroy_event_private(struct lttng_event *event);
1334 int lttng_kprobes_register_event_notifier(const char *symbol_name,
1335 uint64_t offset,
1336 uint64_t addr,
1337 struct lttng_event_notifier *event_notifier);
1338 void lttng_kprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier);
1339 void lttng_kprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier);
1340 #else
1341 static inline
1342 int lttng_kprobes_register_event(const char *name,
1343 const char *symbol_name,
1344 uint64_t offset,
1345 uint64_t addr,
1346 struct lttng_event *event)
1347 {
1348 return -ENOSYS;
1349 }
1350
1351 static inline
1352 void lttng_kprobes_unregister_event(struct lttng_event *event)
1353 {
1354 }
1355
1356 static inline
1357 void lttng_kprobes_destroy_event_private(struct lttng_event *event)
1358 {
1359 }
1360
1361 static inline
1362 int lttng_kprobes_register_event_notifier(const char *symbol_name,
1363 uint64_t offset,
1364 uint64_t addr,
1365 struct lttng_event_notifier *event_notifier)
1366 {
1367 return -ENOSYS;
1368 }
1369
1370 static inline
1371 void lttng_kprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier)
1372 {
1373 }
1374
1375 static inline
1376 void lttng_kprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier)
1377 {
1378 }
1379 #endif
1380
1381 int lttng_event_add_callsite(struct lttng_event *event,
1382 struct lttng_kernel_abi_event_callsite __user *callsite);
1383
1384 int lttng_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1385 struct lttng_kernel_abi_event_callsite __user *callsite);
1386
1387 #ifdef CONFIG_UPROBES
1388 int lttng_uprobes_register_event(const char *name,
1389 int fd, struct lttng_event *event);
1390 int lttng_uprobes_event_add_callsite(struct lttng_event *event,
1391 struct lttng_kernel_abi_event_callsite __user *callsite);
1392 void lttng_uprobes_unregister_event(struct lttng_event *event);
1393 void lttng_uprobes_destroy_event_private(struct lttng_event *event);
1394 int lttng_uprobes_register_event_notifier(const char *name,
1395 int fd, struct lttng_event_notifier *event_notifier);
1396 int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1397 struct lttng_kernel_abi_event_callsite __user *callsite);
1398 void lttng_uprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier);
1399 void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier);
1400 #else
1401 static inline
1402 int lttng_uprobes_register_event(const char *name,
1403 int fd, struct lttng_event *event)
1404 {
1405 return -ENOSYS;
1406 }
1407
1408 static inline
1409 int lttng_uprobes_event_add_callsite(struct lttng_event *event,
1410 struct lttng_kernel_abi_event_callsite __user *callsite)
1411 {
1412 return -ENOSYS;
1413 }
1414
1415 static inline
1416 void lttng_uprobes_unregister_event(struct lttng_event *event)
1417 {
1418 }
1419
1420 static inline
1421 void lttng_uprobes_destroy_event_private(struct lttng_event *event)
1422 {
1423 }
1424
1425 static inline
1426 int lttng_uprobes_register_event_notifier(const char *name,
1427 int fd, struct lttng_event_notifier *event_notifier)
1428 {
1429 return -ENOSYS;
1430 }
1431
1432 static inline
1433 int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1434 struct lttng_kernel_abi_event_callsite __user *callsite)
1435 {
1436 return -ENOSYS;
1437 }
1438
1439 static inline
1440 void lttng_uprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier)
1441 {
1442 }
1443
1444 static inline
1445 void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier)
1446 {
1447 }
1448 #endif
1449
1450 #ifdef CONFIG_KRETPROBES
1451 int lttng_kretprobes_register(const char *name,
1452 const char *symbol_name,
1453 uint64_t offset,
1454 uint64_t addr,
1455 struct lttng_event *event_entry,
1456 struct lttng_event *event_exit);
1457 void lttng_kretprobes_unregister(struct lttng_event *event);
1458 void lttng_kretprobes_destroy_private(struct lttng_event *event);
1459 int lttng_kretprobes_event_enable_state(struct lttng_event *event,
1460 int enable);
1461 #else
1462 static inline
1463 int lttng_kretprobes_register(const char *name,
1464 const char *symbol_name,
1465 uint64_t offset,
1466 uint64_t addr,
1467 struct lttng_event *event_entry,
1468 struct lttng_event *event_exit)
1469 {
1470 return -ENOSYS;
1471 }
1472
1473 static inline
1474 void lttng_kretprobes_unregister(struct lttng_event *event)
1475 {
1476 }
1477
1478 static inline
1479 void lttng_kretprobes_destroy_private(struct lttng_event *event)
1480 {
1481 }
1482
1483 static inline
1484 int lttng_kretprobes_event_enable_state(struct lttng_event *event,
1485 int enable)
1486 {
1487 return -ENOSYS;
1488 }
1489 #endif
1490
1491 int lttng_calibrate(struct lttng_kernel_abi_calibrate *calibrate);
1492
1493 extern const struct file_operations lttng_tracepoint_list_fops;
1494 extern const struct file_operations lttng_syscall_list_fops;
1495
1496 #define TRACEPOINT_HAS_DATA_ARG
1497
1498 #endif /* _LTTNG_EVENTS_H */
This page took 0.093841 seconds and 4 git commands to generate.