4 * Copyright 2010-2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
8 * Dual LGPL v2.1/GPL v2 license.
11 #include <linux/module.h>
12 #include <linux/list.h>
13 #include <linux/mutex.h>
14 #include <linux/sched.h>
15 #include <linux/slab.h>
16 #include <linux/jiffies.h>
17 #include <linux/utsname.h>
18 #include "wrapper/uuid.h"
19 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
20 #include "wrapper/random.h"
21 #include "lttng-events.h"
22 #include "lttng-tracer.h"
24 static LIST_HEAD(sessions
);
25 static LIST_HEAD(lttng_transport_list
);
26 static DEFINE_MUTEX(sessions_mutex
);
27 static struct kmem_cache
*event_cache
;
29 static void _lttng_event_destroy(struct lttng_event
*event
);
30 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
31 static int _lttng_event_unregister(struct lttng_event
*event
);
33 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
34 struct lttng_channel
*chan
,
35 struct lttng_event
*event
);
37 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
39 void synchronize_trace(void)
42 #ifdef CONFIG_PREEMPT_RT
47 struct lttng_session
*lttng_session_create(void)
49 struct lttng_session
*session
;
51 mutex_lock(&sessions_mutex
);
52 session
= kzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
55 INIT_LIST_HEAD(&session
->chan
);
56 INIT_LIST_HEAD(&session
->events
);
57 uuid_le_gen(&session
->uuid
);
58 list_add(&session
->list
, &sessions
);
59 mutex_unlock(&sessions_mutex
);
63 void lttng_session_destroy(struct lttng_session
*session
)
65 struct lttng_channel
*chan
, *tmpchan
;
66 struct lttng_event
*event
, *tmpevent
;
69 mutex_lock(&sessions_mutex
);
70 ACCESS_ONCE(session
->active
) = 0;
71 list_for_each_entry(chan
, &session
->chan
, list
) {
72 ret
= lttng_syscalls_unregister(chan
);
75 list_for_each_entry(event
, &session
->events
, list
) {
76 ret
= _lttng_event_unregister(event
);
79 synchronize_trace(); /* Wait for in-flight events to complete */
80 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
81 _lttng_event_destroy(event
);
82 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
83 _lttng_channel_destroy(chan
);
84 list_del(&session
->list
);
85 mutex_unlock(&sessions_mutex
);
89 int lttng_session_enable(struct lttng_session
*session
)
92 struct lttng_channel
*chan
;
94 mutex_lock(&sessions_mutex
);
95 if (session
->active
) {
101 * Snapshot the number of events per channel to know the type of header
104 list_for_each_entry(chan
, &session
->chan
, list
) {
105 if (chan
->header_type
)
106 continue; /* don't change it if session stop/restart */
107 if (chan
->free_event_id
< 31)
108 chan
->header_type
= 1; /* compact */
110 chan
->header_type
= 2; /* large */
113 ACCESS_ONCE(session
->active
) = 1;
114 ACCESS_ONCE(session
->been_active
) = 1;
115 ret
= _lttng_session_metadata_statedump(session
);
117 ACCESS_ONCE(session
->active
) = 0;
119 mutex_unlock(&sessions_mutex
);
123 int lttng_session_disable(struct lttng_session
*session
)
127 mutex_lock(&sessions_mutex
);
128 if (!session
->active
) {
132 ACCESS_ONCE(session
->active
) = 0;
134 mutex_unlock(&sessions_mutex
);
138 int lttng_channel_enable(struct lttng_channel
*channel
)
142 if (channel
== channel
->session
->metadata
)
144 old
= xchg(&channel
->enabled
, 1);
150 int lttng_channel_disable(struct lttng_channel
*channel
)
154 if (channel
== channel
->session
->metadata
)
156 old
= xchg(&channel
->enabled
, 0);
162 int lttng_event_enable(struct lttng_event
*event
)
166 if (event
->chan
== event
->chan
->session
->metadata
)
168 old
= xchg(&event
->enabled
, 1);
174 int lttng_event_disable(struct lttng_event
*event
)
178 if (event
->chan
== event
->chan
->session
->metadata
)
180 old
= xchg(&event
->enabled
, 0);
186 static struct lttng_transport
*lttng_transport_find(const char *name
)
188 struct lttng_transport
*transport
;
190 list_for_each_entry(transport
, <tng_transport_list
, node
) {
191 if (!strcmp(transport
->name
, name
))
197 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
198 const char *transport_name
,
200 size_t subbuf_size
, size_t num_subbuf
,
201 unsigned int switch_timer_interval
,
202 unsigned int read_timer_interval
)
204 struct lttng_channel
*chan
;
205 struct lttng_transport
*transport
= NULL
;
207 mutex_lock(&sessions_mutex
);
208 if (session
->been_active
)
209 goto active
; /* Refuse to add channel to active session */
210 transport
= lttng_transport_find(transport_name
);
212 printk(KERN_WARNING
"LTTng transport %s not found\n",
216 if (!try_module_get(transport
->owner
)) {
217 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
220 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
223 chan
->session
= session
;
224 chan
->id
= session
->free_chan_id
++;
226 * Note: the channel creation op already writes into the packet
227 * headers. Therefore the "chan" information used as input
228 * should be already accessible.
230 chan
->chan
= transport
->ops
.channel_create("[lttng]", chan
, buf_addr
,
231 subbuf_size
, num_subbuf
, switch_timer_interval
,
232 read_timer_interval
);
236 chan
->ops
= &transport
->ops
;
237 chan
->transport
= transport
;
238 list_add(&chan
->list
, &session
->chan
);
239 mutex_unlock(&sessions_mutex
);
246 module_put(transport
->owner
);
249 mutex_unlock(&sessions_mutex
);
254 * Only used internally at session destruction.
257 void _lttng_channel_destroy(struct lttng_channel
*chan
)
259 chan
->ops
->channel_destroy(chan
->chan
);
260 module_put(chan
->transport
->owner
);
261 list_del(&chan
->list
);
262 lttng_destroy_context(chan
->ctx
);
267 * Supports event creation while tracing session is active.
269 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
270 struct lttng_kernel_event
*event_param
,
272 const struct lttng_event_desc
*internal_desc
)
274 struct lttng_event
*event
;
277 mutex_lock(&sessions_mutex
);
278 if (chan
->free_event_id
== -1UL)
281 * This is O(n^2) (for each event, the loop is called at event
282 * creation). Might require a hash if we have lots of events.
284 list_for_each_entry(event
, &chan
->session
->events
, list
)
285 if (!strcmp(event
->desc
->name
, event_param
->name
))
287 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
291 event
->filter
= filter
;
292 event
->id
= chan
->free_event_id
++;
294 event
->instrumentation
= event_param
->instrumentation
;
295 /* Populate lttng_event structure before tracepoint registration. */
297 switch (event_param
->instrumentation
) {
298 case LTTNG_KERNEL_TRACEPOINT
:
299 event
->desc
= lttng_event_get(event_param
->name
);
302 ret
= tracepoint_probe_register(event_param
->name
,
303 event
->desc
->probe_callback
,
308 case LTTNG_KERNEL_KPROBE
:
309 ret
= lttng_kprobes_register(event_param
->name
,
310 event_param
->u
.kprobe
.symbol_name
,
311 event_param
->u
.kprobe
.offset
,
312 event_param
->u
.kprobe
.addr
,
316 ret
= try_module_get(event
->desc
->owner
);
319 case LTTNG_KERNEL_KRETPROBE
:
321 struct lttng_event
*event_return
;
323 /* kretprobe defines 2 events */
325 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
328 event_return
->chan
= chan
;
329 event_return
->filter
= filter
;
330 event_return
->id
= chan
->free_event_id
++;
331 event_return
->enabled
= 1;
332 event_return
->instrumentation
= event_param
->instrumentation
;
334 * Populate lttng_event structure before kretprobe registration.
337 ret
= lttng_kretprobes_register(event_param
->name
,
338 event_param
->u
.kretprobe
.symbol_name
,
339 event_param
->u
.kretprobe
.offset
,
340 event_param
->u
.kretprobe
.addr
,
341 event
, event_return
);
343 kmem_cache_free(event_cache
, event_return
);
346 /* Take 2 refs on the module: one per event. */
347 ret
= try_module_get(event
->desc
->owner
);
349 ret
= try_module_get(event
->desc
->owner
);
351 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
354 kmem_cache_free(event_cache
, event_return
);
355 module_put(event
->desc
->owner
);
356 module_put(event
->desc
->owner
);
357 goto statedump_error
;
359 list_add(&event_return
->list
, &chan
->session
->events
);
362 case LTTNG_KERNEL_FUNCTION
:
363 ret
= lttng_ftrace_register(event_param
->name
,
364 event_param
->u
.ftrace
.symbol_name
,
368 ret
= try_module_get(event
->desc
->owner
);
371 case LTTNG_KERNEL_NOOP
:
372 event
->desc
= internal_desc
;
379 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
381 goto statedump_error
;
382 list_add(&event
->list
, &chan
->session
->events
);
383 mutex_unlock(&sessions_mutex
);
387 /* If a statedump error occurs, events will not be readable. */
389 kmem_cache_free(event_cache
, event
);
393 mutex_unlock(&sessions_mutex
);
398 * Only used internally at session destruction.
400 int _lttng_event_unregister(struct lttng_event
*event
)
404 switch (event
->instrumentation
) {
405 case LTTNG_KERNEL_TRACEPOINT
:
406 ret
= tracepoint_probe_unregister(event
->desc
->name
,
407 event
->desc
->probe_callback
,
412 case LTTNG_KERNEL_KPROBE
:
413 lttng_kprobes_unregister(event
);
416 case LTTNG_KERNEL_KRETPROBE
:
417 lttng_kretprobes_unregister(event
);
420 case LTTNG_KERNEL_FUNCTION
:
421 lttng_ftrace_unregister(event
);
424 case LTTNG_KERNEL_NOOP
:
434 * Only used internally at session destruction.
437 void _lttng_event_destroy(struct lttng_event
*event
)
439 switch (event
->instrumentation
) {
440 case LTTNG_KERNEL_TRACEPOINT
:
441 lttng_event_put(event
->desc
);
443 case LTTNG_KERNEL_KPROBE
:
444 module_put(event
->desc
->owner
);
445 lttng_kprobes_destroy_private(event
);
447 case LTTNG_KERNEL_KRETPROBE
:
448 module_put(event
->desc
->owner
);
449 lttng_kretprobes_destroy_private(event
);
451 case LTTNG_KERNEL_FUNCTION
:
452 module_put(event
->desc
->owner
);
453 lttng_ftrace_destroy_private(event
);
455 case LTTNG_KERNEL_NOOP
:
460 list_del(&event
->list
);
461 lttng_destroy_context(event
->ctx
);
462 kmem_cache_free(event_cache
, event
);
466 * We have exclusive access to our metadata buffer (protected by the
467 * sessions_mutex), so we can do racy operations such as looking for
468 * remaining space left in packet and write, since mutual exclusion
469 * protects us from concurrent writes.
471 int lttng_metadata_printf(struct lttng_session
*session
,
472 const char *fmt
, ...)
474 struct lib_ring_buffer_ctx ctx
;
475 struct lttng_channel
*chan
= session
->metadata
;
477 int ret
= 0, waitret
;
478 size_t len
, reserve_len
, pos
;
481 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
484 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
492 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
493 reserve_len
= min_t(size_t,
494 chan
->ops
->packet_avail_size(chan
->chan
),
496 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
499 * We don't care about metadata buffer's records lost
500 * count, because we always retry here. Report error if
501 * we need to bail out after timeout or being
504 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
506 ret
= chan
->ops
->event_reserve(&ctx
, 0);
507 ret
!= -ENOBUFS
|| !ret
;
509 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
510 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
511 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
512 waitret
== -ERESTARTSYS
? "interrupted" :
513 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
514 if (waitret
== -ERESTARTSYS
)
518 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
519 chan
->ops
->event_commit(&ctx
);
527 int _lttng_field_statedump(struct lttng_session
*session
,
528 const struct lttng_event_field
*field
)
532 switch (field
->type
.atype
) {
534 ret
= lttng_metadata_printf(session
,
535 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
536 field
->type
.u
.basic
.integer
.size
,
537 field
->type
.u
.basic
.integer
.alignment
,
538 field
->type
.u
.basic
.integer
.signedness
,
539 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
541 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
544 field
->type
.u
.basic
.integer
.base
,
546 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
548 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
553 ret
= lttng_metadata_printf(session
,
555 field
->type
.u
.basic
.enumeration
.name
,
560 const struct lttng_basic_type
*elem_type
;
562 elem_type
= &field
->type
.u
.array
.elem_type
;
563 ret
= lttng_metadata_printf(session
,
564 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
565 elem_type
->u
.basic
.integer
.size
,
566 elem_type
->u
.basic
.integer
.alignment
,
567 elem_type
->u
.basic
.integer
.signedness
,
568 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
570 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
573 elem_type
->u
.basic
.integer
.base
,
575 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
577 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
579 field
->name
, field
->type
.u
.array
.length
);
584 const struct lttng_basic_type
*elem_type
;
585 const struct lttng_basic_type
*length_type
;
587 elem_type
= &field
->type
.u
.sequence
.elem_type
;
588 length_type
= &field
->type
.u
.sequence
.length_type
;
589 ret
= lttng_metadata_printf(session
,
590 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
591 length_type
->u
.basic
.integer
.size
,
592 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
593 length_type
->u
.basic
.integer
.signedness
,
594 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
596 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
599 length_type
->u
.basic
.integer
.base
,
601 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
603 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
609 ret
= lttng_metadata_printf(session
,
610 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
611 elem_type
->u
.basic
.integer
.size
,
612 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
613 elem_type
->u
.basic
.integer
.signedness
,
614 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
616 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
619 elem_type
->u
.basic
.integer
.base
,
621 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
623 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
631 /* Default encoding is UTF8 */
632 ret
= lttng_metadata_printf(session
,
634 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
635 " { encoding = ASCII; }" : "",
646 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
647 struct lttng_ctx
*ctx
)
654 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
655 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
657 ret
= _lttng_field_statedump(session
, &field
->event_field
);
665 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
666 struct lttng_event
*event
)
668 const struct lttng_event_desc
*desc
= event
->desc
;
672 for (i
= 0; i
< desc
->nr_fields
; i
++) {
673 const struct lttng_event_field
*field
= &desc
->fields
[i
];
675 ret
= _lttng_field_statedump(session
, field
);
683 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
684 struct lttng_channel
*chan
,
685 struct lttng_event
*event
)
689 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
691 if (chan
== session
->metadata
)
694 ret
= lttng_metadata_printf(session
,
698 " stream_id = %u;\n",
706 ret
= lttng_metadata_printf(session
,
707 " context := struct {\n");
711 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
715 ret
= lttng_metadata_printf(session
,
721 ret
= lttng_metadata_printf(session
,
722 " fields := struct {\n"
727 ret
= _lttng_fields_metadata_statedump(session
, event
);
732 * LTTng space reservation can only reserve multiples of the
735 ret
= lttng_metadata_printf(session
,
741 event
->metadata_dumped
= 1;
748 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
749 struct lttng_channel
*chan
)
753 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
755 if (chan
== session
->metadata
)
758 WARN_ON_ONCE(!chan
->header_type
);
759 ret
= lttng_metadata_printf(session
,
762 " event.header := %s;\n"
763 " packet.context := struct packet_context;\n",
765 chan
->header_type
== 1 ? "struct event_header_compact" :
766 "struct event_header_large");
771 ret
= lttng_metadata_printf(session
,
772 " event.context := struct {\n");
776 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
780 ret
= lttng_metadata_printf(session
,
786 ret
= lttng_metadata_printf(session
,
789 chan
->metadata_dumped
= 1;
795 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
797 return lttng_metadata_printf(session
,
798 "struct packet_context {\n"
799 " uint64_clock_monotonic_t timestamp_begin;\n"
800 " uint64_clock_monotonic_t timestamp_end;\n"
801 " uint32_t events_discarded;\n"
802 " uint32_t content_size;\n"
803 " uint32_t packet_size;\n"
804 " uint32_t cpu_id;\n"
812 * id 31 is reserved to indicate an extended header.
815 * id: range: 0 - 65534.
816 * id 65535 is reserved to indicate an extended header.
819 int _lttng_event_header_declare(struct lttng_session
*session
)
821 return lttng_metadata_printf(session
,
822 "struct event_header_compact {\n"
823 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
826 " uint27_clock_monotonic_t timestamp;\n"
830 " uint64_clock_monotonic_t timestamp;\n"
835 "struct event_header_large {\n"
836 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
839 " uint32_clock_monotonic_t timestamp;\n"
843 " uint64_clock_monotonic_t timestamp;\n"
847 lttng_alignof(uint32_t) * CHAR_BIT
,
848 lttng_alignof(uint16_t) * CHAR_BIT
853 * Approximation of NTP time of day to clock monotonic correlation,
854 * taken at start of trace.
855 * Yes, this is only an approximation. Yes, we can (and will) do better
856 * in future versions.
859 uint64_t measure_clock_offset(void)
861 uint64_t offset
, monotonic
[2], realtime
;
862 struct timespec rts
= { 0, 0 };
865 /* Disable interrupts to increase correlation precision. */
866 local_irq_save(flags
);
867 monotonic
[0] = trace_clock_read64();
868 getnstimeofday(&rts
);
869 monotonic
[1] = trace_clock_read64();
870 local_irq_restore(flags
);
872 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
873 realtime
= rts
.tv_sec
* NSEC_PER_SEC
;
874 realtime
+= rts
.tv_nsec
;
875 offset
= realtime
- offset
;
880 * Output metadata into this session's metadata buffers.
883 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
885 unsigned char *uuid_c
= session
->uuid
.b
;
886 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
887 struct lttng_channel
*chan
;
888 struct lttng_event
*event
;
891 if (!ACCESS_ONCE(session
->active
))
893 if (session
->metadata_dumped
)
895 if (!session
->metadata
) {
896 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
900 snprintf(uuid_s
, sizeof(uuid_s
),
901 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
902 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
903 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
904 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
905 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
907 ret
= lttng_metadata_printf(session
,
908 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
909 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
910 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
911 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
912 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
913 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
919 " byte_order = %s;\n"
920 " packet.header := struct {\n"
922 " uint8_t uuid[16];\n"
923 " uint32_t stream_id;\n"
926 lttng_alignof(uint8_t) * CHAR_BIT
,
927 lttng_alignof(uint16_t) * CHAR_BIT
,
928 lttng_alignof(uint32_t) * CHAR_BIT
,
929 lttng_alignof(uint64_t) * CHAR_BIT
,
942 ret
= lttng_metadata_printf(session
,
944 " domain = \"%s\";\n"
945 " sysname = \"%s\";\n"
946 " release = \"%s\";\n"
947 " version = \"%s\";\n"
957 ret
= lttng_metadata_printf(session
,
965 if (!trace_clock_uuid(clock_uuid_s
)) {
966 ret
= lttng_metadata_printf(session
,
974 ret
= lttng_metadata_printf(session
,
975 " description = \"Monotonic Clock\";\n"
976 " freq = %llu; /* Frequency, in Hz */\n"
977 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
980 (unsigned long long) trace_clock_freq(),
981 (unsigned long long) measure_clock_offset()
986 ret
= lttng_metadata_printf(session
,
987 "typealias integer {\n"
988 " size = 27; align = 1; signed = false;\n"
989 " map = clock.monotonic.value;\n"
990 "} := uint27_clock_monotonic_t;\n"
992 "typealias integer {\n"
993 " size = 32; align = %u; signed = false;\n"
994 " map = clock.monotonic.value;\n"
995 "} := uint32_clock_monotonic_t;\n"
997 "typealias integer {\n"
998 " size = 64; align = %u; signed = false;\n"
999 " map = clock.monotonic.value;\n"
1000 "} := uint64_clock_monotonic_t;\n\n",
1001 lttng_alignof(uint32_t) * CHAR_BIT
,
1002 lttng_alignof(uint64_t) * CHAR_BIT
1007 ret
= _lttng_stream_packet_context_declare(session
);
1011 ret
= _lttng_event_header_declare(session
);
1016 list_for_each_entry(chan
, &session
->chan
, list
) {
1017 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1022 list_for_each_entry(event
, &session
->events
, list
) {
1023 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1027 session
->metadata_dumped
= 1;
1033 * lttng_transport_register - LTT transport registration
1034 * @transport: transport structure
1036 * Registers a transport which can be used as output to extract the data out of
1037 * LTTng. The module calling this registration function must ensure that no
1038 * trap-inducing code will be executed by the transport functions. E.g.
1039 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1040 * is made visible to the transport function. This registration acts as a
1041 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1042 * after its registration must it synchronize the TLBs.
1044 void lttng_transport_register(struct lttng_transport
*transport
)
1047 * Make sure no page fault can be triggered by the module about to be
1048 * registered. We deal with this here so we don't have to call
1049 * vmalloc_sync_all() in each module's init.
1051 wrapper_vmalloc_sync_all();
1053 mutex_lock(&sessions_mutex
);
1054 list_add_tail(&transport
->node
, <tng_transport_list
);
1055 mutex_unlock(&sessions_mutex
);
1057 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1060 * lttng_transport_unregister - LTT transport unregistration
1061 * @transport: transport structure
1063 void lttng_transport_unregister(struct lttng_transport
*transport
)
1065 mutex_lock(&sessions_mutex
);
1066 list_del(&transport
->node
);
1067 mutex_unlock(&sessions_mutex
);
1069 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1071 static int __init
lttng_events_init(void)
1075 event_cache
= KMEM_CACHE(lttng_event
, 0);
1078 ret
= lttng_abi_init();
1083 kmem_cache_destroy(event_cache
);
1087 module_init(lttng_events_init
);
1089 static void __exit
lttng_events_exit(void)
1091 struct lttng_session
*session
, *tmpsession
;
1094 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1095 lttng_session_destroy(session
);
1096 kmem_cache_destroy(event_cache
);
1099 module_exit(lttng_events_exit
);
1101 MODULE_LICENSE("GPL and additional rights");
1102 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1103 MODULE_DESCRIPTION("LTTng Events");