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 "wrapper/uuid.h"
18 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
19 #include "wrapper/random.h"
20 #include "lttng-events.h"
21 #include "lttng-tracer.h"
23 static LIST_HEAD(sessions
);
24 static LIST_HEAD(lttng_transport_list
);
25 static DEFINE_MUTEX(sessions_mutex
);
26 static struct kmem_cache
*event_cache
;
28 static void _lttng_event_destroy(struct lttng_event
*event
);
29 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
30 static int _lttng_event_unregister(struct lttng_event
*event
);
32 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
33 struct lttng_channel
*chan
,
34 struct lttng_event
*event
);
36 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
38 void synchronize_trace(void)
41 #ifdef CONFIG_PREEMPT_RT
46 struct lttng_session
*lttng_session_create(void)
48 struct lttng_session
*session
;
50 mutex_lock(&sessions_mutex
);
51 session
= kzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
54 INIT_LIST_HEAD(&session
->chan
);
55 INIT_LIST_HEAD(&session
->events
);
56 uuid_le_gen(&session
->uuid
);
57 list_add(&session
->list
, &sessions
);
58 mutex_unlock(&sessions_mutex
);
62 void lttng_session_destroy(struct lttng_session
*session
)
64 struct lttng_channel
*chan
, *tmpchan
;
65 struct lttng_event
*event
, *tmpevent
;
68 mutex_lock(&sessions_mutex
);
69 ACCESS_ONCE(session
->active
) = 0;
70 list_for_each_entry(chan
, &session
->chan
, list
) {
71 ret
= lttng_syscalls_unregister(chan
);
74 list_for_each_entry(event
, &session
->events
, list
) {
75 ret
= _lttng_event_unregister(event
);
78 synchronize_trace(); /* Wait for in-flight events to complete */
79 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
80 _lttng_event_destroy(event
);
81 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
82 _lttng_channel_destroy(chan
);
83 list_del(&session
->list
);
84 mutex_unlock(&sessions_mutex
);
88 int lttng_session_enable(struct lttng_session
*session
)
91 struct lttng_channel
*chan
;
93 mutex_lock(&sessions_mutex
);
94 if (session
->active
) {
100 * Snapshot the number of events per channel to know the type of header
103 list_for_each_entry(chan
, &session
->chan
, list
) {
104 if (chan
->header_type
)
105 continue; /* don't change it if session stop/restart */
106 if (chan
->free_event_id
< 31)
107 chan
->header_type
= 1; /* compact */
109 chan
->header_type
= 2; /* large */
112 ACCESS_ONCE(session
->active
) = 1;
113 ACCESS_ONCE(session
->been_active
) = 1;
114 ret
= _lttng_session_metadata_statedump(session
);
116 ACCESS_ONCE(session
->active
) = 0;
118 mutex_unlock(&sessions_mutex
);
122 int lttng_session_disable(struct lttng_session
*session
)
126 mutex_lock(&sessions_mutex
);
127 if (!session
->active
) {
131 ACCESS_ONCE(session
->active
) = 0;
133 mutex_unlock(&sessions_mutex
);
137 int lttng_channel_enable(struct lttng_channel
*channel
)
141 if (channel
== channel
->session
->metadata
)
143 old
= xchg(&channel
->enabled
, 1);
149 int lttng_channel_disable(struct lttng_channel
*channel
)
153 if (channel
== channel
->session
->metadata
)
155 old
= xchg(&channel
->enabled
, 0);
161 int lttng_event_enable(struct lttng_event
*event
)
165 if (event
->chan
== event
->chan
->session
->metadata
)
167 old
= xchg(&event
->enabled
, 1);
173 int lttng_event_disable(struct lttng_event
*event
)
177 if (event
->chan
== event
->chan
->session
->metadata
)
179 old
= xchg(&event
->enabled
, 0);
185 static struct lttng_transport
*lttng_transport_find(const char *name
)
187 struct lttng_transport
*transport
;
189 list_for_each_entry(transport
, <tng_transport_list
, node
) {
190 if (!strcmp(transport
->name
, name
))
196 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
197 const char *transport_name
,
199 size_t subbuf_size
, size_t num_subbuf
,
200 unsigned int switch_timer_interval
,
201 unsigned int read_timer_interval
)
203 struct lttng_channel
*chan
;
204 struct lttng_transport
*transport
= NULL
;
206 mutex_lock(&sessions_mutex
);
207 if (session
->been_active
)
208 goto active
; /* Refuse to add channel to active session */
209 transport
= lttng_transport_find(transport_name
);
211 printk(KERN_WARNING
"LTTng transport %s not found\n",
215 if (!try_module_get(transport
->owner
)) {
216 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
219 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
222 chan
->session
= session
;
223 chan
->id
= session
->free_chan_id
++;
225 * Note: the channel creation op already writes into the packet
226 * headers. Therefore the "chan" information used as input
227 * should be already accessible.
229 chan
->chan
= transport
->ops
.channel_create("[lttng]", chan
, buf_addr
,
230 subbuf_size
, num_subbuf
, switch_timer_interval
,
231 read_timer_interval
);
235 chan
->ops
= &transport
->ops
;
236 chan
->transport
= transport
;
237 list_add(&chan
->list
, &session
->chan
);
238 mutex_unlock(&sessions_mutex
);
245 module_put(transport
->owner
);
248 mutex_unlock(&sessions_mutex
);
253 * Only used internally at session destruction.
256 void _lttng_channel_destroy(struct lttng_channel
*chan
)
258 chan
->ops
->channel_destroy(chan
->chan
);
259 module_put(chan
->transport
->owner
);
260 list_del(&chan
->list
);
261 lttng_destroy_context(chan
->ctx
);
266 * Supports event creation while tracing session is active.
268 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
269 struct lttng_kernel_event
*event_param
,
271 const struct lttng_event_desc
*internal_desc
)
273 struct lttng_event
*event
;
276 mutex_lock(&sessions_mutex
);
277 if (chan
->free_event_id
== -1UL)
280 * This is O(n^2) (for each event, the loop is called at event
281 * creation). Might require a hash if we have lots of events.
283 list_for_each_entry(event
, &chan
->session
->events
, list
)
284 if (!strcmp(event
->desc
->name
, event_param
->name
))
286 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
290 event
->filter
= filter
;
291 event
->id
= chan
->free_event_id
++;
293 event
->instrumentation
= event_param
->instrumentation
;
294 /* Populate lttng_event structure before tracepoint registration. */
296 switch (event_param
->instrumentation
) {
297 case LTTNG_KERNEL_TRACEPOINT
:
298 event
->desc
= lttng_event_get(event_param
->name
);
301 ret
= tracepoint_probe_register(event_param
->name
,
302 event
->desc
->probe_callback
,
307 case LTTNG_KERNEL_KPROBE
:
308 ret
= lttng_kprobes_register(event_param
->name
,
309 event_param
->u
.kprobe
.symbol_name
,
310 event_param
->u
.kprobe
.offset
,
311 event_param
->u
.kprobe
.addr
,
315 ret
= try_module_get(event
->desc
->owner
);
318 case LTTNG_KERNEL_KRETPROBE
:
320 struct lttng_event
*event_return
;
322 /* kretprobe defines 2 events */
324 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
327 event_return
->chan
= chan
;
328 event_return
->filter
= filter
;
329 event_return
->id
= chan
->free_event_id
++;
330 event_return
->enabled
= 1;
331 event_return
->instrumentation
= event_param
->instrumentation
;
333 * Populate lttng_event structure before kretprobe registration.
336 ret
= lttng_kretprobes_register(event_param
->name
,
337 event_param
->u
.kretprobe
.symbol_name
,
338 event_param
->u
.kretprobe
.offset
,
339 event_param
->u
.kretprobe
.addr
,
340 event
, event_return
);
342 kmem_cache_free(event_cache
, event_return
);
345 /* Take 2 refs on the module: one per event. */
346 ret
= try_module_get(event
->desc
->owner
);
348 ret
= try_module_get(event
->desc
->owner
);
350 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
353 kmem_cache_free(event_cache
, event_return
);
354 module_put(event
->desc
->owner
);
355 module_put(event
->desc
->owner
);
356 goto statedump_error
;
358 list_add(&event_return
->list
, &chan
->session
->events
);
361 case LTTNG_KERNEL_FUNCTION
:
362 ret
= lttng_ftrace_register(event_param
->name
,
363 event_param
->u
.ftrace
.symbol_name
,
367 ret
= try_module_get(event
->desc
->owner
);
370 case LTTNG_KERNEL_NOOP
:
371 event
->desc
= internal_desc
;
378 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
380 goto statedump_error
;
381 list_add(&event
->list
, &chan
->session
->events
);
382 mutex_unlock(&sessions_mutex
);
386 /* If a statedump error occurs, events will not be readable. */
388 kmem_cache_free(event_cache
, event
);
392 mutex_unlock(&sessions_mutex
);
397 * Only used internally at session destruction.
399 int _lttng_event_unregister(struct lttng_event
*event
)
403 switch (event
->instrumentation
) {
404 case LTTNG_KERNEL_TRACEPOINT
:
405 ret
= tracepoint_probe_unregister(event
->desc
->name
,
406 event
->desc
->probe_callback
,
411 case LTTNG_KERNEL_KPROBE
:
412 lttng_kprobes_unregister(event
);
415 case LTTNG_KERNEL_KRETPROBE
:
416 lttng_kretprobes_unregister(event
);
419 case LTTNG_KERNEL_FUNCTION
:
420 lttng_ftrace_unregister(event
);
423 case LTTNG_KERNEL_NOOP
:
433 * Only used internally at session destruction.
436 void _lttng_event_destroy(struct lttng_event
*event
)
438 switch (event
->instrumentation
) {
439 case LTTNG_KERNEL_TRACEPOINT
:
440 lttng_event_put(event
->desc
);
442 case LTTNG_KERNEL_KPROBE
:
443 module_put(event
->desc
->owner
);
444 lttng_kprobes_destroy_private(event
);
446 case LTTNG_KERNEL_KRETPROBE
:
447 module_put(event
->desc
->owner
);
448 lttng_kretprobes_destroy_private(event
);
450 case LTTNG_KERNEL_FUNCTION
:
451 module_put(event
->desc
->owner
);
452 lttng_ftrace_destroy_private(event
);
454 case LTTNG_KERNEL_NOOP
:
459 list_del(&event
->list
);
460 lttng_destroy_context(event
->ctx
);
461 kmem_cache_free(event_cache
, event
);
465 * We have exclusive access to our metadata buffer (protected by the
466 * sessions_mutex), so we can do racy operations such as looking for
467 * remaining space left in packet and write, since mutual exclusion
468 * protects us from concurrent writes.
470 int lttng_metadata_printf(struct lttng_session
*session
,
471 const char *fmt
, ...)
473 struct lib_ring_buffer_ctx ctx
;
474 struct lttng_channel
*chan
= session
->metadata
;
476 int ret
= 0, waitret
;
477 size_t len
, reserve_len
, pos
;
480 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
483 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
491 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
492 reserve_len
= min_t(size_t,
493 chan
->ops
->packet_avail_size(chan
->chan
),
495 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
498 * We don't care about metadata buffer's records lost
499 * count, because we always retry here. Report error if
500 * we need to bail out after timeout or being
503 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
505 ret
= chan
->ops
->event_reserve(&ctx
, 0);
506 ret
!= -ENOBUFS
|| !ret
;
508 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
509 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
510 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
511 waitret
== -ERESTARTSYS
? "interrupted" :
512 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
513 if (waitret
== -ERESTARTSYS
)
517 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
518 chan
->ops
->event_commit(&ctx
);
526 int _lttng_field_statedump(struct lttng_session
*session
,
527 const struct lttng_event_field
*field
)
531 switch (field
->type
.atype
) {
533 ret
= lttng_metadata_printf(session
,
534 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
535 field
->type
.u
.basic
.integer
.size
,
536 field
->type
.u
.basic
.integer
.alignment
,
537 field
->type
.u
.basic
.integer
.signedness
,
538 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
540 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
543 field
->type
.u
.basic
.integer
.base
,
545 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
547 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
552 ret
= lttng_metadata_printf(session
,
554 field
->type
.u
.basic
.enumeration
.name
,
559 const struct lttng_basic_type
*elem_type
;
561 elem_type
= &field
->type
.u
.array
.elem_type
;
562 ret
= lttng_metadata_printf(session
,
563 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
564 elem_type
->u
.basic
.integer
.size
,
565 elem_type
->u
.basic
.integer
.alignment
,
566 elem_type
->u
.basic
.integer
.signedness
,
567 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
569 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
572 elem_type
->u
.basic
.integer
.base
,
574 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
576 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
578 field
->name
, field
->type
.u
.array
.length
);
583 const struct lttng_basic_type
*elem_type
;
584 const struct lttng_basic_type
*length_type
;
586 elem_type
= &field
->type
.u
.sequence
.elem_type
;
587 length_type
= &field
->type
.u
.sequence
.length_type
;
588 ret
= lttng_metadata_printf(session
,
589 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
590 length_type
->u
.basic
.integer
.size
,
591 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
592 length_type
->u
.basic
.integer
.signedness
,
593 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
595 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
598 length_type
->u
.basic
.integer
.base
,
600 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
602 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
608 ret
= lttng_metadata_printf(session
,
609 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
610 elem_type
->u
.basic
.integer
.size
,
611 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
612 elem_type
->u
.basic
.integer
.signedness
,
613 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
615 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
618 elem_type
->u
.basic
.integer
.base
,
620 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
622 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
630 /* Default encoding is UTF8 */
631 ret
= lttng_metadata_printf(session
,
633 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
634 " { encoding = ASCII; }" : "",
645 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
646 struct lttng_ctx
*ctx
)
653 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
654 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
656 ret
= _lttng_field_statedump(session
, &field
->event_field
);
664 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
665 struct lttng_event
*event
)
667 const struct lttng_event_desc
*desc
= event
->desc
;
671 for (i
= 0; i
< desc
->nr_fields
; i
++) {
672 const struct lttng_event_field
*field
= &desc
->fields
[i
];
674 ret
= _lttng_field_statedump(session
, field
);
682 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
683 struct lttng_channel
*chan
,
684 struct lttng_event
*event
)
688 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
690 if (chan
== session
->metadata
)
693 ret
= lttng_metadata_printf(session
,
697 " stream_id = %u;\n",
705 ret
= lttng_metadata_printf(session
,
706 " context := struct {\n");
710 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
714 ret
= lttng_metadata_printf(session
,
720 ret
= lttng_metadata_printf(session
,
721 " fields := struct {\n"
726 ret
= _lttng_fields_metadata_statedump(session
, event
);
731 * LTTng space reservation can only reserve multiples of the
734 ret
= lttng_metadata_printf(session
,
740 event
->metadata_dumped
= 1;
747 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
748 struct lttng_channel
*chan
)
752 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
754 if (chan
== session
->metadata
)
757 WARN_ON_ONCE(!chan
->header_type
);
758 ret
= lttng_metadata_printf(session
,
761 " event.header := %s;\n"
762 " packet.context := struct packet_context;\n",
764 chan
->header_type
== 1 ? "struct event_header_compact" :
765 "struct event_header_large");
770 ret
= lttng_metadata_printf(session
,
771 " event.context := struct {\n");
775 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
779 ret
= lttng_metadata_printf(session
,
785 ret
= lttng_metadata_printf(session
,
788 chan
->metadata_dumped
= 1;
794 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
796 return lttng_metadata_printf(session
,
797 "struct packet_context {\n"
798 " uint64_clock_monotonic_t timestamp_begin;\n"
799 " uint64_clock_monotonic_t timestamp_end;\n"
800 " uint32_t events_discarded;\n"
801 " uint32_t content_size;\n"
802 " uint32_t packet_size;\n"
803 " uint32_t cpu_id;\n"
811 * id 31 is reserved to indicate an extended header.
814 * id: range: 0 - 65534.
815 * id 65535 is reserved to indicate an extended header.
818 int _lttng_event_header_declare(struct lttng_session
*session
)
820 return lttng_metadata_printf(session
,
821 "struct event_header_compact {\n"
822 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
825 " uint27_clock_monotonic_t timestamp;\n"
829 " uint64_clock_monotonic_t timestamp;\n"
834 "struct event_header_large {\n"
835 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
838 " uint32_clock_monotonic_t timestamp;\n"
842 " uint64_clock_monotonic_t timestamp;\n"
846 lttng_alignof(uint32_t) * CHAR_BIT
,
847 lttng_alignof(uint16_t) * CHAR_BIT
852 * Approximation of NTP time of day to clock monotonic correlation,
853 * taken at start of trace.
854 * Yes, this is only an approximation. Yes, we can (and will) do better
855 * in future versions.
858 uint64_t measure_clock_offset(void)
860 uint64_t offset
, monotonic
[2], realtime
;
861 struct timespec rts
= { 0, 0 };
864 /* Disable interrupts to increase correlation precision. */
865 local_irq_save(flags
);
866 monotonic
[0] = trace_clock_read64();
867 getnstimeofday(&rts
);
868 monotonic
[1] = trace_clock_read64();
869 local_irq_restore(flags
);
871 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
872 realtime
= rts
.tv_sec
* NSEC_PER_SEC
;
873 realtime
+= rts
.tv_nsec
;
874 offset
= realtime
- offset
;
879 * Output metadata into this session's metadata buffers.
882 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
884 unsigned char *uuid_c
= session
->uuid
.b
;
885 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
886 struct lttng_channel
*chan
;
887 struct lttng_event
*event
;
890 if (!ACCESS_ONCE(session
->active
))
892 if (session
->metadata_dumped
)
894 if (!session
->metadata
) {
895 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
899 snprintf(uuid_s
, sizeof(uuid_s
),
900 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
901 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
902 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
903 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
904 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
906 ret
= lttng_metadata_printf(session
,
907 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
908 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
909 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
910 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
911 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
912 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
918 " byte_order = %s;\n"
919 " packet.header := struct {\n"
921 " uint8_t uuid[16];\n"
922 " uint32_t stream_id;\n"
925 lttng_alignof(uint8_t) * CHAR_BIT
,
926 lttng_alignof(uint16_t) * CHAR_BIT
,
927 lttng_alignof(uint32_t) * CHAR_BIT
,
928 lttng_alignof(uint64_t) * CHAR_BIT
,
941 ret
= lttng_metadata_printf(session
,
949 if (!trace_clock_uuid(clock_uuid_s
)) {
950 ret
= lttng_metadata_printf(session
,
958 ret
= lttng_metadata_printf(session
,
959 " description = \"Monotonic Clock\";\n"
960 " freq = %llu; /* Frequency, in Hz */\n"
961 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
964 (unsigned long long) trace_clock_freq(),
965 (unsigned long long) measure_clock_offset()
970 ret
= lttng_metadata_printf(session
,
971 "typealias integer {\n"
972 " size = 27; align = 1; signed = false;\n"
973 " map = clock.monotonic.value;\n"
974 "} := uint27_clock_monotonic_t;\n"
976 "typealias integer {\n"
977 " size = 32; align = %u; signed = false;\n"
978 " map = clock.monotonic.value;\n"
979 "} := uint32_clock_monotonic_t;\n"
981 "typealias integer {\n"
982 " size = 64; align = %u; signed = false;\n"
983 " map = clock.monotonic.value;\n"
984 "} := uint64_clock_monotonic_t;\n\n",
985 lttng_alignof(uint32_t) * CHAR_BIT
,
986 lttng_alignof(uint64_t) * CHAR_BIT
991 ret
= _lttng_stream_packet_context_declare(session
);
995 ret
= _lttng_event_header_declare(session
);
1000 list_for_each_entry(chan
, &session
->chan
, list
) {
1001 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1006 list_for_each_entry(event
, &session
->events
, list
) {
1007 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1011 session
->metadata_dumped
= 1;
1017 * lttng_transport_register - LTT transport registration
1018 * @transport: transport structure
1020 * Registers a transport which can be used as output to extract the data out of
1021 * LTTng. The module calling this registration function must ensure that no
1022 * trap-inducing code will be executed by the transport functions. E.g.
1023 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1024 * is made visible to the transport function. This registration acts as a
1025 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1026 * after its registration must it synchronize the TLBs.
1028 void lttng_transport_register(struct lttng_transport
*transport
)
1031 * Make sure no page fault can be triggered by the module about to be
1032 * registered. We deal with this here so we don't have to call
1033 * vmalloc_sync_all() in each module's init.
1035 wrapper_vmalloc_sync_all();
1037 mutex_lock(&sessions_mutex
);
1038 list_add_tail(&transport
->node
, <tng_transport_list
);
1039 mutex_unlock(&sessions_mutex
);
1041 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1044 * lttng_transport_unregister - LTT transport unregistration
1045 * @transport: transport structure
1047 void lttng_transport_unregister(struct lttng_transport
*transport
)
1049 mutex_lock(&sessions_mutex
);
1050 list_del(&transport
->node
);
1051 mutex_unlock(&sessions_mutex
);
1053 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1055 static int __init
lttng_events_init(void)
1059 event_cache
= KMEM_CACHE(lttng_event
, 0);
1062 ret
= lttng_abi_init();
1067 kmem_cache_destroy(event_cache
);
1071 module_init(lttng_events_init
);
1073 static void __exit
lttng_events_exit(void)
1075 struct lttng_session
*session
, *tmpsession
;
1078 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1079 lttng_session_destroy(session
);
1080 kmem_cache_destroy(event_cache
);
1083 module_exit(lttng_events_exit
);
1085 MODULE_LICENSE("GPL and additional rights");
1086 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1087 MODULE_DESCRIPTION("LTTng Events");