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_ust_event_recorder
*event_recorder
= ctx
->priv
;
176 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
177 size_t orig_offset
= offset
;
180 switch (lttng_chan
->header_type
) {
181 case 1: /* compact */
182 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
184 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
185 offset
+= sizeof(uint32_t); /* id and timestamp */
187 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
188 offset
+= (LTTNG_COMPACT_EVENT_BITS
+ CHAR_BIT
- 1) / CHAR_BIT
;
189 /* Align extended struct on largest member */
190 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
191 offset
+= sizeof(uint32_t); /* id */
192 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
193 offset
+= sizeof(uint64_t); /* timestamp */
197 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
199 offset
+= sizeof(uint16_t);
200 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
201 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
202 offset
+= sizeof(uint32_t); /* timestamp */
204 /* Align extended struct on largest member */
205 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
206 offset
+= sizeof(uint32_t); /* id */
207 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
208 offset
+= sizeof(uint64_t); /* timestamp */
216 /* 2.8+ probe ABI. */
217 offset
+= ctx_get_aligned_size(offset
, lttng_ctx
->chan_ctx
,
218 client_ctx
->packet_context_len
);
219 offset
+= ctx_get_aligned_size(offset
, lttng_ctx
->event_ctx
,
220 client_ctx
->event_context_len
);
222 /* Pre 2.8 probe ABI. */
223 offset
+= ctx_get_aligned_size(offset
, lttng_chan
->ctx
,
224 client_ctx
->packet_context_len
);
225 offset
+= ctx_get_aligned_size(offset
, event_recorder
->ctx
,
226 client_ctx
->event_context_len
);
228 *pre_header_padding
= padding
;
229 return offset
- orig_offset
;
232 #include "../libringbuffer/api.h"
233 #include "lttng-rb-clients.h"
236 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
237 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
241 * lttng_write_event_header
243 * Writes the event header to the offset (already aligned on 32-bits).
245 * @config: ring buffer instance configuration
246 * @ctx: reservation context
247 * @event_id: event ID
250 void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config
*config
,
251 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
254 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
255 struct lttng_ust_event_recorder
*event_recorder
= ctx
->priv
;
256 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
258 if (caa_unlikely(ctx
->rflags
))
261 switch (lttng_chan
->header_type
) {
262 case 1: /* compact */
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
,
274 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
279 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
280 uint16_t id
= event_id
;
282 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
283 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
284 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
292 /* 2.8+ probe ABI. */
293 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
294 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
296 /* Pre 2.8 probe ABI. */
297 ctx_record(ctx
, lttng_chan
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
298 ctx_record(ctx
, lttng_chan
, event_recorder
->ctx
, APP_CTX_DISABLED
);
300 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
305 lttng_write_event_header_slow(config
, ctx
, event_id
);
309 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
310 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
313 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
314 struct lttng_ust_event_recorder
*event_recorder
= ctx
->priv
;
315 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
317 switch (lttng_chan
->header_type
) {
318 case 1: /* compact */
319 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
320 uint32_t id_time
= 0;
322 bt_bitfield_write(&id_time
, uint32_t,
324 LTTNG_COMPACT_EVENT_BITS
,
326 bt_bitfield_write(&id_time
, uint32_t,
327 LTTNG_COMPACT_EVENT_BITS
,
328 LTTNG_COMPACT_TSC_BITS
,
330 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
333 uint64_t timestamp
= ctx
->tsc
;
335 bt_bitfield_write(&id
, uint8_t,
337 LTTNG_COMPACT_EVENT_BITS
,
339 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
340 /* Align extended struct on largest member */
341 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
342 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
343 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
344 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
349 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
350 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
351 uint16_t id
= event_id
;
353 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
354 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
355 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
358 uint64_t timestamp
= ctx
->tsc
;
360 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
361 /* Align extended struct on largest member */
362 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
363 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
364 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
365 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
373 /* 2.8+ probe ABI. */
374 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
375 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
377 /* Pre 2.8 probe ABI. */
378 ctx_record(ctx
, lttng_chan
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
379 ctx_record(ctx
, lttng_chan
, event_recorder
->ctx
, APP_CTX_DISABLED
);
381 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
384 static const struct lttng_ust_lib_ring_buffer_config client_config
;
386 static uint64_t client_ring_buffer_clock_read(struct channel
*chan
)
388 return lib_ring_buffer_clock_read(chan
);
392 size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
393 struct channel
*chan
, size_t offset
,
394 size_t *pre_header_padding
,
395 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
398 return record_header_size(config
, chan
, offset
,
399 pre_header_padding
, ctx
, client_ctx
);
403 * client_packet_header_size - called on buffer-switch to a new sub-buffer
405 * Return header size without padding after the structure. Don't use packed
406 * structure because gcc generates inefficient code on some architectures
409 static size_t client_packet_header_size(void)
411 return offsetof(struct packet_header
, ctx
.header_end
);
414 static void client_buffer_begin(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
415 unsigned int subbuf_idx
,
416 struct lttng_ust_shm_handle
*handle
)
418 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
419 struct packet_header
*header
=
420 (struct packet_header
*)
421 lib_ring_buffer_offset_address(&buf
->backend
,
422 subbuf_idx
* chan
->backend
.subbuf_size
,
424 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
425 uint64_t cnt
= shmp_index(handle
, buf
->backend
.buf_cnt
, subbuf_idx
)->seq_cnt
;
430 header
->magic
= CTF_MAGIC_NUMBER
;
431 memcpy(header
->uuid
, lttng_chan
->uuid
, sizeof(lttng_chan
->uuid
));
432 header
->stream_id
= lttng_chan
->id
;
433 header
->stream_instance_id
= buf
->backend
.cpu
;
434 header
->ctx
.timestamp_begin
= tsc
;
435 header
->ctx
.timestamp_end
= 0;
436 header
->ctx
.content_size
= ~0ULL; /* for debugging */
437 header
->ctx
.packet_size
= ~0ULL;
438 header
->ctx
.packet_seq_num
= chan
->backend
.num_subbuf
* cnt
+ subbuf_idx
;
439 header
->ctx
.events_discarded
= 0;
440 header
->ctx
.cpu_id
= buf
->backend
.cpu
;
444 * offset is assumed to never be 0 here : never deliver a completely empty
445 * subbuffer. data_size is between 1 and subbuf_size.
447 static void client_buffer_end(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
448 unsigned int subbuf_idx
, unsigned long data_size
,
449 struct lttng_ust_shm_handle
*handle
)
451 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
452 struct packet_header
*header
=
453 (struct packet_header
*)
454 lib_ring_buffer_offset_address(&buf
->backend
,
455 subbuf_idx
* chan
->backend
.subbuf_size
,
457 unsigned long records_lost
= 0;
462 header
->ctx
.timestamp_end
= tsc
;
463 header
->ctx
.content_size
=
464 (uint64_t) data_size
* CHAR_BIT
; /* in bits */
465 header
->ctx
.packet_size
=
466 (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size
) * CHAR_BIT
; /* in bits */
468 records_lost
+= lib_ring_buffer_get_records_lost_full(&client_config
, buf
);
469 records_lost
+= lib_ring_buffer_get_records_lost_wrap(&client_config
, buf
);
470 records_lost
+= lib_ring_buffer_get_records_lost_big(&client_config
, buf
);
471 header
->ctx
.events_discarded
= records_lost
;
474 static int client_buffer_create(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
,
475 int cpu
, const char *name
, struct lttng_ust_shm_handle
*handle
)
480 static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
, int cpu
, struct lttng_ust_shm_handle
*handle
)
484 static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
485 size_t *offset
, size_t *length
)
487 *offset
= offsetof(struct packet_header
, ctx
.content_size
);
488 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.content_size
);
491 static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
492 size_t *offset
, size_t *length
)
494 *offset
= offsetof(struct packet_header
, ctx
.packet_size
);
495 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.packet_size
);
498 static struct packet_header
*client_packet_header(struct lttng_ust_lib_ring_buffer
*buf
,
499 struct lttng_ust_shm_handle
*handle
)
501 return lib_ring_buffer_read_offset_address(&buf
->backend
, 0, handle
);
504 static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer
*buf
,
505 struct lttng_ust_shm_handle
*handle
,
506 uint64_t *timestamp_begin
)
508 struct packet_header
*header
;
510 header
= client_packet_header(buf
, handle
);
513 *timestamp_begin
= header
->ctx
.timestamp_begin
;
517 static int client_timestamp_end(struct lttng_ust_lib_ring_buffer
*buf
,
518 struct lttng_ust_shm_handle
*handle
,
519 uint64_t *timestamp_end
)
521 struct packet_header
*header
;
523 header
= client_packet_header(buf
, handle
);
526 *timestamp_end
= header
->ctx
.timestamp_end
;
530 static int client_events_discarded(struct lttng_ust_lib_ring_buffer
*buf
,
531 struct lttng_ust_shm_handle
*handle
,
532 uint64_t *events_discarded
)
534 struct packet_header
*header
;
536 header
= client_packet_header(buf
, handle
);
539 *events_discarded
= header
->ctx
.events_discarded
;
543 static int client_content_size(struct lttng_ust_lib_ring_buffer
*buf
,
544 struct lttng_ust_shm_handle
*handle
,
545 uint64_t *content_size
)
547 struct packet_header
*header
;
549 header
= client_packet_header(buf
, handle
);
552 *content_size
= header
->ctx
.content_size
;
556 static int client_packet_size(struct lttng_ust_lib_ring_buffer
*buf
,
557 struct lttng_ust_shm_handle
*handle
,
558 uint64_t *packet_size
)
560 struct packet_header
*header
;
562 header
= client_packet_header(buf
, handle
);
565 *packet_size
= header
->ctx
.packet_size
;
569 static int client_stream_id(struct lttng_ust_lib_ring_buffer
*buf
,
570 struct lttng_ust_shm_handle
*handle
,
573 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
574 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
576 *stream_id
= lttng_chan
->id
;
581 static int client_current_timestamp(struct lttng_ust_lib_ring_buffer
*buf
,
582 struct lttng_ust_shm_handle
*handle
,
585 struct channel
*chan
;
587 chan
= shmp(handle
, handle
->chan
);
588 *ts
= client_ring_buffer_clock_read(chan
);
593 static int client_sequence_number(struct lttng_ust_lib_ring_buffer
*buf
,
594 struct lttng_ust_shm_handle
*handle
,
597 struct packet_header
*header
;
599 header
= client_packet_header(buf
, handle
);
602 *seq
= header
->ctx
.packet_seq_num
;
606 static int client_instance_id(struct lttng_ust_lib_ring_buffer
*buf
,
607 struct lttng_ust_shm_handle
*handle
,
610 *id
= buf
->backend
.cpu
;
616 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb
= {
618 .ring_buffer_clock_read
= client_ring_buffer_clock_read
,
619 .record_header_size
= client_record_header_size
,
620 .subbuffer_header_size
= client_packet_header_size
,
621 .buffer_begin
= client_buffer_begin
,
622 .buffer_end
= client_buffer_end
,
623 .buffer_create
= client_buffer_create
,
624 .buffer_finalize
= client_buffer_finalize
,
625 .content_size_field
= client_content_size_field
,
626 .packet_size_field
= client_packet_size_field
,
628 .timestamp_begin
= client_timestamp_begin
,
629 .timestamp_end
= client_timestamp_end
,
630 .events_discarded
= client_events_discarded
,
631 .content_size
= client_content_size
,
632 .packet_size
= client_packet_size
,
633 .stream_id
= client_stream_id
,
634 .current_timestamp
= client_current_timestamp
,
635 .sequence_number
= client_sequence_number
,
636 .instance_id
= client_instance_id
,
639 static const struct lttng_ust_lib_ring_buffer_config client_config
= {
640 .cb
.ring_buffer_clock_read
= client_ring_buffer_clock_read
,
641 .cb
.record_header_size
= client_record_header_size
,
642 .cb
.subbuffer_header_size
= client_packet_header_size
,
643 .cb
.buffer_begin
= client_buffer_begin
,
644 .cb
.buffer_end
= client_buffer_end
,
645 .cb
.buffer_create
= client_buffer_create
,
646 .cb
.buffer_finalize
= client_buffer_finalize
,
647 .cb
.content_size_field
= client_content_size_field
,
648 .cb
.packet_size_field
= client_packet_size_field
,
650 .tsc_bits
= LTTNG_COMPACT_TSC_BITS
,
651 .alloc
= RING_BUFFER_ALLOC_PER_CPU
,
652 .sync
= RING_BUFFER_SYNC_GLOBAL
,
653 .mode
= RING_BUFFER_MODE_TEMPLATE
,
654 .backend
= RING_BUFFER_PAGE
,
655 .output
= RING_BUFFER_MMAP
,
656 .oops
= RING_BUFFER_OOPS_CONSISTENCY
,
657 .ipi
= RING_BUFFER_NO_IPI_BARRIER
,
658 .wakeup
= LTTNG_CLIENT_WAKEUP
,
659 .client_type
= LTTNG_CLIENT_TYPE
,
661 .cb_ptr
= &client_cb
.parent
,
665 struct lttng_channel
*_channel_create(const char *name
,
667 size_t subbuf_size
, size_t num_subbuf
,
668 unsigned int switch_timer_interval
,
669 unsigned int read_timer_interval
,
672 const int *stream_fds
, int nr_stream_fds
,
673 int64_t blocking_timeout
)
675 struct lttng_channel chan_priv_init
;
676 struct lttng_ust_shm_handle
*handle
;
677 struct lttng_channel
*lttng_chan
;
680 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
681 memcpy(chan_priv_init
.uuid
, uuid
, LTTNG_UST_UUID_LEN
);
682 chan_priv_init
.id
= chan_id
;
683 handle
= channel_create(&client_config
, name
,
684 &priv
, __alignof__(struct lttng_channel
),
685 sizeof(struct lttng_channel
),
687 buf_addr
, subbuf_size
, num_subbuf
,
688 switch_timer_interval
, read_timer_interval
,
689 stream_fds
, nr_stream_fds
, blocking_timeout
);
693 lttng_chan
->handle
= handle
;
694 lttng_chan
->chan
= shmp(handle
, handle
->chan
);
699 void lttng_channel_destroy(struct lttng_channel
*chan
)
701 channel_destroy(chan
->chan
, chan
->handle
, 1);
705 int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
708 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
709 struct lttng_ust_event_recorder
*event_recorder
= ctx
->priv
;
710 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
711 struct lttng_client_ctx client_ctx
;
714 /* Compute internal size of context structures. */
717 /* 2.8+ probe ABI. */
718 ctx_get_struct_size(lttng_ctx
->chan_ctx
, &client_ctx
.packet_context_len
,
720 ctx_get_struct_size(lttng_ctx
->event_ctx
, &client_ctx
.event_context_len
,
723 /* Pre 2.8 probe ABI. */
724 ctx_get_struct_size(lttng_chan
->ctx
, &client_ctx
.packet_context_len
,
726 ctx_get_struct_size(event_recorder
->ctx
, &client_ctx
.event_context_len
,
730 cpu
= lib_ring_buffer_get_cpu(&client_config
);
735 switch (lttng_chan
->header_type
) {
736 case 1: /* compact */
738 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
741 if (event_id
> 65534)
742 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
748 ret
= lib_ring_buffer_reserve(&client_config
, ctx
, &client_ctx
);
749 if (caa_unlikely(ret
))
751 if (caa_likely(ctx
->ctx_len
752 >= sizeof(struct lttng_ust_lib_ring_buffer_ctx
))) {
753 if (lib_ring_buffer_backend_get_pages(&client_config
, ctx
,
754 &ctx
->backend_pages
)) {
759 lttng_write_event_header(&client_config
, ctx
, event_id
);
762 lib_ring_buffer_put_cpu(&client_config
);
767 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
769 lib_ring_buffer_commit(&client_config
, ctx
);
770 lib_ring_buffer_put_cpu(&client_config
);
774 void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
777 lib_ring_buffer_write(&client_config
, ctx
, src
, len
);
781 void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const char *src
,
784 lib_ring_buffer_strcpy(&client_config
, ctx
, src
, len
, '#');
789 wait_queue_head_t
*lttng_get_reader_wait_queue(struct channel
*chan
)
791 return &chan
->read_wait
;
795 wait_queue_head_t
*lttng_get_hp_wait_queue(struct channel
*chan
)
797 return &chan
->hp_wait
;
802 int lttng_is_finalized(struct channel
*chan
)
804 return lib_ring_buffer_channel_is_finalized(chan
);
808 int lttng_is_disabled(struct channel
*chan
)
810 return lib_ring_buffer_channel_is_disabled(chan
);
814 int lttng_flush_buffer(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
)
816 struct lttng_ust_lib_ring_buffer
*buf
;
819 for_each_channel_cpu(cpu
, chan
) {
820 int shm_fd
, wait_fd
, wakeup_fd
;
821 uint64_t memory_map_size
;
823 buf
= channel_get_ring_buffer(&client_config
, chan
,
824 cpu
, handle
, &shm_fd
, &wait_fd
,
825 &wakeup_fd
, &memory_map_size
);
826 lib_ring_buffer_switch(&client_config
, buf
,
827 SWITCH_ACTIVE
, handle
);
832 static struct lttng_transport lttng_relay_transport
= {
833 .name
= "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap",
835 .channel_create
= _channel_create
,
836 .channel_destroy
= lttng_channel_destroy
,
837 .event_reserve
= lttng_event_reserve
,
838 .event_commit
= lttng_event_commit
,
839 .event_write
= lttng_event_write
,
840 .packet_avail_size
= NULL
, /* Would be racy anyway */
841 .is_finalized
= lttng_is_finalized
,
842 .is_disabled
= lttng_is_disabled
,
843 .flush_buffer
= lttng_flush_buffer
,
844 .event_strcpy
= lttng_event_strcpy
,
846 .client_config
= &client_config
,
849 void RING_BUFFER_MODE_TEMPLATE_INIT(void)
851 DBG("LTT : ltt ring buffer client \"%s\" init\n",
852 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
853 lttng_transport_register(<tng_relay_transport
);
856 void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
858 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
859 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
860 lttng_transport_unregister(<tng_relay_transport
);