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 lttng_ust_lib_ring_buffer_channel
*chan
)
69 return trace_clock_read64();
73 size_t ctx_get_aligned_size(size_t offset
, struct lttng_ust_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_ust_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_ust_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 lttng_ust_lib_ring_buffer_channel
*chan
,
171 size_t *pre_header_padding
,
172 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
173 struct lttng_client_ctx
*client_ctx
)
175 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
176 struct lttng_ust_stack_ctx
*lttng_ctx
= ctx
->priv
;
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 */
215 offset
+= ctx_get_aligned_size(offset
, lttng_ctx
->chan_ctx
,
216 client_ctx
->packet_context_len
);
217 offset
+= ctx_get_aligned_size(offset
, lttng_ctx
->event_ctx
,
218 client_ctx
->event_context_len
);
219 *pre_header_padding
= padding
;
220 return offset
- orig_offset
;
223 #include "../libringbuffer/api.h"
224 #include "lttng-rb-clients.h"
227 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
228 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
232 * lttng_write_event_header
234 * Writes the event header to the offset (already aligned on 32-bits).
236 * @config: ring buffer instance configuration
237 * @ctx: reservation context
238 * @event_id: event ID
241 void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config
*config
,
242 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
245 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
246 struct lttng_ust_stack_ctx
*lttng_ctx
= ctx
->priv
;
248 if (caa_unlikely(ctx
->rflags
))
251 switch (lttng_chan
->header_type
) {
252 case 1: /* compact */
254 uint32_t id_time
= 0;
256 bt_bitfield_write(&id_time
, uint32_t,
258 LTTNG_COMPACT_EVENT_BITS
,
260 bt_bitfield_write(&id_time
, uint32_t,
261 LTTNG_COMPACT_EVENT_BITS
,
262 LTTNG_COMPACT_TSC_BITS
,
264 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
269 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
270 uint16_t id
= event_id
;
272 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
273 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
274 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
281 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
282 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
283 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
288 lttng_write_event_header_slow(config
, ctx
, event_id
);
292 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
293 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
296 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
297 struct lttng_ust_stack_ctx
*lttng_ctx
= ctx
->priv
;
299 switch (lttng_chan
->header_type
) {
300 case 1: /* compact */
301 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
302 uint32_t id_time
= 0;
304 bt_bitfield_write(&id_time
, uint32_t,
306 LTTNG_COMPACT_EVENT_BITS
,
308 bt_bitfield_write(&id_time
, uint32_t,
309 LTTNG_COMPACT_EVENT_BITS
,
310 LTTNG_COMPACT_TSC_BITS
,
312 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
315 uint64_t timestamp
= ctx
->tsc
;
317 bt_bitfield_write(&id
, uint8_t,
319 LTTNG_COMPACT_EVENT_BITS
,
321 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
322 /* Align extended struct on largest member */
323 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
324 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
325 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
326 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
331 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
332 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
333 uint16_t id
= event_id
;
335 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
336 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
337 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
340 uint64_t timestamp
= ctx
->tsc
;
342 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
343 /* Align extended struct on largest member */
344 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
345 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
346 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
347 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
354 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
355 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
356 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
359 static const struct lttng_ust_lib_ring_buffer_config client_config
;
361 static uint64_t client_ring_buffer_clock_read(struct lttng_ust_lib_ring_buffer_channel
*chan
)
363 return lib_ring_buffer_clock_read(chan
);
367 size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
368 struct lttng_ust_lib_ring_buffer_channel
*chan
,
370 size_t *pre_header_padding
,
371 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
374 return record_header_size(config
, chan
, offset
,
375 pre_header_padding
, ctx
, client_ctx
);
379 * client_packet_header_size - called on buffer-switch to a new sub-buffer
381 * Return header size without padding after the structure. Don't use packed
382 * structure because gcc generates inefficient code on some architectures
385 static size_t client_packet_header_size(void)
387 return offsetof(struct packet_header
, ctx
.header_end
);
390 static void client_buffer_begin(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
391 unsigned int subbuf_idx
,
392 struct lttng_ust_shm_handle
*handle
)
394 struct lttng_ust_lib_ring_buffer_channel
*chan
= shmp(handle
, buf
->backend
.chan
);
395 struct packet_header
*header
=
396 (struct packet_header
*)
397 lib_ring_buffer_offset_address(&buf
->backend
,
398 subbuf_idx
* chan
->backend
.subbuf_size
,
400 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
401 uint64_t cnt
= shmp_index(handle
, buf
->backend
.buf_cnt
, subbuf_idx
)->seq_cnt
;
406 header
->magic
= CTF_MAGIC_NUMBER
;
407 memcpy(header
->uuid
, lttng_chan
->uuid
, sizeof(lttng_chan
->uuid
));
408 header
->stream_id
= lttng_chan
->id
;
409 header
->stream_instance_id
= buf
->backend
.cpu
;
410 header
->ctx
.timestamp_begin
= tsc
;
411 header
->ctx
.timestamp_end
= 0;
412 header
->ctx
.content_size
= ~0ULL; /* for debugging */
413 header
->ctx
.packet_size
= ~0ULL;
414 header
->ctx
.packet_seq_num
= chan
->backend
.num_subbuf
* cnt
+ subbuf_idx
;
415 header
->ctx
.events_discarded
= 0;
416 header
->ctx
.cpu_id
= buf
->backend
.cpu
;
420 * offset is assumed to never be 0 here : never deliver a completely empty
421 * subbuffer. data_size is between 1 and subbuf_size.
423 static void client_buffer_end(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
424 unsigned int subbuf_idx
, unsigned long data_size
,
425 struct lttng_ust_shm_handle
*handle
)
427 struct lttng_ust_lib_ring_buffer_channel
*chan
= shmp(handle
, buf
->backend
.chan
);
428 struct packet_header
*header
=
429 (struct packet_header
*)
430 lib_ring_buffer_offset_address(&buf
->backend
,
431 subbuf_idx
* chan
->backend
.subbuf_size
,
433 unsigned long records_lost
= 0;
438 header
->ctx
.timestamp_end
= tsc
;
439 header
->ctx
.content_size
=
440 (uint64_t) data_size
* CHAR_BIT
; /* in bits */
441 header
->ctx
.packet_size
=
442 (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size
) * CHAR_BIT
; /* in bits */
444 records_lost
+= lib_ring_buffer_get_records_lost_full(&client_config
, buf
);
445 records_lost
+= lib_ring_buffer_get_records_lost_wrap(&client_config
, buf
);
446 records_lost
+= lib_ring_buffer_get_records_lost_big(&client_config
, buf
);
447 header
->ctx
.events_discarded
= records_lost
;
450 static int client_buffer_create(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
,
451 int cpu
, const char *name
, struct lttng_ust_shm_handle
*handle
)
456 static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
, int cpu
, struct lttng_ust_shm_handle
*handle
)
460 static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
461 size_t *offset
, size_t *length
)
463 *offset
= offsetof(struct packet_header
, ctx
.content_size
);
464 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.content_size
);
467 static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
468 size_t *offset
, size_t *length
)
470 *offset
= offsetof(struct packet_header
, ctx
.packet_size
);
471 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.packet_size
);
474 static struct packet_header
*client_packet_header(struct lttng_ust_lib_ring_buffer
*buf
,
475 struct lttng_ust_shm_handle
*handle
)
477 return lib_ring_buffer_read_offset_address(&buf
->backend
, 0, handle
);
480 static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer
*buf
,
481 struct lttng_ust_shm_handle
*handle
,
482 uint64_t *timestamp_begin
)
484 struct packet_header
*header
;
486 header
= client_packet_header(buf
, handle
);
489 *timestamp_begin
= header
->ctx
.timestamp_begin
;
493 static int client_timestamp_end(struct lttng_ust_lib_ring_buffer
*buf
,
494 struct lttng_ust_shm_handle
*handle
,
495 uint64_t *timestamp_end
)
497 struct packet_header
*header
;
499 header
= client_packet_header(buf
, handle
);
502 *timestamp_end
= header
->ctx
.timestamp_end
;
506 static int client_events_discarded(struct lttng_ust_lib_ring_buffer
*buf
,
507 struct lttng_ust_shm_handle
*handle
,
508 uint64_t *events_discarded
)
510 struct packet_header
*header
;
512 header
= client_packet_header(buf
, handle
);
515 *events_discarded
= header
->ctx
.events_discarded
;
519 static int client_content_size(struct lttng_ust_lib_ring_buffer
*buf
,
520 struct lttng_ust_shm_handle
*handle
,
521 uint64_t *content_size
)
523 struct packet_header
*header
;
525 header
= client_packet_header(buf
, handle
);
528 *content_size
= header
->ctx
.content_size
;
532 static int client_packet_size(struct lttng_ust_lib_ring_buffer
*buf
,
533 struct lttng_ust_shm_handle
*handle
,
534 uint64_t *packet_size
)
536 struct packet_header
*header
;
538 header
= client_packet_header(buf
, handle
);
541 *packet_size
= header
->ctx
.packet_size
;
545 static int client_stream_id(struct lttng_ust_lib_ring_buffer
*buf
,
546 struct lttng_ust_shm_handle
*handle
,
549 struct lttng_ust_lib_ring_buffer_channel
*chan
= shmp(handle
,
551 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
553 *stream_id
= lttng_chan
->id
;
558 static int client_current_timestamp(struct lttng_ust_lib_ring_buffer
*buf
,
559 struct lttng_ust_shm_handle
*handle
,
562 struct lttng_ust_lib_ring_buffer_channel
*chan
;
564 chan
= shmp(handle
, handle
->chan
);
565 *ts
= client_ring_buffer_clock_read(chan
);
570 static int client_sequence_number(struct lttng_ust_lib_ring_buffer
*buf
,
571 struct lttng_ust_shm_handle
*handle
,
574 struct packet_header
*header
;
576 header
= client_packet_header(buf
, handle
);
579 *seq
= header
->ctx
.packet_seq_num
;
583 static int client_instance_id(struct lttng_ust_lib_ring_buffer
*buf
,
584 struct lttng_ust_shm_handle
*handle
,
587 *id
= buf
->backend
.cpu
;
593 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb
= {
595 .ring_buffer_clock_read
= client_ring_buffer_clock_read
,
596 .record_header_size
= client_record_header_size
,
597 .subbuffer_header_size
= client_packet_header_size
,
598 .buffer_begin
= client_buffer_begin
,
599 .buffer_end
= client_buffer_end
,
600 .buffer_create
= client_buffer_create
,
601 .buffer_finalize
= client_buffer_finalize
,
602 .content_size_field
= client_content_size_field
,
603 .packet_size_field
= client_packet_size_field
,
605 .timestamp_begin
= client_timestamp_begin
,
606 .timestamp_end
= client_timestamp_end
,
607 .events_discarded
= client_events_discarded
,
608 .content_size
= client_content_size
,
609 .packet_size
= client_packet_size
,
610 .stream_id
= client_stream_id
,
611 .current_timestamp
= client_current_timestamp
,
612 .sequence_number
= client_sequence_number
,
613 .instance_id
= client_instance_id
,
616 static const struct lttng_ust_lib_ring_buffer_config client_config
= {
617 .cb
.ring_buffer_clock_read
= client_ring_buffer_clock_read
,
618 .cb
.record_header_size
= client_record_header_size
,
619 .cb
.subbuffer_header_size
= client_packet_header_size
,
620 .cb
.buffer_begin
= client_buffer_begin
,
621 .cb
.buffer_end
= client_buffer_end
,
622 .cb
.buffer_create
= client_buffer_create
,
623 .cb
.buffer_finalize
= client_buffer_finalize
,
624 .cb
.content_size_field
= client_content_size_field
,
625 .cb
.packet_size_field
= client_packet_size_field
,
627 .tsc_bits
= LTTNG_COMPACT_TSC_BITS
,
628 .alloc
= RING_BUFFER_ALLOC_PER_CPU
,
629 .sync
= RING_BUFFER_SYNC_GLOBAL
,
630 .mode
= RING_BUFFER_MODE_TEMPLATE
,
631 .backend
= RING_BUFFER_PAGE
,
632 .output
= RING_BUFFER_MMAP
,
633 .oops
= RING_BUFFER_OOPS_CONSISTENCY
,
634 .ipi
= RING_BUFFER_NO_IPI_BARRIER
,
635 .wakeup
= LTTNG_CLIENT_WAKEUP
,
636 .client_type
= LTTNG_CLIENT_TYPE
,
638 .cb_ptr
= &client_cb
.parent
,
642 struct lttng_channel
*_channel_create(const char *name
,
644 size_t subbuf_size
, size_t num_subbuf
,
645 unsigned int switch_timer_interval
,
646 unsigned int read_timer_interval
,
649 const int *stream_fds
, int nr_stream_fds
,
650 int64_t blocking_timeout
)
652 struct lttng_channel chan_priv_init
;
653 struct lttng_ust_shm_handle
*handle
;
654 struct lttng_channel
*lttng_chan
;
657 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
658 memcpy(chan_priv_init
.uuid
, uuid
, LTTNG_UST_UUID_LEN
);
659 chan_priv_init
.id
= chan_id
;
660 handle
= channel_create(&client_config
, name
,
661 &priv
, __alignof__(struct lttng_channel
),
662 sizeof(struct lttng_channel
),
664 buf_addr
, subbuf_size
, num_subbuf
,
665 switch_timer_interval
, read_timer_interval
,
666 stream_fds
, nr_stream_fds
, blocking_timeout
);
670 lttng_chan
->handle
= handle
;
671 lttng_chan
->chan
= shmp(handle
, handle
->chan
);
676 void lttng_channel_destroy(struct lttng_channel
*chan
)
678 channel_destroy(chan
->chan
, chan
->handle
, 1);
682 int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
685 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
686 struct lttng_ust_stack_ctx
*lttng_ctx
= ctx
->priv
;
687 struct lttng_client_ctx client_ctx
;
690 /* Compute internal size of context structures. */
691 ctx_get_struct_size(lttng_ctx
->chan_ctx
, &client_ctx
.packet_context_len
,
693 ctx_get_struct_size(lttng_ctx
->event_ctx
, &client_ctx
.event_context_len
,
696 cpu
= lib_ring_buffer_get_cpu(&client_config
);
701 switch (lttng_chan
->header_type
) {
702 case 1: /* compact */
704 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
707 if (event_id
> 65534)
708 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
714 ret
= lib_ring_buffer_reserve(&client_config
, ctx
, &client_ctx
);
715 if (caa_unlikely(ret
))
717 if (lib_ring_buffer_backend_get_pages(&client_config
, ctx
,
718 &ctx
->backend_pages
)) {
722 lttng_write_event_header(&client_config
, ctx
, event_id
);
725 lib_ring_buffer_put_cpu(&client_config
);
730 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
732 lib_ring_buffer_commit(&client_config
, ctx
);
733 lib_ring_buffer_put_cpu(&client_config
);
737 void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
740 lib_ring_buffer_write(&client_config
, ctx
, src
, len
);
744 void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const char *src
,
747 lib_ring_buffer_strcpy(&client_config
, ctx
, src
, len
, '#');
752 wait_queue_head_t
*lttng_get_reader_wait_queue(struct lttng_ust_lib_ring_buffer_channel
*chan
)
754 return &chan
->read_wait
;
758 wait_queue_head_t
*lttng_get_hp_wait_queue(struct lttng_ust_lib_ring_buffer_channel
*chan
)
760 return &chan
->hp_wait
;
765 int lttng_is_finalized(struct lttng_ust_lib_ring_buffer_channel
*chan
)
767 return lib_ring_buffer_channel_is_finalized(chan
);
771 int lttng_is_disabled(struct lttng_ust_lib_ring_buffer_channel
*chan
)
773 return lib_ring_buffer_channel_is_disabled(chan
);
777 int lttng_flush_buffer(struct lttng_ust_lib_ring_buffer_channel
*chan
,
778 struct lttng_ust_shm_handle
*handle
)
780 struct lttng_ust_lib_ring_buffer
*buf
;
783 for_each_channel_cpu(cpu
, chan
) {
784 int shm_fd
, wait_fd
, wakeup_fd
;
785 uint64_t memory_map_size
;
787 buf
= channel_get_ring_buffer(&client_config
, chan
,
788 cpu
, handle
, &shm_fd
, &wait_fd
,
789 &wakeup_fd
, &memory_map_size
);
790 lib_ring_buffer_switch(&client_config
, buf
,
791 SWITCH_ACTIVE
, handle
);
796 static struct lttng_transport lttng_relay_transport
= {
797 .name
= "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap",
799 .struct_size
= sizeof(struct lttng_ust_channel_ops
),
800 .channel_create
= _channel_create
,
801 .channel_destroy
= lttng_channel_destroy
,
802 .event_reserve
= lttng_event_reserve
,
803 .event_commit
= lttng_event_commit
,
804 .event_write
= lttng_event_write
,
805 .packet_avail_size
= NULL
, /* Would be racy anyway */
806 .is_finalized
= lttng_is_finalized
,
807 .is_disabled
= lttng_is_disabled
,
808 .flush_buffer
= lttng_flush_buffer
,
809 .event_strcpy
= lttng_event_strcpy
,
811 .client_config
= &client_config
,
814 void RING_BUFFER_MODE_TEMPLATE_INIT(void)
816 DBG("LTT : ltt ring buffer client \"%s\" init\n",
817 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
818 lttng_transport_register(<tng_relay_transport
);
821 void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
823 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
824 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
825 lttng_transport_unregister(<tng_relay_transport
);