1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3 * lttng/events-internal.h
5 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 #ifndef _LTTNG_EVENTS_INTERNAL_H
9 #define _LTTNG_EVENTS_INTERNAL_H
11 #include <wrapper/compiler_attributes.h>
13 #include <lttng/events.h>
15 struct lttng_syscall_filter
;
16 struct lttng_metadata_cache
;
18 struct perf_event_attr
;
19 struct lttng_kernel_ring_buffer_config
;
21 enum lttng_enabler_format_type
{
22 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
23 LTTNG_ENABLER_FORMAT_NAME
,
32 * Objects in a linked-list of enablers, owned by an event.
34 struct lttng_enabler_ref
{
35 struct list_head node
; /* enabler ref list */
36 struct lttng_event_enabler_common
*ref
; /* backward ref */
39 struct lttng_krp
; /* Kretprobe handling */
41 struct lttng_uprobe_handler
{
42 struct lttng_kernel_event_common
*event
;
44 struct uprobe_consumer up_consumer
;
45 struct list_head node
;
55 struct list_head head
;
58 enum lttng_syscall_entryexit
{
63 enum lttng_syscall_abi
{
64 LTTNG_SYSCALL_ABI_NATIVE
,
65 LTTNG_SYSCALL_ABI_COMPAT
,
68 struct lttng_kernel_event_common_private
{
69 struct lttng_kernel_event_common
*pub
; /* Public event interface */
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 */
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
;
81 struct hlist_node hlist_node
; /* node in events hash table */
82 struct list_head node
; /* node in event list */
84 enum lttng_kernel_abi_instrumentation instrumentation
;
85 /* Selected by instrumentation */
87 struct lttng_kprobe kprobe
;
88 struct lttng_uprobe uprobe
;
90 struct lttng_krp
*lttng_krp
;
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
;
102 struct lttng_kernel_event_recorder_private
{
103 struct lttng_kernel_event_common_private parent
;
105 struct lttng_kernel_event_recorder
*pub
; /* Public event interface */
106 struct lttng_kernel_ctx
*ctx
;
108 unsigned int metadata_dumped
:1;
111 struct lttng_kernel_event_notifier_private
{
112 struct lttng_kernel_event_common_private parent
;
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
;
121 struct lttng_kernel_syscall_table
{
122 unsigned int sys_enter_registered
:1,
123 sys_exit_registered
:1;
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
;
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
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
;
142 struct lttng_syscall_filter
*sc_filter
;
143 int syscall_all_entry
;
144 int syscall_all_exit
;
147 struct lttng_kernel_channel_common_private
{
148 struct lttng_kernel_channel_common
*pub
;
150 struct file
*file
; /* File associated to channel */
151 unsigned int tstate
:1; /* Transient enable state */
153 struct lttng_kernel_syscall_table syscall_table
;
156 struct lttng_kernel_channel_buffer_private
{
157 struct lttng_kernel_channel_common_private parent
;
159 struct lttng_kernel_channel_buffer
*pub
;
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 */
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
;
173 enum lttng_kernel_bytecode_interpreter_ret
{
174 LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
= -1,
175 LTTNG_KERNEL_BYTECODE_INTERPRETER_OK
= 0,
178 enum lttng_kernel_bytecode_filter_result
{
179 LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT
= 0,
180 LTTNG_KERNEL_BYTECODE_FILTER_REJECT
= 1,
183 struct lttng_kernel_bytecode_filter_ctx
{
184 enum lttng_kernel_bytecode_filter_result result
;
187 struct lttng_interpreter_output
;
189 enum lttng_kernel_bytecode_type
{
190 LTTNG_KERNEL_BYTECODE_TYPE_FILTER
,
191 LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE
,
194 enum lttng_kernel_event_enabler_type
{
195 LTTNG_EVENT_ENABLER_TYPE_RECORDER
,
196 LTTNG_EVENT_ENABLER_TYPE_NOTIFIER
,
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
;
205 uint32_t reloc_offset
;
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
,
220 struct list_head node
; /* list of bytecode runtime in event */
221 struct lttng_kernel_ctx
*ctx
;
225 * Enabler field, within whatever object is enabling an event. Target of
226 * backward reference.
228 struct lttng_event_enabler_common
{
229 enum lttng_kernel_event_enabler_type enabler_type
;
230 enum lttng_enabler_format_type format_type
;
232 /* head list of struct lttng_kernel_bytecode_node */
233 struct list_head filter_bytecode_head
;
235 struct lttng_kernel_abi_event event_param
;
236 unsigned int enabled
:1;
238 uint64_t user_token
; /* User-provided token. */
240 struct list_head node
; /* list of enablers */
241 bool published
; /* published in list. */
244 struct lttng_event_recorder_enabler
{
245 struct lttng_event_enabler_common parent
;
246 struct lttng_kernel_channel_buffer
*chan
;
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
;
254 /* head list of struct lttng_kernel_bytecode_node */
255 struct list_head capture_bytecode_head
;
256 uint64_t num_captures
;
259 struct lttng_ctx_value
{
268 * We need to keep this perf counter field separately from struct
269 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
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
;
276 struct notifier_block nb
;
279 struct perf_event_attr
*attr
;
280 struct perf_event
**e
; /* per-cpu array */
282 struct lttng_kernel_event_field
*event_field
;
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
,
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
);
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 */
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 */
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 */
330 struct lttng_kernel_channel_buffer_ops_private
{
331 struct lttng_kernel_channel_buffer_ops
*pub
; /* Public channel buffer ops interface */
333 struct lttng_kernel_ring_buffer_channel
*(*channel_create
)(const char *name
,
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
);
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.
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
,
374 int (*sequence_number
) (const struct lttng_kernel_ring_buffer_config
*config
,
375 struct lttng_kernel_ring_buffer
*bufb
,
377 int (*instance_id
) (const struct lttng_kernel_ring_buffer_config
*config
,
378 struct lttng_kernel_ring_buffer
*bufb
,
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
,
390 * counter_read reads a specific cpu's counter if @cpu >= 0, or
391 * the global aggregation counter if @cpu == -1.
393 int (*counter_read
)(struct lib_counter
*counter
, const size_t *dimension_indexes
, int cpu
,
394 int64_t *value
, bool *overflow
, bool *underflow
);
396 * counter_aggregate returns the total sum of all per-cpu counters and
397 * the global aggregation counter.
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
);
404 struct lttng_counter
{
405 struct file
*file
; /* File associated to counter. */
407 struct lttng_counter_transport
*transport
;
408 struct lib_counter
*counter
;
409 struct lttng_counter_ops
*ops
;
412 #define LTTNG_EVENT_HT_BITS 12
413 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
415 struct lttng_event_ht
{
416 struct hlist_head table
[LTTNG_EVENT_HT_SIZE
];
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. */
433 struct lttng_kernel_syscall_table syscall_table
;
435 struct lttng_counter
*error_counter
;
436 size_t error_counter_len
;
439 struct lttng_transport
{
441 struct module
*owner
;
442 struct list_head node
;
443 struct lttng_kernel_channel_buffer_ops ops
;
446 struct lttng_counter_transport
{
448 struct module
*owner
;
449 struct list_head node
;
450 struct lttng_counter_ops ops
;
453 struct lttng_kernel_session_private
{
454 struct lttng_kernel_session
*pub
; /* Public session interface */
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
];
474 struct lttng_id_hash_node
{
475 struct hlist_node hlist
;
490 struct lttng_kernel_id_tracker_private
{
491 struct lttng_kernel_id_tracker
*pub
; /* Public interface */
493 struct lttng_kernel_session
*session
;
494 enum tracker_type tracker_type
;
497 extern struct lttng_kernel_ctx
*lttng_static_ctx
;
500 const struct lttng_kernel_type_integer
*lttng_kernel_get_type_integer(const struct lttng_kernel_type_common
*type
)
502 if (type
->type
!= lttng_kernel_type_integer
)
504 return container_of(type
, const struct lttng_kernel_type_integer
, parent
);
508 const struct lttng_kernel_type_string
*lttng_kernel_get_type_string(const struct lttng_kernel_type_common
*type
)
510 if (type
->type
!= lttng_kernel_type_string
)
512 return container_of(type
, const struct lttng_kernel_type_string
, parent
);
516 const struct lttng_kernel_type_enum
*lttng_kernel_get_type_enum(const struct lttng_kernel_type_common
*type
)
518 if (type
->type
!= lttng_kernel_type_enum
)
520 return container_of(type
, const struct lttng_kernel_type_enum
, parent
);
524 const struct lttng_kernel_type_array
*lttng_kernel_get_type_array(const struct lttng_kernel_type_common
*type
)
526 if (type
->type
!= lttng_kernel_type_array
)
528 return container_of(type
, const struct lttng_kernel_type_array
, parent
);
532 const struct lttng_kernel_type_sequence
*lttng_kernel_get_type_sequence(const struct lttng_kernel_type_common
*type
)
534 if (type
->type
!= lttng_kernel_type_sequence
)
536 return container_of(type
, const struct lttng_kernel_type_sequence
, parent
);
540 const struct lttng_kernel_type_struct
*lttng_kernel_get_type_struct(const struct lttng_kernel_type_common
*type
)
542 if (type
->type
!= lttng_kernel_type_struct
)
544 return container_of(type
, const struct lttng_kernel_type_struct
, parent
);
548 const struct lttng_kernel_type_variant
*lttng_kernel_get_type_variant(const struct lttng_kernel_type_common
*type
)
550 if (type
->type
!= lttng_kernel_type_variant
)
552 return container_of(type
, const struct lttng_kernel_type_variant
, parent
);
555 static inline bool lttng_kernel_type_is_bytewise_integer(const struct lttng_kernel_type_common
*type
)
557 const struct lttng_kernel_type_integer
*type_integer
= lttng_kernel_get_type_integer(type
);
561 switch (type_integer
->size
) {
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
);
582 struct lttng_event_enabler_common
*lttng_event_recorder_enabler_as_enabler(
583 struct lttng_event_recorder_enabler
*event_recorder_enabler
)
585 return &event_recorder_enabler
->parent
;
589 struct lttng_event_enabler_common
*lttng_event_notifier_enabler_as_enabler(
590 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
592 return &event_notifier_enabler
->parent
;
596 struct lttng_event_ht
*lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common
*event_enabler
)
598 switch (event_enabler
->enabler_type
) {
599 case LTTNG_EVENT_ENABLER_TYPE_RECORDER
:
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
;
605 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER
:
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
;
617 struct list_head
*lttng_get_event_list_head_from_enabler(struct lttng_event_enabler_common
*event_enabler
)
619 switch (event_enabler
->enabler_type
) {
620 case LTTNG_EVENT_ENABLER_TYPE_RECORDER
:
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
;
626 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER
:
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
;
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
,
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
);
664 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx
**ctx
)
669 #ifdef CONFIG_PREEMPT_RT_FULL
670 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx
**ctx
);
673 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx
**ctx
)
679 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx
**ctx
, int type
);
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
);
687 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
698 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
709 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
720 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
731 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
742 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
753 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
765 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
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
);
784 #if defined(CONFIG_PERF_EVENTS)
785 int lttng_add_perf_counter_to_ctx(uint32_t type
,
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
);
795 int lttng_add_perf_counter_to_ctx(uint32_t type
,
798 struct lttng_kernel_ctx
**ctx
)
803 int lttng_cpuhp_perf_counter_online(unsigned int cpu
,
804 struct lttng_cpuhp_node
*node
)
809 int lttng_cpuhp_perf_counter_dead(unsigned int cpu
,
810 struct lttng_cpuhp_node
*node
)
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
);
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
);
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
);
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 bool lttng_event_enabler_event_name_match_event(struct lttng_event_enabler_common
*event_enabler
,
847 const char *event_name
,
848 struct lttng_kernel_event_common
*event
);
850 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc
*event_desc
,
851 struct lttng_kernel_ctx
*ctx
,
852 struct list_head
*instance_bytecode_runtime_head
,
853 struct list_head
*enabler_bytecode_runtime_head
);
855 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
856 int lttng_event_enabler_create_syscall_events_if_missing(struct lttng_event_enabler_common
*event_enabler
);
857 int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common
*event
);
858 int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common
*event
);
860 int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table
*syscall_table
);
861 int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table
*syscall_table
);
863 long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table
*syscall_table
,
864 struct lttng_kernel_abi_syscall_mask __user
*usyscall_mask
);
866 void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common
*event_enabler
);
868 static inline int lttng_event_enabler_create_syscall_events_if_missing(struct lttng_event_enabler_common
*event_enabler
)
873 static inline int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common
*event
)
878 static inline int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common
*event
)
883 static inline int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table
*syscall_table
)
888 static inline int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table
*syscall_table
)
893 static inline long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table
*syscall_table
,
894 struct lttng_kernel_abi_syscall_mask __user
*usyscall_mask
)
899 static inline int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_notifier_enabler
*event_notifier_enabler
)
904 static inline void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common
*event_enabler
)
909 #ifdef CONFIG_KPROBES
910 int lttng_kprobes_register_event(const char *name
,
911 const char *symbol_name
,
914 struct lttng_kernel_event_common
*event
);
915 void lttng_kprobes_unregister_event(struct lttng_kernel_event_common
*event
);
916 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common
*event
);
919 int lttng_kprobes_register_event(const char *name
,
920 const char *symbol_name
,
923 struct lttng_kernel_event_common
*event
)
929 void lttng_kprobes_unregister_event(struct lttng_kernel_event_common
*event
)
934 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common
*event
)
939 int lttng_event_add_callsite(struct lttng_kernel_event_common
*event
,
940 struct lttng_kernel_abi_event_callsite __user
*callsite
);
942 #ifdef CONFIG_UPROBES
943 int lttng_uprobes_register_event(const char *name
,
944 int fd
, struct lttng_kernel_event_common
*event
);
945 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common
*event
,
946 struct lttng_kernel_abi_event_callsite __user
*callsite
);
947 void lttng_uprobes_unregister_event(struct lttng_kernel_event_common
*event
);
948 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common
*event
);
951 int lttng_uprobes_register_event(const char *name
,
952 int fd
, struct lttng_kernel_event_common
*event
)
958 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common
*event
,
959 struct lttng_kernel_abi_event_callsite __user
*callsite
)
965 void lttng_uprobes_unregister_event(struct lttng_kernel_event_common
*event
)
970 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common
*event
)
975 #ifdef CONFIG_KRETPROBES
976 int lttng_kretprobes_register(const char *name
,
977 const char *symbol_name
,
980 struct lttng_kernel_event_common
*event_entry
,
981 struct lttng_kernel_event_common
*event_exit
);
982 void lttng_kretprobes_unregister(struct lttng_kernel_event_common
*event
);
983 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common
*event
);
984 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common
*event
,
988 int lttng_kretprobes_register(const char *name
,
989 const char *symbol_name
,
992 struct lttng_kernel_event_common
*event_entry
,
993 struct lttng_kernel_event_common
*event_exit
)
999 void lttng_kretprobes_unregister(struct lttng_kernel_event_common
*event
)
1004 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common
*event
)
1009 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common
*event
,
1016 void lttng_lock_sessions(void);
1017 void lttng_unlock_sessions(void);
1019 struct list_head
*lttng_get_probe_list_head(void);
1021 int lttng_fix_pending_events(void);
1022 int lttng_fix_pending_event_notifiers(void);
1023 int lttng_session_active(void);
1024 bool lttng_event_notifier_active(void);
1026 struct lttng_kernel_session
*lttng_session_create(void);
1027 int lttng_session_enable(struct lttng_kernel_session
*session
);
1028 int lttng_session_disable(struct lttng_kernel_session
*session
);
1029 void lttng_session_destroy(struct lttng_kernel_session
*session
);
1030 int lttng_session_metadata_regenerate(struct lttng_kernel_session
*session
);
1031 int lttng_session_statedump(struct lttng_kernel_session
*session
);
1032 void metadata_cache_destroy(struct kref
*kref
);
1034 struct lttng_counter
*lttng_kernel_counter_create(
1035 const char *counter_transport_name
, size_t number_dimensions
,
1036 const size_t *dimensions_sizes
);
1037 int lttng_kernel_counter_read(struct lttng_counter
*counter
,
1038 const size_t *dimension_indexes
, int32_t cpu
,
1039 int64_t *val
, bool *overflow
, bool *underflow
);
1040 int lttng_kernel_counter_aggregate(struct lttng_counter
*counter
,
1041 const size_t *dimension_indexes
, int64_t *val
,
1042 bool *overflow
, bool *underflow
);
1043 int lttng_kernel_counter_clear(struct lttng_counter
*counter
,
1044 const size_t *dimension_indexes
);
1045 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void);
1046 int lttng_event_notifier_group_create_error_counter(
1047 struct file
*event_notifier_group_file
,
1048 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
);
1049 void lttng_event_notifier_group_destroy(
1050 struct lttng_event_notifier_group
*event_notifier_group
);
1052 struct lttng_kernel_channel_buffer
*lttng_channel_buffer_create(struct lttng_kernel_session
*session
,
1053 const char *transport_name
,
1055 size_t subbuf_size
, size_t num_subbuf
,
1056 unsigned int switch_timer_interval
,
1057 unsigned int read_timer_interval
,
1058 enum channel_type channel_type
);
1059 struct lttng_kernel_channel_buffer
*lttng_global_channel_create(struct lttng_kernel_session
*session
,
1060 int overwrite
, void *buf_addr
,
1061 size_t subbuf_size
, size_t num_subbuf
,
1062 unsigned int switch_timer_interval
,
1063 unsigned int read_timer_interval
);
1065 void lttng_metadata_channel_destroy(struct lttng_kernel_channel_buffer
*chan
);
1066 struct lttng_kernel_event_common
*_lttng_kernel_event_create(struct lttng_event_enabler_common
*event_enabler
,
1067 const struct lttng_kernel_event_desc
*event_desc
);
1068 struct lttng_kernel_event_common
*lttng_kernel_event_create(struct lttng_event_enabler_common
*event_enabler
,
1069 const struct lttng_kernel_event_desc
*event_desc
);
1071 int lttng_channel_enable(struct lttng_kernel_channel_common
*channel
);
1072 int lttng_channel_disable(struct lttng_kernel_channel_common
*channel
);
1073 int lttng_event_enable(struct lttng_kernel_event_common
*event
);
1074 int lttng_event_disable(struct lttng_kernel_event_common
*event
);
1076 void lttng_transport_register(struct lttng_transport
*transport
);
1077 void lttng_transport_unregister(struct lttng_transport
*transport
);
1079 void lttng_counter_transport_register(struct lttng_counter_transport
*transport
);
1080 void lttng_counter_transport_unregister(struct lttng_counter_transport
*transport
);
1082 void synchronize_trace(void);
1083 int lttng_abi_init(void);
1084 int lttng_abi_compat_old_init(void);
1085 void lttng_abi_exit(void);
1086 void lttng_abi_compat_old_exit(void);
1088 const struct lttng_kernel_event_desc
*lttng_event_desc_get(const char *name
);
1089 void lttng_event_desc_put(const struct lttng_kernel_event_desc
*desc
);
1090 int lttng_probes_init(void);
1091 void lttng_probes_exit(void);
1093 int lttng_metadata_output_channel(struct lttng_metadata_stream
*stream
,
1094 struct lttng_kernel_ring_buffer_channel
*chan
, bool *coherent
);
1096 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node
*node
);
1097 int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker
*lf
);
1098 int lttng_id_tracker_init(struct lttng_kernel_id_tracker
*lf
,
1099 struct lttng_kernel_session
*session
,
1100 enum tracker_type type
);
1101 void lttng_id_tracker_fini(struct lttng_kernel_id_tracker
*lf
);
1102 void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker
*lf
, bool rcu
);
1103 int lttng_id_tracker_add(struct lttng_kernel_id_tracker
*lf
, int id
);
1104 int lttng_id_tracker_del(struct lttng_kernel_id_tracker
*lf
, int id
);
1106 int lttng_session_track_id(struct lttng_kernel_session
*session
,
1107 enum tracker_type tracker_type
, int id
);
1108 int lttng_session_untrack_id(struct lttng_kernel_session
*session
,
1109 enum tracker_type tracker_type
, int id
);
1111 int lttng_session_list_tracker_ids(struct lttng_kernel_session
*session
,
1112 enum tracker_type tracker_type
);
1114 void lttng_clock_ref(void);
1115 void lttng_clock_unref(void);
1117 void lttng_free_event_filter_runtime(struct lttng_kernel_event_common
*event
);
1119 int lttng_probes_init(void);
1121 int lttng_logger_init(void);
1122 void lttng_logger_exit(void);
1124 extern int lttng_statedump_start(struct lttng_kernel_session
*session
);
1126 int lttng_calibrate(struct lttng_kernel_abi_calibrate
*calibrate
);
1128 extern const struct file_operations lttng_tracepoint_list_fops
;
1129 extern const struct file_operations lttng_syscall_list_fops
;
1131 #define lttng_kernel_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
1132 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
1133 .event_field = (_event_field), \
1134 .get_size = (_get_size), \
1135 .record = (_record), \
1136 .get_value = (_get_value), \
1137 .destroy = (_destroy), \
1141 #endif /* _LTTNG_EVENTS_INTERNAL_H */