Add context support with metadata description
[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 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[ __%s_length ];\n",
474 length_type->u.basic.integer.size,
475 length_type->u.basic.integer.alignment,
476 length_type->u.basic.integer.signedness,
477 (length_type->u.basic.integer.encoding == lttng_encode_none)
478 ? "none"
479 : (length_type->u.basic.integer.encoding == lttng_encode_UTF8)
480 ? "UTF8"
481 : "ASCII",
482 length_type->u.basic.integer.base,
483 #ifdef __BIG_ENDIAN
484 length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
485 #else
486 length_type->u.basic.integer.reverse_byte_order
487 ? " byte_order = be;" : "",
488 #endif
489 field->name,
490 elem_type->u.basic.integer.size,
491 elem_type->u.basic.integer.alignment,
492 elem_type->u.basic.integer.signedness,
493 (elem_type->u.basic.integer.encoding == lttng_encode_none)
494 ? "none"
495 : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
496 ? "UTF8"
497 : "ASCII",
498 elem_type->u.basic.integer.base,
499 #ifdef __BIG_ENDIAN
500 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
501 #else
502 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
503 #endif
504 field->name,
505 field->name
506 );
507 break;
508 }
509
510 case atype_string:
511 /* Default encoding is UTF8 */
512 ret = lttng_metadata_printf(session,
513 " string%s %s;\n",
514 field->type.u.basic.string.encoding == lttng_encode_ASCII ?
515 " { encoding = ASCII; }" : "",
516 field->name);
517 break;
518 default:
519 WARN_ON_ONCE(1);
520 return -EINVAL;
521 }
522 return ret;
523 }
524
525 static
526 int _ltt_context_metadata_statedump(struct ltt_session *session,
527 struct lttng_ctx *ctx)
528 {
529 int ret = 0;
530 int i;
531
532 if (!ctx)
533 return 0;
534 for (i = 0; i < ctx->nr_fields; i++) {
535 const struct lttng_ctx_field *field = &ctx->fields[i];
536
537 ret = _ltt_field_statedump(session, &field->event_field);
538 if (ret)
539 return ret;
540 }
541 return ret;
542 }
543
544 static
545 int _ltt_fields_metadata_statedump(struct ltt_session *session,
546 struct ltt_event *event)
547 {
548 const struct lttng_event_desc *desc = event->desc;
549 int ret = 0;
550 int i;
551
552 for (i = 0; i < desc->nr_fields; i++) {
553 const struct lttng_event_field *field = &desc->fields[i];
554
555 ret = _ltt_field_statedump(session, field);
556 if (ret)
557 return ret;
558 }
559 return ret;
560 }
561
562 static
563 int _ltt_event_metadata_statedump(struct ltt_session *session,
564 struct ltt_channel *chan,
565 struct ltt_event *event)
566 {
567 int ret = 0;
568
569 if (event->metadata_dumped || !ACCESS_ONCE(session->active))
570 return 0;
571 if (chan == session->metadata)
572 return 0;
573
574 ret = lttng_metadata_printf(session,
575 "event {\n"
576 " name = %s;\n"
577 " id = %u;\n"
578 " stream_id = %u;\n"
579 " context := struct {\n",
580 event->desc->name,
581 event->id,
582 event->chan->id);
583 if (ret)
584 goto end;
585
586 ret = _ltt_context_metadata_statedump(session, event->ctx);
587 if (ret)
588 goto end;
589
590 ret = lttng_metadata_printf(session,
591 " };\n"
592 " fields := struct {\n"
593 );
594 if (ret)
595 goto end;
596
597 ret = _ltt_fields_metadata_statedump(session, event);
598 if (ret)
599 goto end;
600
601 /*
602 * LTTng space reservation can only reserve multiples of the
603 * byte size.
604 */
605 ret = lttng_metadata_printf(session,
606 " };\n"
607 "};\n\n");
608 if (ret)
609 goto end;
610
611 event->metadata_dumped = 1;
612 end:
613 return ret;
614
615 }
616
617 static
618 int _ltt_channel_metadata_statedump(struct ltt_session *session,
619 struct ltt_channel *chan)
620 {
621 int ret = 0;
622
623 if (chan->metadata_dumped || !ACCESS_ONCE(session->active))
624 return 0;
625 if (chan == session->metadata)
626 return 0;
627
628 WARN_ON_ONCE(!chan->header_type);
629 ret = lttng_metadata_printf(session,
630 "stream {\n"
631 " id = %u;\n"
632 " event.header := %s;\n"
633 " packet.context := struct packet_context;\n"
634 " event.context := {\n",
635 chan->id,
636 chan->header_type == 1 ? "struct event_header_compact" :
637 "struct event_header_large");
638 if (ret)
639 goto end;
640
641 ret = _ltt_context_metadata_statedump(session, chan->ctx);
642 if (ret)
643 goto end;
644
645 ret = lttng_metadata_printf(session,
646 " };\n"
647 "};\n\n"
648 );
649
650 chan->metadata_dumped = 1;
651 end:
652 return ret;
653 }
654
655 static
656 int _ltt_stream_packet_context_declare(struct ltt_session *session)
657 {
658 return lttng_metadata_printf(session,
659 "struct packet_context {\n"
660 " uint64_t timestamp_begin;\n"
661 " uint64_t timestamp_end;\n"
662 " uint32_t events_discarded;\n"
663 " uint32_t content_size;\n"
664 " uint32_t packet_size;\n"
665 " uint32_t cpu_id;\n"
666 "};\n\n"
667 );
668 }
669
670 /*
671 * Compact header:
672 * id: range: 0 - 30.
673 * id 31 is reserved to indicate an extended header.
674 *
675 * Large header:
676 * id: range: 0 - 65534.
677 * id 65535 is reserved to indicate an extended header.
678 */
679 static
680 int _ltt_event_header_declare(struct ltt_session *session)
681 {
682 return lttng_metadata_printf(session,
683 "struct event_header_compact {\n"
684 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
685 " variant <id> {\n"
686 " struct {\n"
687 " uint27_t timestamp;\n"
688 " } compact;\n"
689 " struct {\n"
690 " uint32_t id;\n"
691 " uint64_t timestamp;\n"
692 " } extended;\n"
693 " } v;\n"
694 "} align(%u);\n"
695 "\n"
696 "struct event_header_large {\n"
697 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
698 " variant <id> {\n"
699 " struct {\n"
700 " uint32_t timestamp;\n"
701 " } compact;\n"
702 " struct {\n"
703 " uint32_t id;\n"
704 " uint64_t timestamp;\n"
705 " } extended;\n"
706 " } v;\n"
707 "} align(%u);\n\n",
708 ltt_alignof(uint32_t) * CHAR_BIT,
709 ltt_alignof(uint16_t) * CHAR_BIT
710 );
711 }
712
713 /*
714 * Output metadata into this session's metadata buffers.
715 */
716 static
717 int _ltt_session_metadata_statedump(struct ltt_session *session)
718 {
719 unsigned char *uuid_c = session->uuid.b;
720 unsigned char uuid_s[37];
721 struct ltt_channel *chan;
722 struct ltt_event *event;
723 int ret = 0;
724
725 if (!ACCESS_ONCE(session->active))
726 return 0;
727 if (session->metadata_dumped)
728 goto skip_session;
729 if (!session->metadata) {
730 printk(KERN_WARNING "LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
731 return -EPERM;
732 }
733
734 snprintf(uuid_s, sizeof(uuid_s),
735 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
736 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
737 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
738 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
739 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
740
741 ret = lttng_metadata_printf(session,
742 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
743 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
744 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
745 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
746 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
747 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
748 "\n"
749 "trace {\n"
750 " major = %u;\n"
751 " minor = %u;\n"
752 " uuid = \"%s\";\n"
753 " byte_order = %s;\n"
754 " packet.header := struct {\n"
755 " uint32_t magic;\n"
756 " uint8_t uuid[16];\n"
757 " uint32_t stream_id;\n"
758 " };\n"
759 "};\n\n",
760 ltt_alignof(uint8_t) * CHAR_BIT,
761 ltt_alignof(uint16_t) * CHAR_BIT,
762 ltt_alignof(uint32_t) * CHAR_BIT,
763 ltt_alignof(uint64_t) * CHAR_BIT,
764 CTF_VERSION_MAJOR,
765 CTF_VERSION_MINOR,
766 uuid_s,
767 #ifdef __BIG_ENDIAN
768 "be"
769 #else
770 "le"
771 #endif
772 );
773 if (ret)
774 goto end;
775
776 ret = _ltt_stream_packet_context_declare(session);
777 if (ret)
778 goto end;
779
780 ret = _ltt_event_header_declare(session);
781 if (ret)
782 goto end;
783
784 skip_session:
785 list_for_each_entry(chan, &session->chan, list) {
786 ret = _ltt_channel_metadata_statedump(session, chan);
787 if (ret)
788 goto end;
789 }
790
791 list_for_each_entry(event, &session->events, list) {
792 ret = _ltt_event_metadata_statedump(session, event->chan, event);
793 if (ret)
794 goto end;
795 }
796 session->metadata_dumped = 1;
797 end:
798 return ret;
799 }
800
801 /**
802 * ltt_transport_register - LTT transport registration
803 * @transport: transport structure
804 *
805 * Registers a transport which can be used as output to extract the data out of
806 * LTTng. The module calling this registration function must ensure that no
807 * trap-inducing code will be executed by the transport functions. E.g.
808 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
809 * is made visible to the transport function. This registration acts as a
810 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
811 * after its registration must it synchronize the TLBs.
812 */
813 void ltt_transport_register(struct ltt_transport *transport)
814 {
815 /*
816 * Make sure no page fault can be triggered by the module about to be
817 * registered. We deal with this here so we don't have to call
818 * vmalloc_sync_all() in each module's init.
819 */
820 wrapper_vmalloc_sync_all();
821
822 mutex_lock(&sessions_mutex);
823 list_add_tail(&transport->node, &ltt_transport_list);
824 mutex_unlock(&sessions_mutex);
825 }
826 EXPORT_SYMBOL_GPL(ltt_transport_register);
827
828 /**
829 * ltt_transport_unregister - LTT transport unregistration
830 * @transport: transport structure
831 */
832 void ltt_transport_unregister(struct ltt_transport *transport)
833 {
834 mutex_lock(&sessions_mutex);
835 list_del(&transport->node);
836 mutex_unlock(&sessions_mutex);
837 }
838 EXPORT_SYMBOL_GPL(ltt_transport_unregister);
839
840 static int __init ltt_events_init(void)
841 {
842 int ret;
843
844 event_cache = KMEM_CACHE(ltt_event, 0);
845 if (!event_cache)
846 return -ENOMEM;
847 ret = ltt_debugfs_abi_init();
848 if (ret)
849 goto error_abi;
850 return 0;
851 error_abi:
852 kmem_cache_destroy(event_cache);
853 return ret;
854 }
855
856 module_init(ltt_events_init);
857
858 static void __exit ltt_events_exit(void)
859 {
860 struct ltt_session *session, *tmpsession;
861
862 ltt_debugfs_abi_exit();
863 list_for_each_entry_safe(session, tmpsession, &sessions, list)
864 ltt_session_destroy(session);
865 kmem_cache_destroy(event_cache);
866 }
867
868 module_exit(ltt_events_exit);
869
870 MODULE_LICENSE("GPL and additional rights");
871 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
872 MODULE_DESCRIPTION("LTTng Events");
This page took 0.048558 seconds and 5 git commands to generate.