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 "lttng-events.h"
34 #include "lttng-tracer.h"
36 static LIST_HEAD(sessions
);
37 static LIST_HEAD(lttng_transport_list
);
38 static DEFINE_MUTEX(sessions_mutex
);
39 static struct kmem_cache
*event_cache
;
41 static void _lttng_event_destroy(struct lttng_event
*event
);
42 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
43 static int _lttng_event_unregister(struct lttng_event
*event
);
45 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
46 struct lttng_channel
*chan
,
47 struct lttng_event
*event
);
49 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
51 void synchronize_trace(void)
54 #ifdef CONFIG_PREEMPT_RT
59 struct lttng_session
*lttng_session_create(void)
61 struct lttng_session
*session
;
63 mutex_lock(&sessions_mutex
);
64 session
= kzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
67 INIT_LIST_HEAD(&session
->chan
);
68 INIT_LIST_HEAD(&session
->events
);
69 uuid_le_gen(&session
->uuid
);
70 list_add(&session
->list
, &sessions
);
71 mutex_unlock(&sessions_mutex
);
75 void lttng_session_destroy(struct lttng_session
*session
)
77 struct lttng_channel
*chan
, *tmpchan
;
78 struct lttng_event
*event
, *tmpevent
;
81 mutex_lock(&sessions_mutex
);
82 ACCESS_ONCE(session
->active
) = 0;
83 list_for_each_entry(chan
, &session
->chan
, list
) {
84 ret
= lttng_syscalls_unregister(chan
);
87 list_for_each_entry(event
, &session
->events
, list
) {
88 ret
= _lttng_event_unregister(event
);
91 synchronize_trace(); /* Wait for in-flight events to complete */
92 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
93 _lttng_event_destroy(event
);
94 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
95 _lttng_channel_destroy(chan
);
96 list_del(&session
->list
);
97 mutex_unlock(&sessions_mutex
);
101 int lttng_session_enable(struct lttng_session
*session
)
104 struct lttng_channel
*chan
;
106 mutex_lock(&sessions_mutex
);
107 if (session
->active
) {
113 * Snapshot the number of events per channel to know the type of header
116 list_for_each_entry(chan
, &session
->chan
, list
) {
117 if (chan
->header_type
)
118 continue; /* don't change it if session stop/restart */
119 if (chan
->free_event_id
< 31)
120 chan
->header_type
= 1; /* compact */
122 chan
->header_type
= 2; /* large */
125 ACCESS_ONCE(session
->active
) = 1;
126 ACCESS_ONCE(session
->been_active
) = 1;
127 ret
= _lttng_session_metadata_statedump(session
);
129 ACCESS_ONCE(session
->active
) = 0;
132 ret
= lttng_statedump_start(session
);
134 ACCESS_ONCE(session
->active
) = 0;
136 mutex_unlock(&sessions_mutex
);
140 int lttng_session_disable(struct lttng_session
*session
)
144 mutex_lock(&sessions_mutex
);
145 if (!session
->active
) {
149 ACCESS_ONCE(session
->active
) = 0;
151 mutex_unlock(&sessions_mutex
);
155 int lttng_channel_enable(struct lttng_channel
*channel
)
159 if (channel
== channel
->session
->metadata
)
161 old
= xchg(&channel
->enabled
, 1);
167 int lttng_channel_disable(struct lttng_channel
*channel
)
171 if (channel
== channel
->session
->metadata
)
173 old
= xchg(&channel
->enabled
, 0);
179 int lttng_event_enable(struct lttng_event
*event
)
183 if (event
->chan
== event
->chan
->session
->metadata
)
185 old
= xchg(&event
->enabled
, 1);
191 int lttng_event_disable(struct lttng_event
*event
)
195 if (event
->chan
== event
->chan
->session
->metadata
)
197 old
= xchg(&event
->enabled
, 0);
203 static struct lttng_transport
*lttng_transport_find(const char *name
)
205 struct lttng_transport
*transport
;
207 list_for_each_entry(transport
, <tng_transport_list
, node
) {
208 if (!strcmp(transport
->name
, name
))
214 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
215 const char *transport_name
,
217 size_t subbuf_size
, size_t num_subbuf
,
218 unsigned int switch_timer_interval
,
219 unsigned int read_timer_interval
)
221 struct lttng_channel
*chan
;
222 struct lttng_transport
*transport
= NULL
;
224 mutex_lock(&sessions_mutex
);
225 if (session
->been_active
)
226 goto active
; /* Refuse to add channel to active session */
227 transport
= lttng_transport_find(transport_name
);
229 printk(KERN_WARNING
"LTTng transport %s not found\n",
233 if (!try_module_get(transport
->owner
)) {
234 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
237 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
240 chan
->session
= session
;
241 chan
->id
= session
->free_chan_id
++;
243 * Note: the channel creation op already writes into the packet
244 * headers. Therefore the "chan" information used as input
245 * should be already accessible.
247 chan
->chan
= transport
->ops
.channel_create(transport_name
,
248 chan
, buf_addr
, subbuf_size
, num_subbuf
,
249 switch_timer_interval
, read_timer_interval
);
253 chan
->ops
= &transport
->ops
;
254 chan
->transport
= transport
;
255 list_add(&chan
->list
, &session
->chan
);
256 mutex_unlock(&sessions_mutex
);
263 module_put(transport
->owner
);
266 mutex_unlock(&sessions_mutex
);
271 * Only used internally at session destruction.
274 void _lttng_channel_destroy(struct lttng_channel
*chan
)
276 chan
->ops
->channel_destroy(chan
->chan
);
277 module_put(chan
->transport
->owner
);
278 list_del(&chan
->list
);
279 lttng_destroy_context(chan
->ctx
);
284 * Supports event creation while tracing session is active.
286 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
287 struct lttng_kernel_event
*event_param
,
289 const struct lttng_event_desc
*internal_desc
)
291 struct lttng_event
*event
;
294 mutex_lock(&sessions_mutex
);
295 if (chan
->free_event_id
== -1UL)
298 * This is O(n^2) (for each event, the loop is called at event
299 * creation). Might require a hash if we have lots of events.
301 list_for_each_entry(event
, &chan
->session
->events
, list
)
302 if (!strcmp(event
->desc
->name
, event_param
->name
))
304 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
308 event
->filter
= filter
;
309 event
->id
= chan
->free_event_id
++;
311 event
->instrumentation
= event_param
->instrumentation
;
312 /* Populate lttng_event structure before tracepoint registration. */
314 switch (event_param
->instrumentation
) {
315 case LTTNG_KERNEL_TRACEPOINT
:
316 event
->desc
= lttng_event_get(event_param
->name
);
319 ret
= tracepoint_probe_register(event_param
->name
,
320 event
->desc
->probe_callback
,
325 case LTTNG_KERNEL_KPROBE
:
326 ret
= lttng_kprobes_register(event_param
->name
,
327 event_param
->u
.kprobe
.symbol_name
,
328 event_param
->u
.kprobe
.offset
,
329 event_param
->u
.kprobe
.addr
,
333 ret
= try_module_get(event
->desc
->owner
);
336 case LTTNG_KERNEL_KRETPROBE
:
338 struct lttng_event
*event_return
;
340 /* kretprobe defines 2 events */
342 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
345 event_return
->chan
= chan
;
346 event_return
->filter
= filter
;
347 event_return
->id
= chan
->free_event_id
++;
348 event_return
->enabled
= 1;
349 event_return
->instrumentation
= event_param
->instrumentation
;
351 * Populate lttng_event structure before kretprobe registration.
354 ret
= lttng_kretprobes_register(event_param
->name
,
355 event_param
->u
.kretprobe
.symbol_name
,
356 event_param
->u
.kretprobe
.offset
,
357 event_param
->u
.kretprobe
.addr
,
358 event
, event_return
);
360 kmem_cache_free(event_cache
, event_return
);
363 /* Take 2 refs on the module: one per event. */
364 ret
= try_module_get(event
->desc
->owner
);
366 ret
= try_module_get(event
->desc
->owner
);
368 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
371 kmem_cache_free(event_cache
, event_return
);
372 module_put(event
->desc
->owner
);
373 module_put(event
->desc
->owner
);
374 goto statedump_error
;
376 list_add(&event_return
->list
, &chan
->session
->events
);
379 case LTTNG_KERNEL_FUNCTION
:
380 ret
= lttng_ftrace_register(event_param
->name
,
381 event_param
->u
.ftrace
.symbol_name
,
385 ret
= try_module_get(event
->desc
->owner
);
388 case LTTNG_KERNEL_NOOP
:
389 event
->desc
= internal_desc
;
396 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
398 goto statedump_error
;
399 list_add(&event
->list
, &chan
->session
->events
);
400 mutex_unlock(&sessions_mutex
);
404 /* If a statedump error occurs, events will not be readable. */
406 kmem_cache_free(event_cache
, event
);
410 mutex_unlock(&sessions_mutex
);
415 * Only used internally at session destruction.
417 int _lttng_event_unregister(struct lttng_event
*event
)
421 switch (event
->instrumentation
) {
422 case LTTNG_KERNEL_TRACEPOINT
:
423 ret
= tracepoint_probe_unregister(event
->desc
->name
,
424 event
->desc
->probe_callback
,
429 case LTTNG_KERNEL_KPROBE
:
430 lttng_kprobes_unregister(event
);
433 case LTTNG_KERNEL_KRETPROBE
:
434 lttng_kretprobes_unregister(event
);
437 case LTTNG_KERNEL_FUNCTION
:
438 lttng_ftrace_unregister(event
);
441 case LTTNG_KERNEL_NOOP
:
451 * Only used internally at session destruction.
454 void _lttng_event_destroy(struct lttng_event
*event
)
456 switch (event
->instrumentation
) {
457 case LTTNG_KERNEL_TRACEPOINT
:
458 lttng_event_put(event
->desc
);
460 case LTTNG_KERNEL_KPROBE
:
461 module_put(event
->desc
->owner
);
462 lttng_kprobes_destroy_private(event
);
464 case LTTNG_KERNEL_KRETPROBE
:
465 module_put(event
->desc
->owner
);
466 lttng_kretprobes_destroy_private(event
);
468 case LTTNG_KERNEL_FUNCTION
:
469 module_put(event
->desc
->owner
);
470 lttng_ftrace_destroy_private(event
);
472 case LTTNG_KERNEL_NOOP
:
477 list_del(&event
->list
);
478 lttng_destroy_context(event
->ctx
);
479 kmem_cache_free(event_cache
, event
);
483 * We have exclusive access to our metadata buffer (protected by the
484 * sessions_mutex), so we can do racy operations such as looking for
485 * remaining space left in packet and write, since mutual exclusion
486 * protects us from concurrent writes.
488 int lttng_metadata_printf(struct lttng_session
*session
,
489 const char *fmt
, ...)
491 struct lib_ring_buffer_ctx ctx
;
492 struct lttng_channel
*chan
= session
->metadata
;
494 int ret
= 0, waitret
;
495 size_t len
, reserve_len
, pos
;
498 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
501 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
509 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
510 reserve_len
= min_t(size_t,
511 chan
->ops
->packet_avail_size(chan
->chan
),
513 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
516 * We don't care about metadata buffer's records lost
517 * count, because we always retry here. Report error if
518 * we need to bail out after timeout or being
521 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
523 ret
= chan
->ops
->event_reserve(&ctx
, 0);
524 ret
!= -ENOBUFS
|| !ret
;
526 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
527 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
528 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
529 waitret
== -ERESTARTSYS
? "interrupted" :
530 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
531 if (waitret
== -ERESTARTSYS
)
535 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
536 chan
->ops
->event_commit(&ctx
);
544 int _lttng_field_statedump(struct lttng_session
*session
,
545 const struct lttng_event_field
*field
)
549 switch (field
->type
.atype
) {
551 ret
= lttng_metadata_printf(session
,
552 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
553 field
->type
.u
.basic
.integer
.size
,
554 field
->type
.u
.basic
.integer
.alignment
,
555 field
->type
.u
.basic
.integer
.signedness
,
556 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
558 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
561 field
->type
.u
.basic
.integer
.base
,
563 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
565 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
570 ret
= lttng_metadata_printf(session
,
572 field
->type
.u
.basic
.enumeration
.name
,
577 const struct lttng_basic_type
*elem_type
;
579 elem_type
= &field
->type
.u
.array
.elem_type
;
580 ret
= lttng_metadata_printf(session
,
581 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
582 elem_type
->u
.basic
.integer
.size
,
583 elem_type
->u
.basic
.integer
.alignment
,
584 elem_type
->u
.basic
.integer
.signedness
,
585 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
587 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
590 elem_type
->u
.basic
.integer
.base
,
592 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
594 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
596 field
->name
, field
->type
.u
.array
.length
);
601 const struct lttng_basic_type
*elem_type
;
602 const struct lttng_basic_type
*length_type
;
604 elem_type
= &field
->type
.u
.sequence
.elem_type
;
605 length_type
= &field
->type
.u
.sequence
.length_type
;
606 ret
= lttng_metadata_printf(session
,
607 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
608 length_type
->u
.basic
.integer
.size
,
609 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
610 length_type
->u
.basic
.integer
.signedness
,
611 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
613 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
616 length_type
->u
.basic
.integer
.base
,
618 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
620 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
626 ret
= lttng_metadata_printf(session
,
627 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
628 elem_type
->u
.basic
.integer
.size
,
629 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
630 elem_type
->u
.basic
.integer
.signedness
,
631 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
633 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
636 elem_type
->u
.basic
.integer
.base
,
638 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
640 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
648 /* Default encoding is UTF8 */
649 ret
= lttng_metadata_printf(session
,
651 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
652 " { encoding = ASCII; }" : "",
663 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
664 struct lttng_ctx
*ctx
)
671 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
672 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
674 ret
= _lttng_field_statedump(session
, &field
->event_field
);
682 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
683 struct lttng_event
*event
)
685 const struct lttng_event_desc
*desc
= event
->desc
;
689 for (i
= 0; i
< desc
->nr_fields
; i
++) {
690 const struct lttng_event_field
*field
= &desc
->fields
[i
];
692 ret
= _lttng_field_statedump(session
, field
);
700 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
701 struct lttng_channel
*chan
,
702 struct lttng_event
*event
)
706 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
708 if (chan
== session
->metadata
)
711 ret
= lttng_metadata_printf(session
,
715 " stream_id = %u;\n",
723 ret
= lttng_metadata_printf(session
,
724 " context := struct {\n");
728 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
732 ret
= lttng_metadata_printf(session
,
738 ret
= lttng_metadata_printf(session
,
739 " fields := struct {\n"
744 ret
= _lttng_fields_metadata_statedump(session
, event
);
749 * LTTng space reservation can only reserve multiples of the
752 ret
= lttng_metadata_printf(session
,
758 event
->metadata_dumped
= 1;
765 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
766 struct lttng_channel
*chan
)
770 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
772 if (chan
== session
->metadata
)
775 WARN_ON_ONCE(!chan
->header_type
);
776 ret
= lttng_metadata_printf(session
,
779 " event.header := %s;\n"
780 " packet.context := struct packet_context;\n",
782 chan
->header_type
== 1 ? "struct event_header_compact" :
783 "struct event_header_large");
788 ret
= lttng_metadata_printf(session
,
789 " event.context := struct {\n");
793 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
797 ret
= lttng_metadata_printf(session
,
803 ret
= lttng_metadata_printf(session
,
806 chan
->metadata_dumped
= 1;
812 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
814 return lttng_metadata_printf(session
,
815 "struct packet_context {\n"
816 " uint64_clock_monotonic_t timestamp_begin;\n"
817 " uint64_clock_monotonic_t timestamp_end;\n"
818 " uint32_t events_discarded;\n"
819 " uint32_t content_size;\n"
820 " uint32_t packet_size;\n"
821 " uint32_t cpu_id;\n"
829 * id 31 is reserved to indicate an extended header.
832 * id: range: 0 - 65534.
833 * id 65535 is reserved to indicate an extended header.
836 int _lttng_event_header_declare(struct lttng_session
*session
)
838 return lttng_metadata_printf(session
,
839 "struct event_header_compact {\n"
840 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
843 " uint27_clock_monotonic_t timestamp;\n"
847 " uint64_clock_monotonic_t timestamp;\n"
852 "struct event_header_large {\n"
853 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
856 " uint32_clock_monotonic_t timestamp;\n"
860 " uint64_clock_monotonic_t timestamp;\n"
864 lttng_alignof(uint32_t) * CHAR_BIT
,
865 lttng_alignof(uint16_t) * CHAR_BIT
870 * Approximation of NTP time of day to clock monotonic correlation,
871 * taken at start of trace.
872 * Yes, this is only an approximation. Yes, we can (and will) do better
873 * in future versions.
876 uint64_t measure_clock_offset(void)
878 uint64_t offset
, monotonic
[2], realtime
;
879 struct timespec rts
= { 0, 0 };
882 /* Disable interrupts to increase correlation precision. */
883 local_irq_save(flags
);
884 monotonic
[0] = trace_clock_read64();
885 getnstimeofday(&rts
);
886 monotonic
[1] = trace_clock_read64();
887 local_irq_restore(flags
);
889 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
890 realtime
= (uint64_t) rts
.tv_sec
* NSEC_PER_SEC
;
891 realtime
+= rts
.tv_nsec
;
892 offset
= realtime
- offset
;
897 * Output metadata into this session's metadata buffers.
900 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
902 unsigned char *uuid_c
= session
->uuid
.b
;
903 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
904 struct lttng_channel
*chan
;
905 struct lttng_event
*event
;
908 if (!ACCESS_ONCE(session
->active
))
910 if (session
->metadata_dumped
)
912 if (!session
->metadata
) {
913 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
917 snprintf(uuid_s
, sizeof(uuid_s
),
918 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
919 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
920 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
921 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
922 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
924 ret
= lttng_metadata_printf(session
,
925 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
926 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
927 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
928 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
929 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
930 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
936 " byte_order = %s;\n"
937 " packet.header := struct {\n"
939 " uint8_t uuid[16];\n"
940 " uint32_t stream_id;\n"
943 lttng_alignof(uint8_t) * CHAR_BIT
,
944 lttng_alignof(uint16_t) * CHAR_BIT
,
945 lttng_alignof(uint32_t) * CHAR_BIT
,
946 lttng_alignof(uint64_t) * CHAR_BIT
,
959 ret
= lttng_metadata_printf(session
,
961 " domain = \"kernel\";\n"
962 " sysname = \"%s\";\n"
963 " kernel_release = \"%s\";\n"
964 " kernel_version = \"%s\";\n"
965 " tracer_name = \"lttng-modules\";\n"
966 " tracer_major = %d;\n"
967 " tracer_minor = %d;\n"
968 " tracer_patchlevel = %d;\n"
973 LTTNG_MODULES_MAJOR_VERSION
,
974 LTTNG_MODULES_MINOR_VERSION
,
975 LTTNG_MODULES_PATCHLEVEL_VERSION
980 ret
= lttng_metadata_printf(session
,
988 if (!trace_clock_uuid(clock_uuid_s
)) {
989 ret
= lttng_metadata_printf(session
,
997 ret
= lttng_metadata_printf(session
,
998 " description = \"Monotonic Clock\";\n"
999 " freq = %llu; /* Frequency, in Hz */\n"
1000 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1003 (unsigned long long) trace_clock_freq(),
1004 (unsigned long long) measure_clock_offset()
1009 ret
= lttng_metadata_printf(session
,
1010 "typealias integer {\n"
1011 " size = 27; align = 1; signed = false;\n"
1012 " map = clock.monotonic.value;\n"
1013 "} := uint27_clock_monotonic_t;\n"
1015 "typealias integer {\n"
1016 " size = 32; align = %u; signed = false;\n"
1017 " map = clock.monotonic.value;\n"
1018 "} := uint32_clock_monotonic_t;\n"
1020 "typealias integer {\n"
1021 " size = 64; align = %u; signed = false;\n"
1022 " map = clock.monotonic.value;\n"
1023 "} := uint64_clock_monotonic_t;\n\n",
1024 lttng_alignof(uint32_t) * CHAR_BIT
,
1025 lttng_alignof(uint64_t) * CHAR_BIT
1030 ret
= _lttng_stream_packet_context_declare(session
);
1034 ret
= _lttng_event_header_declare(session
);
1039 list_for_each_entry(chan
, &session
->chan
, list
) {
1040 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1045 list_for_each_entry(event
, &session
->events
, list
) {
1046 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1050 session
->metadata_dumped
= 1;
1056 * lttng_transport_register - LTT transport registration
1057 * @transport: transport structure
1059 * Registers a transport which can be used as output to extract the data out of
1060 * LTTng. The module calling this registration function must ensure that no
1061 * trap-inducing code will be executed by the transport functions. E.g.
1062 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1063 * is made visible to the transport function. This registration acts as a
1064 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1065 * after its registration must it synchronize the TLBs.
1067 void lttng_transport_register(struct lttng_transport
*transport
)
1070 * Make sure no page fault can be triggered by the module about to be
1071 * registered. We deal with this here so we don't have to call
1072 * vmalloc_sync_all() in each module's init.
1074 wrapper_vmalloc_sync_all();
1076 mutex_lock(&sessions_mutex
);
1077 list_add_tail(&transport
->node
, <tng_transport_list
);
1078 mutex_unlock(&sessions_mutex
);
1080 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1083 * lttng_transport_unregister - LTT transport unregistration
1084 * @transport: transport structure
1086 void lttng_transport_unregister(struct lttng_transport
*transport
)
1088 mutex_lock(&sessions_mutex
);
1089 list_del(&transport
->node
);
1090 mutex_unlock(&sessions_mutex
);
1092 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1094 static int __init
lttng_events_init(void)
1098 event_cache
= KMEM_CACHE(lttng_event
, 0);
1101 ret
= lttng_abi_init();
1106 kmem_cache_destroy(event_cache
);
1110 module_init(lttng_events_init
);
1112 static void __exit
lttng_events_exit(void)
1114 struct lttng_session
*session
, *tmpsession
;
1117 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1118 lttng_session_destroy(session
);
1119 kmem_cache_destroy(event_cache
);
1122 module_exit(lttng_events_exit
);
1124 MODULE_LICENSE("GPL and additional rights");
1125 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1126 MODULE_DESCRIPTION("LTTng Events");