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;
120 ret
= lttng_statedump_start(session
);
122 ACCESS_ONCE(session
->active
) = 0;
124 mutex_unlock(&sessions_mutex
);
128 int lttng_session_disable(struct lttng_session
*session
)
132 mutex_lock(&sessions_mutex
);
133 if (!session
->active
) {
137 ACCESS_ONCE(session
->active
) = 0;
139 mutex_unlock(&sessions_mutex
);
143 int lttng_channel_enable(struct lttng_channel
*channel
)
147 if (channel
== channel
->session
->metadata
)
149 old
= xchg(&channel
->enabled
, 1);
155 int lttng_channel_disable(struct lttng_channel
*channel
)
159 if (channel
== channel
->session
->metadata
)
161 old
= xchg(&channel
->enabled
, 0);
167 int lttng_event_enable(struct lttng_event
*event
)
171 if (event
->chan
== event
->chan
->session
->metadata
)
173 old
= xchg(&event
->enabled
, 1);
179 int lttng_event_disable(struct lttng_event
*event
)
183 if (event
->chan
== event
->chan
->session
->metadata
)
185 old
= xchg(&event
->enabled
, 0);
191 static struct lttng_transport
*lttng_transport_find(const char *name
)
193 struct lttng_transport
*transport
;
195 list_for_each_entry(transport
, <tng_transport_list
, node
) {
196 if (!strcmp(transport
->name
, name
))
202 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
203 const char *transport_name
,
205 size_t subbuf_size
, size_t num_subbuf
,
206 unsigned int switch_timer_interval
,
207 unsigned int read_timer_interval
)
209 struct lttng_channel
*chan
;
210 struct lttng_transport
*transport
= NULL
;
212 mutex_lock(&sessions_mutex
);
213 if (session
->been_active
)
214 goto active
; /* Refuse to add channel to active session */
215 transport
= lttng_transport_find(transport_name
);
217 printk(KERN_WARNING
"LTTng transport %s not found\n",
221 if (!try_module_get(transport
->owner
)) {
222 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
225 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
228 chan
->session
= session
;
229 chan
->id
= session
->free_chan_id
++;
231 * Note: the channel creation op already writes into the packet
232 * headers. Therefore the "chan" information used as input
233 * should be already accessible.
235 chan
->chan
= transport
->ops
.channel_create("[lttng]", chan
, buf_addr
,
236 subbuf_size
, num_subbuf
, switch_timer_interval
,
237 read_timer_interval
);
241 chan
->ops
= &transport
->ops
;
242 chan
->transport
= transport
;
243 list_add(&chan
->list
, &session
->chan
);
244 mutex_unlock(&sessions_mutex
);
251 module_put(transport
->owner
);
254 mutex_unlock(&sessions_mutex
);
259 * Only used internally at session destruction.
262 void _lttng_channel_destroy(struct lttng_channel
*chan
)
264 chan
->ops
->channel_destroy(chan
->chan
);
265 module_put(chan
->transport
->owner
);
266 list_del(&chan
->list
);
267 lttng_destroy_context(chan
->ctx
);
272 * Supports event creation while tracing session is active.
274 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
275 struct lttng_kernel_event
*event_param
,
277 const struct lttng_event_desc
*internal_desc
)
279 struct lttng_event
*event
;
282 mutex_lock(&sessions_mutex
);
283 if (chan
->free_event_id
== -1UL)
286 * This is O(n^2) (for each event, the loop is called at event
287 * creation). Might require a hash if we have lots of events.
289 list_for_each_entry(event
, &chan
->session
->events
, list
)
290 if (!strcmp(event
->desc
->name
, event_param
->name
))
292 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
296 event
->filter
= filter
;
297 event
->id
= chan
->free_event_id
++;
299 event
->instrumentation
= event_param
->instrumentation
;
300 /* Populate lttng_event structure before tracepoint registration. */
302 switch (event_param
->instrumentation
) {
303 case LTTNG_KERNEL_TRACEPOINT
:
304 event
->desc
= lttng_event_get(event_param
->name
);
307 ret
= tracepoint_probe_register(event_param
->name
,
308 event
->desc
->probe_callback
,
313 case LTTNG_KERNEL_KPROBE
:
314 ret
= lttng_kprobes_register(event_param
->name
,
315 event_param
->u
.kprobe
.symbol_name
,
316 event_param
->u
.kprobe
.offset
,
317 event_param
->u
.kprobe
.addr
,
321 ret
= try_module_get(event
->desc
->owner
);
324 case LTTNG_KERNEL_KRETPROBE
:
326 struct lttng_event
*event_return
;
328 /* kretprobe defines 2 events */
330 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
333 event_return
->chan
= chan
;
334 event_return
->filter
= filter
;
335 event_return
->id
= chan
->free_event_id
++;
336 event_return
->enabled
= 1;
337 event_return
->instrumentation
= event_param
->instrumentation
;
339 * Populate lttng_event structure before kretprobe registration.
342 ret
= lttng_kretprobes_register(event_param
->name
,
343 event_param
->u
.kretprobe
.symbol_name
,
344 event_param
->u
.kretprobe
.offset
,
345 event_param
->u
.kretprobe
.addr
,
346 event
, event_return
);
348 kmem_cache_free(event_cache
, event_return
);
351 /* Take 2 refs on the module: one per event. */
352 ret
= try_module_get(event
->desc
->owner
);
354 ret
= try_module_get(event
->desc
->owner
);
356 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
359 kmem_cache_free(event_cache
, event_return
);
360 module_put(event
->desc
->owner
);
361 module_put(event
->desc
->owner
);
362 goto statedump_error
;
364 list_add(&event_return
->list
, &chan
->session
->events
);
367 case LTTNG_KERNEL_FUNCTION
:
368 ret
= lttng_ftrace_register(event_param
->name
,
369 event_param
->u
.ftrace
.symbol_name
,
373 ret
= try_module_get(event
->desc
->owner
);
376 case LTTNG_KERNEL_NOOP
:
377 event
->desc
= internal_desc
;
384 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
386 goto statedump_error
;
387 list_add(&event
->list
, &chan
->session
->events
);
388 mutex_unlock(&sessions_mutex
);
392 /* If a statedump error occurs, events will not be readable. */
394 kmem_cache_free(event_cache
, event
);
398 mutex_unlock(&sessions_mutex
);
403 * Only used internally at session destruction.
405 int _lttng_event_unregister(struct lttng_event
*event
)
409 switch (event
->instrumentation
) {
410 case LTTNG_KERNEL_TRACEPOINT
:
411 ret
= tracepoint_probe_unregister(event
->desc
->name
,
412 event
->desc
->probe_callback
,
417 case LTTNG_KERNEL_KPROBE
:
418 lttng_kprobes_unregister(event
);
421 case LTTNG_KERNEL_KRETPROBE
:
422 lttng_kretprobes_unregister(event
);
425 case LTTNG_KERNEL_FUNCTION
:
426 lttng_ftrace_unregister(event
);
429 case LTTNG_KERNEL_NOOP
:
439 * Only used internally at session destruction.
442 void _lttng_event_destroy(struct lttng_event
*event
)
444 switch (event
->instrumentation
) {
445 case LTTNG_KERNEL_TRACEPOINT
:
446 lttng_event_put(event
->desc
);
448 case LTTNG_KERNEL_KPROBE
:
449 module_put(event
->desc
->owner
);
450 lttng_kprobes_destroy_private(event
);
452 case LTTNG_KERNEL_KRETPROBE
:
453 module_put(event
->desc
->owner
);
454 lttng_kretprobes_destroy_private(event
);
456 case LTTNG_KERNEL_FUNCTION
:
457 module_put(event
->desc
->owner
);
458 lttng_ftrace_destroy_private(event
);
460 case LTTNG_KERNEL_NOOP
:
465 list_del(&event
->list
);
466 lttng_destroy_context(event
->ctx
);
467 kmem_cache_free(event_cache
, event
);
471 * We have exclusive access to our metadata buffer (protected by the
472 * sessions_mutex), so we can do racy operations such as looking for
473 * remaining space left in packet and write, since mutual exclusion
474 * protects us from concurrent writes.
476 int lttng_metadata_printf(struct lttng_session
*session
,
477 const char *fmt
, ...)
479 struct lib_ring_buffer_ctx ctx
;
480 struct lttng_channel
*chan
= session
->metadata
;
482 int ret
= 0, waitret
;
483 size_t len
, reserve_len
, pos
;
486 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
489 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
497 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
498 reserve_len
= min_t(size_t,
499 chan
->ops
->packet_avail_size(chan
->chan
),
501 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
504 * We don't care about metadata buffer's records lost
505 * count, because we always retry here. Report error if
506 * we need to bail out after timeout or being
509 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
511 ret
= chan
->ops
->event_reserve(&ctx
, 0);
512 ret
!= -ENOBUFS
|| !ret
;
514 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
515 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
516 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
517 waitret
== -ERESTARTSYS
? "interrupted" :
518 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
519 if (waitret
== -ERESTARTSYS
)
523 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
524 chan
->ops
->event_commit(&ctx
);
532 int _lttng_field_statedump(struct lttng_session
*session
,
533 const struct lttng_event_field
*field
)
537 switch (field
->type
.atype
) {
539 ret
= lttng_metadata_printf(session
,
540 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
541 field
->type
.u
.basic
.integer
.size
,
542 field
->type
.u
.basic
.integer
.alignment
,
543 field
->type
.u
.basic
.integer
.signedness
,
544 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
546 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
549 field
->type
.u
.basic
.integer
.base
,
551 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
553 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
558 ret
= lttng_metadata_printf(session
,
560 field
->type
.u
.basic
.enumeration
.name
,
565 const struct lttng_basic_type
*elem_type
;
567 elem_type
= &field
->type
.u
.array
.elem_type
;
568 ret
= lttng_metadata_printf(session
,
569 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
570 elem_type
->u
.basic
.integer
.size
,
571 elem_type
->u
.basic
.integer
.alignment
,
572 elem_type
->u
.basic
.integer
.signedness
,
573 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
575 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
578 elem_type
->u
.basic
.integer
.base
,
580 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
582 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
584 field
->name
, field
->type
.u
.array
.length
);
589 const struct lttng_basic_type
*elem_type
;
590 const struct lttng_basic_type
*length_type
;
592 elem_type
= &field
->type
.u
.sequence
.elem_type
;
593 length_type
= &field
->type
.u
.sequence
.length_type
;
594 ret
= lttng_metadata_printf(session
,
595 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
596 length_type
->u
.basic
.integer
.size
,
597 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
598 length_type
->u
.basic
.integer
.signedness
,
599 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
601 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
604 length_type
->u
.basic
.integer
.base
,
606 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
608 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
614 ret
= lttng_metadata_printf(session
,
615 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
616 elem_type
->u
.basic
.integer
.size
,
617 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
618 elem_type
->u
.basic
.integer
.signedness
,
619 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
621 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
624 elem_type
->u
.basic
.integer
.base
,
626 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
628 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
636 /* Default encoding is UTF8 */
637 ret
= lttng_metadata_printf(session
,
639 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
640 " { encoding = ASCII; }" : "",
651 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
652 struct lttng_ctx
*ctx
)
659 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
660 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
662 ret
= _lttng_field_statedump(session
, &field
->event_field
);
670 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
671 struct lttng_event
*event
)
673 const struct lttng_event_desc
*desc
= event
->desc
;
677 for (i
= 0; i
< desc
->nr_fields
; i
++) {
678 const struct lttng_event_field
*field
= &desc
->fields
[i
];
680 ret
= _lttng_field_statedump(session
, field
);
688 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
689 struct lttng_channel
*chan
,
690 struct lttng_event
*event
)
694 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
696 if (chan
== session
->metadata
)
699 ret
= lttng_metadata_printf(session
,
703 " stream_id = %u;\n",
711 ret
= lttng_metadata_printf(session
,
712 " context := struct {\n");
716 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
720 ret
= lttng_metadata_printf(session
,
726 ret
= lttng_metadata_printf(session
,
727 " fields := struct {\n"
732 ret
= _lttng_fields_metadata_statedump(session
, event
);
737 * LTTng space reservation can only reserve multiples of the
740 ret
= lttng_metadata_printf(session
,
746 event
->metadata_dumped
= 1;
753 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
754 struct lttng_channel
*chan
)
758 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
760 if (chan
== session
->metadata
)
763 WARN_ON_ONCE(!chan
->header_type
);
764 ret
= lttng_metadata_printf(session
,
767 " event.header := %s;\n"
768 " packet.context := struct packet_context;\n",
770 chan
->header_type
== 1 ? "struct event_header_compact" :
771 "struct event_header_large");
776 ret
= lttng_metadata_printf(session
,
777 " event.context := struct {\n");
781 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
785 ret
= lttng_metadata_printf(session
,
791 ret
= lttng_metadata_printf(session
,
794 chan
->metadata_dumped
= 1;
800 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
802 return lttng_metadata_printf(session
,
803 "struct packet_context {\n"
804 " uint64_clock_monotonic_t timestamp_begin;\n"
805 " uint64_clock_monotonic_t timestamp_end;\n"
806 " uint32_t events_discarded;\n"
807 " uint32_t content_size;\n"
808 " uint32_t packet_size;\n"
809 " uint32_t cpu_id;\n"
817 * id 31 is reserved to indicate an extended header.
820 * id: range: 0 - 65534.
821 * id 65535 is reserved to indicate an extended header.
824 int _lttng_event_header_declare(struct lttng_session
*session
)
826 return lttng_metadata_printf(session
,
827 "struct event_header_compact {\n"
828 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
831 " uint27_clock_monotonic_t timestamp;\n"
835 " uint64_clock_monotonic_t timestamp;\n"
840 "struct event_header_large {\n"
841 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
844 " uint32_clock_monotonic_t timestamp;\n"
848 " uint64_clock_monotonic_t timestamp;\n"
852 lttng_alignof(uint32_t) * CHAR_BIT
,
853 lttng_alignof(uint16_t) * CHAR_BIT
858 * Approximation of NTP time of day to clock monotonic correlation,
859 * taken at start of trace.
860 * Yes, this is only an approximation. Yes, we can (and will) do better
861 * in future versions.
864 uint64_t measure_clock_offset(void)
866 uint64_t offset
, monotonic
[2], realtime
;
867 struct timespec rts
= { 0, 0 };
870 /* Disable interrupts to increase correlation precision. */
871 local_irq_save(flags
);
872 monotonic
[0] = trace_clock_read64();
873 getnstimeofday(&rts
);
874 monotonic
[1] = trace_clock_read64();
875 local_irq_restore(flags
);
877 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
878 realtime
= rts
.tv_sec
* NSEC_PER_SEC
;
879 realtime
+= rts
.tv_nsec
;
880 offset
= realtime
- offset
;
885 * Output metadata into this session's metadata buffers.
888 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
890 unsigned char *uuid_c
= session
->uuid
.b
;
891 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
892 struct lttng_channel
*chan
;
893 struct lttng_event
*event
;
896 if (!ACCESS_ONCE(session
->active
))
898 if (session
->metadata_dumped
)
900 if (!session
->metadata
) {
901 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
905 snprintf(uuid_s
, sizeof(uuid_s
),
906 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
907 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
908 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
909 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
910 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
912 ret
= lttng_metadata_printf(session
,
913 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
914 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
915 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
916 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
917 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
918 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
924 " byte_order = %s;\n"
925 " packet.header := struct {\n"
927 " uint8_t uuid[16];\n"
928 " uint32_t stream_id;\n"
931 lttng_alignof(uint8_t) * CHAR_BIT
,
932 lttng_alignof(uint16_t) * CHAR_BIT
,
933 lttng_alignof(uint32_t) * CHAR_BIT
,
934 lttng_alignof(uint64_t) * CHAR_BIT
,
947 ret
= lttng_metadata_printf(session
,
949 " domain = \"%s\";\n"
950 " sysname = \"%s\";\n"
951 " release = \"%s\";\n"
952 " version = \"%s\";\n"
962 ret
= lttng_metadata_printf(session
,
970 if (!trace_clock_uuid(clock_uuid_s
)) {
971 ret
= lttng_metadata_printf(session
,
979 ret
= lttng_metadata_printf(session
,
980 " description = \"Monotonic Clock\";\n"
981 " freq = %llu; /* Frequency, in Hz */\n"
982 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
985 (unsigned long long) trace_clock_freq(),
986 (unsigned long long) measure_clock_offset()
991 ret
= lttng_metadata_printf(session
,
992 "typealias integer {\n"
993 " size = 27; align = 1; signed = false;\n"
994 " map = clock.monotonic.value;\n"
995 "} := uint27_clock_monotonic_t;\n"
997 "typealias integer {\n"
998 " size = 32; align = %u; signed = false;\n"
999 " map = clock.monotonic.value;\n"
1000 "} := uint32_clock_monotonic_t;\n"
1002 "typealias integer {\n"
1003 " size = 64; align = %u; signed = false;\n"
1004 " map = clock.monotonic.value;\n"
1005 "} := uint64_clock_monotonic_t;\n\n",
1006 lttng_alignof(uint32_t) * CHAR_BIT
,
1007 lttng_alignof(uint64_t) * CHAR_BIT
1012 ret
= _lttng_stream_packet_context_declare(session
);
1016 ret
= _lttng_event_header_declare(session
);
1021 list_for_each_entry(chan
, &session
->chan
, list
) {
1022 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1027 list_for_each_entry(event
, &session
->events
, list
) {
1028 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1032 session
->metadata_dumped
= 1;
1038 * lttng_transport_register - LTT transport registration
1039 * @transport: transport structure
1041 * Registers a transport which can be used as output to extract the data out of
1042 * LTTng. The module calling this registration function must ensure that no
1043 * trap-inducing code will be executed by the transport functions. E.g.
1044 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1045 * is made visible to the transport function. This registration acts as a
1046 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1047 * after its registration must it synchronize the TLBs.
1049 void lttng_transport_register(struct lttng_transport
*transport
)
1052 * Make sure no page fault can be triggered by the module about to be
1053 * registered. We deal with this here so we don't have to call
1054 * vmalloc_sync_all() in each module's init.
1056 wrapper_vmalloc_sync_all();
1058 mutex_lock(&sessions_mutex
);
1059 list_add_tail(&transport
->node
, <tng_transport_list
);
1060 mutex_unlock(&sessions_mutex
);
1062 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1065 * lttng_transport_unregister - LTT transport unregistration
1066 * @transport: transport structure
1068 void lttng_transport_unregister(struct lttng_transport
*transport
)
1070 mutex_lock(&sessions_mutex
);
1071 list_del(&transport
->node
);
1072 mutex_unlock(&sessions_mutex
);
1074 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1076 static int __init
lttng_events_init(void)
1080 event_cache
= KMEM_CACHE(lttng_event
, 0);
1083 ret
= lttng_abi_init();
1088 kmem_cache_destroy(event_cache
);
1092 module_init(lttng_events_init
);
1094 static void __exit
lttng_events_exit(void)
1096 struct lttng_session
*session
, *tmpsession
;
1099 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1100 lttng_session_destroy(session
);
1101 kmem_cache_destroy(event_cache
);
1104 module_exit(lttng_events_exit
);
1106 MODULE_LICENSE("GPL and additional rights");
1107 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1108 MODULE_DESCRIPTION("LTTng Events");