Refactoring: move enablers list into 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 struct list_head node; /* list of enablers */
241 bool published; /* published in list. */
242 };
243
244 struct lttng_event_recorder_enabler {
245 struct lttng_event_enabler_common parent;
246 struct lttng_kernel_channel_buffer *chan;
247 };
248
249 struct lttng_event_notifier_enabler {
250 struct lttng_event_enabler_common parent;
251 uint64_t error_counter_index;
252 struct lttng_event_notifier_group *group;
253
254 /* head list of struct lttng_kernel_bytecode_node */
255 struct list_head capture_bytecode_head;
256 uint64_t num_captures;
257 };
258
259 struct lttng_ctx_value {
260 union {
261 int64_t s64;
262 const char *str;
263 double d;
264 } u;
265 };
266
267 /*
268 * We need to keep this perf counter field separately from struct
269 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
270 */
271 struct lttng_perf_counter_field {
272 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
273 struct lttng_cpuhp_node cpuhp_prepare;
274 struct lttng_cpuhp_node cpuhp_online;
275 #else
276 struct notifier_block nb;
277 int hp_enable;
278 #endif
279 struct perf_event_attr *attr;
280 struct perf_event **e; /* per-cpu array */
281 char *name;
282 struct lttng_kernel_event_field *event_field;
283 };
284
285 struct lttng_kernel_ctx_field {
286 const struct lttng_kernel_event_field *event_field;
287 size_t (*get_size)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
288 size_t offset);
289 void (*record)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
290 struct lttng_kernel_ring_buffer_ctx *ctx,
291 struct lttng_kernel_channel_buffer *chan);
292 void (*get_value)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
293 struct lttng_ctx_value *value);
294 void (*destroy)(void *priv);
295 void *priv;
296 };
297
298 struct lttng_kernel_ctx {
299 struct lttng_kernel_ctx_field *fields;
300 unsigned int nr_fields;
301 unsigned int allocated_fields;
302 size_t largest_align; /* in bytes */
303 };
304
305 struct lttng_metadata_cache {
306 char *data; /* Metadata cache */
307 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
308 unsigned int metadata_written; /* Number of bytes written in metadata cache */
309 atomic_t producing; /* Metadata being produced (incomplete) */
310 struct kref refcount; /* Metadata cache usage */
311 struct list_head metadata_stream; /* Metadata stream list */
312 uuid_le uuid; /* Trace session unique ID (copy) */
313 struct mutex lock; /* Produce/consume lock */
314 uint64_t version; /* Current version of the metadata */
315 };
316
317 struct lttng_metadata_stream {
318 void *priv; /* Ring buffer private data */
319 struct lttng_metadata_cache *metadata_cache;
320 unsigned int metadata_in; /* Bytes read from the cache */
321 unsigned int metadata_out; /* Bytes consumed from stream */
322 int finalized; /* Has channel been finalized */
323 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
324 struct list_head list; /* Stream list */
325 struct lttng_transport *transport;
326 uint64_t version; /* Current version of the metadata cache */
327 bool coherent; /* Stream in a coherent state */
328 };
329
330 struct lttng_kernel_channel_buffer_ops_private {
331 struct lttng_kernel_channel_buffer_ops *pub; /* Public channel buffer ops interface */
332
333 struct lttng_kernel_ring_buffer_channel *(*channel_create)(const char *name,
334 void *priv,
335 void *buf_addr,
336 size_t subbuf_size, size_t num_subbuf,
337 unsigned int switch_timer_interval,
338 unsigned int read_timer_interval);
339 void (*channel_destroy)(struct lttng_kernel_ring_buffer_channel *chan);
340 struct lttng_kernel_ring_buffer *(*buffer_read_open)(struct lttng_kernel_ring_buffer_channel *chan);
341 int (*buffer_has_read_closed_stream)(struct lttng_kernel_ring_buffer_channel *chan);
342 void (*buffer_read_close)(struct lttng_kernel_ring_buffer *buf);
343 /*
344 * packet_avail_size returns the available size in the current
345 * packet. Note that the size returned is only a hint, since it
346 * may change due to concurrent writes.
347 */
348 size_t (*packet_avail_size)(struct lttng_kernel_ring_buffer_channel *chan);
349 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct lttng_kernel_ring_buffer_channel *chan, int cpu);
350 wait_queue_head_t *(*get_hp_wait_queue)(struct lttng_kernel_ring_buffer_channel *chan);
351 int (*is_finalized)(struct lttng_kernel_ring_buffer_channel *chan);
352 int (*is_disabled)(struct lttng_kernel_ring_buffer_channel *chan);
353 int (*timestamp_begin) (const struct lttng_kernel_ring_buffer_config *config,
354 struct lttng_kernel_ring_buffer *bufb,
355 uint64_t *timestamp_begin);
356 int (*timestamp_end) (const struct lttng_kernel_ring_buffer_config *config,
357 struct lttng_kernel_ring_buffer *bufb,
358 uint64_t *timestamp_end);
359 int (*events_discarded) (const struct lttng_kernel_ring_buffer_config *config,
360 struct lttng_kernel_ring_buffer *bufb,
361 uint64_t *events_discarded);
362 int (*content_size) (const struct lttng_kernel_ring_buffer_config *config,
363 struct lttng_kernel_ring_buffer *bufb,
364 uint64_t *content_size);
365 int (*packet_size) (const struct lttng_kernel_ring_buffer_config *config,
366 struct lttng_kernel_ring_buffer *bufb,
367 uint64_t *packet_size);
368 int (*stream_id) (const struct lttng_kernel_ring_buffer_config *config,
369 struct lttng_kernel_ring_buffer *bufb,
370 uint64_t *stream_id);
371 int (*current_timestamp) (const struct lttng_kernel_ring_buffer_config *config,
372 struct lttng_kernel_ring_buffer *bufb,
373 uint64_t *ts);
374 int (*sequence_number) (const struct lttng_kernel_ring_buffer_config *config,
375 struct lttng_kernel_ring_buffer *bufb,
376 uint64_t *seq);
377 int (*instance_id) (const struct lttng_kernel_ring_buffer_config *config,
378 struct lttng_kernel_ring_buffer *bufb,
379 uint64_t *id);
380 };
381
382 struct lttng_counter_ops {
383 struct lib_counter *(*counter_create)(size_t nr_dimensions,
384 const size_t *max_nr_elem, /* for each dimension */
385 int64_t global_sum_step);
386 void (*counter_destroy)(struct lib_counter *counter);
387 int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes,
388 int64_t v);
389 /*
390 * counter_read reads a specific cpu's counter if @cpu >= 0, or
391 * the global aggregation counter if @cpu == -1.
392 */
393 int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
394 int64_t *value, bool *overflow, bool *underflow);
395 /*
396 * counter_aggregate returns the total sum of all per-cpu counters and
397 * the global aggregation counter.
398 */
399 int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes,
400 int64_t *value, bool *overflow, bool *underflow);
401 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
402 };
403
404 struct lttng_counter {
405 struct file *file; /* File associated to counter. */
406 struct file *owner;
407 struct lttng_counter_transport *transport;
408 struct lib_counter *counter;
409 struct lttng_counter_ops *ops;
410 };
411
412 #define LTTNG_EVENT_HT_BITS 12
413 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
414
415 struct lttng_event_ht {
416 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
417 };
418
419 struct lttng_event_notifier_group {
420 struct file *file; /* File associated to event notifier group */
421 struct file *notif_file; /* File used to expose notifications to userspace. */
422 struct list_head node; /* event notifier group list */
423 struct list_head enablers_head; /* List of enablers */
424 struct list_head event_notifiers_head; /* List of event notifier */
425 struct lttng_event_ht events_ht; /* Hash table of event notifiers */
426 struct lttng_kernel_channel_buffer_ops *ops;
427 struct lttng_transport *transport;
428 struct lttng_kernel_ring_buffer_channel *chan; /* Ring buffer channel for event notifier group. */
429 struct lttng_kernel_ring_buffer *buf; /* Ring buffer for event notifier group. */
430 wait_queue_head_t read_wait;
431 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
432
433 struct lttng_kernel_syscall_table syscall_table;
434
435 struct lttng_counter *error_counter;
436 size_t error_counter_len;
437 };
438
439 struct lttng_transport {
440 char *name;
441 struct module *owner;
442 struct list_head node;
443 struct lttng_kernel_channel_buffer_ops ops;
444 };
445
446 struct lttng_counter_transport {
447 char *name;
448 struct module *owner;
449 struct list_head node;
450 struct lttng_counter_ops ops;
451 };
452
453 struct lttng_kernel_session_private {
454 struct lttng_kernel_session *pub; /* Public session interface */
455
456 int been_active; /* Has trace session been active ? */
457 struct file *file; /* File associated to session */
458 struct list_head chan; /* Channel list head */
459 struct list_head events; /* Event list head */
460 struct list_head list; /* Session list */
461 unsigned int free_chan_id; /* Next chan ID to allocate */
462 uuid_le uuid; /* Trace session unique ID */
463 struct lttng_metadata_cache *metadata_cache;
464 unsigned int metadata_dumped:1,
465 tstate:1; /* Transient enable state */
466 /* List of event enablers */
467 struct list_head enablers_head;
468 /* Hash table of events */
469 struct lttng_event_ht events_ht;
470 char name[LTTNG_KERNEL_ABI_SESSION_NAME_LEN];
471 char creation_time[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN];
472 };
473
474 struct lttng_id_hash_node {
475 struct hlist_node hlist;
476 int id;
477 };
478
479 enum tracker_type {
480 TRACKER_PID,
481 TRACKER_VPID,
482 TRACKER_UID,
483 TRACKER_VUID,
484 TRACKER_GID,
485 TRACKER_VGID,
486
487 TRACKER_UNKNOWN,
488 };
489
490 struct lttng_kernel_id_tracker_private {
491 struct lttng_kernel_id_tracker *pub; /* Public interface */
492
493 struct lttng_kernel_session *session;
494 enum tracker_type tracker_type;
495 };
496
497 extern struct lttng_kernel_ctx *lttng_static_ctx;
498
499 static inline
500 const struct lttng_kernel_type_integer *lttng_kernel_get_type_integer(const struct lttng_kernel_type_common *type)
501 {
502 if (type->type != lttng_kernel_type_integer)
503 return NULL;
504 return container_of(type, const struct lttng_kernel_type_integer, parent);
505 }
506
507 static inline
508 const struct lttng_kernel_type_string *lttng_kernel_get_type_string(const struct lttng_kernel_type_common *type)
509 {
510 if (type->type != lttng_kernel_type_string)
511 return NULL;
512 return container_of(type, const struct lttng_kernel_type_string, parent);
513 }
514
515 static inline
516 const struct lttng_kernel_type_enum *lttng_kernel_get_type_enum(const struct lttng_kernel_type_common *type)
517 {
518 if (type->type != lttng_kernel_type_enum)
519 return NULL;
520 return container_of(type, const struct lttng_kernel_type_enum, parent);
521 }
522
523 static inline
524 const struct lttng_kernel_type_array *lttng_kernel_get_type_array(const struct lttng_kernel_type_common *type)
525 {
526 if (type->type != lttng_kernel_type_array)
527 return NULL;
528 return container_of(type, const struct lttng_kernel_type_array, parent);
529 }
530
531 static inline
532 const struct lttng_kernel_type_sequence *lttng_kernel_get_type_sequence(const struct lttng_kernel_type_common *type)
533 {
534 if (type->type != lttng_kernel_type_sequence)
535 return NULL;
536 return container_of(type, const struct lttng_kernel_type_sequence, parent);
537 }
538
539 static inline
540 const struct lttng_kernel_type_struct *lttng_kernel_get_type_struct(const struct lttng_kernel_type_common *type)
541 {
542 if (type->type != lttng_kernel_type_struct)
543 return NULL;
544 return container_of(type, const struct lttng_kernel_type_struct, parent);
545 }
546
547 static inline
548 const struct lttng_kernel_type_variant *lttng_kernel_get_type_variant(const struct lttng_kernel_type_common *type)
549 {
550 if (type->type != lttng_kernel_type_variant)
551 return NULL;
552 return container_of(type, const struct lttng_kernel_type_variant, parent);
553 }
554
555 static inline bool lttng_kernel_type_is_bytewise_integer(const struct lttng_kernel_type_common *type)
556 {
557 const struct lttng_kernel_type_integer *type_integer = lttng_kernel_get_type_integer(type);
558
559 if (!type_integer)
560 return false;
561 switch (type_integer->size) {
562 case 8:
563 lttng_fallthrough;
564 case 16:
565 lttng_fallthrough;
566 case 32:
567 lttng_fallthrough;
568 case 64:
569 break;
570 default:
571 return false;
572 }
573 return true;
574 }
575
576 int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common *event,
577 const char *interpreter_stack_data,
578 struct lttng_kernel_probe_ctx *probe_ctx,
579 void *event_filter_ctx);
580
581 static inline
582 struct lttng_event_enabler_common *lttng_event_recorder_enabler_as_enabler(
583 struct lttng_event_recorder_enabler *event_recorder_enabler)
584 {
585 return &event_recorder_enabler->parent;
586 }
587
588 static inline
589 struct lttng_event_enabler_common *lttng_event_notifier_enabler_as_enabler(
590 struct lttng_event_notifier_enabler *event_notifier_enabler)
591 {
592 return &event_notifier_enabler->parent;
593 }
594
595 static inline
596 struct lttng_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common *event_enabler)
597 {
598 switch (event_enabler->enabler_type) {
599 case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
600 {
601 struct lttng_event_recorder_enabler *event_recorder_enabler =
602 container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
603 return &event_recorder_enabler->chan->parent.session->priv->events_ht;
604 }
605 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
606 {
607 struct lttng_event_notifier_enabler *event_notifier_enabler =
608 container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
609 return &event_notifier_enabler->group->events_ht;
610 }
611 default:
612 return NULL;
613 }
614 }
615
616 static inline
617 struct list_head *lttng_get_event_list_head_from_enabler(struct lttng_event_enabler_common *event_enabler)
618 {
619 switch (event_enabler->enabler_type) {
620 case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
621 {
622 struct lttng_event_recorder_enabler *event_recorder_enabler =
623 container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
624 return &event_recorder_enabler->chan->parent.session->priv->events;
625 }
626 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
627 {
628 struct lttng_event_notifier_enabler *event_notifier_enabler =
629 container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
630 return &event_notifier_enabler->group->event_notifiers_head;
631 }
632 default:
633 return NULL;
634 }
635 }
636
637 int lttng_context_init(void);
638 void lttng_context_exit(void);
639 int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
640 const struct lttng_kernel_ctx_field *f);
641 void lttng_kernel_context_remove_last(struct lttng_kernel_ctx **ctx_p);
642 struct lttng_kernel_ctx_field *lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx *ctx,
643 size_t index);
644 int lttng_kernel_find_context(struct lttng_kernel_ctx *ctx, const char *name);
645 int lttng_kernel_get_context_index(struct lttng_kernel_ctx *ctx, const char *name);
646 void lttng_kernel_destroy_context(struct lttng_kernel_ctx *ctx);
647 int lttng_add_pid_to_ctx(struct lttng_kernel_ctx **ctx);
648 int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx **ctx);
649 int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx);
650 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx);
651 int lttng_add_nice_to_ctx(struct lttng_kernel_ctx **ctx);
652 int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx **ctx);
653 int lttng_add_tid_to_ctx(struct lttng_kernel_ctx **ctx);
654 int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx **ctx);
655 int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx **ctx);
656 int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx);
657 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx **ctx);
658 int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx **ctx);
659 int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx **ctx);
660 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
661 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx);
662 #else
663 static inline
664 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
665 {
666 return -ENOSYS;
667 }
668 #endif
669 #ifdef CONFIG_PREEMPT_RT_FULL
670 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx);
671 #else
672 static inline
673 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx)
674 {
675 return -ENOSYS;
676 }
677 #endif
678
679 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx **ctx, int type);
680
681 #if defined(CONFIG_CGROUPS) && \
682 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
683 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
684 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx);
685 #else
686 static inline
687 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx)
688 {
689 return -ENOSYS;
690 }
691 #endif
692
693 #if defined(CONFIG_IPC_NS) && \
694 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
695 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx);
696 #else
697 static inline
698 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx)
699 {
700 return -ENOSYS;
701 }
702 #endif
703
704 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
705 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
706 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx);
707 #else
708 static inline
709 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx)
710 {
711 return -ENOSYS;
712 }
713 #endif
714
715 #if defined(CONFIG_NET_NS) && \
716 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
717 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx);
718 #else
719 static inline
720 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx)
721 {
722 return -ENOSYS;
723 }
724 #endif
725
726 #if defined(CONFIG_PID_NS) && \
727 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
728 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx);
729 #else
730 static inline
731 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx)
732 {
733 return -ENOSYS;
734 }
735 #endif
736
737 #if defined(CONFIG_USER_NS) && \
738 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
739 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx);
740 #else
741 static inline
742 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx)
743 {
744 return -ENOSYS;
745 }
746 #endif
747
748 #if defined(CONFIG_UTS_NS) && \
749 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
750 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx);
751 #else
752 static inline
753 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx)
754 {
755 return -ENOSYS;
756 }
757 #endif
758
759 #if defined(CONFIG_TIME_NS) && \
760 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \
761 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
762 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx);
763 #else
764 static inline
765 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx)
766 {
767 return -ENOSYS;
768 }
769 #endif
770
771 int lttng_add_uid_to_ctx(struct lttng_kernel_ctx **ctx);
772 int lttng_add_euid_to_ctx(struct lttng_kernel_ctx **ctx);
773 int lttng_add_suid_to_ctx(struct lttng_kernel_ctx **ctx);
774 int lttng_add_gid_to_ctx(struct lttng_kernel_ctx **ctx);
775 int lttng_add_egid_to_ctx(struct lttng_kernel_ctx **ctx);
776 int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx **ctx);
777 int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx **ctx);
778 int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx **ctx);
779 int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx **ctx);
780 int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx **ctx);
781 int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx **ctx);
782 int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx **ctx);
783
784 #if defined(CONFIG_PERF_EVENTS)
785 int lttng_add_perf_counter_to_ctx(uint32_t type,
786 uint64_t config,
787 const char *name,
788 struct lttng_kernel_ctx **ctx);
789 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
790 struct lttng_cpuhp_node *node);
791 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
792 struct lttng_cpuhp_node *node);
793 #else
794 static inline
795 int lttng_add_perf_counter_to_ctx(uint32_t type,
796 uint64_t config,
797 const char *name,
798 struct lttng_kernel_ctx **ctx)
799 {
800 return -ENOSYS;
801 }
802 static inline
803 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
804 struct lttng_cpuhp_node *node)
805 {
806 return 0;
807 }
808 static inline
809 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
810 struct lttng_cpuhp_node *node)
811 {
812 return 0;
813 }
814 #endif
815
816 struct lttng_event_recorder_enabler *lttng_event_recorder_enabler_create(
817 enum lttng_enabler_format_type format_type,
818 struct lttng_kernel_abi_event *event_param,
819 struct lttng_kernel_channel_buffer *chan);
820 void lttng_event_enabler_session_add(struct lttng_kernel_session *session,
821 struct lttng_event_recorder_enabler *event_enabler);
822
823 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
824 enum lttng_enabler_format_type format_type,
825 struct lttng_kernel_abi_event_notifier *event_notifier_param,
826 struct lttng_event_notifier_group *event_notifier_group);
827 void lttng_event_notifier_enabler_group_add(struct lttng_event_notifier_group *event_notifier_group,
828 struct lttng_event_notifier_enabler *event_notifier_enabler);
829 int lttng_event_notifier_enabler_attach_capture_bytecode(
830 struct lttng_event_notifier_enabler *event_notifier_enabler,
831 struct lttng_kernel_abi_capture_bytecode __user *bytecode);
832
833 int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler);
834 int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler);
835 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler,
836 struct lttng_kernel_abi_filter_bytecode __user *bytecode);
837 void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler);
838
839 bool lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc,
840 struct lttng_event_enabler_common *enabler);
841 bool lttng_event_enabler_match_event(struct lttng_event_enabler_common *event_enabler,
842 struct lttng_kernel_event_common *event);
843 bool lttng_event_enabler_desc_match_event(struct lttng_event_enabler_common *event_enabler,
844 const struct lttng_kernel_event_desc *desc,
845 struct lttng_kernel_event_common *event);
846
847 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_desc,
848 struct lttng_kernel_ctx *ctx,
849 struct list_head *instance_bytecode_runtime_head,
850 struct list_head *enabler_bytecode_runtime_head);
851
852 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
853 int lttng_syscalls_register_event(struct lttng_event_enabler_common *event_enabler);
854 int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event);
855 int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event);
856
857 int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table);
858 int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table);
859
860 long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table,
861 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask);
862
863 void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common *event_enabler);
864 #else
865 static inline int lttng_syscalls_register_event(struct lttng_event_enabler_common *event_enabler)
866 {
867 return -ENOSYS;
868 }
869
870 static inline int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event)
871 {
872 return -ENOSYS;
873 }
874
875 static inline int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event)
876 {
877 return -ENOSYS;
878 }
879
880 static inline int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table)
881 {
882 return 0;
883 }
884
885 static inline int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table)
886 {
887 return 0;
888 }
889
890 static inline long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table,
891 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask)
892 {
893 return -ENOSYS;
894 }
895
896 static inline int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_notifier_enabler *event_notifier_enabler)
897 {
898 return -ENOSYS;
899 }
900
901 static inline void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common *event_enabler)
902 {
903 }
904 #endif
905
906 #ifdef CONFIG_KPROBES
907 int lttng_kprobes_register_event(const char *name,
908 const char *symbol_name,
909 uint64_t offset,
910 uint64_t addr,
911 struct lttng_kernel_event_common *event);
912 void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event);
913 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event);
914 #else
915 static inline
916 int lttng_kprobes_register_event(const char *name,
917 const char *symbol_name,
918 uint64_t offset,
919 uint64_t addr,
920 struct lttng_kernel_event_common *event)
921 {
922 return -ENOSYS;
923 }
924
925 static inline
926 void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event)
927 {
928 }
929
930 static inline
931 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event)
932 {
933 }
934 #endif
935
936 int lttng_event_add_callsite(struct lttng_kernel_event_common *event,
937 struct lttng_kernel_abi_event_callsite __user *callsite);
938
939 #ifdef CONFIG_UPROBES
940 int lttng_uprobes_register_event(const char *name,
941 int fd, struct lttng_kernel_event_common *event);
942 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
943 struct lttng_kernel_abi_event_callsite __user *callsite);
944 void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event);
945 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event);
946 #else
947 static inline
948 int lttng_uprobes_register_event(const char *name,
949 int fd, struct lttng_kernel_event_common *event)
950 {
951 return -ENOSYS;
952 }
953
954 static inline
955 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
956 struct lttng_kernel_abi_event_callsite __user *callsite)
957 {
958 return -ENOSYS;
959 }
960
961 static inline
962 void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event)
963 {
964 }
965
966 static inline
967 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event)
968 {
969 }
970 #endif
971
972 #ifdef CONFIG_KRETPROBES
973 int lttng_kretprobes_register(const char *name,
974 const char *symbol_name,
975 uint64_t offset,
976 uint64_t addr,
977 struct lttng_kernel_event_common *event_entry,
978 struct lttng_kernel_event_common *event_exit);
979 void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event);
980 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event);
981 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
982 int enable);
983 #else
984 static inline
985 int lttng_kretprobes_register(const char *name,
986 const char *symbol_name,
987 uint64_t offset,
988 uint64_t addr,
989 struct lttng_kernel_event_common *event_entry,
990 struct lttng_kernel_event_common *event_exit)
991 {
992 return -ENOSYS;
993 }
994
995 static inline
996 void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event)
997 {
998 }
999
1000 static inline
1001 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event)
1002 {
1003 }
1004
1005 static inline
1006 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
1007 int enable)
1008 {
1009 return -ENOSYS;
1010 }
1011 #endif
1012
1013 void lttng_lock_sessions(void);
1014 void lttng_unlock_sessions(void);
1015
1016 struct list_head *lttng_get_probe_list_head(void);
1017
1018 int lttng_fix_pending_events(void);
1019 int lttng_fix_pending_event_notifiers(void);
1020 int lttng_session_active(void);
1021 bool lttng_event_notifier_active(void);
1022
1023 struct lttng_kernel_session *lttng_session_create(void);
1024 int lttng_session_enable(struct lttng_kernel_session *session);
1025 int lttng_session_disable(struct lttng_kernel_session *session);
1026 void lttng_session_destroy(struct lttng_kernel_session *session);
1027 int lttng_session_metadata_regenerate(struct lttng_kernel_session *session);
1028 int lttng_session_statedump(struct lttng_kernel_session *session);
1029 void metadata_cache_destroy(struct kref *kref);
1030
1031 struct lttng_counter *lttng_kernel_counter_create(
1032 const char *counter_transport_name, size_t number_dimensions,
1033 const size_t *dimensions_sizes);
1034 int lttng_kernel_counter_read(struct lttng_counter *counter,
1035 const size_t *dimension_indexes, int32_t cpu,
1036 int64_t *val, bool *overflow, bool *underflow);
1037 int lttng_kernel_counter_aggregate(struct lttng_counter *counter,
1038 const size_t *dimension_indexes, int64_t *val,
1039 bool *overflow, bool *underflow);
1040 int lttng_kernel_counter_clear(struct lttng_counter *counter,
1041 const size_t *dimension_indexes);
1042 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
1043 int lttng_event_notifier_group_create_error_counter(
1044 struct file *event_notifier_group_file,
1045 const struct lttng_kernel_abi_counter_conf *error_counter_conf);
1046 void lttng_event_notifier_group_destroy(
1047 struct lttng_event_notifier_group *event_notifier_group);
1048
1049 struct lttng_kernel_channel_buffer *lttng_channel_buffer_create(struct lttng_kernel_session *session,
1050 const char *transport_name,
1051 void *buf_addr,
1052 size_t subbuf_size, size_t num_subbuf,
1053 unsigned int switch_timer_interval,
1054 unsigned int read_timer_interval,
1055 enum channel_type channel_type);
1056 struct lttng_kernel_channel_buffer *lttng_global_channel_create(struct lttng_kernel_session *session,
1057 int overwrite, void *buf_addr,
1058 size_t subbuf_size, size_t num_subbuf,
1059 unsigned int switch_timer_interval,
1060 unsigned int read_timer_interval);
1061
1062 void lttng_metadata_channel_destroy(struct lttng_kernel_channel_buffer *chan);
1063 struct lttng_kernel_event_common *_lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler,
1064 const struct lttng_kernel_event_desc *event_desc);
1065 struct lttng_kernel_event_common *lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler,
1066 const struct lttng_kernel_event_desc *event_desc);
1067
1068 int lttng_channel_enable(struct lttng_kernel_channel_common *channel);
1069 int lttng_channel_disable(struct lttng_kernel_channel_common *channel);
1070 int lttng_event_enable(struct lttng_kernel_event_common *event);
1071 int lttng_event_disable(struct lttng_kernel_event_common *event);
1072
1073 void lttng_transport_register(struct lttng_transport *transport);
1074 void lttng_transport_unregister(struct lttng_transport *transport);
1075
1076 void lttng_counter_transport_register(struct lttng_counter_transport *transport);
1077 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
1078
1079 void synchronize_trace(void);
1080 int lttng_abi_init(void);
1081 int lttng_abi_compat_old_init(void);
1082 void lttng_abi_exit(void);
1083 void lttng_abi_compat_old_exit(void);
1084
1085 const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name);
1086 void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc);
1087 int lttng_probes_init(void);
1088 void lttng_probes_exit(void);
1089
1090 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
1091 struct lttng_kernel_ring_buffer_channel *chan, bool *coherent);
1092
1093 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
1094 int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker *lf);
1095 int lttng_id_tracker_init(struct lttng_kernel_id_tracker *lf,
1096 struct lttng_kernel_session *session,
1097 enum tracker_type type);
1098 void lttng_id_tracker_fini(struct lttng_kernel_id_tracker *lf);
1099 void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker *lf, bool rcu);
1100 int lttng_id_tracker_add(struct lttng_kernel_id_tracker *lf, int id);
1101 int lttng_id_tracker_del(struct lttng_kernel_id_tracker *lf, int id);
1102
1103 int lttng_session_track_id(struct lttng_kernel_session *session,
1104 enum tracker_type tracker_type, int id);
1105 int lttng_session_untrack_id(struct lttng_kernel_session *session,
1106 enum tracker_type tracker_type, int id);
1107
1108 int lttng_session_list_tracker_ids(struct lttng_kernel_session *session,
1109 enum tracker_type tracker_type);
1110
1111 void lttng_clock_ref(void);
1112 void lttng_clock_unref(void);
1113
1114 void lttng_free_event_filter_runtime(struct lttng_kernel_event_common *event);
1115
1116 int lttng_probes_init(void);
1117
1118 int lttng_logger_init(void);
1119 void lttng_logger_exit(void);
1120
1121 extern int lttng_statedump_start(struct lttng_kernel_session *session);
1122
1123 int lttng_calibrate(struct lttng_kernel_abi_calibrate *calibrate);
1124
1125 extern const struct file_operations lttng_tracepoint_list_fops;
1126 extern const struct file_operations lttng_syscall_list_fops;
1127
1128 #define lttng_kernel_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
1129 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
1130 .event_field = (_event_field), \
1131 .get_size = (_get_size), \
1132 .record = (_record), \
1133 .get_value = (_get_value), \
1134 .destroy = (_destroy), \
1135 .priv = (_priv), \
1136 })
1137
1138 #endif /* _LTTNG_EVENTS_INTERNAL_H */
This page took 0.081778 seconds and 4 git commands to generate.