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_enabler
*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
;
80 enum lttng_kernel_abi_instrumentation instrumentation
;
81 /* Selected by instrumentation */
83 struct lttng_kprobe kprobe
;
84 struct lttng_uprobe uprobe
;
86 struct lttng_krp
*lttng_krp
;
90 enum lttng_syscall_entryexit entryexit
;
91 enum lttng_syscall_abi abi
;
92 struct hlist_node node
; /* chain registered syscall event_notifier */
93 unsigned int syscall_id
;
98 struct lttng_kernel_event_recorder_private
{
99 struct lttng_kernel_event_common_private parent
;
101 struct lttng_kernel_event_recorder
*pub
; /* Public event interface */
102 struct list_head node
; /* Event recorder list */
103 struct hlist_node hlist
; /* Hash table of event recorders */
104 struct lttng_kernel_ctx
*ctx
;
106 unsigned int metadata_dumped
:1;
109 struct lttng_kernel_event_notifier_private
{
110 struct lttng_kernel_event_common_private parent
;
112 struct lttng_kernel_event_notifier
*pub
; /* Public event notifier interface */
113 struct lttng_event_notifier_group
*group
; /* weak ref */
114 size_t num_captures
; /* Needed to allocate the msgpack array. */
115 uint64_t error_counter_index
;
116 struct list_head node
; /* Event notifier list */
117 struct hlist_node hlist
; /* Hash table of event notifiers */
118 struct list_head capture_bytecode_runtime_head
;
122 struct lttng_kernel_channel_common_private
{
123 struct lttng_kernel_channel_common
*pub
;
125 struct file
*file
; /* File associated to channel */
126 unsigned int sys_enter_registered
:1,
127 sys_exit_registered
:1,
128 tstate
:1; /* Transient enable state */
130 struct hlist_head
*sc_table
; /* for syscall tracing */
131 struct hlist_head
*compat_sc_table
;
132 struct hlist_head
*sc_exit_table
; /* for syscall exit tracing */
133 struct hlist_head
*compat_sc_exit_table
;
134 struct hlist_head sc_unknown
; /* for unknown syscalls */
135 struct hlist_head sc_compat_unknown
;
136 struct hlist_head sc_exit_unknown
;
137 struct hlist_head compat_sc_exit_unknown
;
138 struct lttng_syscall_filter
*sc_filter
;
139 int syscall_all_entry
;
140 int syscall_all_exit
;
143 struct lttng_kernel_channel_buffer_private
{
144 struct lttng_kernel_channel_common_private parent
;
146 struct lttng_kernel_channel_buffer
*pub
;
148 unsigned int id
; /* Channel ID */
149 unsigned int free_event_id
; /* Next event ID to allocate */
150 int header_type
; /* 0: unset, 1: compact, 2: large */
152 enum channel_type channel_type
;
153 struct lttng_kernel_ctx
*ctx
;
154 struct lttng_kernel_ring_buffer_channel
*rb_chan
; /* Ring buffer channel */
155 unsigned int metadata_dumped
:1;
156 struct list_head node
; /* Channel list in session */
157 struct lttng_transport
*transport
;
160 enum lttng_kernel_bytecode_interpreter_ret
{
161 LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR
= -1,
162 LTTNG_KERNEL_BYTECODE_INTERPRETER_OK
= 0,
165 enum lttng_kernel_bytecode_filter_result
{
166 LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT
= 0,
167 LTTNG_KERNEL_BYTECODE_FILTER_REJECT
= 1,
170 struct lttng_kernel_bytecode_filter_ctx
{
171 enum lttng_kernel_bytecode_filter_result result
;
174 struct lttng_interpreter_output
;
176 enum lttng_kernel_bytecode_type
{
177 LTTNG_KERNEL_BYTECODE_TYPE_FILTER
,
178 LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE
,
181 struct lttng_kernel_bytecode_node
{
182 enum lttng_kernel_bytecode_type type
;
183 struct list_head node
;
184 struct lttng_enabler
*enabler
;
187 uint32_t reloc_offset
;
193 struct lttng_kernel_bytecode_runtime
{
194 /* Associated bytecode */
195 enum lttng_kernel_bytecode_type type
;
196 struct lttng_kernel_bytecode_node
*bc
;
197 int (*interpreter_func
)(struct lttng_kernel_bytecode_runtime
*kernel_bytecode
,
198 const char *interpreter_stack_data
,
199 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
202 struct list_head node
; /* list of bytecode runtime in event */
203 struct lttng_kernel_ctx
*ctx
;
207 * Enabler field, within whatever object is enabling an event. Target of
208 * backward reference.
210 struct lttng_enabler
{
211 enum lttng_enabler_format_type format_type
;
213 /* head list of struct lttng_kernel_bytecode_node */
214 struct list_head filter_bytecode_head
;
216 struct lttng_kernel_abi_event event_param
;
217 unsigned int enabled
:1;
219 uint64_t user_token
; /* User-provided token. */
222 struct lttng_event_enabler
{
223 struct lttng_enabler base
;
224 struct list_head node
; /* per-session list of enablers */
225 struct lttng_kernel_channel_buffer
*chan
;
228 struct lttng_event_notifier_enabler
{
229 struct lttng_enabler base
;
230 uint64_t error_counter_index
;
231 struct list_head node
; /* List of event_notifier enablers */
232 struct lttng_event_notifier_group
*group
;
234 /* head list of struct lttng_kernel_bytecode_node */
235 struct list_head capture_bytecode_head
;
236 uint64_t num_captures
;
239 struct lttng_ctx_value
{
248 * We need to keep this perf counter field separately from struct
249 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
251 struct lttng_perf_counter_field
{
252 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
253 struct lttng_cpuhp_node cpuhp_prepare
;
254 struct lttng_cpuhp_node cpuhp_online
;
256 struct notifier_block nb
;
259 struct perf_event_attr
*attr
;
260 struct perf_event
**e
; /* per-cpu array */
262 struct lttng_kernel_event_field
*event_field
;
265 struct lttng_kernel_ctx_field
{
266 const struct lttng_kernel_event_field
*event_field
;
267 size_t (*get_size
)(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
,
269 void (*record
)(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
,
270 struct lttng_kernel_ring_buffer_ctx
*ctx
,
271 struct lttng_kernel_channel_buffer
*chan
);
272 void (*get_value
)(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
,
273 struct lttng_ctx_value
*value
);
274 void (*destroy
)(void *priv
);
278 struct lttng_kernel_ctx
{
279 struct lttng_kernel_ctx_field
*fields
;
280 unsigned int nr_fields
;
281 unsigned int allocated_fields
;
282 size_t largest_align
; /* in bytes */
285 struct lttng_metadata_cache
{
286 char *data
; /* Metadata cache */
287 unsigned int cache_alloc
; /* Metadata allocated size (bytes) */
288 unsigned int metadata_written
; /* Number of bytes written in metadata cache */
289 atomic_t producing
; /* Metadata being produced (incomplete) */
290 struct kref refcount
; /* Metadata cache usage */
291 struct list_head metadata_stream
; /* Metadata stream list */
292 uuid_le uuid
; /* Trace session unique ID (copy) */
293 struct mutex lock
; /* Produce/consume lock */
294 uint64_t version
; /* Current version of the metadata */
297 struct lttng_metadata_stream
{
298 void *priv
; /* Ring buffer private data */
299 struct lttng_metadata_cache
*metadata_cache
;
300 unsigned int metadata_in
; /* Bytes read from the cache */
301 unsigned int metadata_out
; /* Bytes consumed from stream */
302 int finalized
; /* Has channel been finalized */
303 wait_queue_head_t read_wait
; /* Reader buffer-level wait queue */
304 struct list_head list
; /* Stream list */
305 struct lttng_transport
*transport
;
306 uint64_t version
; /* Current version of the metadata cache */
307 bool coherent
; /* Stream in a coherent state */
310 struct lttng_kernel_channel_buffer_ops_private
{
311 struct lttng_kernel_channel_buffer_ops
*pub
; /* Public channel buffer ops interface */
313 struct lttng_kernel_ring_buffer_channel
*(*channel_create
)(const char *name
,
316 size_t subbuf_size
, size_t num_subbuf
,
317 unsigned int switch_timer_interval
,
318 unsigned int read_timer_interval
);
319 void (*channel_destroy
)(struct lttng_kernel_ring_buffer_channel
*chan
);
320 struct lttng_kernel_ring_buffer
*(*buffer_read_open
)(struct lttng_kernel_ring_buffer_channel
*chan
);
321 int (*buffer_has_read_closed_stream
)(struct lttng_kernel_ring_buffer_channel
*chan
);
322 void (*buffer_read_close
)(struct lttng_kernel_ring_buffer
*buf
);
324 * packet_avail_size returns the available size in the current
325 * packet. Note that the size returned is only a hint, since it
326 * may change due to concurrent writes.
328 size_t (*packet_avail_size
)(struct lttng_kernel_ring_buffer_channel
*chan
);
329 wait_queue_head_t
*(*get_writer_buf_wait_queue
)(struct lttng_kernel_ring_buffer_channel
*chan
, int cpu
);
330 wait_queue_head_t
*(*get_hp_wait_queue
)(struct lttng_kernel_ring_buffer_channel
*chan
);
331 int (*is_finalized
)(struct lttng_kernel_ring_buffer_channel
*chan
);
332 int (*is_disabled
)(struct lttng_kernel_ring_buffer_channel
*chan
);
333 int (*timestamp_begin
) (const struct lttng_kernel_ring_buffer_config
*config
,
334 struct lttng_kernel_ring_buffer
*bufb
,
335 uint64_t *timestamp_begin
);
336 int (*timestamp_end
) (const struct lttng_kernel_ring_buffer_config
*config
,
337 struct lttng_kernel_ring_buffer
*bufb
,
338 uint64_t *timestamp_end
);
339 int (*events_discarded
) (const struct lttng_kernel_ring_buffer_config
*config
,
340 struct lttng_kernel_ring_buffer
*bufb
,
341 uint64_t *events_discarded
);
342 int (*content_size
) (const struct lttng_kernel_ring_buffer_config
*config
,
343 struct lttng_kernel_ring_buffer
*bufb
,
344 uint64_t *content_size
);
345 int (*packet_size
) (const struct lttng_kernel_ring_buffer_config
*config
,
346 struct lttng_kernel_ring_buffer
*bufb
,
347 uint64_t *packet_size
);
348 int (*stream_id
) (const struct lttng_kernel_ring_buffer_config
*config
,
349 struct lttng_kernel_ring_buffer
*bufb
,
350 uint64_t *stream_id
);
351 int (*current_timestamp
) (const struct lttng_kernel_ring_buffer_config
*config
,
352 struct lttng_kernel_ring_buffer
*bufb
,
354 int (*sequence_number
) (const struct lttng_kernel_ring_buffer_config
*config
,
355 struct lttng_kernel_ring_buffer
*bufb
,
357 int (*instance_id
) (const struct lttng_kernel_ring_buffer_config
*config
,
358 struct lttng_kernel_ring_buffer
*bufb
,
362 struct lttng_counter_ops
{
363 struct lib_counter
*(*counter_create
)(size_t nr_dimensions
,
364 const size_t *max_nr_elem
, /* for each dimension */
365 int64_t global_sum_step
);
366 void (*counter_destroy
)(struct lib_counter
*counter
);
367 int (*counter_add
)(struct lib_counter
*counter
, const size_t *dimension_indexes
,
370 * counter_read reads a specific cpu's counter if @cpu >= 0, or
371 * the global aggregation counter if @cpu == -1.
373 int (*counter_read
)(struct lib_counter
*counter
, const size_t *dimension_indexes
, int cpu
,
374 int64_t *value
, bool *overflow
, bool *underflow
);
376 * counter_aggregate returns the total sum of all per-cpu counters and
377 * the global aggregation counter.
379 int (*counter_aggregate
)(struct lib_counter
*counter
, const size_t *dimension_indexes
,
380 int64_t *value
, bool *overflow
, bool *underflow
);
381 int (*counter_clear
)(struct lib_counter
*counter
, const size_t *dimension_indexes
);
384 struct lttng_counter
{
385 struct file
*file
; /* File associated to counter. */
387 struct lttng_counter_transport
*transport
;
388 struct lib_counter
*counter
;
389 struct lttng_counter_ops
*ops
;
392 #define LTTNG_EVENT_NOTIFIER_HT_BITS 12
393 #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
395 struct lttng_event_notifier_ht
{
396 struct hlist_head table
[LTTNG_EVENT_NOTIFIER_HT_SIZE
];
399 struct lttng_event_notifier_group
{
400 struct file
*file
; /* File associated to event notifier group */
401 struct file
*notif_file
; /* File used to expose notifications to userspace. */
402 struct list_head node
; /* event notifier group list */
403 struct list_head enablers_head
; /* List of enablers */
404 struct list_head event_notifiers_head
; /* List of event notifier */
405 struct lttng_event_notifier_ht event_notifiers_ht
; /* Hash table of event notifiers */
406 struct lttng_kernel_channel_buffer_ops
*ops
;
407 struct lttng_transport
*transport
;
408 struct lttng_kernel_ring_buffer_channel
*chan
; /* Ring buffer channel for event notifier group. */
409 struct lttng_kernel_ring_buffer
*buf
; /* Ring buffer for event notifier group. */
410 wait_queue_head_t read_wait
;
411 struct irq_work wakeup_pending
; /* Pending wakeup irq work. */
412 struct lttng_kernel_event_notifier
*sc_unknown
; /* for unknown syscalls */
413 struct lttng_kernel_event_notifier
*sc_compat_unknown
;
415 struct lttng_syscall_filter
*sc_filter
;
417 struct hlist_head
*event_notifier_syscall_dispatch
;
418 struct hlist_head
*event_notifier_compat_syscall_dispatch
;
419 struct hlist_head
*event_notifier_exit_syscall_dispatch
;
420 struct hlist_head
*event_notifier_exit_compat_syscall_dispatch
;
422 struct hlist_head event_notifier_unknown_syscall_dispatch
;
423 struct hlist_head event_notifier_compat_unknown_syscall_dispatch
;
424 struct hlist_head event_notifier_exit_unknown_syscall_dispatch
;
425 struct hlist_head event_notifier_exit_compat_unknown_syscall_dispatch
;
427 int syscall_all_entry
;
428 int syscall_all_exit
;
430 unsigned int sys_enter_registered
:1, sys_exit_registered
:1;
432 struct lttng_counter
*error_counter
;
433 size_t error_counter_len
;
436 struct lttng_transport
{
438 struct module
*owner
;
439 struct list_head node
;
440 struct lttng_kernel_channel_buffer_ops ops
;
443 struct lttng_counter_transport
{
445 struct module
*owner
;
446 struct list_head node
;
447 struct lttng_counter_ops ops
;
450 #define LTTNG_EVENT_HT_BITS 12
451 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
453 struct lttng_event_ht
{
454 struct hlist_head table
[LTTNG_EVENT_HT_SIZE
];
457 struct lttng_kernel_session_private
{
458 struct lttng_kernel_session
*pub
; /* Public session interface */
460 int been_active
; /* Has trace session been active ? */
461 struct file
*file
; /* File associated to session */
462 struct list_head chan
; /* Channel list head */
463 struct list_head events
; /* Event list head */
464 struct list_head list
; /* Session list */
465 unsigned int free_chan_id
; /* Next chan ID to allocate */
466 uuid_le uuid
; /* Trace session unique ID */
467 struct lttng_metadata_cache
*metadata_cache
;
468 unsigned int metadata_dumped
:1,
469 tstate
:1; /* Transient enable state */
470 /* List of event enablers */
471 struct list_head enablers_head
;
472 /* Hash table of events */
473 struct lttng_event_ht events_ht
;
474 char name
[LTTNG_KERNEL_ABI_SESSION_NAME_LEN
];
475 char creation_time
[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN
];
478 struct lttng_id_hash_node
{
479 struct hlist_node hlist
;
494 struct lttng_kernel_id_tracker_private
{
495 struct lttng_kernel_id_tracker
*pub
; /* Public interface */
497 struct lttng_kernel_session
*session
;
498 enum tracker_type tracker_type
;
501 extern struct lttng_kernel_ctx
*lttng_static_ctx
;
504 const struct lttng_kernel_type_integer
*lttng_kernel_get_type_integer(const struct lttng_kernel_type_common
*type
)
506 if (type
->type
!= lttng_kernel_type_integer
)
508 return container_of(type
, const struct lttng_kernel_type_integer
, parent
);
512 const struct lttng_kernel_type_string
*lttng_kernel_get_type_string(const struct lttng_kernel_type_common
*type
)
514 if (type
->type
!= lttng_kernel_type_string
)
516 return container_of(type
, const struct lttng_kernel_type_string
, parent
);
520 const struct lttng_kernel_type_enum
*lttng_kernel_get_type_enum(const struct lttng_kernel_type_common
*type
)
522 if (type
->type
!= lttng_kernel_type_enum
)
524 return container_of(type
, const struct lttng_kernel_type_enum
, parent
);
528 const struct lttng_kernel_type_array
*lttng_kernel_get_type_array(const struct lttng_kernel_type_common
*type
)
530 if (type
->type
!= lttng_kernel_type_array
)
532 return container_of(type
, const struct lttng_kernel_type_array
, parent
);
536 const struct lttng_kernel_type_sequence
*lttng_kernel_get_type_sequence(const struct lttng_kernel_type_common
*type
)
538 if (type
->type
!= lttng_kernel_type_sequence
)
540 return container_of(type
, const struct lttng_kernel_type_sequence
, parent
);
544 const struct lttng_kernel_type_struct
*lttng_kernel_get_type_struct(const struct lttng_kernel_type_common
*type
)
546 if (type
->type
!= lttng_kernel_type_struct
)
548 return container_of(type
, const struct lttng_kernel_type_struct
, parent
);
552 const struct lttng_kernel_type_variant
*lttng_kernel_get_type_variant(const struct lttng_kernel_type_common
*type
)
554 if (type
->type
!= lttng_kernel_type_variant
)
556 return container_of(type
, const struct lttng_kernel_type_variant
, parent
);
559 static inline bool lttng_kernel_type_is_bytewise_integer(const struct lttng_kernel_type_common
*type
)
561 const struct lttng_kernel_type_integer
*type_integer
= lttng_kernel_get_type_integer(type
);
565 switch (type_integer
->size
) {
580 int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common
*event
,
581 const char *interpreter_stack_data
,
582 struct lttng_kernel_probe_ctx
*probe_ctx
,
583 void *event_filter_ctx
);
586 struct lttng_enabler
*lttng_event_enabler_as_enabler(
587 struct lttng_event_enabler
*event_enabler
)
589 return &event_enabler
->base
;
593 struct lttng_enabler
*lttng_event_notifier_enabler_as_enabler(
594 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
596 return &event_notifier_enabler
->base
;
599 int lttng_context_init(void);
600 void lttng_context_exit(void);
601 int lttng_kernel_context_append(struct lttng_kernel_ctx
**ctx_p
,
602 const struct lttng_kernel_ctx_field
*f
);
603 void lttng_kernel_context_remove_last(struct lttng_kernel_ctx
**ctx_p
);
604 struct lttng_kernel_ctx_field
*lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx
*ctx
,
606 int lttng_kernel_find_context(struct lttng_kernel_ctx
*ctx
, const char *name
);
607 int lttng_kernel_get_context_index(struct lttng_kernel_ctx
*ctx
, const char *name
);
608 void lttng_kernel_destroy_context(struct lttng_kernel_ctx
*ctx
);
609 int lttng_add_pid_to_ctx(struct lttng_kernel_ctx
**ctx
);
610 int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx
**ctx
);
611 int lttng_add_procname_to_ctx(struct lttng_kernel_ctx
**ctx
);
612 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx
**ctx
);
613 int lttng_add_nice_to_ctx(struct lttng_kernel_ctx
**ctx
);
614 int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx
**ctx
);
615 int lttng_add_tid_to_ctx(struct lttng_kernel_ctx
**ctx
);
616 int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx
**ctx
);
617 int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx
**ctx
);
618 int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx
**ctx
);
619 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx
**ctx
);
620 int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx
**ctx
);
621 int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx
**ctx
);
622 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
623 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx
**ctx
);
626 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx
**ctx
)
631 #ifdef CONFIG_PREEMPT_RT_FULL
632 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx
**ctx
);
635 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx
**ctx
)
641 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx
**ctx
, int type
);
643 #if defined(CONFIG_CGROUPS) && \
644 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
645 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
646 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
649 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
655 #if defined(CONFIG_IPC_NS) && \
656 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
657 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
660 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
666 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
667 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
668 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
671 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
677 #if defined(CONFIG_NET_NS) && \
678 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
679 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
682 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
688 #if defined(CONFIG_PID_NS) && \
689 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
690 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
693 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
699 #if defined(CONFIG_USER_NS) && \
700 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
701 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
704 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
710 #if defined(CONFIG_UTS_NS) && \
711 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
712 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
715 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
721 #if defined(CONFIG_TIME_NS) && \
722 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \
723 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
724 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx
**ctx
);
727 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx
**ctx
)
733 int lttng_add_uid_to_ctx(struct lttng_kernel_ctx
**ctx
);
734 int lttng_add_euid_to_ctx(struct lttng_kernel_ctx
**ctx
);
735 int lttng_add_suid_to_ctx(struct lttng_kernel_ctx
**ctx
);
736 int lttng_add_gid_to_ctx(struct lttng_kernel_ctx
**ctx
);
737 int lttng_add_egid_to_ctx(struct lttng_kernel_ctx
**ctx
);
738 int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx
**ctx
);
739 int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx
**ctx
);
740 int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx
**ctx
);
741 int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx
**ctx
);
742 int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx
**ctx
);
743 int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx
**ctx
);
744 int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx
**ctx
);
746 #if defined(CONFIG_PERF_EVENTS)
747 int lttng_add_perf_counter_to_ctx(uint32_t type
,
750 struct lttng_kernel_ctx
**ctx
);
751 int lttng_cpuhp_perf_counter_online(unsigned int cpu
,
752 struct lttng_cpuhp_node
*node
);
753 int lttng_cpuhp_perf_counter_dead(unsigned int cpu
,
754 struct lttng_cpuhp_node
*node
);
757 int lttng_add_perf_counter_to_ctx(uint32_t type
,
760 struct lttng_kernel_ctx
**ctx
)
765 int lttng_cpuhp_perf_counter_online(unsigned int cpu
,
766 struct lttng_cpuhp_node
*node
)
771 int lttng_cpuhp_perf_counter_dead(unsigned int cpu
,
772 struct lttng_cpuhp_node
*node
)
778 struct lttng_event_enabler
*lttng_event_enabler_create(
779 enum lttng_enabler_format_type format_type
,
780 struct lttng_kernel_abi_event
*event_param
,
781 struct lttng_kernel_channel_buffer
*chan
);
783 int lttng_event_enabler_enable(struct lttng_event_enabler
*event_enabler
);
784 int lttng_event_enabler_disable(struct lttng_event_enabler
*event_enabler
);
785 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
786 struct lttng_event_notifier_group
*event_notifier_group
,
787 enum lttng_enabler_format_type format_type
,
788 struct lttng_kernel_abi_event_notifier
*event_notifier_param
);
790 int lttng_event_notifier_enabler_enable(
791 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
792 int lttng_event_notifier_enabler_disable(
793 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
795 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler
*event_enabler
,
796 struct lttng_kernel_abi_filter_bytecode __user
*bytecode
);
797 int lttng_event_notifier_enabler_attach_filter_bytecode(
798 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
799 struct lttng_kernel_abi_filter_bytecode __user
*bytecode
);
800 int lttng_event_notifier_enabler_attach_capture_bytecode(
801 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
802 struct lttng_kernel_abi_capture_bytecode __user
*bytecode
);
804 int lttng_desc_match_enabler(const struct lttng_kernel_event_desc
*desc
,
805 struct lttng_enabler
*enabler
);
807 void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc
*event_desc
,
808 struct lttng_kernel_ctx
*ctx
,
809 struct list_head
*instance_bytecode_runtime_head
,
810 struct list_head
*enabler_bytecode_runtime_head
);
812 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
813 int lttng_syscalls_register_event(struct lttng_event_enabler
*event_enabler
);
814 int lttng_syscalls_unregister_channel(struct lttng_kernel_channel_buffer
*chan
);
815 int lttng_syscalls_destroy_event(struct lttng_kernel_channel_buffer
*chan
);
816 int lttng_syscall_filter_enable_event(
817 struct lttng_kernel_channel_buffer
*chan
,
818 struct lttng_kernel_event_recorder
*event
);
819 int lttng_syscall_filter_disable_event(
820 struct lttng_kernel_channel_buffer
*chan
,
821 struct lttng_kernel_event_recorder
*event
);
823 long lttng_channel_syscall_mask(struct lttng_kernel_channel_buffer
*channel
,
824 struct lttng_kernel_abi_syscall_mask __user
*usyscall_mask
);
826 int lttng_syscalls_register_event_notifier(
827 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
828 int lttng_syscalls_create_matching_event_notifiers(
829 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
830 int lttng_syscalls_unregister_event_notifier_group(struct lttng_event_notifier_group
*group
);
831 int lttng_syscall_filter_enable_event_notifier(struct lttng_kernel_event_notifier
*event_notifier
);
832 int lttng_syscall_filter_disable_event_notifier(struct lttng_kernel_event_notifier
*event_notifier
);
834 static inline int lttng_syscalls_register_event(
835 struct lttng_event_enabler
*event_enabler
)
840 static inline int lttng_syscalls_unregister_channel(struct lttng_kernel_channel_buffer
*chan
)
845 static inline int lttng_syscalls_destroy(struct lttng_kernel_channel_buffer
*chan
)
850 static inline int lttng_syscall_filter_enable_event(struct lttng_kernel_channel_buffer
*chan
,
851 struct lttng_kernel_event_recorder
*event
);
856 static inline int lttng_syscall_filter_disable_event(struct lttng_kernel_channel_buffer
*chan
,
857 struct lttng_kernel_event_recorder
*event
);
862 static inline long lttng_channel_syscall_mask(struct lttng_kernel_channel_buffer
*channel
,
863 struct lttng_kernel_syscall_mask __user
*usyscall_mask
)
868 static inline int lttng_syscalls_register_event_notifier(
869 struct lttng_event_notifier_group
*group
)
874 static inline int lttng_syscalls_unregister_event_notifier_group(
875 struct lttng_event_notifier_group
*group
)
880 static inline int lttng_syscall_filter_enable_event_notifier(
881 struct lttng_event_notifier_group
*group
,
887 static inline int lttng_syscall_filter_disable_event_notifier(
888 struct lttng_event_notifier_group
*group
,
896 #ifdef CONFIG_KPROBES
897 int lttng_kprobes_register_event(const char *name
,
898 const char *symbol_name
,
901 struct lttng_kernel_event_recorder
*event
);
902 void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder
*event
);
903 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder
*event
);
904 int lttng_kprobes_register_event_notifier(const char *symbol_name
,
907 struct lttng_kernel_event_notifier
*event_notifier
);
908 void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier
*event_notifier
);
909 void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier
*event_notifier
);
912 int lttng_kprobes_register_event(const char *name
,
913 const char *symbol_name
,
916 struct lttng_kernel_event_recorder
*event
)
922 void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder
*event
)
927 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder
*event
)
932 int lttng_kprobes_register_event_notifier(const char *symbol_name
,
935 struct lttng_kernel_event_notifier
*event_notifier
)
941 void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier
*event_notifier
)
946 void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier
*event_notifier
)
951 int lttng_event_add_callsite(struct lttng_kernel_event_common
*event
,
952 struct lttng_kernel_abi_event_callsite __user
*callsite
);
954 #ifdef CONFIG_UPROBES
955 int lttng_uprobes_register_event(const char *name
,
956 int fd
, struct lttng_kernel_event_recorder
*event
);
957 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common
*event
,
958 struct lttng_kernel_abi_event_callsite __user
*callsite
);
959 void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder
*event
);
960 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder
*event
);
961 int lttng_uprobes_register_event_notifier(const char *name
,
962 int fd
, struct lttng_kernel_event_notifier
*event_notifier
);
963 void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier
*event_notifier
);
964 void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier
*event_notifier
);
967 int lttng_uprobes_register_event(const char *name
,
968 int fd
, struct lttng_kernel_event_recorder
*event
)
974 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common
*event
,
975 struct lttng_kernel_abi_event_callsite __user
*callsite
)
981 void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder
*event
)
986 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder
*event
)
991 int lttng_uprobes_register_event_notifier(const char *name
,
992 int fd
, struct lttng_kernel_event_notifier
*event_notifier
)
998 void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier
*event_notifier
)
1003 void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier
*event_notifier
)
1008 #ifdef CONFIG_KRETPROBES
1009 int lttng_kretprobes_register(const char *name
,
1010 const char *symbol_name
,
1013 struct lttng_kernel_event_recorder
*event_entry
,
1014 struct lttng_kernel_event_recorder
*event_exit
);
1015 void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder
*event
);
1016 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder
*event
);
1017 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common
*event
,
1021 int lttng_kretprobes_register(const char *name
,
1022 const char *symbol_name
,
1025 struct lttng_kernel_event_recorder
*event_entry
,
1026 struct lttng_kernel_event_recorder
*event_exit
)
1032 void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder
*event
)
1037 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder
*event
)
1042 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common
*event
,
1049 void lttng_lock_sessions(void);
1050 void lttng_unlock_sessions(void);
1052 struct list_head
*lttng_get_probe_list_head(void);
1054 int lttng_fix_pending_events(void);
1055 int lttng_fix_pending_event_notifiers(void);
1056 int lttng_session_active(void);
1057 bool lttng_event_notifier_active(void);
1059 struct lttng_kernel_session
*lttng_session_create(void);
1060 int lttng_session_enable(struct lttng_kernel_session
*session
);
1061 int lttng_session_disable(struct lttng_kernel_session
*session
);
1062 void lttng_session_destroy(struct lttng_kernel_session
*session
);
1063 int lttng_session_metadata_regenerate(struct lttng_kernel_session
*session
);
1064 int lttng_session_statedump(struct lttng_kernel_session
*session
);
1065 void metadata_cache_destroy(struct kref
*kref
);
1067 struct lttng_counter
*lttng_kernel_counter_create(
1068 const char *counter_transport_name
, size_t number_dimensions
,
1069 const size_t *dimensions_sizes
);
1070 int lttng_kernel_counter_read(struct lttng_counter
*counter
,
1071 const size_t *dimension_indexes
, int32_t cpu
,
1072 int64_t *val
, bool *overflow
, bool *underflow
);
1073 int lttng_kernel_counter_aggregate(struct lttng_counter
*counter
,
1074 const size_t *dimension_indexes
, int64_t *val
,
1075 bool *overflow
, bool *underflow
);
1076 int lttng_kernel_counter_clear(struct lttng_counter
*counter
,
1077 const size_t *dimension_indexes
);
1078 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void);
1079 int lttng_event_notifier_group_create_error_counter(
1080 struct file
*event_notifier_group_file
,
1081 const struct lttng_kernel_abi_counter_conf
*error_counter_conf
);
1082 void lttng_event_notifier_group_destroy(
1083 struct lttng_event_notifier_group
*event_notifier_group
);
1085 struct lttng_kernel_channel_buffer
*lttng_channel_create(struct lttng_kernel_session
*session
,
1086 const char *transport_name
,
1088 size_t subbuf_size
, size_t num_subbuf
,
1089 unsigned int switch_timer_interval
,
1090 unsigned int read_timer_interval
,
1091 enum channel_type channel_type
);
1092 struct lttng_kernel_channel_buffer
*lttng_global_channel_create(struct lttng_kernel_session
*session
,
1093 int overwrite
, void *buf_addr
,
1094 size_t subbuf_size
, size_t num_subbuf
,
1095 unsigned int switch_timer_interval
,
1096 unsigned int read_timer_interval
);
1098 void lttng_metadata_channel_destroy(struct lttng_kernel_channel_buffer
*chan
);
1099 struct lttng_kernel_event_recorder
*lttng_kernel_event_recorder_create(struct lttng_kernel_channel_buffer
*chan
,
1100 struct lttng_kernel_abi_event
*event_param
,
1101 const struct lttng_kernel_event_desc
*event_desc
,
1102 enum lttng_kernel_abi_instrumentation itype
);
1103 struct lttng_kernel_event_recorder
*_lttng_kernel_event_recorder_create(struct lttng_kernel_channel_buffer
*chan
,
1104 struct lttng_kernel_abi_event
*event_param
,
1105 const struct lttng_kernel_event_desc
*event_desc
,
1106 enum lttng_kernel_abi_instrumentation itype
);
1107 struct lttng_kernel_event_recorder
*lttng_event_compat_old_create(struct lttng_kernel_channel_buffer
*chan
,
1108 struct lttng_kernel_abi_old_event
*old_event_param
,
1109 const struct lttng_kernel_event_desc
*internal_desc
);
1111 struct lttng_kernel_event_notifier
*lttng_event_notifier_create(
1112 const struct lttng_kernel_event_desc
*event_notifier_desc
,
1114 uint64_t error_counter_idx
,
1115 struct lttng_event_notifier_group
*event_notifier_group
,
1116 struct lttng_kernel_abi_event_notifier
*event_notifier_param
,
1117 enum lttng_kernel_abi_instrumentation itype
);
1118 struct lttng_kernel_event_notifier
*_lttng_event_notifier_create(
1119 const struct lttng_kernel_event_desc
*event_notifier_desc
,
1121 uint64_t error_counter_idx
,
1122 struct lttng_event_notifier_group
*event_notifier_group
,
1123 struct lttng_kernel_abi_event_notifier
*event_notifier_param
,
1124 enum lttng_kernel_abi_instrumentation itype
);
1126 int lttng_channel_enable(struct lttng_kernel_channel_buffer
*channel
);
1127 int lttng_channel_disable(struct lttng_kernel_channel_buffer
*channel
);
1128 int lttng_event_enable(struct lttng_kernel_event_common
*event
);
1129 int lttng_event_disable(struct lttng_kernel_event_common
*event
);
1131 void lttng_transport_register(struct lttng_transport
*transport
);
1132 void lttng_transport_unregister(struct lttng_transport
*transport
);
1134 void lttng_counter_transport_register(struct lttng_counter_transport
*transport
);
1135 void lttng_counter_transport_unregister(struct lttng_counter_transport
*transport
);
1137 void synchronize_trace(void);
1138 int lttng_abi_init(void);
1139 int lttng_abi_compat_old_init(void);
1140 void lttng_abi_exit(void);
1141 void lttng_abi_compat_old_exit(void);
1143 const struct lttng_kernel_event_desc
*lttng_event_desc_get(const char *name
);
1144 void lttng_event_desc_put(const struct lttng_kernel_event_desc
*desc
);
1145 int lttng_probes_init(void);
1146 void lttng_probes_exit(void);
1148 int lttng_metadata_output_channel(struct lttng_metadata_stream
*stream
,
1149 struct lttng_kernel_ring_buffer_channel
*chan
, bool *coherent
);
1151 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node
*node
);
1152 int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker
*lf
);
1153 int lttng_id_tracker_init(struct lttng_kernel_id_tracker
*lf
,
1154 struct lttng_kernel_session
*session
,
1155 enum tracker_type type
);
1156 void lttng_id_tracker_fini(struct lttng_kernel_id_tracker
*lf
);
1157 void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker
*lf
, bool rcu
);
1158 int lttng_id_tracker_add(struct lttng_kernel_id_tracker
*lf
, int id
);
1159 int lttng_id_tracker_del(struct lttng_kernel_id_tracker
*lf
, int id
);
1161 int lttng_session_track_id(struct lttng_kernel_session
*session
,
1162 enum tracker_type tracker_type
, int id
);
1163 int lttng_session_untrack_id(struct lttng_kernel_session
*session
,
1164 enum tracker_type tracker_type
, int id
);
1166 int lttng_session_list_tracker_ids(struct lttng_kernel_session
*session
,
1167 enum tracker_type tracker_type
);
1169 void lttng_clock_ref(void);
1170 void lttng_clock_unref(void);
1172 void lttng_free_event_filter_runtime(struct lttng_kernel_event_common
*event
);
1174 int lttng_probes_init(void);
1176 int lttng_logger_init(void);
1177 void lttng_logger_exit(void);
1179 extern int lttng_statedump_start(struct lttng_kernel_session
*session
);
1181 int lttng_calibrate(struct lttng_kernel_abi_calibrate
*calibrate
);
1183 extern const struct file_operations lttng_tracepoint_list_fops
;
1184 extern const struct file_operations lttng_syscall_list_fops
;
1186 #define lttng_kernel_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
1187 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
1188 .event_field = (_event_field), \
1189 .get_size = (_get_size), \
1190 .record = (_record), \
1191 .get_value = (_get_value), \
1192 .destroy = (_destroy), \
1196 #endif /* _LTTNG_EVENTS_INTERNAL_H */