2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * LTTng lib ring buffer client template.
12 #include <ust-events-internal.h>
13 #include "ust-bitfield.h"
14 #include "ust-compat.h"
16 #include "context-internal.h"
17 #include "lttng-tracer.h"
18 #include "../libringbuffer/frontend_types.h"
20 #define LTTNG_COMPACT_EVENT_BITS 5
21 #define LTTNG_COMPACT_TSC_BITS 27
29 * Keep the natural field alignment for _each field_ within this structure if
30 * you ever add/remove a field from this header. Packed attribute is not used
31 * because gcc generates poor code on at least powerpc and mips. Don't ever
32 * let gcc add padding between the structure elements.
35 struct packet_header
{
36 /* Trace packet header */
39 * contains endianness information.
41 uint8_t uuid
[LTTNG_UST_UUID_LEN
];
43 uint64_t stream_instance_id
;
46 /* Stream packet context */
47 uint64_t timestamp_begin
; /* Cycle count at subbuffer start */
48 uint64_t timestamp_end
; /* Cycle count at subbuffer end */
49 uint64_t content_size
; /* Size of data in subbuffer */
50 uint64_t packet_size
; /* Subbuffer size (include padding) */
51 uint64_t packet_seq_num
; /* Packet sequence number */
52 unsigned long events_discarded
; /*
53 * Events lost in this subbuffer since
54 * the beginning of the trace.
57 uint32_t cpu_id
; /* CPU id associated with stream */
58 uint8_t header_end
; /* End of header */
62 struct lttng_client_ctx
{
63 size_t packet_context_len
;
64 size_t event_context_len
;
67 static inline uint64_t lib_ring_buffer_clock_read(struct channel
*chan
)
69 return trace_clock_read64();
73 size_t ctx_get_aligned_size(size_t offset
, struct lttng_ctx
*ctx
,
76 size_t orig_offset
= offset
;
80 offset
+= lib_ring_buffer_align(offset
, ctx
->largest_align
);
82 return offset
- orig_offset
;
86 void ctx_get_struct_size(struct lttng_ctx
*ctx
, size_t *ctx_len
,
87 enum app_ctx_mode mode
)
92 if (caa_likely(!ctx
)) {
96 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
97 if (mode
== APP_CTX_ENABLED
) {
98 offset
+= ctx
->fields
[i
].get_size(&ctx
->fields
[i
], offset
);
100 if (lttng_context_is_app(ctx
->fields
[i
].event_field
.name
)) {
102 * Before UST 2.8, we cannot use the
103 * application context, because we
104 * cannot trust that the handler used
105 * for get_size is the same used for
106 * ctx_record, which would result in
107 * corrupted traces when tracing
108 * concurrently with application context
109 * register/unregister.
111 offset
+= lttng_ust_dummy_get_size(&ctx
->fields
[i
], offset
);
113 offset
+= ctx
->fields
[i
].get_size(&ctx
->fields
[i
], offset
);
121 void ctx_record(struct lttng_ust_lib_ring_buffer_ctx
*bufctx
,
122 struct lttng_channel
*chan
,
123 struct lttng_ctx
*ctx
,
124 enum app_ctx_mode mode
)
128 if (caa_likely(!ctx
))
130 lib_ring_buffer_align_ctx(bufctx
, ctx
->largest_align
);
131 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
132 if (mode
== APP_CTX_ENABLED
) {
133 ctx
->fields
[i
].record(&ctx
->fields
[i
], bufctx
, chan
);
135 if (lttng_context_is_app(ctx
->fields
[i
].event_field
.name
)) {
137 * Before UST 2.8, we cannot use the
138 * application context, because we
139 * cannot trust that the handler used
140 * for get_size is the same used for
141 * ctx_record, which would result in
142 * corrupted traces when tracing
143 * concurrently with application context
144 * register/unregister.
146 lttng_ust_dummy_record(&ctx
->fields
[i
], bufctx
, chan
);
148 ctx
->fields
[i
].record(&ctx
->fields
[i
], bufctx
, chan
);
155 * record_header_size - Calculate the header size and padding necessary.
156 * @config: ring buffer instance configuration
158 * @offset: offset in the write buffer
159 * @pre_header_padding: padding to add before the header (output)
160 * @ctx: reservation context
162 * Returns the event header size (including padding).
164 * The payload must itself determine its own alignment from the biggest type it
168 size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
169 struct channel
*chan
, size_t offset
,
170 size_t *pre_header_padding
,
171 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
172 struct lttng_client_ctx
*client_ctx
)
174 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
175 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv
;
176 size_t orig_offset
= offset
;
179 switch (lttng_chan
->header_type
) {
180 case 1: /* compact */
181 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
183 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
184 offset
+= sizeof(uint32_t); /* id and timestamp */
186 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
187 offset
+= (LTTNG_COMPACT_EVENT_BITS
+ CHAR_BIT
- 1) / CHAR_BIT
;
188 /* Align extended struct on largest member */
189 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
190 offset
+= sizeof(uint32_t); /* id */
191 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
192 offset
+= sizeof(uint64_t); /* timestamp */
196 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
198 offset
+= sizeof(uint16_t);
199 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
200 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
201 offset
+= sizeof(uint32_t); /* timestamp */
203 /* Align extended struct on largest member */
204 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
205 offset
+= sizeof(uint32_t); /* id */
206 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
207 offset
+= sizeof(uint64_t); /* timestamp */
214 offset
+= ctx_get_aligned_size(offset
, lttng_ctx
->chan_ctx
,
215 client_ctx
->packet_context_len
);
216 offset
+= ctx_get_aligned_size(offset
, lttng_ctx
->event_ctx
,
217 client_ctx
->event_context_len
);
218 *pre_header_padding
= padding
;
219 return offset
- orig_offset
;
222 #include "../libringbuffer/api.h"
223 #include "lttng-rb-clients.h"
226 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
227 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
231 * lttng_write_event_header
233 * Writes the event header to the offset (already aligned on 32-bits).
235 * @config: ring buffer instance configuration
236 * @ctx: reservation context
237 * @event_id: event ID
240 void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config
*config
,
241 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
244 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
245 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv
;
247 if (caa_unlikely(ctx
->rflags
))
250 switch (lttng_chan
->header_type
) {
251 case 1: /* compact */
253 uint32_t id_time
= 0;
255 bt_bitfield_write(&id_time
, uint32_t,
257 LTTNG_COMPACT_EVENT_BITS
,
259 bt_bitfield_write(&id_time
, uint32_t,
260 LTTNG_COMPACT_EVENT_BITS
,
261 LTTNG_COMPACT_TSC_BITS
,
263 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
268 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
269 uint16_t id
= event_id
;
271 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
272 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
273 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
280 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
281 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
282 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
287 lttng_write_event_header_slow(config
, ctx
, event_id
);
291 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
292 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
295 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
296 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv
;
298 switch (lttng_chan
->header_type
) {
299 case 1: /* compact */
300 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
301 uint32_t id_time
= 0;
303 bt_bitfield_write(&id_time
, uint32_t,
305 LTTNG_COMPACT_EVENT_BITS
,
307 bt_bitfield_write(&id_time
, uint32_t,
308 LTTNG_COMPACT_EVENT_BITS
,
309 LTTNG_COMPACT_TSC_BITS
,
311 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
314 uint64_t timestamp
= ctx
->tsc
;
316 bt_bitfield_write(&id
, uint8_t,
318 LTTNG_COMPACT_EVENT_BITS
,
320 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
321 /* Align extended struct on largest member */
322 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
323 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
324 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
325 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
330 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
331 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
332 uint16_t id
= event_id
;
334 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
335 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
336 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
339 uint64_t timestamp
= ctx
->tsc
;
341 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
342 /* Align extended struct on largest member */
343 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
344 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
345 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
346 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
353 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
354 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
355 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
358 static const struct lttng_ust_lib_ring_buffer_config client_config
;
360 static uint64_t client_ring_buffer_clock_read(struct channel
*chan
)
362 return lib_ring_buffer_clock_read(chan
);
366 size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
367 struct channel
*chan
, size_t offset
,
368 size_t *pre_header_padding
,
369 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
372 return record_header_size(config
, chan
, offset
,
373 pre_header_padding
, ctx
, client_ctx
);
377 * client_packet_header_size - called on buffer-switch to a new sub-buffer
379 * Return header size without padding after the structure. Don't use packed
380 * structure because gcc generates inefficient code on some architectures
383 static size_t client_packet_header_size(void)
385 return offsetof(struct packet_header
, ctx
.header_end
);
388 static void client_buffer_begin(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
389 unsigned int subbuf_idx
,
390 struct lttng_ust_shm_handle
*handle
)
392 struct channel
*chan
= shmp(handle
, 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
,
398 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
399 uint64_t cnt
= shmp_index(handle
, buf
->backend
.buf_cnt
, subbuf_idx
)->seq_cnt
;
404 header
->magic
= CTF_MAGIC_NUMBER
;
405 memcpy(header
->uuid
, lttng_chan
->uuid
, sizeof(lttng_chan
->uuid
));
406 header
->stream_id
= lttng_chan
->id
;
407 header
->stream_instance_id
= buf
->backend
.cpu
;
408 header
->ctx
.timestamp_begin
= tsc
;
409 header
->ctx
.timestamp_end
= 0;
410 header
->ctx
.content_size
= ~0ULL; /* for debugging */
411 header
->ctx
.packet_size
= ~0ULL;
412 header
->ctx
.packet_seq_num
= chan
->backend
.num_subbuf
* cnt
+ subbuf_idx
;
413 header
->ctx
.events_discarded
= 0;
414 header
->ctx
.cpu_id
= buf
->backend
.cpu
;
418 * offset is assumed to never be 0 here : never deliver a completely empty
419 * subbuffer. data_size is between 1 and subbuf_size.
421 static void client_buffer_end(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
422 unsigned int subbuf_idx
, unsigned long data_size
,
423 struct lttng_ust_shm_handle
*handle
)
425 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
426 struct packet_header
*header
=
427 (struct packet_header
*)
428 lib_ring_buffer_offset_address(&buf
->backend
,
429 subbuf_idx
* chan
->backend
.subbuf_size
,
431 unsigned long records_lost
= 0;
436 header
->ctx
.timestamp_end
= tsc
;
437 header
->ctx
.content_size
=
438 (uint64_t) data_size
* CHAR_BIT
; /* in bits */
439 header
->ctx
.packet_size
=
440 (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size
) * CHAR_BIT
; /* in bits */
442 records_lost
+= lib_ring_buffer_get_records_lost_full(&client_config
, buf
);
443 records_lost
+= lib_ring_buffer_get_records_lost_wrap(&client_config
, buf
);
444 records_lost
+= lib_ring_buffer_get_records_lost_big(&client_config
, buf
);
445 header
->ctx
.events_discarded
= records_lost
;
448 static int client_buffer_create(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
,
449 int cpu
, const char *name
, struct lttng_ust_shm_handle
*handle
)
454 static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
, int cpu
, struct lttng_ust_shm_handle
*handle
)
458 static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
459 size_t *offset
, size_t *length
)
461 *offset
= offsetof(struct packet_header
, ctx
.content_size
);
462 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.content_size
);
465 static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
466 size_t *offset
, size_t *length
)
468 *offset
= offsetof(struct packet_header
, ctx
.packet_size
);
469 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.packet_size
);
472 static struct packet_header
*client_packet_header(struct lttng_ust_lib_ring_buffer
*buf
,
473 struct lttng_ust_shm_handle
*handle
)
475 return lib_ring_buffer_read_offset_address(&buf
->backend
, 0, handle
);
478 static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer
*buf
,
479 struct lttng_ust_shm_handle
*handle
,
480 uint64_t *timestamp_begin
)
482 struct packet_header
*header
;
484 header
= client_packet_header(buf
, handle
);
487 *timestamp_begin
= header
->ctx
.timestamp_begin
;
491 static int client_timestamp_end(struct lttng_ust_lib_ring_buffer
*buf
,
492 struct lttng_ust_shm_handle
*handle
,
493 uint64_t *timestamp_end
)
495 struct packet_header
*header
;
497 header
= client_packet_header(buf
, handle
);
500 *timestamp_end
= header
->ctx
.timestamp_end
;
504 static int client_events_discarded(struct lttng_ust_lib_ring_buffer
*buf
,
505 struct lttng_ust_shm_handle
*handle
,
506 uint64_t *events_discarded
)
508 struct packet_header
*header
;
510 header
= client_packet_header(buf
, handle
);
513 *events_discarded
= header
->ctx
.events_discarded
;
517 static int client_content_size(struct lttng_ust_lib_ring_buffer
*buf
,
518 struct lttng_ust_shm_handle
*handle
,
519 uint64_t *content_size
)
521 struct packet_header
*header
;
523 header
= client_packet_header(buf
, handle
);
526 *content_size
= header
->ctx
.content_size
;
530 static int client_packet_size(struct lttng_ust_lib_ring_buffer
*buf
,
531 struct lttng_ust_shm_handle
*handle
,
532 uint64_t *packet_size
)
534 struct packet_header
*header
;
536 header
= client_packet_header(buf
, handle
);
539 *packet_size
= header
->ctx
.packet_size
;
543 static int client_stream_id(struct lttng_ust_lib_ring_buffer
*buf
,
544 struct lttng_ust_shm_handle
*handle
,
547 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
548 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
550 *stream_id
= lttng_chan
->id
;
555 static int client_current_timestamp(struct lttng_ust_lib_ring_buffer
*buf
,
556 struct lttng_ust_shm_handle
*handle
,
559 struct channel
*chan
;
561 chan
= shmp(handle
, handle
->chan
);
562 *ts
= client_ring_buffer_clock_read(chan
);
567 static int client_sequence_number(struct lttng_ust_lib_ring_buffer
*buf
,
568 struct lttng_ust_shm_handle
*handle
,
571 struct packet_header
*header
;
573 header
= client_packet_header(buf
, handle
);
576 *seq
= header
->ctx
.packet_seq_num
;
580 static int client_instance_id(struct lttng_ust_lib_ring_buffer
*buf
,
581 struct lttng_ust_shm_handle
*handle
,
584 *id
= buf
->backend
.cpu
;
590 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb
= {
592 .ring_buffer_clock_read
= client_ring_buffer_clock_read
,
593 .record_header_size
= client_record_header_size
,
594 .subbuffer_header_size
= client_packet_header_size
,
595 .buffer_begin
= client_buffer_begin
,
596 .buffer_end
= client_buffer_end
,
597 .buffer_create
= client_buffer_create
,
598 .buffer_finalize
= client_buffer_finalize
,
599 .content_size_field
= client_content_size_field
,
600 .packet_size_field
= client_packet_size_field
,
602 .timestamp_begin
= client_timestamp_begin
,
603 .timestamp_end
= client_timestamp_end
,
604 .events_discarded
= client_events_discarded
,
605 .content_size
= client_content_size
,
606 .packet_size
= client_packet_size
,
607 .stream_id
= client_stream_id
,
608 .current_timestamp
= client_current_timestamp
,
609 .sequence_number
= client_sequence_number
,
610 .instance_id
= client_instance_id
,
613 static const struct lttng_ust_lib_ring_buffer_config client_config
= {
614 .cb
.ring_buffer_clock_read
= client_ring_buffer_clock_read
,
615 .cb
.record_header_size
= client_record_header_size
,
616 .cb
.subbuffer_header_size
= client_packet_header_size
,
617 .cb
.buffer_begin
= client_buffer_begin
,
618 .cb
.buffer_end
= client_buffer_end
,
619 .cb
.buffer_create
= client_buffer_create
,
620 .cb
.buffer_finalize
= client_buffer_finalize
,
621 .cb
.content_size_field
= client_content_size_field
,
622 .cb
.packet_size_field
= client_packet_size_field
,
624 .tsc_bits
= LTTNG_COMPACT_TSC_BITS
,
625 .alloc
= RING_BUFFER_ALLOC_PER_CPU
,
626 .sync
= RING_BUFFER_SYNC_GLOBAL
,
627 .mode
= RING_BUFFER_MODE_TEMPLATE
,
628 .backend
= RING_BUFFER_PAGE
,
629 .output
= RING_BUFFER_MMAP
,
630 .oops
= RING_BUFFER_OOPS_CONSISTENCY
,
631 .ipi
= RING_BUFFER_NO_IPI_BARRIER
,
632 .wakeup
= LTTNG_CLIENT_WAKEUP
,
633 .client_type
= LTTNG_CLIENT_TYPE
,
635 .cb_ptr
= &client_cb
.parent
,
639 struct lttng_channel
*_channel_create(const char *name
,
641 size_t subbuf_size
, size_t num_subbuf
,
642 unsigned int switch_timer_interval
,
643 unsigned int read_timer_interval
,
646 const int *stream_fds
, int nr_stream_fds
,
647 int64_t blocking_timeout
)
649 struct lttng_channel chan_priv_init
;
650 struct lttng_ust_shm_handle
*handle
;
651 struct lttng_channel
*lttng_chan
;
654 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
655 memcpy(chan_priv_init
.uuid
, uuid
, LTTNG_UST_UUID_LEN
);
656 chan_priv_init
.id
= chan_id
;
657 handle
= channel_create(&client_config
, name
,
658 &priv
, __alignof__(struct lttng_channel
),
659 sizeof(struct lttng_channel
),
661 buf_addr
, subbuf_size
, num_subbuf
,
662 switch_timer_interval
, read_timer_interval
,
663 stream_fds
, nr_stream_fds
, blocking_timeout
);
667 lttng_chan
->handle
= handle
;
668 lttng_chan
->chan
= shmp(handle
, handle
->chan
);
673 void lttng_channel_destroy(struct lttng_channel
*chan
)
675 channel_destroy(chan
->chan
, chan
->handle
, 1);
679 int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
682 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
683 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv
;
684 struct lttng_client_ctx client_ctx
;
687 /* Compute internal size of context structures. */
688 ctx_get_struct_size(lttng_ctx
->chan_ctx
, &client_ctx
.packet_context_len
,
690 ctx_get_struct_size(lttng_ctx
->event_ctx
, &client_ctx
.event_context_len
,
693 cpu
= lib_ring_buffer_get_cpu(&client_config
);
698 switch (lttng_chan
->header_type
) {
699 case 1: /* compact */
701 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
704 if (event_id
> 65534)
705 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
711 ret
= lib_ring_buffer_reserve(&client_config
, ctx
, &client_ctx
);
712 if (caa_unlikely(ret
))
714 if (lib_ring_buffer_backend_get_pages(&client_config
, ctx
,
715 &ctx
->backend_pages
)) {
719 lttng_write_event_header(&client_config
, ctx
, event_id
);
722 lib_ring_buffer_put_cpu(&client_config
);
727 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
729 lib_ring_buffer_commit(&client_config
, ctx
);
730 lib_ring_buffer_put_cpu(&client_config
);
734 void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
737 lib_ring_buffer_write(&client_config
, ctx
, src
, len
);
741 void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const char *src
,
744 lib_ring_buffer_strcpy(&client_config
, ctx
, src
, len
, '#');
749 wait_queue_head_t
*lttng_get_reader_wait_queue(struct channel
*chan
)
751 return &chan
->read_wait
;
755 wait_queue_head_t
*lttng_get_hp_wait_queue(struct channel
*chan
)
757 return &chan
->hp_wait
;
762 int lttng_is_finalized(struct channel
*chan
)
764 return lib_ring_buffer_channel_is_finalized(chan
);
768 int lttng_is_disabled(struct channel
*chan
)
770 return lib_ring_buffer_channel_is_disabled(chan
);
774 int lttng_flush_buffer(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
)
776 struct lttng_ust_lib_ring_buffer
*buf
;
779 for_each_channel_cpu(cpu
, chan
) {
780 int shm_fd
, wait_fd
, wakeup_fd
;
781 uint64_t memory_map_size
;
783 buf
= channel_get_ring_buffer(&client_config
, chan
,
784 cpu
, handle
, &shm_fd
, &wait_fd
,
785 &wakeup_fd
, &memory_map_size
);
786 lib_ring_buffer_switch(&client_config
, buf
,
787 SWITCH_ACTIVE
, handle
);
792 static struct lttng_transport lttng_relay_transport
= {
793 .name
= "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap",
795 .struct_size
= sizeof(struct lttng_ust_channel_ops
),
796 .channel_create
= _channel_create
,
797 .channel_destroy
= lttng_channel_destroy
,
798 .event_reserve
= lttng_event_reserve
,
799 .event_commit
= lttng_event_commit
,
800 .event_write
= lttng_event_write
,
801 .packet_avail_size
= NULL
, /* Would be racy anyway */
802 .is_finalized
= lttng_is_finalized
,
803 .is_disabled
= lttng_is_disabled
,
804 .flush_buffer
= lttng_flush_buffer
,
805 .event_strcpy
= lttng_event_strcpy
,
807 .client_config
= &client_config
,
810 void RING_BUFFER_MODE_TEMPLATE_INIT(void)
812 DBG("LTT : ltt ring buffer client \"%s\" init\n",
813 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
814 lttng_transport_register(<tng_relay_transport
);
817 void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
819 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
820 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
821 lttng_transport_unregister(<tng_relay_transport
);