Add a packet sequence number
[lttng-modules.git] / lttng-ring-buffer-client.h
1 /*
2 * lttng-ring-buffer-client.h
3 *
4 * LTTng lib ring buffer client template.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include "lib/bitfield.h"
26 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
27 #include "wrapper/trace-clock.h"
28 #include "lttng-events.h"
29 #include "lttng-tracer.h"
30 #include "wrapper/ringbuffer/frontend_types.h"
31
32 #define LTTNG_COMPACT_EVENT_BITS 5
33 #define LTTNG_COMPACT_TSC_BITS 27
34
35 static struct lttng_transport lttng_relay_transport;
36
37 /*
38 * Keep the natural field alignment for _each field_ within this structure if
39 * you ever add/remove a field from this header. Packed attribute is not used
40 * because gcc generates poor code on at least powerpc and mips. Don't ever
41 * let gcc add padding between the structure elements.
42 *
43 * The guarantee we have with timestamps is that all the events in a
44 * packet are included (inclusive) within the begin/end timestamps of
45 * the packet. Another guarantee we have is that the "timestamp begin",
46 * as well as the event timestamps, are monotonically increasing (never
47 * decrease) when moving forward in a stream (physically). But this
48 * guarantee does not apply to "timestamp end", because it is sampled at
49 * commit time, which is not ordered with respect to space reservation.
50 */
51
52 struct packet_header {
53 /* Trace packet header */
54 uint32_t magic; /*
55 * Trace magic number.
56 * contains endianness information.
57 */
58 uint8_t uuid[16];
59 uint32_t stream_id;
60
61 struct {
62 /* Stream packet context */
63 uint64_t timestamp_begin; /* Cycle count at subbuffer start */
64 uint64_t timestamp_end; /* Cycle count at subbuffer end */
65 uint64_t content_size; /* Size of data in subbuffer */
66 uint64_t packet_size; /* Subbuffer size (include padding) */
67 uint64_t packet_seq_num; /* Packet sequence number */
68 unsigned long events_discarded; /*
69 * Events lost in this subbuffer since
70 * the beginning of the trace.
71 * (may overflow)
72 */
73 uint32_t cpu_id; /* CPU id associated with stream */
74 uint8_t header_end; /* End of header */
75 } ctx;
76 };
77
78
79 static inline notrace u64 lib_ring_buffer_clock_read(struct channel *chan)
80 {
81 return trace_clock_read64();
82 }
83
84 static inline
85 size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx)
86 {
87 int i;
88 size_t orig_offset = offset;
89
90 if (likely(!ctx))
91 return 0;
92 offset += lib_ring_buffer_align(offset, ctx->largest_align);
93 for (i = 0; i < ctx->nr_fields; i++)
94 offset += ctx->fields[i].get_size(offset);
95 return offset - orig_offset;
96 }
97
98 static inline
99 void ctx_record(struct lib_ring_buffer_ctx *bufctx,
100 struct lttng_channel *chan,
101 struct lttng_ctx *ctx)
102 {
103 int i;
104
105 if (likely(!ctx))
106 return;
107 lib_ring_buffer_align_ctx(bufctx, ctx->largest_align);
108 for (i = 0; i < ctx->nr_fields; i++)
109 ctx->fields[i].record(&ctx->fields[i], bufctx, chan);
110 }
111
112 /*
113 * record_header_size - Calculate the header size and padding necessary.
114 * @config: ring buffer instance configuration
115 * @chan: channel
116 * @offset: offset in the write buffer
117 * @pre_header_padding: padding to add before the header (output)
118 * @ctx: reservation context
119 *
120 * Returns the event header size (including padding).
121 *
122 * The payload must itself determine its own alignment from the biggest type it
123 * contains.
124 */
125 static __inline__
126 unsigned char record_header_size(const struct lib_ring_buffer_config *config,
127 struct channel *chan, size_t offset,
128 size_t *pre_header_padding,
129 struct lib_ring_buffer_ctx *ctx)
130 {
131 struct lttng_channel *lttng_chan = channel_get_private(chan);
132 struct lttng_event *event = ctx->priv;
133 size_t orig_offset = offset;
134 size_t padding;
135
136 switch (lttng_chan->header_type) {
137 case 1: /* compact */
138 padding = lib_ring_buffer_align(offset, lttng_alignof(uint32_t));
139 offset += padding;
140 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
141 offset += sizeof(uint32_t); /* id and timestamp */
142 } else {
143 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
144 offset += (LTTNG_COMPACT_EVENT_BITS + CHAR_BIT - 1) / CHAR_BIT;
145 /* Align extended struct on largest member */
146 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
147 offset += sizeof(uint32_t); /* id */
148 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
149 offset += sizeof(uint64_t); /* timestamp */
150 }
151 break;
152 case 2: /* large */
153 padding = lib_ring_buffer_align(offset, lttng_alignof(uint16_t));
154 offset += padding;
155 offset += sizeof(uint16_t);
156 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
157 offset += lib_ring_buffer_align(offset, lttng_alignof(uint32_t));
158 offset += sizeof(uint32_t); /* timestamp */
159 } else {
160 /* Align extended struct on largest member */
161 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
162 offset += sizeof(uint32_t); /* id */
163 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
164 offset += sizeof(uint64_t); /* timestamp */
165 }
166 break;
167 default:
168 padding = 0;
169 WARN_ON_ONCE(1);
170 }
171 offset += ctx_get_size(offset, event->ctx);
172 offset += ctx_get_size(offset, lttng_chan->ctx);
173
174 *pre_header_padding = padding;
175 return offset - orig_offset;
176 }
177
178 #include "wrapper/ringbuffer/api.h"
179
180 static
181 void lttng_write_event_header_slow(const struct lib_ring_buffer_config *config,
182 struct lib_ring_buffer_ctx *ctx,
183 uint32_t event_id);
184
185 /*
186 * lttng_write_event_header
187 *
188 * Writes the event header to the offset (already aligned on 32-bits).
189 *
190 * @config: ring buffer instance configuration
191 * @ctx: reservation context
192 * @event_id: event ID
193 */
194 static __inline__
195 void lttng_write_event_header(const struct lib_ring_buffer_config *config,
196 struct lib_ring_buffer_ctx *ctx,
197 uint32_t event_id)
198 {
199 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
200 struct lttng_event *event = ctx->priv;
201
202 if (unlikely(ctx->rflags))
203 goto slow_path;
204
205 switch (lttng_chan->header_type) {
206 case 1: /* compact */
207 {
208 uint32_t id_time = 0;
209
210 bt_bitfield_write(&id_time, uint32_t,
211 0,
212 LTTNG_COMPACT_EVENT_BITS,
213 event_id);
214 bt_bitfield_write(&id_time, uint32_t,
215 LTTNG_COMPACT_EVENT_BITS,
216 LTTNG_COMPACT_TSC_BITS,
217 ctx->tsc);
218 lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
219 break;
220 }
221 case 2: /* large */
222 {
223 uint32_t timestamp = (uint32_t) ctx->tsc;
224 uint16_t id = event_id;
225
226 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
227 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint32_t));
228 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
229 break;
230 }
231 default:
232 WARN_ON_ONCE(1);
233 }
234
235 ctx_record(ctx, lttng_chan, lttng_chan->ctx);
236 ctx_record(ctx, lttng_chan, event->ctx);
237 lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
238
239 return;
240
241 slow_path:
242 lttng_write_event_header_slow(config, ctx, event_id);
243 }
244
245 static
246 void lttng_write_event_header_slow(const struct lib_ring_buffer_config *config,
247 struct lib_ring_buffer_ctx *ctx,
248 uint32_t event_id)
249 {
250 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
251 struct lttng_event *event = ctx->priv;
252
253 switch (lttng_chan->header_type) {
254 case 1: /* compact */
255 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
256 uint32_t id_time = 0;
257
258 bt_bitfield_write(&id_time, uint32_t,
259 0,
260 LTTNG_COMPACT_EVENT_BITS,
261 event_id);
262 bt_bitfield_write(&id_time, uint32_t,
263 LTTNG_COMPACT_EVENT_BITS,
264 LTTNG_COMPACT_TSC_BITS, ctx->tsc);
265 lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
266 } else {
267 uint8_t id = 0;
268 uint64_t timestamp = ctx->tsc;
269
270 bt_bitfield_write(&id, uint8_t,
271 0,
272 LTTNG_COMPACT_EVENT_BITS,
273 31);
274 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
275 /* Align extended struct on largest member */
276 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
277 lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
278 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
279 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
280 }
281 break;
282 case 2: /* large */
283 {
284 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
285 uint32_t timestamp = (uint32_t) ctx->tsc;
286 uint16_t id = event_id;
287
288 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
289 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint32_t));
290 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
291 } else {
292 uint16_t id = 65535;
293 uint64_t timestamp = ctx->tsc;
294
295 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
296 /* Align extended struct on largest member */
297 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
298 lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
299 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
300 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
301 }
302 break;
303 }
304 default:
305 WARN_ON_ONCE(1);
306 }
307 ctx_record(ctx, lttng_chan, lttng_chan->ctx);
308 ctx_record(ctx, lttng_chan, event->ctx);
309 lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
310 }
311
312 static const struct lib_ring_buffer_config client_config;
313
314 static u64 client_ring_buffer_clock_read(struct channel *chan)
315 {
316 return lib_ring_buffer_clock_read(chan);
317 }
318
319 static
320 size_t client_record_header_size(const struct lib_ring_buffer_config *config,
321 struct channel *chan, size_t offset,
322 size_t *pre_header_padding,
323 struct lib_ring_buffer_ctx *ctx)
324 {
325 return record_header_size(config, chan, offset,
326 pre_header_padding, ctx);
327 }
328
329 /**
330 * client_packet_header_size - called on buffer-switch to a new sub-buffer
331 *
332 * Return header size without padding after the structure. Don't use packed
333 * structure because gcc generates inefficient code on some architectures
334 * (powerpc, mips..)
335 */
336 static size_t client_packet_header_size(void)
337 {
338 return offsetof(struct packet_header, ctx.header_end);
339 }
340
341 static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc,
342 unsigned int subbuf_idx)
343 {
344 struct channel *chan = buf->backend.chan;
345 struct packet_header *header =
346 (struct packet_header *)
347 lib_ring_buffer_offset_address(&buf->backend,
348 subbuf_idx * chan->backend.subbuf_size);
349 struct lttng_channel *lttng_chan = channel_get_private(chan);
350 struct lttng_session *session = lttng_chan->session;
351
352 header->magic = CTF_MAGIC_NUMBER;
353 memcpy(header->uuid, session->uuid.b, sizeof(session->uuid));
354 header->stream_id = lttng_chan->id;
355 header->ctx.timestamp_begin = tsc;
356 header->ctx.timestamp_end = 0;
357 header->ctx.content_size = ~0ULL; /* for debugging */
358 header->ctx.packet_size = ~0ULL;
359 header->ctx.packet_seq_num = chan->backend.num_subbuf * \
360 buf->backend.buf_cnt[subbuf_idx].seq_cnt + \
361 subbuf_idx;
362 header->ctx.events_discarded = 0;
363 header->ctx.cpu_id = buf->backend.cpu;
364 }
365
366 /*
367 * offset is assumed to never be 0 here : never deliver a completely empty
368 * subbuffer. data_size is between 1 and subbuf_size.
369 */
370 static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc,
371 unsigned int subbuf_idx, unsigned long data_size)
372 {
373 struct channel *chan = buf->backend.chan;
374 struct packet_header *header =
375 (struct packet_header *)
376 lib_ring_buffer_offset_address(&buf->backend,
377 subbuf_idx * chan->backend.subbuf_size);
378 unsigned long records_lost = 0;
379
380 header->ctx.timestamp_end = tsc;
381 header->ctx.content_size =
382 (uint64_t) data_size * CHAR_BIT; /* in bits */
383 header->ctx.packet_size =
384 (uint64_t) PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
385 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
386 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
387 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
388 header->ctx.events_discarded = records_lost;
389 }
390
391 static int client_buffer_create(struct lib_ring_buffer *buf, void *priv,
392 int cpu, const char *name)
393 {
394 return 0;
395 }
396
397 static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu)
398 {
399 }
400
401 static struct packet_header *client_packet_header(
402 const struct lib_ring_buffer_config *config,
403 struct lib_ring_buffer *buf)
404 {
405 return lib_ring_buffer_read_offset_address(&buf->backend, 0);
406 }
407
408 static int client_timestamp_begin(const struct lib_ring_buffer_config *config,
409 struct lib_ring_buffer *buf,
410 uint64_t *timestamp_begin)
411 {
412 struct packet_header *header = client_packet_header(config, buf);
413 *timestamp_begin = header->ctx.timestamp_begin;
414
415 return 0;
416 }
417
418 static int client_timestamp_end(const struct lib_ring_buffer_config *config,
419 struct lib_ring_buffer *buf,
420 uint64_t *timestamp_end)
421 {
422 struct packet_header *header = client_packet_header(config, buf);
423 *timestamp_end = header->ctx.timestamp_end;
424
425 return 0;
426 }
427
428 static int client_events_discarded(const struct lib_ring_buffer_config *config,
429 struct lib_ring_buffer *buf,
430 uint64_t *events_discarded)
431 {
432 struct packet_header *header = client_packet_header(config, buf);
433 *events_discarded = header->ctx.events_discarded;
434
435 return 0;
436 }
437
438 static int client_content_size(const struct lib_ring_buffer_config *config,
439 struct lib_ring_buffer *buf,
440 uint64_t *content_size)
441 {
442 struct packet_header *header = client_packet_header(config, buf);
443 *content_size = header->ctx.content_size;
444
445 return 0;
446 }
447
448 static int client_packet_size(const struct lib_ring_buffer_config *config,
449 struct lib_ring_buffer *buf,
450 uint64_t *packet_size)
451 {
452 struct packet_header *header = client_packet_header(config, buf);
453 *packet_size = header->ctx.packet_size;
454
455 return 0;
456 }
457
458 static int client_stream_id(const struct lib_ring_buffer_config *config,
459 struct lib_ring_buffer *buf,
460 uint64_t *stream_id)
461 {
462 struct packet_header *header = client_packet_header(config, buf);
463 *stream_id = header->stream_id;
464
465 return 0;
466 }
467
468 static int client_current_timestamp(const struct lib_ring_buffer_config *config,
469 struct lib_ring_buffer *bufb,
470 uint64_t *ts)
471 {
472 *ts = config->cb.ring_buffer_clock_read(bufb->backend.chan);
473
474 return 0;
475 }
476
477 static int client_sequence_number(const struct lib_ring_buffer_config *config,
478 struct lib_ring_buffer *buf,
479 uint64_t *seq)
480 {
481 struct packet_header *header = client_packet_header(config, buf);
482
483 *seq = header->ctx.packet_seq_num;
484
485 return 0;
486 }
487
488 static const struct lib_ring_buffer_config client_config = {
489 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
490 .cb.record_header_size = client_record_header_size,
491 .cb.subbuffer_header_size = client_packet_header_size,
492 .cb.buffer_begin = client_buffer_begin,
493 .cb.buffer_end = client_buffer_end,
494 .cb.buffer_create = client_buffer_create,
495 .cb.buffer_finalize = client_buffer_finalize,
496
497 .tsc_bits = LTTNG_COMPACT_TSC_BITS,
498 .alloc = RING_BUFFER_ALLOC_PER_CPU,
499 .sync = RING_BUFFER_SYNC_PER_CPU,
500 .mode = RING_BUFFER_MODE_TEMPLATE,
501 .backend = RING_BUFFER_PAGE,
502 .output = RING_BUFFER_OUTPUT_TEMPLATE,
503 .oops = RING_BUFFER_OOPS_CONSISTENCY,
504 .ipi = RING_BUFFER_IPI_BARRIER,
505 .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
506 };
507
508 static
509 void release_priv_ops(void *priv_ops)
510 {
511 module_put(THIS_MODULE);
512 }
513
514 static
515 void lttng_channel_destroy(struct channel *chan)
516 {
517 channel_destroy(chan);
518 }
519
520 static
521 struct channel *_channel_create(const char *name,
522 struct lttng_channel *lttng_chan, void *buf_addr,
523 size_t subbuf_size, size_t num_subbuf,
524 unsigned int switch_timer_interval,
525 unsigned int read_timer_interval)
526 {
527 struct channel *chan;
528
529 chan = channel_create(&client_config, name, lttng_chan, buf_addr,
530 subbuf_size, num_subbuf, switch_timer_interval,
531 read_timer_interval);
532 if (chan) {
533 /*
534 * Ensure this module is not unloaded before we finish
535 * using lttng_relay_transport.ops.
536 */
537 if (!try_module_get(THIS_MODULE)) {
538 printk(KERN_WARNING "LTT : Can't lock transport module.\n");
539 goto error;
540 }
541 chan->backend.priv_ops = &lttng_relay_transport.ops;
542 chan->backend.release_priv_ops = release_priv_ops;
543 }
544 return chan;
545
546 error:
547 lttng_channel_destroy(chan);
548 return NULL;
549 }
550
551 static
552 struct lib_ring_buffer *lttng_buffer_read_open(struct channel *chan)
553 {
554 struct lib_ring_buffer *buf;
555 int cpu;
556
557 for_each_channel_cpu(cpu, chan) {
558 buf = channel_get_ring_buffer(&client_config, chan, cpu);
559 if (!lib_ring_buffer_open_read(buf))
560 return buf;
561 }
562 return NULL;
563 }
564
565 static
566 int lttng_buffer_has_read_closed_stream(struct channel *chan)
567 {
568 struct lib_ring_buffer *buf;
569 int cpu;
570
571 for_each_channel_cpu(cpu, chan) {
572 buf = channel_get_ring_buffer(&client_config, chan, cpu);
573 if (!atomic_long_read(&buf->active_readers))
574 return 1;
575 }
576 return 0;
577 }
578
579 static
580 void lttng_buffer_read_close(struct lib_ring_buffer *buf)
581 {
582 lib_ring_buffer_release_read(buf);
583 }
584
585 static
586 int lttng_event_reserve(struct lib_ring_buffer_ctx *ctx,
587 uint32_t event_id)
588 {
589 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
590 int ret, cpu;
591
592 cpu = lib_ring_buffer_get_cpu(&client_config);
593 if (cpu < 0)
594 return -EPERM;
595 ctx->cpu = cpu;
596
597 switch (lttng_chan->header_type) {
598 case 1: /* compact */
599 if (event_id > 30)
600 ctx->rflags |= LTTNG_RFLAG_EXTENDED;
601 break;
602 case 2: /* large */
603 if (event_id > 65534)
604 ctx->rflags |= LTTNG_RFLAG_EXTENDED;
605 break;
606 default:
607 WARN_ON_ONCE(1);
608 }
609
610 ret = lib_ring_buffer_reserve(&client_config, ctx);
611 if (ret)
612 goto put;
613 lttng_write_event_header(&client_config, ctx, event_id);
614 return 0;
615 put:
616 lib_ring_buffer_put_cpu(&client_config);
617 return ret;
618 }
619
620 static
621 void lttng_event_commit(struct lib_ring_buffer_ctx *ctx)
622 {
623 lib_ring_buffer_commit(&client_config, ctx);
624 lib_ring_buffer_put_cpu(&client_config);
625 }
626
627 static
628 void lttng_event_write(struct lib_ring_buffer_ctx *ctx, const void *src,
629 size_t len)
630 {
631 lib_ring_buffer_write(&client_config, ctx, src, len);
632 }
633
634 static
635 void lttng_event_write_from_user(struct lib_ring_buffer_ctx *ctx,
636 const void __user *src, size_t len)
637 {
638 lib_ring_buffer_copy_from_user_inatomic(&client_config, ctx, src, len);
639 }
640
641 static
642 void lttng_event_memset(struct lib_ring_buffer_ctx *ctx,
643 int c, size_t len)
644 {
645 lib_ring_buffer_memset(&client_config, ctx, c, len);
646 }
647
648 static
649 void lttng_event_strcpy(struct lib_ring_buffer_ctx *ctx, const char *src,
650 size_t len)
651 {
652 lib_ring_buffer_strcpy(&client_config, ctx, src, len, '#');
653 }
654
655 static
656 void lttng_event_strcpy_from_user(struct lib_ring_buffer_ctx *ctx,
657 const char __user *src, size_t len)
658 {
659 lib_ring_buffer_strcpy_from_user_inatomic(&client_config, ctx, src,
660 len, '#');
661 }
662
663 static
664 wait_queue_head_t *lttng_get_writer_buf_wait_queue(struct channel *chan, int cpu)
665 {
666 struct lib_ring_buffer *buf = channel_get_ring_buffer(&client_config,
667 chan, cpu);
668 return &buf->write_wait;
669 }
670
671 static
672 wait_queue_head_t *lttng_get_hp_wait_queue(struct channel *chan)
673 {
674 return &chan->hp_wait;
675 }
676
677 static
678 int lttng_is_finalized(struct channel *chan)
679 {
680 return lib_ring_buffer_channel_is_finalized(chan);
681 }
682
683 static
684 int lttng_is_disabled(struct channel *chan)
685 {
686 return lib_ring_buffer_channel_is_disabled(chan);
687 }
688
689 static struct lttng_transport lttng_relay_transport = {
690 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING,
691 .owner = THIS_MODULE,
692 .ops = {
693 .channel_create = _channel_create,
694 .channel_destroy = lttng_channel_destroy,
695 .buffer_read_open = lttng_buffer_read_open,
696 .buffer_has_read_closed_stream =
697 lttng_buffer_has_read_closed_stream,
698 .buffer_read_close = lttng_buffer_read_close,
699 .event_reserve = lttng_event_reserve,
700 .event_commit = lttng_event_commit,
701 .event_write = lttng_event_write,
702 .event_write_from_user = lttng_event_write_from_user,
703 .event_memset = lttng_event_memset,
704 .event_strcpy = lttng_event_strcpy,
705 .event_strcpy_from_user = lttng_event_strcpy_from_user,
706 .packet_avail_size = NULL, /* Would be racy anyway */
707 .get_writer_buf_wait_queue = lttng_get_writer_buf_wait_queue,
708 .get_hp_wait_queue = lttng_get_hp_wait_queue,
709 .is_finalized = lttng_is_finalized,
710 .is_disabled = lttng_is_disabled,
711 .timestamp_begin = client_timestamp_begin,
712 .timestamp_end = client_timestamp_end,
713 .events_discarded = client_events_discarded,
714 .content_size = client_content_size,
715 .packet_size = client_packet_size,
716 .stream_id = client_stream_id,
717 .current_timestamp = client_current_timestamp,
718 .sequence_number = client_sequence_number,
719 },
720 };
721
722 static int __init lttng_ring_buffer_client_init(void)
723 {
724 /*
725 * This vmalloc sync all also takes care of the lib ring buffer
726 * vmalloc'd module pages when it is built as a module into LTTng.
727 */
728 wrapper_vmalloc_sync_all();
729 lttng_transport_register(&lttng_relay_transport);
730 return 0;
731 }
732
733 module_init(lttng_ring_buffer_client_init);
734
735 static void __exit lttng_ring_buffer_client_exit(void)
736 {
737 lttng_transport_unregister(&lttng_relay_transport);
738 }
739
740 module_exit(lttng_ring_buffer_client_exit);
741
742 MODULE_LICENSE("GPL and additional rights");
743 MODULE_AUTHOR("Mathieu Desnoyers");
744 MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
745 " client");
This page took 0.043734 seconds and 5 git commands to generate.