Refactoring: move event list node field to common structure
[lttng-modules.git] / include / lttng / events-internal.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng/events-internal.h
4 *
5 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8 #ifndef _LTTNG_EVENTS_INTERNAL_H
9 #define _LTTNG_EVENTS_INTERNAL_H
10
11 #include <wrapper/compiler_attributes.h>
12
13 #include <lttng/events.h>
14
15 struct lttng_syscall_filter;
16 struct lttng_metadata_cache;
17 struct perf_event;
18 struct perf_event_attr;
19 struct lttng_kernel_ring_buffer_config;
20
21 enum lttng_enabler_format_type {
22 LTTNG_ENABLER_FORMAT_STAR_GLOB,
23 LTTNG_ENABLER_FORMAT_NAME,
24 };
25
26 enum channel_type {
27 PER_CPU_CHANNEL,
28 METADATA_CHANNEL,
29 };
30
31 /*
32 * Objects in a linked-list of enablers, owned by an event.
33 */
34 struct lttng_enabler_ref {
35 struct list_head node; /* enabler ref list */
36 struct lttng_event_enabler_common *ref; /* backward ref */
37 };
38
39 struct lttng_krp; /* Kretprobe handling */
40
41 struct lttng_uprobe_handler {
42 struct lttng_kernel_event_common *event;
43 loff_t offset;
44 struct uprobe_consumer up_consumer;
45 struct list_head node;
46 };
47
48 struct lttng_kprobe {
49 struct kprobe kp;
50 char *symbol_name;
51 };
52
53 struct lttng_uprobe {
54 struct inode *inode;
55 struct list_head head;
56 };
57
58 enum lttng_syscall_entryexit {
59 LTTNG_SYSCALL_ENTRY,
60 LTTNG_SYSCALL_EXIT,
61 };
62
63 enum lttng_syscall_abi {
64 LTTNG_SYSCALL_ABI_NATIVE,
65 LTTNG_SYSCALL_ABI_COMPAT,
66 };
67
68 struct lttng_kernel_event_common_private {
69 struct lttng_kernel_event_common *pub; /* Public event interface */
70
71 const struct lttng_kernel_event_desc *desc;
72 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
73 struct list_head enablers_ref_head;
74 int registered; /* has reg'd tracepoint probe */
75 uint64_t user_token;
76
77 int has_enablers_without_filter_bytecode;
78 /* list of struct lttng_kernel_bytecode_runtime, sorted by seqnum */
79 struct list_head filter_bytecode_runtime_head;
80
81 struct hlist_node hlist_node; /* node in events hash table */
82 struct list_head node; /* node in event list */
83
84 enum lttng_kernel_abi_instrumentation instrumentation;
85 /* Selected by instrumentation */
86 union {
87 struct lttng_kprobe kprobe;
88 struct lttng_uprobe uprobe;
89 struct {
90 struct lttng_krp *lttng_krp;
91 char *symbol_name;
92 } kretprobe;
93 struct {
94 enum lttng_syscall_entryexit entryexit;
95 enum lttng_syscall_abi abi;
96 struct hlist_node node; /* chain registered syscall event_notifier */
97 unsigned int syscall_id;
98 } syscall;
99 } u;
100 };
101
102 struct lttng_kernel_event_recorder_private {
103 struct lttng_kernel_event_common_private parent;
104
105 struct lttng_kernel_event_recorder *pub; /* Public event interface */
106 struct lttng_kernel_ctx *ctx;
107 unsigned int id;
108 unsigned int metadata_dumped:1;
109 };
110
111 struct lttng_kernel_event_notifier_private {
112 struct lttng_kernel_event_common_private parent;
113
114 struct lttng_kernel_event_notifier *pub; /* Public event notifier interface */
115 struct lttng_event_notifier_group *group; /* weak ref */
116 size_t num_captures; /* Needed to allocate the msgpack array. */
117 uint64_t error_counter_index;
118 struct list_head capture_bytecode_runtime_head;
119 };
120
121 struct lttng_kernel_syscall_table {
122 unsigned int sys_enter_registered:1,
123 sys_exit_registered:1;
124
125 struct hlist_head *syscall_dispatch; /* for syscall tracing */
126 struct hlist_head *compat_syscall_dispatch;
127 struct hlist_head *syscall_exit_dispatch; /* for syscall exit tracing */
128 struct hlist_head *compat_syscall_exit_dispatch;
129
130 /*
131 * Combining all unknown syscall events works as long as they
132 * are only matched by "all" syscalls enablers, but will require
133 * a design change when we allow matching by syscall number, for
134 * instance by allocating sc_tables accomodating NR_syscalls
135 * entries.
136 */
137 struct hlist_head unknown_syscall_dispatch; /* for unknown syscalls */
138 struct hlist_head compat_unknown_syscall_dispatch;
139 struct hlist_head unknown_syscall_exit_dispatch;
140 struct hlist_head compat_unknown_syscall_exit_dispatch;
141
142 struct lttng_syscall_filter *sc_filter;
143 int syscall_all_entry;
144 int syscall_all_exit;
145 };
146
147 struct lttng_kernel_channel_common_private {
148 struct lttng_kernel_channel_common *pub;
149
150 struct file *file; /* File associated to channel */
151 unsigned int tstate:1; /* Transient enable state */
152
153 struct lttng_kernel_syscall_table syscall_table;
154 };
155
156 struct lttng_kernel_channel_buffer_private {
157 struct lttng_kernel_channel_common_private parent;
158
159 struct lttng_kernel_channel_buffer *pub;
160
161 unsigned int id; /* Channel ID */
162 unsigned int free_event_id; /* Next event ID to allocate */
163 int header_type; /* 0: unset, 1: compact, 2: large */
164
165 enum channel_type channel_type;
166 struct lttng_kernel_ctx *ctx;
167 struct lttng_kernel_ring_buffer_channel *rb_chan; /* Ring buffer channel */
168 unsigned int metadata_dumped:1;
169 struct list_head node; /* Channel list in session */
170 struct lttng_transport *transport;
171 };
172
173 enum lttng_kernel_bytecode_interpreter_ret {
174 LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR = -1,
175 LTTNG_KERNEL_BYTECODE_INTERPRETER_OK = 0,
176 };
177
178 enum lttng_kernel_bytecode_filter_result {
179 LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT = 0,
180 LTTNG_KERNEL_BYTECODE_FILTER_REJECT = 1,
181 };
182
183 struct lttng_kernel_bytecode_filter_ctx {
184 enum lttng_kernel_bytecode_filter_result result;
185 };
186
187 struct lttng_interpreter_output;
188
189 enum lttng_kernel_bytecode_type {
190 LTTNG_KERNEL_BYTECODE_TYPE_FILTER,
191 LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE,
192 };
193
194 enum lttng_kernel_event_enabler_type {
195 LTTNG_EVENT_ENABLER_TYPE_RECORDER,
196 LTTNG_EVENT_ENABLER_TYPE_NOTIFIER,
197 };
198
199 struct lttng_kernel_bytecode_node {
200 enum lttng_kernel_bytecode_type type;
201 struct list_head node;
202 struct lttng_event_enabler_common *enabler;
203 struct {
204 uint32_t len;
205 uint32_t reloc_offset;
206 uint64_t seqnum;
207 char data[];
208 } bc;
209 };
210
211 struct lttng_kernel_bytecode_runtime {
212 /* Associated bytecode */
213 enum lttng_kernel_bytecode_type type;
214 struct lttng_kernel_bytecode_node *bc;
215 int (*interpreter_func)(struct lttng_kernel_bytecode_runtime *kernel_bytecode,
216 const char *interpreter_stack_data,
217 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
218 void *caller_ctx);
219 int link_failed;
220 struct list_head node; /* list of bytecode runtime in event */
221 struct lttng_kernel_ctx *ctx;
222 };
223
224 /*
225 * Enabler field, within whatever object is enabling an event. Target of
226 * backward reference.
227 */
228 struct lttng_event_enabler_common {
229 enum lttng_kernel_event_enabler_type enabler_type;
230 enum lttng_enabler_format_type format_type;
231
232 /* head list of struct lttng_kernel_bytecode_node */
233 struct list_head filter_bytecode_head;
234
235 struct lttng_kernel_abi_event event_param;
236 unsigned int enabled:1;
237
238 uint64_t user_token; /* User-provided token. */
239 };
240
241 struct lttng_event_recorder_enabler {
242 struct lttng_event_enabler_common parent;
243 struct list_head node; /* per-session list of enablers */
244 bool published; /* published in per-session list. */
245 struct lttng_kernel_channel_buffer *chan;
246 };
247
248 struct lttng_event_notifier_enabler {
249 struct lttng_event_enabler_common parent;
250 uint64_t error_counter_index;
251 struct list_head node; /* List of event_notifier enablers */
252 bool published; /* published in group list. */
253 struct lttng_event_notifier_group *group;
254
255 /* head list of struct lttng_kernel_bytecode_node */
256 struct list_head capture_bytecode_head;
257 uint64_t num_captures;
258 };
259
260 struct lttng_ctx_value {
261 union {
262 int64_t s64;
263 const char *str;
264 double d;
265 } u;
266 };
267
268 /*
269 * We need to keep this perf counter field separately from struct
270 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
271 */
272 struct lttng_perf_counter_field {
273 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
274 struct lttng_cpuhp_node cpuhp_prepare;
275 struct lttng_cpuhp_node cpuhp_online;
276 #else
277 struct notifier_block nb;
278 int hp_enable;
279 #endif
280 struct perf_event_attr *attr;
281 struct perf_event **e; /* per-cpu array */
282 char *name;
283 struct lttng_kernel_event_field *event_field;
284 };
285
286 struct lttng_kernel_ctx_field {
287 const struct lttng_kernel_event_field *event_field;
288 size_t (*get_size)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
289 size_t offset);
290 void (*record)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
291 struct lttng_kernel_ring_buffer_ctx *ctx,
292 struct lttng_kernel_channel_buffer *chan);
293 void (*get_value)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
294 struct lttng_ctx_value *value);
295 void (*destroy)(void *priv);
296 void *priv;
297 };
298
299 struct lttng_kernel_ctx {
300 struct lttng_kernel_ctx_field *fields;
301 unsigned int nr_fields;
302 unsigned int allocated_fields;
303 size_t largest_align; /* in bytes */
304 };
305
306 struct lttng_metadata_cache {
307 char *data; /* Metadata cache */
308 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
309 unsigned int metadata_written; /* Number of bytes written in metadata cache */
310 atomic_t producing; /* Metadata being produced (incomplete) */
311 struct kref refcount; /* Metadata cache usage */
312 struct list_head metadata_stream; /* Metadata stream list */
313 uuid_le uuid; /* Trace session unique ID (copy) */
314 struct mutex lock; /* Produce/consume lock */
315 uint64_t version; /* Current version of the metadata */
316 };
317
318 struct lttng_metadata_stream {
319 void *priv; /* Ring buffer private data */
320 struct lttng_metadata_cache *metadata_cache;
321 unsigned int metadata_in; /* Bytes read from the cache */
322 unsigned int metadata_out; /* Bytes consumed from stream */
323 int finalized; /* Has channel been finalized */
324 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
325 struct list_head list; /* Stream list */
326 struct lttng_transport *transport;
327 uint64_t version; /* Current version of the metadata cache */
328 bool coherent; /* Stream in a coherent state */
329 };
330
331 struct lttng_kernel_channel_buffer_ops_private {
332 struct lttng_kernel_channel_buffer_ops *pub; /* Public channel buffer ops interface */
333
334 struct lttng_kernel_ring_buffer_channel *(*channel_create)(const char *name,
335 void *priv,
336 void *buf_addr,
337 size_t subbuf_size, size_t num_subbuf,
338 unsigned int switch_timer_interval,
339 unsigned int read_timer_interval);
340 void (*channel_destroy)(struct lttng_kernel_ring_buffer_channel *chan);
341 struct lttng_kernel_ring_buffer *(*buffer_read_open)(struct lttng_kernel_ring_buffer_channel *chan);
342 int (*buffer_has_read_closed_stream)(struct lttng_kernel_ring_buffer_channel *chan);
343 void (*buffer_read_close)(struct lttng_kernel_ring_buffer *buf);
344 /*
345 * packet_avail_size returns the available size in the current
346 * packet. Note that the size returned is only a hint, since it
347 * may change due to concurrent writes.
348 */
349 size_t (*packet_avail_size)(struct lttng_kernel_ring_buffer_channel *chan);
350 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct lttng_kernel_ring_buffer_channel *chan, int cpu);
351 wait_queue_head_t *(*get_hp_wait_queue)(struct lttng_kernel_ring_buffer_channel *chan);
352 int (*is_finalized)(struct lttng_kernel_ring_buffer_channel *chan);
353 int (*is_disabled)(struct lttng_kernel_ring_buffer_channel *chan);
354 int (*timestamp_begin) (const struct lttng_kernel_ring_buffer_config *config,
355 struct lttng_kernel_ring_buffer *bufb,
356 uint64_t *timestamp_begin);
357 int (*timestamp_end) (const struct lttng_kernel_ring_buffer_config *config,
358 struct lttng_kernel_ring_buffer *bufb,
359 uint64_t *timestamp_end);
360 int (*events_discarded) (const struct lttng_kernel_ring_buffer_config *config,
361 struct lttng_kernel_ring_buffer *bufb,
362 uint64_t *events_discarded);
363 int (*content_size) (const struct lttng_kernel_ring_buffer_config *config,
364 struct lttng_kernel_ring_buffer *bufb,
365 uint64_t *content_size);
366 int (*packet_size) (const struct lttng_kernel_ring_buffer_config *config,
367 struct lttng_kernel_ring_buffer *bufb,
368 uint64_t *packet_size);
369 int (*stream_id) (const struct lttng_kernel_ring_buffer_config *config,
370 struct lttng_kernel_ring_buffer *bufb,
371 uint64_t *stream_id);
372 int (*current_timestamp) (const struct lttng_kernel_ring_buffer_config *config,
373 struct lttng_kernel_ring_buffer *bufb,
374 uint64_t *ts);
375 int (*sequence_number) (const struct lttng_kernel_ring_buffer_config *config,
376 struct lttng_kernel_ring_buffer *bufb,
377 uint64_t *seq);
378 int (*instance_id) (const struct lttng_kernel_ring_buffer_config *config,
379 struct lttng_kernel_ring_buffer *bufb,
380 uint64_t *id);
381 };
382
383 struct lttng_counter_ops {
384 struct lib_counter *(*counter_create)(size_t nr_dimensions,
385 const size_t *max_nr_elem, /* for each dimension */
386 int64_t global_sum_step);
387 void (*counter_destroy)(struct lib_counter *counter);
388 int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes,
389 int64_t v);
390 /*
391 * counter_read reads a specific cpu's counter if @cpu >= 0, or
392 * the global aggregation counter if @cpu == -1.
393 */
394 int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
395 int64_t *value, bool *overflow, bool *underflow);
396 /*
397 * counter_aggregate returns the total sum of all per-cpu counters and
398 * the global aggregation counter.
399 */
400 int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes,
401 int64_t *value, bool *overflow, bool *underflow);
402 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
403 };
404
405 struct lttng_counter {
406 struct file *file; /* File associated to counter. */
407 struct file *owner;
408 struct lttng_counter_transport *transport;
409 struct lib_counter *counter;
410 struct lttng_counter_ops *ops;
411 };
412
413 #define LTTNG_EVENT_HT_BITS 12
414 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
415
416 struct lttng_event_ht {
417 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
418 };
419
420 struct lttng_event_notifier_group {
421 struct file *file; /* File associated to event notifier group */
422 struct file *notif_file; /* File used to expose notifications to userspace. */
423 struct list_head node; /* event notifier group list */
424 struct list_head enablers_head; /* List of enablers */
425 struct list_head event_notifiers_head; /* List of event notifier */
426 struct lttng_event_ht events_ht; /* Hash table of event notifiers */
427 struct lttng_kernel_channel_buffer_ops *ops;
428 struct lttng_transport *transport;
429 struct lttng_kernel_ring_buffer_channel *chan; /* Ring buffer channel for event notifier group. */
430 struct lttng_kernel_ring_buffer *buf; /* Ring buffer for event notifier group. */
431 wait_queue_head_t read_wait;
432 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
433
434 struct lttng_kernel_syscall_table syscall_table;
435
436 struct lttng_counter *error_counter;
437 size_t error_counter_len;
438 };
439
440 struct lttng_transport {
441 char *name;
442 struct module *owner;
443 struct list_head node;
444 struct lttng_kernel_channel_buffer_ops ops;
445 };
446
447 struct lttng_counter_transport {
448 char *name;
449 struct module *owner;
450 struct list_head node;
451 struct lttng_counter_ops ops;
452 };
453
454 struct lttng_kernel_session_private {
455 struct lttng_kernel_session *pub; /* Public session interface */
456
457 int been_active; /* Has trace session been active ? */
458 struct file *file; /* File associated to session */
459 struct list_head chan; /* Channel list head */
460 struct list_head events; /* Event list head */
461 struct list_head list; /* Session list */
462 unsigned int free_chan_id; /* Next chan ID to allocate */
463 uuid_le uuid; /* Trace session unique ID */
464 struct lttng_metadata_cache *metadata_cache;
465 unsigned int metadata_dumped:1,
466 tstate:1; /* Transient enable state */
467 /* List of event enablers */
468 struct list_head enablers_head;
469 /* Hash table of events */
470 struct lttng_event_ht events_ht;
471 char name[LTTNG_KERNEL_ABI_SESSION_NAME_LEN];
472 char creation_time[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN];
473 };
474
475 struct lttng_id_hash_node {
476 struct hlist_node hlist;
477 int id;
478 };
479
480 enum tracker_type {
481 TRACKER_PID,
482 TRACKER_VPID,
483 TRACKER_UID,
484 TRACKER_VUID,
485 TRACKER_GID,
486 TRACKER_VGID,
487
488 TRACKER_UNKNOWN,
489 };
490
491 struct lttng_kernel_id_tracker_private {
492 struct lttng_kernel_id_tracker *pub; /* Public interface */
493
494 struct lttng_kernel_session *session;
495 enum tracker_type tracker_type;
496 };
497
498 extern struct lttng_kernel_ctx *lttng_static_ctx;
499
500 static inline
501 const struct lttng_kernel_type_integer *lttng_kernel_get_type_integer(const struct lttng_kernel_type_common *type)
502 {
503 if (type->type != lttng_kernel_type_integer)
504 return NULL;
505 return container_of(type, const struct lttng_kernel_type_integer, parent);
506 }
507
508 static inline
509 const struct lttng_kernel_type_string *lttng_kernel_get_type_string(const struct lttng_kernel_type_common *type)
510 {
511 if (type->type != lttng_kernel_type_string)
512 return NULL;
513 return container_of(type, const struct lttng_kernel_type_string, parent);
514 }
515
516 static inline
517 const struct lttng_kernel_type_enum *lttng_kernel_get_type_enum(const struct lttng_kernel_type_common *type)
518 {
519 if (type->type != lttng_kernel_type_enum)
520 return NULL;
521 return container_of(type, const struct lttng_kernel_type_enum, parent);
522 }
523
524 static inline
525 const struct lttng_kernel_type_array *lttng_kernel_get_type_array(const struct lttng_kernel_type_common *type)
526 {
527 if (type->type != lttng_kernel_type_array)
528 return NULL;
529 return container_of(type, const struct lttng_kernel_type_array, parent);
530 }
531
532 static inline
533 const struct lttng_kernel_type_sequence *lttng_kernel_get_type_sequence(const struct lttng_kernel_type_common *type)
534 {
535 if (type->type != lttng_kernel_type_sequence)
536 return NULL;
537 return container_of(type, const struct lttng_kernel_type_sequence, parent);
538 }
539
540 static inline
541 const struct lttng_kernel_type_struct *lttng_kernel_get_type_struct(const struct lttng_kernel_type_common *type)
542 {
543 if (type->type != lttng_kernel_type_struct)
544 return NULL;
545 return container_of(type, const struct lttng_kernel_type_struct, parent);
546 }
547
548 static inline
549 const struct lttng_kernel_type_variant *lttng_kernel_get_type_variant(const struct lttng_kernel_type_common *type)
550 {
551 if (type->type != lttng_kernel_type_variant)
552 return NULL;
553 return container_of(type, const struct lttng_kernel_type_variant, parent);
554 }
555
556 static inline bool lttng_kernel_type_is_bytewise_integer(const struct lttng_kernel_type_common *type)
557 {
558 const struct lttng_kernel_type_integer *type_integer = lttng_kernel_get_type_integer(type);
559
560 if (!type_integer)
561 return false;
562 switch (type_integer->size) {
563 case 8:
564 lttng_fallthrough;
565 case 16:
566 lttng_fallthrough;
567 case 32:
568 lttng_fallthrough;
569 case 64:
570 break;
571 default:
572 return false;
573 }
574 return true;
575 }
576
577 int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common *event,
578 const char *interpreter_stack_data,
579 struct lttng_kernel_probe_ctx *probe_ctx,
580 void *event_filter_ctx);
581
582 static inline
583 struct lttng_event_enabler_common *lttng_event_recorder_enabler_as_enabler(
584 struct lttng_event_recorder_enabler *event_recorder_enabler)
585 {
586 return &event_recorder_enabler->parent;
587 }
588
589 static inline
590 struct lttng_event_enabler_common *lttng_event_notifier_enabler_as_enabler(
591 struct lttng_event_notifier_enabler *event_notifier_enabler)
592 {
593 return &event_notifier_enabler->parent;
594 }
595
596 static inline
597 struct lttng_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common *event_enabler)
598 {
599 switch (event_enabler->enabler_type) {
600 case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
601 {
602 struct lttng_event_recorder_enabler *event_recorder_enabler =
603 container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
604 return &event_recorder_enabler->chan->parent.session->priv->events_ht;
605 }
606 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
607 {
608 struct lttng_event_notifier_enabler *event_notifier_enabler =
609 container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
610 return &event_notifier_enabler->group->events_ht;
611 }
612 default:
613 return NULL;
614 }
615 }
616
617 int lttng_context_init(void);
618 void lttng_context_exit(void);
619 int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
620 const struct lttng_kernel_ctx_field *f);
621 void lttng_kernel_context_remove_last(struct lttng_kernel_ctx **ctx_p);
622 struct lttng_kernel_ctx_field *lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx *ctx,
623 size_t index);
624 int lttng_kernel_find_context(struct lttng_kernel_ctx *ctx, const char *name);
625 int lttng_kernel_get_context_index(struct lttng_kernel_ctx *ctx, const char *name);
626 void lttng_kernel_destroy_context(struct lttng_kernel_ctx *ctx);
627 int lttng_add_pid_to_ctx(struct lttng_kernel_ctx **ctx);
628 int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx **ctx);
629 int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx);
630 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx);
631 int lttng_add_nice_to_ctx(struct lttng_kernel_ctx **ctx);
632 int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx **ctx);
633 int lttng_add_tid_to_ctx(struct lttng_kernel_ctx **ctx);
634 int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx **ctx);
635 int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx **ctx);
636 int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx);
637 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx **ctx);
638 int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx **ctx);
639 int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx **ctx);
640 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
641 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx);
642 #else
643 static inline
644 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
645 {
646 return -ENOSYS;
647 }
648 #endif
649 #ifdef CONFIG_PREEMPT_RT_FULL
650 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx);
651 #else
652 static inline
653 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx)
654 {
655 return -ENOSYS;
656 }
657 #endif
658
659 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx **ctx, int type);
660
661 #if defined(CONFIG_CGROUPS) && \
662 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
663 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
664 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx);
665 #else
666 static inline
667 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx)
668 {
669 return -ENOSYS;
670 }
671 #endif
672
673 #if defined(CONFIG_IPC_NS) && \
674 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
675 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx);
676 #else
677 static inline
678 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx)
679 {
680 return -ENOSYS;
681 }
682 #endif
683
684 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
685 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
686 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx);
687 #else
688 static inline
689 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx)
690 {
691 return -ENOSYS;
692 }
693 #endif
694
695 #if defined(CONFIG_NET_NS) && \
696 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
697 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx);
698 #else
699 static inline
700 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx)
701 {
702 return -ENOSYS;
703 }
704 #endif
705
706 #if defined(CONFIG_PID_NS) && \
707 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
708 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx);
709 #else
710 static inline
711 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx)
712 {
713 return -ENOSYS;
714 }
715 #endif
716
717 #if defined(CONFIG_USER_NS) && \
718 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
719 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx);
720 #else
721 static inline
722 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx)
723 {
724 return -ENOSYS;
725 }
726 #endif
727
728 #if defined(CONFIG_UTS_NS) && \
729 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
730 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx);
731 #else
732 static inline
733 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx)
734 {
735 return -ENOSYS;
736 }
737 #endif
738
739 #if defined(CONFIG_TIME_NS) && \
740 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \
741 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
742 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx);
743 #else
744 static inline
745 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx)
746 {
747 return -ENOSYS;
748 }
749 #endif
750
751 int lttng_add_uid_to_ctx(struct lttng_kernel_ctx **ctx);
752 int lttng_add_euid_to_ctx(struct lttng_kernel_ctx **ctx);
753 int lttng_add_suid_to_ctx(struct lttng_kernel_ctx **ctx);
754 int lttng_add_gid_to_ctx(struct lttng_kernel_ctx **ctx);
755 int lttng_add_egid_to_ctx(struct lttng_kernel_ctx **ctx);
756 int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx **ctx);
757 int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx **ctx);
758 int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx **ctx);
759 int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx **ctx);
760 int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx **ctx);
761 int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx **ctx);
762 int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx **ctx);
763
764 #if defined(CONFIG_PERF_EVENTS)
765 int lttng_add_perf_counter_to_ctx(uint32_t type,
766 uint64_t config,
767 const char *name,
768 struct lttng_kernel_ctx **ctx);
769 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
770 struct lttng_cpuhp_node *node);
771 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
772 struct lttng_cpuhp_node *node);
773 #else
774 static inline
775 int lttng_add_perf_counter_to_ctx(uint32_t type,
776 uint64_t config,
777 const char *name,
778 struct lttng_kernel_ctx **ctx)
779 {
780 return -ENOSYS;
781 }
782 static inline
783 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
784 struct lttng_cpuhp_node *node)
785 {
786 return 0;
787 }
788 static inline
789 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
790 struct lttng_cpuhp_node *node)
791 {
792 return 0;
793 }
794 #endif
795
796 struct lttng_event_recorder_enabler *lttng_event_recorder_enabler_create(
797 enum lttng_enabler_format_type format_type,
798 struct lttng_kernel_abi_event *event_param,
799 struct lttng_kernel_channel_buffer *chan);
800 void lttng_event_enabler_session_add(struct lttng_kernel_session *session,
801 struct lttng_event_recorder_enabler *event_enabler);
802
803 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
804 enum lttng_enabler_format_type format_type,
805 struct lttng_kernel_abi_event_notifier *event_notifier_param,
806 struct lttng_event_notifier_group *event_notifier_group);
807 void lttng_event_notifier_enabler_group_add(struct lttng_event_notifier_group *event_notifier_group,
808 struct lttng_event_notifier_enabler *event_notifier_enabler);
809 int lttng_event_notifier_enabler_attach_capture_bytecode(
810 struct lttng_event_notifier_enabler *event_notifier_enabler,
811 struct lttng_kernel_abi_capture_bytecode __user *bytecode);
812
813 int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler);
814 int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler);
815 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler,
816 struct lttng_kernel_abi_filter_bytecode __user *bytecode);
817 void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler);
818
819 bool lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc,
820 struct lttng_event_enabler_common *enabler);
821 bool lttng_event_enabler_match_event(struct lttng_event_enabler_common *event_enabler,
822 struct lttng_kernel_event_common *event);
823 bool lttng_event_enabler_desc_match_event(struct lttng_event_enabler_common *event_enabler,
824 const struct lttng_kernel_event_desc *desc,
825 struct lttng_kernel_event_common *event);
826
827 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_desc,
828 struct lttng_kernel_ctx *ctx,
829 struct list_head *instance_bytecode_runtime_head,
830 struct list_head *enabler_bytecode_runtime_head);
831
832 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
833 int lttng_syscalls_register_event(struct lttng_event_enabler_common *event_enabler);
834 int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event);
835 int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event);
836
837 int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table);
838 int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table);
839
840 long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table,
841 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask);
842 #else
843 static inline int lttng_syscalls_register_event(struct lttng_event_enabler_common *event_enabler)
844 {
845 return -ENOSYS;
846 }
847
848 static inline int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event)
849 {
850 return -ENOSYS;
851 }
852
853 static inline int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event)
854 {
855 return -ENOSYS;
856 }
857
858 static inline int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table)
859 {
860 return 0;
861 }
862
863 static inline int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table)
864 {
865 return 0;
866 }
867
868 static inline long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table,
869 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask)
870 {
871 return -ENOSYS;
872 }
873
874 static inline int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_notifier_enabler *event_notifier_enabler)
875 {
876 return -ENOSYS;
877 }
878
879 #endif
880
881 #ifdef CONFIG_KPROBES
882 int lttng_kprobes_register_event(const char *name,
883 const char *symbol_name,
884 uint64_t offset,
885 uint64_t addr,
886 struct lttng_kernel_event_common *event);
887 void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event);
888 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event);
889 #else
890 static inline
891 int lttng_kprobes_register_event(const char *name,
892 const char *symbol_name,
893 uint64_t offset,
894 uint64_t addr,
895 struct lttng_kernel_event_common *event)
896 {
897 return -ENOSYS;
898 }
899
900 static inline
901 void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event)
902 {
903 }
904
905 static inline
906 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event)
907 {
908 }
909 #endif
910
911 int lttng_event_add_callsite(struct lttng_kernel_event_common *event,
912 struct lttng_kernel_abi_event_callsite __user *callsite);
913
914 #ifdef CONFIG_UPROBES
915 int lttng_uprobes_register_event(const char *name,
916 int fd, struct lttng_kernel_event_common *event);
917 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
918 struct lttng_kernel_abi_event_callsite __user *callsite);
919 void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event);
920 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event);
921 #else
922 static inline
923 int lttng_uprobes_register_event(const char *name,
924 int fd, struct lttng_kernel_event_common *event)
925 {
926 return -ENOSYS;
927 }
928
929 static inline
930 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
931 struct lttng_kernel_abi_event_callsite __user *callsite)
932 {
933 return -ENOSYS;
934 }
935
936 static inline
937 void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event)
938 {
939 }
940
941 static inline
942 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event)
943 {
944 }
945 #endif
946
947 #ifdef CONFIG_KRETPROBES
948 int lttng_kretprobes_register(const char *name,
949 const char *symbol_name,
950 uint64_t offset,
951 uint64_t addr,
952 struct lttng_kernel_event_common *event_entry,
953 struct lttng_kernel_event_common *event_exit);
954 void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event);
955 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event);
956 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
957 int enable);
958 #else
959 static inline
960 int lttng_kretprobes_register(const char *name,
961 const char *symbol_name,
962 uint64_t offset,
963 uint64_t addr,
964 struct lttng_kernel_event_common *event_entry,
965 struct lttng_kernel_event_common *event_exit)
966 {
967 return -ENOSYS;
968 }
969
970 static inline
971 void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event)
972 {
973 }
974
975 static inline
976 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event)
977 {
978 }
979
980 static inline
981 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
982 int enable)
983 {
984 return -ENOSYS;
985 }
986 #endif
987
988 void lttng_lock_sessions(void);
989 void lttng_unlock_sessions(void);
990
991 struct list_head *lttng_get_probe_list_head(void);
992
993 int lttng_fix_pending_events(void);
994 int lttng_fix_pending_event_notifiers(void);
995 int lttng_session_active(void);
996 bool lttng_event_notifier_active(void);
997
998 struct lttng_kernel_session *lttng_session_create(void);
999 int lttng_session_enable(struct lttng_kernel_session *session);
1000 int lttng_session_disable(struct lttng_kernel_session *session);
1001 void lttng_session_destroy(struct lttng_kernel_session *session);
1002 int lttng_session_metadata_regenerate(struct lttng_kernel_session *session);
1003 int lttng_session_statedump(struct lttng_kernel_session *session);
1004 void metadata_cache_destroy(struct kref *kref);
1005
1006 struct lttng_counter *lttng_kernel_counter_create(
1007 const char *counter_transport_name, size_t number_dimensions,
1008 const size_t *dimensions_sizes);
1009 int lttng_kernel_counter_read(struct lttng_counter *counter,
1010 const size_t *dimension_indexes, int32_t cpu,
1011 int64_t *val, bool *overflow, bool *underflow);
1012 int lttng_kernel_counter_aggregate(struct lttng_counter *counter,
1013 const size_t *dimension_indexes, int64_t *val,
1014 bool *overflow, bool *underflow);
1015 int lttng_kernel_counter_clear(struct lttng_counter *counter,
1016 const size_t *dimension_indexes);
1017 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
1018 int lttng_event_notifier_group_create_error_counter(
1019 struct file *event_notifier_group_file,
1020 const struct lttng_kernel_abi_counter_conf *error_counter_conf);
1021 void lttng_event_notifier_group_destroy(
1022 struct lttng_event_notifier_group *event_notifier_group);
1023
1024 struct lttng_kernel_channel_buffer *lttng_channel_buffer_create(struct lttng_kernel_session *session,
1025 const char *transport_name,
1026 void *buf_addr,
1027 size_t subbuf_size, size_t num_subbuf,
1028 unsigned int switch_timer_interval,
1029 unsigned int read_timer_interval,
1030 enum channel_type channel_type);
1031 struct lttng_kernel_channel_buffer *lttng_global_channel_create(struct lttng_kernel_session *session,
1032 int overwrite, void *buf_addr,
1033 size_t subbuf_size, size_t num_subbuf,
1034 unsigned int switch_timer_interval,
1035 unsigned int read_timer_interval);
1036
1037 void lttng_metadata_channel_destroy(struct lttng_kernel_channel_buffer *chan);
1038 struct lttng_kernel_event_common *_lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler,
1039 const struct lttng_kernel_event_desc *event_desc);
1040 struct lttng_kernel_event_common *lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler,
1041 const struct lttng_kernel_event_desc *event_desc);
1042
1043 int lttng_channel_enable(struct lttng_kernel_channel_common *channel);
1044 int lttng_channel_disable(struct lttng_kernel_channel_common *channel);
1045 int lttng_event_enable(struct lttng_kernel_event_common *event);
1046 int lttng_event_disable(struct lttng_kernel_event_common *event);
1047
1048 void lttng_transport_register(struct lttng_transport *transport);
1049 void lttng_transport_unregister(struct lttng_transport *transport);
1050
1051 void lttng_counter_transport_register(struct lttng_counter_transport *transport);
1052 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
1053
1054 void synchronize_trace(void);
1055 int lttng_abi_init(void);
1056 int lttng_abi_compat_old_init(void);
1057 void lttng_abi_exit(void);
1058 void lttng_abi_compat_old_exit(void);
1059
1060 const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name);
1061 void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc);
1062 int lttng_probes_init(void);
1063 void lttng_probes_exit(void);
1064
1065 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
1066 struct lttng_kernel_ring_buffer_channel *chan, bool *coherent);
1067
1068 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
1069 int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker *lf);
1070 int lttng_id_tracker_init(struct lttng_kernel_id_tracker *lf,
1071 struct lttng_kernel_session *session,
1072 enum tracker_type type);
1073 void lttng_id_tracker_fini(struct lttng_kernel_id_tracker *lf);
1074 void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker *lf, bool rcu);
1075 int lttng_id_tracker_add(struct lttng_kernel_id_tracker *lf, int id);
1076 int lttng_id_tracker_del(struct lttng_kernel_id_tracker *lf, int id);
1077
1078 int lttng_session_track_id(struct lttng_kernel_session *session,
1079 enum tracker_type tracker_type, int id);
1080 int lttng_session_untrack_id(struct lttng_kernel_session *session,
1081 enum tracker_type tracker_type, int id);
1082
1083 int lttng_session_list_tracker_ids(struct lttng_kernel_session *session,
1084 enum tracker_type tracker_type);
1085
1086 void lttng_clock_ref(void);
1087 void lttng_clock_unref(void);
1088
1089 void lttng_free_event_filter_runtime(struct lttng_kernel_event_common *event);
1090
1091 int lttng_probes_init(void);
1092
1093 int lttng_logger_init(void);
1094 void lttng_logger_exit(void);
1095
1096 extern int lttng_statedump_start(struct lttng_kernel_session *session);
1097
1098 int lttng_calibrate(struct lttng_kernel_abi_calibrate *calibrate);
1099
1100 extern const struct file_operations lttng_tracepoint_list_fops;
1101 extern const struct file_operations lttng_syscall_list_fops;
1102
1103 #define lttng_kernel_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
1104 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
1105 .event_field = (_event_field), \
1106 .get_size = (_get_size), \
1107 .record = (_record), \
1108 .get_value = (_get_value), \
1109 .destroy = (_destroy), \
1110 .priv = (_priv), \
1111 })
1112
1113 #endif /* _LTTNG_EVENTS_INTERNAL_H */
This page took 0.063239 seconds and 4 git commands to generate.