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
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <linux/mutex.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/jiffies.h>
29 #include <linux/utsname.h>
30 #include "wrapper/uuid.h"
31 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
32 #include "wrapper/random.h"
33 #include "wrapper/tracepoint.h"
34 #include "lttng-kernel-version.h"
35 #include "lttng-events.h"
36 #include "lttng-tracer.h"
37 #include "lttng-abi-old.h"
39 static LIST_HEAD(sessions
);
40 static LIST_HEAD(lttng_transport_list
);
41 static DEFINE_MUTEX(sessions_mutex
);
42 static struct kmem_cache
*event_cache
;
44 static void _lttng_event_destroy(struct lttng_event
*event
);
45 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
46 static int _lttng_event_unregister(struct lttng_event
*event
);
48 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
49 struct lttng_channel
*chan
,
50 struct lttng_event
*event
);
52 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
54 void synchronize_trace(void)
57 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
58 #ifdef CONFIG_PREEMPT_RT_FULL
61 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
62 #ifdef CONFIG_PREEMPT_RT
65 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
68 struct lttng_session
*lttng_session_create(void)
70 struct lttng_session
*session
;
72 mutex_lock(&sessions_mutex
);
73 session
= kzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
76 INIT_LIST_HEAD(&session
->chan
);
77 INIT_LIST_HEAD(&session
->events
);
78 uuid_le_gen(&session
->uuid
);
79 list_add(&session
->list
, &sessions
);
80 mutex_unlock(&sessions_mutex
);
84 void lttng_session_destroy(struct lttng_session
*session
)
86 struct lttng_channel
*chan
, *tmpchan
;
87 struct lttng_event
*event
, *tmpevent
;
90 mutex_lock(&sessions_mutex
);
91 ACCESS_ONCE(session
->active
) = 0;
92 list_for_each_entry(chan
, &session
->chan
, list
) {
93 ret
= lttng_syscalls_unregister(chan
);
96 list_for_each_entry(event
, &session
->events
, list
) {
97 ret
= _lttng_event_unregister(event
);
100 synchronize_trace(); /* Wait for in-flight events to complete */
101 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
102 _lttng_event_destroy(event
);
103 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
104 _lttng_channel_destroy(chan
);
105 list_del(&session
->list
);
106 mutex_unlock(&sessions_mutex
);
110 int lttng_session_enable(struct lttng_session
*session
)
113 struct lttng_channel
*chan
;
115 mutex_lock(&sessions_mutex
);
116 if (session
->active
) {
122 * Snapshot the number of events per channel to know the type of header
125 list_for_each_entry(chan
, &session
->chan
, list
) {
126 if (chan
->header_type
)
127 continue; /* don't change it if session stop/restart */
128 if (chan
->free_event_id
< 31)
129 chan
->header_type
= 1; /* compact */
131 chan
->header_type
= 2; /* large */
134 ACCESS_ONCE(session
->active
) = 1;
135 ACCESS_ONCE(session
->been_active
) = 1;
136 ret
= _lttng_session_metadata_statedump(session
);
138 ACCESS_ONCE(session
->active
) = 0;
141 ret
= lttng_statedump_start(session
);
143 ACCESS_ONCE(session
->active
) = 0;
145 mutex_unlock(&sessions_mutex
);
149 int lttng_session_disable(struct lttng_session
*session
)
153 mutex_lock(&sessions_mutex
);
154 if (!session
->active
) {
158 ACCESS_ONCE(session
->active
) = 0;
160 mutex_unlock(&sessions_mutex
);
164 int lttng_channel_enable(struct lttng_channel
*channel
)
168 if (channel
== channel
->session
->metadata
)
170 old
= xchg(&channel
->enabled
, 1);
176 int lttng_channel_disable(struct lttng_channel
*channel
)
180 if (channel
== channel
->session
->metadata
)
182 old
= xchg(&channel
->enabled
, 0);
188 int lttng_event_enable(struct lttng_event
*event
)
192 if (event
->chan
== event
->chan
->session
->metadata
)
194 old
= xchg(&event
->enabled
, 1);
200 int lttng_event_disable(struct lttng_event
*event
)
204 if (event
->chan
== event
->chan
->session
->metadata
)
206 old
= xchg(&event
->enabled
, 0);
212 static struct lttng_transport
*lttng_transport_find(const char *name
)
214 struct lttng_transport
*transport
;
216 list_for_each_entry(transport
, <tng_transport_list
, node
) {
217 if (!strcmp(transport
->name
, name
))
223 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
224 const char *transport_name
,
226 size_t subbuf_size
, size_t num_subbuf
,
227 unsigned int switch_timer_interval
,
228 unsigned int read_timer_interval
)
230 struct lttng_channel
*chan
;
231 struct lttng_transport
*transport
= NULL
;
233 mutex_lock(&sessions_mutex
);
234 if (session
->been_active
)
235 goto active
; /* Refuse to add channel to active session */
236 transport
= lttng_transport_find(transport_name
);
238 printk(KERN_WARNING
"LTTng transport %s not found\n",
242 if (!try_module_get(transport
->owner
)) {
243 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
246 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
249 chan
->session
= session
;
250 chan
->id
= session
->free_chan_id
++;
252 * Note: the channel creation op already writes into the packet
253 * headers. Therefore the "chan" information used as input
254 * should be already accessible.
256 chan
->chan
= transport
->ops
.channel_create(transport_name
,
257 chan
, buf_addr
, subbuf_size
, num_subbuf
,
258 switch_timer_interval
, read_timer_interval
);
262 chan
->ops
= &transport
->ops
;
263 chan
->transport
= transport
;
264 list_add(&chan
->list
, &session
->chan
);
265 mutex_unlock(&sessions_mutex
);
272 module_put(transport
->owner
);
275 mutex_unlock(&sessions_mutex
);
280 * Only used internally at session destruction.
283 void _lttng_channel_destroy(struct lttng_channel
*chan
)
285 chan
->ops
->channel_destroy(chan
->chan
);
286 module_put(chan
->transport
->owner
);
287 list_del(&chan
->list
);
288 lttng_destroy_context(chan
->ctx
);
293 * Supports event creation while tracing session is active.
295 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
296 struct lttng_kernel_event
*event_param
,
298 const struct lttng_event_desc
*internal_desc
)
300 struct lttng_event
*event
;
303 mutex_lock(&sessions_mutex
);
304 if (chan
->free_event_id
== -1U)
307 * This is O(n^2) (for each event, the loop is called at event
308 * creation). Might require a hash if we have lots of events.
310 list_for_each_entry(event
, &chan
->session
->events
, list
)
311 if (!strcmp(event
->desc
->name
, event_param
->name
))
313 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
317 event
->filter
= filter
;
318 event
->id
= chan
->free_event_id
++;
320 event
->instrumentation
= event_param
->instrumentation
;
321 /* Populate lttng_event structure before tracepoint registration. */
323 switch (event_param
->instrumentation
) {
324 case LTTNG_KERNEL_TRACEPOINT
:
325 event
->desc
= lttng_event_get(event_param
->name
);
328 ret
= kabi_2635_tracepoint_probe_register(event_param
->name
,
329 event
->desc
->probe_callback
,
334 case LTTNG_KERNEL_KPROBE
:
335 ret
= lttng_kprobes_register(event_param
->name
,
336 event_param
->u
.kprobe
.symbol_name
,
337 event_param
->u
.kprobe
.offset
,
338 event_param
->u
.kprobe
.addr
,
342 ret
= try_module_get(event
->desc
->owner
);
345 case LTTNG_KERNEL_KRETPROBE
:
347 struct lttng_event
*event_return
;
349 /* kretprobe defines 2 events */
351 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
354 event_return
->chan
= chan
;
355 event_return
->filter
= filter
;
356 event_return
->id
= chan
->free_event_id
++;
357 event_return
->enabled
= 1;
358 event_return
->instrumentation
= event_param
->instrumentation
;
360 * Populate lttng_event structure before kretprobe registration.
363 ret
= lttng_kretprobes_register(event_param
->name
,
364 event_param
->u
.kretprobe
.symbol_name
,
365 event_param
->u
.kretprobe
.offset
,
366 event_param
->u
.kretprobe
.addr
,
367 event
, event_return
);
369 kmem_cache_free(event_cache
, event_return
);
372 /* Take 2 refs on the module: one per event. */
373 ret
= try_module_get(event
->desc
->owner
);
375 ret
= try_module_get(event
->desc
->owner
);
377 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
380 kmem_cache_free(event_cache
, event_return
);
381 module_put(event
->desc
->owner
);
382 module_put(event
->desc
->owner
);
383 goto statedump_error
;
385 list_add(&event_return
->list
, &chan
->session
->events
);
388 case LTTNG_KERNEL_FUNCTION
:
389 ret
= lttng_ftrace_register(event_param
->name
,
390 event_param
->u
.ftrace
.symbol_name
,
394 ret
= try_module_get(event
->desc
->owner
);
397 case LTTNG_KERNEL_NOOP
:
398 event
->desc
= internal_desc
;
405 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
407 goto statedump_error
;
408 list_add(&event
->list
, &chan
->session
->events
);
409 mutex_unlock(&sessions_mutex
);
413 /* If a statedump error occurs, events will not be readable. */
415 kmem_cache_free(event_cache
, event
);
419 mutex_unlock(&sessions_mutex
);
424 * Only used internally at session destruction.
426 int _lttng_event_unregister(struct lttng_event
*event
)
430 switch (event
->instrumentation
) {
431 case LTTNG_KERNEL_TRACEPOINT
:
432 ret
= kabi_2635_tracepoint_probe_unregister(event
->desc
->name
,
433 event
->desc
->probe_callback
,
438 case LTTNG_KERNEL_KPROBE
:
439 lttng_kprobes_unregister(event
);
442 case LTTNG_KERNEL_KRETPROBE
:
443 lttng_kretprobes_unregister(event
);
446 case LTTNG_KERNEL_FUNCTION
:
447 lttng_ftrace_unregister(event
);
450 case LTTNG_KERNEL_NOOP
:
460 * Only used internally at session destruction.
463 void _lttng_event_destroy(struct lttng_event
*event
)
465 switch (event
->instrumentation
) {
466 case LTTNG_KERNEL_TRACEPOINT
:
467 lttng_event_put(event
->desc
);
469 case LTTNG_KERNEL_KPROBE
:
470 module_put(event
->desc
->owner
);
471 lttng_kprobes_destroy_private(event
);
473 case LTTNG_KERNEL_KRETPROBE
:
474 module_put(event
->desc
->owner
);
475 lttng_kretprobes_destroy_private(event
);
477 case LTTNG_KERNEL_FUNCTION
:
478 module_put(event
->desc
->owner
);
479 lttng_ftrace_destroy_private(event
);
481 case LTTNG_KERNEL_NOOP
:
486 list_del(&event
->list
);
487 lttng_destroy_context(event
->ctx
);
488 kmem_cache_free(event_cache
, event
);
492 * We have exclusive access to our metadata buffer (protected by the
493 * sessions_mutex), so we can do racy operations such as looking for
494 * remaining space left in packet and write, since mutual exclusion
495 * protects us from concurrent writes.
497 int lttng_metadata_printf(struct lttng_session
*session
,
498 const char *fmt
, ...)
500 struct lib_ring_buffer_ctx ctx
;
501 struct lttng_channel
*chan
= session
->metadata
;
503 int ret
= 0, waitret
;
504 size_t len
, reserve_len
, pos
;
507 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
510 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
518 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
519 reserve_len
= min_t(size_t,
520 chan
->ops
->packet_avail_size(chan
->chan
),
522 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
525 * We don't care about metadata buffer's records lost
526 * count, because we always retry here. Report error if
527 * we need to bail out after timeout or being
530 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
532 ret
= chan
->ops
->event_reserve(&ctx
, 0);
533 ret
!= -ENOBUFS
|| !ret
;
535 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
536 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
537 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
538 waitret
== -ERESTARTSYS
? "interrupted" :
539 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
540 if (waitret
== -ERESTARTSYS
)
544 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
545 chan
->ops
->event_commit(&ctx
);
553 int _lttng_field_statedump(struct lttng_session
*session
,
554 const struct lttng_event_field
*field
)
558 switch (field
->type
.atype
) {
560 ret
= lttng_metadata_printf(session
,
561 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
562 field
->type
.u
.basic
.integer
.size
,
563 field
->type
.u
.basic
.integer
.alignment
,
564 field
->type
.u
.basic
.integer
.signedness
,
565 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
567 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
570 field
->type
.u
.basic
.integer
.base
,
572 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
574 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
579 ret
= lttng_metadata_printf(session
,
581 field
->type
.u
.basic
.enumeration
.name
,
586 const struct lttng_basic_type
*elem_type
;
588 elem_type
= &field
->type
.u
.array
.elem_type
;
589 ret
= lttng_metadata_printf(session
,
590 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
591 elem_type
->u
.basic
.integer
.size
,
592 elem_type
->u
.basic
.integer
.alignment
,
593 elem_type
->u
.basic
.integer
.signedness
,
594 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
596 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
599 elem_type
->u
.basic
.integer
.base
,
601 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
603 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
605 field
->name
, field
->type
.u
.array
.length
);
610 const struct lttng_basic_type
*elem_type
;
611 const struct lttng_basic_type
*length_type
;
613 elem_type
= &field
->type
.u
.sequence
.elem_type
;
614 length_type
= &field
->type
.u
.sequence
.length_type
;
615 ret
= lttng_metadata_printf(session
,
616 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
617 length_type
->u
.basic
.integer
.size
,
618 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
619 length_type
->u
.basic
.integer
.signedness
,
620 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
622 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
625 length_type
->u
.basic
.integer
.base
,
627 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
629 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
635 ret
= lttng_metadata_printf(session
,
636 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
637 elem_type
->u
.basic
.integer
.size
,
638 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
639 elem_type
->u
.basic
.integer
.signedness
,
640 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
642 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
645 elem_type
->u
.basic
.integer
.base
,
647 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
649 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
657 /* Default encoding is UTF8 */
658 ret
= lttng_metadata_printf(session
,
660 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
661 " { encoding = ASCII; }" : "",
672 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
673 struct lttng_ctx
*ctx
)
680 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
681 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
683 ret
= _lttng_field_statedump(session
, &field
->event_field
);
691 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
692 struct lttng_event
*event
)
694 const struct lttng_event_desc
*desc
= event
->desc
;
698 for (i
= 0; i
< desc
->nr_fields
; i
++) {
699 const struct lttng_event_field
*field
= &desc
->fields
[i
];
701 ret
= _lttng_field_statedump(session
, field
);
709 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
710 struct lttng_channel
*chan
,
711 struct lttng_event
*event
)
715 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
717 if (chan
== session
->metadata
)
720 ret
= lttng_metadata_printf(session
,
724 " stream_id = %u;\n",
732 ret
= lttng_metadata_printf(session
,
733 " context := struct {\n");
737 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
741 ret
= lttng_metadata_printf(session
,
747 ret
= lttng_metadata_printf(session
,
748 " fields := struct {\n"
753 ret
= _lttng_fields_metadata_statedump(session
, event
);
758 * LTTng space reservation can only reserve multiples of the
761 ret
= lttng_metadata_printf(session
,
767 event
->metadata_dumped
= 1;
774 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
775 struct lttng_channel
*chan
)
779 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
781 if (chan
== session
->metadata
)
784 WARN_ON_ONCE(!chan
->header_type
);
785 ret
= lttng_metadata_printf(session
,
788 " event.header := %s;\n"
789 " packet.context := struct packet_context;\n",
791 chan
->header_type
== 1 ? "struct event_header_compact" :
792 "struct event_header_large");
797 ret
= lttng_metadata_printf(session
,
798 " event.context := struct {\n");
802 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
806 ret
= lttng_metadata_printf(session
,
812 ret
= lttng_metadata_printf(session
,
815 chan
->metadata_dumped
= 1;
821 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
823 return lttng_metadata_printf(session
,
824 "struct packet_context {\n"
825 " uint64_clock_monotonic_t timestamp_begin;\n"
826 " uint64_clock_monotonic_t timestamp_end;\n"
827 " uint64_t content_size;\n"
828 " uint64_t packet_size;\n"
829 " unsigned long events_discarded;\n"
830 " uint32_t cpu_id;\n"
838 * id 31 is reserved to indicate an extended header.
841 * id: range: 0 - 65534.
842 * id 65535 is reserved to indicate an extended header.
845 int _lttng_event_header_declare(struct lttng_session
*session
)
847 return lttng_metadata_printf(session
,
848 "struct event_header_compact {\n"
849 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
852 " uint27_clock_monotonic_t timestamp;\n"
856 " uint64_clock_monotonic_t timestamp;\n"
861 "struct event_header_large {\n"
862 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
865 " uint32_clock_monotonic_t timestamp;\n"
869 " uint64_clock_monotonic_t timestamp;\n"
873 lttng_alignof(uint32_t) * CHAR_BIT
,
874 lttng_alignof(uint16_t) * CHAR_BIT
879 * Approximation of NTP time of day to clock monotonic correlation,
880 * taken at start of trace.
881 * Yes, this is only an approximation. Yes, we can (and will) do better
882 * in future versions.
885 uint64_t measure_clock_offset(void)
887 uint64_t offset
, monotonic
[2], realtime
;
888 struct timespec rts
= { 0, 0 };
891 /* Disable interrupts to increase correlation precision. */
892 local_irq_save(flags
);
893 monotonic
[0] = trace_clock_read64();
894 getnstimeofday(&rts
);
895 monotonic
[1] = trace_clock_read64();
896 local_irq_restore(flags
);
898 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
899 realtime
= (uint64_t) rts
.tv_sec
* NSEC_PER_SEC
;
900 realtime
+= rts
.tv_nsec
;
901 offset
= realtime
- offset
;
906 * Output metadata into this session's metadata buffers.
909 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
911 unsigned char *uuid_c
= session
->uuid
.b
;
912 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
913 struct lttng_channel
*chan
;
914 struct lttng_event
*event
;
917 if (!ACCESS_ONCE(session
->active
))
919 if (session
->metadata_dumped
)
921 if (!session
->metadata
) {
922 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
926 snprintf(uuid_s
, sizeof(uuid_s
),
927 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
928 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
929 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
930 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
931 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
933 ret
= lttng_metadata_printf(session
,
934 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
935 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
936 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
937 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
938 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
939 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
940 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
946 " byte_order = %s;\n"
947 " packet.header := struct {\n"
949 " uint8_t uuid[16];\n"
950 " uint32_t stream_id;\n"
953 lttng_alignof(uint8_t) * CHAR_BIT
,
954 lttng_alignof(uint16_t) * CHAR_BIT
,
955 lttng_alignof(uint32_t) * CHAR_BIT
,
956 lttng_alignof(uint64_t) * CHAR_BIT
,
957 sizeof(unsigned long) * CHAR_BIT
,
958 lttng_alignof(unsigned long) * CHAR_BIT
,
971 ret
= lttng_metadata_printf(session
,
973 " hostname = \"%s\";\n"
974 " domain = \"kernel\";\n"
975 " sysname = \"%s\";\n"
976 " kernel_release = \"%s\";\n"
977 " kernel_version = \"%s\";\n"
978 " tracer_name = \"lttng-modules\";\n"
979 " tracer_major = %d;\n"
980 " tracer_minor = %d;\n"
981 " tracer_patchlevel = %d;\n"
983 current
->nsproxy
->uts_ns
->name
.nodename
,
987 LTTNG_MODULES_MAJOR_VERSION
,
988 LTTNG_MODULES_MINOR_VERSION
,
989 LTTNG_MODULES_PATCHLEVEL_VERSION
994 ret
= lttng_metadata_printf(session
,
1002 if (!trace_clock_uuid(clock_uuid_s
)) {
1003 ret
= lttng_metadata_printf(session
,
1004 " uuid = \"%s\";\n",
1011 ret
= lttng_metadata_printf(session
,
1012 " description = \"Monotonic Clock\";\n"
1013 " freq = %llu; /* Frequency, in Hz */\n"
1014 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1017 (unsigned long long) trace_clock_freq(),
1018 (unsigned long long) measure_clock_offset()
1023 ret
= lttng_metadata_printf(session
,
1024 "typealias integer {\n"
1025 " size = 27; align = 1; signed = false;\n"
1026 " map = clock.monotonic.value;\n"
1027 "} := uint27_clock_monotonic_t;\n"
1029 "typealias integer {\n"
1030 " size = 32; align = %u; signed = false;\n"
1031 " map = clock.monotonic.value;\n"
1032 "} := uint32_clock_monotonic_t;\n"
1034 "typealias integer {\n"
1035 " size = 64; align = %u; signed = false;\n"
1036 " map = clock.monotonic.value;\n"
1037 "} := uint64_clock_monotonic_t;\n\n",
1038 lttng_alignof(uint32_t) * CHAR_BIT
,
1039 lttng_alignof(uint64_t) * CHAR_BIT
1044 ret
= _lttng_stream_packet_context_declare(session
);
1048 ret
= _lttng_event_header_declare(session
);
1053 list_for_each_entry(chan
, &session
->chan
, list
) {
1054 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1059 list_for_each_entry(event
, &session
->events
, list
) {
1060 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1064 session
->metadata_dumped
= 1;
1070 * lttng_transport_register - LTT transport registration
1071 * @transport: transport structure
1073 * Registers a transport which can be used as output to extract the data out of
1074 * LTTng. The module calling this registration function must ensure that no
1075 * trap-inducing code will be executed by the transport functions. E.g.
1076 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1077 * is made visible to the transport function. This registration acts as a
1078 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1079 * after its registration must it synchronize the TLBs.
1081 void lttng_transport_register(struct lttng_transport
*transport
)
1084 * Make sure no page fault can be triggered by the module about to be
1085 * registered. We deal with this here so we don't have to call
1086 * vmalloc_sync_all() in each module's init.
1088 wrapper_vmalloc_sync_all();
1090 mutex_lock(&sessions_mutex
);
1091 list_add_tail(&transport
->node
, <tng_transport_list
);
1092 mutex_unlock(&sessions_mutex
);
1094 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1097 * lttng_transport_unregister - LTT transport unregistration
1098 * @transport: transport structure
1100 void lttng_transport_unregister(struct lttng_transport
*transport
)
1102 mutex_lock(&sessions_mutex
);
1103 list_del(&transport
->node
);
1104 mutex_unlock(&sessions_mutex
);
1106 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1108 static int __init
lttng_events_init(void)
1112 event_cache
= KMEM_CACHE(lttng_event
, 0);
1115 ret
= lttng_abi_init();
1120 kmem_cache_destroy(event_cache
);
1124 module_init(lttng_events_init
);
1126 static void __exit
lttng_events_exit(void)
1128 struct lttng_session
*session
, *tmpsession
;
1131 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1132 lttng_session_destroy(session
);
1133 kmem_cache_destroy(event_cache
);
1136 module_exit(lttng_events_exit
);
1138 MODULE_LICENSE("GPL and additional rights");
1139 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1140 MODULE_DESCRIPTION("LTTng Events");