Refactoring: type description structures
[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_event_type {
382 LTTNG_TYPE_EVENT = 0,
383 LTTNG_TYPE_ENABLER = 1,
384 };
385
386 enum lttng_bytecode_node_type {
387 LTTNG_BYTECODE_NODE_TYPE_FILTER,
388 LTTNG_BYTECODE_NODE_TYPE_CAPTURE,
389 };
390
391 struct lttng_bytecode_node {
392 enum lttng_bytecode_node_type type;
393 struct list_head node;
394 struct lttng_enabler *enabler;
395 struct {
396 uint32_t len;
397 uint32_t reloc_offset;
398 uint64_t seqnum;
399 char data[];
400 } bc;
401 };
402
403 /*
404 * Bytecode interpreter return value masks.
405 */
406 enum lttng_bytecode_interpreter_ret {
407 LTTNG_INTERPRETER_DISCARD = 0,
408 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
409 /* Other bits are kept for future use. */
410 };
411
412 struct lttng_interpreter_output;
413
414 struct lttng_bytecode_runtime {
415 /* Associated bytecode */
416 struct lttng_bytecode_node *bc;
417 union {
418 uint64_t (*filter)(void *filter_data,
419 struct lttng_probe_ctx *lttng_probe_ctx,
420 const char *filter_stack_data);
421 uint64_t (*capture)(void *filter_data,
422 struct lttng_probe_ctx *lttng_probe_ctx,
423 const char *capture_stack_data,
424 struct lttng_interpreter_output *output);
425 } interpreter_funcs;
426 int link_failed;
427 struct list_head node; /* list of bytecode runtime in event */
428 struct lttng_kernel_ctx *ctx;
429 };
430
431 /*
432 * Objects in a linked-list of enablers, owned by an event.
433 */
434 struct lttng_enabler_ref {
435 struct list_head node; /* enabler ref list */
436 struct lttng_enabler *ref; /* backward ref */
437 };
438
439 struct lttng_uprobe_handler {
440 union {
441 struct lttng_event *event;
442 struct lttng_event_notifier *event_notifier;
443 } u;
444 loff_t offset;
445 struct uprobe_consumer up_consumer;
446 struct list_head node;
447 };
448
449 struct lttng_kprobe {
450 struct kprobe kp;
451 char *symbol_name;
452 };
453
454 struct lttng_uprobe {
455 struct inode *inode;
456 struct list_head head;
457 };
458
459 enum lttng_syscall_entryexit {
460 LTTNG_SYSCALL_ENTRY,
461 LTTNG_SYSCALL_EXIT,
462 };
463
464 enum lttng_syscall_abi {
465 LTTNG_SYSCALL_ABI_NATIVE,
466 LTTNG_SYSCALL_ABI_COMPAT,
467 };
468
469 /*
470 * lttng_event structure is referred to by the tracing fast path. It must be
471 * kept small.
472 */
473 struct lttng_event {
474 enum lttng_event_type evtype; /* First field. */
475 unsigned int id;
476 struct lttng_channel *chan;
477 int enabled;
478 const struct lttng_kernel_event_desc *desc;
479 void *filter;
480 struct lttng_kernel_ctx *ctx;
481 enum lttng_kernel_instrumentation instrumentation;
482 union {
483 struct lttng_kprobe kprobe;
484 struct {
485 struct lttng_krp *lttng_krp;
486 char *symbol_name;
487 } kretprobe;
488 struct lttng_uprobe uprobe;
489 struct {
490 enum lttng_syscall_entryexit entryexit;
491 enum lttng_syscall_abi abi;
492 struct hlist_node node; /* chain registered syscall event */
493 } syscall;
494 } u;
495 struct list_head list; /* Event list in session */
496 unsigned int metadata_dumped:1;
497
498 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
499 struct list_head enablers_ref_head;
500 struct hlist_node hlist; /* session ht of events */
501 int registered; /* has reg'd tracepoint probe */
502 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
503 struct list_head filter_bytecode_runtime_head;
504 int has_enablers_without_bytecode;
505 };
506
507 struct lttng_kernel_notifier_ctx {
508 int eval_capture;
509 };
510
511 // FIXME: Really similar to lttng_event above. Could those be merged ?
512 struct lttng_event_notifier {
513 enum lttng_event_type evtype; /* First field. */
514 uint64_t user_token;
515 uint64_t error_counter_index;
516 int enabled;
517 int registered; /* has reg'd tracepoint probe */
518 const struct lttng_kernel_event_desc *desc;
519 void *filter;
520 struct list_head list; /* event_notifier list in event_notifier group */
521
522 enum lttng_kernel_instrumentation instrumentation;
523 union {
524 struct lttng_kprobe kprobe;
525 struct lttng_uprobe uprobe;
526 struct {
527 enum lttng_syscall_entryexit entryexit;
528 enum lttng_syscall_abi abi;
529 struct hlist_node node; /* chain registered syscall event_notifier */
530 unsigned int syscall_id;
531 } syscall;
532
533 } u;
534
535 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
536 struct list_head enablers_ref_head;
537 struct hlist_node hlist; /* session ht of event_notifiers */
538 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
539 struct list_head filter_bytecode_runtime_head;
540 size_t num_captures;
541 struct list_head capture_bytecode_runtime_head;
542 int has_enablers_without_bytecode;
543 int eval_capture; /* Should evaluate capture */
544
545 void (*send_notification)(struct lttng_event_notifier *event_notifier,
546 struct lttng_probe_ctx *lttng_probe_ctx,
547 const char *interpreter_stack_data,
548 struct lttng_kernel_notifier_ctx *notif_ctx);
549 struct lttng_event_notifier_group *group; /* Weak ref */
550 };
551
552 enum lttng_enabler_format_type {
553 LTTNG_ENABLER_FORMAT_STAR_GLOB,
554 LTTNG_ENABLER_FORMAT_NAME,
555 };
556
557 /*
558 * Enabler field, within whatever object is enabling an event. Target of
559 * backward reference.
560 */
561 struct lttng_enabler {
562 enum lttng_event_type evtype; /* First field. */
563
564 enum lttng_enabler_format_type format_type;
565
566 /* head list of struct lttng_bytecode_node */
567 struct list_head filter_bytecode_head;
568
569 struct lttng_kernel_event event_param;
570 unsigned int enabled:1;
571
572 uint64_t user_token; /* User-provided token. */
573 };
574
575 struct lttng_event_enabler {
576 struct lttng_enabler base;
577 struct list_head node; /* per-session list of enablers */
578 struct lttng_channel *chan;
579 /*
580 * Unused, but kept around to make it explicit that the tracer can do
581 * it.
582 */
583 struct lttng_kernel_ctx *ctx;
584 };
585
586 struct lttng_event_notifier_enabler {
587 struct lttng_enabler base;
588 uint64_t error_counter_index;
589 struct list_head node; /* List of event_notifier enablers */
590 struct lttng_event_notifier_group *group;
591
592 /* head list of struct lttng_bytecode_node */
593 struct list_head capture_bytecode_head;
594 uint64_t num_captures;
595 };
596
597
598 static inline
599 struct lttng_enabler *lttng_event_enabler_as_enabler(
600 struct lttng_event_enabler *event_enabler)
601 {
602 return &event_enabler->base;
603 }
604
605 static inline
606 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
607 struct lttng_event_notifier_enabler *event_notifier_enabler)
608 {
609 return &event_notifier_enabler->base;
610 }
611
612 struct lttng_channel_ops {
613 struct channel *(*channel_create)(const char *name,
614 void *priv,
615 void *buf_addr,
616 size_t subbuf_size, size_t num_subbuf,
617 unsigned int switch_timer_interval,
618 unsigned int read_timer_interval);
619 void (*channel_destroy)(struct channel *chan);
620 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
621 int (*buffer_has_read_closed_stream)(struct channel *chan);
622 void (*buffer_read_close)(struct lib_ring_buffer *buf);
623 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
624 uint32_t event_id);
625 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
626 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
627 size_t len);
628 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
629 const void *src, size_t len);
630 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
631 int c, size_t len);
632 void (*event_strcpy)(struct lib_ring_buffer_ctx *ctx, const char *src,
633 size_t len);
634 void (*event_strcpy_from_user)(struct lib_ring_buffer_ctx *ctx,
635 const char __user *src, size_t len);
636 /*
637 * packet_avail_size returns the available size in the current
638 * packet. Note that the size returned is only a hint, since it
639 * may change due to concurrent writes.
640 */
641 size_t (*packet_avail_size)(struct channel *chan);
642 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
643 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
644 int (*is_finalized)(struct channel *chan);
645 int (*is_disabled)(struct channel *chan);
646 int (*timestamp_begin) (const struct lib_ring_buffer_config *config,
647 struct lib_ring_buffer *bufb,
648 uint64_t *timestamp_begin);
649 int (*timestamp_end) (const struct lib_ring_buffer_config *config,
650 struct lib_ring_buffer *bufb,
651 uint64_t *timestamp_end);
652 int (*events_discarded) (const struct lib_ring_buffer_config *config,
653 struct lib_ring_buffer *bufb,
654 uint64_t *events_discarded);
655 int (*content_size) (const struct lib_ring_buffer_config *config,
656 struct lib_ring_buffer *bufb,
657 uint64_t *content_size);
658 int (*packet_size) (const struct lib_ring_buffer_config *config,
659 struct lib_ring_buffer *bufb,
660 uint64_t *packet_size);
661 int (*stream_id) (const struct lib_ring_buffer_config *config,
662 struct lib_ring_buffer *bufb,
663 uint64_t *stream_id);
664 int (*current_timestamp) (const struct lib_ring_buffer_config *config,
665 struct lib_ring_buffer *bufb,
666 uint64_t *ts);
667 int (*sequence_number) (const struct lib_ring_buffer_config *config,
668 struct lib_ring_buffer *bufb,
669 uint64_t *seq);
670 int (*instance_id) (const struct lib_ring_buffer_config *config,
671 struct lib_ring_buffer *bufb,
672 uint64_t *id);
673 };
674
675 struct lttng_counter_ops {
676 struct lib_counter *(*counter_create)(size_t nr_dimensions,
677 const size_t *max_nr_elem, /* for each dimension */
678 int64_t global_sum_step);
679 void (*counter_destroy)(struct lib_counter *counter);
680 int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes,
681 int64_t v);
682 /*
683 * counter_read reads a specific cpu's counter if @cpu >= 0, or
684 * the global aggregation counter if @cpu == -1.
685 */
686 int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
687 int64_t *value, bool *overflow, bool *underflow);
688 /*
689 * counter_aggregate returns the total sum of all per-cpu counters and
690 * the global aggregation counter.
691 */
692 int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes,
693 int64_t *value, bool *overflow, bool *underflow);
694 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
695 };
696
697 struct lttng_transport {
698 char *name;
699 struct module *owner;
700 struct list_head node;
701 struct lttng_channel_ops ops;
702 };
703
704 struct lttng_counter_transport {
705 char *name;
706 struct module *owner;
707 struct list_head node;
708 struct lttng_counter_ops ops;
709 };
710
711 struct lttng_syscall_filter;
712
713 #define LTTNG_EVENT_HT_BITS 12
714 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
715
716 struct lttng_event_ht {
717 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
718 };
719
720 #define LTTNG_EVENT_NOTIFIER_HT_BITS 12
721 #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
722
723 struct lttng_event_notifier_ht {
724 struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE];
725 };
726
727 struct lttng_channel {
728 unsigned int id;
729 struct channel *chan; /* Channel buffers */
730 int enabled;
731 struct lttng_kernel_ctx *ctx;
732 /* Event ID management */
733 struct lttng_session *session;
734 struct file *file; /* File associated to channel */
735 unsigned int free_event_id; /* Next event ID to allocate */
736 struct list_head list; /* Channel list */
737 struct lttng_channel_ops *ops;
738 struct lttng_transport *transport;
739 struct hlist_head *sc_table; /* for syscall tracing */
740 struct hlist_head *compat_sc_table;
741 struct hlist_head *sc_exit_table; /* for syscall exit tracing */
742 struct hlist_head *compat_sc_exit_table;
743 struct hlist_head sc_unknown; /* for unknown syscalls */
744 struct hlist_head sc_compat_unknown;
745 struct hlist_head sc_exit_unknown;
746 struct hlist_head compat_sc_exit_unknown;
747 struct lttng_syscall_filter *sc_filter;
748 int header_type; /* 0: unset, 1: compact, 2: large */
749 enum channel_type channel_type;
750 int syscall_all_entry;
751 int syscall_all_exit;
752 unsigned int metadata_dumped:1,
753 sys_enter_registered:1,
754 sys_exit_registered:1,
755 tstate:1; /* Transient enable state */
756 };
757
758 struct lttng_metadata_stream {
759 void *priv; /* Ring buffer private data */
760 struct lttng_metadata_cache *metadata_cache;
761 unsigned int metadata_in; /* Bytes read from the cache */
762 unsigned int metadata_out; /* Bytes consumed from stream */
763 int finalized; /* Has channel been finalized */
764 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
765 struct list_head list; /* Stream list */
766 struct lttng_transport *transport;
767 uint64_t version; /* Current version of the metadata cache */
768 bool coherent; /* Stream in a coherent state */
769 };
770
771 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
772
773 struct lttng_dynamic_len_stack {
774 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
775 size_t offset;
776 };
777
778 DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
779
780 /*
781 * struct lttng_id_tracker declared in header due to deferencing of *v
782 * in RCU_INITIALIZER(v).
783 */
784 #define LTTNG_ID_HASH_BITS 6
785 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
786
787 enum tracker_type {
788 TRACKER_PID,
789 TRACKER_VPID,
790 TRACKER_UID,
791 TRACKER_VUID,
792 TRACKER_GID,
793 TRACKER_VGID,
794
795 TRACKER_UNKNOWN,
796 };
797
798 struct lttng_id_tracker_rcu {
799 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
800 };
801
802 struct lttng_id_tracker {
803 struct lttng_session *session;
804 enum tracker_type tracker_type;
805 struct lttng_id_tracker_rcu *p; /* RCU dereferenced. */
806 };
807
808 struct lttng_id_hash_node {
809 struct hlist_node hlist;
810 int id;
811 };
812
813 struct lttng_session {
814 int active; /* Is trace session active ? */
815 int been_active; /* Has trace session been active ? */
816 struct file *file; /* File associated to session */
817 struct list_head chan; /* Channel list head */
818 struct list_head events; /* Event list head */
819 struct list_head list; /* Session list */
820 unsigned int free_chan_id; /* Next chan ID to allocate */
821 uuid_le uuid; /* Trace session unique ID */
822 struct lttng_metadata_cache *metadata_cache;
823 struct lttng_id_tracker pid_tracker;
824 struct lttng_id_tracker vpid_tracker;
825 struct lttng_id_tracker uid_tracker;
826 struct lttng_id_tracker vuid_tracker;
827 struct lttng_id_tracker gid_tracker;
828 struct lttng_id_tracker vgid_tracker;
829 unsigned int metadata_dumped:1,
830 tstate:1; /* Transient enable state */
831 /* List of event enablers */
832 struct list_head enablers_head;
833 /* Hash table of events */
834 struct lttng_event_ht events_ht;
835 char name[LTTNG_KERNEL_SESSION_NAME_LEN];
836 char creation_time[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN];
837 };
838
839 struct lttng_counter {
840 struct file *file; /* File associated to counter. */
841 struct file *owner;
842 struct lttng_counter_transport *transport;
843 struct lib_counter *counter;
844 struct lttng_counter_ops *ops;
845 };
846
847 struct lttng_event_notifier_group {
848 struct file *file; /* File associated to event notifier group */
849 struct file *notif_file; /* File used to expose notifications to userspace. */
850 struct list_head node; /* event notifier group list */
851 struct list_head enablers_head; /* List of enablers */
852 struct list_head event_notifiers_head; /* List of event notifier */
853 struct lttng_event_notifier_ht event_notifiers_ht; /* Hash table of event notifiers */
854 struct lttng_channel_ops *ops;
855 struct lttng_transport *transport;
856 struct channel *chan; /* Ring buffer channel for event notifier group. */
857 struct lib_ring_buffer *buf; /* Ring buffer for event notifier group. */
858 wait_queue_head_t read_wait;
859 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
860 struct lttng_event_notifier *sc_unknown; /* for unknown syscalls */
861 struct lttng_event_notifier *sc_compat_unknown;
862
863 struct lttng_syscall_filter *sc_filter;
864
865 struct hlist_head *event_notifier_syscall_dispatch;
866 struct hlist_head *event_notifier_compat_syscall_dispatch;
867 struct hlist_head *event_notifier_exit_syscall_dispatch;
868 struct hlist_head *event_notifier_exit_compat_syscall_dispatch;
869
870 struct hlist_head event_notifier_unknown_syscall_dispatch;
871 struct hlist_head event_notifier_compat_unknown_syscall_dispatch;
872 struct hlist_head event_notifier_exit_unknown_syscall_dispatch;
873 struct hlist_head event_notifier_exit_compat_unknown_syscall_dispatch;
874
875 int syscall_all_entry;
876 int syscall_all_exit;
877
878 unsigned int sys_enter_registered:1, sys_exit_registered:1;
879
880 struct lttng_counter *error_counter;
881 size_t error_counter_len;
882 };
883
884 struct lttng_metadata_cache {
885 char *data; /* Metadata cache */
886 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
887 unsigned int metadata_written; /* Number of bytes written in metadata cache */
888 atomic_t producing; /* Metadata being produced (incomplete) */
889 struct kref refcount; /* Metadata cache usage */
890 struct list_head metadata_stream; /* Metadata stream list */
891 uuid_le uuid; /* Trace session unique ID (copy) */
892 struct mutex lock; /* Produce/consume lock */
893 uint64_t version; /* Current version of the metadata */
894 };
895
896 void lttng_lock_sessions(void);
897 void lttng_unlock_sessions(void);
898
899 struct list_head *lttng_get_probe_list_head(void);
900
901 struct lttng_event_enabler *lttng_event_enabler_create(
902 enum lttng_enabler_format_type format_type,
903 struct lttng_kernel_event *event_param,
904 struct lttng_channel *chan);
905
906 int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler);
907 int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler);
908 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
909 struct lttng_event_notifier_group *event_notifier_group,
910 enum lttng_enabler_format_type format_type,
911 struct lttng_kernel_event_notifier *event_notifier_param);
912
913 int lttng_event_notifier_enabler_enable(
914 struct lttng_event_notifier_enabler *event_notifier_enabler);
915 int lttng_event_notifier_enabler_disable(
916 struct lttng_event_notifier_enabler *event_notifier_enabler);
917 int lttng_fix_pending_events(void);
918 int lttng_fix_pending_event_notifiers(void);
919 int lttng_session_active(void);
920 bool lttng_event_notifier_active(void);
921
922 struct lttng_session *lttng_session_create(void);
923 int lttng_session_enable(struct lttng_session *session);
924 int lttng_session_disable(struct lttng_session *session);
925 void lttng_session_destroy(struct lttng_session *session);
926 int lttng_session_metadata_regenerate(struct lttng_session *session);
927 int lttng_session_statedump(struct lttng_session *session);
928 void metadata_cache_destroy(struct kref *kref);
929
930 struct lttng_counter *lttng_kernel_counter_create(
931 const char *counter_transport_name, size_t number_dimensions,
932 const size_t *dimensions_sizes);
933 int lttng_kernel_counter_read(struct lttng_counter *counter,
934 const size_t *dimension_indexes, int32_t cpu,
935 int64_t *val, bool *overflow, bool *underflow);
936 int lttng_kernel_counter_aggregate(struct lttng_counter *counter,
937 const size_t *dimension_indexes, int64_t *val,
938 bool *overflow, bool *underflow);
939 int lttng_kernel_counter_clear(struct lttng_counter *counter,
940 const size_t *dimension_indexes);
941
942
943 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
944 int lttng_event_notifier_group_create_error_counter(
945 struct file *event_notifier_group_file,
946 const struct lttng_kernel_counter_conf *error_counter_conf);
947 void lttng_event_notifier_group_destroy(
948 struct lttng_event_notifier_group *event_notifier_group);
949
950 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
951 const char *transport_name,
952 void *buf_addr,
953 size_t subbuf_size, size_t num_subbuf,
954 unsigned int switch_timer_interval,
955 unsigned int read_timer_interval,
956 enum channel_type channel_type);
957 struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
958 int overwrite, void *buf_addr,
959 size_t subbuf_size, size_t num_subbuf,
960 unsigned int switch_timer_interval,
961 unsigned int read_timer_interval);
962
963 void lttng_metadata_channel_destroy(struct lttng_channel *chan);
964 struct lttng_event *lttng_event_create(struct lttng_channel *chan,
965 struct lttng_kernel_event *event_param,
966 void *filter,
967 const struct lttng_kernel_event_desc *event_desc,
968 enum lttng_kernel_instrumentation itype);
969 struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
970 struct lttng_kernel_event *event_param,
971 void *filter,
972 const struct lttng_kernel_event_desc *event_desc,
973 enum lttng_kernel_instrumentation itype);
974 struct lttng_event *lttng_event_compat_old_create(struct lttng_channel *chan,
975 struct lttng_kernel_old_event *old_event_param,
976 void *filter,
977 const struct lttng_kernel_event_desc *internal_desc);
978
979 struct lttng_event_notifier *lttng_event_notifier_create(
980 const struct lttng_kernel_event_desc *event_notifier_desc,
981 uint64_t id,
982 uint64_t error_counter_idx,
983 struct lttng_event_notifier_group *event_notifier_group,
984 struct lttng_kernel_event_notifier *event_notifier_param,
985 void *filter,
986 enum lttng_kernel_instrumentation itype);
987 struct lttng_event_notifier *_lttng_event_notifier_create(
988 const struct lttng_kernel_event_desc *event_notifier_desc,
989 uint64_t id,
990 uint64_t error_counter_idx,
991 struct lttng_event_notifier_group *event_notifier_group,
992 struct lttng_kernel_event_notifier *event_notifier_param,
993 void *filter,
994 enum lttng_kernel_instrumentation itype);
995
996 int lttng_channel_enable(struct lttng_channel *channel);
997 int lttng_channel_disable(struct lttng_channel *channel);
998 int lttng_event_enable(struct lttng_event *event);
999 int lttng_event_disable(struct lttng_event *event);
1000
1001 int lttng_event_notifier_enable(struct lttng_event_notifier *event_notifier);
1002 int lttng_event_notifier_disable(struct lttng_event_notifier *event_notifier);
1003
1004 void lttng_transport_register(struct lttng_transport *transport);
1005 void lttng_transport_unregister(struct lttng_transport *transport);
1006
1007 void lttng_counter_transport_register(struct lttng_counter_transport *transport);
1008 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
1009
1010 void synchronize_trace(void);
1011 int lttng_abi_init(void);
1012 int lttng_abi_compat_old_init(void);
1013 void lttng_abi_exit(void);
1014 void lttng_abi_compat_old_exit(void);
1015
1016 int lttng_probe_register(struct lttng_kernel_probe_desc *desc);
1017 void lttng_probe_unregister(struct lttng_kernel_probe_desc *desc);
1018 const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name);
1019 void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc);
1020 int lttng_probes_init(void);
1021 void lttng_probes_exit(void);
1022
1023 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
1024 struct channel *chan, bool *coherent);
1025
1026 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
1027 int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf);
1028 void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu);
1029 bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id);
1030 int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id);
1031 int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id);
1032
1033 int lttng_session_track_id(struct lttng_session *session,
1034 enum tracker_type tracker_type, int id);
1035 int lttng_session_untrack_id(struct lttng_session *session,
1036 enum tracker_type tracker_type, int id);
1037
1038 int lttng_session_list_tracker_ids(struct lttng_session *session,
1039 enum tracker_type tracker_type);
1040
1041 void lttng_clock_ref(void);
1042 void lttng_clock_unref(void);
1043
1044 int lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc,
1045 struct lttng_enabler *enabler);
1046
1047 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
1048 int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, void *filter);
1049 int lttng_syscalls_unregister_channel(struct lttng_channel *chan);
1050 int lttng_syscalls_destroy_event(struct lttng_channel *chan);
1051 int lttng_syscall_filter_enable_event(
1052 struct lttng_channel *chan,
1053 struct lttng_event *event);
1054 int lttng_syscall_filter_disable_event(
1055 struct lttng_channel *chan,
1056 struct lttng_event *event);
1057
1058 long lttng_channel_syscall_mask(struct lttng_channel *channel,
1059 struct lttng_kernel_syscall_mask __user *usyscall_mask);
1060
1061 int lttng_syscalls_register_event_notifier(
1062 struct lttng_event_notifier_enabler *event_notifier_enabler,
1063 void *filter);
1064 int lttng_syscals_create_matching_event_notifiers(
1065 struct lttng_event_notifier_enabler *event_notifier_enabler, void *filter);
1066 int lttng_syscalls_unregister_event_notifier_group(struct lttng_event_notifier_group *group);
1067 int lttng_syscall_filter_enable_event_notifier(struct lttng_event_notifier *event_notifier);
1068 int lttng_syscall_filter_disable_event_notifier(struct lttng_event_notifier *event_notifier);
1069 #else
1070 static inline int lttng_syscalls_register_event(
1071 struct lttng_event_enabler *event_enabler, void *filter)
1072 {
1073 return -ENOSYS;
1074 }
1075
1076 static inline int lttng_syscalls_unregister_channel(struct lttng_channel *chan)
1077 {
1078 return 0;
1079 }
1080
1081 static inline int lttng_syscalls_destroy(struct lttng_channel *chan)
1082 {
1083 return 0;
1084 }
1085
1086 static inline int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
1087 struct lttng_event *event);
1088 {
1089 return -ENOSYS;
1090 }
1091
1092 static inline int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
1093 struct lttng_event *event);
1094 {
1095 return -ENOSYS;
1096 }
1097
1098 static inline long lttng_channel_syscall_mask(struct lttng_channel *channel,
1099 struct lttng_kernel_syscall_mask __user *usyscall_mask)
1100 {
1101 return -ENOSYS;
1102 }
1103
1104 static inline int lttng_syscalls_register_event_notifier(
1105 struct lttng_event_notifier_group *group, void *filter)
1106 {
1107 return -ENOSYS;
1108 }
1109
1110 static inline int lttng_syscalls_unregister_event_notifier_group(
1111 struct lttng_event_notifier_group *group)
1112 {
1113 return 0;
1114 }
1115
1116 static inline int lttng_syscall_filter_enable_event_notifier(
1117 struct lttng_event_notifier_group *group,
1118 const char *name)
1119 {
1120 return -ENOSYS;
1121 }
1122
1123 static inline int lttng_syscall_filter_disable_event_notifier(
1124 struct lttng_event_notifier_group *group,
1125 const char *name)
1126 {
1127 return -ENOSYS;
1128 }
1129
1130 #endif
1131
1132 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event_enabler,
1133 struct lttng_kernel_filter_bytecode __user *bytecode);
1134 int lttng_event_notifier_enabler_attach_filter_bytecode(
1135 struct lttng_event_notifier_enabler *event_notifier_enabler,
1136 struct lttng_kernel_filter_bytecode __user *bytecode);
1137 int lttng_event_notifier_enabler_attach_capture_bytecode(
1138 struct lttng_event_notifier_enabler *event_notifier_enabler,
1139 struct lttng_kernel_capture_bytecode __user *bytecode);
1140
1141 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_desc,
1142 struct lttng_kernel_ctx *ctx,
1143 struct list_head *instance_bytecode_runtime_head,
1144 struct list_head *enabler_bytecode_runtime_head);
1145 void lttng_free_event_filter_runtime(struct lttng_event *event);
1146 void lttng_free_event_notifier_filter_runtime(struct lttng_event_notifier *event_notifier);
1147
1148 int lttng_probes_init(void);
1149
1150 extern struct lttng_kernel_ctx *lttng_static_ctx;
1151
1152 int lttng_context_init(void);
1153 void lttng_context_exit(void);
1154 int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
1155 const struct lttng_kernel_ctx_field *f);
1156 void lttng_kernel_context_remove_last(struct lttng_kernel_ctx **ctx_p);
1157 struct lttng_kernel_ctx_field *lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx *ctx,
1158 size_t index);
1159 int lttng_kernel_find_context(struct lttng_kernel_ctx *ctx, const char *name);
1160 int lttng_kernel_get_context_index(struct lttng_kernel_ctx *ctx, const char *name);
1161 void lttng_kernel_destroy_context(struct lttng_kernel_ctx *ctx);
1162 int lttng_add_pid_to_ctx(struct lttng_kernel_ctx **ctx);
1163 int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx **ctx);
1164 int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx);
1165 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx);
1166 int lttng_add_nice_to_ctx(struct lttng_kernel_ctx **ctx);
1167 int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx **ctx);
1168 int lttng_add_tid_to_ctx(struct lttng_kernel_ctx **ctx);
1169 int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx **ctx);
1170 int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx **ctx);
1171 int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx);
1172 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx **ctx);
1173 int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx **ctx);
1174 int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx **ctx);
1175 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
1176 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx);
1177 #else
1178 static inline
1179 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
1180 {
1181 return -ENOSYS;
1182 }
1183 #endif
1184 #ifdef CONFIG_PREEMPT_RT_FULL
1185 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx);
1186 #else
1187 static inline
1188 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx)
1189 {
1190 return -ENOSYS;
1191 }
1192 #endif
1193
1194 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx **ctx, int type);
1195
1196 #if defined(CONFIG_CGROUPS) && \
1197 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
1198 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
1199 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1200 #else
1201 static inline
1202 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1203 {
1204 return -ENOSYS;
1205 }
1206 #endif
1207
1208 #if defined(CONFIG_IPC_NS) && \
1209 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1210 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1211 #else
1212 static inline
1213 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1214 {
1215 return -ENOSYS;
1216 }
1217 #endif
1218
1219 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
1220 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1221 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1222 #else
1223 static inline
1224 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1225 {
1226 return -ENOSYS;
1227 }
1228 #endif
1229
1230 #if defined(CONFIG_NET_NS) && \
1231 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1232 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1233 #else
1234 static inline
1235 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1236 {
1237 return -ENOSYS;
1238 }
1239 #endif
1240
1241 #if defined(CONFIG_PID_NS) && \
1242 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1243 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1244 #else
1245 static inline
1246 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1247 {
1248 return -ENOSYS;
1249 }
1250 #endif
1251
1252 #if defined(CONFIG_USER_NS) && \
1253 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1254 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1255 #else
1256 static inline
1257 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1258 {
1259 return -ENOSYS;
1260 }
1261 #endif
1262
1263 #if defined(CONFIG_UTS_NS) && \
1264 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
1265 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1266 #else
1267 static inline
1268 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1269 {
1270 return -ENOSYS;
1271 }
1272 #endif
1273
1274 #if defined(CONFIG_TIME_NS) && \
1275 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
1276 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx);
1277 #else
1278 static inline
1279 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx)
1280 {
1281 return -ENOSYS;
1282 }
1283 #endif
1284
1285 int lttng_add_uid_to_ctx(struct lttng_kernel_ctx **ctx);
1286 int lttng_add_euid_to_ctx(struct lttng_kernel_ctx **ctx);
1287 int lttng_add_suid_to_ctx(struct lttng_kernel_ctx **ctx);
1288 int lttng_add_gid_to_ctx(struct lttng_kernel_ctx **ctx);
1289 int lttng_add_egid_to_ctx(struct lttng_kernel_ctx **ctx);
1290 int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx **ctx);
1291 int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx **ctx);
1292 int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx **ctx);
1293 int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx **ctx);
1294 int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx **ctx);
1295 int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx **ctx);
1296 int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx **ctx);
1297
1298 #if defined(CONFIG_PERF_EVENTS)
1299 int lttng_add_perf_counter_to_ctx(uint32_t type,
1300 uint64_t config,
1301 const char *name,
1302 struct lttng_kernel_ctx **ctx);
1303 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
1304 struct lttng_cpuhp_node *node);
1305 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
1306 struct lttng_cpuhp_node *node);
1307 #else
1308 static inline
1309 int lttng_add_perf_counter_to_ctx(uint32_t type,
1310 uint64_t config,
1311 const char *name,
1312 struct lttng_kernel_ctx **ctx)
1313 {
1314 return -ENOSYS;
1315 }
1316 static inline
1317 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
1318 struct lttng_cpuhp_node *node)
1319 {
1320 return 0;
1321 }
1322 static inline
1323 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
1324 struct lttng_cpuhp_node *node)
1325 {
1326 return 0;
1327 }
1328 #endif
1329
1330 int lttng_logger_init(void);
1331 void lttng_logger_exit(void);
1332
1333 extern int lttng_statedump_start(struct lttng_session *session);
1334
1335 #ifdef CONFIG_KPROBES
1336 int lttng_kprobes_register_event(const char *name,
1337 const char *symbol_name,
1338 uint64_t offset,
1339 uint64_t addr,
1340 struct lttng_event *event);
1341 void lttng_kprobes_unregister_event(struct lttng_event *event);
1342 void lttng_kprobes_destroy_event_private(struct lttng_event *event);
1343 int lttng_kprobes_register_event_notifier(const char *symbol_name,
1344 uint64_t offset,
1345 uint64_t addr,
1346 struct lttng_event_notifier *event_notifier);
1347 void lttng_kprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier);
1348 void lttng_kprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier);
1349 #else
1350 static inline
1351 int lttng_kprobes_register_event(const char *name,
1352 const char *symbol_name,
1353 uint64_t offset,
1354 uint64_t addr,
1355 struct lttng_event *event)
1356 {
1357 return -ENOSYS;
1358 }
1359
1360 static inline
1361 void lttng_kprobes_unregister_event(struct lttng_event *event)
1362 {
1363 }
1364
1365 static inline
1366 void lttng_kprobes_destroy_event_private(struct lttng_event *event)
1367 {
1368 }
1369
1370 static inline
1371 int lttng_kprobes_register_event_notifier(const char *symbol_name,
1372 uint64_t offset,
1373 uint64_t addr,
1374 struct lttng_event_notifier *event_notifier)
1375 {
1376 return -ENOSYS;
1377 }
1378
1379 static inline
1380 void lttng_kprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier)
1381 {
1382 }
1383
1384 static inline
1385 void lttng_kprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier)
1386 {
1387 }
1388 #endif
1389
1390 int lttng_event_add_callsite(struct lttng_event *event,
1391 struct lttng_kernel_event_callsite *callsite);
1392
1393 int lttng_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1394 struct lttng_kernel_event_callsite *callsite);
1395
1396 #ifdef CONFIG_UPROBES
1397 int lttng_uprobes_register_event(const char *name,
1398 int fd, struct lttng_event *event);
1399 int lttng_uprobes_event_add_callsite(struct lttng_event *event,
1400 struct lttng_kernel_event_callsite *callsite);
1401 void lttng_uprobes_unregister_event(struct lttng_event *event);
1402 void lttng_uprobes_destroy_event_private(struct lttng_event *event);
1403 int lttng_uprobes_register_event_notifier(const char *name,
1404 int fd, struct lttng_event_notifier *event_notifier);
1405 int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1406 struct lttng_kernel_event_callsite *callsite);
1407 void lttng_uprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier);
1408 void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier);
1409 #else
1410 static inline
1411 int lttng_uprobes_register_event(const char *name,
1412 int fd, struct lttng_event *event)
1413 {
1414 return -ENOSYS;
1415 }
1416
1417 static inline
1418 int lttng_uprobes_event_add_callsite(struct lttng_event *event,
1419 struct lttng_kernel_event_callsite *callsite)
1420 {
1421 return -ENOSYS;
1422 }
1423
1424 static inline
1425 void lttng_uprobes_unregister_event(struct lttng_event *event)
1426 {
1427 }
1428
1429 static inline
1430 void lttng_uprobes_destroy_event_private(struct lttng_event *event)
1431 {
1432 }
1433
1434 static inline
1435 int lttng_uprobes_register_event_notifier(const char *name,
1436 int fd, struct lttng_event_notifier *event_notifier)
1437 {
1438 return -ENOSYS;
1439 }
1440
1441 static inline
1442 int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1443 struct lttng_kernel_event_callsite *callsite)
1444 {
1445 return -ENOSYS;
1446 }
1447
1448 static inline
1449 void lttng_uprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier)
1450 {
1451 }
1452
1453 static inline
1454 void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier)
1455 {
1456 }
1457 #endif
1458
1459 #ifdef CONFIG_KRETPROBES
1460 int lttng_kretprobes_register(const char *name,
1461 const char *symbol_name,
1462 uint64_t offset,
1463 uint64_t addr,
1464 struct lttng_event *event_entry,
1465 struct lttng_event *event_exit);
1466 void lttng_kretprobes_unregister(struct lttng_event *event);
1467 void lttng_kretprobes_destroy_private(struct lttng_event *event);
1468 int lttng_kretprobes_event_enable_state(struct lttng_event *event,
1469 int enable);
1470 #else
1471 static inline
1472 int lttng_kretprobes_register(const char *name,
1473 const char *symbol_name,
1474 uint64_t offset,
1475 uint64_t addr,
1476 struct lttng_event *event_entry,
1477 struct lttng_event *event_exit)
1478 {
1479 return -ENOSYS;
1480 }
1481
1482 static inline
1483 void lttng_kretprobes_unregister(struct lttng_event *event)
1484 {
1485 }
1486
1487 static inline
1488 void lttng_kretprobes_destroy_private(struct lttng_event *event)
1489 {
1490 }
1491
1492 static inline
1493 int lttng_kretprobes_event_enable_state(struct lttng_event *event,
1494 int enable)
1495 {
1496 return -ENOSYS;
1497 }
1498 #endif
1499
1500 int lttng_calibrate(struct lttng_kernel_calibrate *calibrate);
1501
1502 extern const struct file_operations lttng_tracepoint_list_fops;
1503 extern const struct file_operations lttng_syscall_list_fops;
1504
1505 #define TRACEPOINT_HAS_DATA_ARG
1506
1507 #endif /* _LTTNG_EVENTS_H */
This page took 0.058636 seconds and 4 git commands to generate.