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