1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
5 * Holds LTTng per-session event registry.
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This page_alloc.h wrapper needs to be included before gfpflags.h because it
12 * overrides a function with a define.
14 #include "wrapper/page_alloc.h"
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/sched.h>
19 #include <linux/slab.h>
20 #include <linux/jiffies.h>
21 #include <linux/utsname.h>
22 #include <linux/err.h>
23 #include <linux/seq_file.h>
24 #include <linux/file.h>
25 #include <linux/anon_inodes.h>
26 #include <wrapper/file.h>
27 #include <linux/jhash.h>
28 #include <linux/uaccess.h>
29 #include <linux/vmalloc.h>
31 #include <wrapper/uuid.h>
32 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
33 #include <wrapper/random.h>
34 #include <wrapper/tracepoint.h>
35 #include <wrapper/list.h>
36 #include <wrapper/types.h>
37 #include <lttng-kernel-version.h>
38 #include <lttng-events.h>
39 #include <lttng-tracer.h>
40 #include <lttng-abi-old.h>
41 #include <lttng-endian.h>
42 #include <lttng-string-utils.h>
43 #include <wrapper/vzalloc.h>
44 #include <wrapper/ringbuffer/backend.h>
45 #include <wrapper/ringbuffer/frontend.h>
46 #include <wrapper/time.h>
48 #define METADATA_CACHE_DEFAULT_SIZE 4096
50 static LIST_HEAD(sessions
);
51 static LIST_HEAD(lttng_transport_list
);
53 * Protect the sessions and metadata caches.
55 static DEFINE_MUTEX(sessions_mutex
);
56 static struct kmem_cache
*event_cache
;
58 static void lttng_session_lazy_sync_enablers(struct lttng_session
*session
);
59 static void lttng_session_sync_enablers(struct lttng_session
*session
);
60 static void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
62 static void _lttng_event_destroy(struct lttng_event
*event
);
63 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
64 static int _lttng_event_unregister(struct lttng_event
*event
);
66 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
67 struct lttng_channel
*chan
,
68 struct lttng_event
*event
);
70 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
72 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream
*stream
);
74 int _lttng_field_statedump(struct lttng_session
*session
,
75 const struct lttng_event_field
*field
,
78 void synchronize_trace(void)
80 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
86 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
87 #ifdef CONFIG_PREEMPT_RT_FULL
90 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
91 #ifdef CONFIG_PREEMPT_RT
94 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
97 void lttng_lock_sessions(void)
99 mutex_lock(&sessions_mutex
);
102 void lttng_unlock_sessions(void)
104 mutex_unlock(&sessions_mutex
);
108 * Called with sessions lock held.
110 int lttng_session_active(void)
112 struct lttng_session
*iter
;
114 list_for_each_entry(iter
, &sessions
, list
) {
121 struct lttng_session
*lttng_session_create(void)
123 struct lttng_session
*session
;
124 struct lttng_metadata_cache
*metadata_cache
;
127 mutex_lock(&sessions_mutex
);
128 session
= lttng_kvzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
131 INIT_LIST_HEAD(&session
->chan
);
132 INIT_LIST_HEAD(&session
->events
);
133 uuid_le_gen(&session
->uuid
);
135 metadata_cache
= kzalloc(sizeof(struct lttng_metadata_cache
),
138 goto err_free_session
;
139 metadata_cache
->data
= lttng_vzalloc(METADATA_CACHE_DEFAULT_SIZE
);
140 if (!metadata_cache
->data
)
142 metadata_cache
->cache_alloc
= METADATA_CACHE_DEFAULT_SIZE
;
143 kref_init(&metadata_cache
->refcount
);
144 mutex_init(&metadata_cache
->lock
);
145 session
->metadata_cache
= metadata_cache
;
146 INIT_LIST_HEAD(&metadata_cache
->metadata_stream
);
147 memcpy(&metadata_cache
->uuid
, &session
->uuid
,
148 sizeof(metadata_cache
->uuid
));
149 INIT_LIST_HEAD(&session
->enablers_head
);
150 for (i
= 0; i
< LTTNG_EVENT_HT_SIZE
; i
++)
151 INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
152 list_add(&session
->list
, &sessions
);
153 mutex_unlock(&sessions_mutex
);
157 kfree(metadata_cache
);
159 lttng_kvfree(session
);
161 mutex_unlock(&sessions_mutex
);
165 void metadata_cache_destroy(struct kref
*kref
)
167 struct lttng_metadata_cache
*cache
=
168 container_of(kref
, struct lttng_metadata_cache
, refcount
);
173 void lttng_session_destroy(struct lttng_session
*session
)
175 struct lttng_channel
*chan
, *tmpchan
;
176 struct lttng_event
*event
, *tmpevent
;
177 struct lttng_metadata_stream
*metadata_stream
;
178 struct lttng_enabler
*enabler
, *tmpenabler
;
181 mutex_lock(&sessions_mutex
);
182 WRITE_ONCE(session
->active
, 0);
183 list_for_each_entry(chan
, &session
->chan
, list
) {
184 ret
= lttng_syscalls_unregister(chan
);
187 list_for_each_entry(event
, &session
->events
, list
) {
188 ret
= _lttng_event_unregister(event
);
191 synchronize_trace(); /* Wait for in-flight events to complete */
192 list_for_each_entry_safe(enabler
, tmpenabler
,
193 &session
->enablers_head
, node
)
194 lttng_enabler_destroy(enabler
);
195 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
196 _lttng_event_destroy(event
);
197 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
) {
198 BUG_ON(chan
->channel_type
== METADATA_CHANNEL
);
199 _lttng_channel_destroy(chan
);
201 list_for_each_entry(metadata_stream
, &session
->metadata_cache
->metadata_stream
, list
)
202 _lttng_metadata_channel_hangup(metadata_stream
);
203 if (session
->pid_tracker
)
204 lttng_pid_tracker_destroy(session
->pid_tracker
);
205 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
206 list_del(&session
->list
);
207 mutex_unlock(&sessions_mutex
);
208 lttng_kvfree(session
);
211 int lttng_session_statedump(struct lttng_session
*session
)
215 mutex_lock(&sessions_mutex
);
216 ret
= lttng_statedump_start(session
);
217 mutex_unlock(&sessions_mutex
);
221 int lttng_session_enable(struct lttng_session
*session
)
224 struct lttng_channel
*chan
;
226 mutex_lock(&sessions_mutex
);
227 if (session
->active
) {
232 /* Set transient enabler state to "enabled" */
236 * Snapshot the number of events per channel to know the type of header
239 list_for_each_entry(chan
, &session
->chan
, list
) {
240 if (chan
->header_type
)
241 continue; /* don't change it if session stop/restart */
242 if (chan
->free_event_id
< 31)
243 chan
->header_type
= 1; /* compact */
245 chan
->header_type
= 2; /* large */
248 /* We need to sync enablers with session before activation. */
249 lttng_session_sync_enablers(session
);
251 /* Clear each stream's quiescent state. */
252 list_for_each_entry(chan
, &session
->chan
, list
) {
253 if (chan
->channel_type
!= METADATA_CHANNEL
)
254 lib_ring_buffer_clear_quiescent_channel(chan
->chan
);
257 WRITE_ONCE(session
->active
, 1);
258 WRITE_ONCE(session
->been_active
, 1);
259 ret
= _lttng_session_metadata_statedump(session
);
261 WRITE_ONCE(session
->active
, 0);
264 ret
= lttng_statedump_start(session
);
266 WRITE_ONCE(session
->active
, 0);
268 mutex_unlock(&sessions_mutex
);
272 int lttng_session_disable(struct lttng_session
*session
)
275 struct lttng_channel
*chan
;
277 mutex_lock(&sessions_mutex
);
278 if (!session
->active
) {
282 WRITE_ONCE(session
->active
, 0);
284 /* Set transient enabler state to "disabled" */
286 lttng_session_sync_enablers(session
);
288 /* Set each stream's quiescent state. */
289 list_for_each_entry(chan
, &session
->chan
, list
) {
290 if (chan
->channel_type
!= METADATA_CHANNEL
)
291 lib_ring_buffer_set_quiescent_channel(chan
->chan
);
294 mutex_unlock(&sessions_mutex
);
298 int lttng_session_metadata_regenerate(struct lttng_session
*session
)
301 struct lttng_channel
*chan
;
302 struct lttng_event
*event
;
303 struct lttng_metadata_cache
*cache
= session
->metadata_cache
;
304 struct lttng_metadata_stream
*stream
;
306 mutex_lock(&sessions_mutex
);
307 if (!session
->active
) {
312 mutex_lock(&cache
->lock
);
313 memset(cache
->data
, 0, cache
->cache_alloc
);
314 cache
->metadata_written
= 0;
316 list_for_each_entry(stream
, &session
->metadata_cache
->metadata_stream
, list
) {
317 stream
->metadata_out
= 0;
318 stream
->metadata_in
= 0;
320 mutex_unlock(&cache
->lock
);
322 session
->metadata_dumped
= 0;
323 list_for_each_entry(chan
, &session
->chan
, list
) {
324 chan
->metadata_dumped
= 0;
327 list_for_each_entry(event
, &session
->events
, list
) {
328 event
->metadata_dumped
= 0;
331 ret
= _lttng_session_metadata_statedump(session
);
334 mutex_unlock(&sessions_mutex
);
338 int lttng_channel_enable(struct lttng_channel
*channel
)
342 mutex_lock(&sessions_mutex
);
343 if (channel
->channel_type
== METADATA_CHANNEL
) {
347 if (channel
->enabled
) {
351 /* Set transient enabler state to "enabled" */
353 lttng_session_sync_enablers(channel
->session
);
354 /* Set atomically the state to "enabled" */
355 WRITE_ONCE(channel
->enabled
, 1);
357 mutex_unlock(&sessions_mutex
);
361 int lttng_channel_disable(struct lttng_channel
*channel
)
365 mutex_lock(&sessions_mutex
);
366 if (channel
->channel_type
== METADATA_CHANNEL
) {
370 if (!channel
->enabled
) {
374 /* Set atomically the state to "disabled" */
375 WRITE_ONCE(channel
->enabled
, 0);
376 /* Set transient enabler state to "enabled" */
378 lttng_session_sync_enablers(channel
->session
);
380 mutex_unlock(&sessions_mutex
);
384 int lttng_event_enable(struct lttng_event
*event
)
388 mutex_lock(&sessions_mutex
);
389 if (event
->chan
->channel_type
== METADATA_CHANNEL
) {
393 if (event
->enabled
) {
397 switch (event
->instrumentation
) {
398 case LTTNG_KERNEL_TRACEPOINT
:
399 case LTTNG_KERNEL_SYSCALL
:
402 case LTTNG_KERNEL_KPROBE
:
403 case LTTNG_KERNEL_UPROBE
:
404 case LTTNG_KERNEL_NOOP
:
405 WRITE_ONCE(event
->enabled
, 1);
407 case LTTNG_KERNEL_KRETPROBE
:
408 ret
= lttng_kretprobes_event_enable_state(event
, 1);
410 case LTTNG_KERNEL_FUNCTION
: /* Fall-through. */
416 mutex_unlock(&sessions_mutex
);
420 int lttng_event_disable(struct lttng_event
*event
)
424 mutex_lock(&sessions_mutex
);
425 if (event
->chan
->channel_type
== METADATA_CHANNEL
) {
429 if (!event
->enabled
) {
433 switch (event
->instrumentation
) {
434 case LTTNG_KERNEL_TRACEPOINT
:
435 case LTTNG_KERNEL_SYSCALL
:
438 case LTTNG_KERNEL_KPROBE
:
439 case LTTNG_KERNEL_UPROBE
:
440 case LTTNG_KERNEL_NOOP
:
441 WRITE_ONCE(event
->enabled
, 0);
443 case LTTNG_KERNEL_KRETPROBE
:
444 ret
= lttng_kretprobes_event_enable_state(event
, 0);
446 case LTTNG_KERNEL_FUNCTION
: /* Fall-through. */
452 mutex_unlock(&sessions_mutex
);
456 static struct lttng_transport
*lttng_transport_find(const char *name
)
458 struct lttng_transport
*transport
;
460 list_for_each_entry(transport
, <tng_transport_list
, node
) {
461 if (!strcmp(transport
->name
, name
))
467 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
468 const char *transport_name
,
470 size_t subbuf_size
, size_t num_subbuf
,
471 unsigned int switch_timer_interval
,
472 unsigned int read_timer_interval
,
473 enum channel_type channel_type
)
475 struct lttng_channel
*chan
;
476 struct lttng_transport
*transport
= NULL
;
478 mutex_lock(&sessions_mutex
);
479 if (session
->been_active
&& channel_type
!= METADATA_CHANNEL
)
480 goto active
; /* Refuse to add channel to active session */
481 transport
= lttng_transport_find(transport_name
);
483 printk(KERN_WARNING
"LTTng transport %s not found\n",
487 if (!try_module_get(transport
->owner
)) {
488 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
491 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
494 chan
->session
= session
;
495 chan
->id
= session
->free_chan_id
++;
496 chan
->ops
= &transport
->ops
;
498 * Note: the channel creation op already writes into the packet
499 * headers. Therefore the "chan" information used as input
500 * should be already accessible.
502 chan
->chan
= transport
->ops
.channel_create(transport_name
,
503 chan
, buf_addr
, subbuf_size
, num_subbuf
,
504 switch_timer_interval
, read_timer_interval
);
509 chan
->transport
= transport
;
510 chan
->channel_type
= channel_type
;
511 list_add(&chan
->list
, &session
->chan
);
512 mutex_unlock(&sessions_mutex
);
519 module_put(transport
->owner
);
522 mutex_unlock(&sessions_mutex
);
527 * Only used internally at session destruction for per-cpu channels, and
528 * when metadata channel is released.
529 * Needs to be called with sessions mutex held.
532 void _lttng_channel_destroy(struct lttng_channel
*chan
)
534 chan
->ops
->channel_destroy(chan
->chan
);
535 module_put(chan
->transport
->owner
);
536 list_del(&chan
->list
);
537 lttng_destroy_context(chan
->ctx
);
541 void lttng_metadata_channel_destroy(struct lttng_channel
*chan
)
543 BUG_ON(chan
->channel_type
!= METADATA_CHANNEL
);
545 /* Protect the metadata cache with the sessions_mutex. */
546 mutex_lock(&sessions_mutex
);
547 _lttng_channel_destroy(chan
);
548 mutex_unlock(&sessions_mutex
);
550 EXPORT_SYMBOL_GPL(lttng_metadata_channel_destroy
);
553 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream
*stream
)
555 stream
->finalized
= 1;
556 wake_up_interruptible(&stream
->read_wait
);
560 * Supports event creation while tracing session is active.
561 * Needs to be called with sessions mutex held.
563 struct lttng_event
*_lttng_event_create(struct lttng_channel
*chan
,
564 struct lttng_kernel_event
*event_param
,
566 const struct lttng_event_desc
*event_desc
,
567 enum lttng_kernel_instrumentation itype
)
569 struct lttng_session
*session
= chan
->session
;
570 struct lttng_event
*event
;
571 const char *event_name
;
572 struct hlist_head
*head
;
577 if (chan
->free_event_id
== -1U) {
583 case LTTNG_KERNEL_TRACEPOINT
:
584 event_name
= event_desc
->name
;
586 case LTTNG_KERNEL_KPROBE
:
587 case LTTNG_KERNEL_UPROBE
:
588 case LTTNG_KERNEL_KRETPROBE
:
589 case LTTNG_KERNEL_NOOP
:
590 case LTTNG_KERNEL_SYSCALL
:
591 event_name
= event_param
->name
;
593 case LTTNG_KERNEL_FUNCTION
: /* Fall-through. */
599 name_len
= strlen(event_name
);
600 hash
= jhash(event_name
, name_len
, 0);
601 head
= &session
->events_ht
.table
[hash
& (LTTNG_EVENT_HT_SIZE
- 1)];
602 lttng_hlist_for_each_entry(event
, head
, hlist
) {
603 WARN_ON_ONCE(!event
->desc
);
604 if (!strncmp(event
->desc
->name
, event_name
,
605 LTTNG_KERNEL_SYM_NAME_LEN
- 1)
606 && chan
== event
->chan
) {
612 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
618 event
->filter
= filter
;
619 event
->id
= chan
->free_event_id
++;
620 event
->instrumentation
= itype
;
621 event
->evtype
= LTTNG_TYPE_EVENT
;
622 INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
623 INIT_LIST_HEAD(&event
->enablers_ref_head
);
626 case LTTNG_KERNEL_TRACEPOINT
:
627 /* Event will be enabled by enabler sync. */
629 event
->registered
= 0;
630 event
->desc
= lttng_event_get(event_name
);
635 /* Populate lttng_event structure before event registration. */
638 case LTTNG_KERNEL_KPROBE
:
640 * Needs to be explicitly enabled after creation, since
641 * we may want to apply filters.
644 event
->registered
= 1;
646 * Populate lttng_event structure before event
650 ret
= lttng_kprobes_register(event_name
,
651 event_param
->u
.kprobe
.symbol_name
,
652 event_param
->u
.kprobe
.offset
,
653 event_param
->u
.kprobe
.addr
,
659 ret
= try_module_get(event
->desc
->owner
);
662 case LTTNG_KERNEL_KRETPROBE
:
664 struct lttng_event
*event_return
;
666 /* kretprobe defines 2 events */
668 * Needs to be explicitly enabled after creation, since
669 * we may want to apply filters.
672 event
->registered
= 1;
674 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
679 event_return
->chan
= chan
;
680 event_return
->filter
= filter
;
681 event_return
->id
= chan
->free_event_id
++;
682 event_return
->enabled
= 0;
683 event_return
->registered
= 1;
684 event_return
->instrumentation
= itype
;
686 * Populate lttng_event structure before kretprobe registration.
689 ret
= lttng_kretprobes_register(event_name
,
690 event_param
->u
.kretprobe
.symbol_name
,
691 event_param
->u
.kretprobe
.offset
,
692 event_param
->u
.kretprobe
.addr
,
693 event
, event_return
);
695 kmem_cache_free(event_cache
, event_return
);
699 /* Take 2 refs on the module: one per event. */
700 ret
= try_module_get(event
->desc
->owner
);
702 ret
= try_module_get(event
->desc
->owner
);
704 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
706 WARN_ON_ONCE(ret
> 0);
708 kmem_cache_free(event_cache
, event_return
);
709 module_put(event
->desc
->owner
);
710 module_put(event
->desc
->owner
);
711 goto statedump_error
;
713 list_add(&event_return
->list
, &chan
->session
->events
);
716 case LTTNG_KERNEL_NOOP
:
717 case LTTNG_KERNEL_SYSCALL
:
719 * Needs to be explicitly enabled after creation, since
720 * we may want to apply filters.
723 event
->registered
= 0;
724 event
->desc
= event_desc
;
730 case LTTNG_KERNEL_UPROBE
:
732 * Needs to be explicitly enabled after creation, since
733 * we may want to apply filters.
736 event
->registered
= 1;
739 * Populate lttng_event structure before event
744 ret
= lttng_uprobes_register(event_param
->name
,
745 event_param
->u
.uprobe
.fd
,
749 ret
= try_module_get(event
->desc
->owner
);
752 case LTTNG_KERNEL_FUNCTION
: /* Fall-through */
758 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
759 WARN_ON_ONCE(ret
> 0);
761 goto statedump_error
;
763 hlist_add_head(&event
->hlist
, head
);
764 list_add(&event
->list
, &chan
->session
->events
);
768 /* If a statedump error occurs, events will not be readable. */
770 kmem_cache_free(event_cache
, event
);
778 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
779 struct lttng_kernel_event
*event_param
,
781 const struct lttng_event_desc
*event_desc
,
782 enum lttng_kernel_instrumentation itype
)
784 struct lttng_event
*event
;
786 mutex_lock(&sessions_mutex
);
787 event
= _lttng_event_create(chan
, event_param
, filter
, event_desc
,
789 mutex_unlock(&sessions_mutex
);
793 /* Only used for tracepoints for now. */
795 void register_event(struct lttng_event
*event
)
797 const struct lttng_event_desc
*desc
;
800 if (event
->registered
)
804 switch (event
->instrumentation
) {
805 case LTTNG_KERNEL_TRACEPOINT
:
806 ret
= lttng_wrapper_tracepoint_probe_register(desc
->kname
,
807 desc
->probe_callback
,
810 case LTTNG_KERNEL_SYSCALL
:
811 ret
= lttng_syscall_filter_enable(event
->chan
,
814 case LTTNG_KERNEL_KPROBE
:
815 case LTTNG_KERNEL_UPROBE
:
816 case LTTNG_KERNEL_KRETPROBE
:
817 case LTTNG_KERNEL_NOOP
:
820 case LTTNG_KERNEL_FUNCTION
: /* Fall-through */
825 event
->registered
= 1;
829 * Only used internally at session destruction.
831 int _lttng_event_unregister(struct lttng_event
*event
)
833 const struct lttng_event_desc
*desc
;
836 if (!event
->registered
)
840 switch (event
->instrumentation
) {
841 case LTTNG_KERNEL_TRACEPOINT
:
842 ret
= lttng_wrapper_tracepoint_probe_unregister(event
->desc
->kname
,
843 event
->desc
->probe_callback
,
846 case LTTNG_KERNEL_KPROBE
:
847 lttng_kprobes_unregister(event
);
850 case LTTNG_KERNEL_KRETPROBE
:
851 lttng_kretprobes_unregister(event
);
854 case LTTNG_KERNEL_SYSCALL
:
855 ret
= lttng_syscall_filter_disable(event
->chan
,
858 case LTTNG_KERNEL_NOOP
:
861 case LTTNG_KERNEL_UPROBE
:
862 lttng_uprobes_unregister(event
);
865 case LTTNG_KERNEL_FUNCTION
: /* Fall-through */
870 event
->registered
= 0;
875 * Only used internally at session destruction.
878 void _lttng_event_destroy(struct lttng_event
*event
)
880 switch (event
->instrumentation
) {
881 case LTTNG_KERNEL_TRACEPOINT
:
882 lttng_event_put(event
->desc
);
884 case LTTNG_KERNEL_KPROBE
:
885 module_put(event
->desc
->owner
);
886 lttng_kprobes_destroy_private(event
);
888 case LTTNG_KERNEL_KRETPROBE
:
889 module_put(event
->desc
->owner
);
890 lttng_kretprobes_destroy_private(event
);
892 case LTTNG_KERNEL_NOOP
:
893 case LTTNG_KERNEL_SYSCALL
:
895 case LTTNG_KERNEL_UPROBE
:
896 module_put(event
->desc
->owner
);
897 lttng_uprobes_destroy_private(event
);
899 case LTTNG_KERNEL_FUNCTION
: /* Fall-through */
903 list_del(&event
->list
);
904 lttng_destroy_context(event
->ctx
);
905 kmem_cache_free(event_cache
, event
);
908 int lttng_session_track_pid(struct lttng_session
*session
, int pid
)
914 mutex_lock(&sessions_mutex
);
916 /* track all pids: destroy tracker. */
917 if (session
->pid_tracker
) {
918 struct lttng_pid_tracker
*lpf
;
920 lpf
= session
->pid_tracker
;
921 rcu_assign_pointer(session
->pid_tracker
, NULL
);
923 lttng_pid_tracker_destroy(lpf
);
927 if (!session
->pid_tracker
) {
928 struct lttng_pid_tracker
*lpf
;
930 lpf
= lttng_pid_tracker_create();
935 ret
= lttng_pid_tracker_add(lpf
, pid
);
936 rcu_assign_pointer(session
->pid_tracker
, lpf
);
938 ret
= lttng_pid_tracker_add(session
->pid_tracker
, pid
);
942 mutex_unlock(&sessions_mutex
);
946 int lttng_session_untrack_pid(struct lttng_session
*session
, int pid
)
952 mutex_lock(&sessions_mutex
);
954 /* untrack all pids: replace by empty tracker. */
955 struct lttng_pid_tracker
*old_lpf
= session
->pid_tracker
;
956 struct lttng_pid_tracker
*lpf
;
958 lpf
= lttng_pid_tracker_create();
963 rcu_assign_pointer(session
->pid_tracker
, lpf
);
966 lttng_pid_tracker_destroy(old_lpf
);
969 if (!session
->pid_tracker
) {
973 ret
= lttng_pid_tracker_del(session
->pid_tracker
, pid
);
976 mutex_unlock(&sessions_mutex
);
981 void *pid_list_start(struct seq_file
*m
, loff_t
*pos
)
983 struct lttng_session
*session
= m
->private;
984 struct lttng_pid_tracker
*lpf
;
985 struct lttng_pid_hash_node
*e
;
988 mutex_lock(&sessions_mutex
);
989 lpf
= session
->pid_tracker
;
991 for (i
= 0; i
< LTTNG_PID_TABLE_SIZE
; i
++) {
992 struct hlist_head
*head
= &lpf
->pid_hash
[i
];
994 lttng_hlist_for_each_entry(e
, head
, hlist
) {
1000 /* PID tracker disabled. */
1001 if (iter
>= *pos
&& iter
== 0) {
1002 return session
; /* empty tracker */
1010 /* Called with sessions_mutex held. */
1012 void *pid_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1014 struct lttng_session
*session
= m
->private;
1015 struct lttng_pid_tracker
*lpf
;
1016 struct lttng_pid_hash_node
*e
;
1020 lpf
= session
->pid_tracker
;
1022 for (i
= 0; i
< LTTNG_PID_TABLE_SIZE
; i
++) {
1023 struct hlist_head
*head
= &lpf
->pid_hash
[i
];
1025 lttng_hlist_for_each_entry(e
, head
, hlist
) {
1026 if (iter
++ >= *ppos
)
1031 /* PID tracker disabled. */
1032 if (iter
>= *ppos
&& iter
== 0)
1033 return session
; /* empty tracker */
1042 void pid_list_stop(struct seq_file
*m
, void *p
)
1044 mutex_unlock(&sessions_mutex
);
1048 int pid_list_show(struct seq_file
*m
, void *p
)
1052 if (p
== m
->private) {
1053 /* Tracker disabled. */
1056 const struct lttng_pid_hash_node
*e
= p
;
1058 pid
= lttng_pid_tracker_get_node_pid(e
);
1060 seq_printf(m
, "process { pid = %d; };\n", pid
);
1065 const struct seq_operations lttng_tracker_pids_list_seq_ops
= {
1066 .start
= pid_list_start
,
1067 .next
= pid_list_next
,
1068 .stop
= pid_list_stop
,
1069 .show
= pid_list_show
,
1073 int lttng_tracker_pids_list_open(struct inode
*inode
, struct file
*file
)
1075 return seq_open(file
, <tng_tracker_pids_list_seq_ops
);
1079 int lttng_tracker_pids_list_release(struct inode
*inode
, struct file
*file
)
1081 struct seq_file
*m
= file
->private_data
;
1082 struct lttng_session
*session
= m
->private;
1085 WARN_ON_ONCE(!session
);
1086 ret
= seq_release(inode
, file
);
1087 if (!ret
&& session
)
1088 fput(session
->file
);
1092 const struct file_operations lttng_tracker_pids_list_fops
= {
1093 .owner
= THIS_MODULE
,
1094 .open
= lttng_tracker_pids_list_open
,
1096 .llseek
= seq_lseek
,
1097 .release
= lttng_tracker_pids_list_release
,
1100 int lttng_session_list_tracker_pids(struct lttng_session
*session
)
1102 struct file
*tracker_pids_list_file
;
1106 file_fd
= lttng_get_unused_fd();
1112 tracker_pids_list_file
= anon_inode_getfile("[lttng_tracker_pids_list]",
1113 <tng_tracker_pids_list_fops
,
1115 if (IS_ERR(tracker_pids_list_file
)) {
1116 ret
= PTR_ERR(tracker_pids_list_file
);
1119 if (!atomic_long_add_unless(&session
->file
->f_count
, 1, LONG_MAX
)) {
1121 goto refcount_error
;
1123 ret
= lttng_tracker_pids_list_fops
.open(NULL
, tracker_pids_list_file
);
1126 m
= tracker_pids_list_file
->private_data
;
1127 m
->private = session
;
1128 fd_install(file_fd
, tracker_pids_list_file
);
1133 atomic_long_dec(&session
->file
->f_count
);
1135 fput(tracker_pids_list_file
);
1137 put_unused_fd(file_fd
);
1143 * Enabler management.
1146 int lttng_match_enabler_star_glob(const char *desc_name
,
1147 const char *pattern
)
1149 if (!strutils_star_glob_match(pattern
, LTTNG_SIZE_MAX
,
1150 desc_name
, LTTNG_SIZE_MAX
))
1156 int lttng_match_enabler_name(const char *desc_name
,
1159 if (strcmp(desc_name
, name
))
1165 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
1166 struct lttng_enabler
*enabler
)
1168 const char *desc_name
, *enabler_name
;
1170 enabler_name
= enabler
->event_param
.name
;
1171 switch (enabler
->event_param
.instrumentation
) {
1172 case LTTNG_KERNEL_TRACEPOINT
:
1173 desc_name
= desc
->name
;
1175 case LTTNG_KERNEL_SYSCALL
:
1176 desc_name
= desc
->name
;
1177 if (!strncmp(desc_name
, "compat_", strlen("compat_")))
1178 desc_name
+= strlen("compat_");
1179 if (!strncmp(desc_name
, "syscall_exit_",
1180 strlen("syscall_exit_"))) {
1181 desc_name
+= strlen("syscall_exit_");
1182 } else if (!strncmp(desc_name
, "syscall_entry_",
1183 strlen("syscall_entry_"))) {
1184 desc_name
+= strlen("syscall_entry_");
1194 switch (enabler
->type
) {
1195 case LTTNG_ENABLER_STAR_GLOB
:
1196 return lttng_match_enabler_star_glob(desc_name
, enabler_name
);
1197 case LTTNG_ENABLER_NAME
:
1198 return lttng_match_enabler_name(desc_name
, enabler_name
);
1205 int lttng_event_match_enabler(struct lttng_event
*event
,
1206 struct lttng_enabler
*enabler
)
1208 if (enabler
->event_param
.instrumentation
!= event
->instrumentation
)
1210 if (lttng_desc_match_enabler(event
->desc
, enabler
)
1211 && event
->chan
== enabler
->chan
)
1218 struct lttng_enabler_ref
*lttng_event_enabler_ref(struct lttng_event
*event
,
1219 struct lttng_enabler
*enabler
)
1221 struct lttng_enabler_ref
*enabler_ref
;
1223 list_for_each_entry(enabler_ref
,
1224 &event
->enablers_ref_head
, node
) {
1225 if (enabler_ref
->ref
== enabler
)
1232 void lttng_create_tracepoint_if_missing(struct lttng_enabler
*enabler
)
1234 struct lttng_session
*session
= enabler
->chan
->session
;
1235 struct lttng_probe_desc
*probe_desc
;
1236 const struct lttng_event_desc
*desc
;
1238 struct list_head
*probe_list
;
1240 probe_list
= lttng_get_probe_list_head();
1242 * For each probe event, if we find that a probe event matches
1243 * our enabler, create an associated lttng_event if not
1246 list_for_each_entry(probe_desc
, probe_list
, head
) {
1247 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1249 struct hlist_head
*head
;
1250 const char *event_name
;
1253 struct lttng_event
*event
;
1255 desc
= probe_desc
->event_desc
[i
];
1256 if (!lttng_desc_match_enabler(desc
, enabler
))
1258 event_name
= desc
->name
;
1259 name_len
= strlen(event_name
);
1262 * Check if already created.
1264 hash
= jhash(event_name
, name_len
, 0);
1265 head
= &session
->events_ht
.table
[hash
& (LTTNG_EVENT_HT_SIZE
- 1)];
1266 lttng_hlist_for_each_entry(event
, head
, hlist
) {
1267 if (event
->desc
== desc
1268 && event
->chan
== enabler
->chan
)
1275 * We need to create an event for this
1278 event
= _lttng_event_create(enabler
->chan
,
1280 LTTNG_KERNEL_TRACEPOINT
);
1282 printk(KERN_INFO
"Unable to create event %s\n",
1283 probe_desc
->event_desc
[i
]->name
);
1290 void lttng_create_syscall_if_missing(struct lttng_enabler
*enabler
)
1294 ret
= lttng_syscalls_register(enabler
->chan
, NULL
);
1299 * Create struct lttng_event if it is missing and present in the list of
1300 * tracepoint probes.
1301 * Should be called with sessions mutex held.
1304 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
1306 switch (enabler
->event_param
.instrumentation
) {
1307 case LTTNG_KERNEL_TRACEPOINT
:
1308 lttng_create_tracepoint_if_missing(enabler
);
1310 case LTTNG_KERNEL_SYSCALL
:
1311 lttng_create_syscall_if_missing(enabler
);
1320 * Create events associated with an enabler (if not already present),
1321 * and add backward reference from the event to the enabler.
1322 * Should be called with sessions mutex held.
1325 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
1327 struct lttng_session
*session
= enabler
->chan
->session
;
1328 struct lttng_event
*event
;
1330 /* First ensure that probe events are created for this enabler. */
1331 lttng_create_event_if_missing(enabler
);
1333 /* For each event matching enabler in session event list. */
1334 list_for_each_entry(event
, &session
->events
, list
) {
1335 struct lttng_enabler_ref
*enabler_ref
;
1337 if (!lttng_event_match_enabler(event
, enabler
))
1339 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
1342 * If no backward ref, create it.
1343 * Add backward ref from event to enabler.
1345 enabler_ref
= kzalloc(sizeof(*enabler_ref
), GFP_KERNEL
);
1348 enabler_ref
->ref
= enabler
;
1349 list_add(&enabler_ref
->node
,
1350 &event
->enablers_ref_head
);
1354 * Link filter bytecodes if not linked yet.
1356 lttng_enabler_event_link_bytecode(event
, enabler
);
1358 /* TODO: merge event context. */
1364 * Called at module load: connect the probe on all enablers matching
1366 * Called with sessions lock held.
1368 int lttng_fix_pending_events(void)
1370 struct lttng_session
*session
;
1372 list_for_each_entry(session
, &sessions
, list
)
1373 lttng_session_lazy_sync_enablers(session
);
1377 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
1378 struct lttng_kernel_event
*event_param
,
1379 struct lttng_channel
*chan
)
1381 struct lttng_enabler
*enabler
;
1383 enabler
= kzalloc(sizeof(*enabler
), GFP_KERNEL
);
1386 enabler
->type
= type
;
1387 INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
1388 memcpy(&enabler
->event_param
, event_param
,
1389 sizeof(enabler
->event_param
));
1390 enabler
->chan
= chan
;
1392 enabler
->enabled
= 0;
1393 enabler
->evtype
= LTTNG_TYPE_ENABLER
;
1394 mutex_lock(&sessions_mutex
);
1395 list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
1396 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1397 mutex_unlock(&sessions_mutex
);
1401 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
1403 mutex_lock(&sessions_mutex
);
1404 enabler
->enabled
= 1;
1405 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1406 mutex_unlock(&sessions_mutex
);
1410 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
1412 mutex_lock(&sessions_mutex
);
1413 enabler
->enabled
= 0;
1414 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1415 mutex_unlock(&sessions_mutex
);
1419 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
1420 struct lttng_kernel_filter_bytecode __user
*bytecode
)
1422 struct lttng_filter_bytecode_node
*bytecode_node
;
1423 uint32_t bytecode_len
;
1426 ret
= get_user(bytecode_len
, &bytecode
->len
);
1429 bytecode_node
= kzalloc(sizeof(*bytecode_node
) + bytecode_len
,
1433 ret
= copy_from_user(&bytecode_node
->bc
, bytecode
,
1434 sizeof(*bytecode
) + bytecode_len
);
1437 bytecode_node
->enabler
= enabler
;
1438 /* Enforce length based on allocated size */
1439 bytecode_node
->bc
.len
= bytecode_len
;
1440 list_add_tail(&bytecode_node
->node
, &enabler
->filter_bytecode_head
);
1441 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1445 kfree(bytecode_node
);
1449 int lttng_event_add_callsite(struct lttng_event
*event
,
1450 struct lttng_kernel_event_callsite __user
*callsite
)
1453 switch (event
->instrumentation
) {
1454 case LTTNG_KERNEL_UPROBE
:
1455 return lttng_uprobes_add_callsite(event
, callsite
);
1461 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1462 struct lttng_kernel_context
*context_param
)
1468 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1470 struct lttng_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1472 /* Destroy filter bytecode */
1473 list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1474 &enabler
->filter_bytecode_head
, node
) {
1478 /* Destroy contexts */
1479 lttng_destroy_context(enabler
->ctx
);
1481 list_del(&enabler
->node
);
1486 * lttng_session_sync_enablers should be called just before starting a
1488 * Should be called with sessions mutex held.
1491 void lttng_session_sync_enablers(struct lttng_session
*session
)
1493 struct lttng_enabler
*enabler
;
1494 struct lttng_event
*event
;
1496 list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1497 lttng_enabler_ref_events(enabler
);
1499 * For each event, if at least one of its enablers is enabled,
1500 * and its channel and session transient states are enabled, we
1501 * enable the event, else we disable it.
1503 list_for_each_entry(event
, &session
->events
, list
) {
1504 struct lttng_enabler_ref
*enabler_ref
;
1505 struct lttng_bytecode_runtime
*runtime
;
1506 int enabled
= 0, has_enablers_without_bytecode
= 0;
1508 switch (event
->instrumentation
) {
1509 case LTTNG_KERNEL_TRACEPOINT
:
1510 case LTTNG_KERNEL_SYSCALL
:
1512 list_for_each_entry(enabler_ref
,
1513 &event
->enablers_ref_head
, node
) {
1514 if (enabler_ref
->ref
->enabled
) {
1521 /* Not handled with lazy sync. */
1525 * Enabled state is based on union of enablers, with
1526 * intesection of session and channel transient enable
1529 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1531 WRITE_ONCE(event
->enabled
, enabled
);
1533 * Sync tracepoint registration with event enabled
1537 register_event(event
);
1539 _lttng_event_unregister(event
);
1542 /* Check if has enablers without bytecode enabled */
1543 list_for_each_entry(enabler_ref
,
1544 &event
->enablers_ref_head
, node
) {
1545 if (enabler_ref
->ref
->enabled
1546 && list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1547 has_enablers_without_bytecode
= 1;
1551 event
->has_enablers_without_bytecode
=
1552 has_enablers_without_bytecode
;
1554 /* Enable filters */
1555 list_for_each_entry(runtime
,
1556 &event
->bytecode_runtime_head
, node
)
1557 lttng_filter_sync_state(runtime
);
1562 * Apply enablers to session events, adding events to session if need
1563 * be. It is required after each modification applied to an active
1564 * session, and right before session "start".
1565 * "lazy" sync means we only sync if required.
1566 * Should be called with sessions mutex held.
1569 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1571 /* We can skip if session is not active */
1572 if (!session
->active
)
1574 lttng_session_sync_enablers(session
);
1578 * Serialize at most one packet worth of metadata into a metadata
1580 * We grab the metadata cache mutex to get exclusive access to our metadata
1581 * buffer and to the metadata cache. Exclusive access to the metadata buffer
1582 * allows us to do racy operations such as looking for remaining space left in
1583 * packet and write, since mutual exclusion protects us from concurrent writes.
1584 * Mutual exclusion on the metadata cache allow us to read the cache content
1585 * without racing against reallocation of the cache by updates.
1586 * Returns the number of bytes written in the channel, 0 if no data
1587 * was written and a negative value on error.
1589 int lttng_metadata_output_channel(struct lttng_metadata_stream
*stream
,
1590 struct channel
*chan
)
1592 struct lib_ring_buffer_ctx ctx
;
1594 size_t len
, reserve_len
;
1597 * Ensure we support mutiple get_next / put sequences followed by
1598 * put_next. The metadata cache lock protects reading the metadata
1599 * cache. It can indeed be read concurrently by "get_next_subbuf" and
1600 * "flush" operations on the buffer invoked by different processes.
1601 * Moreover, since the metadata cache memory can be reallocated, we
1602 * need to have exclusive access against updates even though we only
1605 mutex_lock(&stream
->metadata_cache
->lock
);
1606 WARN_ON(stream
->metadata_in
< stream
->metadata_out
);
1607 if (stream
->metadata_in
!= stream
->metadata_out
)
1610 /* Metadata regenerated, change the version. */
1611 if (stream
->metadata_cache
->version
!= stream
->version
)
1612 stream
->version
= stream
->metadata_cache
->version
;
1614 len
= stream
->metadata_cache
->metadata_written
-
1615 stream
->metadata_in
;
1618 reserve_len
= min_t(size_t,
1619 stream
->transport
->ops
.packet_avail_size(chan
),
1621 lib_ring_buffer_ctx_init(&ctx
, chan
, NULL
, reserve_len
,
1624 * If reservation failed, return an error to the caller.
1626 ret
= stream
->transport
->ops
.event_reserve(&ctx
, 0);
1628 printk(KERN_WARNING
"LTTng: Metadata event reservation failed\n");
1631 stream
->transport
->ops
.event_write(&ctx
,
1632 stream
->metadata_cache
->data
+ stream
->metadata_in
,
1634 stream
->transport
->ops
.event_commit(&ctx
);
1635 stream
->metadata_in
+= reserve_len
;
1639 mutex_unlock(&stream
->metadata_cache
->lock
);
1644 * Write the metadata to the metadata cache.
1645 * Must be called with sessions_mutex held.
1646 * The metadata cache lock protects us from concurrent read access from
1647 * thread outputting metadata content to ring buffer.
1649 int lttng_metadata_printf(struct lttng_session
*session
,
1650 const char *fmt
, ...)
1655 struct lttng_metadata_stream
*stream
;
1657 WARN_ON_ONCE(!READ_ONCE(session
->active
));
1660 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
1666 mutex_lock(&session
->metadata_cache
->lock
);
1667 if (session
->metadata_cache
->metadata_written
+ len
>
1668 session
->metadata_cache
->cache_alloc
) {
1669 char *tmp_cache_realloc
;
1670 unsigned int tmp_cache_alloc_size
;
1672 tmp_cache_alloc_size
= max_t(unsigned int,
1673 session
->metadata_cache
->cache_alloc
+ len
,
1674 session
->metadata_cache
->cache_alloc
<< 1);
1675 tmp_cache_realloc
= lttng_vzalloc(tmp_cache_alloc_size
);
1676 if (!tmp_cache_realloc
)
1678 if (session
->metadata_cache
->data
) {
1679 memcpy(tmp_cache_realloc
,
1680 session
->metadata_cache
->data
,
1681 session
->metadata_cache
->cache_alloc
);
1682 vfree(session
->metadata_cache
->data
);
1685 session
->metadata_cache
->cache_alloc
= tmp_cache_alloc_size
;
1686 session
->metadata_cache
->data
= tmp_cache_realloc
;
1688 memcpy(session
->metadata_cache
->data
+
1689 session
->metadata_cache
->metadata_written
,
1691 session
->metadata_cache
->metadata_written
+= len
;
1692 mutex_unlock(&session
->metadata_cache
->lock
);
1695 list_for_each_entry(stream
, &session
->metadata_cache
->metadata_stream
, list
)
1696 wake_up_interruptible(&stream
->read_wait
);
1701 mutex_unlock(&session
->metadata_cache
->lock
);
1707 int print_tabs(struct lttng_session
*session
, size_t nesting
)
1711 for (i
= 0; i
< nesting
; i
++) {
1714 ret
= lttng_metadata_printf(session
, " ");
1723 * Must be called with sessions_mutex held.
1726 int _lttng_struct_type_statedump(struct lttng_session
*session
,
1727 const struct lttng_type
*type
,
1731 uint32_t i
, nr_fields
;
1733 ret
= print_tabs(session
, nesting
);
1736 ret
= lttng_metadata_printf(session
,
1740 nr_fields
= type
->u
._struct
.nr_fields
;
1741 for (i
= 0; i
< nr_fields
; i
++) {
1742 const struct lttng_event_field
*iter_field
;
1744 iter_field
= &type
->u
._struct
.fields
[i
];
1745 ret
= _lttng_field_statedump(session
, iter_field
, nesting
+ 1);
1749 ret
= print_tabs(session
, nesting
);
1752 ret
= lttng_metadata_printf(session
,
1758 * Must be called with sessions_mutex held.
1761 int _lttng_struct_statedump(struct lttng_session
*session
,
1762 const struct lttng_event_field
*field
,
1767 ret
= _lttng_struct_type_statedump(session
,
1768 &field
->type
, nesting
);
1771 ret
= lttng_metadata_printf(session
,
1778 * Must be called with sessions_mutex held.
1781 int _lttng_variant_type_statedump(struct lttng_session
*session
,
1782 const struct lttng_type
*type
,
1786 uint32_t i
, nr_choices
;
1788 ret
= print_tabs(session
, nesting
);
1791 ret
= lttng_metadata_printf(session
,
1792 "variant <_%s> {\n",
1793 type
->u
.variant
.tag_name
);
1796 nr_choices
= type
->u
.variant
.nr_choices
;
1797 for (i
= 0; i
< nr_choices
; i
++) {
1798 const struct lttng_event_field
*iter_field
;
1800 iter_field
= &type
->u
.variant
.choices
[i
];
1801 ret
= _lttng_field_statedump(session
, iter_field
, nesting
+ 1);
1805 ret
= print_tabs(session
, nesting
);
1808 ret
= lttng_metadata_printf(session
,
1814 * Must be called with sessions_mutex held.
1817 int _lttng_variant_statedump(struct lttng_session
*session
,
1818 const struct lttng_event_field
*field
,
1823 ret
= _lttng_variant_type_statedump(session
,
1824 &field
->type
, nesting
);
1827 ret
= lttng_metadata_printf(session
,
1834 * Must be called with sessions_mutex held.
1837 int _lttng_array_compound_statedump(struct lttng_session
*session
,
1838 const struct lttng_event_field
*field
,
1842 const struct lttng_type
*elem_type
;
1844 /* Only array of structures and variants are currently supported. */
1845 elem_type
= field
->type
.u
.array_compound
.elem_type
;
1846 switch (elem_type
->atype
) {
1848 ret
= _lttng_struct_type_statedump(session
, elem_type
, nesting
);
1853 ret
= _lttng_variant_type_statedump(session
, elem_type
, nesting
);
1860 ret
= lttng_metadata_printf(session
,
1863 field
->type
.u
.array_compound
.length
);
1868 * Must be called with sessions_mutex held.
1871 int _lttng_sequence_compound_statedump(struct lttng_session
*session
,
1872 const struct lttng_event_field
*field
,
1876 const char *length_name
;
1877 const struct lttng_type
*elem_type
;
1879 length_name
= field
->type
.u
.sequence_compound
.length_name
;
1881 /* Only array of structures and variants are currently supported. */
1882 elem_type
= field
->type
.u
.sequence_compound
.elem_type
;
1883 switch (elem_type
->atype
) {
1885 ret
= _lttng_struct_type_statedump(session
, elem_type
, nesting
);
1890 ret
= _lttng_variant_type_statedump(session
, elem_type
, nesting
);
1897 ret
= lttng_metadata_printf(session
,
1905 * Must be called with sessions_mutex held.
1908 int _lttng_enum_statedump(struct lttng_session
*session
,
1909 const struct lttng_event_field
*field
,
1912 const struct lttng_enum_desc
*enum_desc
;
1913 const struct lttng_integer_type
*container_type
;
1915 unsigned int i
, nr_entries
;
1917 enum_desc
= field
->type
.u
.basic
.enumeration
.desc
;
1918 container_type
= &field
->type
.u
.basic
.enumeration
.container_type
;
1919 nr_entries
= enum_desc
->nr_entries
;
1921 ret
= print_tabs(session
, nesting
);
1924 ret
= lttng_metadata_printf(session
,
1925 "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n",
1926 container_type
->size
,
1927 container_type
->alignment
,
1928 container_type
->signedness
,
1929 (container_type
->encoding
== lttng_encode_none
)
1931 : (container_type
->encoding
== lttng_encode_UTF8
)
1934 container_type
->base
,
1935 #if __BYTE_ORDER == __BIG_ENDIAN
1936 container_type
->reverse_byte_order
? " byte_order = le;" : ""
1938 container_type
->reverse_byte_order
? " byte_order = be;" : ""
1943 /* Dump all entries */
1944 for (i
= 0; i
< nr_entries
; i
++) {
1945 const struct lttng_enum_entry
*entry
= &enum_desc
->entries
[i
];
1948 ret
= print_tabs(session
, nesting
+ 1);
1951 ret
= lttng_metadata_printf(session
,
1955 len
= strlen(entry
->string
);
1956 /* Escape the character '"' */
1957 for (j
= 0; j
< len
; j
++) {
1958 char c
= entry
->string
[j
];
1962 ret
= lttng_metadata_printf(session
,
1966 ret
= lttng_metadata_printf(session
,
1970 ret
= lttng_metadata_printf(session
,
1977 ret
= lttng_metadata_printf(session
, "\"");
1981 if (entry
->options
.is_auto
) {
1982 ret
= lttng_metadata_printf(session
, ",\n");
1986 ret
= lttng_metadata_printf(session
,
1990 if (entry
->start
.signedness
)
1991 ret
= lttng_metadata_printf(session
,
1992 "%lld", (long long) entry
->start
.value
);
1994 ret
= lttng_metadata_printf(session
,
1995 "%llu", entry
->start
.value
);
1998 if (entry
->start
.signedness
== entry
->end
.signedness
&&
2000 == entry
->end
.value
) {
2001 ret
= lttng_metadata_printf(session
,
2004 if (entry
->end
.signedness
) {
2005 ret
= lttng_metadata_printf(session
,
2007 (long long) entry
->end
.value
);
2009 ret
= lttng_metadata_printf(session
,
2018 ret
= print_tabs(session
, nesting
);
2021 ret
= lttng_metadata_printf(session
, "} _%s;\n",
2028 * Must be called with sessions_mutex held.
2031 int _lttng_field_statedump(struct lttng_session
*session
,
2032 const struct lttng_event_field
*field
,
2037 switch (field
->type
.atype
) {
2039 ret
= print_tabs(session
, nesting
);
2042 ret
= lttng_metadata_printf(session
,
2043 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
2044 field
->type
.u
.basic
.integer
.size
,
2045 field
->type
.u
.basic
.integer
.alignment
,
2046 field
->type
.u
.basic
.integer
.signedness
,
2047 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
2049 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2052 field
->type
.u
.basic
.integer
.base
,
2053 #if __BYTE_ORDER == __BIG_ENDIAN
2054 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2056 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2061 ret
= _lttng_enum_statedump(session
, field
, nesting
);
2064 case atype_array_bitfield
:
2066 const struct lttng_basic_type
*elem_type
;
2068 elem_type
= &field
->type
.u
.array
.elem_type
;
2069 if (field
->type
.u
.array
.elem_alignment
) {
2070 ret
= print_tabs(session
, nesting
);
2073 ret
= lttng_metadata_printf(session
,
2074 "struct { } align(%u) _%s_padding;\n",
2075 field
->type
.u
.array
.elem_alignment
* CHAR_BIT
,
2080 ret
= print_tabs(session
, nesting
);
2083 ret
= lttng_metadata_printf(session
,
2084 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
2085 elem_type
->u
.basic
.integer
.size
,
2086 elem_type
->u
.basic
.integer
.alignment
,
2087 elem_type
->u
.basic
.integer
.signedness
,
2088 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2090 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2093 elem_type
->u
.basic
.integer
.base
,
2094 #if __BYTE_ORDER == __BIG_ENDIAN
2095 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2097 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2099 field
->name
, field
->type
.u
.array
.length
);
2102 case atype_sequence
:
2103 case atype_sequence_bitfield
:
2105 const struct lttng_basic_type
*elem_type
;
2106 const struct lttng_basic_type
*length_type
;
2108 elem_type
= &field
->type
.u
.sequence
.elem_type
;
2109 length_type
= &field
->type
.u
.sequence
.length_type
;
2110 ret
= print_tabs(session
, nesting
);
2113 ret
= lttng_metadata_printf(session
,
2114 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
2115 length_type
->u
.basic
.integer
.size
,
2116 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
2117 length_type
->u
.basic
.integer
.signedness
,
2118 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2120 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2123 length_type
->u
.basic
.integer
.base
,
2124 #if __BYTE_ORDER == __BIG_ENDIAN
2125 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2127 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2133 if (field
->type
.u
.sequence
.elem_alignment
) {
2134 ret
= print_tabs(session
, nesting
);
2137 ret
= lttng_metadata_printf(session
,
2138 "struct { } align(%u) _%s_padding;\n",
2139 field
->type
.u
.sequence
.elem_alignment
* CHAR_BIT
,
2144 ret
= print_tabs(session
, nesting
);
2147 ret
= lttng_metadata_printf(session
,
2148 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
2149 elem_type
->u
.basic
.integer
.size
,
2150 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
2151 elem_type
->u
.basic
.integer
.signedness
,
2152 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2154 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2157 elem_type
->u
.basic
.integer
.base
,
2158 #if __BYTE_ORDER == __BIG_ENDIAN
2159 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2161 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2169 /* Default encoding is UTF8 */
2170 ret
= print_tabs(session
, nesting
);
2173 ret
= lttng_metadata_printf(session
,
2175 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
2176 " { encoding = ASCII; }" : "",
2180 ret
= _lttng_struct_statedump(session
, field
, nesting
);
2182 case atype_array_compound
:
2183 ret
= _lttng_array_compound_statedump(session
, field
, nesting
);
2185 case atype_sequence_compound
:
2186 ret
= _lttng_sequence_compound_statedump(session
, field
, nesting
);
2189 ret
= _lttng_variant_statedump(session
, field
, nesting
);
2200 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
2201 struct lttng_ctx
*ctx
)
2208 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
2209 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
2211 ret
= _lttng_field_statedump(session
, &field
->event_field
, 2);
2219 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
2220 struct lttng_event
*event
)
2222 const struct lttng_event_desc
*desc
= event
->desc
;
2226 for (i
= 0; i
< desc
->nr_fields
; i
++) {
2227 const struct lttng_event_field
*field
= &desc
->fields
[i
];
2229 ret
= _lttng_field_statedump(session
, field
, 2);
2237 * Must be called with sessions_mutex held.
2240 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
2241 struct lttng_channel
*chan
,
2242 struct lttng_event
*event
)
2246 if (event
->metadata_dumped
|| !READ_ONCE(session
->active
))
2248 if (chan
->channel_type
== METADATA_CHANNEL
)
2251 ret
= lttng_metadata_printf(session
,
2255 " stream_id = %u;\n",
2263 ret
= lttng_metadata_printf(session
,
2264 " context := struct {\n");
2268 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
2272 ret
= lttng_metadata_printf(session
,
2278 ret
= lttng_metadata_printf(session
,
2279 " fields := struct {\n"
2284 ret
= _lttng_fields_metadata_statedump(session
, event
);
2289 * LTTng space reservation can only reserve multiples of the
2292 ret
= lttng_metadata_printf(session
,
2298 event
->metadata_dumped
= 1;
2305 * Must be called with sessions_mutex held.
2308 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
2309 struct lttng_channel
*chan
)
2313 if (chan
->metadata_dumped
|| !READ_ONCE(session
->active
))
2316 if (chan
->channel_type
== METADATA_CHANNEL
)
2319 WARN_ON_ONCE(!chan
->header_type
);
2320 ret
= lttng_metadata_printf(session
,
2323 " event.header := %s;\n"
2324 " packet.context := struct packet_context;\n",
2326 chan
->header_type
== 1 ? "struct event_header_compact" :
2327 "struct event_header_large");
2332 ret
= lttng_metadata_printf(session
,
2333 " event.context := struct {\n");
2337 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
2341 ret
= lttng_metadata_printf(session
,
2347 ret
= lttng_metadata_printf(session
,
2350 chan
->metadata_dumped
= 1;
2356 * Must be called with sessions_mutex held.
2359 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
2361 return lttng_metadata_printf(session
,
2362 "struct packet_context {\n"
2363 " uint64_clock_monotonic_t timestamp_begin;\n"
2364 " uint64_clock_monotonic_t timestamp_end;\n"
2365 " uint64_t content_size;\n"
2366 " uint64_t packet_size;\n"
2367 " uint64_t packet_seq_num;\n"
2368 " unsigned long events_discarded;\n"
2369 " uint32_t cpu_id;\n"
2376 * id: range: 0 - 30.
2377 * id 31 is reserved to indicate an extended header.
2380 * id: range: 0 - 65534.
2381 * id 65535 is reserved to indicate an extended header.
2383 * Must be called with sessions_mutex held.
2386 int _lttng_event_header_declare(struct lttng_session
*session
)
2388 return lttng_metadata_printf(session
,
2389 "struct event_header_compact {\n"
2390 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
2393 " uint27_clock_monotonic_t timestamp;\n"
2397 " uint64_clock_monotonic_t timestamp;\n"
2402 "struct event_header_large {\n"
2403 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
2406 " uint32_clock_monotonic_t timestamp;\n"
2410 " uint64_clock_monotonic_t timestamp;\n"
2414 lttng_alignof(uint32_t) * CHAR_BIT
,
2415 lttng_alignof(uint16_t) * CHAR_BIT
2420 * Approximation of NTP time of day to clock monotonic correlation,
2421 * taken at start of trace.
2422 * Yes, this is only an approximation. Yes, we can (and will) do better
2423 * in future versions.
2424 * This function may return a negative offset. It may happen if the
2425 * system sets the REALTIME clock to 0 after boot.
2427 * Use 64bit timespec on kernels that have it, this makes 32bit arch
2431 int64_t measure_clock_offset(void)
2433 uint64_t monotonic_avg
, monotonic
[2], realtime
;
2434 uint64_t tcf
= trace_clock_freq();
2436 unsigned long flags
;
2437 #ifdef LTTNG_KERNEL_HAS_TIMESPEC64
2438 struct timespec64 rts
= { 0, 0 };
2440 struct timespec rts
= { 0, 0 };
2443 /* Disable interrupts to increase correlation precision. */
2444 local_irq_save(flags
);
2445 monotonic
[0] = trace_clock_read64();
2446 #ifdef LTTNG_KERNEL_HAS_TIMESPEC64
2447 ktime_get_real_ts64(&rts
);
2449 getnstimeofday(&rts
);
2451 monotonic
[1] = trace_clock_read64();
2452 local_irq_restore(flags
);
2454 monotonic_avg
= (monotonic
[0] + monotonic
[1]) >> 1;
2455 realtime
= (uint64_t) rts
.tv_sec
* tcf
;
2456 if (tcf
== NSEC_PER_SEC
) {
2457 realtime
+= rts
.tv_nsec
;
2459 uint64_t n
= rts
.tv_nsec
* tcf
;
2461 do_div(n
, NSEC_PER_SEC
);
2464 offset
= (int64_t) realtime
- monotonic_avg
;
2469 int print_escaped_ctf_string(struct lttng_session
*session
, const char *string
)
2477 while (cur
!= '\0') {
2480 ret
= lttng_metadata_printf(session
, "%s", "\\n");
2484 ret
= lttng_metadata_printf(session
, "%c", '\\');
2487 /* We still print the current char */
2490 ret
= lttng_metadata_printf(session
, "%c", cur
);
2504 int print_metadata_escaped_field(struct lttng_session
*session
, const char *field
,
2505 const char *field_value
)
2509 ret
= lttng_metadata_printf(session
, " %s = \"", field
);
2513 ret
= print_escaped_ctf_string(session
, field_value
);
2517 ret
= lttng_metadata_printf(session
, "\";\n");
2524 * Output metadata into this session's metadata buffers.
2525 * Must be called with sessions_mutex held.
2528 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
2530 unsigned char *uuid_c
= session
->uuid
.b
;
2531 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
2532 struct lttng_channel
*chan
;
2533 struct lttng_event
*event
;
2536 if (!READ_ONCE(session
->active
))
2538 if (session
->metadata_dumped
)
2541 snprintf(uuid_s
, sizeof(uuid_s
),
2542 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2543 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
2544 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
2545 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
2546 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
2548 ret
= lttng_metadata_printf(session
,
2549 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
2550 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
2551 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
2552 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
2553 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
2554 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
2555 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
2561 " byte_order = %s;\n"
2562 " packet.header := struct {\n"
2563 " uint32_t magic;\n"
2564 " uint8_t uuid[16];\n"
2565 " uint32_t stream_id;\n"
2566 " uint64_t stream_instance_id;\n"
2569 lttng_alignof(uint8_t) * CHAR_BIT
,
2570 lttng_alignof(uint16_t) * CHAR_BIT
,
2571 lttng_alignof(uint32_t) * CHAR_BIT
,
2572 lttng_alignof(uint64_t) * CHAR_BIT
,
2573 sizeof(unsigned long) * CHAR_BIT
,
2574 lttng_alignof(unsigned long) * CHAR_BIT
,
2578 #if __BYTE_ORDER == __BIG_ENDIAN
2587 ret
= lttng_metadata_printf(session
,
2589 " hostname = \"%s\";\n"
2590 " domain = \"kernel\";\n"
2591 " sysname = \"%s\";\n"
2592 " kernel_release = \"%s\";\n"
2593 " kernel_version = \"%s\";\n"
2594 " tracer_name = \"lttng-modules\";\n"
2595 " tracer_major = %d;\n"
2596 " tracer_minor = %d;\n"
2597 " tracer_patchlevel = %d;\n"
2598 " trace_buffering_scheme = \"global\";\n",
2599 current
->nsproxy
->uts_ns
->name
.nodename
,
2603 LTTNG_MODULES_MAJOR_VERSION
,
2604 LTTNG_MODULES_MINOR_VERSION
,
2605 LTTNG_MODULES_PATCHLEVEL_VERSION
2610 ret
= print_metadata_escaped_field(session
, "trace_name", session
->name
);
2613 ret
= print_metadata_escaped_field(session
, "trace_creation_datetime",
2614 session
->creation_time
);
2619 ret
= lttng_metadata_printf(session
, "};\n\n");
2623 ret
= lttng_metadata_printf(session
,
2625 " name = \"%s\";\n",
2631 if (!trace_clock_uuid(clock_uuid_s
)) {
2632 ret
= lttng_metadata_printf(session
,
2633 " uuid = \"%s\";\n",
2640 ret
= lttng_metadata_printf(session
,
2641 " description = \"%s\";\n"
2642 " freq = %llu; /* Frequency, in Hz */\n"
2643 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
2646 trace_clock_description(),
2647 (unsigned long long) trace_clock_freq(),
2648 (long long) measure_clock_offset()
2653 ret
= lttng_metadata_printf(session
,
2654 "typealias integer {\n"
2655 " size = 27; align = 1; signed = false;\n"
2656 " map = clock.%s.value;\n"
2657 "} := uint27_clock_monotonic_t;\n"
2659 "typealias integer {\n"
2660 " size = 32; align = %u; signed = false;\n"
2661 " map = clock.%s.value;\n"
2662 "} := uint32_clock_monotonic_t;\n"
2664 "typealias integer {\n"
2665 " size = 64; align = %u; signed = false;\n"
2666 " map = clock.%s.value;\n"
2667 "} := uint64_clock_monotonic_t;\n\n",
2669 lttng_alignof(uint32_t) * CHAR_BIT
,
2671 lttng_alignof(uint64_t) * CHAR_BIT
,
2677 ret
= _lttng_stream_packet_context_declare(session
);
2681 ret
= _lttng_event_header_declare(session
);
2686 list_for_each_entry(chan
, &session
->chan
, list
) {
2687 ret
= _lttng_channel_metadata_statedump(session
, chan
);
2692 list_for_each_entry(event
, &session
->events
, list
) {
2693 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
2697 session
->metadata_dumped
= 1;
2703 * lttng_transport_register - LTT transport registration
2704 * @transport: transport structure
2706 * Registers a transport which can be used as output to extract the data out of
2707 * LTTng. The module calling this registration function must ensure that no
2708 * trap-inducing code will be executed by the transport functions. E.g.
2709 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
2710 * is made visible to the transport function. This registration acts as a
2711 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
2712 * after its registration must it synchronize the TLBs.
2714 void lttng_transport_register(struct lttng_transport
*transport
)
2717 * Make sure no page fault can be triggered by the module about to be
2718 * registered. We deal with this here so we don't have to call
2719 * vmalloc_sync_all() in each module's init.
2721 wrapper_vmalloc_sync_all();
2723 mutex_lock(&sessions_mutex
);
2724 list_add_tail(&transport
->node
, <tng_transport_list
);
2725 mutex_unlock(&sessions_mutex
);
2727 EXPORT_SYMBOL_GPL(lttng_transport_register
);
2730 * lttng_transport_unregister - LTT transport unregistration
2731 * @transport: transport structure
2733 void lttng_transport_unregister(struct lttng_transport
*transport
)
2735 mutex_lock(&sessions_mutex
);
2736 list_del(&transport
->node
);
2737 mutex_unlock(&sessions_mutex
);
2739 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
2741 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
2743 enum cpuhp_state lttng_hp_prepare
;
2744 enum cpuhp_state lttng_hp_online
;
2746 static int lttng_hotplug_prepare(unsigned int cpu
, struct hlist_node
*node
)
2748 struct lttng_cpuhp_node
*lttng_node
;
2750 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2751 switch (lttng_node
->component
) {
2752 case LTTNG_RING_BUFFER_FRONTEND
:
2754 case LTTNG_RING_BUFFER_BACKEND
:
2755 return lttng_cpuhp_rb_backend_prepare(cpu
, lttng_node
);
2756 case LTTNG_RING_BUFFER_ITER
:
2758 case LTTNG_CONTEXT_PERF_COUNTERS
:
2765 static int lttng_hotplug_dead(unsigned int cpu
, struct hlist_node
*node
)
2767 struct lttng_cpuhp_node
*lttng_node
;
2769 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2770 switch (lttng_node
->component
) {
2771 case LTTNG_RING_BUFFER_FRONTEND
:
2772 return lttng_cpuhp_rb_frontend_dead(cpu
, lttng_node
);
2773 case LTTNG_RING_BUFFER_BACKEND
:
2775 case LTTNG_RING_BUFFER_ITER
:
2777 case LTTNG_CONTEXT_PERF_COUNTERS
:
2778 return lttng_cpuhp_perf_counter_dead(cpu
, lttng_node
);
2784 static int lttng_hotplug_online(unsigned int cpu
, struct hlist_node
*node
)
2786 struct lttng_cpuhp_node
*lttng_node
;
2788 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2789 switch (lttng_node
->component
) {
2790 case LTTNG_RING_BUFFER_FRONTEND
:
2791 return lttng_cpuhp_rb_frontend_online(cpu
, lttng_node
);
2792 case LTTNG_RING_BUFFER_BACKEND
:
2794 case LTTNG_RING_BUFFER_ITER
:
2795 return lttng_cpuhp_rb_iter_online(cpu
, lttng_node
);
2796 case LTTNG_CONTEXT_PERF_COUNTERS
:
2797 return lttng_cpuhp_perf_counter_online(cpu
, lttng_node
);
2803 static int lttng_hotplug_offline(unsigned int cpu
, struct hlist_node
*node
)
2805 struct lttng_cpuhp_node
*lttng_node
;
2807 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2808 switch (lttng_node
->component
) {
2809 case LTTNG_RING_BUFFER_FRONTEND
:
2810 return lttng_cpuhp_rb_frontend_offline(cpu
, lttng_node
);
2811 case LTTNG_RING_BUFFER_BACKEND
:
2813 case LTTNG_RING_BUFFER_ITER
:
2815 case LTTNG_CONTEXT_PERF_COUNTERS
:
2822 static int __init
lttng_init_cpu_hotplug(void)
2826 ret
= cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN
, "lttng:prepare",
2827 lttng_hotplug_prepare
,
2828 lttng_hotplug_dead
);
2832 lttng_hp_prepare
= ret
;
2833 lttng_rb_set_hp_prepare(ret
);
2835 ret
= cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN
, "lttng:online",
2836 lttng_hotplug_online
,
2837 lttng_hotplug_offline
);
2839 cpuhp_remove_multi_state(lttng_hp_prepare
);
2840 lttng_hp_prepare
= 0;
2843 lttng_hp_online
= ret
;
2844 lttng_rb_set_hp_online(ret
);
2849 static void __exit
lttng_exit_cpu_hotplug(void)
2851 lttng_rb_set_hp_online(0);
2852 cpuhp_remove_multi_state(lttng_hp_online
);
2853 lttng_rb_set_hp_prepare(0);
2854 cpuhp_remove_multi_state(lttng_hp_prepare
);
2857 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2858 static int lttng_init_cpu_hotplug(void)
2862 static void lttng_exit_cpu_hotplug(void)
2865 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2868 static int __init
lttng_events_init(void)
2872 ret
= wrapper_lttng_fixup_sig(THIS_MODULE
);
2875 ret
= wrapper_get_pfnblock_flags_mask_init();
2878 ret
= wrapper_get_pageblock_flags_mask_init();
2881 ret
= lttng_probes_init();
2884 ret
= lttng_context_init();
2887 ret
= lttng_tracepoint_init();
2890 event_cache
= KMEM_CACHE(lttng_event
, 0);
2895 ret
= lttng_abi_init();
2898 ret
= lttng_logger_init();
2901 ret
= lttng_init_cpu_hotplug();
2904 printk(KERN_NOTICE
"LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n",
2905 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2906 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2907 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2908 LTTNG_MODULES_EXTRAVERSION
,
2910 #ifdef LTTNG_EXTRA_VERSION_GIT
2911 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2915 #ifdef LTTNG_EXTRA_VERSION_NAME
2916 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2923 lttng_logger_exit();
2927 kmem_cache_destroy(event_cache
);
2929 lttng_tracepoint_exit();
2931 lttng_context_exit();
2932 printk(KERN_NOTICE
"LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n",
2933 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2934 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2935 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2936 LTTNG_MODULES_EXTRAVERSION
,
2938 #ifdef LTTNG_EXTRA_VERSION_GIT
2939 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2943 #ifdef LTTNG_EXTRA_VERSION_NAME
2944 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2951 module_init(lttng_events_init
);
2953 static void __exit
lttng_events_exit(void)
2955 struct lttng_session
*session
, *tmpsession
;
2957 lttng_exit_cpu_hotplug();
2958 lttng_logger_exit();
2960 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
2961 lttng_session_destroy(session
);
2962 kmem_cache_destroy(event_cache
);
2963 lttng_tracepoint_exit();
2964 lttng_context_exit();
2965 printk(KERN_NOTICE
"LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n",
2966 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2967 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2968 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2969 LTTNG_MODULES_EXTRAVERSION
,
2971 #ifdef LTTNG_EXTRA_VERSION_GIT
2972 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2976 #ifdef LTTNG_EXTRA_VERSION_NAME
2977 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2983 module_exit(lttng_events_exit
);
2985 #include "extra_version/patches.i"
2986 #ifdef LTTNG_EXTRA_VERSION_GIT
2987 MODULE_INFO(extra_version_git
, LTTNG_EXTRA_VERSION_GIT
);
2989 #ifdef LTTNG_EXTRA_VERSION_NAME
2990 MODULE_INFO(extra_version_name
, LTTNG_EXTRA_VERSION_NAME
);
2992 MODULE_LICENSE("GPL and additional rights");
2993 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
2994 MODULE_DESCRIPTION("LTTng tracer");
2995 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
2996 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
2997 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
2998 LTTNG_MODULES_EXTRAVERSION
);