Implement event notifiers for syscalls
[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 <linux/irq_work.h>
14 #include <linux/version.h>
15 #include <linux/list.h>
16 #include <linux/kprobes.h>
17 #include <linux/kref.h>
18 #include <linux/uuid.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)) < 0)
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 abstract_types {
39 atype_integer,
40 atype_string,
41 atype_enum_nestable,
42 atype_array_nestable,
43 atype_sequence_nestable,
44 atype_struct_nestable,
45 atype_variant_nestable,
46 NR_ABSTRACT_TYPES,
47 };
48
49 enum lttng_string_encodings {
50 lttng_encode_none = 0,
51 lttng_encode_UTF8 = 1,
52 lttng_encode_ASCII = 2,
53 NR_STRING_ENCODINGS,
54 };
55
56 enum channel_type {
57 PER_CPU_CHANNEL,
58 METADATA_CHANNEL,
59 };
60
61 struct lttng_enum_value {
62 unsigned long long value;
63 unsigned int signedness:1;
64 };
65
66 struct lttng_enum_entry {
67 struct lttng_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 #define __type_integer(_type, _size, _alignment, _signedness, \
75 _byte_order, _base, _encoding) \
76 { \
77 .atype = atype_integer, \
78 .u.integer = \
79 { \
80 .size = (_size) ? : sizeof(_type) * CHAR_BIT, \
81 .alignment = (_alignment) ? : lttng_alignof(_type) * CHAR_BIT, \
82 .signedness = (_signedness) >= 0 ? (_signedness) : lttng_is_signed_type(_type), \
83 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
84 .base = _base, \
85 .encoding = lttng_encode_##_encoding, \
86 }, \
87 } \
88
89 struct lttng_integer_type {
90 unsigned int size; /* in bits */
91 unsigned short alignment; /* in bits */
92 unsigned int signedness:1,
93 reverse_byte_order:1;
94 unsigned int base; /* 2, 8, 10, 16, for pretty print */
95 enum lttng_string_encodings encoding;
96 };
97
98 struct lttng_type {
99 enum abstract_types atype;
100 union {
101 struct lttng_integer_type integer;
102 struct {
103 enum lttng_string_encodings encoding;
104 } string;
105 struct {
106 const struct lttng_enum_desc *desc; /* Enumeration mapping */
107 const struct lttng_type *container_type;
108 } enum_nestable;
109 struct {
110 const struct lttng_type *elem_type;
111 unsigned int length; /* Num. elems. */
112 unsigned int alignment;
113 } array_nestable;
114 struct {
115 const char *length_name; /* Length field name. */
116 const struct lttng_type *elem_type;
117 unsigned int alignment; /* Alignment before elements. */
118 } sequence_nestable;
119 struct {
120 unsigned int nr_fields;
121 const struct lttng_event_field *fields; /* Array of fields. */
122 unsigned int alignment;
123 } struct_nestable;
124 struct {
125 const char *tag_name;
126 const struct lttng_event_field *choices; /* Array of fields. */
127 unsigned int nr_choices;
128 unsigned int alignment;
129 } variant_nestable;
130 } u;
131 };
132
133 struct lttng_enum_desc {
134 const char *name;
135 const struct lttng_enum_entry *entries;
136 unsigned int nr_entries;
137 };
138
139 /* Event field description */
140
141 struct lttng_event_field {
142 const char *name;
143 struct lttng_type 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 union lttng_ctx_value {
150 int64_t s64;
151 const char *str;
152 double d;
153 };
154
155 /*
156 * We need to keep this perf counter field separately from struct
157 * lttng_ctx_field because cpu hotplug needs fixed-location addresses.
158 */
159 struct lttng_perf_counter_field {
160 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
161 struct lttng_cpuhp_node cpuhp_prepare;
162 struct lttng_cpuhp_node cpuhp_online;
163 #else
164 struct notifier_block nb;
165 int hp_enable;
166 #endif
167 struct perf_event_attr *attr;
168 struct perf_event **e; /* per-cpu array */
169 };
170
171 struct lttng_probe_ctx {
172 struct lttng_event *event;
173 struct lttng_event_notifier *event_notifier; // Not sure if we will ever need it.
174 uint8_t interruptible;
175 };
176
177 struct lttng_ctx_field {
178 struct lttng_event_field event_field;
179 size_t (*get_size)(size_t offset);
180 size_t (*get_size_arg)(size_t offset, struct lttng_ctx_field *field,
181 struct lib_ring_buffer_ctx *ctx,
182 struct lttng_channel *chan);
183 void (*record)(struct lttng_ctx_field *field,
184 struct lib_ring_buffer_ctx *ctx,
185 struct lttng_channel *chan);
186 void (*get_value)(struct lttng_ctx_field *field,
187 struct lttng_probe_ctx *lttng_probe_ctx,
188 union lttng_ctx_value *value);
189 union {
190 struct lttng_perf_counter_field *perf_counter;
191 } u;
192 void (*destroy)(struct lttng_ctx_field *field);
193 /*
194 * Private data to keep state between get_size and record.
195 * User must perform its own synchronization to protect against
196 * concurrent and reentrant contexts.
197 */
198 void *priv;
199 };
200
201 struct lttng_ctx {
202 struct lttng_ctx_field *fields;
203 unsigned int nr_fields;
204 unsigned int allocated_fields;
205 size_t largest_align; /* in bytes */
206 };
207
208 struct lttng_event_desc {
209 const char *name; /* lttng-modules name */
210 const char *kname; /* Linux kernel name (tracepoints) */
211 void *probe_callback;
212 const struct lttng_event_ctx *ctx; /* context */
213 const struct lttng_event_field *fields; /* event payload */
214 unsigned int nr_fields;
215 struct module *owner;
216 void *event_notifier_callback;
217 };
218
219 struct lttng_probe_desc {
220 const char *provider;
221 const struct lttng_event_desc **event_desc;
222 unsigned int nr_events;
223 struct list_head head; /* chain registered probes */
224 struct list_head lazy_init_head;
225 int lazy; /* lazy registration */
226 };
227
228 struct lttng_krp; /* Kretprobe handling */
229
230 enum lttng_event_type {
231 LTTNG_TYPE_EVENT = 0,
232 LTTNG_TYPE_ENABLER = 1,
233 };
234
235 struct lttng_filter_bytecode_node {
236 struct list_head node;
237 struct lttng_enabler *enabler;
238 /*
239 * struct lttng_kernel_filter_bytecode has var. sized array, must be
240 * last field.
241 */
242 struct lttng_kernel_filter_bytecode bc;
243 };
244
245 /*
246 * Filter return value masks.
247 */
248 enum lttng_filter_ret {
249 LTTNG_FILTER_DISCARD = 0,
250 LTTNG_FILTER_RECORD_FLAG = (1ULL << 0),
251 /* Other bits are kept for future use. */
252 };
253
254 struct lttng_bytecode_runtime {
255 /* Associated bytecode */
256 struct lttng_filter_bytecode_node *bc;
257 uint64_t (*filter)(void *filter_data, struct lttng_probe_ctx *lttng_probe_ctx,
258 const char *filter_stack_data);
259 int link_failed;
260 struct list_head node; /* list of bytecode runtime in event */
261 struct lttng_ctx *ctx;
262 };
263
264 /*
265 * Objects in a linked-list of enablers, owned by an event.
266 */
267 struct lttng_enabler_ref {
268 struct list_head node; /* enabler ref list */
269 struct lttng_enabler *ref; /* backward ref */
270 };
271
272 struct lttng_uprobe_handler {
273 union {
274 struct lttng_event *event;
275 struct lttng_event_notifier *event_notifier;
276 } u;
277 loff_t offset;
278 struct uprobe_consumer up_consumer;
279 struct list_head node;
280 };
281
282 struct lttng_kprobe {
283 struct kprobe kp;
284 char *symbol_name;
285 };
286
287 struct lttng_uprobe {
288 struct inode *inode;
289 struct list_head head;
290 };
291
292 enum lttng_syscall_entryexit {
293 LTTNG_SYSCALL_ENTRY,
294 LTTNG_SYSCALL_EXIT,
295 };
296
297 enum lttng_syscall_abi {
298 LTTNG_SYSCALL_ABI_NATIVE,
299 LTTNG_SYSCALL_ABI_COMPAT,
300 };
301
302 struct lttng_syscall {
303 struct list_head node; /* chain registered syscall event_notifier */
304 unsigned int syscall_id;
305 bool is_compat;
306 };
307
308 /*
309 * lttng_event structure is referred to by the tracing fast path. It must be
310 * kept small.
311 */
312 struct lttng_event {
313 enum lttng_event_type evtype; /* First field. */
314 unsigned int id;
315 struct lttng_channel *chan;
316 int enabled;
317 const struct lttng_event_desc *desc;
318 void *filter;
319 struct lttng_ctx *ctx;
320 enum lttng_kernel_instrumentation instrumentation;
321 union {
322 struct lttng_kprobe kprobe;
323 struct {
324 struct lttng_krp *lttng_krp;
325 char *symbol_name;
326 } kretprobe;
327 struct lttng_uprobe uprobe;
328 struct {
329 char *syscall_name;
330 enum lttng_syscall_entryexit entryexit;
331 enum lttng_syscall_abi abi;
332 } syscall;
333 } u;
334 struct list_head list; /* Event list in session */
335 unsigned int metadata_dumped:1;
336
337 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
338 struct list_head enablers_ref_head;
339 struct hlist_node hlist; /* session ht of events */
340 int registered; /* has reg'd tracepoint probe */
341 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
342 struct list_head bytecode_runtime_head;
343 int has_enablers_without_bytecode;
344 };
345
346 // FIXME: Really similar to lttng_event above. Could those be merged ?
347 struct lttng_event_notifier {
348 enum lttng_event_type evtype; /* First field. */
349 uint64_t user_token;
350 int enabled;
351 int registered; /* has reg'd tracepoint probe */
352 const struct lttng_event_desc *desc;
353 void *filter;
354 struct list_head list; /* event_notifier list in event_notifier group */
355
356 enum lttng_kernel_instrumentation instrumentation;
357 union {
358 struct lttng_kprobe kprobe;
359 struct lttng_uprobe uprobe;
360 struct lttng_syscall syscall;
361 } u;
362
363 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
364 struct list_head enablers_ref_head;
365 struct hlist_node hlist; /* session ht of event_notifiers */
366 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
367 struct list_head bytecode_runtime_head;
368 int has_enablers_without_bytecode;
369
370 void (*send_notification)(struct lttng_event_notifier *event_notifier);
371 struct lttng_event_notifier_group *group; /* Weak ref */
372 };
373
374 enum lttng_enabler_format_type {
375 LTTNG_ENABLER_FORMAT_STAR_GLOB,
376 LTTNG_ENABLER_FORMAT_NAME,
377 };
378
379 /*
380 * Enabler field, within whatever object is enabling an event. Target of
381 * backward reference.
382 */
383 struct lttng_enabler {
384 enum lttng_event_type evtype; /* First field. */
385
386 enum lttng_enabler_format_type format_type;
387
388 /* head list of struct lttng_ust_filter_bytecode_node */
389 struct list_head filter_bytecode_head;
390
391 struct lttng_kernel_event event_param;
392 unsigned int enabled:1;
393
394 uint64_t user_token; /* User-provided token. */
395 };
396
397 struct lttng_event_enabler {
398 struct lttng_enabler base;
399 struct list_head node; /* per-session list of enablers */
400 struct lttng_channel *chan;
401 /*
402 * Unused, but kept around to make it explicit that the tracer can do
403 * it.
404 */
405 struct lttng_ctx *ctx;
406 };
407
408 struct lttng_event_notifier_enabler {
409 struct lttng_enabler base;
410 struct list_head node; /* List of event_notifier enablers */
411 struct lttng_event_notifier_group *group;
412 };
413
414 static inline
415 struct lttng_enabler *lttng_event_enabler_as_enabler(
416 struct lttng_event_enabler *event_enabler)
417 {
418 return &event_enabler->base;
419 }
420
421 static inline
422 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
423 struct lttng_event_notifier_enabler *event_notifier_enabler)
424 {
425 return &event_notifier_enabler->base;
426 }
427
428 struct lttng_channel_ops {
429 struct channel *(*channel_create)(const char *name,
430 void *priv,
431 void *buf_addr,
432 size_t subbuf_size, size_t num_subbuf,
433 unsigned int switch_timer_interval,
434 unsigned int read_timer_interval);
435 void (*channel_destroy)(struct channel *chan);
436 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
437 int (*buffer_has_read_closed_stream)(struct channel *chan);
438 void (*buffer_read_close)(struct lib_ring_buffer *buf);
439 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
440 uint32_t event_id);
441 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
442 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
443 size_t len);
444 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
445 const void *src, size_t len);
446 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
447 int c, size_t len);
448 void (*event_strcpy)(struct lib_ring_buffer_ctx *ctx, const char *src,
449 size_t len);
450 void (*event_strcpy_from_user)(struct lib_ring_buffer_ctx *ctx,
451 const char __user *src, size_t len);
452 /*
453 * packet_avail_size returns the available size in the current
454 * packet. Note that the size returned is only a hint, since it
455 * may change due to concurrent writes.
456 */
457 size_t (*packet_avail_size)(struct channel *chan);
458 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
459 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
460 int (*is_finalized)(struct channel *chan);
461 int (*is_disabled)(struct channel *chan);
462 int (*timestamp_begin) (const struct lib_ring_buffer_config *config,
463 struct lib_ring_buffer *bufb,
464 uint64_t *timestamp_begin);
465 int (*timestamp_end) (const struct lib_ring_buffer_config *config,
466 struct lib_ring_buffer *bufb,
467 uint64_t *timestamp_end);
468 int (*events_discarded) (const struct lib_ring_buffer_config *config,
469 struct lib_ring_buffer *bufb,
470 uint64_t *events_discarded);
471 int (*content_size) (const struct lib_ring_buffer_config *config,
472 struct lib_ring_buffer *bufb,
473 uint64_t *content_size);
474 int (*packet_size) (const struct lib_ring_buffer_config *config,
475 struct lib_ring_buffer *bufb,
476 uint64_t *packet_size);
477 int (*stream_id) (const struct lib_ring_buffer_config *config,
478 struct lib_ring_buffer *bufb,
479 uint64_t *stream_id);
480 int (*current_timestamp) (const struct lib_ring_buffer_config *config,
481 struct lib_ring_buffer *bufb,
482 uint64_t *ts);
483 int (*sequence_number) (const struct lib_ring_buffer_config *config,
484 struct lib_ring_buffer *bufb,
485 uint64_t *seq);
486 int (*instance_id) (const struct lib_ring_buffer_config *config,
487 struct lib_ring_buffer *bufb,
488 uint64_t *id);
489 };
490
491 struct lttng_transport {
492 char *name;
493 struct module *owner;
494 struct list_head node;
495 struct lttng_channel_ops ops;
496 };
497
498 struct lttng_syscall_filter;
499
500 #define LTTNG_EVENT_HT_BITS 12
501 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
502
503 struct lttng_event_ht {
504 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
505 };
506
507 #define LTTNG_EVENT_NOTIFIER_HT_BITS 12
508 #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
509
510 struct lttng_event_notifier_ht {
511 struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE];
512 };
513
514 struct lttng_channel {
515 unsigned int id;
516 struct channel *chan; /* Channel buffers */
517 int enabled;
518 struct lttng_ctx *ctx;
519 /* Event ID management */
520 struct lttng_session *session;
521 struct file *file; /* File associated to channel */
522 unsigned int free_event_id; /* Next event ID to allocate */
523 struct list_head list; /* Channel list */
524 struct lttng_channel_ops *ops;
525 struct lttng_transport *transport;
526 struct lttng_event **sc_table; /* for syscall tracing */
527 struct lttng_event **compat_sc_table;
528 struct lttng_event **sc_exit_table; /* for syscall exit tracing */
529 struct lttng_event **compat_sc_exit_table;
530 struct lttng_event *sc_unknown; /* for unknown syscalls */
531 struct lttng_event *sc_compat_unknown;
532 struct lttng_event *sc_exit_unknown;
533 struct lttng_event *compat_sc_exit_unknown;
534 struct lttng_syscall_filter *sc_filter;
535 int header_type; /* 0: unset, 1: compact, 2: large */
536 enum channel_type channel_type;
537 int syscall_all;
538 unsigned int metadata_dumped:1,
539 sys_enter_registered:1,
540 sys_exit_registered:1,
541 tstate:1; /* Transient enable state */
542 };
543
544 struct lttng_metadata_stream {
545 void *priv; /* Ring buffer private data */
546 struct lttng_metadata_cache *metadata_cache;
547 unsigned int metadata_in; /* Bytes read from the cache */
548 unsigned int metadata_out; /* Bytes consumed from stream */
549 int finalized; /* Has channel been finalized */
550 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
551 struct list_head list; /* Stream list */
552 struct lttng_transport *transport;
553 uint64_t version; /* Current version of the metadata cache */
554 bool coherent; /* Stream in a coherent state */
555 };
556
557 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
558
559 struct lttng_dynamic_len_stack {
560 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
561 size_t offset;
562 };
563
564 DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
565
566 /*
567 * struct lttng_id_tracker declared in header due to deferencing of *v
568 * in RCU_INITIALIZER(v).
569 */
570 #define LTTNG_ID_HASH_BITS 6
571 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
572
573 enum tracker_type {
574 TRACKER_PID,
575 TRACKER_VPID,
576 TRACKER_UID,
577 TRACKER_VUID,
578 TRACKER_GID,
579 TRACKER_VGID,
580
581 TRACKER_UNKNOWN,
582 };
583
584 struct lttng_id_tracker_rcu {
585 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
586 };
587
588 struct lttng_id_tracker {
589 struct lttng_session *session;
590 enum tracker_type tracker_type;
591 struct lttng_id_tracker_rcu *p; /* RCU dereferenced. */
592 };
593
594 struct lttng_id_hash_node {
595 struct hlist_node hlist;
596 int id;
597 };
598
599 struct lttng_session {
600 int active; /* Is trace session active ? */
601 int been_active; /* Has trace session been active ? */
602 struct file *file; /* File associated to session */
603 struct list_head chan; /* Channel list head */
604 struct list_head events; /* Event list head */
605 struct list_head list; /* Session list */
606 unsigned int free_chan_id; /* Next chan ID to allocate */
607 uuid_le uuid; /* Trace session unique ID */
608 struct lttng_metadata_cache *metadata_cache;
609 struct lttng_id_tracker pid_tracker;
610 struct lttng_id_tracker vpid_tracker;
611 struct lttng_id_tracker uid_tracker;
612 struct lttng_id_tracker vuid_tracker;
613 struct lttng_id_tracker gid_tracker;
614 struct lttng_id_tracker vgid_tracker;
615 unsigned int metadata_dumped:1,
616 tstate:1; /* Transient enable state */
617 /* List of event enablers */
618 struct list_head enablers_head;
619 /* Hash table of events */
620 struct lttng_event_ht events_ht;
621 char name[LTTNG_KERNEL_SESSION_NAME_LEN];
622 char creation_time[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN];
623 };
624
625 struct lttng_event_notifier_group {
626 struct file *file; /* File associated to event notifier group */
627 struct file *notif_file; /* File used to expose notifications to userspace. */
628 struct list_head node; /* event notifier group list */
629 struct list_head enablers_head; /* List of enablers */
630 struct list_head event_notifiers_head; /* List of event notifier */
631 struct lttng_event_notifier_ht event_notifiers_ht; /* Hash table of event notifiers */
632 struct lttng_ctx *ctx; /* Contexts for filters. */
633 struct lttng_channel_ops *ops;
634 struct lttng_transport *transport;
635 struct channel *chan; /* Ring buffer channel for event notifier group. */
636 struct lib_ring_buffer *buf; /* Ring buffer for event notifier group. */
637 wait_queue_head_t read_wait;
638 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
639
640 struct list_head *event_notifier_syscall_dispatch;
641 struct list_head *event_notifier_compat_syscall_dispatch;
642
643 unsigned int syscall_all:1,
644 sys_enter_registered:1;
645 };
646
647 struct lttng_metadata_cache {
648 char *data; /* Metadata cache */
649 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
650 unsigned int metadata_written; /* Number of bytes written in metadata cache */
651 atomic_t producing; /* Metadata being produced (incomplete) */
652 struct kref refcount; /* Metadata cache usage */
653 struct list_head metadata_stream; /* Metadata stream list */
654 uuid_le uuid; /* Trace session unique ID (copy) */
655 struct mutex lock; /* Produce/consume lock */
656 uint64_t version; /* Current version of the metadata */
657 };
658
659 void lttng_lock_sessions(void);
660 void lttng_unlock_sessions(void);
661
662 struct list_head *lttng_get_probe_list_head(void);
663
664 struct lttng_event_enabler *lttng_event_enabler_create(
665 enum lttng_enabler_format_type format_type,
666 struct lttng_kernel_event *event_param,
667 struct lttng_channel *chan);
668
669 int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler);
670 int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler);
671 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
672 struct lttng_event_notifier_group *event_notifier_group,
673 enum lttng_enabler_format_type format_type,
674 struct lttng_kernel_event_notifier *event_notifier_param);
675
676 int lttng_event_notifier_enabler_enable(
677 struct lttng_event_notifier_enabler *event_notifier_enabler);
678 int lttng_event_notifier_enabler_disable(
679 struct lttng_event_notifier_enabler *event_notifier_enabler);
680 int lttng_fix_pending_events(void);
681 int lttng_fix_pending_event_notifiers(void);
682 int lttng_session_active(void);
683 bool lttng_event_notifier_active(void);
684
685 struct lttng_session *lttng_session_create(void);
686 int lttng_session_enable(struct lttng_session *session);
687 int lttng_session_disable(struct lttng_session *session);
688 void lttng_session_destroy(struct lttng_session *session);
689 int lttng_session_metadata_regenerate(struct lttng_session *session);
690 int lttng_session_statedump(struct lttng_session *session);
691 void metadata_cache_destroy(struct kref *kref);
692
693 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
694 void lttng_event_notifier_group_destroy(
695 struct lttng_event_notifier_group *event_notifier_group);
696
697 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
698 const char *transport_name,
699 void *buf_addr,
700 size_t subbuf_size, size_t num_subbuf,
701 unsigned int switch_timer_interval,
702 unsigned int read_timer_interval,
703 enum channel_type channel_type);
704 struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
705 int overwrite, void *buf_addr,
706 size_t subbuf_size, size_t num_subbuf,
707 unsigned int switch_timer_interval,
708 unsigned int read_timer_interval);
709
710 void lttng_metadata_channel_destroy(struct lttng_channel *chan);
711 struct lttng_event *lttng_event_create(struct lttng_channel *chan,
712 struct lttng_kernel_event *event_param,
713 void *filter,
714 const struct lttng_event_desc *event_desc,
715 enum lttng_kernel_instrumentation itype);
716 struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
717 struct lttng_kernel_event *event_param,
718 void *filter,
719 const struct lttng_event_desc *event_desc,
720 enum lttng_kernel_instrumentation itype);
721 struct lttng_event *lttng_event_compat_old_create(struct lttng_channel *chan,
722 struct lttng_kernel_old_event *old_event_param,
723 void *filter,
724 const struct lttng_event_desc *internal_desc);
725
726 struct lttng_event_notifier *lttng_event_notifier_create(
727 const struct lttng_event_desc *event_notifier_desc,
728 uint64_t id,
729 struct lttng_event_notifier_group *event_notifier_group,
730 struct lttng_kernel_event_notifier *event_notifier_param,
731 void *filter,
732 enum lttng_kernel_instrumentation itype);
733 struct lttng_event_notifier *_lttng_event_notifier_create(
734 const struct lttng_event_desc *event_notifier_desc,
735 uint64_t id,
736 struct lttng_event_notifier_group *event_notifier_group,
737 struct lttng_kernel_event_notifier *event_notifier_param,
738 void *filter,
739 enum lttng_kernel_instrumentation itype);
740
741 int lttng_channel_enable(struct lttng_channel *channel);
742 int lttng_channel_disable(struct lttng_channel *channel);
743 int lttng_event_enable(struct lttng_event *event);
744 int lttng_event_disable(struct lttng_event *event);
745
746 int lttng_event_notifier_enable(struct lttng_event_notifier *event_notifier);
747 int lttng_event_notifier_disable(struct lttng_event_notifier *event_notifier);
748
749 void lttng_transport_register(struct lttng_transport *transport);
750 void lttng_transport_unregister(struct lttng_transport *transport);
751
752 void synchronize_trace(void);
753 int lttng_abi_init(void);
754 int lttng_abi_compat_old_init(void);
755 void lttng_abi_exit(void);
756 void lttng_abi_compat_old_exit(void);
757
758 int lttng_probe_register(struct lttng_probe_desc *desc);
759 void lttng_probe_unregister(struct lttng_probe_desc *desc);
760 const struct lttng_event_desc *lttng_event_desc_get(const char *name);
761 void lttng_event_desc_put(const struct lttng_event_desc *desc);
762 int lttng_probes_init(void);
763 void lttng_probes_exit(void);
764
765 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
766 struct channel *chan, bool *coherent);
767
768 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
769 int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf);
770 void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu);
771 bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id);
772 int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id);
773 int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id);
774
775 int lttng_session_track_id(struct lttng_session *session,
776 enum tracker_type tracker_type, int id);
777 int lttng_session_untrack_id(struct lttng_session *session,
778 enum tracker_type tracker_type, int id);
779
780 int lttng_session_list_tracker_ids(struct lttng_session *session,
781 enum tracker_type tracker_type);
782
783 void lttng_clock_ref(void);
784 void lttng_clock_unref(void);
785
786 int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
787 struct lttng_enabler *enabler);
788
789 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
790 int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter);
791 int lttng_syscalls_unregister_event(struct lttng_channel *chan);
792 int lttng_syscalls_destroy_event(struct lttng_channel *chan);
793 int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
794 struct lttng_event *event);
795 int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
796 struct lttng_event *event);
797 long lttng_channel_syscall_mask(struct lttng_channel *channel,
798 struct lttng_kernel_syscall_mask __user *usyscall_mask);
799
800 int lttng_syscalls_register_event_notifier(
801 struct lttng_event_notifier_enabler *event_notifier_enabler,
802 void *filter);
803 int lttng_syscals_create_matching_event_notifiers(
804 struct lttng_event_notifier_enabler *event_notifier_enabler, void *filter);
805 int lttng_syscalls_unregister_event_notifier(struct lttng_event_notifier_group *group);
806 int lttng_syscall_filter_enable_event_notifier(struct lttng_event_notifier *event_notifier);
807 int lttng_syscall_filter_disable_event_notifier(struct lttng_event_notifier *event_notifier);
808 #else
809 static inline int lttng_syscalls_register_event(
810 struct lttng_channel *chan, void *filter)
811 {
812 return -ENOSYS;
813 }
814
815 static inline int lttng_syscalls_unregister_event(struct lttng_channel *chan)
816 {
817 return 0;
818 }
819
820 static inline int lttng_syscalls_destroy(struct lttng_channel *chan)
821 {
822 return 0;
823 }
824
825 static inline int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
826 struct lttng_event *event);
827 {
828 return -ENOSYS;
829 }
830
831 static inline int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
832 struct lttng_event *event);
833 {
834 return -ENOSYS;
835 }
836
837 static inline long lttng_channel_syscall_mask(struct lttng_channel *channel,
838 struct lttng_kernel_syscall_mask __user *usyscall_mask)
839 {
840 return -ENOSYS;
841 }
842
843 static inline int lttng_syscalls_register_event_notifier(
844 struct lttng_event_notifier_group *group, void *filter)
845 {
846 return -ENOSYS;
847 }
848
849 static inline int lttng_syscalls_unregister_event_notifier(
850 struct lttng_event_notifier_group *group)
851 {
852 return 0;
853 }
854
855 static inline int lttng_syscall_filter_enable_event_notifier(
856 struct lttng_event_notifier_group *group,
857 const char *name)
858 {
859 return -ENOSYS;
860 }
861
862 static inline int lttng_syscall_filter_disable_event_notifier(
863 struct lttng_event_notifier_group *group,
864 const char *name)
865 {
866 return -ENOSYS;
867 }
868
869 #endif
870
871 void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime);
872 int lttng_event_enabler_attach_bytecode(struct lttng_event_enabler *event_enabler,
873 struct lttng_kernel_filter_bytecode __user *bytecode);
874 int lttng_event_notifier_enabler_attach_bytecode(
875 struct lttng_event_notifier_enabler *event_notifier_enabler,
876 struct lttng_kernel_filter_bytecode __user *bytecode);
877
878 void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
879 struct lttng_ctx *ctx,
880 struct list_head *bytecode_runtime_head,
881 struct lttng_enabler *enabler);
882
883 int lttng_probes_init(void);
884
885 extern struct lttng_ctx *lttng_static_ctx;
886
887 int lttng_context_init(void);
888 void lttng_context_exit(void);
889 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
890 ssize_t lttng_append_context_index(struct lttng_ctx **ctx_p);
891 struct lttng_ctx_field *lttng_get_context_field_from_index(struct lttng_ctx *ctx,
892 size_t index);
893 void lttng_context_update(struct lttng_ctx *ctx);
894 int lttng_find_context(struct lttng_ctx *ctx, const char *name);
895 int lttng_get_context_index(struct lttng_ctx *ctx, const char *name);
896 void lttng_remove_context_field(struct lttng_ctx **ctx,
897 struct lttng_ctx_field *field);
898 void lttng_remove_context_field_index(struct lttng_ctx **ctx_p, size_t index);
899 void lttng_destroy_context(struct lttng_ctx *ctx);
900 int lttng_add_pid_to_ctx(struct lttng_ctx **ctx);
901 int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx);
902 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
903 int lttng_add_prio_to_ctx(struct lttng_ctx **ctx);
904 int lttng_add_nice_to_ctx(struct lttng_ctx **ctx);
905 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
906 int lttng_add_tid_to_ctx(struct lttng_ctx **ctx);
907 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
908 int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx);
909 int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx);
910 int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx);
911 int lttng_add_interruptible_to_ctx(struct lttng_ctx **ctx);
912 int lttng_add_need_reschedule_to_ctx(struct lttng_ctx **ctx);
913 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
914 int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx);
915 #else
916 static inline
917 int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx)
918 {
919 return -ENOSYS;
920 }
921 #endif
922 #ifdef CONFIG_PREEMPT_RT_FULL
923 int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx);
924 #else
925 static inline
926 int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx)
927 {
928 return -ENOSYS;
929 }
930 #endif
931
932 int lttng_add_callstack_to_ctx(struct lttng_ctx **ctx, int type);
933
934 #if defined(CONFIG_CGROUPS) && \
935 ((LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)) || \
936 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
937 int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx);
938 #else
939 static inline
940 int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx)
941 {
942 return -ENOSYS;
943 }
944 #endif
945
946 #if defined(CONFIG_IPC_NS) && \
947 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
948 int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx);
949 #else
950 static inline
951 int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx)
952 {
953 return -ENOSYS;
954 }
955 #endif
956
957 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
958 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
959 int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx);
960 #else
961 static inline
962 int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx)
963 {
964 return -ENOSYS;
965 }
966 #endif
967
968 #if defined(CONFIG_NET_NS) && \
969 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
970 int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx);
971 #else
972 static inline
973 int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx)
974 {
975 return -ENOSYS;
976 }
977 #endif
978
979 #if defined(CONFIG_PID_NS) && \
980 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
981 int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx);
982 #else
983 static inline
984 int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx)
985 {
986 return -ENOSYS;
987 }
988 #endif
989
990 #if defined(CONFIG_USER_NS) && \
991 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
992 int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx);
993 #else
994 static inline
995 int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx)
996 {
997 return -ENOSYS;
998 }
999 #endif
1000
1001 #if defined(CONFIG_UTS_NS) && \
1002 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
1003 int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx);
1004 #else
1005 static inline
1006 int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx)
1007 {
1008 return -ENOSYS;
1009 }
1010 #endif
1011
1012 #if defined(CONFIG_TIME_NS) && \
1013 (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
1014 int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx);
1015 #else
1016 static inline
1017 int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx)
1018 {
1019 return -ENOSYS;
1020 }
1021 #endif
1022
1023 int lttng_add_uid_to_ctx(struct lttng_ctx **ctx);
1024 int lttng_add_euid_to_ctx(struct lttng_ctx **ctx);
1025 int lttng_add_suid_to_ctx(struct lttng_ctx **ctx);
1026 int lttng_add_gid_to_ctx(struct lttng_ctx **ctx);
1027 int lttng_add_egid_to_ctx(struct lttng_ctx **ctx);
1028 int lttng_add_sgid_to_ctx(struct lttng_ctx **ctx);
1029 int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx);
1030 int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx);
1031 int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx);
1032 int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx);
1033 int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx);
1034 int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx);
1035
1036 #if defined(CONFIG_PERF_EVENTS)
1037 int lttng_add_perf_counter_to_ctx(uint32_t type,
1038 uint64_t config,
1039 const char *name,
1040 struct lttng_ctx **ctx);
1041 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
1042 struct lttng_cpuhp_node *node);
1043 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
1044 struct lttng_cpuhp_node *node);
1045 #else
1046 static inline
1047 int lttng_add_perf_counter_to_ctx(uint32_t type,
1048 uint64_t config,
1049 const char *name,
1050 struct lttng_ctx **ctx)
1051 {
1052 return -ENOSYS;
1053 }
1054 static inline
1055 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
1056 struct lttng_cpuhp_node *node)
1057 {
1058 return 0;
1059 }
1060 static inline
1061 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
1062 struct lttng_cpuhp_node *node)
1063 {
1064 return 0;
1065 }
1066 #endif
1067
1068 int lttng_logger_init(void);
1069 void lttng_logger_exit(void);
1070
1071 extern int lttng_statedump_start(struct lttng_session *session);
1072
1073 #ifdef CONFIG_KPROBES
1074 int lttng_kprobes_register_event(const char *name,
1075 const char *symbol_name,
1076 uint64_t offset,
1077 uint64_t addr,
1078 struct lttng_event *event);
1079 void lttng_kprobes_unregister_event(struct lttng_event *event);
1080 void lttng_kprobes_destroy_event_private(struct lttng_event *event);
1081 int lttng_kprobes_register_event_notifier(const char *symbol_name,
1082 uint64_t offset,
1083 uint64_t addr,
1084 struct lttng_event_notifier *event_notifier);
1085 void lttng_kprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier);
1086 void lttng_kprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier);
1087 #else
1088 static inline
1089 int lttng_kprobes_register_event(const char *name,
1090 const char *symbol_name,
1091 uint64_t offset,
1092 uint64_t addr,
1093 struct lttng_event *event)
1094 {
1095 return -ENOSYS;
1096 }
1097
1098 static inline
1099 void lttng_kprobes_unregister_event(struct lttng_event *event)
1100 {
1101 }
1102
1103 static inline
1104 void lttng_kprobes_destroy_event_private(struct lttng_event *event)
1105 {
1106 }
1107
1108 static inline
1109 int lttng_kprobes_register_event_notifier(const char *symbol_name,
1110 uint64_t offset,
1111 uint64_t addr,
1112 struct lttng_event_notifier *event_notifier)
1113 {
1114 return -ENOSYS;
1115 }
1116
1117 static inline
1118 void lttng_kprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier)
1119 {
1120 }
1121
1122 static inline
1123 void lttng_kprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier)
1124 {
1125 }
1126 #endif
1127
1128 int lttng_event_add_callsite(struct lttng_event *event,
1129 struct lttng_kernel_event_callsite *callsite);
1130
1131 int lttng_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1132 struct lttng_kernel_event_callsite *callsite);
1133
1134 #ifdef CONFIG_UPROBES
1135 int lttng_uprobes_register_event(const char *name,
1136 int fd, struct lttng_event *event);
1137 int lttng_uprobes_event_add_callsite(struct lttng_event *event,
1138 struct lttng_kernel_event_callsite *callsite);
1139 void lttng_uprobes_unregister_event(struct lttng_event *event);
1140 void lttng_uprobes_destroy_event_private(struct lttng_event *event);
1141 int lttng_uprobes_register_event_notifier(const char *name,
1142 int fd, struct lttng_event_notifier *event_notifier);
1143 int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1144 struct lttng_kernel_event_callsite *callsite);
1145 void lttng_uprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier);
1146 void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier);
1147 #else
1148 static inline
1149 int lttng_uprobes_register_event(const char *name,
1150 int fd, struct lttng_event *event)
1151 {
1152 return -ENOSYS;
1153 }
1154
1155 static inline
1156 int lttng_uprobes_event_add_callsite(struct lttng_event *event,
1157 struct lttng_kernel_event_callsite *callsite)
1158 {
1159 return -ENOSYS;
1160 }
1161
1162 static inline
1163 void lttng_uprobes_unregister_event(struct lttng_event *event)
1164 {
1165 }
1166
1167 static inline
1168 void lttng_uprobes_destroy_event_private(struct lttng_event *event)
1169 {
1170 }
1171
1172 static inline
1173 int lttng_uprobes_register_event_notifier(const char *name,
1174 int fd, struct lttng_event_notifier *event_notifier)
1175 {
1176 return -ENOSYS;
1177 }
1178
1179 static inline
1180 int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier,
1181 struct lttng_kernel_event_callsite *callsite)
1182 {
1183 return -ENOSYS;
1184 }
1185
1186 static inline
1187 void lttng_uprobes_unregister_event_notifier(struct lttng_event_notifier *event_notifier)
1188 {
1189 }
1190
1191 static inline
1192 void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier)
1193 {
1194 }
1195 #endif
1196
1197 #ifdef CONFIG_KRETPROBES
1198 int lttng_kretprobes_register(const char *name,
1199 const char *symbol_name,
1200 uint64_t offset,
1201 uint64_t addr,
1202 struct lttng_event *event_entry,
1203 struct lttng_event *event_exit);
1204 void lttng_kretprobes_unregister(struct lttng_event *event);
1205 void lttng_kretprobes_destroy_private(struct lttng_event *event);
1206 int lttng_kretprobes_event_enable_state(struct lttng_event *event,
1207 int enable);
1208 #else
1209 static inline
1210 int lttng_kretprobes_register(const char *name,
1211 const char *symbol_name,
1212 uint64_t offset,
1213 uint64_t addr,
1214 struct lttng_event *event_entry,
1215 struct lttng_event *event_exit)
1216 {
1217 return -ENOSYS;
1218 }
1219
1220 static inline
1221 void lttng_kretprobes_unregister(struct lttng_event *event)
1222 {
1223 }
1224
1225 static inline
1226 void lttng_kretprobes_destroy_private(struct lttng_event *event)
1227 {
1228 }
1229
1230 static inline
1231 int lttng_kretprobes_event_enable_state(struct lttng_event *event,
1232 int enable)
1233 {
1234 return -ENOSYS;
1235 }
1236 #endif
1237
1238 int lttng_calibrate(struct lttng_kernel_calibrate *calibrate);
1239
1240 extern const struct file_operations lttng_tracepoint_list_fops;
1241 extern const struct file_operations lttng_syscall_list_fops;
1242
1243 #define TRACEPOINT_HAS_DATA_ARG
1244
1245 static inline bool lttng_is_bytewise_integer(const struct lttng_type *type)
1246 {
1247 if (type->atype != atype_integer)
1248 return false;
1249 switch (type->u.integer.size) {
1250 case 8: /* Fall-through. */
1251 case 16: /* Fall-through. */
1252 case 32: /* Fall-through. */
1253 case 64:
1254 break;
1255 default:
1256 return false;
1257 }
1258 return true;
1259 }
1260
1261 #endif /* _LTTNG_EVENTS_H */
This page took 0.091021 seconds and 4 git commands to generate.