4 * Holds LTTng per-session event registry.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <linux/mutex.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/jiffies.h>
29 #include <linux/utsname.h>
30 #include "wrapper/uuid.h"
31 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
32 #include "wrapper/random.h"
33 #include "wrapper/tracepoint.h"
34 #include "lttng-events.h"
35 #include "lttng-tracer.h"
36 #include "lttng-abi-old.h"
38 static LIST_HEAD(sessions
);
39 static LIST_HEAD(lttng_transport_list
);
40 static DEFINE_MUTEX(sessions_mutex
);
41 static struct kmem_cache
*event_cache
;
43 static void _lttng_event_destroy(struct lttng_event
*event
);
44 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
45 static int _lttng_event_unregister(struct lttng_event
*event
);
47 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
48 struct lttng_channel
*chan
,
49 struct lttng_event
*event
);
51 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
53 void synchronize_trace(void)
56 #ifdef CONFIG_PREEMPT_RT
61 struct lttng_session
*lttng_session_create(void)
63 struct lttng_session
*session
;
65 mutex_lock(&sessions_mutex
);
66 session
= kzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
69 INIT_LIST_HEAD(&session
->chan
);
70 INIT_LIST_HEAD(&session
->events
);
71 uuid_le_gen(&session
->uuid
);
72 list_add(&session
->list
, &sessions
);
73 mutex_unlock(&sessions_mutex
);
77 void lttng_session_destroy(struct lttng_session
*session
)
79 struct lttng_channel
*chan
, *tmpchan
;
80 struct lttng_event
*event
, *tmpevent
;
83 mutex_lock(&sessions_mutex
);
84 ACCESS_ONCE(session
->active
) = 0;
85 list_for_each_entry(chan
, &session
->chan
, list
) {
86 ret
= lttng_syscalls_unregister(chan
);
89 list_for_each_entry(event
, &session
->events
, list
) {
90 ret
= _lttng_event_unregister(event
);
93 synchronize_trace(); /* Wait for in-flight events to complete */
94 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
95 _lttng_event_destroy(event
);
96 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
97 _lttng_channel_destroy(chan
);
98 list_del(&session
->list
);
99 mutex_unlock(&sessions_mutex
);
103 int lttng_session_enable(struct lttng_session
*session
)
106 struct lttng_channel
*chan
;
108 mutex_lock(&sessions_mutex
);
109 if (session
->active
) {
115 * Snapshot the number of events per channel to know the type of header
118 list_for_each_entry(chan
, &session
->chan
, list
) {
119 if (chan
->header_type
)
120 continue; /* don't change it if session stop/restart */
121 if (chan
->free_event_id
< 31)
122 chan
->header_type
= 1; /* compact */
124 chan
->header_type
= 2; /* large */
127 ACCESS_ONCE(session
->active
) = 1;
128 ACCESS_ONCE(session
->been_active
) = 1;
129 ret
= _lttng_session_metadata_statedump(session
);
131 ACCESS_ONCE(session
->active
) = 0;
134 ret
= lttng_statedump_start(session
);
136 ACCESS_ONCE(session
->active
) = 0;
138 mutex_unlock(&sessions_mutex
);
142 int lttng_session_disable(struct lttng_session
*session
)
146 mutex_lock(&sessions_mutex
);
147 if (!session
->active
) {
151 ACCESS_ONCE(session
->active
) = 0;
153 mutex_unlock(&sessions_mutex
);
157 int lttng_channel_enable(struct lttng_channel
*channel
)
161 if (channel
== channel
->session
->metadata
)
163 old
= xchg(&channel
->enabled
, 1);
169 int lttng_channel_disable(struct lttng_channel
*channel
)
173 if (channel
== channel
->session
->metadata
)
175 old
= xchg(&channel
->enabled
, 0);
181 int lttng_event_enable(struct lttng_event
*event
)
185 if (event
->chan
== event
->chan
->session
->metadata
)
187 old
= xchg(&event
->enabled
, 1);
193 int lttng_event_disable(struct lttng_event
*event
)
197 if (event
->chan
== event
->chan
->session
->metadata
)
199 old
= xchg(&event
->enabled
, 0);
205 static struct lttng_transport
*lttng_transport_find(const char *name
)
207 struct lttng_transport
*transport
;
209 list_for_each_entry(transport
, <tng_transport_list
, node
) {
210 if (!strcmp(transport
->name
, name
))
216 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
217 const char *transport_name
,
219 size_t subbuf_size
, size_t num_subbuf
,
220 unsigned int switch_timer_interval
,
221 unsigned int read_timer_interval
)
223 struct lttng_channel
*chan
;
224 struct lttng_transport
*transport
= NULL
;
226 mutex_lock(&sessions_mutex
);
227 if (session
->been_active
)
228 goto active
; /* Refuse to add channel to active session */
229 transport
= lttng_transport_find(transport_name
);
231 printk(KERN_WARNING
"LTTng transport %s not found\n",
235 if (!try_module_get(transport
->owner
)) {
236 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
239 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
242 chan
->session
= session
;
243 chan
->id
= session
->free_chan_id
++;
245 * Note: the channel creation op already writes into the packet
246 * headers. Therefore the "chan" information used as input
247 * should be already accessible.
249 chan
->chan
= transport
->ops
.channel_create(transport_name
,
250 chan
, buf_addr
, subbuf_size
, num_subbuf
,
251 switch_timer_interval
, read_timer_interval
);
255 chan
->ops
= &transport
->ops
;
256 chan
->transport
= transport
;
257 list_add(&chan
->list
, &session
->chan
);
258 mutex_unlock(&sessions_mutex
);
265 module_put(transport
->owner
);
268 mutex_unlock(&sessions_mutex
);
273 * Only used internally at session destruction.
276 void _lttng_channel_destroy(struct lttng_channel
*chan
)
278 chan
->ops
->channel_destroy(chan
->chan
);
279 module_put(chan
->transport
->owner
);
280 list_del(&chan
->list
);
281 lttng_destroy_context(chan
->ctx
);
286 * Supports event creation while tracing session is active.
288 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
289 struct lttng_kernel_event
*event_param
,
291 const struct lttng_event_desc
*internal_desc
)
293 struct lttng_event
*event
;
296 mutex_lock(&sessions_mutex
);
297 if (chan
->free_event_id
== -1U)
300 * This is O(n^2) (for each event, the loop is called at event
301 * creation). Might require a hash if we have lots of events.
303 list_for_each_entry(event
, &chan
->session
->events
, list
)
304 if (!strcmp(event
->desc
->name
, event_param
->name
))
306 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
310 event
->filter
= filter
;
311 event
->id
= chan
->free_event_id
++;
313 event
->instrumentation
= event_param
->instrumentation
;
314 /* Populate lttng_event structure before tracepoint registration. */
316 switch (event_param
->instrumentation
) {
317 case LTTNG_KERNEL_TRACEPOINT
:
318 event
->desc
= lttng_event_get(event_param
->name
);
321 ret
= kabi_2635_tracepoint_probe_register(event_param
->name
,
322 event
->desc
->probe_callback
,
327 case LTTNG_KERNEL_KPROBE
:
328 ret
= lttng_kprobes_register(event_param
->name
,
329 event_param
->u
.kprobe
.symbol_name
,
330 event_param
->u
.kprobe
.offset
,
331 event_param
->u
.kprobe
.addr
,
335 ret
= try_module_get(event
->desc
->owner
);
338 case LTTNG_KERNEL_KRETPROBE
:
340 struct lttng_event
*event_return
;
342 /* kretprobe defines 2 events */
344 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
347 event_return
->chan
= chan
;
348 event_return
->filter
= filter
;
349 event_return
->id
= chan
->free_event_id
++;
350 event_return
->enabled
= 1;
351 event_return
->instrumentation
= event_param
->instrumentation
;
353 * Populate lttng_event structure before kretprobe registration.
356 ret
= lttng_kretprobes_register(event_param
->name
,
357 event_param
->u
.kretprobe
.symbol_name
,
358 event_param
->u
.kretprobe
.offset
,
359 event_param
->u
.kretprobe
.addr
,
360 event
, event_return
);
362 kmem_cache_free(event_cache
, event_return
);
365 /* Take 2 refs on the module: one per event. */
366 ret
= try_module_get(event
->desc
->owner
);
368 ret
= try_module_get(event
->desc
->owner
);
370 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
373 kmem_cache_free(event_cache
, event_return
);
374 module_put(event
->desc
->owner
);
375 module_put(event
->desc
->owner
);
376 goto statedump_error
;
378 list_add(&event_return
->list
, &chan
->session
->events
);
381 case LTTNG_KERNEL_FUNCTION
:
382 ret
= lttng_ftrace_register(event_param
->name
,
383 event_param
->u
.ftrace
.symbol_name
,
387 ret
= try_module_get(event
->desc
->owner
);
390 case LTTNG_KERNEL_NOOP
:
391 event
->desc
= internal_desc
;
398 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
400 goto statedump_error
;
401 list_add(&event
->list
, &chan
->session
->events
);
402 mutex_unlock(&sessions_mutex
);
406 /* If a statedump error occurs, events will not be readable. */
408 kmem_cache_free(event_cache
, event
);
412 mutex_unlock(&sessions_mutex
);
417 * Only used internally at session destruction.
419 int _lttng_event_unregister(struct lttng_event
*event
)
423 switch (event
->instrumentation
) {
424 case LTTNG_KERNEL_TRACEPOINT
:
425 ret
= kabi_2635_tracepoint_probe_unregister(event
->desc
->name
,
426 event
->desc
->probe_callback
,
431 case LTTNG_KERNEL_KPROBE
:
432 lttng_kprobes_unregister(event
);
435 case LTTNG_KERNEL_KRETPROBE
:
436 lttng_kretprobes_unregister(event
);
439 case LTTNG_KERNEL_FUNCTION
:
440 lttng_ftrace_unregister(event
);
443 case LTTNG_KERNEL_NOOP
:
453 * Only used internally at session destruction.
456 void _lttng_event_destroy(struct lttng_event
*event
)
458 switch (event
->instrumentation
) {
459 case LTTNG_KERNEL_TRACEPOINT
:
460 lttng_event_put(event
->desc
);
462 case LTTNG_KERNEL_KPROBE
:
463 module_put(event
->desc
->owner
);
464 lttng_kprobes_destroy_private(event
);
466 case LTTNG_KERNEL_KRETPROBE
:
467 module_put(event
->desc
->owner
);
468 lttng_kretprobes_destroy_private(event
);
470 case LTTNG_KERNEL_FUNCTION
:
471 module_put(event
->desc
->owner
);
472 lttng_ftrace_destroy_private(event
);
474 case LTTNG_KERNEL_NOOP
:
479 list_del(&event
->list
);
480 lttng_destroy_context(event
->ctx
);
481 kmem_cache_free(event_cache
, event
);
485 * We have exclusive access to our metadata buffer (protected by the
486 * sessions_mutex), so we can do racy operations such as looking for
487 * remaining space left in packet and write, since mutual exclusion
488 * protects us from concurrent writes.
490 int lttng_metadata_printf(struct lttng_session
*session
,
491 const char *fmt
, ...)
493 struct lib_ring_buffer_ctx ctx
;
494 struct lttng_channel
*chan
= session
->metadata
;
496 int ret
= 0, waitret
;
497 size_t len
, reserve_len
, pos
;
500 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
503 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
511 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
512 reserve_len
= min_t(size_t,
513 chan
->ops
->packet_avail_size(chan
->chan
),
515 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
518 * We don't care about metadata buffer's records lost
519 * count, because we always retry here. Report error if
520 * we need to bail out after timeout or being
523 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
525 ret
= chan
->ops
->event_reserve(&ctx
, 0);
526 ret
!= -ENOBUFS
|| !ret
;
528 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
529 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
530 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
531 waitret
== -ERESTARTSYS
? "interrupted" :
532 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
533 if (waitret
== -ERESTARTSYS
)
537 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
538 chan
->ops
->event_commit(&ctx
);
546 int _lttng_field_statedump(struct lttng_session
*session
,
547 const struct lttng_event_field
*field
)
551 switch (field
->type
.atype
) {
553 ret
= lttng_metadata_printf(session
,
554 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
555 field
->type
.u
.basic
.integer
.size
,
556 field
->type
.u
.basic
.integer
.alignment
,
557 field
->type
.u
.basic
.integer
.signedness
,
558 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
560 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
563 field
->type
.u
.basic
.integer
.base
,
565 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
567 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
572 ret
= lttng_metadata_printf(session
,
574 field
->type
.u
.basic
.enumeration
.name
,
579 const struct lttng_basic_type
*elem_type
;
581 elem_type
= &field
->type
.u
.array
.elem_type
;
582 ret
= lttng_metadata_printf(session
,
583 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
584 elem_type
->u
.basic
.integer
.size
,
585 elem_type
->u
.basic
.integer
.alignment
,
586 elem_type
->u
.basic
.integer
.signedness
,
587 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
589 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
592 elem_type
->u
.basic
.integer
.base
,
594 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
596 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
598 field
->name
, field
->type
.u
.array
.length
);
603 const struct lttng_basic_type
*elem_type
;
604 const struct lttng_basic_type
*length_type
;
606 elem_type
= &field
->type
.u
.sequence
.elem_type
;
607 length_type
= &field
->type
.u
.sequence
.length_type
;
608 ret
= lttng_metadata_printf(session
,
609 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
610 length_type
->u
.basic
.integer
.size
,
611 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
612 length_type
->u
.basic
.integer
.signedness
,
613 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
615 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
618 length_type
->u
.basic
.integer
.base
,
620 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
622 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
628 ret
= lttng_metadata_printf(session
,
629 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
630 elem_type
->u
.basic
.integer
.size
,
631 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
632 elem_type
->u
.basic
.integer
.signedness
,
633 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
635 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
638 elem_type
->u
.basic
.integer
.base
,
640 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
642 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
650 /* Default encoding is UTF8 */
651 ret
= lttng_metadata_printf(session
,
653 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
654 " { encoding = ASCII; }" : "",
665 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
666 struct lttng_ctx
*ctx
)
673 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
674 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
676 ret
= _lttng_field_statedump(session
, &field
->event_field
);
684 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
685 struct lttng_event
*event
)
687 const struct lttng_event_desc
*desc
= event
->desc
;
691 for (i
= 0; i
< desc
->nr_fields
; i
++) {
692 const struct lttng_event_field
*field
= &desc
->fields
[i
];
694 ret
= _lttng_field_statedump(session
, field
);
702 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
703 struct lttng_channel
*chan
,
704 struct lttng_event
*event
)
708 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
710 if (chan
== session
->metadata
)
713 ret
= lttng_metadata_printf(session
,
717 " stream_id = %u;\n",
725 ret
= lttng_metadata_printf(session
,
726 " context := struct {\n");
730 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
734 ret
= lttng_metadata_printf(session
,
740 ret
= lttng_metadata_printf(session
,
741 " fields := struct {\n"
746 ret
= _lttng_fields_metadata_statedump(session
, event
);
751 * LTTng space reservation can only reserve multiples of the
754 ret
= lttng_metadata_printf(session
,
760 event
->metadata_dumped
= 1;
767 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
768 struct lttng_channel
*chan
)
772 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
774 if (chan
== session
->metadata
)
777 WARN_ON_ONCE(!chan
->header_type
);
778 ret
= lttng_metadata_printf(session
,
781 " event.header := %s;\n"
782 " packet.context := struct packet_context;\n",
784 chan
->header_type
== 1 ? "struct event_header_compact" :
785 "struct event_header_large");
790 ret
= lttng_metadata_printf(session
,
791 " event.context := struct {\n");
795 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
799 ret
= lttng_metadata_printf(session
,
805 ret
= lttng_metadata_printf(session
,
808 chan
->metadata_dumped
= 1;
814 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
816 return lttng_metadata_printf(session
,
817 "struct packet_context {\n"
818 " uint64_clock_monotonic_t timestamp_begin;\n"
819 " uint64_clock_monotonic_t timestamp_end;\n"
820 " uint64_t content_size;\n"
821 " uint64_t packet_size;\n"
822 " unsigned long events_discarded;\n"
823 " uint32_t cpu_id;\n"
831 * id 31 is reserved to indicate an extended header.
834 * id: range: 0 - 65534.
835 * id 65535 is reserved to indicate an extended header.
838 int _lttng_event_header_declare(struct lttng_session
*session
)
840 return lttng_metadata_printf(session
,
841 "struct event_header_compact {\n"
842 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
845 " uint27_clock_monotonic_t timestamp;\n"
849 " uint64_clock_monotonic_t timestamp;\n"
854 "struct event_header_large {\n"
855 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
858 " uint32_clock_monotonic_t timestamp;\n"
862 " uint64_clock_monotonic_t timestamp;\n"
866 lttng_alignof(uint32_t) * CHAR_BIT
,
867 lttng_alignof(uint16_t) * CHAR_BIT
872 * Approximation of NTP time of day to clock monotonic correlation,
873 * taken at start of trace.
874 * Yes, this is only an approximation. Yes, we can (and will) do better
875 * in future versions.
878 uint64_t measure_clock_offset(void)
880 uint64_t offset
, monotonic
[2], realtime
;
881 struct timespec rts
= { 0, 0 };
884 /* Disable interrupts to increase correlation precision. */
885 local_irq_save(flags
);
886 monotonic
[0] = trace_clock_read64();
887 getnstimeofday(&rts
);
888 monotonic
[1] = trace_clock_read64();
889 local_irq_restore(flags
);
891 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
892 realtime
= (uint64_t) rts
.tv_sec
* NSEC_PER_SEC
;
893 realtime
+= rts
.tv_nsec
;
894 offset
= realtime
- offset
;
899 * Output metadata into this session's metadata buffers.
902 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
904 unsigned char *uuid_c
= session
->uuid
.b
;
905 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
906 struct lttng_channel
*chan
;
907 struct lttng_event
*event
;
910 if (!ACCESS_ONCE(session
->active
))
912 if (session
->metadata_dumped
)
914 if (!session
->metadata
) {
915 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
919 snprintf(uuid_s
, sizeof(uuid_s
),
920 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
921 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
922 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
923 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
924 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
926 ret
= lttng_metadata_printf(session
,
927 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
928 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
929 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
930 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
931 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
932 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
933 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
939 " byte_order = %s;\n"
940 " packet.header := struct {\n"
942 " uint8_t uuid[16];\n"
943 " uint32_t stream_id;\n"
946 lttng_alignof(uint8_t) * CHAR_BIT
,
947 lttng_alignof(uint16_t) * CHAR_BIT
,
948 lttng_alignof(uint32_t) * CHAR_BIT
,
949 lttng_alignof(uint64_t) * CHAR_BIT
,
950 sizeof(unsigned long) * CHAR_BIT
,
951 lttng_alignof(unsigned long) * CHAR_BIT
,
964 ret
= lttng_metadata_printf(session
,
966 " hostname = \"%s\";\n"
967 " domain = \"kernel\";\n"
968 " sysname = \"%s\";\n"
969 " kernel_release = \"%s\";\n"
970 " kernel_version = \"%s\";\n"
971 " tracer_name = \"lttng-modules\";\n"
972 " tracer_major = %d;\n"
973 " tracer_minor = %d;\n"
974 " tracer_patchlevel = %d;\n"
976 current
->nsproxy
->uts_ns
->name
.nodename
,
980 LTTNG_MODULES_MAJOR_VERSION
,
981 LTTNG_MODULES_MINOR_VERSION
,
982 LTTNG_MODULES_PATCHLEVEL_VERSION
987 ret
= lttng_metadata_printf(session
,
995 if (!trace_clock_uuid(clock_uuid_s
)) {
996 ret
= lttng_metadata_printf(session
,
1004 ret
= lttng_metadata_printf(session
,
1005 " description = \"Monotonic Clock\";\n"
1006 " freq = %llu; /* Frequency, in Hz */\n"
1007 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1010 (unsigned long long) trace_clock_freq(),
1011 (unsigned long long) measure_clock_offset()
1016 ret
= lttng_metadata_printf(session
,
1017 "typealias integer {\n"
1018 " size = 27; align = 1; signed = false;\n"
1019 " map = clock.monotonic.value;\n"
1020 "} := uint27_clock_monotonic_t;\n"
1022 "typealias integer {\n"
1023 " size = 32; align = %u; signed = false;\n"
1024 " map = clock.monotonic.value;\n"
1025 "} := uint32_clock_monotonic_t;\n"
1027 "typealias integer {\n"
1028 " size = 64; align = %u; signed = false;\n"
1029 " map = clock.monotonic.value;\n"
1030 "} := uint64_clock_monotonic_t;\n\n",
1031 lttng_alignof(uint32_t) * CHAR_BIT
,
1032 lttng_alignof(uint64_t) * CHAR_BIT
1037 ret
= _lttng_stream_packet_context_declare(session
);
1041 ret
= _lttng_event_header_declare(session
);
1046 list_for_each_entry(chan
, &session
->chan
, list
) {
1047 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1052 list_for_each_entry(event
, &session
->events
, list
) {
1053 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1057 session
->metadata_dumped
= 1;
1063 * lttng_transport_register - LTT transport registration
1064 * @transport: transport structure
1066 * Registers a transport which can be used as output to extract the data out of
1067 * LTTng. The module calling this registration function must ensure that no
1068 * trap-inducing code will be executed by the transport functions. E.g.
1069 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1070 * is made visible to the transport function. This registration acts as a
1071 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1072 * after its registration must it synchronize the TLBs.
1074 void lttng_transport_register(struct lttng_transport
*transport
)
1077 * Make sure no page fault can be triggered by the module about to be
1078 * registered. We deal with this here so we don't have to call
1079 * vmalloc_sync_all() in each module's init.
1081 wrapper_vmalloc_sync_all();
1083 mutex_lock(&sessions_mutex
);
1084 list_add_tail(&transport
->node
, <tng_transport_list
);
1085 mutex_unlock(&sessions_mutex
);
1087 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1090 * lttng_transport_unregister - LTT transport unregistration
1091 * @transport: transport structure
1093 void lttng_transport_unregister(struct lttng_transport
*transport
)
1095 mutex_lock(&sessions_mutex
);
1096 list_del(&transport
->node
);
1097 mutex_unlock(&sessions_mutex
);
1099 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1101 static int __init
lttng_events_init(void)
1105 event_cache
= KMEM_CACHE(lttng_event
, 0);
1108 ret
= lttng_abi_init();
1113 kmem_cache_destroy(event_cache
);
1117 module_init(lttng_events_init
);
1119 static void __exit
lttng_events_exit(void)
1121 struct lttng_session
*session
, *tmpsession
;
1124 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1125 lttng_session_destroy(session
);
1126 kmem_cache_destroy(event_cache
);
1129 module_exit(lttng_events_exit
);
1131 MODULE_LICENSE("GPL and additional rights");
1132 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1133 MODULE_DESCRIPTION("LTTng Events");