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.
11 #include <lttng/ust-events.h>
12 #include "ust-bitfield.h"
14 #include "lttng-tracer.h"
15 #include "../libringbuffer/frontend_types.h"
17 #define LTTNG_COMPACT_EVENT_BITS 5
18 #define LTTNG_COMPACT_TSC_BITS 27
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.
32 struct packet_header
{
33 /* Trace packet header */
36 * contains endianness information.
38 uint8_t uuid
[LTTNG_UST_UUID_LEN
];
40 uint64_t stream_instance_id
;
43 /* Stream packet context */
44 uint64_t timestamp_begin
; /* Cycle count at subbuffer start */
45 uint64_t timestamp_end
; /* Cycle count at subbuffer end */
46 uint64_t content_size
; /* Size of data in subbuffer */
47 uint64_t packet_size
; /* Subbuffer size (include padding) */
48 uint64_t packet_seq_num
; /* Packet sequence number */
49 unsigned long events_discarded
; /*
50 * Events lost in this subbuffer since
51 * the beginning of the trace.
54 uint32_t cpu_id
; /* CPU id associated with stream */
55 uint8_t header_end
; /* End of header */
59 struct lttng_client_ctx
{
60 size_t packet_context_len
;
61 size_t event_context_len
;
64 static inline uint64_t lib_ring_buffer_clock_read(struct channel
*chan
)
66 return trace_clock_read64();
70 size_t ctx_get_aligned_size(size_t offset
, struct lttng_ctx
*ctx
,
73 size_t orig_offset
= offset
;
77 offset
+= lib_ring_buffer_align(offset
, ctx
->largest_align
);
79 return offset
- orig_offset
;
83 void ctx_get_struct_size(struct lttng_ctx
*ctx
, size_t *ctx_len
,
84 enum app_ctx_mode mode
)
89 if (caa_likely(!ctx
)) {
93 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
94 if (mode
== APP_CTX_ENABLED
) {
95 offset
+= ctx
->fields
[i
].get_size(&ctx
->fields
[i
], offset
);
97 if (lttng_context_is_app(ctx
->fields
[i
].event_field
.name
)) {
99 * Before UST 2.8, we cannot use the
100 * application context, because we
101 * cannot trust that the handler used
102 * for get_size is the same used for
103 * ctx_record, which would result in
104 * corrupted traces when tracing
105 * concurrently with application context
106 * register/unregister.
108 offset
+= lttng_ust_dummy_get_size(&ctx
->fields
[i
], offset
);
110 offset
+= ctx
->fields
[i
].get_size(&ctx
->fields
[i
], offset
);
118 void ctx_record(struct lttng_ust_lib_ring_buffer_ctx
*bufctx
,
119 struct lttng_channel
*chan
,
120 struct lttng_ctx
*ctx
,
121 enum app_ctx_mode mode
)
125 if (caa_likely(!ctx
))
127 lib_ring_buffer_align_ctx(bufctx
, ctx
->largest_align
);
128 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
129 if (mode
== APP_CTX_ENABLED
) {
130 ctx
->fields
[i
].record(&ctx
->fields
[i
], bufctx
, chan
);
132 if (lttng_context_is_app(ctx
->fields
[i
].event_field
.name
)) {
134 * Before UST 2.8, we cannot use the
135 * application context, because we
136 * cannot trust that the handler used
137 * for get_size is the same used for
138 * ctx_record, which would result in
139 * corrupted traces when tracing
140 * concurrently with application context
141 * register/unregister.
143 lttng_ust_dummy_record(&ctx
->fields
[i
], bufctx
, chan
);
145 ctx
->fields
[i
].record(&ctx
->fields
[i
], bufctx
, chan
);
152 * record_header_size - Calculate the header size and padding necessary.
153 * @config: ring buffer instance configuration
155 * @offset: offset in the write buffer
156 * @pre_header_padding: padding to add before the header (output)
157 * @ctx: reservation context
159 * Returns the event header size (including padding).
161 * The payload must itself determine its own alignment from the biggest type it
165 size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
166 struct channel
*chan
, size_t offset
,
167 size_t *pre_header_padding
,
168 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
169 struct lttng_client_ctx
*client_ctx
)
171 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
172 struct lttng_event
*event
= ctx
->priv
;
173 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
174 size_t orig_offset
= offset
;
177 switch (lttng_chan
->header_type
) {
178 case 1: /* compact */
179 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
181 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
182 offset
+= sizeof(uint32_t); /* id and timestamp */
184 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
185 offset
+= (LTTNG_COMPACT_EVENT_BITS
+ CHAR_BIT
- 1) / CHAR_BIT
;
186 /* Align extended struct on largest member */
187 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
188 offset
+= sizeof(uint32_t); /* id */
189 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
190 offset
+= sizeof(uint64_t); /* timestamp */
194 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
196 offset
+= sizeof(uint16_t);
197 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
198 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
199 offset
+= sizeof(uint32_t); /* timestamp */
201 /* Align extended struct on largest member */
202 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
203 offset
+= sizeof(uint32_t); /* id */
204 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
205 offset
+= sizeof(uint64_t); /* timestamp */
213 /* 2.8+ probe ABI. */
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
);
219 /* Pre 2.8 probe ABI. */
220 offset
+= ctx_get_aligned_size(offset
, lttng_chan
->ctx
,
221 client_ctx
->packet_context_len
);
222 offset
+= ctx_get_aligned_size(offset
, event
->ctx
,
223 client_ctx
->event_context_len
);
225 *pre_header_padding
= padding
;
226 return offset
- orig_offset
;
229 #include "../libringbuffer/api.h"
230 #include "lttng-rb-clients.h"
233 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
234 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
238 * lttng_write_event_header
240 * Writes the event header to the offset (already aligned on 32-bits).
242 * @config: ring buffer instance configuration
243 * @ctx: reservation context
244 * @event_id: event ID
247 void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config
*config
,
248 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
251 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
252 struct lttng_event
*event
= ctx
->priv
;
253 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
255 if (caa_unlikely(ctx
->rflags
))
258 switch (lttng_chan
->header_type
) {
259 case 1: /* compact */
261 uint32_t id_time
= 0;
263 bt_bitfield_write(&id_time
, uint32_t,
265 LTTNG_COMPACT_EVENT_BITS
,
267 bt_bitfield_write(&id_time
, uint32_t,
268 LTTNG_COMPACT_EVENT_BITS
,
269 LTTNG_COMPACT_TSC_BITS
,
271 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
276 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
277 uint16_t id
= event_id
;
279 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
280 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
281 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
289 /* 2.8+ probe ABI. */
290 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
291 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
293 /* Pre 2.8 probe ABI. */
294 ctx_record(ctx
, lttng_chan
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
295 ctx_record(ctx
, lttng_chan
, event
->ctx
, APP_CTX_DISABLED
);
297 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
302 lttng_write_event_header_slow(config
, ctx
, event_id
);
306 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
307 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
310 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
311 struct lttng_event
*event
= ctx
->priv
;
312 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
314 switch (lttng_chan
->header_type
) {
315 case 1: /* compact */
316 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
317 uint32_t id_time
= 0;
319 bt_bitfield_write(&id_time
, uint32_t,
321 LTTNG_COMPACT_EVENT_BITS
,
323 bt_bitfield_write(&id_time
, uint32_t,
324 LTTNG_COMPACT_EVENT_BITS
,
325 LTTNG_COMPACT_TSC_BITS
,
327 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
330 uint64_t timestamp
= ctx
->tsc
;
332 bt_bitfield_write(&id
, uint8_t,
334 LTTNG_COMPACT_EVENT_BITS
,
336 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
337 /* Align extended struct on largest member */
338 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
339 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
340 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
341 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
346 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
347 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
348 uint16_t id
= event_id
;
350 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
351 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
352 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
355 uint64_t timestamp
= ctx
->tsc
;
357 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
358 /* Align extended struct on largest member */
359 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
360 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
361 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
362 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
370 /* 2.8+ probe ABI. */
371 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
372 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
374 /* Pre 2.8 probe ABI. */
375 ctx_record(ctx
, lttng_chan
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
376 ctx_record(ctx
, lttng_chan
, event
->ctx
, APP_CTX_DISABLED
);
378 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
381 static const struct lttng_ust_lib_ring_buffer_config client_config
;
383 static uint64_t client_ring_buffer_clock_read(struct channel
*chan
)
385 return lib_ring_buffer_clock_read(chan
);
389 size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
390 struct channel
*chan
, size_t offset
,
391 size_t *pre_header_padding
,
392 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
395 return record_header_size(config
, chan
, offset
,
396 pre_header_padding
, ctx
, client_ctx
);
400 * client_packet_header_size - called on buffer-switch to a new sub-buffer
402 * Return header size without padding after the structure. Don't use packed
403 * structure because gcc generates inefficient code on some architectures
406 static size_t client_packet_header_size(void)
408 return offsetof(struct packet_header
, ctx
.header_end
);
411 static void client_buffer_begin(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
412 unsigned int subbuf_idx
,
413 struct lttng_ust_shm_handle
*handle
)
415 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
416 struct packet_header
*header
=
417 (struct packet_header
*)
418 lib_ring_buffer_offset_address(&buf
->backend
,
419 subbuf_idx
* chan
->backend
.subbuf_size
,
421 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
422 uint64_t cnt
= shmp_index(handle
, buf
->backend
.buf_cnt
, subbuf_idx
)->seq_cnt
;
427 header
->magic
= CTF_MAGIC_NUMBER
;
428 memcpy(header
->uuid
, lttng_chan
->uuid
, sizeof(lttng_chan
->uuid
));
429 header
->stream_id
= lttng_chan
->id
;
430 header
->stream_instance_id
= buf
->backend
.cpu
;
431 header
->ctx
.timestamp_begin
= tsc
;
432 header
->ctx
.timestamp_end
= 0;
433 header
->ctx
.content_size
= ~0ULL; /* for debugging */
434 header
->ctx
.packet_size
= ~0ULL;
435 header
->ctx
.packet_seq_num
= chan
->backend
.num_subbuf
* cnt
+ subbuf_idx
;
436 header
->ctx
.events_discarded
= 0;
437 header
->ctx
.cpu_id
= buf
->backend
.cpu
;
441 * offset is assumed to never be 0 here : never deliver a completely empty
442 * subbuffer. data_size is between 1 and subbuf_size.
444 static void client_buffer_end(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
445 unsigned int subbuf_idx
, unsigned long data_size
,
446 struct lttng_ust_shm_handle
*handle
)
448 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
449 struct packet_header
*header
=
450 (struct packet_header
*)
451 lib_ring_buffer_offset_address(&buf
->backend
,
452 subbuf_idx
* chan
->backend
.subbuf_size
,
454 unsigned long records_lost
= 0;
459 header
->ctx
.timestamp_end
= tsc
;
460 header
->ctx
.content_size
=
461 (uint64_t) data_size
* CHAR_BIT
; /* in bits */
462 header
->ctx
.packet_size
=
463 (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size
) * CHAR_BIT
; /* in bits */
465 records_lost
+= lib_ring_buffer_get_records_lost_full(&client_config
, buf
);
466 records_lost
+= lib_ring_buffer_get_records_lost_wrap(&client_config
, buf
);
467 records_lost
+= lib_ring_buffer_get_records_lost_big(&client_config
, buf
);
468 header
->ctx
.events_discarded
= records_lost
;
471 static int client_buffer_create(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
,
472 int cpu
, const char *name
, struct lttng_ust_shm_handle
*handle
)
477 static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
, int cpu
, struct lttng_ust_shm_handle
*handle
)
481 static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
482 size_t *offset
, size_t *length
)
484 *offset
= offsetof(struct packet_header
, ctx
.content_size
);
485 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.content_size
);
488 static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
489 size_t *offset
, size_t *length
)
491 *offset
= offsetof(struct packet_header
, ctx
.packet_size
);
492 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.packet_size
);
495 static struct packet_header
*client_packet_header(struct lttng_ust_lib_ring_buffer
*buf
,
496 struct lttng_ust_shm_handle
*handle
)
498 return lib_ring_buffer_read_offset_address(&buf
->backend
, 0, handle
);
501 static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer
*buf
,
502 struct lttng_ust_shm_handle
*handle
,
503 uint64_t *timestamp_begin
)
505 struct packet_header
*header
;
507 header
= client_packet_header(buf
, handle
);
510 *timestamp_begin
= header
->ctx
.timestamp_begin
;
514 static int client_timestamp_end(struct lttng_ust_lib_ring_buffer
*buf
,
515 struct lttng_ust_shm_handle
*handle
,
516 uint64_t *timestamp_end
)
518 struct packet_header
*header
;
520 header
= client_packet_header(buf
, handle
);
523 *timestamp_end
= header
->ctx
.timestamp_end
;
527 static int client_events_discarded(struct lttng_ust_lib_ring_buffer
*buf
,
528 struct lttng_ust_shm_handle
*handle
,
529 uint64_t *events_discarded
)
531 struct packet_header
*header
;
533 header
= client_packet_header(buf
, handle
);
536 *events_discarded
= header
->ctx
.events_discarded
;
540 static int client_content_size(struct lttng_ust_lib_ring_buffer
*buf
,
541 struct lttng_ust_shm_handle
*handle
,
542 uint64_t *content_size
)
544 struct packet_header
*header
;
546 header
= client_packet_header(buf
, handle
);
549 *content_size
= header
->ctx
.content_size
;
553 static int client_packet_size(struct lttng_ust_lib_ring_buffer
*buf
,
554 struct lttng_ust_shm_handle
*handle
,
555 uint64_t *packet_size
)
557 struct packet_header
*header
;
559 header
= client_packet_header(buf
, handle
);
562 *packet_size
= header
->ctx
.packet_size
;
566 static int client_stream_id(struct lttng_ust_lib_ring_buffer
*buf
,
567 struct lttng_ust_shm_handle
*handle
,
570 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
571 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
573 *stream_id
= lttng_chan
->id
;
578 static int client_current_timestamp(struct lttng_ust_lib_ring_buffer
*buf
,
579 struct lttng_ust_shm_handle
*handle
,
582 struct channel
*chan
;
584 chan
= shmp(handle
, handle
->chan
);
585 *ts
= client_ring_buffer_clock_read(chan
);
590 static int client_sequence_number(struct lttng_ust_lib_ring_buffer
*buf
,
591 struct lttng_ust_shm_handle
*handle
,
594 struct packet_header
*header
;
596 header
= client_packet_header(buf
, handle
);
599 *seq
= header
->ctx
.packet_seq_num
;
603 static int client_instance_id(struct lttng_ust_lib_ring_buffer
*buf
,
604 struct lttng_ust_shm_handle
*handle
,
607 *id
= buf
->backend
.cpu
;
613 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb
= {
615 .ring_buffer_clock_read
= client_ring_buffer_clock_read
,
616 .record_header_size
= client_record_header_size
,
617 .subbuffer_header_size
= client_packet_header_size
,
618 .buffer_begin
= client_buffer_begin
,
619 .buffer_end
= client_buffer_end
,
620 .buffer_create
= client_buffer_create
,
621 .buffer_finalize
= client_buffer_finalize
,
622 .content_size_field
= client_content_size_field
,
623 .packet_size_field
= client_packet_size_field
,
625 .timestamp_begin
= client_timestamp_begin
,
626 .timestamp_end
= client_timestamp_end
,
627 .events_discarded
= client_events_discarded
,
628 .content_size
= client_content_size
,
629 .packet_size
= client_packet_size
,
630 .stream_id
= client_stream_id
,
631 .current_timestamp
= client_current_timestamp
,
632 .sequence_number
= client_sequence_number
,
633 .instance_id
= client_instance_id
,
636 static const struct lttng_ust_lib_ring_buffer_config client_config
= {
637 .cb
.ring_buffer_clock_read
= client_ring_buffer_clock_read
,
638 .cb
.record_header_size
= client_record_header_size
,
639 .cb
.subbuffer_header_size
= client_packet_header_size
,
640 .cb
.buffer_begin
= client_buffer_begin
,
641 .cb
.buffer_end
= client_buffer_end
,
642 .cb
.buffer_create
= client_buffer_create
,
643 .cb
.buffer_finalize
= client_buffer_finalize
,
644 .cb
.content_size_field
= client_content_size_field
,
645 .cb
.packet_size_field
= client_packet_size_field
,
647 .tsc_bits
= LTTNG_COMPACT_TSC_BITS
,
648 .alloc
= RING_BUFFER_ALLOC_PER_CPU
,
649 .sync
= RING_BUFFER_SYNC_GLOBAL
,
650 .mode
= RING_BUFFER_MODE_TEMPLATE
,
651 .backend
= RING_BUFFER_PAGE
,
652 .output
= RING_BUFFER_MMAP
,
653 .oops
= RING_BUFFER_OOPS_CONSISTENCY
,
654 .ipi
= RING_BUFFER_NO_IPI_BARRIER
,
655 .wakeup
= LTTNG_CLIENT_WAKEUP
,
656 .client_type
= LTTNG_CLIENT_TYPE
,
658 .cb_ptr
= &client_cb
.parent
,
661 const struct lttng_ust_client_lib_ring_buffer_client_cb
*LTTNG_CLIENT_CALLBACKS
= &client_cb
;
664 struct lttng_channel
*_channel_create(const char *name
,
666 size_t subbuf_size
, size_t num_subbuf
,
667 unsigned int switch_timer_interval
,
668 unsigned int read_timer_interval
,
671 const int *stream_fds
, int nr_stream_fds
,
672 int64_t blocking_timeout
)
674 struct lttng_channel chan_priv_init
;
675 struct lttng_ust_shm_handle
*handle
;
676 struct lttng_channel
*lttng_chan
;
679 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
680 memcpy(chan_priv_init
.uuid
, uuid
, LTTNG_UST_UUID_LEN
);
681 chan_priv_init
.id
= chan_id
;
682 handle
= channel_create(&client_config
, name
,
683 &priv
, __alignof__(struct lttng_channel
),
684 sizeof(struct lttng_channel
),
686 buf_addr
, subbuf_size
, num_subbuf
,
687 switch_timer_interval
, read_timer_interval
,
688 stream_fds
, nr_stream_fds
, blocking_timeout
);
692 lttng_chan
->handle
= handle
;
693 lttng_chan
->chan
= shmp(handle
, handle
->chan
);
698 void lttng_channel_destroy(struct lttng_channel
*chan
)
700 channel_destroy(chan
->chan
, chan
->handle
, 1);
704 int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
707 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
708 struct lttng_event
*event
= ctx
->priv
;
709 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
710 struct lttng_client_ctx client_ctx
;
713 /* Compute internal size of context structures. */
716 /* 2.8+ probe ABI. */
717 ctx_get_struct_size(lttng_ctx
->chan_ctx
, &client_ctx
.packet_context_len
,
719 ctx_get_struct_size(lttng_ctx
->event_ctx
, &client_ctx
.event_context_len
,
722 /* Pre 2.8 probe ABI. */
723 ctx_get_struct_size(lttng_chan
->ctx
, &client_ctx
.packet_context_len
,
725 ctx_get_struct_size(event
->ctx
, &client_ctx
.event_context_len
,
729 cpu
= lib_ring_buffer_get_cpu(&client_config
);
734 switch (lttng_chan
->header_type
) {
735 case 1: /* compact */
737 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
740 if (event_id
> 65534)
741 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
747 ret
= lib_ring_buffer_reserve(&client_config
, ctx
, &client_ctx
);
748 if (caa_unlikely(ret
))
750 if (caa_likely(ctx
->ctx_len
751 >= sizeof(struct lttng_ust_lib_ring_buffer_ctx
))) {
752 if (lib_ring_buffer_backend_get_pages(&client_config
, ctx
,
753 &ctx
->backend_pages
)) {
758 lttng_write_event_header(&client_config
, ctx
, event_id
);
761 lib_ring_buffer_put_cpu(&client_config
);
766 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
768 lib_ring_buffer_commit(&client_config
, ctx
);
769 lib_ring_buffer_put_cpu(&client_config
);
773 void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
776 lib_ring_buffer_write(&client_config
, ctx
, src
, len
);
780 void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const char *src
,
783 lib_ring_buffer_strcpy(&client_config
, ctx
, src
, len
, '#');
788 wait_queue_head_t
*lttng_get_reader_wait_queue(struct channel
*chan
)
790 return &chan
->read_wait
;
794 wait_queue_head_t
*lttng_get_hp_wait_queue(struct channel
*chan
)
796 return &chan
->hp_wait
;
801 int lttng_is_finalized(struct channel
*chan
)
803 return lib_ring_buffer_channel_is_finalized(chan
);
807 int lttng_is_disabled(struct channel
*chan
)
809 return lib_ring_buffer_channel_is_disabled(chan
);
813 int lttng_flush_buffer(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
)
815 struct lttng_ust_lib_ring_buffer
*buf
;
818 for_each_channel_cpu(cpu
, chan
) {
819 int shm_fd
, wait_fd
, wakeup_fd
;
820 uint64_t memory_map_size
;
822 buf
= channel_get_ring_buffer(&client_config
, chan
,
823 cpu
, handle
, &shm_fd
, &wait_fd
,
824 &wakeup_fd
, &memory_map_size
);
825 lib_ring_buffer_switch(&client_config
, buf
,
826 SWITCH_ACTIVE
, handle
);
831 static struct lttng_transport lttng_relay_transport
= {
832 .name
= "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap",
834 .channel_create
= _channel_create
,
835 .channel_destroy
= lttng_channel_destroy
,
836 .event_reserve
= lttng_event_reserve
,
837 .event_commit
= lttng_event_commit
,
838 .event_write
= lttng_event_write
,
839 .packet_avail_size
= NULL
, /* Would be racy anyway */
840 .is_finalized
= lttng_is_finalized
,
841 .is_disabled
= lttng_is_disabled
,
842 .flush_buffer
= lttng_flush_buffer
,
843 .event_strcpy
= lttng_event_strcpy
,
845 .client_config
= &client_config
,
848 void RING_BUFFER_MODE_TEMPLATE_INIT(void)
850 DBG("LTT : ltt ring buffer client \"%s\" init\n",
851 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
852 lttng_transport_register(<tng_relay_transport
);
855 void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
857 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
858 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
859 lttng_transport_unregister(<tng_relay_transport
);