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