Update licensing info
[deliverable/lttng-modules.git] / ltt-events.c
1 /*
2 * ltt-events.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng per-session event registry.
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11 #include <linux/module.h>
12 #include <linux/list.h>
13 #include <linux/mutex.h>
14 #include <linux/sched.h>
15 #include <linux/slab.h>
16 #include <linux/jiffies.h>
17 #include <linux/uuid.h>
18 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
19 #include "ltt-events.h"
20 #include "ltt-tracer.h"
21
22 static LIST_HEAD(sessions);
23 static LIST_HEAD(ltt_transport_list);
24 static DEFINE_MUTEX(sessions_mutex);
25 static struct kmem_cache *event_cache;
26
27 static void _ltt_event_destroy(struct ltt_event *event);
28 static void _ltt_channel_destroy(struct ltt_channel *chan);
29 static int _ltt_event_unregister(struct ltt_event *event);
30 static
31 int _ltt_event_metadata_statedump(struct ltt_session *session,
32 struct ltt_channel *chan,
33 struct ltt_event *event);
34 static
35 int _ltt_session_metadata_statedump(struct ltt_session *session);
36
37
38 static
39 void synchronize_trace(void)
40 {
41 synchronize_sched();
42 #ifdef CONFIG_PREEMPT_RT
43 synchronize_rcu();
44 #endif
45 }
46
47 struct ltt_session *ltt_session_create(void)
48 {
49 struct ltt_session *session;
50
51 mutex_lock(&sessions_mutex);
52 session = kzalloc(sizeof(struct ltt_session), GFP_KERNEL);
53 if (!session)
54 return NULL;
55 INIT_LIST_HEAD(&session->chan);
56 INIT_LIST_HEAD(&session->events);
57 uuid_le_gen(&session->uuid);
58 list_add(&session->list, &sessions);
59 mutex_unlock(&sessions_mutex);
60 return session;
61 }
62
63 void ltt_session_destroy(struct ltt_session *session)
64 {
65 struct ltt_channel *chan, *tmpchan;
66 struct ltt_event *event, *tmpevent;
67 int ret;
68
69 mutex_lock(&sessions_mutex);
70 ACCESS_ONCE(session->active) = 0;
71 list_for_each_entry(event, &session->events, list) {
72 ret = _ltt_event_unregister(event);
73 WARN_ON(ret);
74 }
75 synchronize_trace(); /* Wait for in-flight events to complete */
76 list_for_each_entry_safe(event, tmpevent, &session->events, list)
77 _ltt_event_destroy(event);
78 list_for_each_entry_safe(chan, tmpchan, &session->chan, list)
79 _ltt_channel_destroy(chan);
80 list_del(&session->list);
81 mutex_unlock(&sessions_mutex);
82 kfree(session);
83 }
84
85 int ltt_session_start(struct ltt_session *session)
86 {
87 int ret = 0;
88 struct ltt_channel *chan;
89
90 mutex_lock(&sessions_mutex);
91 if (session->active) {
92 ret = -EBUSY;
93 goto end;
94 }
95
96 /*
97 * Snapshot the number of events per channel to know the type of header
98 * we need to use.
99 */
100 list_for_each_entry(chan, &session->chan, list) {
101 if (chan->header_type)
102 continue; /* don't change it if session stop/restart */
103 if (chan->free_event_id < 31)
104 chan->header_type = 1; /* compact */
105 else
106 chan->header_type = 2; /* large */
107 }
108
109 ACCESS_ONCE(session->active) = 1;
110 ACCESS_ONCE(session->been_active) = 1;
111 synchronize_trace(); /* Wait for in-flight events to complete */
112 ret = _ltt_session_metadata_statedump(session);
113 if (ret) {
114 ACCESS_ONCE(session->active) = 0;
115 synchronize_trace(); /* Wait for in-flight events to complete */
116 }
117 end:
118 mutex_unlock(&sessions_mutex);
119 return ret;
120 }
121
122 int ltt_session_stop(struct ltt_session *session)
123 {
124 int ret = 0;
125
126 mutex_lock(&sessions_mutex);
127 if (!session->active) {
128 ret = -EBUSY;
129 goto end;
130 }
131 ACCESS_ONCE(session->active) = 0;
132 synchronize_trace(); /* Wait for in-flight events to complete */
133 end:
134 mutex_unlock(&sessions_mutex);
135 return ret;
136 }
137
138 static struct ltt_transport *ltt_transport_find(const char *name)
139 {
140 struct ltt_transport *transport;
141
142 list_for_each_entry(transport, &ltt_transport_list, node) {
143 if (!strcmp(transport->name, name))
144 return transport;
145 }
146 return NULL;
147 }
148
149 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
150 const char *transport_name,
151 void *buf_addr,
152 size_t subbuf_size, size_t num_subbuf,
153 unsigned int switch_timer_interval,
154 unsigned int read_timer_interval)
155 {
156 struct ltt_channel *chan;
157 struct ltt_transport *transport;
158
159 mutex_lock(&sessions_mutex);
160 if (session->been_active)
161 goto active; /* Refuse to add channel to active session */
162 transport = ltt_transport_find(transport_name);
163 if (!transport) {
164 printk(KERN_WARNING "LTTng transport %s not found\n",
165 transport_name);
166 goto notransport;
167 }
168 chan = kzalloc(sizeof(struct ltt_channel), GFP_KERNEL);
169 if (!chan)
170 goto nomem;
171 chan->session = session;
172 init_waitqueue_head(&chan->notify_wait);
173 chan->id = session->free_chan_id++;
174 /*
175 * Note: the channel creation op already writes into the packet
176 * headers. Therefore the "chan" information used as input
177 * should be already accessible.
178 */
179 chan->chan = transport->ops.channel_create("[lttng]", chan, buf_addr,
180 subbuf_size, num_subbuf, switch_timer_interval,
181 read_timer_interval);
182 if (!chan->chan)
183 goto create_error;
184 chan->ops = &transport->ops;
185 list_add(&chan->list, &session->chan);
186 mutex_unlock(&sessions_mutex);
187 return chan;
188
189 create_error:
190 kfree(chan);
191 nomem:
192 notransport:
193 active:
194 mutex_unlock(&sessions_mutex);
195 return NULL;
196 }
197
198 /*
199 * Only used internally at session destruction.
200 */
201 static
202 void _ltt_channel_destroy(struct ltt_channel *chan)
203 {
204 chan->ops->channel_destroy(chan->chan);
205 list_del(&chan->list);
206 lttng_destroy_context(chan->ctx);
207 kfree(chan);
208 }
209
210 /*
211 * Supports event creation while tracing session is active.
212 */
213 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
214 struct lttng_kernel_event *event_param,
215 void *filter)
216 {
217 struct ltt_event *event;
218 int ret;
219
220 mutex_lock(&sessions_mutex);
221 if (chan->free_event_id == -1UL)
222 goto full;
223 /*
224 * This is O(n^2) (for each event, the loop is called at event
225 * creation). Might require a hash if we have lots of events.
226 */
227 list_for_each_entry(event, &chan->session->events, list)
228 if (!strcmp(event->desc->name, event_param->name))
229 goto exist;
230 event = kmem_cache_zalloc(event_cache, GFP_KERNEL);
231 if (!event)
232 goto cache_error;
233 event->chan = chan;
234 event->filter = filter;
235 event->id = chan->free_event_id++;
236 event->instrumentation = event_param->instrumentation;
237 /* Populate ltt_event structure before tracepoint registration. */
238 smp_wmb();
239 switch (event_param->instrumentation) {
240 case LTTNG_KERNEL_TRACEPOINT:
241 event->desc = ltt_event_get(event_param->name);
242 if (!event->desc)
243 goto register_error;
244 ret = tracepoint_probe_register(event_param->name,
245 event->desc->probe_callback,
246 event);
247 if (ret)
248 goto register_error;
249 break;
250 case LTTNG_KERNEL_KPROBE:
251 ret = lttng_kprobes_register(event_param->name,
252 event_param->u.kprobe.symbol_name,
253 event_param->u.kprobe.offset,
254 event_param->u.kprobe.addr,
255 event);
256 if (ret)
257 goto register_error;
258 ret = try_module_get(event->desc->owner);
259 WARN_ON_ONCE(!ret);
260 break;
261 case LTTNG_KERNEL_FUNCTION:
262 ret = lttng_ftrace_register(event_param->name,
263 event_param->u.ftrace.symbol_name,
264 event);
265 if (ret)
266 goto register_error;
267 ret = try_module_get(event->desc->owner);
268 WARN_ON_ONCE(!ret);
269 break;
270 default:
271 WARN_ON_ONCE(1);
272 }
273 ret = _ltt_event_metadata_statedump(chan->session, chan, event);
274 if (ret)
275 goto statedump_error;
276 list_add(&event->list, &chan->session->events);
277 mutex_unlock(&sessions_mutex);
278 return event;
279
280 statedump_error:
281 WARN_ON_ONCE(tracepoint_probe_unregister(event_param->name,
282 event->desc->probe_callback,
283 event));
284 ltt_event_put(event->desc);
285 register_error:
286 kmem_cache_free(event_cache, event);
287 cache_error:
288 exist:
289 full:
290 mutex_unlock(&sessions_mutex);
291 return NULL;
292 }
293
294 /*
295 * Only used internally at session destruction.
296 */
297 int _ltt_event_unregister(struct ltt_event *event)
298 {
299 int ret = -EINVAL;
300
301 switch (event->instrumentation) {
302 case LTTNG_KERNEL_TRACEPOINT:
303 ret = tracepoint_probe_unregister(event->desc->name,
304 event->desc->probe_callback,
305 event);
306 if (ret)
307 return ret;
308 break;
309 case LTTNG_KERNEL_KPROBE:
310 lttng_kprobes_unregister(event);
311 ret = 0;
312 break;
313 case LTTNG_KERNEL_FUNCTION:
314 lttng_ftrace_unregister(event);
315 ret = 0;
316 break;
317 default:
318 WARN_ON_ONCE(1);
319 }
320 return ret;
321 }
322
323 /*
324 * Only used internally at session destruction.
325 */
326 static
327 void _ltt_event_destroy(struct ltt_event *event)
328 {
329 switch (event->instrumentation) {
330 case LTTNG_KERNEL_TRACEPOINT:
331 ltt_event_put(event->desc);
332 break;
333 case LTTNG_KERNEL_KPROBE:
334 module_put(event->desc->owner);
335 lttng_kprobes_destroy_private(event);
336 break;
337 case LTTNG_KERNEL_FUNCTION:
338 module_put(event->desc->owner);
339 lttng_ftrace_destroy_private(event);
340 break;
341 default:
342 WARN_ON_ONCE(1);
343 }
344 list_del(&event->list);
345 lttng_destroy_context(event->ctx);
346 kmem_cache_free(event_cache, event);
347 }
348
349 /*
350 * We have exclusive access to our metadata buffer (protected by the
351 * sessions_mutex), so we can do racy operations such as looking for
352 * remaining space left in packet and write, since mutual exclusion
353 * protects us from concurrent writes.
354 */
355 int lttng_metadata_printf(struct ltt_session *session,
356 const char *fmt, ...)
357 {
358 struct lib_ring_buffer_ctx ctx;
359 struct ltt_channel *chan = session->metadata;
360 char *str;
361 int ret = 0, waitret;
362 size_t len, reserve_len, pos;
363 va_list ap;
364
365 WARN_ON_ONCE(!ACCESS_ONCE(session->active));
366
367 va_start(ap, fmt);
368 str = kvasprintf(GFP_KERNEL, fmt, ap);
369 va_end(ap);
370 if (!str)
371 return -ENOMEM;
372
373 len = strlen(str);
374 pos = 0;
375
376 for (pos = 0; pos < len; pos += reserve_len) {
377 reserve_len = min_t(size_t,
378 chan->ops->packet_avail_size(chan->chan),
379 len - pos);
380 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
381 sizeof(char), -1);
382 /*
383 * We don't care about metadata buffer's records lost
384 * count, because we always retry here. Report error if
385 * we need to bail out after timeout or being
386 * interrupted.
387 */
388 waitret = wait_event_interruptible_timeout(*chan->ops->get_reader_wait_queue(chan),
389 ({
390 ret = chan->ops->event_reserve(&ctx, 0);
391 ret != -ENOBUFS || !ret;
392 }),
393 msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC));
394 if (!waitret || waitret == -ERESTARTSYS || ret) {
395 printk(KERN_WARNING "LTTng: Failure to write metadata to buffers (%s)\n",
396 waitret == -ERESTARTSYS ? "interrupted" :
397 (ret == -ENOBUFS ? "timeout" : "I/O error"));
398 if (waitret == -ERESTARTSYS)
399 ret = waitret;
400 goto end;
401 }
402 chan->ops->event_write(&ctx, &str[pos], len);
403 chan->ops->event_commit(&ctx);
404 }
405 end:
406 kfree(str);
407 return ret;
408 }
409
410 static
411 int _ltt_field_statedump(struct ltt_session *session,
412 const struct lttng_event_field *field)
413 {
414 int ret = 0;
415
416 switch (field->type.atype) {
417 case atype_integer:
418 ret = lttng_metadata_printf(session,
419 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s;\n",
420 field->type.u.basic.integer.size,
421 field->type.u.basic.integer.alignment,
422 field->type.u.basic.integer.signedness,
423 (field->type.u.basic.integer.encoding == lttng_encode_none)
424 ? "none"
425 : (field->type.u.basic.integer.encoding == lttng_encode_UTF8)
426 ? "UTF8"
427 : "ASCII",
428 field->type.u.basic.integer.base,
429 #ifdef __BIG_ENDIAN
430 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
431 #else
432 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
433 #endif
434 field->name);
435 break;
436 case atype_enum:
437 ret = lttng_metadata_printf(session,
438 " %s %s;\n",
439 field->type.u.basic.enumeration.name,
440 field->name);
441 break;
442 case atype_array:
443 {
444 const struct lttng_basic_type *elem_type;
445
446 elem_type = &field->type.u.array.elem_type;
447 ret = lttng_metadata_printf(session,
448 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[%u];\n",
449 elem_type->u.basic.integer.size,
450 elem_type->u.basic.integer.alignment,
451 elem_type->u.basic.integer.signedness,
452 (elem_type->u.basic.integer.encoding == lttng_encode_none)
453 ? "none"
454 : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
455 ? "UTF8"
456 : "ASCII",
457 elem_type->u.basic.integer.base,
458 #ifdef __BIG_ENDIAN
459 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
460 #else
461 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
462 #endif
463 field->name, field->type.u.array.length);
464 break;
465 }
466 case atype_sequence:
467 {
468 const struct lttng_basic_type *elem_type;
469 const struct lttng_basic_type *length_type;
470
471 elem_type = &field->type.u.sequence.elem_type;
472 length_type = &field->type.u.sequence.length_type;
473 ret = lttng_metadata_printf(session,
474 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
475 length_type->u.basic.integer.size,
476 (unsigned int) length_type->u.basic.integer.alignment,
477 length_type->u.basic.integer.signedness,
478 (length_type->u.basic.integer.encoding == lttng_encode_none)
479 ? "none"
480 : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8)
481 ? "UTF8"
482 : "ASCII"),
483 length_type->u.basic.integer.base,
484 #ifdef __BIG_ENDIAN
485 length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
486 #else
487 length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
488 #endif
489 field->name);
490 if (ret)
491 return ret;
492
493 ret = lttng_metadata_printf(session,
494 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[ __%s_length ];\n",
495 elem_type->u.basic.integer.size,
496 (unsigned int) elem_type->u.basic.integer.alignment,
497 elem_type->u.basic.integer.signedness,
498 (elem_type->u.basic.integer.encoding == lttng_encode_none)
499 ? "none"
500 : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
501 ? "UTF8"
502 : "ASCII"),
503 elem_type->u.basic.integer.base,
504 #ifdef __BIG_ENDIAN
505 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
506 #else
507 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
508 #endif
509 field->name,
510 field->name);
511 break;
512 }
513
514 case atype_string:
515 /* Default encoding is UTF8 */
516 ret = lttng_metadata_printf(session,
517 " string%s %s;\n",
518 field->type.u.basic.string.encoding == lttng_encode_ASCII ?
519 " { encoding = ASCII; }" : "",
520 field->name);
521 break;
522 default:
523 WARN_ON_ONCE(1);
524 return -EINVAL;
525 }
526 return ret;
527 }
528
529 static
530 int _ltt_context_metadata_statedump(struct ltt_session *session,
531 struct lttng_ctx *ctx)
532 {
533 int ret = 0;
534 int i;
535
536 if (!ctx)
537 return 0;
538 for (i = 0; i < ctx->nr_fields; i++) {
539 const struct lttng_ctx_field *field = &ctx->fields[i];
540
541 ret = _ltt_field_statedump(session, &field->event_field);
542 if (ret)
543 return ret;
544 }
545 return ret;
546 }
547
548 static
549 int _ltt_fields_metadata_statedump(struct ltt_session *session,
550 struct ltt_event *event)
551 {
552 const struct lttng_event_desc *desc = event->desc;
553 int ret = 0;
554 int i;
555
556 for (i = 0; i < desc->nr_fields; i++) {
557 const struct lttng_event_field *field = &desc->fields[i];
558
559 ret = _ltt_field_statedump(session, field);
560 if (ret)
561 return ret;
562 }
563 return ret;
564 }
565
566 static
567 int _ltt_event_metadata_statedump(struct ltt_session *session,
568 struct ltt_channel *chan,
569 struct ltt_event *event)
570 {
571 int ret = 0;
572
573 if (event->metadata_dumped || !ACCESS_ONCE(session->active))
574 return 0;
575 if (chan == session->metadata)
576 return 0;
577
578 ret = lttng_metadata_printf(session,
579 "event {\n"
580 " name = %s;\n"
581 " id = %u;\n"
582 " stream_id = %u;\n",
583 event->desc->name,
584 event->id,
585 event->chan->id);
586 if (ret)
587 goto end;
588
589 if (event->ctx) {
590 ret = lttng_metadata_printf(session,
591 " context := struct {\n");
592 if (ret)
593 goto end;
594 }
595 ret = _ltt_context_metadata_statedump(session, event->ctx);
596 if (ret)
597 goto end;
598 if (event->ctx) {
599 ret = lttng_metadata_printf(session,
600 " };\n");
601 if (ret)
602 goto end;
603 }
604
605 ret = lttng_metadata_printf(session,
606 " fields := struct {\n"
607 );
608 if (ret)
609 goto end;
610
611 ret = _ltt_fields_metadata_statedump(session, event);
612 if (ret)
613 goto end;
614
615 /*
616 * LTTng space reservation can only reserve multiples of the
617 * byte size.
618 */
619 ret = lttng_metadata_printf(session,
620 " };\n"
621 "};\n\n");
622 if (ret)
623 goto end;
624
625 event->metadata_dumped = 1;
626 end:
627 return ret;
628
629 }
630
631 static
632 int _ltt_channel_metadata_statedump(struct ltt_session *session,
633 struct ltt_channel *chan)
634 {
635 int ret = 0;
636
637 if (chan->metadata_dumped || !ACCESS_ONCE(session->active))
638 return 0;
639 if (chan == session->metadata)
640 return 0;
641
642 WARN_ON_ONCE(!chan->header_type);
643 ret = lttng_metadata_printf(session,
644 "stream {\n"
645 " id = %u;\n"
646 " event.header := %s;\n"
647 " packet.context := struct packet_context;\n",
648 chan->id,
649 chan->header_type == 1 ? "struct event_header_compact" :
650 "struct event_header_large");
651 if (ret)
652 goto end;
653
654 if (chan->ctx) {
655 ret = lttng_metadata_printf(session,
656 " event.context := struct {\n");
657 if (ret)
658 goto end;
659 }
660 ret = _ltt_context_metadata_statedump(session, chan->ctx);
661 if (ret)
662 goto end;
663 if (chan->ctx) {
664 ret = lttng_metadata_printf(session,
665 " };\n");
666 if (ret)
667 goto end;
668 }
669
670 ret = lttng_metadata_printf(session,
671 "};\n\n");
672
673 chan->metadata_dumped = 1;
674 end:
675 return ret;
676 }
677
678 static
679 int _ltt_stream_packet_context_declare(struct ltt_session *session)
680 {
681 return lttng_metadata_printf(session,
682 "struct packet_context {\n"
683 " uint64_t timestamp_begin;\n"
684 " uint64_t timestamp_end;\n"
685 " uint32_t events_discarded;\n"
686 " uint32_t content_size;\n"
687 " uint32_t packet_size;\n"
688 " uint32_t cpu_id;\n"
689 "};\n\n"
690 );
691 }
692
693 /*
694 * Compact header:
695 * id: range: 0 - 30.
696 * id 31 is reserved to indicate an extended header.
697 *
698 * Large header:
699 * id: range: 0 - 65534.
700 * id 65535 is reserved to indicate an extended header.
701 */
702 static
703 int _ltt_event_header_declare(struct ltt_session *session)
704 {
705 return lttng_metadata_printf(session,
706 "struct event_header_compact {\n"
707 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
708 " variant <id> {\n"
709 " struct {\n"
710 " uint27_t timestamp;\n"
711 " } compact;\n"
712 " struct {\n"
713 " uint32_t id;\n"
714 " uint64_t timestamp;\n"
715 " } extended;\n"
716 " } v;\n"
717 "} align(%u);\n"
718 "\n"
719 "struct event_header_large {\n"
720 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
721 " variant <id> {\n"
722 " struct {\n"
723 " uint32_t timestamp;\n"
724 " } compact;\n"
725 " struct {\n"
726 " uint32_t id;\n"
727 " uint64_t timestamp;\n"
728 " } extended;\n"
729 " } v;\n"
730 "} align(%u);\n\n",
731 ltt_alignof(uint32_t) * CHAR_BIT,
732 ltt_alignof(uint16_t) * CHAR_BIT
733 );
734 }
735
736 /*
737 * Output metadata into this session's metadata buffers.
738 */
739 static
740 int _ltt_session_metadata_statedump(struct ltt_session *session)
741 {
742 unsigned char *uuid_c = session->uuid.b;
743 unsigned char uuid_s[37];
744 struct ltt_channel *chan;
745 struct ltt_event *event;
746 int ret = 0;
747
748 if (!ACCESS_ONCE(session->active))
749 return 0;
750 if (session->metadata_dumped)
751 goto skip_session;
752 if (!session->metadata) {
753 printk(KERN_WARNING "LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
754 return -EPERM;
755 }
756
757 snprintf(uuid_s, sizeof(uuid_s),
758 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
759 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
760 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
761 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
762 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
763
764 ret = lttng_metadata_printf(session,
765 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
766 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
767 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
768 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
769 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
770 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
771 "\n"
772 "trace {\n"
773 " major = %u;\n"
774 " minor = %u;\n"
775 " uuid = \"%s\";\n"
776 " byte_order = %s;\n"
777 " packet.header := struct {\n"
778 " uint32_t magic;\n"
779 " uint8_t uuid[16];\n"
780 " uint32_t stream_id;\n"
781 " };\n"
782 "};\n\n",
783 ltt_alignof(uint8_t) * CHAR_BIT,
784 ltt_alignof(uint16_t) * CHAR_BIT,
785 ltt_alignof(uint32_t) * CHAR_BIT,
786 ltt_alignof(uint64_t) * CHAR_BIT,
787 CTF_VERSION_MAJOR,
788 CTF_VERSION_MINOR,
789 uuid_s,
790 #ifdef __BIG_ENDIAN
791 "be"
792 #else
793 "le"
794 #endif
795 );
796 if (ret)
797 goto end;
798
799 ret = _ltt_stream_packet_context_declare(session);
800 if (ret)
801 goto end;
802
803 ret = _ltt_event_header_declare(session);
804 if (ret)
805 goto end;
806
807 skip_session:
808 list_for_each_entry(chan, &session->chan, list) {
809 ret = _ltt_channel_metadata_statedump(session, chan);
810 if (ret)
811 goto end;
812 }
813
814 list_for_each_entry(event, &session->events, list) {
815 ret = _ltt_event_metadata_statedump(session, event->chan, event);
816 if (ret)
817 goto end;
818 }
819 session->metadata_dumped = 1;
820 end:
821 return ret;
822 }
823
824 /**
825 * ltt_transport_register - LTT transport registration
826 * @transport: transport structure
827 *
828 * Registers a transport which can be used as output to extract the data out of
829 * LTTng. The module calling this registration function must ensure that no
830 * trap-inducing code will be executed by the transport functions. E.g.
831 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
832 * is made visible to the transport function. This registration acts as a
833 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
834 * after its registration must it synchronize the TLBs.
835 */
836 void ltt_transport_register(struct ltt_transport *transport)
837 {
838 /*
839 * Make sure no page fault can be triggered by the module about to be
840 * registered. We deal with this here so we don't have to call
841 * vmalloc_sync_all() in each module's init.
842 */
843 wrapper_vmalloc_sync_all();
844
845 mutex_lock(&sessions_mutex);
846 list_add_tail(&transport->node, &ltt_transport_list);
847 mutex_unlock(&sessions_mutex);
848 }
849 EXPORT_SYMBOL_GPL(ltt_transport_register);
850
851 /**
852 * ltt_transport_unregister - LTT transport unregistration
853 * @transport: transport structure
854 */
855 void ltt_transport_unregister(struct ltt_transport *transport)
856 {
857 mutex_lock(&sessions_mutex);
858 list_del(&transport->node);
859 mutex_unlock(&sessions_mutex);
860 }
861 EXPORT_SYMBOL_GPL(ltt_transport_unregister);
862
863 static int __init ltt_events_init(void)
864 {
865 int ret;
866
867 event_cache = KMEM_CACHE(ltt_event, 0);
868 if (!event_cache)
869 return -ENOMEM;
870 ret = ltt_debugfs_abi_init();
871 if (ret)
872 goto error_abi;
873 return 0;
874 error_abi:
875 kmem_cache_destroy(event_cache);
876 return ret;
877 }
878
879 module_init(ltt_events_init);
880
881 static void __exit ltt_events_exit(void)
882 {
883 struct ltt_session *session, *tmpsession;
884
885 ltt_debugfs_abi_exit();
886 list_for_each_entry_safe(session, tmpsession, &sessions, list)
887 ltt_session_destroy(session);
888 kmem_cache_destroy(event_cache);
889 }
890
891 module_exit(ltt_events_exit);
892
893 MODULE_LICENSE("GPL and additional rights");
894 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
895 MODULE_DESCRIPTION("LTTng Events");
This page took 0.050443 seconds and 5 git commands to generate.