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>
30 #include <linux/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/ringbuffer/backend.h>
44 #include <wrapper/ringbuffer/frontend.h>
46 #define METADATA_CACHE_DEFAULT_SIZE 4096
48 static LIST_HEAD(sessions
);
49 static LIST_HEAD(lttng_transport_list
);
51 * Protect the sessions and metadata caches.
53 static DEFINE_MUTEX(sessions_mutex
);
54 static struct kmem_cache
*event_cache
;
56 static void lttng_session_lazy_sync_enablers(struct lttng_session
*session
);
57 static void lttng_session_sync_enablers(struct lttng_session
*session
);
58 static void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
60 static void _lttng_event_destroy(struct lttng_event
*event
);
61 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
62 static int _lttng_event_unregister(struct lttng_event
*event
);
64 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
65 struct lttng_channel
*chan
,
66 struct lttng_event
*event
);
68 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
70 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream
*stream
);
72 int _lttng_field_statedump(struct lttng_session
*session
,
73 const struct lttng_event_field
*field
,
76 void synchronize_trace(void)
78 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
84 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
85 #ifdef CONFIG_PREEMPT_RT_FULL
88 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
89 #ifdef CONFIG_PREEMPT_RT
92 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
95 void lttng_lock_sessions(void)
97 mutex_lock(&sessions_mutex
);
100 void lttng_unlock_sessions(void)
102 mutex_unlock(&sessions_mutex
);
106 * Called with sessions lock held.
108 int lttng_session_active(void)
110 struct lttng_session
*iter
;
112 list_for_each_entry(iter
, &sessions
, list
) {
119 struct lttng_session
*lttng_session_create(void)
121 struct lttng_session
*session
;
122 struct lttng_metadata_cache
*metadata_cache
;
125 mutex_lock(&sessions_mutex
);
126 session
= lttng_kvzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
129 INIT_LIST_HEAD(&session
->chan
);
130 INIT_LIST_HEAD(&session
->events
);
131 uuid_le_gen(&session
->uuid
);
133 metadata_cache
= kzalloc(sizeof(struct lttng_metadata_cache
),
136 goto err_free_session
;
137 metadata_cache
->data
= vzalloc(METADATA_CACHE_DEFAULT_SIZE
);
138 if (!metadata_cache
->data
)
140 metadata_cache
->cache_alloc
= METADATA_CACHE_DEFAULT_SIZE
;
141 kref_init(&metadata_cache
->refcount
);
142 mutex_init(&metadata_cache
->lock
);
143 session
->metadata_cache
= metadata_cache
;
144 INIT_LIST_HEAD(&metadata_cache
->metadata_stream
);
145 memcpy(&metadata_cache
->uuid
, &session
->uuid
,
146 sizeof(metadata_cache
->uuid
));
147 INIT_LIST_HEAD(&session
->enablers_head
);
148 for (i
= 0; i
< LTTNG_EVENT_HT_SIZE
; i
++)
149 INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
150 list_add(&session
->list
, &sessions
);
151 mutex_unlock(&sessions_mutex
);
155 kfree(metadata_cache
);
157 lttng_kvfree(session
);
159 mutex_unlock(&sessions_mutex
);
163 void metadata_cache_destroy(struct kref
*kref
)
165 struct lttng_metadata_cache
*cache
=
166 container_of(kref
, struct lttng_metadata_cache
, refcount
);
171 void lttng_session_destroy(struct lttng_session
*session
)
173 struct lttng_channel
*chan
, *tmpchan
;
174 struct lttng_event
*event
, *tmpevent
;
175 struct lttng_metadata_stream
*metadata_stream
;
176 struct lttng_enabler
*enabler
, *tmpenabler
;
179 mutex_lock(&sessions_mutex
);
180 WRITE_ONCE(session
->active
, 0);
181 list_for_each_entry(chan
, &session
->chan
, list
) {
182 ret
= lttng_syscalls_unregister(chan
);
185 list_for_each_entry(event
, &session
->events
, list
) {
186 ret
= _lttng_event_unregister(event
);
189 synchronize_trace(); /* Wait for in-flight events to complete */
190 list_for_each_entry_safe(enabler
, tmpenabler
,
191 &session
->enablers_head
, node
)
192 lttng_enabler_destroy(enabler
);
193 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
194 _lttng_event_destroy(event
);
195 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
) {
196 BUG_ON(chan
->channel_type
== METADATA_CHANNEL
);
197 _lttng_channel_destroy(chan
);
199 list_for_each_entry(metadata_stream
, &session
->metadata_cache
->metadata_stream
, list
)
200 _lttng_metadata_channel_hangup(metadata_stream
);
201 if (session
->pid_tracker
)
202 lttng_pid_tracker_destroy(session
->pid_tracker
);
203 kref_put(&session
->metadata_cache
->refcount
, metadata_cache_destroy
);
204 list_del(&session
->list
);
205 mutex_unlock(&sessions_mutex
);
206 lttng_kvfree(session
);
209 int lttng_session_statedump(struct lttng_session
*session
)
213 mutex_lock(&sessions_mutex
);
214 ret
= lttng_statedump_start(session
);
215 mutex_unlock(&sessions_mutex
);
219 int lttng_session_enable(struct lttng_session
*session
)
222 struct lttng_channel
*chan
;
224 mutex_lock(&sessions_mutex
);
225 if (session
->active
) {
230 /* Set transient enabler state to "enabled" */
233 /* We need to sync enablers with session before activation. */
234 lttng_session_sync_enablers(session
);
237 * Snapshot the number of events per channel to know the type of header
240 list_for_each_entry(chan
, &session
->chan
, list
) {
241 if (chan
->header_type
)
242 continue; /* don't change it if session stop/restart */
243 if (chan
->free_event_id
< 31)
244 chan
->header_type
= 1; /* compact */
246 chan
->header_type
= 2; /* large */
249 /* Clear each stream's quiescent state. */
250 list_for_each_entry(chan
, &session
->chan
, list
) {
251 if (chan
->channel_type
!= METADATA_CHANNEL
)
252 lib_ring_buffer_clear_quiescent_channel(chan
->chan
);
255 WRITE_ONCE(session
->active
, 1);
256 WRITE_ONCE(session
->been_active
, 1);
257 ret
= _lttng_session_metadata_statedump(session
);
259 WRITE_ONCE(session
->active
, 0);
262 ret
= lttng_statedump_start(session
);
264 WRITE_ONCE(session
->active
, 0);
266 mutex_unlock(&sessions_mutex
);
270 int lttng_session_disable(struct lttng_session
*session
)
273 struct lttng_channel
*chan
;
275 mutex_lock(&sessions_mutex
);
276 if (!session
->active
) {
280 WRITE_ONCE(session
->active
, 0);
282 /* Set transient enabler state to "disabled" */
284 lttng_session_sync_enablers(session
);
286 /* Set each stream's quiescent state. */
287 list_for_each_entry(chan
, &session
->chan
, list
) {
288 if (chan
->channel_type
!= METADATA_CHANNEL
)
289 lib_ring_buffer_set_quiescent_channel(chan
->chan
);
292 mutex_unlock(&sessions_mutex
);
296 int lttng_session_metadata_regenerate(struct lttng_session
*session
)
299 struct lttng_channel
*chan
;
300 struct lttng_event
*event
;
301 struct lttng_metadata_cache
*cache
= session
->metadata_cache
;
302 struct lttng_metadata_stream
*stream
;
304 mutex_lock(&sessions_mutex
);
305 if (!session
->active
) {
310 mutex_lock(&cache
->lock
);
311 memset(cache
->data
, 0, cache
->cache_alloc
);
312 cache
->metadata_written
= 0;
314 list_for_each_entry(stream
, &session
->metadata_cache
->metadata_stream
, list
) {
315 stream
->metadata_out
= 0;
316 stream
->metadata_in
= 0;
318 mutex_unlock(&cache
->lock
);
320 session
->metadata_dumped
= 0;
321 list_for_each_entry(chan
, &session
->chan
, list
) {
322 chan
->metadata_dumped
= 0;
325 list_for_each_entry(event
, &session
->events
, list
) {
326 event
->metadata_dumped
= 0;
329 ret
= _lttng_session_metadata_statedump(session
);
332 mutex_unlock(&sessions_mutex
);
336 int lttng_channel_enable(struct lttng_channel
*channel
)
340 mutex_lock(&sessions_mutex
);
341 if (channel
->channel_type
== METADATA_CHANNEL
) {
345 if (channel
->enabled
) {
349 /* Set transient enabler state to "enabled" */
351 lttng_session_sync_enablers(channel
->session
);
352 /* Set atomically the state to "enabled" */
353 WRITE_ONCE(channel
->enabled
, 1);
355 mutex_unlock(&sessions_mutex
);
359 int lttng_channel_disable(struct lttng_channel
*channel
)
363 mutex_lock(&sessions_mutex
);
364 if (channel
->channel_type
== METADATA_CHANNEL
) {
368 if (!channel
->enabled
) {
372 /* Set atomically the state to "disabled" */
373 WRITE_ONCE(channel
->enabled
, 0);
374 /* Set transient enabler state to "enabled" */
376 lttng_session_sync_enablers(channel
->session
);
378 mutex_unlock(&sessions_mutex
);
382 int lttng_event_enable(struct lttng_event
*event
)
386 mutex_lock(&sessions_mutex
);
387 if (event
->chan
->channel_type
== METADATA_CHANNEL
) {
391 if (event
->enabled
) {
395 switch (event
->instrumentation
) {
396 case LTTNG_KERNEL_TRACEPOINT
:
397 case LTTNG_KERNEL_SYSCALL
:
400 case LTTNG_KERNEL_KPROBE
:
401 case LTTNG_KERNEL_FUNCTION
:
402 case LTTNG_KERNEL_UPROBE
:
403 case LTTNG_KERNEL_NOOP
:
404 WRITE_ONCE(event
->enabled
, 1);
406 case LTTNG_KERNEL_KRETPROBE
:
407 ret
= lttng_kretprobes_event_enable_state(event
, 1);
414 mutex_unlock(&sessions_mutex
);
418 int lttng_event_disable(struct lttng_event
*event
)
422 mutex_lock(&sessions_mutex
);
423 if (event
->chan
->channel_type
== METADATA_CHANNEL
) {
427 if (!event
->enabled
) {
431 switch (event
->instrumentation
) {
432 case LTTNG_KERNEL_TRACEPOINT
:
433 case LTTNG_KERNEL_SYSCALL
:
436 case LTTNG_KERNEL_KPROBE
:
437 case LTTNG_KERNEL_FUNCTION
:
438 case LTTNG_KERNEL_UPROBE
:
439 case LTTNG_KERNEL_NOOP
:
440 WRITE_ONCE(event
->enabled
, 0);
442 case LTTNG_KERNEL_KRETPROBE
:
443 ret
= lttng_kretprobes_event_enable_state(event
, 0);
450 mutex_unlock(&sessions_mutex
);
454 static struct lttng_transport
*lttng_transport_find(const char *name
)
456 struct lttng_transport
*transport
;
458 list_for_each_entry(transport
, <tng_transport_list
, node
) {
459 if (!strcmp(transport
->name
, name
))
465 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
466 const char *transport_name
,
468 size_t subbuf_size
, size_t num_subbuf
,
469 unsigned int switch_timer_interval
,
470 unsigned int read_timer_interval
,
471 enum channel_type channel_type
)
473 struct lttng_channel
*chan
;
474 struct lttng_transport
*transport
= NULL
;
476 mutex_lock(&sessions_mutex
);
477 if (session
->been_active
&& channel_type
!= METADATA_CHANNEL
)
478 goto active
; /* Refuse to add channel to active session */
479 transport
= lttng_transport_find(transport_name
);
481 printk(KERN_WARNING
"LTTng transport %s not found\n",
485 if (!try_module_get(transport
->owner
)) {
486 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
489 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
492 chan
->session
= session
;
493 chan
->id
= session
->free_chan_id
++;
494 chan
->ops
= &transport
->ops
;
496 * Note: the channel creation op already writes into the packet
497 * headers. Therefore the "chan" information used as input
498 * should be already accessible.
500 chan
->chan
= transport
->ops
.channel_create(transport_name
,
501 chan
, buf_addr
, subbuf_size
, num_subbuf
,
502 switch_timer_interval
, read_timer_interval
);
507 chan
->transport
= transport
;
508 chan
->channel_type
= channel_type
;
509 list_add(&chan
->list
, &session
->chan
);
510 mutex_unlock(&sessions_mutex
);
517 module_put(transport
->owner
);
520 mutex_unlock(&sessions_mutex
);
525 * Only used internally at session destruction for per-cpu channels, and
526 * when metadata channel is released.
527 * Needs to be called with sessions mutex held.
530 void _lttng_channel_destroy(struct lttng_channel
*chan
)
532 chan
->ops
->channel_destroy(chan
->chan
);
533 module_put(chan
->transport
->owner
);
534 list_del(&chan
->list
);
535 lttng_destroy_context(chan
->ctx
);
539 void lttng_metadata_channel_destroy(struct lttng_channel
*chan
)
541 BUG_ON(chan
->channel_type
!= METADATA_CHANNEL
);
543 /* Protect the metadata cache with the sessions_mutex. */
544 mutex_lock(&sessions_mutex
);
545 _lttng_channel_destroy(chan
);
546 mutex_unlock(&sessions_mutex
);
548 EXPORT_SYMBOL_GPL(lttng_metadata_channel_destroy
);
551 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream
*stream
)
553 stream
->finalized
= 1;
554 wake_up_interruptible(&stream
->read_wait
);
558 * Supports event creation while tracing session is active.
559 * Needs to be called with sessions mutex held.
561 struct lttng_event
*_lttng_event_create(struct lttng_channel
*chan
,
562 struct lttng_kernel_event
*event_param
,
564 const struct lttng_event_desc
*event_desc
,
565 enum lttng_kernel_instrumentation itype
)
567 struct lttng_session
*session
= chan
->session
;
568 struct lttng_event
*event
;
569 const char *event_name
;
570 struct hlist_head
*head
;
575 if (chan
->free_event_id
== -1U) {
581 case LTTNG_KERNEL_TRACEPOINT
:
582 event_name
= event_desc
->name
;
584 case LTTNG_KERNEL_KPROBE
:
585 case LTTNG_KERNEL_UPROBE
:
586 case LTTNG_KERNEL_KRETPROBE
:
587 case LTTNG_KERNEL_FUNCTION
:
588 case LTTNG_KERNEL_NOOP
:
589 case LTTNG_KERNEL_SYSCALL
:
590 event_name
= event_param
->name
;
597 name_len
= strlen(event_name
);
598 hash
= jhash(event_name
, name_len
, 0);
599 head
= &session
->events_ht
.table
[hash
& (LTTNG_EVENT_HT_SIZE
- 1)];
600 lttng_hlist_for_each_entry(event
, head
, hlist
) {
601 WARN_ON_ONCE(!event
->desc
);
602 if (!strncmp(event
->desc
->name
, event_name
,
603 LTTNG_KERNEL_SYM_NAME_LEN
- 1)
604 && chan
== event
->chan
) {
610 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
616 event
->filter
= filter
;
617 event
->id
= chan
->free_event_id
++;
618 event
->instrumentation
= itype
;
619 event
->evtype
= LTTNG_TYPE_EVENT
;
620 INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
621 INIT_LIST_HEAD(&event
->enablers_ref_head
);
624 case LTTNG_KERNEL_TRACEPOINT
:
625 /* Event will be enabled by enabler sync. */
627 event
->registered
= 0;
628 event
->desc
= lttng_event_get(event_name
);
633 /* Populate lttng_event structure before event registration. */
636 case LTTNG_KERNEL_KPROBE
:
638 * Needs to be explicitly enabled after creation, since
639 * we may want to apply filters.
642 event
->registered
= 1;
644 * Populate lttng_event structure before event
648 ret
= lttng_kprobes_register(event_name
,
649 event_param
->u
.kprobe
.symbol_name
,
650 event_param
->u
.kprobe
.offset
,
651 event_param
->u
.kprobe
.addr
,
657 ret
= try_module_get(event
->desc
->owner
);
660 case LTTNG_KERNEL_KRETPROBE
:
662 struct lttng_event
*event_return
;
664 /* kretprobe defines 2 events */
666 * Needs to be explicitly enabled after creation, since
667 * we may want to apply filters.
670 event
->registered
= 1;
672 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
677 event_return
->chan
= chan
;
678 event_return
->filter
= filter
;
679 event_return
->id
= chan
->free_event_id
++;
680 event_return
->enabled
= 0;
681 event_return
->registered
= 1;
682 event_return
->instrumentation
= itype
;
684 * Populate lttng_event structure before kretprobe registration.
687 ret
= lttng_kretprobes_register(event_name
,
688 event_param
->u
.kretprobe
.symbol_name
,
689 event_param
->u
.kretprobe
.offset
,
690 event_param
->u
.kretprobe
.addr
,
691 event
, event_return
);
693 kmem_cache_free(event_cache
, event_return
);
697 /* Take 2 refs on the module: one per event. */
698 ret
= try_module_get(event
->desc
->owner
);
700 ret
= try_module_get(event
->desc
->owner
);
702 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
704 WARN_ON_ONCE(ret
> 0);
706 kmem_cache_free(event_cache
, event_return
);
707 module_put(event
->desc
->owner
);
708 module_put(event
->desc
->owner
);
709 goto statedump_error
;
711 list_add(&event_return
->list
, &chan
->session
->events
);
714 case LTTNG_KERNEL_FUNCTION
:
716 * Needs to be explicitly enabled after creation, since
717 * we may want to apply filters.
720 event
->registered
= 1;
722 * Populate lttng_event structure before event
726 ret
= lttng_ftrace_register(event_name
,
727 event_param
->u
.ftrace
.symbol_name
,
732 ret
= try_module_get(event
->desc
->owner
);
735 case LTTNG_KERNEL_NOOP
:
736 case LTTNG_KERNEL_SYSCALL
:
738 * Needs to be explicitly enabled after creation, since
739 * we may want to apply filters.
742 event
->registered
= 0;
743 event
->desc
= event_desc
;
749 case LTTNG_KERNEL_UPROBE
:
751 * Needs to be explicitly enabled after creation, since
752 * we may want to apply filters.
755 event
->registered
= 1;
758 * Populate lttng_event structure before event
763 ret
= lttng_uprobes_register(event_param
->name
,
764 event_param
->u
.uprobe
.fd
,
768 ret
= try_module_get(event
->desc
->owner
);
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_UPROBE
:
834 case LTTNG_KERNEL_KRETPROBE
:
835 case LTTNG_KERNEL_FUNCTION
:
836 case LTTNG_KERNEL_NOOP
:
843 event
->registered
= 1;
847 * Only used internally at session destruction.
849 int _lttng_event_unregister(struct lttng_event
*event
)
851 const struct lttng_event_desc
*desc
;
854 if (!event
->registered
)
858 switch (event
->instrumentation
) {
859 case LTTNG_KERNEL_TRACEPOINT
:
860 ret
= lttng_wrapper_tracepoint_probe_unregister(event
->desc
->kname
,
861 event
->desc
->probe_callback
,
864 case LTTNG_KERNEL_KPROBE
:
865 lttng_kprobes_unregister(event
);
868 case LTTNG_KERNEL_KRETPROBE
:
869 lttng_kretprobes_unregister(event
);
872 case LTTNG_KERNEL_FUNCTION
:
873 lttng_ftrace_unregister(event
);
876 case LTTNG_KERNEL_SYSCALL
:
877 ret
= lttng_syscall_filter_disable(event
->chan
,
880 case LTTNG_KERNEL_NOOP
:
883 case LTTNG_KERNEL_UPROBE
:
884 lttng_uprobes_unregister(event
);
891 event
->registered
= 0;
896 * Only used internally at session destruction.
899 void _lttng_event_destroy(struct lttng_event
*event
)
901 switch (event
->instrumentation
) {
902 case LTTNG_KERNEL_TRACEPOINT
:
903 lttng_event_put(event
->desc
);
905 case LTTNG_KERNEL_KPROBE
:
906 module_put(event
->desc
->owner
);
907 lttng_kprobes_destroy_private(event
);
909 case LTTNG_KERNEL_KRETPROBE
:
910 module_put(event
->desc
->owner
);
911 lttng_kretprobes_destroy_private(event
);
913 case LTTNG_KERNEL_FUNCTION
:
914 module_put(event
->desc
->owner
);
915 lttng_ftrace_destroy_private(event
);
917 case LTTNG_KERNEL_NOOP
:
918 case LTTNG_KERNEL_SYSCALL
:
920 case LTTNG_KERNEL_UPROBE
:
921 module_put(event
->desc
->owner
);
922 lttng_uprobes_destroy_private(event
);
927 list_del(&event
->list
);
928 lttng_destroy_context(event
->ctx
);
929 kmem_cache_free(event_cache
, event
);
932 int lttng_session_track_pid(struct lttng_session
*session
, int pid
)
938 mutex_lock(&sessions_mutex
);
940 /* track all pids: destroy tracker. */
941 if (session
->pid_tracker
) {
942 struct lttng_pid_tracker
*lpf
;
944 lpf
= session
->pid_tracker
;
945 rcu_assign_pointer(session
->pid_tracker
, NULL
);
947 lttng_pid_tracker_destroy(lpf
);
951 if (!session
->pid_tracker
) {
952 struct lttng_pid_tracker
*lpf
;
954 lpf
= lttng_pid_tracker_create();
959 ret
= lttng_pid_tracker_add(lpf
, pid
);
960 rcu_assign_pointer(session
->pid_tracker
, lpf
);
962 ret
= lttng_pid_tracker_add(session
->pid_tracker
, pid
);
966 mutex_unlock(&sessions_mutex
);
970 int lttng_session_untrack_pid(struct lttng_session
*session
, int pid
)
976 mutex_lock(&sessions_mutex
);
978 /* untrack all pids: replace by empty tracker. */
979 struct lttng_pid_tracker
*old_lpf
= session
->pid_tracker
;
980 struct lttng_pid_tracker
*lpf
;
982 lpf
= lttng_pid_tracker_create();
987 rcu_assign_pointer(session
->pid_tracker
, lpf
);
990 lttng_pid_tracker_destroy(old_lpf
);
993 if (!session
->pid_tracker
) {
997 ret
= lttng_pid_tracker_del(session
->pid_tracker
, pid
);
1000 mutex_unlock(&sessions_mutex
);
1005 void *pid_list_start(struct seq_file
*m
, loff_t
*pos
)
1007 struct lttng_session
*session
= m
->private;
1008 struct lttng_pid_tracker
*lpf
;
1009 struct lttng_pid_hash_node
*e
;
1012 mutex_lock(&sessions_mutex
);
1013 lpf
= session
->pid_tracker
;
1015 for (i
= 0; i
< LTTNG_PID_TABLE_SIZE
; i
++) {
1016 struct hlist_head
*head
= &lpf
->pid_hash
[i
];
1018 lttng_hlist_for_each_entry(e
, head
, hlist
) {
1024 /* PID tracker disabled. */
1025 if (iter
>= *pos
&& iter
== 0) {
1026 return session
; /* empty tracker */
1034 /* Called with sessions_mutex held. */
1036 void *pid_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1038 struct lttng_session
*session
= m
->private;
1039 struct lttng_pid_tracker
*lpf
;
1040 struct lttng_pid_hash_node
*e
;
1044 lpf
= session
->pid_tracker
;
1046 for (i
= 0; i
< LTTNG_PID_TABLE_SIZE
; i
++) {
1047 struct hlist_head
*head
= &lpf
->pid_hash
[i
];
1049 lttng_hlist_for_each_entry(e
, head
, hlist
) {
1050 if (iter
++ >= *ppos
)
1055 /* PID tracker disabled. */
1056 if (iter
>= *ppos
&& iter
== 0)
1057 return session
; /* empty tracker */
1066 void pid_list_stop(struct seq_file
*m
, void *p
)
1068 mutex_unlock(&sessions_mutex
);
1072 int pid_list_show(struct seq_file
*m
, void *p
)
1076 if (p
== m
->private) {
1077 /* Tracker disabled. */
1080 const struct lttng_pid_hash_node
*e
= p
;
1082 pid
= lttng_pid_tracker_get_node_pid(e
);
1084 seq_printf(m
, "process { pid = %d; };\n", pid
);
1089 const struct seq_operations lttng_tracker_pids_list_seq_ops
= {
1090 .start
= pid_list_start
,
1091 .next
= pid_list_next
,
1092 .stop
= pid_list_stop
,
1093 .show
= pid_list_show
,
1097 int lttng_tracker_pids_list_open(struct inode
*inode
, struct file
*file
)
1099 return seq_open(file
, <tng_tracker_pids_list_seq_ops
);
1103 int lttng_tracker_pids_list_release(struct inode
*inode
, struct file
*file
)
1105 struct seq_file
*m
= file
->private_data
;
1106 struct lttng_session
*session
= m
->private;
1109 WARN_ON_ONCE(!session
);
1110 ret
= seq_release(inode
, file
);
1111 if (!ret
&& session
)
1112 fput(session
->file
);
1116 const struct file_operations lttng_tracker_pids_list_fops
= {
1117 .owner
= THIS_MODULE
,
1118 .open
= lttng_tracker_pids_list_open
,
1120 .llseek
= seq_lseek
,
1121 .release
= lttng_tracker_pids_list_release
,
1124 int lttng_session_list_tracker_pids(struct lttng_session
*session
)
1126 struct file
*tracker_pids_list_file
;
1130 file_fd
= lttng_get_unused_fd();
1136 tracker_pids_list_file
= anon_inode_getfile("[lttng_tracker_pids_list]",
1137 <tng_tracker_pids_list_fops
,
1139 if (IS_ERR(tracker_pids_list_file
)) {
1140 ret
= PTR_ERR(tracker_pids_list_file
);
1143 if (!atomic_long_add_unless(&session
->file
->f_count
, 1, LONG_MAX
)) {
1145 goto refcount_error
;
1147 ret
= lttng_tracker_pids_list_fops
.open(NULL
, tracker_pids_list_file
);
1150 m
= tracker_pids_list_file
->private_data
;
1151 m
->private = session
;
1152 fd_install(file_fd
, tracker_pids_list_file
);
1157 atomic_long_dec(&session
->file
->f_count
);
1159 fput(tracker_pids_list_file
);
1161 put_unused_fd(file_fd
);
1167 * Enabler management.
1170 int lttng_match_enabler_star_glob(const char *desc_name
,
1171 const char *pattern
)
1173 if (!strutils_star_glob_match(pattern
, LTTNG_SIZE_MAX
,
1174 desc_name
, LTTNG_SIZE_MAX
))
1180 int lttng_match_enabler_name(const char *desc_name
,
1183 if (strcmp(desc_name
, name
))
1189 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
1190 struct lttng_enabler
*enabler
)
1192 const char *desc_name
, *enabler_name
;
1194 enabler_name
= enabler
->event_param
.name
;
1195 switch (enabler
->event_param
.instrumentation
) {
1196 case LTTNG_KERNEL_TRACEPOINT
:
1197 desc_name
= desc
->name
;
1199 case LTTNG_KERNEL_SYSCALL
:
1200 desc_name
= desc
->name
;
1201 if (!strncmp(desc_name
, "compat_", strlen("compat_")))
1202 desc_name
+= strlen("compat_");
1203 if (!strncmp(desc_name
, "syscall_exit_",
1204 strlen("syscall_exit_"))) {
1205 desc_name
+= strlen("syscall_exit_");
1206 } else if (!strncmp(desc_name
, "syscall_entry_",
1207 strlen("syscall_entry_"))) {
1208 desc_name
+= strlen("syscall_entry_");
1218 switch (enabler
->type
) {
1219 case LTTNG_ENABLER_STAR_GLOB
:
1220 return lttng_match_enabler_star_glob(desc_name
, enabler_name
);
1221 case LTTNG_ENABLER_NAME
:
1222 return lttng_match_enabler_name(desc_name
, enabler_name
);
1229 int lttng_event_match_enabler(struct lttng_event
*event
,
1230 struct lttng_enabler
*enabler
)
1232 if (enabler
->event_param
.instrumentation
!= event
->instrumentation
)
1234 if (lttng_desc_match_enabler(event
->desc
, enabler
)
1235 && event
->chan
== enabler
->chan
)
1242 struct lttng_enabler_ref
*lttng_event_enabler_ref(struct lttng_event
*event
,
1243 struct lttng_enabler
*enabler
)
1245 struct lttng_enabler_ref
*enabler_ref
;
1247 list_for_each_entry(enabler_ref
,
1248 &event
->enablers_ref_head
, node
) {
1249 if (enabler_ref
->ref
== enabler
)
1256 void lttng_create_tracepoint_if_missing(struct lttng_enabler
*enabler
)
1258 struct lttng_session
*session
= enabler
->chan
->session
;
1259 struct lttng_probe_desc
*probe_desc
;
1260 const struct lttng_event_desc
*desc
;
1262 struct list_head
*probe_list
;
1264 probe_list
= lttng_get_probe_list_head();
1266 * For each probe event, if we find that a probe event matches
1267 * our enabler, create an associated lttng_event if not
1270 list_for_each_entry(probe_desc
, probe_list
, head
) {
1271 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1273 struct hlist_head
*head
;
1274 const char *event_name
;
1277 struct lttng_event
*event
;
1279 desc
= probe_desc
->event_desc
[i
];
1280 if (!lttng_desc_match_enabler(desc
, enabler
))
1282 event_name
= desc
->name
;
1283 name_len
= strlen(event_name
);
1286 * Check if already created.
1288 hash
= jhash(event_name
, name_len
, 0);
1289 head
= &session
->events_ht
.table
[hash
& (LTTNG_EVENT_HT_SIZE
- 1)];
1290 lttng_hlist_for_each_entry(event
, head
, hlist
) {
1291 if (event
->desc
== desc
1292 && event
->chan
== enabler
->chan
)
1299 * We need to create an event for this
1302 event
= _lttng_event_create(enabler
->chan
,
1304 LTTNG_KERNEL_TRACEPOINT
);
1306 printk(KERN_INFO
"Unable to create event %s\n",
1307 probe_desc
->event_desc
[i
]->name
);
1314 void lttng_create_syscall_if_missing(struct lttng_enabler
*enabler
)
1318 ret
= lttng_syscalls_register(enabler
->chan
, NULL
);
1323 * Create struct lttng_event if it is missing and present in the list of
1324 * tracepoint probes.
1325 * Should be called with sessions mutex held.
1328 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
1330 switch (enabler
->event_param
.instrumentation
) {
1331 case LTTNG_KERNEL_TRACEPOINT
:
1332 lttng_create_tracepoint_if_missing(enabler
);
1334 case LTTNG_KERNEL_SYSCALL
:
1335 lttng_create_syscall_if_missing(enabler
);
1344 * Create events associated with an enabler (if not already present),
1345 * and add backward reference from the event to the enabler.
1346 * Should be called with sessions mutex held.
1349 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
1351 struct lttng_session
*session
= enabler
->chan
->session
;
1352 struct lttng_event
*event
;
1354 /* First ensure that probe events are created for this enabler. */
1355 lttng_create_event_if_missing(enabler
);
1357 /* For each event matching enabler in session event list. */
1358 list_for_each_entry(event
, &session
->events
, list
) {
1359 struct lttng_enabler_ref
*enabler_ref
;
1361 if (!lttng_event_match_enabler(event
, enabler
))
1363 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
1366 * If no backward ref, create it.
1367 * Add backward ref from event to enabler.
1369 enabler_ref
= kzalloc(sizeof(*enabler_ref
), GFP_KERNEL
);
1372 enabler_ref
->ref
= enabler
;
1373 list_add(&enabler_ref
->node
,
1374 &event
->enablers_ref_head
);
1378 * Link filter bytecodes if not linked yet.
1380 lttng_enabler_event_link_bytecode(event
, enabler
);
1382 /* TODO: merge event context. */
1388 * Called at module load: connect the probe on all enablers matching
1390 * Called with sessions lock held.
1392 int lttng_fix_pending_events(void)
1394 struct lttng_session
*session
;
1396 list_for_each_entry(session
, &sessions
, list
)
1397 lttng_session_lazy_sync_enablers(session
);
1401 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
1402 struct lttng_kernel_event
*event_param
,
1403 struct lttng_channel
*chan
)
1405 struct lttng_enabler
*enabler
;
1407 enabler
= kzalloc(sizeof(*enabler
), GFP_KERNEL
);
1410 enabler
->type
= type
;
1411 INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
1412 memcpy(&enabler
->event_param
, event_param
,
1413 sizeof(enabler
->event_param
));
1414 enabler
->chan
= chan
;
1416 enabler
->enabled
= 0;
1417 enabler
->evtype
= LTTNG_TYPE_ENABLER
;
1418 mutex_lock(&sessions_mutex
);
1419 list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
1420 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1421 mutex_unlock(&sessions_mutex
);
1425 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
1427 mutex_lock(&sessions_mutex
);
1428 enabler
->enabled
= 1;
1429 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1430 mutex_unlock(&sessions_mutex
);
1434 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
1436 mutex_lock(&sessions_mutex
);
1437 enabler
->enabled
= 0;
1438 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1439 mutex_unlock(&sessions_mutex
);
1443 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
1444 struct lttng_kernel_filter_bytecode __user
*bytecode
)
1446 struct lttng_filter_bytecode_node
*bytecode_node
;
1447 uint32_t bytecode_len
;
1450 ret
= get_user(bytecode_len
, &bytecode
->len
);
1453 bytecode_node
= kzalloc(sizeof(*bytecode_node
) + bytecode_len
,
1457 ret
= copy_from_user(&bytecode_node
->bc
, bytecode
,
1458 sizeof(*bytecode
) + bytecode_len
);
1461 bytecode_node
->enabler
= enabler
;
1462 /* Enforce length based on allocated size */
1463 bytecode_node
->bc
.len
= bytecode_len
;
1464 list_add_tail(&bytecode_node
->node
, &enabler
->filter_bytecode_head
);
1465 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1469 kfree(bytecode_node
);
1473 int lttng_event_add_callsite(struct lttng_event
*event
,
1474 struct lttng_kernel_event_callsite __user
*callsite
)
1477 switch (event
->instrumentation
) {
1478 case LTTNG_KERNEL_UPROBE
:
1479 return lttng_uprobes_add_callsite(event
, callsite
);
1485 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1486 struct lttng_kernel_context
*context_param
)
1492 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1494 struct lttng_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1496 /* Destroy filter bytecode */
1497 list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1498 &enabler
->filter_bytecode_head
, node
) {
1502 /* Destroy contexts */
1503 lttng_destroy_context(enabler
->ctx
);
1505 list_del(&enabler
->node
);
1510 * lttng_session_sync_enablers should be called just before starting a
1512 * Should be called with sessions mutex held.
1515 void lttng_session_sync_enablers(struct lttng_session
*session
)
1517 struct lttng_enabler
*enabler
;
1518 struct lttng_event
*event
;
1520 list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1521 lttng_enabler_ref_events(enabler
);
1523 * For each event, if at least one of its enablers is enabled,
1524 * and its channel and session transient states are enabled, we
1525 * enable the event, else we disable it.
1527 list_for_each_entry(event
, &session
->events
, list
) {
1528 struct lttng_enabler_ref
*enabler_ref
;
1529 struct lttng_bytecode_runtime
*runtime
;
1530 int enabled
= 0, has_enablers_without_bytecode
= 0;
1532 switch (event
->instrumentation
) {
1533 case LTTNG_KERNEL_TRACEPOINT
:
1534 case LTTNG_KERNEL_SYSCALL
:
1536 list_for_each_entry(enabler_ref
,
1537 &event
->enablers_ref_head
, node
) {
1538 if (enabler_ref
->ref
->enabled
) {
1545 /* Not handled with lazy sync. */
1549 * Enabled state is based on union of enablers, with
1550 * intesection of session and channel transient enable
1553 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1555 WRITE_ONCE(event
->enabled
, enabled
);
1557 * Sync tracepoint registration with event enabled
1561 register_event(event
);
1563 _lttng_event_unregister(event
);
1566 /* Check if has enablers without bytecode enabled */
1567 list_for_each_entry(enabler_ref
,
1568 &event
->enablers_ref_head
, node
) {
1569 if (enabler_ref
->ref
->enabled
1570 && list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1571 has_enablers_without_bytecode
= 1;
1575 event
->has_enablers_without_bytecode
=
1576 has_enablers_without_bytecode
;
1578 /* Enable filters */
1579 list_for_each_entry(runtime
,
1580 &event
->bytecode_runtime_head
, node
)
1581 lttng_filter_sync_state(runtime
);
1586 * Apply enablers to session events, adding events to session if need
1587 * be. It is required after each modification applied to an active
1588 * session, and right before session "start".
1589 * "lazy" sync means we only sync if required.
1590 * Should be called with sessions mutex held.
1593 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1595 /* We can skip if session is not active */
1596 if (!session
->active
)
1598 lttng_session_sync_enablers(session
);
1602 * Serialize at most one packet worth of metadata into a metadata
1604 * We grab the metadata cache mutex to get exclusive access to our metadata
1605 * buffer and to the metadata cache. Exclusive access to the metadata buffer
1606 * allows us to do racy operations such as looking for remaining space left in
1607 * packet and write, since mutual exclusion protects us from concurrent writes.
1608 * Mutual exclusion on the metadata cache allow us to read the cache content
1609 * without racing against reallocation of the cache by updates.
1610 * Returns the number of bytes written in the channel, 0 if no data
1611 * was written and a negative value on error.
1613 int lttng_metadata_output_channel(struct lttng_metadata_stream
*stream
,
1614 struct channel
*chan
)
1616 struct lib_ring_buffer_ctx ctx
;
1618 size_t len
, reserve_len
;
1621 * Ensure we support mutiple get_next / put sequences followed by
1622 * put_next. The metadata cache lock protects reading the metadata
1623 * cache. It can indeed be read concurrently by "get_next_subbuf" and
1624 * "flush" operations on the buffer invoked by different processes.
1625 * Moreover, since the metadata cache memory can be reallocated, we
1626 * need to have exclusive access against updates even though we only
1629 mutex_lock(&stream
->metadata_cache
->lock
);
1630 WARN_ON(stream
->metadata_in
< stream
->metadata_out
);
1631 if (stream
->metadata_in
!= stream
->metadata_out
)
1634 /* Metadata regenerated, change the version. */
1635 if (stream
->metadata_cache
->version
!= stream
->version
)
1636 stream
->version
= stream
->metadata_cache
->version
;
1638 len
= stream
->metadata_cache
->metadata_written
-
1639 stream
->metadata_in
;
1642 reserve_len
= min_t(size_t,
1643 stream
->transport
->ops
.packet_avail_size(chan
),
1645 lib_ring_buffer_ctx_init(&ctx
, chan
, NULL
, reserve_len
,
1648 * If reservation failed, return an error to the caller.
1650 ret
= stream
->transport
->ops
.event_reserve(&ctx
, 0);
1652 printk(KERN_WARNING
"LTTng: Metadata event reservation failed\n");
1655 stream
->transport
->ops
.event_write(&ctx
,
1656 stream
->metadata_cache
->data
+ stream
->metadata_in
,
1658 stream
->transport
->ops
.event_commit(&ctx
);
1659 stream
->metadata_in
+= reserve_len
;
1663 mutex_unlock(&stream
->metadata_cache
->lock
);
1668 * Write the metadata to the metadata cache.
1669 * Must be called with sessions_mutex held.
1670 * The metadata cache lock protects us from concurrent read access from
1671 * thread outputting metadata content to ring buffer.
1673 int lttng_metadata_printf(struct lttng_session
*session
,
1674 const char *fmt
, ...)
1679 struct lttng_metadata_stream
*stream
;
1681 WARN_ON_ONCE(!READ_ONCE(session
->active
));
1684 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
1690 mutex_lock(&session
->metadata_cache
->lock
);
1691 if (session
->metadata_cache
->metadata_written
+ len
>
1692 session
->metadata_cache
->cache_alloc
) {
1693 char *tmp_cache_realloc
;
1694 unsigned int tmp_cache_alloc_size
;
1696 tmp_cache_alloc_size
= max_t(unsigned int,
1697 session
->metadata_cache
->cache_alloc
+ len
,
1698 session
->metadata_cache
->cache_alloc
<< 1);
1699 tmp_cache_realloc
= vzalloc(tmp_cache_alloc_size
);
1700 if (!tmp_cache_realloc
)
1702 if (session
->metadata_cache
->data
) {
1703 memcpy(tmp_cache_realloc
,
1704 session
->metadata_cache
->data
,
1705 session
->metadata_cache
->cache_alloc
);
1706 vfree(session
->metadata_cache
->data
);
1709 session
->metadata_cache
->cache_alloc
= tmp_cache_alloc_size
;
1710 session
->metadata_cache
->data
= tmp_cache_realloc
;
1712 memcpy(session
->metadata_cache
->data
+
1713 session
->metadata_cache
->metadata_written
,
1715 session
->metadata_cache
->metadata_written
+= len
;
1716 mutex_unlock(&session
->metadata_cache
->lock
);
1719 list_for_each_entry(stream
, &session
->metadata_cache
->metadata_stream
, list
)
1720 wake_up_interruptible(&stream
->read_wait
);
1725 mutex_unlock(&session
->metadata_cache
->lock
);
1731 int print_tabs(struct lttng_session
*session
, size_t nesting
)
1735 for (i
= 0; i
< nesting
; i
++) {
1738 ret
= lttng_metadata_printf(session
, " ");
1747 * Must be called with sessions_mutex held.
1750 int _lttng_struct_type_statedump(struct lttng_session
*session
,
1751 const struct lttng_type
*type
,
1755 uint32_t i
, nr_fields
;
1757 ret
= print_tabs(session
, nesting
);
1760 ret
= lttng_metadata_printf(session
,
1764 nr_fields
= type
->u
._struct
.nr_fields
;
1765 for (i
= 0; i
< nr_fields
; i
++) {
1766 const struct lttng_event_field
*iter_field
;
1768 iter_field
= &type
->u
._struct
.fields
[i
];
1769 ret
= _lttng_field_statedump(session
, iter_field
, nesting
+ 1);
1773 ret
= print_tabs(session
, nesting
);
1776 ret
= lttng_metadata_printf(session
,
1782 * Must be called with sessions_mutex held.
1785 int _lttng_struct_statedump(struct lttng_session
*session
,
1786 const struct lttng_event_field
*field
,
1791 ret
= _lttng_struct_type_statedump(session
,
1792 &field
->type
, nesting
);
1795 ret
= lttng_metadata_printf(session
,
1802 * Must be called with sessions_mutex held.
1805 int _lttng_variant_type_statedump(struct lttng_session
*session
,
1806 const struct lttng_type
*type
,
1810 uint32_t i
, nr_choices
;
1812 ret
= print_tabs(session
, nesting
);
1815 ret
= lttng_metadata_printf(session
,
1816 "variant <_%s> {\n",
1817 type
->u
.variant
.tag_name
);
1820 nr_choices
= type
->u
.variant
.nr_choices
;
1821 for (i
= 0; i
< nr_choices
; i
++) {
1822 const struct lttng_event_field
*iter_field
;
1824 iter_field
= &type
->u
.variant
.choices
[i
];
1825 ret
= _lttng_field_statedump(session
, iter_field
, nesting
+ 1);
1829 ret
= print_tabs(session
, nesting
);
1832 ret
= lttng_metadata_printf(session
,
1838 * Must be called with sessions_mutex held.
1841 int _lttng_variant_statedump(struct lttng_session
*session
,
1842 const struct lttng_event_field
*field
,
1847 ret
= _lttng_variant_type_statedump(session
,
1848 &field
->type
, nesting
);
1851 ret
= lttng_metadata_printf(session
,
1858 * Must be called with sessions_mutex held.
1861 int _lttng_array_compound_statedump(struct lttng_session
*session
,
1862 const struct lttng_event_field
*field
,
1866 const struct lttng_type
*elem_type
;
1868 /* Only array of structures and variants are currently supported. */
1869 elem_type
= field
->type
.u
.array_compound
.elem_type
;
1870 switch (elem_type
->atype
) {
1872 ret
= _lttng_struct_type_statedump(session
, elem_type
, nesting
);
1877 ret
= _lttng_variant_type_statedump(session
, elem_type
, nesting
);
1884 ret
= lttng_metadata_printf(session
,
1887 field
->type
.u
.array_compound
.length
);
1892 * Must be called with sessions_mutex held.
1895 int _lttng_sequence_compound_statedump(struct lttng_session
*session
,
1896 const struct lttng_event_field
*field
,
1900 const char *length_name
;
1901 const struct lttng_type
*elem_type
;
1903 length_name
= field
->type
.u
.sequence_compound
.length_name
;
1905 /* Only array of structures and variants are currently supported. */
1906 elem_type
= field
->type
.u
.sequence_compound
.elem_type
;
1907 switch (elem_type
->atype
) {
1909 ret
= _lttng_struct_type_statedump(session
, elem_type
, nesting
);
1914 ret
= _lttng_variant_type_statedump(session
, elem_type
, nesting
);
1921 ret
= lttng_metadata_printf(session
,
1929 * Must be called with sessions_mutex held.
1932 int _lttng_enum_statedump(struct lttng_session
*session
,
1933 const struct lttng_event_field
*field
,
1936 const struct lttng_enum_desc
*enum_desc
;
1937 const struct lttng_integer_type
*container_type
;
1939 unsigned int i
, nr_entries
;
1941 enum_desc
= field
->type
.u
.basic
.enumeration
.desc
;
1942 container_type
= &field
->type
.u
.basic
.enumeration
.container_type
;
1943 nr_entries
= enum_desc
->nr_entries
;
1945 ret
= print_tabs(session
, nesting
);
1948 ret
= lttng_metadata_printf(session
,
1949 "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n",
1950 container_type
->size
,
1951 container_type
->alignment
,
1952 container_type
->signedness
,
1953 (container_type
->encoding
== lttng_encode_none
)
1955 : (container_type
->encoding
== lttng_encode_UTF8
)
1958 container_type
->base
,
1959 #if __BYTE_ORDER == __BIG_ENDIAN
1960 container_type
->reverse_byte_order
? " byte_order = le;" : ""
1962 container_type
->reverse_byte_order
? " byte_order = be;" : ""
1967 /* Dump all entries */
1968 for (i
= 0; i
< nr_entries
; i
++) {
1969 const struct lttng_enum_entry
*entry
= &enum_desc
->entries
[i
];
1972 ret
= print_tabs(session
, nesting
+ 1);
1975 ret
= lttng_metadata_printf(session
,
1979 len
= strlen(entry
->string
);
1980 /* Escape the character '"' */
1981 for (j
= 0; j
< len
; j
++) {
1982 char c
= entry
->string
[j
];
1986 ret
= lttng_metadata_printf(session
,
1990 ret
= lttng_metadata_printf(session
,
1994 ret
= lttng_metadata_printf(session
,
2001 ret
= lttng_metadata_printf(session
, "\"");
2005 if (entry
->options
.is_auto
) {
2006 ret
= lttng_metadata_printf(session
, ",\n");
2010 ret
= lttng_metadata_printf(session
,
2014 if (entry
->start
.signedness
)
2015 ret
= lttng_metadata_printf(session
,
2016 "%lld", (long long) entry
->start
.value
);
2018 ret
= lttng_metadata_printf(session
,
2019 "%llu", entry
->start
.value
);
2022 if (entry
->start
.signedness
== entry
->end
.signedness
&&
2024 == entry
->end
.value
) {
2025 ret
= lttng_metadata_printf(session
,
2028 if (entry
->end
.signedness
) {
2029 ret
= lttng_metadata_printf(session
,
2031 (long long) entry
->end
.value
);
2033 ret
= lttng_metadata_printf(session
,
2042 ret
= print_tabs(session
, nesting
);
2045 ret
= lttng_metadata_printf(session
, "} _%s;\n",
2052 * Must be called with sessions_mutex held.
2055 int _lttng_field_statedump(struct lttng_session
*session
,
2056 const struct lttng_event_field
*field
,
2061 switch (field
->type
.atype
) {
2063 ret
= print_tabs(session
, nesting
);
2066 ret
= lttng_metadata_printf(session
,
2067 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
2068 field
->type
.u
.basic
.integer
.size
,
2069 field
->type
.u
.basic
.integer
.alignment
,
2070 field
->type
.u
.basic
.integer
.signedness
,
2071 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
2073 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2076 field
->type
.u
.basic
.integer
.base
,
2077 #if __BYTE_ORDER == __BIG_ENDIAN
2078 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2080 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2085 ret
= _lttng_enum_statedump(session
, field
, nesting
);
2088 case atype_array_bitfield
:
2090 const struct lttng_basic_type
*elem_type
;
2092 elem_type
= &field
->type
.u
.array
.elem_type
;
2093 if (field
->type
.u
.array
.elem_alignment
) {
2094 ret
= print_tabs(session
, nesting
);
2097 ret
= lttng_metadata_printf(session
,
2098 "struct { } align(%u) _%s_padding;\n",
2099 field
->type
.u
.array
.elem_alignment
* CHAR_BIT
,
2104 ret
= print_tabs(session
, nesting
);
2107 ret
= lttng_metadata_printf(session
,
2108 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
2109 elem_type
->u
.basic
.integer
.size
,
2110 elem_type
->u
.basic
.integer
.alignment
,
2111 elem_type
->u
.basic
.integer
.signedness
,
2112 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2114 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2117 elem_type
->u
.basic
.integer
.base
,
2118 #if __BYTE_ORDER == __BIG_ENDIAN
2119 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2121 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2123 field
->name
, field
->type
.u
.array
.length
);
2126 case atype_sequence
:
2127 case atype_sequence_bitfield
:
2129 const struct lttng_basic_type
*elem_type
;
2130 const struct lttng_basic_type
*length_type
;
2132 elem_type
= &field
->type
.u
.sequence
.elem_type
;
2133 length_type
= &field
->type
.u
.sequence
.length_type
;
2134 ret
= print_tabs(session
, nesting
);
2137 ret
= lttng_metadata_printf(session
,
2138 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
2139 length_type
->u
.basic
.integer
.size
,
2140 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
2141 length_type
->u
.basic
.integer
.signedness
,
2142 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2144 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2147 length_type
->u
.basic
.integer
.base
,
2148 #if __BYTE_ORDER == __BIG_ENDIAN
2149 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2151 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2157 if (field
->type
.u
.sequence
.elem_alignment
) {
2158 ret
= print_tabs(session
, nesting
);
2161 ret
= lttng_metadata_printf(session
,
2162 "struct { } align(%u) _%s_padding;\n",
2163 field
->type
.u
.sequence
.elem_alignment
* CHAR_BIT
,
2168 ret
= print_tabs(session
, nesting
);
2171 ret
= lttng_metadata_printf(session
,
2172 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
2173 elem_type
->u
.basic
.integer
.size
,
2174 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
2175 elem_type
->u
.basic
.integer
.signedness
,
2176 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
2178 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
2181 elem_type
->u
.basic
.integer
.base
,
2182 #if __BYTE_ORDER == __BIG_ENDIAN
2183 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
2185 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
2193 /* Default encoding is UTF8 */
2194 ret
= print_tabs(session
, nesting
);
2197 ret
= lttng_metadata_printf(session
,
2199 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
2200 " { encoding = ASCII; }" : "",
2204 ret
= _lttng_struct_statedump(session
, field
, nesting
);
2206 case atype_array_compound
:
2207 ret
= _lttng_array_compound_statedump(session
, field
, nesting
);
2209 case atype_sequence_compound
:
2210 ret
= _lttng_sequence_compound_statedump(session
, field
, nesting
);
2213 ret
= _lttng_variant_statedump(session
, field
, nesting
);
2224 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
2225 struct lttng_ctx
*ctx
)
2232 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
2233 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
2235 ret
= _lttng_field_statedump(session
, &field
->event_field
, 2);
2243 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
2244 struct lttng_event
*event
)
2246 const struct lttng_event_desc
*desc
= event
->desc
;
2250 for (i
= 0; i
< desc
->nr_fields
; i
++) {
2251 const struct lttng_event_field
*field
= &desc
->fields
[i
];
2253 ret
= _lttng_field_statedump(session
, field
, 2);
2261 * Must be called with sessions_mutex held.
2264 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
2265 struct lttng_channel
*chan
,
2266 struct lttng_event
*event
)
2270 if (event
->metadata_dumped
|| !READ_ONCE(session
->active
))
2272 if (chan
->channel_type
== METADATA_CHANNEL
)
2275 ret
= lttng_metadata_printf(session
,
2279 " stream_id = %u;\n",
2287 ret
= lttng_metadata_printf(session
,
2288 " context := struct {\n");
2292 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
2296 ret
= lttng_metadata_printf(session
,
2302 ret
= lttng_metadata_printf(session
,
2303 " fields := struct {\n"
2308 ret
= _lttng_fields_metadata_statedump(session
, event
);
2313 * LTTng space reservation can only reserve multiples of the
2316 ret
= lttng_metadata_printf(session
,
2322 event
->metadata_dumped
= 1;
2329 * Must be called with sessions_mutex held.
2332 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
2333 struct lttng_channel
*chan
)
2337 if (chan
->metadata_dumped
|| !READ_ONCE(session
->active
))
2340 if (chan
->channel_type
== METADATA_CHANNEL
)
2343 WARN_ON_ONCE(!chan
->header_type
);
2344 ret
= lttng_metadata_printf(session
,
2347 " event.header := %s;\n"
2348 " packet.context := struct packet_context;\n",
2350 chan
->header_type
== 1 ? "struct event_header_compact" :
2351 "struct event_header_large");
2356 ret
= lttng_metadata_printf(session
,
2357 " event.context := struct {\n");
2361 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
2365 ret
= lttng_metadata_printf(session
,
2371 ret
= lttng_metadata_printf(session
,
2374 chan
->metadata_dumped
= 1;
2380 * Must be called with sessions_mutex held.
2383 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
2385 return lttng_metadata_printf(session
,
2386 "struct packet_context {\n"
2387 " uint64_clock_monotonic_t timestamp_begin;\n"
2388 " uint64_clock_monotonic_t timestamp_end;\n"
2389 " uint64_t content_size;\n"
2390 " uint64_t packet_size;\n"
2391 " uint64_t packet_seq_num;\n"
2392 " unsigned long events_discarded;\n"
2393 " uint32_t cpu_id;\n"
2400 * id: range: 0 - 30.
2401 * id 31 is reserved to indicate an extended header.
2404 * id: range: 0 - 65534.
2405 * id 65535 is reserved to indicate an extended header.
2407 * Must be called with sessions_mutex held.
2410 int _lttng_event_header_declare(struct lttng_session
*session
)
2412 return lttng_metadata_printf(session
,
2413 "struct event_header_compact {\n"
2414 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
2417 " uint27_clock_monotonic_t timestamp;\n"
2421 " uint64_clock_monotonic_t timestamp;\n"
2426 "struct event_header_large {\n"
2427 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
2430 " uint32_clock_monotonic_t timestamp;\n"
2434 " uint64_clock_monotonic_t timestamp;\n"
2438 lttng_alignof(uint32_t) * CHAR_BIT
,
2439 lttng_alignof(uint16_t) * CHAR_BIT
2444 * Approximation of NTP time of day to clock monotonic correlation,
2445 * taken at start of trace.
2446 * Yes, this is only an approximation. Yes, we can (and will) do better
2447 * in future versions.
2448 * This function may return a negative offset. It may happen if the
2449 * system sets the REALTIME clock to 0 after boot.
2452 int64_t measure_clock_offset(void)
2454 uint64_t monotonic_avg
, monotonic
[2], realtime
;
2455 uint64_t tcf
= trace_clock_freq();
2457 struct timespec rts
= { 0, 0 };
2458 unsigned long flags
;
2460 /* Disable interrupts to increase correlation precision. */
2461 local_irq_save(flags
);
2462 monotonic
[0] = trace_clock_read64();
2463 getnstimeofday(&rts
);
2464 monotonic
[1] = trace_clock_read64();
2465 local_irq_restore(flags
);
2467 monotonic_avg
= (monotonic
[0] + monotonic
[1]) >> 1;
2468 realtime
= (uint64_t) rts
.tv_sec
* tcf
;
2469 if (tcf
== NSEC_PER_SEC
) {
2470 realtime
+= rts
.tv_nsec
;
2472 uint64_t n
= rts
.tv_nsec
* tcf
;
2474 do_div(n
, NSEC_PER_SEC
);
2477 offset
= (int64_t) realtime
- monotonic_avg
;
2482 * Output metadata into this session's metadata buffers.
2483 * Must be called with sessions_mutex held.
2486 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
2488 unsigned char *uuid_c
= session
->uuid
.b
;
2489 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
2490 struct lttng_channel
*chan
;
2491 struct lttng_event
*event
;
2494 if (!READ_ONCE(session
->active
))
2496 if (session
->metadata_dumped
)
2499 snprintf(uuid_s
, sizeof(uuid_s
),
2500 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2501 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
2502 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
2503 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
2504 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
2506 ret
= lttng_metadata_printf(session
,
2507 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
2508 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
2509 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
2510 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
2511 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
2512 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
2513 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
2519 " byte_order = %s;\n"
2520 " packet.header := struct {\n"
2521 " uint32_t magic;\n"
2522 " uint8_t uuid[16];\n"
2523 " uint32_t stream_id;\n"
2524 " uint64_t stream_instance_id;\n"
2527 lttng_alignof(uint8_t) * CHAR_BIT
,
2528 lttng_alignof(uint16_t) * CHAR_BIT
,
2529 lttng_alignof(uint32_t) * CHAR_BIT
,
2530 lttng_alignof(uint64_t) * CHAR_BIT
,
2531 sizeof(unsigned long) * CHAR_BIT
,
2532 lttng_alignof(unsigned long) * CHAR_BIT
,
2536 #if __BYTE_ORDER == __BIG_ENDIAN
2545 ret
= lttng_metadata_printf(session
,
2547 " hostname = \"%s\";\n"
2548 " domain = \"kernel\";\n"
2549 " sysname = \"%s\";\n"
2550 " kernel_release = \"%s\";\n"
2551 " kernel_version = \"%s\";\n"
2552 " tracer_name = \"lttng-modules\";\n"
2553 " tracer_major = %d;\n"
2554 " tracer_minor = %d;\n"
2555 " tracer_patchlevel = %d;\n"
2557 current
->nsproxy
->uts_ns
->name
.nodename
,
2561 LTTNG_MODULES_MAJOR_VERSION
,
2562 LTTNG_MODULES_MINOR_VERSION
,
2563 LTTNG_MODULES_PATCHLEVEL_VERSION
2568 ret
= lttng_metadata_printf(session
,
2570 " name = \"%s\";\n",
2576 if (!trace_clock_uuid(clock_uuid_s
)) {
2577 ret
= lttng_metadata_printf(session
,
2578 " uuid = \"%s\";\n",
2585 ret
= lttng_metadata_printf(session
,
2586 " description = \"%s\";\n"
2587 " freq = %llu; /* Frequency, in Hz */\n"
2588 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
2591 trace_clock_description(),
2592 (unsigned long long) trace_clock_freq(),
2593 (long long) measure_clock_offset()
2598 ret
= lttng_metadata_printf(session
,
2599 "typealias integer {\n"
2600 " size = 27; align = 1; signed = false;\n"
2601 " map = clock.%s.value;\n"
2602 "} := uint27_clock_monotonic_t;\n"
2604 "typealias integer {\n"
2605 " size = 32; align = %u; signed = false;\n"
2606 " map = clock.%s.value;\n"
2607 "} := uint32_clock_monotonic_t;\n"
2609 "typealias integer {\n"
2610 " size = 64; align = %u; signed = false;\n"
2611 " map = clock.%s.value;\n"
2612 "} := uint64_clock_monotonic_t;\n\n",
2614 lttng_alignof(uint32_t) * CHAR_BIT
,
2616 lttng_alignof(uint64_t) * CHAR_BIT
,
2622 ret
= _lttng_stream_packet_context_declare(session
);
2626 ret
= _lttng_event_header_declare(session
);
2631 list_for_each_entry(chan
, &session
->chan
, list
) {
2632 ret
= _lttng_channel_metadata_statedump(session
, chan
);
2637 list_for_each_entry(event
, &session
->events
, list
) {
2638 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
2642 session
->metadata_dumped
= 1;
2648 * lttng_transport_register - LTT transport registration
2649 * @transport: transport structure
2651 * Registers a transport which can be used as output to extract the data out of
2652 * LTTng. The module calling this registration function must ensure that no
2653 * trap-inducing code will be executed by the transport functions. E.g.
2654 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
2655 * is made visible to the transport function. This registration acts as a
2656 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
2657 * after its registration must it synchronize the TLBs.
2659 void lttng_transport_register(struct lttng_transport
*transport
)
2662 * Make sure no page fault can be triggered by the module about to be
2663 * registered. We deal with this here so we don't have to call
2664 * vmalloc_sync_all() in each module's init.
2666 wrapper_vmalloc_sync_all();
2668 mutex_lock(&sessions_mutex
);
2669 list_add_tail(&transport
->node
, <tng_transport_list
);
2670 mutex_unlock(&sessions_mutex
);
2672 EXPORT_SYMBOL_GPL(lttng_transport_register
);
2675 * lttng_transport_unregister - LTT transport unregistration
2676 * @transport: transport structure
2678 void lttng_transport_unregister(struct lttng_transport
*transport
)
2680 mutex_lock(&sessions_mutex
);
2681 list_del(&transport
->node
);
2682 mutex_unlock(&sessions_mutex
);
2684 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
2686 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
2688 enum cpuhp_state lttng_hp_prepare
;
2689 enum cpuhp_state lttng_hp_online
;
2691 static int lttng_hotplug_prepare(unsigned int cpu
, struct hlist_node
*node
)
2693 struct lttng_cpuhp_node
*lttng_node
;
2695 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2696 switch (lttng_node
->component
) {
2697 case LTTNG_RING_BUFFER_FRONTEND
:
2699 case LTTNG_RING_BUFFER_BACKEND
:
2700 return lttng_cpuhp_rb_backend_prepare(cpu
, lttng_node
);
2701 case LTTNG_RING_BUFFER_ITER
:
2703 case LTTNG_CONTEXT_PERF_COUNTERS
:
2710 static int lttng_hotplug_dead(unsigned int cpu
, struct hlist_node
*node
)
2712 struct lttng_cpuhp_node
*lttng_node
;
2714 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2715 switch (lttng_node
->component
) {
2716 case LTTNG_RING_BUFFER_FRONTEND
:
2717 return lttng_cpuhp_rb_frontend_dead(cpu
, lttng_node
);
2718 case LTTNG_RING_BUFFER_BACKEND
:
2720 case LTTNG_RING_BUFFER_ITER
:
2722 case LTTNG_CONTEXT_PERF_COUNTERS
:
2723 return lttng_cpuhp_perf_counter_dead(cpu
, lttng_node
);
2729 static int lttng_hotplug_online(unsigned int cpu
, struct hlist_node
*node
)
2731 struct lttng_cpuhp_node
*lttng_node
;
2733 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2734 switch (lttng_node
->component
) {
2735 case LTTNG_RING_BUFFER_FRONTEND
:
2736 return lttng_cpuhp_rb_frontend_online(cpu
, lttng_node
);
2737 case LTTNG_RING_BUFFER_BACKEND
:
2739 case LTTNG_RING_BUFFER_ITER
:
2740 return lttng_cpuhp_rb_iter_online(cpu
, lttng_node
);
2741 case LTTNG_CONTEXT_PERF_COUNTERS
:
2742 return lttng_cpuhp_perf_counter_online(cpu
, lttng_node
);
2748 static int lttng_hotplug_offline(unsigned int cpu
, struct hlist_node
*node
)
2750 struct lttng_cpuhp_node
*lttng_node
;
2752 lttng_node
= container_of(node
, struct lttng_cpuhp_node
, node
);
2753 switch (lttng_node
->component
) {
2754 case LTTNG_RING_BUFFER_FRONTEND
:
2755 return lttng_cpuhp_rb_frontend_offline(cpu
, lttng_node
);
2756 case LTTNG_RING_BUFFER_BACKEND
:
2758 case LTTNG_RING_BUFFER_ITER
:
2760 case LTTNG_CONTEXT_PERF_COUNTERS
:
2767 static int __init
lttng_init_cpu_hotplug(void)
2771 ret
= cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN
, "lttng:prepare",
2772 lttng_hotplug_prepare
,
2773 lttng_hotplug_dead
);
2777 lttng_hp_prepare
= ret
;
2778 lttng_rb_set_hp_prepare(ret
);
2780 ret
= cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN
, "lttng:online",
2781 lttng_hotplug_online
,
2782 lttng_hotplug_offline
);
2784 cpuhp_remove_multi_state(lttng_hp_prepare
);
2785 lttng_hp_prepare
= 0;
2788 lttng_hp_online
= ret
;
2789 lttng_rb_set_hp_online(ret
);
2794 static void __exit
lttng_exit_cpu_hotplug(void)
2796 lttng_rb_set_hp_online(0);
2797 cpuhp_remove_multi_state(lttng_hp_online
);
2798 lttng_rb_set_hp_prepare(0);
2799 cpuhp_remove_multi_state(lttng_hp_prepare
);
2802 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2803 static int lttng_init_cpu_hotplug(void)
2807 static void lttng_exit_cpu_hotplug(void)
2810 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2813 static int __init
lttng_events_init(void)
2817 ret
= wrapper_lttng_fixup_sig(THIS_MODULE
);
2820 ret
= wrapper_get_pfnblock_flags_mask_init();
2823 ret
= wrapper_get_pageblock_flags_mask_init();
2826 ret
= lttng_probes_init();
2829 ret
= lttng_context_init();
2832 ret
= lttng_tracepoint_init();
2835 event_cache
= KMEM_CACHE(lttng_event
, 0);
2840 ret
= lttng_abi_init();
2843 ret
= lttng_logger_init();
2846 ret
= lttng_init_cpu_hotplug();
2849 printk(KERN_NOTICE
"LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n",
2850 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2851 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2852 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2853 LTTNG_MODULES_EXTRAVERSION
,
2855 #ifdef LTTNG_EXTRA_VERSION_GIT
2856 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2860 #ifdef LTTNG_EXTRA_VERSION_NAME
2861 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2868 lttng_logger_exit();
2872 kmem_cache_destroy(event_cache
);
2874 lttng_tracepoint_exit();
2876 lttng_context_exit();
2877 printk(KERN_NOTICE
"LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n",
2878 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2879 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2880 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2881 LTTNG_MODULES_EXTRAVERSION
,
2883 #ifdef LTTNG_EXTRA_VERSION_GIT
2884 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2888 #ifdef LTTNG_EXTRA_VERSION_NAME
2889 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2896 module_init(lttng_events_init
);
2898 static void __exit
lttng_events_exit(void)
2900 struct lttng_session
*session
, *tmpsession
;
2902 lttng_exit_cpu_hotplug();
2903 lttng_logger_exit();
2905 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
2906 lttng_session_destroy(session
);
2907 kmem_cache_destroy(event_cache
);
2908 lttng_tracepoint_exit();
2909 lttng_context_exit();
2910 printk(KERN_NOTICE
"LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n",
2911 __stringify(LTTNG_MODULES_MAJOR_VERSION
),
2912 __stringify(LTTNG_MODULES_MINOR_VERSION
),
2913 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
),
2914 LTTNG_MODULES_EXTRAVERSION
,
2916 #ifdef LTTNG_EXTRA_VERSION_GIT
2917 LTTNG_EXTRA_VERSION_GIT
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT
,
2921 #ifdef LTTNG_EXTRA_VERSION_NAME
2922 LTTNG_EXTRA_VERSION_NAME
[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME
);
2928 module_exit(lttng_events_exit
);
2930 #include "extra_version/patches.i"
2931 #ifdef LTTNG_EXTRA_VERSION_GIT
2932 MODULE_INFO(extra_version_git
, LTTNG_EXTRA_VERSION_GIT
);
2934 #ifdef LTTNG_EXTRA_VERSION_NAME
2935 MODULE_INFO(extra_version_name
, LTTNG_EXTRA_VERSION_NAME
);
2937 MODULE_LICENSE("GPL and additional rights");
2938 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
2939 MODULE_DESCRIPTION("LTTng tracer");
2940 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
2941 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
2942 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
2943 LTTNG_MODULES_EXTRAVERSION
);