1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3 * lttng-ring-buffer-client.h
5 * LTTng lib ring buffer client template.
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <lttng/bitfield.h>
13 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
14 #include <wrapper/trace-clock.h>
15 #include <lttng/events.h>
16 #include <lttng/events-internal.h>
17 #include <lttng/tracer.h>
18 #include <ringbuffer/frontend_types.h>
20 #define LTTNG_COMPACT_EVENT_BITS 5
21 #define LTTNG_COMPACT_TSC_BITS 27
23 static struct lttng_transport lttng_relay_transport
;
26 * Keep the natural field alignment for _each field_ within this structure if
27 * you ever add/remove a field from this header. Packed attribute is not used
28 * because gcc generates poor code on at least powerpc and mips. Don't ever
29 * let gcc add padding between the structure elements.
31 * The guarantee we have with timestamps is that all the events in a
32 * packet are included (inclusive) within the begin/end timestamps of
33 * the packet. Another guarantee we have is that the "timestamp begin",
34 * as well as the event timestamps, are monotonically increasing (never
35 * decrease) when moving forward in a stream (physically). But this
36 * guarantee does not apply to "timestamp end", because it is sampled at
37 * commit time, which is not ordered with respect to space reservation.
40 struct packet_header
{
41 /* Trace packet header */
44 * contains endianness information.
48 uint64_t stream_instance_id
;
51 /* Stream packet context */
52 uint64_t timestamp_begin
; /* Cycle count at subbuffer start */
53 uint64_t timestamp_end
; /* Cycle count at subbuffer end */
54 uint64_t content_size
; /* Size of data in subbuffer */
55 uint64_t packet_size
; /* Subbuffer size (include padding) */
56 uint64_t packet_seq_num
; /* Packet sequence number */
57 unsigned long events_discarded
; /*
58 * Events lost in this subbuffer since
59 * the beginning of the trace.
62 uint32_t cpu_id
; /* CPU id associated with stream */
63 uint8_t header_end
; /* End of header */
67 struct lttng_client_ctx
{
68 size_t packet_context_len
;
69 size_t event_context_len
;
72 static inline notrace u64
lib_ring_buffer_clock_read(struct lttng_kernel_ring_buffer_channel
*chan
)
74 return trace_clock_read64();
78 size_t ctx_get_aligned_size(size_t offset
, struct lttng_kernel_ctx
*ctx
,
81 size_t orig_offset
= offset
;
85 offset
+= lib_ring_buffer_align(offset
, ctx
->largest_align
);
87 return offset
- orig_offset
;
91 void ctx_get_struct_size(struct lttng_kernel_ctx
*ctx
, size_t *ctx_len
,
92 struct lttng_kernel_channel_buffer
*lttng_chan
,
93 struct lttng_kernel_ring_buffer_ctx
*bufctx
)
102 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
103 offset
+= ctx
->fields
[i
].get_size(ctx
->fields
[i
].priv
,
104 bufctx
->probe_ctx
, offset
);
110 void ctx_record(struct lttng_kernel_ring_buffer_ctx
*bufctx
,
111 struct lttng_kernel_channel_buffer
*lttng_chan
,
112 struct lttng_kernel_ctx
*ctx
)
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
].priv
, bufctx
->probe_ctx
,
125 * record_header_size - Calculate the header size and padding necessary.
126 * @config: ring buffer instance configuration
128 * @offset: offset in the write buffer
129 * @pre_header_padding: padding to add before the header (output)
130 * @ctx: reservation context
132 * Returns the event header size (including padding).
134 * The payload must itself determine its own alignment from the biggest type it
138 size_t record_header_size(const struct lttng_kernel_ring_buffer_config
*config
,
139 struct lttng_kernel_ring_buffer_channel
*chan
, size_t offset
,
140 size_t *pre_header_padding
,
141 struct lttng_kernel_ring_buffer_ctx
*ctx
,
142 struct lttng_client_ctx
*client_ctx
)
144 struct lttng_kernel_channel_buffer
*lttng_chan
= channel_get_private(chan
);
145 size_t orig_offset
= offset
;
148 switch (lttng_chan
->priv
->header_type
) {
149 case 1: /* compact */
150 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
152 if (!(ctx
->priv
.rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
153 offset
+= sizeof(uint32_t); /* id and timestamp */
155 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
156 offset
+= (LTTNG_COMPACT_EVENT_BITS
+ CHAR_BIT
- 1) / CHAR_BIT
;
157 /* Align extended struct on largest member */
158 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
159 offset
+= sizeof(uint32_t); /* id */
160 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
161 offset
+= sizeof(uint64_t); /* timestamp */
165 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
167 offset
+= sizeof(uint16_t);
168 if (!(ctx
->priv
.rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
169 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
170 offset
+= sizeof(uint32_t); /* timestamp */
172 /* Align extended struct on largest member */
173 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
174 offset
+= sizeof(uint32_t); /* id */
175 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
176 offset
+= sizeof(uint64_t); /* timestamp */
183 offset
+= ctx_get_aligned_size(offset
, lttng_chan
->priv
->ctx
,
184 client_ctx
->packet_context_len
);
185 *pre_header_padding
= padding
;
186 return offset
- orig_offset
;
189 #include <ringbuffer/api.h>
192 void lttng_write_event_header_slow(const struct lttng_kernel_ring_buffer_config
*config
,
193 struct lttng_kernel_ring_buffer_ctx
*ctx
,
197 * lttng_write_event_header
199 * Writes the event header to the offset (already aligned on 32-bits).
201 * @config: ring buffer instance configuration
202 * @ctx: reservation context
203 * @event_id: event ID
206 void lttng_write_event_header(const struct lttng_kernel_ring_buffer_config
*config
,
207 struct lttng_kernel_ring_buffer_ctx
*ctx
,
210 struct lttng_kernel_channel_buffer
*lttng_chan
= channel_get_private(ctx
->priv
.chan
);
212 if (unlikely(ctx
->priv
.rflags
))
215 switch (lttng_chan
->priv
->header_type
) {
216 case 1: /* compact */
218 uint32_t id_time
= 0;
220 bt_bitfield_write(&id_time
, uint32_t,
222 LTTNG_COMPACT_EVENT_BITS
,
224 bt_bitfield_write(&id_time
, uint32_t,
225 LTTNG_COMPACT_EVENT_BITS
,
226 LTTNG_COMPACT_TSC_BITS
,
228 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
233 uint32_t timestamp
= (uint32_t) ctx
->priv
.tsc
;
234 uint16_t id
= event_id
;
236 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
237 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
238 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
245 ctx_record(ctx
, lttng_chan
, lttng_chan
->priv
->ctx
);
246 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
251 lttng_write_event_header_slow(config
, ctx
, event_id
);
255 void lttng_write_event_header_slow(const struct lttng_kernel_ring_buffer_config
*config
,
256 struct lttng_kernel_ring_buffer_ctx
*ctx
,
259 struct lttng_kernel_channel_buffer
*lttng_chan
= channel_get_private(ctx
->priv
.chan
);
261 switch (lttng_chan
->priv
->header_type
) {
262 case 1: /* compact */
263 if (!(ctx
->priv
.rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
264 uint32_t id_time
= 0;
266 bt_bitfield_write(&id_time
, uint32_t,
268 LTTNG_COMPACT_EVENT_BITS
,
270 bt_bitfield_write(&id_time
, uint32_t,
271 LTTNG_COMPACT_EVENT_BITS
,
272 LTTNG_COMPACT_TSC_BITS
, ctx
->priv
.tsc
);
273 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
276 uint64_t timestamp
= ctx
->priv
.tsc
;
278 bt_bitfield_write(&id
, uint8_t,
280 LTTNG_COMPACT_EVENT_BITS
,
282 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
283 /* Align extended struct on largest member */
284 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
285 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
286 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
287 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
292 if (!(ctx
->priv
.rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
293 uint32_t timestamp
= (uint32_t) ctx
->priv
.tsc
;
294 uint16_t id
= event_id
;
296 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
297 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
298 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
301 uint64_t timestamp
= ctx
->priv
.tsc
;
303 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
304 /* Align extended struct on largest member */
305 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
306 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
307 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
308 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
315 ctx_record(ctx
, lttng_chan
, lttng_chan
->priv
->ctx
);
316 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
319 static const struct lttng_kernel_ring_buffer_config client_config
;
321 static u64
client_ring_buffer_clock_read(struct lttng_kernel_ring_buffer_channel
*chan
)
323 return lib_ring_buffer_clock_read(chan
);
327 size_t client_record_header_size(const struct lttng_kernel_ring_buffer_config
*config
,
328 struct lttng_kernel_ring_buffer_channel
*chan
, size_t offset
,
329 size_t *pre_header_padding
,
330 struct lttng_kernel_ring_buffer_ctx
*ctx
,
333 return record_header_size(config
, chan
, offset
,
334 pre_header_padding
, ctx
, client_ctx
);
338 * client_packet_header_size - called on buffer-switch to a new sub-buffer
340 * Return header size without padding after the structure. Don't use packed
341 * structure because gcc generates inefficient code on some architectures
344 static size_t client_packet_header_size(void)
346 return offsetof(struct packet_header
, ctx
.header_end
);
349 static void client_buffer_begin(struct lttng_kernel_ring_buffer
*buf
, u64 tsc
,
350 unsigned int subbuf_idx
)
352 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
353 struct packet_header
*header
=
354 (struct packet_header
*)
355 lib_ring_buffer_offset_address(&buf
->backend
,
356 subbuf_idx
* chan
->backend
.subbuf_size
);
357 struct lttng_kernel_channel_buffer
*lttng_chan
= channel_get_private(chan
);
358 struct lttng_kernel_session
*session
= lttng_chan
->parent
.session
;
360 header
->magic
= CTF_MAGIC_NUMBER
;
361 memcpy(header
->uuid
, session
->priv
->uuid
.b
, sizeof(session
->priv
->uuid
));
362 header
->stream_id
= lttng_chan
->priv
->id
;
363 header
->stream_instance_id
= buf
->backend
.cpu
;
364 header
->ctx
.timestamp_begin
= tsc
;
365 header
->ctx
.timestamp_end
= 0;
366 header
->ctx
.content_size
= ~0ULL; /* for debugging */
367 header
->ctx
.packet_size
= ~0ULL;
368 header
->ctx
.packet_seq_num
= chan
->backend
.num_subbuf
* \
369 buf
->backend
.buf_cnt
[subbuf_idx
].seq_cnt
+ \
371 header
->ctx
.events_discarded
= 0;
372 header
->ctx
.cpu_id
= buf
->backend
.cpu
;
376 * offset is assumed to never be 0 here : never deliver a completely empty
377 * subbuffer. data_size is between 1 and subbuf_size.
379 static void client_buffer_end(struct lttng_kernel_ring_buffer
*buf
, u64 tsc
,
380 unsigned int subbuf_idx
, unsigned long data_size
)
382 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
383 struct packet_header
*header
=
384 (struct packet_header
*)
385 lib_ring_buffer_offset_address(&buf
->backend
,
386 subbuf_idx
* chan
->backend
.subbuf_size
);
387 unsigned long records_lost
= 0;
389 header
->ctx
.timestamp_end
= tsc
;
390 header
->ctx
.content_size
=
391 (uint64_t) data_size
* CHAR_BIT
; /* in bits */
392 header
->ctx
.packet_size
=
393 (uint64_t) PAGE_ALIGN(data_size
) * CHAR_BIT
; /* in bits */
394 records_lost
+= lib_ring_buffer_get_records_lost_full(&client_config
, buf
);
395 records_lost
+= lib_ring_buffer_get_records_lost_wrap(&client_config
, buf
);
396 records_lost
+= lib_ring_buffer_get_records_lost_big(&client_config
, buf
);
397 header
->ctx
.events_discarded
= records_lost
;
400 static int client_buffer_create(struct lttng_kernel_ring_buffer
*buf
, void *priv
,
401 int cpu
, const char *name
)
406 static void client_buffer_finalize(struct lttng_kernel_ring_buffer
*buf
, void *priv
, int cpu
)
410 static struct packet_header
*client_packet_header(
411 const struct lttng_kernel_ring_buffer_config
*config
,
412 struct lttng_kernel_ring_buffer
*buf
)
414 return lib_ring_buffer_read_offset_address(&buf
->backend
, 0);
417 static int client_timestamp_begin(const struct lttng_kernel_ring_buffer_config
*config
,
418 struct lttng_kernel_ring_buffer
*buf
,
419 uint64_t *timestamp_begin
)
421 struct packet_header
*header
= client_packet_header(config
, buf
);
422 *timestamp_begin
= header
->ctx
.timestamp_begin
;
427 static int client_timestamp_end(const struct lttng_kernel_ring_buffer_config
*config
,
428 struct lttng_kernel_ring_buffer
*buf
,
429 uint64_t *timestamp_end
)
431 struct packet_header
*header
= client_packet_header(config
, buf
);
432 *timestamp_end
= header
->ctx
.timestamp_end
;
437 static int client_events_discarded(const struct lttng_kernel_ring_buffer_config
*config
,
438 struct lttng_kernel_ring_buffer
*buf
,
439 uint64_t *events_discarded
)
441 struct packet_header
*header
= client_packet_header(config
, buf
);
442 *events_discarded
= header
->ctx
.events_discarded
;
447 static int client_content_size(const struct lttng_kernel_ring_buffer_config
*config
,
448 struct lttng_kernel_ring_buffer
*buf
,
449 uint64_t *content_size
)
451 struct packet_header
*header
= client_packet_header(config
, buf
);
452 *content_size
= header
->ctx
.content_size
;
457 static int client_packet_size(const struct lttng_kernel_ring_buffer_config
*config
,
458 struct lttng_kernel_ring_buffer
*buf
,
459 uint64_t *packet_size
)
461 struct packet_header
*header
= client_packet_header(config
, buf
);
462 *packet_size
= header
->ctx
.packet_size
;
467 static int client_stream_id(const struct lttng_kernel_ring_buffer_config
*config
,
468 struct lttng_kernel_ring_buffer
*buf
,
471 struct lttng_kernel_ring_buffer_channel
*chan
= buf
->backend
.chan
;
472 struct lttng_kernel_channel_buffer
*lttng_chan
= channel_get_private(chan
);
474 *stream_id
= lttng_chan
->priv
->id
;
478 static int client_current_timestamp(const struct lttng_kernel_ring_buffer_config
*config
,
479 struct lttng_kernel_ring_buffer
*bufb
,
482 *ts
= config
->cb
.ring_buffer_clock_read(bufb
->backend
.chan
);
487 static int client_sequence_number(const struct lttng_kernel_ring_buffer_config
*config
,
488 struct lttng_kernel_ring_buffer
*buf
,
491 struct packet_header
*header
= client_packet_header(config
, buf
);
493 *seq
= header
->ctx
.packet_seq_num
;
499 int client_instance_id(const struct lttng_kernel_ring_buffer_config
*config
,
500 struct lttng_kernel_ring_buffer
*buf
,
503 *id
= buf
->backend
.cpu
;
508 static const struct lttng_kernel_ring_buffer_config client_config
= {
509 .cb
.ring_buffer_clock_read
= client_ring_buffer_clock_read
,
510 .cb
.record_header_size
= client_record_header_size
,
511 .cb
.subbuffer_header_size
= client_packet_header_size
,
512 .cb
.buffer_begin
= client_buffer_begin
,
513 .cb
.buffer_end
= client_buffer_end
,
514 .cb
.buffer_create
= client_buffer_create
,
515 .cb
.buffer_finalize
= client_buffer_finalize
,
517 .tsc_bits
= LTTNG_COMPACT_TSC_BITS
,
518 .alloc
= RING_BUFFER_ALLOC_PER_CPU
,
519 .sync
= RING_BUFFER_SYNC_PER_CPU
,
520 .mode
= RING_BUFFER_MODE_TEMPLATE
,
521 .backend
= RING_BUFFER_PAGE
,
522 .output
= RING_BUFFER_OUTPUT_TEMPLATE
,
523 .oops
= RING_BUFFER_OOPS_CONSISTENCY
,
524 .ipi
= RING_BUFFER_IPI_BARRIER
,
525 .wakeup
= RING_BUFFER_WAKEUP_BY_TIMER
,
529 void release_priv_ops(void *priv_ops
)
531 module_put(THIS_MODULE
);
535 void lttng_channel_destroy(struct lttng_kernel_ring_buffer_channel
*chan
)
537 channel_destroy(chan
);
541 struct lttng_kernel_ring_buffer_channel
*_channel_create(const char *name
,
542 void *priv
, void *buf_addr
,
543 size_t subbuf_size
, size_t num_subbuf
,
544 unsigned int switch_timer_interval
,
545 unsigned int read_timer_interval
)
547 struct lttng_kernel_channel_buffer
*lttng_chan
= priv
;
548 struct lttng_kernel_ring_buffer_channel
*chan
;
550 chan
= channel_create(&client_config
, name
, lttng_chan
, buf_addr
,
551 subbuf_size
, num_subbuf
, switch_timer_interval
,
552 read_timer_interval
);
555 * Ensure this module is not unloaded before we finish
556 * using lttng_relay_transport.ops.
558 if (!try_module_get(THIS_MODULE
)) {
559 printk(KERN_WARNING
"LTTng: Can't lock transport module.\n");
562 chan
->backend
.priv_ops
= <tng_relay_transport
.ops
;
563 chan
->backend
.release_priv_ops
= release_priv_ops
;
568 lttng_channel_destroy(chan
);
573 struct lttng_kernel_ring_buffer
*lttng_buffer_read_open(struct lttng_kernel_ring_buffer_channel
*chan
)
575 struct lttng_kernel_ring_buffer
*buf
;
578 for_each_channel_cpu(cpu
, chan
) {
579 buf
= channel_get_ring_buffer(&client_config
, chan
, cpu
);
580 if (!lib_ring_buffer_open_read(buf
))
587 int lttng_buffer_has_read_closed_stream(struct lttng_kernel_ring_buffer_channel
*chan
)
589 struct lttng_kernel_ring_buffer
*buf
;
592 for_each_channel_cpu(cpu
, chan
) {
593 buf
= channel_get_ring_buffer(&client_config
, chan
, cpu
);
594 if (!atomic_long_read(&buf
->active_readers
))
601 void lttng_buffer_read_close(struct lttng_kernel_ring_buffer
*buf
)
603 lib_ring_buffer_release_read(buf
);
607 int lttng_event_reserve(struct lttng_kernel_ring_buffer_ctx
*ctx
)
609 struct lttng_kernel_event_recorder
*event_recorder
= ctx
->client_priv
;
610 struct lttng_kernel_channel_buffer
*lttng_chan
= event_recorder
->chan
;
611 struct lttng_client_ctx client_ctx
;
615 cpu
= lib_ring_buffer_get_cpu(&client_config
);
616 if (unlikely(cpu
< 0))
618 event_id
= event_recorder
->priv
->id
;
619 memset(&ctx
->priv
, 0, sizeof(ctx
->priv
));
620 ctx
->priv
.chan
= lttng_chan
->priv
->rb_chan
;
621 ctx
->priv
.reserve_cpu
= cpu
;
623 /* Compute internal size of context structures. */
624 ctx_get_struct_size(lttng_chan
->priv
->ctx
, &client_ctx
.packet_context_len
, lttng_chan
, ctx
);
626 switch (lttng_chan
->priv
->header_type
) {
627 case 1: /* compact */
629 ctx
->priv
.rflags
|= LTTNG_RFLAG_EXTENDED
;
632 if (event_id
> 65534)
633 ctx
->priv
.rflags
|= LTTNG_RFLAG_EXTENDED
;
639 ret
= lib_ring_buffer_reserve(&client_config
, ctx
, &client_ctx
);
642 lib_ring_buffer_backend_get_pages(&client_config
, ctx
,
643 &ctx
->priv
.backend_pages
);
644 lttng_write_event_header(&client_config
, ctx
, event_id
);
647 lib_ring_buffer_put_cpu(&client_config
);
652 void lttng_event_commit(struct lttng_kernel_ring_buffer_ctx
*ctx
)
654 lib_ring_buffer_commit(&client_config
, ctx
);
655 lib_ring_buffer_put_cpu(&client_config
);
659 void lttng_event_write(struct lttng_kernel_ring_buffer_ctx
*ctx
, const void *src
,
660 size_t len
, size_t alignment
)
662 lib_ring_buffer_align_ctx(ctx
, alignment
);
663 lib_ring_buffer_write(&client_config
, ctx
, src
, len
);
667 void lttng_event_write_from_user(struct lttng_kernel_ring_buffer_ctx
*ctx
,
668 const void __user
*src
, size_t len
, size_t alignment
)
670 lib_ring_buffer_align_ctx(ctx
, alignment
);
671 lib_ring_buffer_copy_from_user_inatomic(&client_config
, ctx
, src
, len
);
675 void lttng_event_memset(struct lttng_kernel_ring_buffer_ctx
*ctx
,
678 lib_ring_buffer_memset(&client_config
, ctx
, c
, len
);
682 void lttng_event_strcpy(struct lttng_kernel_ring_buffer_ctx
*ctx
, const char *src
,
685 lib_ring_buffer_strcpy(&client_config
, ctx
, src
, len
, '#');
689 void lttng_event_strcpy_from_user(struct lttng_kernel_ring_buffer_ctx
*ctx
,
690 const char __user
*src
, size_t len
)
692 lib_ring_buffer_strcpy_from_user_inatomic(&client_config
, ctx
, src
,
697 void lttng_event_pstrcpy_pad(struct lttng_kernel_ring_buffer_ctx
*ctx
, const char *src
,
700 lib_ring_buffer_pstrcpy(&client_config
, ctx
, src
, len
, '\0');
704 void lttng_event_pstrcpy_pad_from_user(struct lttng_kernel_ring_buffer_ctx
*ctx
, const char __user
*src
,
707 lib_ring_buffer_pstrcpy_from_user_inatomic(&client_config
, ctx
, src
, len
, '\0');
711 void lttng_channel_buffer_lost_event_too_big(struct lttng_kernel_channel_buffer
*lttng_chan
)
713 lib_ring_buffer_lost_event_too_big(lttng_chan
->priv
->rb_chan
);
717 wait_queue_head_t
*lttng_get_writer_buf_wait_queue(struct lttng_kernel_ring_buffer_channel
*chan
, int cpu
)
719 struct lttng_kernel_ring_buffer
*buf
= channel_get_ring_buffer(&client_config
,
721 return &buf
->write_wait
;
725 wait_queue_head_t
*lttng_get_hp_wait_queue(struct lttng_kernel_ring_buffer_channel
*chan
)
727 return &chan
->hp_wait
;
731 int lttng_is_finalized(struct lttng_kernel_ring_buffer_channel
*chan
)
733 return lib_ring_buffer_channel_is_finalized(chan
);
737 int lttng_is_disabled(struct lttng_kernel_ring_buffer_channel
*chan
)
739 return lib_ring_buffer_channel_is_disabled(chan
);
742 static struct lttng_transport lttng_relay_transport
= {
743 .name
= "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
,
744 .owner
= THIS_MODULE
,
746 .priv
= __LTTNG_COMPOUND_LITERAL(struct lttng_kernel_channel_buffer_ops_private
, {
747 .pub
= <tng_relay_transport
.ops
,
748 .channel_create
= _channel_create
,
749 .channel_destroy
= lttng_channel_destroy
,
750 .buffer_read_open
= lttng_buffer_read_open
,
751 .buffer_has_read_closed_stream
=
752 lttng_buffer_has_read_closed_stream
,
753 .buffer_read_close
= lttng_buffer_read_close
,
754 .packet_avail_size
= NULL
, /* Would be racy anyway */
755 .get_writer_buf_wait_queue
= lttng_get_writer_buf_wait_queue
,
756 .get_hp_wait_queue
= lttng_get_hp_wait_queue
,
757 .is_finalized
= lttng_is_finalized
,
758 .is_disabled
= lttng_is_disabled
,
759 .timestamp_begin
= client_timestamp_begin
,
760 .timestamp_end
= client_timestamp_end
,
761 .events_discarded
= client_events_discarded
,
762 .content_size
= client_content_size
,
763 .packet_size
= client_packet_size
,
764 .stream_id
= client_stream_id
,
765 .current_timestamp
= client_current_timestamp
,
766 .sequence_number
= client_sequence_number
,
767 .instance_id
= client_instance_id
,
769 .event_reserve
= lttng_event_reserve
,
770 .event_commit
= lttng_event_commit
,
771 .event_write
= lttng_event_write
,
772 .event_write_from_user
= lttng_event_write_from_user
,
773 .event_memset
= lttng_event_memset
,
774 .event_strcpy
= lttng_event_strcpy
,
775 .event_strcpy_from_user
= lttng_event_strcpy_from_user
,
776 .event_pstrcpy_pad
= lttng_event_pstrcpy_pad
,
777 .event_pstrcpy_pad_from_user
= lttng_event_pstrcpy_pad_from_user
,
778 .lost_event_too_big
= lttng_channel_buffer_lost_event_too_big
,
782 static int __init
lttng_ring_buffer_client_init(void)
785 * This vmalloc sync all also takes care of the lib ring buffer
786 * vmalloc'd module pages when it is built as a module into LTTng.
788 wrapper_vmalloc_sync_mappings();
789 lttng_transport_register(<tng_relay_transport
);
793 module_init(lttng_ring_buffer_client_init
);
795 static void __exit
lttng_ring_buffer_client_exit(void)
797 lttng_transport_unregister(<tng_relay_transport
);
800 module_exit(lttng_ring_buffer_client_exit
);
802 MODULE_LICENSE("GPL and additional rights");
803 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
804 MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
806 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
807 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
808 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
809 LTTNG_MODULES_EXTRAVERSION
);