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"
37 static LIST_HEAD(sessions
);
38 static LIST_HEAD(lttng_transport_list
);
39 static DEFINE_MUTEX(sessions_mutex
);
40 static struct kmem_cache
*event_cache
;
42 static void _lttng_event_destroy(struct lttng_event
*event
);
43 static void _lttng_channel_destroy(struct lttng_channel
*chan
);
44 static int _lttng_event_unregister(struct lttng_event
*event
);
46 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
47 struct lttng_channel
*chan
,
48 struct lttng_event
*event
);
50 int _lttng_session_metadata_statedump(struct lttng_session
*session
);
52 void synchronize_trace(void)
55 #ifdef CONFIG_PREEMPT_RT
60 struct lttng_session
*lttng_session_create(void)
62 struct lttng_session
*session
;
64 mutex_lock(&sessions_mutex
);
65 session
= kzalloc(sizeof(struct lttng_session
), GFP_KERNEL
);
68 INIT_LIST_HEAD(&session
->chan
);
69 INIT_LIST_HEAD(&session
->events
);
70 uuid_le_gen(&session
->uuid
);
71 list_add(&session
->list
, &sessions
);
72 mutex_unlock(&sessions_mutex
);
76 void lttng_session_destroy(struct lttng_session
*session
)
78 struct lttng_channel
*chan
, *tmpchan
;
79 struct lttng_event
*event
, *tmpevent
;
82 mutex_lock(&sessions_mutex
);
83 ACCESS_ONCE(session
->active
) = 0;
84 list_for_each_entry(chan
, &session
->chan
, list
) {
85 ret
= lttng_syscalls_unregister(chan
);
88 list_for_each_entry(event
, &session
->events
, list
) {
89 ret
= _lttng_event_unregister(event
);
92 synchronize_trace(); /* Wait for in-flight events to complete */
93 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
94 _lttng_event_destroy(event
);
95 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
96 _lttng_channel_destroy(chan
);
97 list_del(&session
->list
);
98 mutex_unlock(&sessions_mutex
);
102 int lttng_session_enable(struct lttng_session
*session
)
105 struct lttng_channel
*chan
;
107 mutex_lock(&sessions_mutex
);
108 if (session
->active
) {
114 * Snapshot the number of events per channel to know the type of header
117 list_for_each_entry(chan
, &session
->chan
, list
) {
118 if (chan
->header_type
)
119 continue; /* don't change it if session stop/restart */
120 if (chan
->free_event_id
< 31)
121 chan
->header_type
= 1; /* compact */
123 chan
->header_type
= 2; /* large */
126 ACCESS_ONCE(session
->active
) = 1;
127 ACCESS_ONCE(session
->been_active
) = 1;
128 ret
= _lttng_session_metadata_statedump(session
);
130 ACCESS_ONCE(session
->active
) = 0;
133 ret
= lttng_statedump_start(session
);
135 ACCESS_ONCE(session
->active
) = 0;
137 mutex_unlock(&sessions_mutex
);
141 int lttng_session_disable(struct lttng_session
*session
)
145 mutex_lock(&sessions_mutex
);
146 if (!session
->active
) {
150 ACCESS_ONCE(session
->active
) = 0;
152 mutex_unlock(&sessions_mutex
);
156 int lttng_channel_enable(struct lttng_channel
*channel
)
160 if (channel
== channel
->session
->metadata
)
162 old
= xchg(&channel
->enabled
, 1);
168 int lttng_channel_disable(struct lttng_channel
*channel
)
172 if (channel
== channel
->session
->metadata
)
174 old
= xchg(&channel
->enabled
, 0);
180 int lttng_event_enable(struct lttng_event
*event
)
184 if (event
->chan
== event
->chan
->session
->metadata
)
186 old
= xchg(&event
->enabled
, 1);
192 int lttng_event_disable(struct lttng_event
*event
)
196 if (event
->chan
== event
->chan
->session
->metadata
)
198 old
= xchg(&event
->enabled
, 0);
204 static struct lttng_transport
*lttng_transport_find(const char *name
)
206 struct lttng_transport
*transport
;
208 list_for_each_entry(transport
, <tng_transport_list
, node
) {
209 if (!strcmp(transport
->name
, name
))
215 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
216 const char *transport_name
,
218 size_t subbuf_size
, size_t num_subbuf
,
219 unsigned int switch_timer_interval
,
220 unsigned int read_timer_interval
)
222 struct lttng_channel
*chan
;
223 struct lttng_transport
*transport
= NULL
;
225 mutex_lock(&sessions_mutex
);
226 if (session
->been_active
)
227 goto active
; /* Refuse to add channel to active session */
228 transport
= lttng_transport_find(transport_name
);
230 printk(KERN_WARNING
"LTTng transport %s not found\n",
234 if (!try_module_get(transport
->owner
)) {
235 printk(KERN_WARNING
"LTT : Can't lock transport module.\n");
238 chan
= kzalloc(sizeof(struct lttng_channel
), GFP_KERNEL
);
241 chan
->session
= session
;
242 chan
->id
= session
->free_chan_id
++;
244 * Note: the channel creation op already writes into the packet
245 * headers. Therefore the "chan" information used as input
246 * should be already accessible.
248 chan
->chan
= transport
->ops
.channel_create(transport_name
,
249 chan
, buf_addr
, subbuf_size
, num_subbuf
,
250 switch_timer_interval
, read_timer_interval
);
254 chan
->ops
= &transport
->ops
;
255 chan
->transport
= transport
;
256 list_add(&chan
->list
, &session
->chan
);
257 mutex_unlock(&sessions_mutex
);
264 module_put(transport
->owner
);
267 mutex_unlock(&sessions_mutex
);
272 * Only used internally at session destruction.
275 void _lttng_channel_destroy(struct lttng_channel
*chan
)
277 chan
->ops
->channel_destroy(chan
->chan
);
278 module_put(chan
->transport
->owner
);
279 list_del(&chan
->list
);
280 lttng_destroy_context(chan
->ctx
);
285 * Supports event creation while tracing session is active.
287 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
288 struct lttng_kernel_event
*event_param
,
290 const struct lttng_event_desc
*internal_desc
)
292 struct lttng_event
*event
;
295 mutex_lock(&sessions_mutex
);
296 if (chan
->free_event_id
== -1U)
299 * This is O(n^2) (for each event, the loop is called at event
300 * creation). Might require a hash if we have lots of events.
302 list_for_each_entry(event
, &chan
->session
->events
, list
)
303 if (!strcmp(event
->desc
->name
, event_param
->name
))
305 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
309 event
->filter
= filter
;
310 event
->id
= chan
->free_event_id
++;
312 event
->instrumentation
= event_param
->instrumentation
;
313 /* Populate lttng_event structure before tracepoint registration. */
315 switch (event_param
->instrumentation
) {
316 case LTTNG_KERNEL_TRACEPOINT
:
317 event
->desc
= lttng_event_get(event_param
->name
);
320 ret
= kabi_2635_tracepoint_probe_register(event_param
->name
,
321 event
->desc
->probe_callback
,
326 case LTTNG_KERNEL_KPROBE
:
327 ret
= lttng_kprobes_register(event_param
->name
,
328 event_param
->u
.kprobe
.symbol_name
,
329 event_param
->u
.kprobe
.offset
,
330 event_param
->u
.kprobe
.addr
,
334 ret
= try_module_get(event
->desc
->owner
);
337 case LTTNG_KERNEL_KRETPROBE
:
339 struct lttng_event
*event_return
;
341 /* kretprobe defines 2 events */
343 kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
346 event_return
->chan
= chan
;
347 event_return
->filter
= filter
;
348 event_return
->id
= chan
->free_event_id
++;
349 event_return
->enabled
= 1;
350 event_return
->instrumentation
= event_param
->instrumentation
;
352 * Populate lttng_event structure before kretprobe registration.
355 ret
= lttng_kretprobes_register(event_param
->name
,
356 event_param
->u
.kretprobe
.symbol_name
,
357 event_param
->u
.kretprobe
.offset
,
358 event_param
->u
.kretprobe
.addr
,
359 event
, event_return
);
361 kmem_cache_free(event_cache
, event_return
);
364 /* Take 2 refs on the module: one per event. */
365 ret
= try_module_get(event
->desc
->owner
);
367 ret
= try_module_get(event
->desc
->owner
);
369 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
,
372 kmem_cache_free(event_cache
, event_return
);
373 module_put(event
->desc
->owner
);
374 module_put(event
->desc
->owner
);
375 goto statedump_error
;
377 list_add(&event_return
->list
, &chan
->session
->events
);
380 case LTTNG_KERNEL_FUNCTION
:
381 ret
= lttng_ftrace_register(event_param
->name
,
382 event_param
->u
.ftrace
.symbol_name
,
386 ret
= try_module_get(event
->desc
->owner
);
389 case LTTNG_KERNEL_NOOP
:
390 event
->desc
= internal_desc
;
397 ret
= _lttng_event_metadata_statedump(chan
->session
, chan
, event
);
399 goto statedump_error
;
400 list_add(&event
->list
, &chan
->session
->events
);
401 mutex_unlock(&sessions_mutex
);
405 /* If a statedump error occurs, events will not be readable. */
407 kmem_cache_free(event_cache
, event
);
411 mutex_unlock(&sessions_mutex
);
416 * Only used internally at session destruction.
418 int _lttng_event_unregister(struct lttng_event
*event
)
422 switch (event
->instrumentation
) {
423 case LTTNG_KERNEL_TRACEPOINT
:
424 ret
= kabi_2635_tracepoint_probe_unregister(event
->desc
->name
,
425 event
->desc
->probe_callback
,
430 case LTTNG_KERNEL_KPROBE
:
431 lttng_kprobes_unregister(event
);
434 case LTTNG_KERNEL_KRETPROBE
:
435 lttng_kretprobes_unregister(event
);
438 case LTTNG_KERNEL_FUNCTION
:
439 lttng_ftrace_unregister(event
);
442 case LTTNG_KERNEL_NOOP
:
452 * Only used internally at session destruction.
455 void _lttng_event_destroy(struct lttng_event
*event
)
457 switch (event
->instrumentation
) {
458 case LTTNG_KERNEL_TRACEPOINT
:
459 lttng_event_put(event
->desc
);
461 case LTTNG_KERNEL_KPROBE
:
462 module_put(event
->desc
->owner
);
463 lttng_kprobes_destroy_private(event
);
465 case LTTNG_KERNEL_KRETPROBE
:
466 module_put(event
->desc
->owner
);
467 lttng_kretprobes_destroy_private(event
);
469 case LTTNG_KERNEL_FUNCTION
:
470 module_put(event
->desc
->owner
);
471 lttng_ftrace_destroy_private(event
);
473 case LTTNG_KERNEL_NOOP
:
478 list_del(&event
->list
);
479 lttng_destroy_context(event
->ctx
);
480 kmem_cache_free(event_cache
, event
);
484 * We have exclusive access to our metadata buffer (protected by the
485 * sessions_mutex), so we can do racy operations such as looking for
486 * remaining space left in packet and write, since mutual exclusion
487 * protects us from concurrent writes.
489 int lttng_metadata_printf(struct lttng_session
*session
,
490 const char *fmt
, ...)
492 struct lib_ring_buffer_ctx ctx
;
493 struct lttng_channel
*chan
= session
->metadata
;
495 int ret
= 0, waitret
;
496 size_t len
, reserve_len
, pos
;
499 WARN_ON_ONCE(!ACCESS_ONCE(session
->active
));
502 str
= kvasprintf(GFP_KERNEL
, fmt
, ap
);
510 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
511 reserve_len
= min_t(size_t,
512 chan
->ops
->packet_avail_size(chan
->chan
),
514 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
517 * We don't care about metadata buffer's records lost
518 * count, because we always retry here. Report error if
519 * we need to bail out after timeout or being
522 waitret
= wait_event_interruptible_timeout(*chan
->ops
->get_writer_buf_wait_queue(chan
->chan
, -1),
524 ret
= chan
->ops
->event_reserve(&ctx
, 0);
525 ret
!= -ENOBUFS
|| !ret
;
527 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC
));
528 if (!waitret
|| waitret
== -ERESTARTSYS
|| ret
) {
529 printk(KERN_WARNING
"LTTng: Failure to write metadata to buffers (%s)\n",
530 waitret
== -ERESTARTSYS
? "interrupted" :
531 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
532 if (waitret
== -ERESTARTSYS
)
536 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
537 chan
->ops
->event_commit(&ctx
);
545 int _lttng_field_statedump(struct lttng_session
*session
,
546 const struct lttng_event_field
*field
)
550 switch (field
->type
.atype
) {
552 ret
= lttng_metadata_printf(session
,
553 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
554 field
->type
.u
.basic
.integer
.size
,
555 field
->type
.u
.basic
.integer
.alignment
,
556 field
->type
.u
.basic
.integer
.signedness
,
557 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
559 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
562 field
->type
.u
.basic
.integer
.base
,
564 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
566 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
571 ret
= lttng_metadata_printf(session
,
573 field
->type
.u
.basic
.enumeration
.name
,
578 const struct lttng_basic_type
*elem_type
;
580 elem_type
= &field
->type
.u
.array
.elem_type
;
581 ret
= lttng_metadata_printf(session
,
582 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
583 elem_type
->u
.basic
.integer
.size
,
584 elem_type
->u
.basic
.integer
.alignment
,
585 elem_type
->u
.basic
.integer
.signedness
,
586 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
588 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
591 elem_type
->u
.basic
.integer
.base
,
593 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
595 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
597 field
->name
, field
->type
.u
.array
.length
);
602 const struct lttng_basic_type
*elem_type
;
603 const struct lttng_basic_type
*length_type
;
605 elem_type
= &field
->type
.u
.sequence
.elem_type
;
606 length_type
= &field
->type
.u
.sequence
.length_type
;
607 ret
= lttng_metadata_printf(session
,
608 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
609 length_type
->u
.basic
.integer
.size
,
610 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
611 length_type
->u
.basic
.integer
.signedness
,
612 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
614 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
617 length_type
->u
.basic
.integer
.base
,
619 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
621 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
627 ret
= lttng_metadata_printf(session
,
628 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
629 elem_type
->u
.basic
.integer
.size
,
630 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
631 elem_type
->u
.basic
.integer
.signedness
,
632 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
634 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
637 elem_type
->u
.basic
.integer
.base
,
639 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
641 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
649 /* Default encoding is UTF8 */
650 ret
= lttng_metadata_printf(session
,
652 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
653 " { encoding = ASCII; }" : "",
664 int _lttng_context_metadata_statedump(struct lttng_session
*session
,
665 struct lttng_ctx
*ctx
)
672 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
673 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
675 ret
= _lttng_field_statedump(session
, &field
->event_field
);
683 int _lttng_fields_metadata_statedump(struct lttng_session
*session
,
684 struct lttng_event
*event
)
686 const struct lttng_event_desc
*desc
= event
->desc
;
690 for (i
= 0; i
< desc
->nr_fields
; i
++) {
691 const struct lttng_event_field
*field
= &desc
->fields
[i
];
693 ret
= _lttng_field_statedump(session
, field
);
701 int _lttng_event_metadata_statedump(struct lttng_session
*session
,
702 struct lttng_channel
*chan
,
703 struct lttng_event
*event
)
707 if (event
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
709 if (chan
== session
->metadata
)
712 ret
= lttng_metadata_printf(session
,
716 " stream_id = %u;\n",
724 ret
= lttng_metadata_printf(session
,
725 " context := struct {\n");
729 ret
= _lttng_context_metadata_statedump(session
, event
->ctx
);
733 ret
= lttng_metadata_printf(session
,
739 ret
= lttng_metadata_printf(session
,
740 " fields := struct {\n"
745 ret
= _lttng_fields_metadata_statedump(session
, event
);
750 * LTTng space reservation can only reserve multiples of the
753 ret
= lttng_metadata_printf(session
,
759 event
->metadata_dumped
= 1;
766 int _lttng_channel_metadata_statedump(struct lttng_session
*session
,
767 struct lttng_channel
*chan
)
771 if (chan
->metadata_dumped
|| !ACCESS_ONCE(session
->active
))
773 if (chan
== session
->metadata
)
776 WARN_ON_ONCE(!chan
->header_type
);
777 ret
= lttng_metadata_printf(session
,
780 " event.header := %s;\n"
781 " packet.context := struct packet_context;\n",
783 chan
->header_type
== 1 ? "struct event_header_compact" :
784 "struct event_header_large");
789 ret
= lttng_metadata_printf(session
,
790 " event.context := struct {\n");
794 ret
= _lttng_context_metadata_statedump(session
, chan
->ctx
);
798 ret
= lttng_metadata_printf(session
,
804 ret
= lttng_metadata_printf(session
,
807 chan
->metadata_dumped
= 1;
813 int _lttng_stream_packet_context_declare(struct lttng_session
*session
)
815 return lttng_metadata_printf(session
,
816 "struct packet_context {\n"
817 " uint64_clock_monotonic_t timestamp_begin;\n"
818 " uint64_clock_monotonic_t timestamp_end;\n"
819 " unsigned long events_discarded;\n"
820 " uint32_t content_size;\n"
821 " uint32_t packet_size;\n"
822 " uint32_t cpu_id;\n"
830 * id 31 is reserved to indicate an extended header.
833 * id: range: 0 - 65534.
834 * id 65535 is reserved to indicate an extended header.
837 int _lttng_event_header_declare(struct lttng_session
*session
)
839 return lttng_metadata_printf(session
,
840 "struct event_header_compact {\n"
841 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
844 " uint27_clock_monotonic_t timestamp;\n"
848 " uint64_clock_monotonic_t timestamp;\n"
853 "struct event_header_large {\n"
854 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
857 " uint32_clock_monotonic_t timestamp;\n"
861 " uint64_clock_monotonic_t timestamp;\n"
865 lttng_alignof(uint32_t) * CHAR_BIT
,
866 lttng_alignof(uint16_t) * CHAR_BIT
871 * Approximation of NTP time of day to clock monotonic correlation,
872 * taken at start of trace.
873 * Yes, this is only an approximation. Yes, we can (and will) do better
874 * in future versions.
877 uint64_t measure_clock_offset(void)
879 uint64_t offset
, monotonic
[2], realtime
;
880 struct timespec rts
= { 0, 0 };
883 /* Disable interrupts to increase correlation precision. */
884 local_irq_save(flags
);
885 monotonic
[0] = trace_clock_read64();
886 getnstimeofday(&rts
);
887 monotonic
[1] = trace_clock_read64();
888 local_irq_restore(flags
);
890 offset
= (monotonic
[0] + monotonic
[1]) >> 1;
891 realtime
= (uint64_t) rts
.tv_sec
* NSEC_PER_SEC
;
892 realtime
+= rts
.tv_nsec
;
893 offset
= realtime
- offset
;
898 * Output metadata into this session's metadata buffers.
901 int _lttng_session_metadata_statedump(struct lttng_session
*session
)
903 unsigned char *uuid_c
= session
->uuid
.b
;
904 unsigned char uuid_s
[37], clock_uuid_s
[BOOT_ID_LEN
];
905 struct lttng_channel
*chan
;
906 struct lttng_event
*event
;
909 if (!ACCESS_ONCE(session
->active
))
911 if (session
->metadata_dumped
)
913 if (!session
->metadata
) {
914 printk(KERN_WARNING
"LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
918 snprintf(uuid_s
, sizeof(uuid_s
),
919 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
920 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
921 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
922 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
923 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
925 ret
= lttng_metadata_printf(session
,
926 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
927 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
928 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
929 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
930 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
931 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
932 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
938 " byte_order = %s;\n"
939 " packet.header := struct {\n"
941 " uint8_t uuid[16];\n"
942 " uint32_t stream_id;\n"
945 lttng_alignof(uint8_t) * CHAR_BIT
,
946 lttng_alignof(uint16_t) * CHAR_BIT
,
947 lttng_alignof(uint32_t) * CHAR_BIT
,
948 lttng_alignof(uint64_t) * CHAR_BIT
,
949 sizeof(unsigned long) * CHAR_BIT
,
950 lttng_alignof(unsigned long) * CHAR_BIT
,
963 ret
= lttng_metadata_printf(session
,
965 " hostname = \"%s\";\n"
966 " domain = \"kernel\";\n"
967 " sysname = \"%s\";\n"
968 " kernel_release = \"%s\";\n"
969 " kernel_version = \"%s\";\n"
970 " tracer_name = \"lttng-modules\";\n"
971 " tracer_major = %d;\n"
972 " tracer_minor = %d;\n"
973 " tracer_patchlevel = %d;\n"
975 current
->nsproxy
->uts_ns
->name
.nodename
,
979 LTTNG_MODULES_MAJOR_VERSION
,
980 LTTNG_MODULES_MINOR_VERSION
,
981 LTTNG_MODULES_PATCHLEVEL_VERSION
986 ret
= lttng_metadata_printf(session
,
994 if (!trace_clock_uuid(clock_uuid_s
)) {
995 ret
= lttng_metadata_printf(session
,
1003 ret
= lttng_metadata_printf(session
,
1004 " description = \"Monotonic Clock\";\n"
1005 " freq = %llu; /* Frequency, in Hz */\n"
1006 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1009 (unsigned long long) trace_clock_freq(),
1010 (unsigned long long) measure_clock_offset()
1015 ret
= lttng_metadata_printf(session
,
1016 "typealias integer {\n"
1017 " size = 27; align = 1; signed = false;\n"
1018 " map = clock.monotonic.value;\n"
1019 "} := uint27_clock_monotonic_t;\n"
1021 "typealias integer {\n"
1022 " size = 32; align = %u; signed = false;\n"
1023 " map = clock.monotonic.value;\n"
1024 "} := uint32_clock_monotonic_t;\n"
1026 "typealias integer {\n"
1027 " size = 64; align = %u; signed = false;\n"
1028 " map = clock.monotonic.value;\n"
1029 "} := uint64_clock_monotonic_t;\n\n",
1030 lttng_alignof(uint32_t) * CHAR_BIT
,
1031 lttng_alignof(uint64_t) * CHAR_BIT
1036 ret
= _lttng_stream_packet_context_declare(session
);
1040 ret
= _lttng_event_header_declare(session
);
1045 list_for_each_entry(chan
, &session
->chan
, list
) {
1046 ret
= _lttng_channel_metadata_statedump(session
, chan
);
1051 list_for_each_entry(event
, &session
->events
, list
) {
1052 ret
= _lttng_event_metadata_statedump(session
, event
->chan
, event
);
1056 session
->metadata_dumped
= 1;
1062 * lttng_transport_register - LTT transport registration
1063 * @transport: transport structure
1065 * Registers a transport which can be used as output to extract the data out of
1066 * LTTng. The module calling this registration function must ensure that no
1067 * trap-inducing code will be executed by the transport functions. E.g.
1068 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
1069 * is made visible to the transport function. This registration acts as a
1070 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
1071 * after its registration must it synchronize the TLBs.
1073 void lttng_transport_register(struct lttng_transport
*transport
)
1076 * Make sure no page fault can be triggered by the module about to be
1077 * registered. We deal with this here so we don't have to call
1078 * vmalloc_sync_all() in each module's init.
1080 wrapper_vmalloc_sync_all();
1082 mutex_lock(&sessions_mutex
);
1083 list_add_tail(&transport
->node
, <tng_transport_list
);
1084 mutex_unlock(&sessions_mutex
);
1086 EXPORT_SYMBOL_GPL(lttng_transport_register
);
1089 * lttng_transport_unregister - LTT transport unregistration
1090 * @transport: transport structure
1092 void lttng_transport_unregister(struct lttng_transport
*transport
)
1094 mutex_lock(&sessions_mutex
);
1095 list_del(&transport
->node
);
1096 mutex_unlock(&sessions_mutex
);
1098 EXPORT_SYMBOL_GPL(lttng_transport_unregister
);
1100 static int __init
lttng_events_init(void)
1104 event_cache
= KMEM_CACHE(lttng_event
, 0);
1107 ret
= lttng_abi_init();
1112 kmem_cache_destroy(event_cache
);
1116 module_init(lttng_events_init
);
1118 static void __exit
lttng_events_exit(void)
1120 struct lttng_session
*session
, *tmpsession
;
1123 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1124 lttng_session_destroy(session
);
1125 kmem_cache_destroy(event_cache
);
1128 module_exit(lttng_events_exit
);
1130 MODULE_LICENSE("GPL and additional rights");
1131 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
1132 MODULE_DESCRIPTION("LTTng Events");