4 * Holds LTTng per-session event registry.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * This page_alloc.h wrapper needs to be included before gfpflags.h because it
25 * overrides a function with a define.
27 #include "wrapper/page_alloc.h"
29 #include <linux/module.h>
30 #include <linux/mutex.h>
31 #include <linux/sched.h>
32 #include <linux/slab.h>
33 #include <linux/jiffies.h>
34 #include <linux/utsname.h>
35 #include <linux/err.h>
36 #include <linux/seq_file.h>
37 #include <linux/file.h>
38 #include <linux/anon_inodes.h>
39 #include <wrapper/file.h>
40 #include <linux/jhash.h>
41 #include <linux/uaccess.h>
42 #include <linux/vmalloc.h>
44 #include <wrapper/uuid.h>
45 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
46 #include <wrapper/random.h>
47 #include <wrapper/tracepoint.h>
48 #include <wrapper/list.h>
49 #include <lttng-kernel-version.h>
50 #include <lttng-events.h>
51 #include <lttng-tracer.h>
52 #include <lttng-abi-old.h>
53 #include <lttng-endian.h>
54 #include <wrapper/vzalloc.h>
55 #include <wrapper/ringbuffer/backend.h>
56 #include <wrapper/ringbuffer/frontend.h>
58 #define METADATA_CACHE_DEFAULT_SIZE 4096
60 static LIST_HEAD(sessions
);
61 static LIST_HEAD(lttng_transport_list
);
63 * Protect the sessions and metadata caches.
65 static DEFINE_MUTEX(sessions_mutex
);
66 static struct kmem_cache
*event_cache
;
68 static void lttng_session_lazy_sync_enablers(struct lttng_session
*session
);
69 static void lttng_session_sync_enablers(struct lttng_session
*session
);
70 static void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
72 static void _lttng_event_destroy(struct lttng_event
*event
);
73 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
74 static int _lttng_event_unregister(struct lttng_event
*event
);
76 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
77 struct lttng_channel
*chan
,
78 struct lttng_event
*event
);
80 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
82 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream
*stream
);
84 int _lttng_field_statedump(struct lttng_session
*session
,
85 const struct lttng_event_field
*field
,
88 void synchronize_trace(void)
91 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
92 #ifdef CONFIG_PREEMPT_RT_FULL
95 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
96 #ifdef CONFIG_PREEMPT_RT
99 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
102 void lttng_lock_sessions(void)
104 mutex_lock(&sessions_mutex
);
107 void lttng_unlock_sessions(void)
109 mutex_unlock(&sessions_mutex
);
113 * Called with sessions lock held.
115 int lttng_session_active(void)
117 struct lttng_session
*iter
;
119 list_for_each_entry(iter
, &sessions
, list
) {
126 struct lttng_session
*lttng_session_create(void)
128 struct lttng_session
*session
;
129 struct lttng_metadata_cache
*metadata_cache
;
132 mutex_lock(&sessions_mutex
);
133 session
= lttng_kvzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
136 INIT_LIST_HEAD(&session
->chan
);
137 INIT_LIST_HEAD(&session
->events
);
138 uuid_le_gen(&session
->uuid
);
140 metadata_cache
= kzalloc(sizeof(struct lttng_metadata_cache
),
143 goto err_free_session
;
144 metadata_cache
->data
= lttng_vzalloc(METADATA_CACHE_DEFAULT_SIZE
);
145 if (!metadata_cache
->data
)
147 metadata_cache
->cache_alloc
= METADATA_CACHE_DEFAULT_SIZE
;
148 kref_init(&metadata_cache
->refcount
);
149 mutex_init(&metadata_cache
->lock
);
150 session
->metadata_cache
= metadata_cache
;
151 INIT_LIST_HEAD(&metadata_cache
->metadata_stream
);
152 memcpy(&metadata_cache
->uuid
, &session
->uuid
,
153 sizeof(metadata_cache
->uuid
));
154 INIT_LIST_HEAD(&session
->enablers_head
);
155 for (i
= 0; i
< LTTNG_EVENT_HT_SIZE
; i
++)
156 INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
157 list_add(&session
->list
, &sessions
);
158 session
->pid_tracker
.session
= session
;
159 session
->pid_tracker
.tracker_type
= TRACKER_PID
;
160 session
->vpid_tracker
.session
= session
;
161 session
->vpid_tracker
.tracker_type
= TRACKER_VPID
;
162 session
->uid_tracker
.session
= session
;
163 session
->uid_tracker
.tracker_type
= TRACKER_UID
;
164 session
->vuid_tracker
.session
= session
;
165 session
->vuid_tracker
.tracker_type
= TRACKER_VUID
;
166 session
->gid_tracker
.session
= session
;
167 session
->gid_tracker
.tracker_type
= TRACKER_GID
;
168 session
->vgid_tracker
.session
= session
;
169 session
->vgid_tracker
.tracker_type
= TRACKER_VGID
;
170 mutex_unlock(&sessions_mutex
);
174 kfree(metadata_cache
);
176 lttng_kvfree(session
);
178 mutex_unlock(&sessions_mutex
);
182 void metadata_cache_destroy(struct kref
*kref
)
184 struct lttng_metadata_cache
*cache
=
185 container_of(kref
, struct lttng_metadata_cache
, refcount
);
190 void lttng_session_destroy(struct lttng_session
*session
)
192 struct lttng_channel
*chan
, *tmpchan
;
193 struct lttng_event
*event
, *tmpevent
;
194 struct lttng_metadata_stream
*metadata_stream
;
195 struct lttng_enabler
*enabler
, *tmpenabler
;
198 mutex_lock(&sessions_mutex
);
199 WRITE_ONCE(session
->active
, 0);
200 list_for_each_entry(chan
, &session
->chan
, list
) {
201 ret
= lttng_syscalls_unregister(chan
);
204 list_for_each_entry(event
, &session
->events
, list
) {
205 ret
= _lttng_event_unregister(event
);
208 synchronize_trace(); /* Wait for in-flight events to complete */
209 list_for_each_entry_safe(enabler
, tmpenabler
,
210 &session
->enablers_head
, node
)
211 lttng_enabler_destroy(enabler
);
212 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
213 _lttng_event_destroy(event
);
214 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
) {
215 BUG_ON(chan
->channel_type
== METADATA_CHANNEL
);
216 _lttng_channel_destroy(chan
);
218 list_for_each_entry(metadata_stream
, &session
->metadata_cache
->metadata_stream
, list
)
219 _lttng_metadata_channel_hangup(metadata_stream
);
220 lttng_id_tracker_destroy(&session
->pid_tracker
, false);
221 lttng_id_tracker_destroy(&session
->vpid_tracker
, false);
222 lttng_id_tracker_destroy(&session
->uid_tracker
, false);
223 lttng_id_tracker_destroy(&session
->vuid_tracker
, false);
224 lttng_id_tracker_destroy(&session
->gid_tracker
, false);
225 lttng_id_tracker_destroy(&session
->vgid_tracker
, false);
226 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
227 list_del(&session
->list
);
228 mutex_unlock(&sessions_mutex
);
229 lttng_kvfree(session
);
232 int lttng_session_statedump(struct lttng_session
*session
)
236 mutex_lock(&sessions_mutex
);
237 ret
= lttng_statedump_start(session
);
238 mutex_unlock(&sessions_mutex
);
242 int lttng_session_enable(struct lttng_session
*session
)
245 struct lttng_channel
*chan
;
247 mutex_lock(&sessions_mutex
);
248 if (session
->active
) {
253 /* Set transient enabler state to "enabled" */
257 * Snapshot the number of events per channel to know the type of header
260 list_for_each_entry(chan
, &session
->chan
, list
) {
261 if (chan
->header_type
)
262 continue; /* don't change it if session stop/restart */
263 if (chan
->free_event_id
< 31)
264 chan
->header_type
= 1; /* compact */
266 chan
->header_type
= 2; /* large */
269 /* We need to sync enablers with session before activation. */
270 lttng_session_sync_enablers(session
);
272 /* Clear each stream's quiescent state. */
273 list_for_each_entry(chan
, &session
->chan
, list
) {
274 if (chan
->channel_type
!= METADATA_CHANNEL
)
275 lib_ring_buffer_clear_quiescent_channel(chan
->chan
);
278 WRITE_ONCE(session
->active
, 1);
279 WRITE_ONCE(session
->been_active
, 1);
280 ret
= _lttng_session_metadata_statedump(session
);
282 WRITE_ONCE(session
->active
, 0);
285 ret
= lttng_statedump_start(session
);
287 WRITE_ONCE(session
->active
, 0);
289 mutex_unlock(&sessions_mutex
);
293 int lttng_session_disable(struct lttng_session
*session
)
296 struct lttng_channel
*chan
;
298 mutex_lock(&sessions_mutex
);
299 if (!session
->active
) {
303 WRITE_ONCE(session
->active
, 0);
305 /* Set transient enabler state to "disabled" */
307 lttng_session_sync_enablers(session
);
309 /* Set each stream's quiescent state. */
310 list_for_each_entry(chan
, &session
->chan
, list
) {
311 if (chan
->channel_type
!= METADATA_CHANNEL
)
312 lib_ring_buffer_set_quiescent_channel(chan
->chan
);
315 mutex_unlock(&sessions_mutex
);
319 int lttng_session_metadata_regenerate(struct lttng_session
*session
)
322 struct lttng_channel
*chan
;
323 struct lttng_event
*event
;
324 struct lttng_metadata_cache
*cache
= session
->metadata_cache
;
325 struct lttng_metadata_stream
*stream
;
327 mutex_lock(&sessions_mutex
);
328 if (!session
->active
) {
333 mutex_lock(&cache
->lock
);
334 memset(cache
->data
, 0, cache
->cache_alloc
);
335 cache
->metadata_written
= 0;
337 list_for_each_entry(stream
, &session
->metadata_cache
->metadata_stream
, list
) {
338 stream
->metadata_out
= 0;
339 stream
->metadata_in
= 0;
341 mutex_unlock(&cache
->lock
);
343 session
->metadata_dumped
= 0;
344 list_for_each_entry(chan
, &session
->chan
, list
) {
345 chan
->metadata_dumped
= 0;
348 list_for_each_entry(event
, &session
->events
, list
) {
349 event
->metadata_dumped
= 0;
352 ret
= _lttng_session_metadata_statedump(session
);
355 mutex_unlock(&sessions_mutex
);
361 int lttng_channel_enable(struct lttng_channel
*channel
)
365 mutex_lock(&sessions_mutex
);
366 if (channel
->channel_type
== METADATA_CHANNEL
) {
370 if (channel
->enabled
) {
374 /* Set transient enabler state to "enabled" */
376 lttng_session_sync_enablers(channel
->session
);
377 /* Set atomically the state to "enabled" */
378 WRITE_ONCE(channel
->enabled
, 1);
380 mutex_unlock(&sessions_mutex
);
384 int lttng_channel_disable(struct lttng_channel
*channel
)
388 mutex_lock(&sessions_mutex
);
389 if (channel
->channel_type
== METADATA_CHANNEL
) {
393 if (!channel
->enabled
) {
397 /* Set atomically the state to "disabled" */
398 WRITE_ONCE(channel
->enabled
, 0);
399 /* Set transient enabler state to "enabled" */
401 lttng_session_sync_enablers(channel
->session
);
403 mutex_unlock(&sessions_mutex
);
407 int lttng_event_enable(struct lttng_event
*event
)
411 mutex_lock(&sessions_mutex
);
412 if (event
->chan
->channel_type
== METADATA_CHANNEL
) {
416 if (event
->enabled
) {
420 switch (event
->instrumentation
) {
421 case LTTNG_KERNEL_TRACEPOINT
:
422 case LTTNG_KERNEL_SYSCALL
:
425 case LTTNG_KERNEL_KPROBE
:
426 case LTTNG_KERNEL_FUNCTION
:
427 case LTTNG_KERNEL_NOOP
:
428 WRITE_ONCE(event
->enabled
, 1);
430 case LTTNG_KERNEL_KRETPROBE
:
431 ret
= lttng_kretprobes_event_enable_state(event
, 1);
438 mutex_unlock(&sessions_mutex
);
442 int lttng_event_disable(struct lttng_event
*event
)
446 mutex_lock(&sessions_mutex
);
447 if (event
->chan
->channel_type
== METADATA_CHANNEL
) {
451 if (!event
->enabled
) {
455 switch (event
->instrumentation
) {
456 case LTTNG_KERNEL_TRACEPOINT
:
457 case LTTNG_KERNEL_SYSCALL
:
460 case LTTNG_KERNEL_KPROBE
:
461 case LTTNG_KERNEL_FUNCTION
:
462 case LTTNG_KERNEL_NOOP
:
463 WRITE_ONCE(event
->enabled
, 0);
465 case LTTNG_KERNEL_KRETPROBE
:
466 ret
= lttng_kretprobes_event_enable_state(event
, 0);
473 mutex_unlock(&sessions_mutex
);
477 static struct lttng_transport
*lttng_transport_find(const char *name
)
479 struct lttng_transport
*transport
;
481 list_for_each_entry(transport
, <tng_transport_list
, node
) {
482 if (!strcmp(transport
->name
, name
))
488 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
489 const char *transport_name
,
491 size_t subbuf_size
, size_t num_subbuf
,
492 unsigned int switch_timer_interval
,
493 unsigned int read_timer_interval
,
494 enum channel_type channel_type
)
496 struct lttng_channel
*chan
;
497 struct lttng_transport
*transport
= NULL
;
499 mutex_lock(&sessions_mutex
);
500 if (session
->been_active
&& channel_type
!= METADATA_CHANNEL
)
501 goto active
; /* Refuse to add channel to active session */
502 transport
= lttng_transport_find(transport_name
);
504 printk(KERN_WARNING
"LTTng transport %s not found\n",
508 if (!try_module_get(transport
->owner
)) {
509 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
512 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
515 chan
->session
= session
;
516 chan
->id
= session
->free_chan_id
++;
517 chan
->ops
= &transport
->ops
;
519 * Note: the channel creation op already writes into the packet
520 * headers. Therefore the "chan" information used as input
521 * should be already accessible.
523 chan
->chan
= transport
->ops
.channel_create(transport_name
,
524 chan
, buf_addr
, subbuf_size
, num_subbuf
,
525 switch_timer_interval
, read_timer_interval
);
530 chan
->transport
= transport
;
531 chan
->channel_type
= channel_type
;
532 list_add(&chan
->list
, &session
->chan
);
533 mutex_unlock(&sessions_mutex
);
540 module_put(transport
->owner
);
543 mutex_unlock(&sessions_mutex
);
548 * Only used internally at session destruction for per-cpu channels, and
549 * when metadata channel is released.
550 * Needs to be called with sessions mutex held.
553 void _lttng_channel_destroy(struct lttng_channel
*chan
)
555 chan
->ops
->channel_destroy(chan
->chan
);
556 module_put(chan
->transport
->owner
);
557 list_del(&chan
->list
);
558 lttng_destroy_context(chan
->ctx
);
562 void lttng_metadata_channel_destroy(struct lttng_channel
*chan
)
564 BUG_ON(chan
->channel_type
!= METADATA_CHANNEL
);
566 /* Protect the metadata cache with the sessions_mutex. */
567 mutex_lock(&sessions_mutex
);
568 _lttng_channel_destroy(chan
);
569 mutex_unlock(&sessions_mutex
);
571 EXPORT_SYMBOL_GPL(lttng_metadata_channel_destroy
);
574 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream
*stream
)
576 stream
->finalized
= 1;
577 wake_up_interruptible(&stream
->read_wait
);
581 * Supports event creation while tracing session is active.
582 * Needs to be called with sessions mutex held.
584 struct lttng_event
*_lttng_event_create(struct lttng_channel
*chan
,
585 struct lttng_kernel_event
*event_param
,
587 const struct lttng_event_desc
*event_desc
,
588 enum lttng_kernel_instrumentation itype
)
590 struct lttng_session
*session
= chan
->session
;
591 struct lttng_event
*event
;
592 const char *event_name
;
593 struct hlist_head
*head
;
598 if (chan
->free_event_id
== -1U) {
604 case LTTNG_KERNEL_TRACEPOINT
:
605 event_name
= event_desc
->name
;
607 case LTTNG_KERNEL_KPROBE
:
608 case LTTNG_KERNEL_KRETPROBE
:
609 case LTTNG_KERNEL_FUNCTION
:
610 case LTTNG_KERNEL_NOOP
:
611 case LTTNG_KERNEL_SYSCALL
:
612 event_name
= event_param
->name
;
619 name_len
= strlen(event_name
);
620 hash
= jhash(event_name
, name_len
, 0);
621 head
= &session
->events_ht
.table
[hash
& (LTTNG_EVENT_HT_SIZE
- 1)];
622 lttng_hlist_for_each_entry(event
, head
, hlist
) {
623 WARN_ON_ONCE(!event
->desc
);
624 if (!strncmp(event
->desc
->name
, event_name
,
625 LTTNG_KERNEL_SYM_NAME_LEN
- 1)
626 && chan
== event
->chan
) {
632 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
638 event
->filter
= filter
;
639 event
->id
= chan
->free_event_id
++;
640 event
->instrumentation
= itype
;
641 event
->evtype
= LTTNG_TYPE_EVENT
;
642 INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
643 INIT_LIST_HEAD(&event
->enablers_ref_head
);
646 case LTTNG_KERNEL_TRACEPOINT
:
647 /* Event will be enabled by enabler sync. */
649 event
->registered
= 0;
650 event
->desc
= lttng_event_get(event_name
);
655 /* Populate lttng_event structure before event registration. */
658 case LTTNG_KERNEL_KPROBE
:
660 * Needs to be explicitly enabled after creation, since
661 * we may want to apply filters.
664 event
->registered
= 1;
666 * Populate lttng_event structure before event
670 ret
= lttng_kprobes_register(event_name
,
671 event_param
->u
.kprobe
.symbol_name
,
672 event_param
->u
.kprobe
.offset
,
673 event_param
->u
.kprobe
.addr
,
679 ret
= try_module_get(event
->desc
->owner
);
682 case LTTNG_KERNEL_KRETPROBE
:
684 struct lttng_event
*event_return
;
686 /* kretprobe defines 2 events */
688 * Needs to be explicitly enabled after creation, since
689 * we may want to apply filters.
692 event
->registered
= 1;
694 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
699 event_return
->chan
= chan
;
700 event_return
->filter
= filter
;
701 event_return
->id
= chan
->free_event_id
++;
702 event_return
->enabled
= 0;
703 event_return
->registered
= 1;
704 event_return
->instrumentation
= itype
;
706 * Populate lttng_event structure before kretprobe registration.
709 ret
= lttng_kretprobes_register(event_name
,
710 event_param
->u
.kretprobe
.symbol_name
,
711 event_param
->u
.kretprobe
.offset
,
712 event_param
->u
.kretprobe
.addr
,
713 event
, event_return
);
715 kmem_cache_free(event_cache
, event_return
);
719 /* Take 2 refs on the module: one per event. */
720 ret
= try_module_get(event
->desc
->owner
);
722 ret
= try_module_get(event
->desc
->owner
);
724 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
726 WARN_ON_ONCE(ret
> 0);
728 kmem_cache_free(event_cache
, event_return
);
729 module_put(event
->desc
->owner
);
730 module_put(event
->desc
->owner
);
731 goto statedump_error
;
733 list_add(&event_return
->list
, &chan
->session
->events
);
736 case LTTNG_KERNEL_FUNCTION
:
738 * Needs to be explicitly enabled after creation, since
739 * we may want to apply filters.
742 event
->registered
= 1;
744 * Populate lttng_event structure before event
748 ret
= lttng_ftrace_register(event_name
,
749 event_param
->u
.ftrace
.symbol_name
,
754 ret
= try_module_get(event
->desc
->owner
);
757 case LTTNG_KERNEL_NOOP
:
758 case LTTNG_KERNEL_SYSCALL
:
760 * Needs to be explicitly enabled after creation, since
761 * we may want to apply filters.
764 event
->registered
= 0;
765 event
->desc
= event_desc
;
776 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
777 WARN_ON_ONCE(ret
> 0);
779 goto statedump_error
;
781 hlist_add_head(&event
->hlist
, head
);
782 list_add(&event
->list
, &chan
->session
->events
);
786 /* If a statedump error occurs, events will not be readable. */
788 kmem_cache_free(event_cache
, event
);
796 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
797 struct lttng_kernel_event
*event_param
,
799 const struct lttng_event_desc
*event_desc
,
800 enum lttng_kernel_instrumentation itype
)
802 struct lttng_event
*event
;
804 mutex_lock(&sessions_mutex
);
805 event
= _lttng_event_create(chan
, event_param
, filter
, event_desc
,
807 mutex_unlock(&sessions_mutex
);
811 /* Only used for tracepoints for now. */
813 void register_event(struct lttng_event
*event
)
815 const struct lttng_event_desc
*desc
;
818 if (event
->registered
)
822 switch (event
->instrumentation
) {
823 case LTTNG_KERNEL_TRACEPOINT
:
824 ret
= lttng_wrapper_tracepoint_probe_register(desc
->kname
,
825 desc
->probe_callback
,
828 case LTTNG_KERNEL_SYSCALL
:
829 ret
= lttng_syscall_filter_enable(event
->chan
,
832 case LTTNG_KERNEL_KPROBE
:
833 case LTTNG_KERNEL_KRETPROBE
:
834 case LTTNG_KERNEL_FUNCTION
:
835 case LTTNG_KERNEL_NOOP
:
842 event
->registered
= 1;
846 * Only used internally at session destruction.
848 int _lttng_event_unregister(struct lttng_event
*event
)
850 const struct lttng_event_desc
*desc
;
853 if (!event
->registered
)
857 switch (event
->instrumentation
) {
858 case LTTNG_KERNEL_TRACEPOINT
:
859 ret
= lttng_wrapper_tracepoint_probe_unregister(event
->desc
->kname
,
860 event
->desc
->probe_callback
,
863 case LTTNG_KERNEL_KPROBE
:
864 lttng_kprobes_unregister(event
);
867 case LTTNG_KERNEL_KRETPROBE
:
868 lttng_kretprobes_unregister(event
);
871 case LTTNG_KERNEL_FUNCTION
:
872 lttng_ftrace_unregister(event
);
875 case LTTNG_KERNEL_SYSCALL
:
876 ret
= lttng_syscall_filter_disable(event
->chan
,
879 case LTTNG_KERNEL_NOOP
:
886 event
->registered
= 0;
891 * Only used internally at session destruction.
894 void _lttng_event_destroy(struct lttng_event
*event
)
896 switch (event
->instrumentation
) {
897 case LTTNG_KERNEL_TRACEPOINT
:
898 lttng_event_put(event
->desc
);
900 case LTTNG_KERNEL_KPROBE
:
901 module_put(event
->desc
->owner
);
902 lttng_kprobes_destroy_private(event
);
904 case LTTNG_KERNEL_KRETPROBE
:
905 module_put(event
->desc
->owner
);
906 lttng_kretprobes_destroy_private(event
);
908 case LTTNG_KERNEL_FUNCTION
:
909 module_put(event
->desc
->owner
);
910 lttng_ftrace_destroy_private(event
);
912 case LTTNG_KERNEL_NOOP
:
913 case LTTNG_KERNEL_SYSCALL
:
918 list_del(&event
->list
);
919 lttng_destroy_context(event
->ctx
);
920 kmem_cache_free(event_cache
, event
);
923 struct lttng_id_tracker
*get_tracker(struct lttng_session
*session
,
924 enum tracker_type tracker_type
)
926 switch (tracker_type
) {
928 return &session
->pid_tracker
;
930 return &session
->vpid_tracker
;
932 return &session
->uid_tracker
;
934 return &session
->vuid_tracker
;
936 return &session
->gid_tracker
;
938 return &session
->vgid_tracker
;
945 int lttng_session_track_id(struct lttng_session
*session
,
946 enum tracker_type tracker_type
, int id
)
948 struct lttng_id_tracker
*tracker
;
951 tracker
= get_tracker(session
, tracker_type
);
956 mutex_lock(&sessions_mutex
);
958 /* track all ids: destroy tracker. */
959 lttng_id_tracker_destroy(tracker
, true);
962 ret
= lttng_id_tracker_add(tracker
, id
);
964 mutex_unlock(&sessions_mutex
);
968 int lttng_session_untrack_id(struct lttng_session
*session
,
969 enum tracker_type tracker_type
, int id
)
971 struct lttng_id_tracker
*tracker
;
974 tracker
= get_tracker(session
, tracker_type
);
979 mutex_lock(&sessions_mutex
);
981 /* untrack all ids: replace by empty tracker. */
982 ret
= lttng_id_tracker_empty_set(tracker
);
984 ret
= lttng_id_tracker_del(tracker
, id
);
986 mutex_unlock(&sessions_mutex
);
991 void *id_list_start(struct seq_file
*m
, loff_t
*pos
)
993 struct lttng_id_tracker
*id_tracker
= m
->private;
994 struct lttng_id_tracker_rcu
*id_tracker_p
= id_tracker
->p
;
995 struct lttng_id_hash_node
*e
;
998 mutex_lock(&sessions_mutex
);
1000 for (i
= 0; i
< LTTNG_ID_TABLE_SIZE
; i
++) {
1001 struct hlist_head
*head
= &id_tracker_p
->id_hash
[i
];
1003 lttng_hlist_for_each_entry(e
, head
, hlist
) {
1009 /* ID tracker disabled. */
1010 if (iter
>= *pos
&& iter
== 0) {
1011 return id_tracker_p
; /* empty tracker */
1019 /* Called with sessions_mutex held. */
1021 void *id_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1023 struct lttng_id_tracker
*id_tracker
= m
->private;
1024 struct lttng_id_tracker_rcu
*id_tracker_p
= id_tracker
->p
;
1025 struct lttng_id_hash_node
*e
;
1030 for (i
= 0; i
< LTTNG_ID_TABLE_SIZE
; i
++) {
1031 struct hlist_head
*head
= &id_tracker_p
->id_hash
[i
];
1033 lttng_hlist_for_each_entry(e
, head
, hlist
) {
1034 if (iter
++ >= *ppos
)
1039 /* ID tracker disabled. */
1040 if (iter
>= *ppos
&& iter
== 0)
1041 return p
; /* empty tracker */
1050 void id_list_stop(struct seq_file
*m
, void *p
)
1052 mutex_unlock(&sessions_mutex
);
1056 int id_list_show(struct seq_file
*m
, void *p
)
1058 struct lttng_id_tracker
*id_tracker
= m
->private;
1059 struct lttng_id_tracker_rcu
*id_tracker_p
= id_tracker
->p
;
1062 if (p
== id_tracker_p
) {
1063 /* Tracker disabled. */
1066 const struct lttng_id_hash_node
*e
= p
;
1068 id
= lttng_id_tracker_get_node_id(e
);
1070 switch (id_tracker
->tracker_type
) {
1072 seq_printf(m
, "process { pid = %d; };\n", id
);
1075 seq_printf(m
, "process { vpid = %d; };\n", id
);
1078 seq_printf(m
, "user { uid = %d; };\n", id
);
1081 seq_printf(m
, "user { vuid = %d; };\n", id
);
1084 seq_printf(m
, "group { gid = %d; };\n", id
);
1087 seq_printf(m
, "group { vgid = %d; };\n", id
);
1090 seq_printf(m
, "UNKNOWN { field = %d };\n", id
);
1096 const struct seq_operations lttng_tracker_ids_list_seq_ops
= {
1097 .start
= id_list_start
,
1098 .next
= id_list_next
,
1099 .stop
= id_list_stop
,
1100 .show
= id_list_show
,
1104 int lttng_tracker_ids_list_open(struct inode
*inode
, struct file
*file
)
1106 return seq_open(file
, <tng_tracker_ids_list_seq_ops
);
1110 int lttng_tracker_ids_list_release(struct inode
*inode
, struct file
*file
)
1112 struct seq_file
*m
= file
->private_data
;
1113 struct lttng_id_tracker
*id_tracker
= m
->private;
1116 WARN_ON_ONCE(!id_tracker
);
1117 ret
= seq_release(inode
, file
);
1119 fput(id_tracker
->session
->file
);
1123 const struct file_operations lttng_tracker_ids_list_fops
= {
1124 .owner
= THIS_MODULE
,
1125 .open
= lttng_tracker_ids_list_open
,
1127 .llseek
= seq_lseek
,
1128 .release
= lttng_tracker_ids_list_release
,
1131 int lttng_session_list_tracker_ids(struct lttng_session
*session
,
1132 enum tracker_type tracker_type
)
1134 struct file
*tracker_ids_list_file
;
1138 file_fd
= lttng_get_unused_fd();
1144 tracker_ids_list_file
= anon_inode_getfile("[lttng_tracker_ids_list]",
1145 <tng_tracker_ids_list_fops
,
1147 if (IS_ERR(tracker_ids_list_file
)) {
1148 ret
= PTR_ERR(tracker_ids_list_file
);
1151 if (atomic_long_add_unless(&session
->file
->f_count
,
1152 1, INT_MAX
) == INT_MAX
) {
1153 goto refcount_error
;
1155 ret
= lttng_tracker_ids_list_fops
.open(NULL
, tracker_ids_list_file
);
1158 m
= tracker_ids_list_file
->private_data
;
1160 m
->private = get_tracker(session
, tracker_type
);
1161 BUG_ON(!m
->private);
1162 fd_install(file_fd
, tracker_ids_list_file
);
1167 atomic_long_dec(&session
->file
->f_count
);
1169 fput(tracker_ids_list_file
);
1171 put_unused_fd(file_fd
);
1177 * Enabler management.
1180 int lttng_match_enabler_wildcard(const char *desc_name
,
1183 /* Compare excluding final '*' */
1184 if (strncmp(desc_name
, name
, strlen(name
) - 1))
1190 int lttng_match_enabler_name(const char *desc_name
,
1193 if (strcmp(desc_name
, name
))
1199 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
1200 struct lttng_enabler
*enabler
)
1202 const char *desc_name
, *enabler_name
;
1204 enabler_name
= enabler
->event_param
.name
;
1205 switch (enabler
->event_param
.instrumentation
) {
1206 case LTTNG_KERNEL_TRACEPOINT
:
1207 desc_name
= desc
->name
;
1209 case LTTNG_KERNEL_SYSCALL
:
1210 desc_name
= desc
->name
;
1211 if (!strncmp(desc_name
, "compat_", strlen("compat_")))
1212 desc_name
+= strlen("compat_");
1213 if (!strncmp(desc_name
, "syscall_exit_",
1214 strlen("syscall_exit_"))) {
1215 desc_name
+= strlen("syscall_exit_");
1216 } else if (!strncmp(desc_name
, "syscall_entry_",
1217 strlen("syscall_entry_"))) {
1218 desc_name
+= strlen("syscall_entry_");
1228 switch (enabler
->type
) {
1229 case LTTNG_ENABLER_WILDCARD
:
1230 return lttng_match_enabler_wildcard(desc_name
, enabler_name
);
1231 case LTTNG_ENABLER_NAME
:
1232 return lttng_match_enabler_name(desc_name
, enabler_name
);
1239 int lttng_event_match_enabler(struct lttng_event
*event
,
1240 struct lttng_enabler
*enabler
)
1242 if (enabler
->event_param
.instrumentation
!= event
->instrumentation
)
1244 if (lttng_desc_match_enabler(event
->desc
, enabler
)
1245 && event
->chan
== enabler
->chan
)
1252 struct lttng_enabler_ref
*lttng_event_enabler_ref(struct lttng_event
*event
,
1253 struct lttng_enabler
*enabler
)
1255 struct lttng_enabler_ref
*enabler_ref
;
1257 list_for_each_entry(enabler_ref
,
1258 &event
->enablers_ref_head
, node
) {
1259 if (enabler_ref
->ref
== enabler
)
1266 void lttng_create_tracepoint_if_missing(struct lttng_enabler
*enabler
)
1268 struct lttng_session
*session
= enabler
->chan
->session
;
1269 struct lttng_probe_desc
*probe_desc
;
1270 const struct lttng_event_desc
*desc
;
1272 struct list_head
*probe_list
;
1274 probe_list
= lttng_get_probe_list_head();
1276 * For each probe event, if we find that a probe event matches
1277 * our enabler, create an associated lttng_event if not
1280 list_for_each_entry(probe_desc
, probe_list
, head
) {
1281 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1283 struct hlist_head
*head
;
1284 const char *event_name
;
1287 struct lttng_event
*event
;
1289 desc
= probe_desc
->event_desc
[i
];
1290 if (!lttng_desc_match_enabler(desc
, enabler
))
1292 event_name
= desc
->name
;
1293 name_len
= strlen(event_name
);
1296 * Check if already created.
1298 hash
= jhash(event_name
, name_len
, 0);
1299 head
= &session
->events_ht
.table
[hash
& (LTTNG_EVENT_HT_SIZE
- 1)];
1300 lttng_hlist_for_each_entry(event
, head
, hlist
) {
1301 if (event
->desc
== desc
1302 && event
->chan
== enabler
->chan
)
1309 * We need to create an event for this
1312 event
= _lttng_event_create(enabler
->chan
,
1314 LTTNG_KERNEL_TRACEPOINT
);
1316 printk(KERN_INFO
"Unable to create event %s\n",
1317 probe_desc
->event_desc
[i
]->name
);
1324 void lttng_create_syscall_if_missing(struct lttng_enabler
*enabler
)
1328 ret
= lttng_syscalls_register(enabler
->chan
, NULL
);
1333 * Create struct lttng_event if it is missing and present in the list of
1334 * tracepoint probes.
1335 * Should be called with sessions mutex held.
1338 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
1340 switch (enabler
->event_param
.instrumentation
) {
1341 case LTTNG_KERNEL_TRACEPOINT
:
1342 lttng_create_tracepoint_if_missing(enabler
);
1344 case LTTNG_KERNEL_SYSCALL
:
1345 lttng_create_syscall_if_missing(enabler
);
1354 * Create events associated with an enabler (if not already present),
1355 * and add backward reference from the event to the enabler.
1356 * Should be called with sessions mutex held.
1359 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
1361 struct lttng_session
*session
= enabler
->chan
->session
;
1362 struct lttng_event
*event
;
1364 /* First ensure that probe events are created for this enabler. */
1365 lttng_create_event_if_missing(enabler
);
1367 /* For each event matching enabler in session event list. */
1368 list_for_each_entry(event
, &session
->events
, list
) {
1369 struct lttng_enabler_ref
*enabler_ref
;
1371 if (!lttng_event_match_enabler(event
, enabler
))
1373 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
1376 * If no backward ref, create it.
1377 * Add backward ref from event to enabler.
1379 enabler_ref
= kzalloc(sizeof(*enabler_ref
), GFP_KERNEL
);
1382 enabler_ref
->ref
= enabler
;
1383 list_add(&enabler_ref
->node
,
1384 &event
->enablers_ref_head
);
1388 * Link filter bytecodes if not linked yet.
1390 lttng_enabler_event_link_bytecode(event
, enabler
);
1392 /* TODO: merge event context. */
1398 * Called at module load: connect the probe on all enablers matching
1400 * Called with sessions lock held.
1402 int lttng_fix_pending_events(void)
1404 struct lttng_session
*session
;
1406 list_for_each_entry(session
, &sessions
, list
)
1407 lttng_session_lazy_sync_enablers(session
);
1411 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
1412 struct lttng_kernel_event
*event_param
,
1413 struct lttng_channel
*chan
)
1415 struct lttng_enabler
*enabler
;
1417 enabler
= kzalloc(sizeof(*enabler
), GFP_KERNEL
);
1420 enabler
->type
= type
;
1421 INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
1422 memcpy(&enabler
->event_param
, event_param
,
1423 sizeof(enabler
->event_param
));
1424 enabler
->chan
= chan
;
1426 enabler
->enabled
= 0;
1427 enabler
->evtype
= LTTNG_TYPE_ENABLER
;
1428 mutex_lock(&sessions_mutex
);
1429 list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
1430 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1431 mutex_unlock(&sessions_mutex
);
1435 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
1437 mutex_lock(&sessions_mutex
);
1438 enabler
->enabled
= 1;
1439 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1440 mutex_unlock(&sessions_mutex
);
1444 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
1446 mutex_lock(&sessions_mutex
);
1447 enabler
->enabled
= 0;
1448 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1449 mutex_unlock(&sessions_mutex
);
1453 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
1454 struct lttng_kernel_filter_bytecode __user
*bytecode
)
1456 struct lttng_filter_bytecode_node
*bytecode_node
;
1457 uint32_t bytecode_len
;
1460 ret
= get_user(bytecode_len
, &bytecode
->len
);
1463 bytecode_node
= kzalloc(sizeof(*bytecode_node
) + bytecode_len
,
1467 ret
= copy_from_user(&bytecode_node
->bc
, bytecode
,
1468 sizeof(*bytecode
) + bytecode_len
);
1471 bytecode_node
->enabler
= enabler
;
1472 /* Enforce length based on allocated size */
1473 bytecode_node
->bc
.len
= bytecode_len
;
1474 list_add_tail(&bytecode_node
->node
, &enabler
->filter_bytecode_head
);
1475 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1479 kfree(bytecode_node
);
1483 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1484 struct lttng_kernel_context
*context_param
)
1490 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1492 struct lttng_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1494 /* Destroy filter bytecode */
1495 list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1496 &enabler
->filter_bytecode_head
, node
) {
1500 /* Destroy contexts */
1501 lttng_destroy_context(enabler
->ctx
);
1503 list_del(&enabler
->node
);
1508 * lttng_session_sync_enablers should be called just before starting a
1510 * Should be called with sessions mutex held.
1513 void lttng_session_sync_enablers(struct lttng_session
*session
)
1515 struct lttng_enabler
*enabler
;
1516 struct lttng_event
*event
;
1518 list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1519 lttng_enabler_ref_events(enabler
);
1521 * For each event, if at least one of its enablers is enabled,
1522 * and its channel and session transient states are enabled, we
1523 * enable the event, else we disable it.
1525 list_for_each_entry(event
, &session
->events
, list
) {
1526 struct lttng_enabler_ref
*enabler_ref
;
1527 struct lttng_bytecode_runtime
*runtime
;
1528 int enabled
= 0, has_enablers_without_bytecode
= 0;
1530 switch (event
->instrumentation
) {
1531 case LTTNG_KERNEL_TRACEPOINT
:
1532 case LTTNG_KERNEL_SYSCALL
:
1534 list_for_each_entry(enabler_ref
,
1535 &event
->enablers_ref_head
, node
) {
1536 if (enabler_ref
->ref
->enabled
) {
1543 /* Not handled with lazy sync. */
1547 * Enabled state is based on union of enablers, with
1548 * intesection of session and channel transient enable
1551 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1553 WRITE_ONCE(event
->enabled
, enabled
);
1555 * Sync tracepoint registration with event enabled
1559 register_event(event
);
1561 _lttng_event_unregister(event
);
1564 /* Check if has enablers without bytecode enabled */
1565 list_for_each_entry(enabler_ref
,
1566 &event
->enablers_ref_head
, node
) {
1567 if (enabler_ref
->ref
->enabled
1568 && list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1569 has_enablers_without_bytecode
= 1;
1573 event
->has_enablers_without_bytecode
=
1574 has_enablers_without_bytecode
;
1576 /* Enable filters */
1577 list_for_each_entry(runtime
,
1578 &event
->bytecode_runtime_head
, node
)
1579 lttng_filter_sync_state(runtime
);
1584 * Apply enablers to session events, adding events to session if need
1585 * be. It is required after each modification applied to an active
1586 * session, and right before session "start".
1587 * "lazy" sync means we only sync if required.
1588 * Should be called with sessions mutex held.
1591 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1593 /* We can skip if session is not active */
1594 if (!session
->active
)
1596 lttng_session_sync_enablers(session
);
1600 * Serialize at most one packet worth of metadata into a metadata
1602 * We grab the metadata cache mutex to get exclusive access to our metadata
1603 * buffer and to the metadata cache. Exclusive access to the metadata buffer
1604 * allows us to do racy operations such as looking for remaining space left in
1605 * packet and write, since mutual exclusion protects us from concurrent writes.
1606 * Mutual exclusion on the metadata cache allow us to read the cache content
1607 * without racing against reallocation of the cache by updates.
1608 * Returns the number of bytes written in the channel, 0 if no data
1609 * was written and a negative value on error.
1611 int lttng_metadata_output_channel(struct lttng_metadata_stream
*stream
,
1612 struct channel
*chan
)
1614 struct lib_ring_buffer_ctx ctx
;
1616 size_t len
, reserve_len
;
1619 * Ensure we support mutiple get_next / put sequences followed by
1620 * put_next. The metadata cache lock protects reading the metadata
1621 * cache. It can indeed be read concurrently by "get_next_subbuf" and
1622 * "flush" operations on the buffer invoked by different processes.
1623 * Moreover, since the metadata cache memory can be reallocated, we
1624 * need to have exclusive access against updates even though we only
1627 mutex_lock(&stream
->metadata_cache
->lock
);
1628 WARN_ON(stream
->metadata_in
< stream
->metadata_out
);
1629 if (stream
->metadata_in
!= stream
->metadata_out
)
1632 /* Metadata regenerated, change the version. */
1633 if (stream
->metadata_cache
->version
!= stream
->version
)
1634 stream
->version
= stream
->metadata_cache
->version
;
1636 len
= stream
->metadata_cache
->metadata_written
-
1637 stream
->metadata_in
;
1640 reserve_len
= min_t(size_t,
1641 stream
->transport
->ops
.packet_avail_size(chan
),
1643 lib_ring_buffer_ctx_init(&ctx
, chan
, NULL
, reserve_len
,
1646 * If reservation failed, return an error to the caller.
1648 ret
= stream
->transport
->ops
.event_reserve(&ctx
, 0);
1650 printk(KERN_WARNING
"LTTng: Metadata event reservation failed\n");
1653 stream
->transport
->ops
.event_write(&ctx
,
1654 stream
->metadata_cache
->data
+ stream
->metadata_in
,
1656 stream
->transport
->ops
.event_commit(&ctx
);
1657 stream
->metadata_in
+= reserve_len
;
1661 mutex_unlock(&stream
->metadata_cache
->lock
);
1666 * Write the metadata to the metadata cache.
1667 * Must be called with sessions_mutex held.
1668 * The metadata cache lock protects us from concurrent read access from
1669 * thread outputting metadata content to ring buffer.
1671 int lttng_metadata_printf(struct lttng_session
*session
,
1672 const char *fmt
, ...)
1677 struct lttng_metadata_stream
*stream
;
1679 WARN_ON_ONCE(!READ_ONCE(session
->active
));
1682 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
1688 mutex_lock(&session
->metadata_cache
->lock
);
1689 if (session
->metadata_cache
->metadata_written
+ len
>
1690 session
->metadata_cache
->cache_alloc
) {
1691 char *tmp_cache_realloc
;
1692 unsigned int tmp_cache_alloc_size
;
1694 tmp_cache_alloc_size
= max_t(unsigned int,
1695 session
->metadata_cache
->cache_alloc
+ len
,
1696 session
->metadata_cache
->cache_alloc
<< 1);
1697 tmp_cache_realloc
= lttng_vzalloc(tmp_cache_alloc_size
);
1698 if (!tmp_cache_realloc
)
1700 if (session
->metadata_cache
->data
) {
1701 memcpy(tmp_cache_realloc
,
1702 session
->metadata_cache
->data
,
1703 session
->metadata_cache
->cache_alloc
);
1704 vfree(session
->metadata_cache
->data
);
1707 session
->metadata_cache
->cache_alloc
= tmp_cache_alloc_size
;
1708 session
->metadata_cache
->data
= tmp_cache_realloc
;
1710 memcpy(session
->metadata_cache
->data
+
1711 session
->metadata_cache
->metadata_written
,
1713 session
->metadata_cache
->metadata_written
+= len
;
1714 mutex_unlock(&session
->metadata_cache
->lock
);
1717 list_for_each_entry(stream
, &session
->metadata_cache
->metadata_stream
, list
)
1718 wake_up_interruptible(&stream
->read_wait
);
1723 mutex_unlock(&session
->metadata_cache
->lock
);
1729 int print_tabs(struct lttng_session
*session
, size_t nesting
)
1733 for (i
= 0; i
< nesting
; i
++) {
1736 ret
= lttng_metadata_printf(session
, " ");
1745 * Must be called with sessions_mutex held.
1748 int _lttng_struct_type_statedump(struct lttng_session
*session
,
1749 const struct lttng_type
*type
,
1753 uint32_t i
, nr_fields
;
1755 ret
= print_tabs(session
, nesting
);
1758 ret
= lttng_metadata_printf(session
,
1762 nr_fields
= type
->u
._struct
.nr_fields
;
1763 for (i
= 0; i
< nr_fields
; i
++) {
1764 const struct lttng_event_field
*iter_field
;
1766 iter_field
= &type
->u
._struct
.fields
[i
];
1767 ret
= _lttng_field_statedump(session
, iter_field
, nesting
+ 1);
1771 ret
= print_tabs(session
, nesting
);
1774 ret
= lttng_metadata_printf(session
,
1780 * Must be called with sessions_mutex held.
1783 int _lttng_struct_statedump(struct lttng_session
*session
,
1784 const struct lttng_event_field
*field
,
1789 ret
= _lttng_struct_type_statedump(session
,
1790 &field
->type
, nesting
);
1793 ret
= lttng_metadata_printf(session
,
1800 * Must be called with sessions_mutex held.
1803 int _lttng_variant_type_statedump(struct lttng_session
*session
,
1804 const struct lttng_type
*type
,
1808 uint32_t i
, nr_choices
;
1810 ret
= print_tabs(session
, nesting
);
1813 ret
= lttng_metadata_printf(session
,
1814 "variant <_%s> {\n",
1815 type
->u
.variant
.tag_name
);
1818 nr_choices
= type
->u
.variant
.nr_choices
;
1819 for (i
= 0; i
< nr_choices
; i
++) {
1820 const struct lttng_event_field
*iter_field
;
1822 iter_field
= &type
->u
.variant
.choices
[i
];
1823 ret
= _lttng_field_statedump(session
, iter_field
, nesting
+ 1);
1827 ret
= print_tabs(session
, nesting
);
1830 ret
= lttng_metadata_printf(session
,
1836 * Must be called with sessions_mutex held.
1839 int _lttng_variant_statedump(struct lttng_session
*session
,
1840 const struct lttng_event_field
*field
,
1845 ret
= _lttng_variant_type_statedump(session
,
1846 &field
->type
, nesting
);
1849 ret
= lttng_metadata_printf(session
,
1856 * Must be called with sessions_mutex held.
1859 int _lttng_array_compound_statedump(struct lttng_session
*session
,
1860 const struct lttng_event_field
*field
,
1864 const struct lttng_type
*elem_type
;
1866 /* Only array of structures and variants are currently supported. */
1867 elem_type
= field
->type
.u
.array_compound
.elem_type
;
1868 switch (elem_type
->atype
) {
1870 ret
= _lttng_struct_type_statedump(session
, elem_type
, nesting
);
1875 ret
= _lttng_variant_type_statedump(session
, elem_type
, nesting
);
1882 ret
= lttng_metadata_printf(session
,
1885 field
->type
.u
.array_compound
.length
);
1890 * Must be called with sessions_mutex held.
1893 int _lttng_sequence_compound_statedump(struct lttng_session
*session
,
1894 const struct lttng_event_field
*field
,
1898 const char *length_name
;
1899 const struct lttng_type
*elem_type
;
1901 length_name
= field
->type
.u
.sequence_compound
.length_name
;
1903 /* Only array of structures and variants are currently supported. */
1904 elem_type
= field
->type
.u
.sequence_compound
.elem_type
;
1905 switch (elem_type
->atype
) {
1907 ret
= _lttng_struct_type_statedump(session
, elem_type
, nesting
);
1912 ret
= _lttng_variant_type_statedump(session
, elem_type
, nesting
);
1919 ret
= lttng_metadata_printf(session
,
1927 * Must be called with sessions_mutex held.
1930 int _lttng_enum_statedump(struct lttng_session
*session
,
1931 const struct lttng_event_field
*field
,
1934 const struct lttng_enum_desc
*enum_desc
;
1935 const struct lttng_integer_type
*container_type
;
1937 unsigned int i
, nr_entries
;
1939 enum_desc
= field
->type
.u
.basic
.enumeration
.desc
;
1940 container_type
= &field
->type
.u
.basic
.enumeration
.container_type
;
1941 nr_entries
= enum_desc
->nr_entries
;
1943 ret
= print_tabs(session
, nesting
);
1946 ret
= lttng_metadata_printf(session
,
1947 "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n",
1948 container_type
->size
,
1949 container_type
->alignment
,
1950 container_type
->signedness
,
1951 (container_type
->encoding
== lttng_encode_none
)
1953 : (container_type
->encoding
== lttng_encode_UTF8
)
1956 container_type
->base
,
1957 #if __BYTE_ORDER == __BIG_ENDIAN
1958 container_type
->reverse_byte_order
? " byte_order = le;" : ""
1960 container_type
->reverse_byte_order
? " byte_order = be;" : ""
1965 /* Dump all entries */
1966 for (i
= 0; i
< nr_entries
; i
++) {
1967 const struct lttng_enum_entry
*entry
= &enum_desc
->entries
[i
];
1970 ret
= print_tabs(session
, nesting
+ 1);
1973 ret
= lttng_metadata_printf(session
,
1977 len
= strlen(entry
->string
);
1978 /* Escape the character '"' */
1979 for (j
= 0; j
< len
; j
++) {
1980 char c
= entry
->string
[j
];
1984 ret
= lttng_metadata_printf(session
,
1988 ret
= lttng_metadata_printf(session
,
1992 ret
= lttng_metadata_printf(session
,
1999 ret
= lttng_metadata_printf(session
, "\"");
2003 if (entry
->options
.is_auto
) {
2004 ret
= lttng_metadata_printf(session
, ",\n");
2008 ret
= lttng_metadata_printf(session
,
2012 if (entry
->start
.signedness
)
2013 ret
= lttng_metadata_printf(session
,
2014 "%lld", (long long) entry
->start
.value
);
2016 ret
= lttng_metadata_printf(session
,
2017 "%llu", entry
->start
.value
);
2020 if (entry
->start
.signedness
== entry
->end
.signedness
&&
2022 == entry
->end
.value
) {
2023 ret
= lttng_metadata_printf(session
,
2026 if (entry
->end
.signedness
) {
2027 ret
= lttng_metadata_printf(session
,
2029 (long long) entry
->end
.value
);
2031 ret
= lttng_metadata_printf(session
,
2040 ret
= print_tabs(session
, nesting
);
2043 ret
= lttng_metadata_printf(session
, "} _%s;\n",
2050 * Must be called with sessions_mutex held.
2053 int _lttng_field_statedump(struct lttng_session
*session
,
2054 const struct lttng_event_field
*field
,
2059 switch (field
->type
.atype
) {
2061 ret
= print_tabs(session
, nesting
);
2064 ret
= lttng_metadata_printf(session
,
2065 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
2066 field
->type
.u
.basic
.integer
.size
,
2067 field
->type
.u
.basic
.integer
.alignment
,
2068 field
->type
.u
.basic
.integer
.signedness
,
2069 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
2071 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2074 field
->type
.u
.basic
.integer
.base
,
2075 #if __BYTE_ORDER == __BIG_ENDIAN
2076 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2078 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2083 ret
= _lttng_enum_statedump(session
, field
, nesting
);
2087 const struct lttng_basic_type
*elem_type
;
2089 elem_type
= &field
->type
.u
.array
.elem_type
;
2090 if (field
->type
.u
.array
.elem_alignment
) {
2091 ret
= print_tabs(session
, nesting
);
2094 ret
= lttng_metadata_printf(session
,
2095 "struct { } align(%u) _%s_padding;\n",
2096 field
->type
.u
.array
.elem_alignment
* CHAR_BIT
,
2101 ret
= print_tabs(session
, nesting
);
2104 ret
= lttng_metadata_printf(session
,
2105 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
2106 elem_type
->u
.basic
.integer
.size
,
2107 elem_type
->u
.basic
.integer
.alignment
,
2108 elem_type
->u
.basic
.integer
.signedness
,
2109 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2111 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2114 elem_type
->u
.basic
.integer
.base
,
2115 #if __BYTE_ORDER == __BIG_ENDIAN
2116 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2118 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2120 field
->name
, field
->type
.u
.array
.length
);
2123 case atype_sequence
:
2125 const struct lttng_basic_type
*elem_type
;
2126 const struct lttng_basic_type
*length_type
;
2128 elem_type
= &field
->type
.u
.sequence
.elem_type
;
2129 length_type
= &field
->type
.u
.sequence
.length_type
;
2130 ret
= print_tabs(session
, nesting
);
2133 ret
= lttng_metadata_printf(session
,
2134 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
2135 length_type
->u
.basic
.integer
.size
,
2136 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
2137 length_type
->u
.basic
.integer
.signedness
,
2138 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2140 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2143 length_type
->u
.basic
.integer
.base
,
2144 #if __BYTE_ORDER == __BIG_ENDIAN
2145 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2147 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2153 if (field
->type
.u
.sequence
.elem_alignment
) {
2154 ret
= print_tabs(session
, nesting
);
2157 ret
= lttng_metadata_printf(session
,
2158 "struct { } align(%u) _%s_padding;\n",
2159 field
->type
.u
.sequence
.elem_alignment
* CHAR_BIT
,
2164 ret
= print_tabs(session
, nesting
);
2167 ret
= lttng_metadata_printf(session
,
2168 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
2169 elem_type
->u
.basic
.integer
.size
,
2170 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
2171 elem_type
->u
.basic
.integer
.signedness
,
2172 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2174 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2177 elem_type
->u
.basic
.integer
.base
,
2178 #if __BYTE_ORDER == __BIG_ENDIAN
2179 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2181 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2189 /* Default encoding is UTF8 */
2190 ret
= print_tabs(session
, nesting
);
2193 ret
= lttng_metadata_printf(session
,
2195 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
2196 " { encoding = ASCII; }" : "",
2200 ret
= _lttng_struct_statedump(session
, field
, nesting
);
2202 case atype_array_compound
:
2203 ret
= _lttng_array_compound_statedump(session
, field
, nesting
);
2205 case atype_sequence_compound
:
2206 ret
= _lttng_sequence_compound_statedump(session
, field
, nesting
);
2209 ret
= _lttng_variant_statedump(session
, field
, nesting
);
2220 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
2221 struct lttng_ctx
*ctx
)
2228 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
2229 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
2231 ret
= _lttng_field_statedump(session
, &field
->event_field
, 2);
2239 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
2240 struct lttng_event
*event
)
2242 const struct lttng_event_desc
*desc
= event
->desc
;
2246 for (i
= 0; i
< desc
->nr_fields
; i
++) {
2247 const struct lttng_event_field
*field
= &desc
->fields
[i
];
2249 ret
= _lttng_field_statedump(session
, field
, 2);
2257 * Must be called with sessions_mutex held.
2260 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
2261 struct lttng_channel
*chan
,
2262 struct lttng_event
*event
)
2266 if (event
->metadata_dumped
|| !READ_ONCE(session
->active
))
2268 if (chan
->channel_type
== METADATA_CHANNEL
)
2271 ret
= lttng_metadata_printf(session
,
2275 " stream_id = %u;\n",
2283 ret
= lttng_metadata_printf(session
,
2284 " context := struct {\n");
2288 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
2292 ret
= lttng_metadata_printf(session
,
2298 ret
= lttng_metadata_printf(session
,
2299 " fields := struct {\n"
2304 ret
= _lttng_fields_metadata_statedump(session
, event
);
2309 * LTTng space reservation can only reserve multiples of the
2312 ret
= lttng_metadata_printf(session
,
2318 event
->metadata_dumped
= 1;
2325 * Must be called with sessions_mutex held.
2328 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
2329 struct lttng_channel
*chan
)
2333 if (chan
->metadata_dumped
|| !READ_ONCE(session
->active
))
2336 if (chan
->channel_type
== METADATA_CHANNEL
)
2339 WARN_ON_ONCE(!chan
->header_type
);
2340 ret
= lttng_metadata_printf(session
,
2343 " event.header := %s;\n"
2344 " packet.context := struct packet_context;\n",
2346 chan
->header_type
== 1 ? "struct event_header_compact" :
2347 "struct event_header_large");
2352 ret
= lttng_metadata_printf(session
,
2353 " event.context := struct {\n");
2357 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
2361 ret
= lttng_metadata_printf(session
,
2367 ret
= lttng_metadata_printf(session
,
2370 chan
->metadata_dumped
= 1;
2376 * Must be called with sessions_mutex held.
2379 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
2381 return lttng_metadata_printf(session
,
2382 "struct packet_context {\n"
2383 " uint64_clock_monotonic_t timestamp_begin;\n"
2384 " uint64_clock_monotonic_t timestamp_end;\n"
2385 " uint64_t content_size;\n"
2386 " uint64_t packet_size;\n"
2387 " uint64_t packet_seq_num;\n"
2388 " unsigned long events_discarded;\n"
2389 " uint32_t cpu_id;\n"
2396 * id: range: 0 - 30.
2397 * id 31 is reserved to indicate an extended header.
2400 * id: range: 0 - 65534.
2401 * id 65535 is reserved to indicate an extended header.
2403 * Must be called with sessions_mutex held.
2406 int _lttng_event_header_declare(struct lttng_session
*session
)
2408 return lttng_metadata_printf(session
,
2409 "struct event_header_compact {\n"
2410 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
2413 " uint27_clock_monotonic_t timestamp;\n"
2417 " uint64_clock_monotonic_t timestamp;\n"
2422 "struct event_header_large {\n"
2423 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
2426 " uint32_clock_monotonic_t timestamp;\n"
2430 " uint64_clock_monotonic_t timestamp;\n"
2434 lttng_alignof(uint32_t) * CHAR_BIT
,
2435 lttng_alignof(uint16_t) * CHAR_BIT
2440 * Approximation of NTP time of day to clock monotonic correlation,
2441 * taken at start of trace.
2442 * Yes, this is only an approximation. Yes, we can (and will) do better
2443 * in future versions.
2444 * This function may return a negative offset. It may happen if the
2445 * system sets the REALTIME clock to 0 after boot.
2448 int64_t measure_clock_offset(void)
2450 uint64_t monotonic_avg
, monotonic
[2], realtime
;
2451 uint64_t tcf
= trace_clock_freq();
2453 struct timespec rts
= { 0, 0 };
2454 unsigned long flags
;
2456 /* Disable interrupts to increase correlation precision. */
2457 local_irq_save(flags
);
2458 monotonic
[0] = trace_clock_read64();
2459 getnstimeofday(&rts
);
2460 monotonic
[1] = trace_clock_read64();
2461 local_irq_restore(flags
);
2463 monotonic_avg
= (monotonic
[0] + monotonic
[1]) >> 1;
2464 realtime
= (uint64_t) rts
.tv_sec
* tcf
;
2465 if (tcf
== NSEC_PER_SEC
) {
2466 realtime
+= rts
.tv_nsec
;
2468 uint64_t n
= rts
.tv_nsec
* tcf
;
2470 do_div(n
, NSEC_PER_SEC
);
2473 offset
= (int64_t) realtime
- monotonic_avg
;
2478 * Output metadata into this session's metadata buffers.
2479 * Must be called with sessions_mutex held.
2482 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
2484 unsigned char *uuid_c
= session
->uuid
.b
;
2485 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
2486 struct lttng_channel
*chan
;
2487 struct lttng_event
*event
;
2490 if (!READ_ONCE(session
->active
))
2492 if (session
->metadata_dumped
)
2495 snprintf(uuid_s
, sizeof(uuid_s
),
2496 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2497 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
2498 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
2499 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
2500 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
2502 ret
= lttng_metadata_printf(session
,
2503 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
2504 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
2505 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
2506 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
2507 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
2508 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
2509 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
2515 " byte_order = %s;\n"
2516 " packet.header := struct {\n"
2517 " uint32_t magic;\n"
2518 " uint8_t uuid[16];\n"
2519 " uint32_t stream_id;\n"
2520 " uint64_t stream_instance_id;\n"
2523 lttng_alignof(uint8_t) * CHAR_BIT
,
2524 lttng_alignof(uint16_t) * CHAR_BIT
,
2525 lttng_alignof(uint32_t) * CHAR_BIT
,
2526 lttng_alignof(uint64_t) * CHAR_BIT
,
2527 sizeof(unsigned long) * CHAR_BIT
,
2528 lttng_alignof(unsigned long) * CHAR_BIT
,
2532 #if __BYTE_ORDER == __BIG_ENDIAN
2541 ret
= lttng_metadata_printf(session
,
2543 " hostname = \"%s\";\n"
2544 " domain = \"kernel\";\n"
2545 " sysname = \"%s\";\n"
2546 " kernel_release = \"%s\";\n"
2547 " kernel_version = \"%s\";\n"
2548 " tracer_name = \"lttng-modules\";\n"
2549 " tracer_major = %d;\n"
2550 " tracer_minor = %d;\n"
2551 " tracer_patchlevel = %d;\n"
2553 current
->nsproxy
->uts_ns
->name
.nodename
,
2557 LTTNG_MODULES_MAJOR_VERSION
,
2558 LTTNG_MODULES_MINOR_VERSION
,
2559 LTTNG_MODULES_PATCHLEVEL_VERSION
2564 ret
= lttng_metadata_printf(session
,
2566 " name = \"%s\";\n",
2572 if (!trace_clock_uuid(clock_uuid_s
)) {
2573 ret
= lttng_metadata_printf(session
,
2574 " uuid = \"%s\";\n",
2581 ret
= lttng_metadata_printf(session
,
2582 " description = \"%s\";\n"
2583 " freq = %llu; /* Frequency, in Hz */\n"
2584 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
2587 trace_clock_description(),
2588 (unsigned long long) trace_clock_freq(),
2589 (long long) measure_clock_offset()
2594 ret
= lttng_metadata_printf(session
,
2595 "typealias integer {\n"
2596 " size = 27; align = 1; signed = false;\n"
2597 " map = clock.%s.value;\n"
2598 "} := uint27_clock_monotonic_t;\n"
2600 "typealias integer {\n"
2601 " size = 32; align = %u; signed = false;\n"
2602 " map = clock.%s.value;\n"
2603 "} := uint32_clock_monotonic_t;\n"
2605 "typealias integer {\n"
2606 " size = 64; align = %u; signed = false;\n"
2607 " map = clock.%s.value;\n"
2608 "} := uint64_clock_monotonic_t;\n\n",
2610 lttng_alignof(uint32_t) * CHAR_BIT
,
2612 lttng_alignof(uint64_t) * CHAR_BIT
,
2618 ret
= _lttng_stream_packet_context_declare(session
);
2622 ret
= _lttng_event_header_declare(session
);
2627 list_for_each_entry(chan
, &session
->chan
, list
) {
2628 ret
= _lttng_channel_metadata_statedump(session
, chan
);
2633 list_for_each_entry(event
, &session
->events
, list
) {
2634 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
2638 session
->metadata_dumped
= 1;
2644 * lttng_transport_register - LTT transport registration
2645 * @transport: transport structure
2647 * Registers a transport which can be used as output to extract the data out of
2648 * LTTng. The module calling this registration function must ensure that no
2649 * trap-inducing code will be executed by the transport functions. E.g.
2650 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
2651 * is made visible to the transport function. This registration acts as a
2652 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
2653 * after its registration must it synchronize the TLBs.
2655 void lttng_transport_register(struct lttng_transport
*transport
)
2658 * Make sure no page fault can be triggered by the module about to be
2659 * registered. We deal with this here so we don't have to call
2660 * vmalloc_sync_all() in each module's init.
2662 wrapper_vmalloc_sync_all();
2664 mutex_lock(&sessions_mutex
);
2665 list_add_tail(&transport
->node
, <tng_transport_list
);
2666 mutex_unlock(&sessions_mutex
);
2668 EXPORT_SYMBOL_GPL(lttng_transport_register
);
2671 * lttng_transport_unregister - LTT transport unregistration
2672 * @transport: transport structure
2674 void lttng_transport_unregister(struct lttng_transport
*transport
)
2676 mutex_lock(&sessions_mutex
);
2677 list_del(&transport
->node
);
2678 mutex_unlock(&sessions_mutex
);
2680 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
2682 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
2684 enum cpuhp_state lttng_hp_prepare
;
2685 enum cpuhp_state lttng_hp_online
;
2687 static int lttng_hotplug_prepare(unsigned int cpu
, struct hlist_node
*node
)
2689 struct lttng_cpuhp_node
*lttng_node
;
2691 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2692 switch (lttng_node
->component
) {
2693 case LTTNG_RING_BUFFER_FRONTEND
:
2695 case LTTNG_RING_BUFFER_BACKEND
:
2696 return lttng_cpuhp_rb_backend_prepare(cpu
, lttng_node
);
2697 case LTTNG_RING_BUFFER_ITER
:
2699 case LTTNG_CONTEXT_PERF_COUNTERS
:
2706 static int lttng_hotplug_dead(unsigned int cpu
, struct hlist_node
*node
)
2708 struct lttng_cpuhp_node
*lttng_node
;
2710 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2711 switch (lttng_node
->component
) {
2712 case LTTNG_RING_BUFFER_FRONTEND
:
2713 return lttng_cpuhp_rb_frontend_dead(cpu
, lttng_node
);
2714 case LTTNG_RING_BUFFER_BACKEND
:
2716 case LTTNG_RING_BUFFER_ITER
:
2718 case LTTNG_CONTEXT_PERF_COUNTERS
:
2719 return lttng_cpuhp_perf_counter_dead(cpu
, lttng_node
);
2725 static int lttng_hotplug_online(unsigned int cpu
, struct hlist_node
*node
)
2727 struct lttng_cpuhp_node
*lttng_node
;
2729 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2730 switch (lttng_node
->component
) {
2731 case LTTNG_RING_BUFFER_FRONTEND
:
2732 return lttng_cpuhp_rb_frontend_online(cpu
, lttng_node
);
2733 case LTTNG_RING_BUFFER_BACKEND
:
2735 case LTTNG_RING_BUFFER_ITER
:
2736 return lttng_cpuhp_rb_iter_online(cpu
, lttng_node
);
2737 case LTTNG_CONTEXT_PERF_COUNTERS
:
2738 return lttng_cpuhp_perf_counter_online(cpu
, lttng_node
);
2744 static int lttng_hotplug_offline(unsigned int cpu
, struct hlist_node
*node
)
2746 struct lttng_cpuhp_node
*lttng_node
;
2748 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2749 switch (lttng_node
->component
) {
2750 case LTTNG_RING_BUFFER_FRONTEND
:
2751 return lttng_cpuhp_rb_frontend_offline(cpu
, lttng_node
);
2752 case LTTNG_RING_BUFFER_BACKEND
:
2754 case LTTNG_RING_BUFFER_ITER
:
2756 case LTTNG_CONTEXT_PERF_COUNTERS
:
2763 static int __init
lttng_init_cpu_hotplug(void)
2767 ret
= cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN
, "lttng:prepare",
2768 lttng_hotplug_prepare
,
2769 lttng_hotplug_dead
);
2773 lttng_hp_prepare
= ret
;
2774 lttng_rb_set_hp_prepare(ret
);
2776 ret
= cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN
, "lttng:online",
2777 lttng_hotplug_online
,
2778 lttng_hotplug_offline
);
2780 cpuhp_remove_multi_state(lttng_hp_prepare
);
2781 lttng_hp_prepare
= 0;
2784 lttng_hp_online
= ret
;
2785 lttng_rb_set_hp_online(ret
);
2790 static void __exit
lttng_exit_cpu_hotplug(void)
2792 lttng_rb_set_hp_online(0);
2793 cpuhp_remove_multi_state(lttng_hp_online
);
2794 lttng_rb_set_hp_prepare(0);
2795 cpuhp_remove_multi_state(lttng_hp_prepare
);
2798 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2799 static int lttng_init_cpu_hotplug(void)
2803 static void lttng_exit_cpu_hotplug(void)
2806 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2809 static int __init
lttng_events_init(void)
2813 ret
= wrapper_lttng_fixup_sig(THIS_MODULE
);
2816 ret
= wrapper_get_pfnblock_flags_mask_init();
2819 ret
= wrapper_get_pageblock_flags_mask_init();
2822 ret
= lttng_probes_init();
2825 ret
= lttng_context_init();
2828 ret
= lttng_tracepoint_init();
2831 event_cache
= KMEM_CACHE(lttng_event
, 0);
2836 ret
= lttng_abi_init();
2839 ret
= lttng_logger_init();
2842 ret
= lttng_init_cpu_hotplug();
2845 printk(KERN_NOTICE
"LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n",
2846 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2847 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2848 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2849 LTTNG_MODULES_EXTRAVERSION
,
2851 #ifdef LTTNG_EXTRA_VERSION_GIT
2852 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2856 #ifdef LTTNG_EXTRA_VERSION_NAME
2857 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2864 lttng_logger_exit();
2868 kmem_cache_destroy(event_cache
);
2870 lttng_tracepoint_exit();
2872 lttng_context_exit();
2873 printk(KERN_NOTICE
"LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n",
2874 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2875 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2876 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2877 LTTNG_MODULES_EXTRAVERSION
,
2879 #ifdef LTTNG_EXTRA_VERSION_GIT
2880 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2884 #ifdef LTTNG_EXTRA_VERSION_NAME
2885 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2892 module_init(lttng_events_init
);
2894 static void __exit
lttng_events_exit(void)
2896 struct lttng_session
*session
, *tmpsession
;
2898 lttng_exit_cpu_hotplug();
2899 lttng_logger_exit();
2901 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
2902 lttng_session_destroy(session
);
2903 kmem_cache_destroy(event_cache
);
2904 lttng_tracepoint_exit();
2905 lttng_context_exit();
2906 printk(KERN_NOTICE
"LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n",
2907 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2908 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2909 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2910 LTTNG_MODULES_EXTRAVERSION
,
2912 #ifdef LTTNG_EXTRA_VERSION_GIT
2913 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2917 #ifdef LTTNG_EXTRA_VERSION_NAME
2918 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2924 module_exit(lttng_events_exit
);
2926 #include "extra_version/patches.i"
2927 #ifdef LTTNG_EXTRA_VERSION_GIT
2928 MODULE_INFO(extra_version_git
, LTTNG_EXTRA_VERSION_GIT
);
2930 #ifdef LTTNG_EXTRA_VERSION_NAME
2931 MODULE_INFO(extra_version_name
, LTTNG_EXTRA_VERSION_NAME
);
2933 MODULE_LICENSE("GPL and additional rights");
2934 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
2935 MODULE_DESCRIPTION("LTTng Events");
2936 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
2937 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
2938 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
2939 LTTNG_MODULES_EXTRAVERSION
);