2 * lttng-ring-buffer-client.h
4 * LTTng lib ring buffer client template.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <lttng/ust-events.h>
25 #include "lttng/bitfield.h"
27 #include "lttng-tracer.h"
28 #include "../libringbuffer/frontend_types.h"
30 #define LTTNG_COMPACT_EVENT_BITS 5
31 #define LTTNG_COMPACT_TSC_BITS 27
39 * Keep the natural field alignment for _each field_ within this structure if
40 * you ever add/remove a field from this header. Packed attribute is not used
41 * because gcc generates poor code on at least powerpc and mips. Don't ever
42 * let gcc add padding between the structure elements.
45 struct packet_header
{
46 /* Trace packet header */
49 * contains endianness information.
51 uint8_t uuid
[LTTNG_UST_UUID_LEN
];
53 uint64_t stream_instance_id
;
56 /* Stream packet context */
57 uint64_t timestamp_begin
; /* Cycle count at subbuffer start */
58 uint64_t timestamp_end
; /* Cycle count at subbuffer end */
59 uint64_t content_size
; /* Size of data in subbuffer */
60 uint64_t packet_size
; /* Subbuffer size (include padding) */
61 uint64_t packet_seq_num
; /* Packet sequence number */
62 unsigned long events_discarded
; /*
63 * Events lost in this subbuffer since
64 * the beginning of the trace.
67 uint32_t cpu_id
; /* CPU id associated with stream */
68 uint8_t header_end
; /* End of header */
73 static inline uint64_t lib_ring_buffer_clock_read(struct channel
*chan
)
75 return trace_clock_read64();
79 size_t ctx_get_size(size_t offset
, struct lttng_ctx
*ctx
,
80 enum app_ctx_mode mode
)
83 size_t orig_offset
= offset
;
87 offset
+= lib_ring_buffer_align(offset
, ctx
->largest_align
);
88 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
89 if (mode
== APP_CTX_ENABLED
) {
90 offset
+= ctx
->fields
[i
].get_size(&ctx
->fields
[i
], offset
);
92 if (lttng_context_is_app(ctx
->fields
[i
].event_field
.name
)) {
94 * Before UST 2.8, we cannot use the
95 * application context, because we
96 * cannot trust that the handler used
97 * for get_size is the same used for
98 * ctx_record, which would result in
99 * corrupted traces when tracing
100 * concurrently with application context
101 * register/unregister.
103 offset
+= lttng_ust_dummy_get_size(&ctx
->fields
[i
], offset
);
105 offset
+= ctx
->fields
[i
].get_size(&ctx
->fields
[i
], offset
);
109 return offset
- orig_offset
;
113 void ctx_record(struct lttng_ust_lib_ring_buffer_ctx
*bufctx
,
114 struct lttng_channel
*chan
,
115 struct lttng_ctx
*ctx
,
116 enum app_ctx_mode mode
)
120 if (caa_likely(!ctx
))
122 lib_ring_buffer_align_ctx(bufctx
, ctx
->largest_align
);
123 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
124 if (mode
== APP_CTX_ENABLED
) {
125 ctx
->fields
[i
].record(&ctx
->fields
[i
], bufctx
, chan
);
127 if (lttng_context_is_app(ctx
->fields
[i
].event_field
.name
)) {
129 * Before UST 2.8, we cannot use the
130 * application context, because we
131 * cannot trust that the handler used
132 * for get_size is the same used for
133 * ctx_record, which would result in
134 * corrupted traces when tracing
135 * concurrently with application context
136 * register/unregister.
138 lttng_ust_dummy_record(&ctx
->fields
[i
], bufctx
, chan
);
140 ctx
->fields
[i
].record(&ctx
->fields
[i
], bufctx
, chan
);
147 * record_header_size - Calculate the header size and padding necessary.
148 * @config: ring buffer instance configuration
150 * @offset: offset in the write buffer
151 * @pre_header_padding: padding to add before the header (output)
152 * @ctx: reservation context
154 * Returns the event header size (including padding).
156 * The payload must itself determine its own alignment from the biggest type it
160 size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
161 struct channel
*chan
, size_t offset
,
162 size_t *pre_header_padding
,
163 struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
165 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
166 struct lttng_event
*event
= ctx
->priv
;
167 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
168 size_t orig_offset
= offset
;
171 switch (lttng_chan
->header_type
) {
172 case 1: /* compact */
173 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
175 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
176 offset
+= sizeof(uint32_t); /* id and timestamp */
178 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
179 offset
+= (LTTNG_COMPACT_EVENT_BITS
+ CHAR_BIT
- 1) / CHAR_BIT
;
180 /* Align extended struct on largest member */
181 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
182 offset
+= sizeof(uint32_t); /* id */
183 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
184 offset
+= sizeof(uint64_t); /* timestamp */
188 padding
= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
190 offset
+= sizeof(uint16_t);
191 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
192 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
193 offset
+= sizeof(uint32_t); /* timestamp */
195 /* Align extended struct on largest member */
196 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
197 offset
+= sizeof(uint32_t); /* id */
198 offset
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
199 offset
+= sizeof(uint64_t); /* timestamp */
207 /* 2.8+ probe ABI. */
208 offset
+= ctx_get_size(offset
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
209 offset
+= ctx_get_size(offset
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
211 /* Pre 2.8 probe ABI. */
212 offset
+= ctx_get_size(offset
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
213 offset
+= ctx_get_size(offset
, event
->ctx
, APP_CTX_DISABLED
);
215 *pre_header_padding
= padding
;
216 return offset
- orig_offset
;
219 #include "../libringbuffer/api.h"
220 #include "lttng-rb-clients.h"
223 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
224 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
228 * lttng_write_event_header
230 * Writes the event header to the offset (already aligned on 32-bits).
232 * @config: ring buffer instance configuration
233 * @ctx: reservation context
234 * @event_id: event ID
237 void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config
*config
,
238 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
241 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
242 struct lttng_event
*event
= ctx
->priv
;
243 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
245 if (caa_unlikely(ctx
->rflags
))
248 switch (lttng_chan
->header_type
) {
249 case 1: /* compact */
251 uint32_t id_time
= 0;
253 bt_bitfield_write(&id_time
, uint32_t,
255 LTTNG_COMPACT_EVENT_BITS
,
257 bt_bitfield_write(&id_time
, uint32_t,
258 LTTNG_COMPACT_EVENT_BITS
,
259 LTTNG_COMPACT_TSC_BITS
,
261 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
266 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
267 uint16_t id
= event_id
;
269 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
270 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
271 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
279 /* 2.8+ probe ABI. */
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
);
283 /* Pre 2.8 probe ABI. */
284 ctx_record(ctx
, lttng_chan
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
285 ctx_record(ctx
, lttng_chan
, event
->ctx
, APP_CTX_DISABLED
);
287 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
292 lttng_write_event_header_slow(config
, ctx
, event_id
);
296 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
*config
,
297 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
300 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
301 struct lttng_event
*event
= ctx
->priv
;
302 struct lttng_stack_ctx
*lttng_ctx
= ctx
->priv2
;
304 switch (lttng_chan
->header_type
) {
305 case 1: /* compact */
306 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
307 uint32_t id_time
= 0;
309 bt_bitfield_write(&id_time
, uint32_t,
311 LTTNG_COMPACT_EVENT_BITS
,
313 bt_bitfield_write(&id_time
, uint32_t,
314 LTTNG_COMPACT_EVENT_BITS
,
315 LTTNG_COMPACT_TSC_BITS
,
317 lib_ring_buffer_write(config
, ctx
, &id_time
, sizeof(id_time
));
320 uint64_t timestamp
= ctx
->tsc
;
322 bt_bitfield_write(&id
, uint8_t,
324 LTTNG_COMPACT_EVENT_BITS
,
326 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
327 /* Align extended struct on largest member */
328 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
329 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
330 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
331 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
336 if (!(ctx
->rflags
& (RING_BUFFER_RFLAG_FULL_TSC
| LTTNG_RFLAG_EXTENDED
))) {
337 uint32_t timestamp
= (uint32_t) ctx
->tsc
;
338 uint16_t id
= event_id
;
340 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
341 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint32_t));
342 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
345 uint64_t timestamp
= ctx
->tsc
;
347 lib_ring_buffer_write(config
, ctx
, &id
, sizeof(id
));
348 /* Align extended struct on largest member */
349 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
350 lib_ring_buffer_write(config
, ctx
, &event_id
, sizeof(event_id
));
351 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(uint64_t));
352 lib_ring_buffer_write(config
, ctx
, ×tamp
, sizeof(timestamp
));
360 /* 2.8+ probe ABI. */
361 ctx_record(ctx
, lttng_chan
, lttng_ctx
->chan_ctx
, APP_CTX_ENABLED
);
362 ctx_record(ctx
, lttng_chan
, lttng_ctx
->event_ctx
, APP_CTX_ENABLED
);
364 /* Pre 2.8 probe ABI. */
365 ctx_record(ctx
, lttng_chan
, lttng_chan
->ctx
, APP_CTX_DISABLED
);
366 ctx_record(ctx
, lttng_chan
, event
->ctx
, APP_CTX_DISABLED
);
368 lib_ring_buffer_align_ctx(ctx
, ctx
->largest_align
);
371 static const struct lttng_ust_lib_ring_buffer_config client_config
;
373 static uint64_t client_ring_buffer_clock_read(struct channel
*chan
)
375 return lib_ring_buffer_clock_read(chan
);
379 size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config
*config
,
380 struct channel
*chan
, size_t offset
,
381 size_t *pre_header_padding
,
382 struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
384 return record_header_size(config
, chan
, offset
,
385 pre_header_padding
, ctx
);
389 * client_packet_header_size - called on buffer-switch to a new sub-buffer
391 * Return header size without padding after the structure. Don't use packed
392 * structure because gcc generates inefficient code on some architectures
395 static size_t client_packet_header_size(void)
397 return offsetof(struct packet_header
, ctx
.header_end
);
400 static void client_buffer_begin(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
401 unsigned int subbuf_idx
,
402 struct lttng_ust_shm_handle
*handle
)
404 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
405 struct packet_header
*header
=
406 (struct packet_header
*)
407 lib_ring_buffer_offset_address(&buf
->backend
,
408 subbuf_idx
* chan
->backend
.subbuf_size
,
410 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
411 uint64_t cnt
= shmp_index(handle
, buf
->backend
.buf_cnt
, subbuf_idx
)->seq_cnt
;
416 header
->magic
= CTF_MAGIC_NUMBER
;
417 memcpy(header
->uuid
, lttng_chan
->uuid
, sizeof(lttng_chan
->uuid
));
418 header
->stream_id
= lttng_chan
->id
;
419 header
->stream_instance_id
= buf
->backend
.cpu
;
420 header
->ctx
.timestamp_begin
= tsc
;
421 header
->ctx
.timestamp_end
= 0;
422 header
->ctx
.content_size
= ~0ULL; /* for debugging */
423 header
->ctx
.packet_size
= ~0ULL;
424 header
->ctx
.packet_seq_num
= chan
->backend
.num_subbuf
* cnt
+ subbuf_idx
;
425 header
->ctx
.events_discarded
= 0;
426 header
->ctx
.cpu_id
= buf
->backend
.cpu
;
430 * offset is assumed to never be 0 here : never deliver a completely empty
431 * subbuffer. data_size is between 1 and subbuf_size.
433 static void client_buffer_end(struct lttng_ust_lib_ring_buffer
*buf
, uint64_t tsc
,
434 unsigned int subbuf_idx
, unsigned long data_size
,
435 struct lttng_ust_shm_handle
*handle
)
437 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
438 struct packet_header
*header
=
439 (struct packet_header
*)
440 lib_ring_buffer_offset_address(&buf
->backend
,
441 subbuf_idx
* chan
->backend
.subbuf_size
,
443 unsigned long records_lost
= 0;
448 header
->ctx
.timestamp_end
= tsc
;
449 header
->ctx
.content_size
=
450 (uint64_t) data_size
* CHAR_BIT
; /* in bits */
451 header
->ctx
.packet_size
=
452 (uint64_t) PAGE_ALIGN(data_size
) * CHAR_BIT
; /* in bits */
454 records_lost
+= lib_ring_buffer_get_records_lost_full(&client_config
, buf
);
455 records_lost
+= lib_ring_buffer_get_records_lost_wrap(&client_config
, buf
);
456 records_lost
+= lib_ring_buffer_get_records_lost_big(&client_config
, buf
);
457 header
->ctx
.events_discarded
= records_lost
;
460 static int client_buffer_create(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
,
461 int cpu
, const char *name
, struct lttng_ust_shm_handle
*handle
)
466 static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer
*buf
, void *priv
, int cpu
, struct lttng_ust_shm_handle
*handle
)
470 static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
471 size_t *offset
, size_t *length
)
473 *offset
= offsetof(struct packet_header
, ctx
.content_size
);
474 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.content_size
);
477 static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config
*config
,
478 size_t *offset
, size_t *length
)
480 *offset
= offsetof(struct packet_header
, ctx
.packet_size
);
481 *length
= sizeof(((struct packet_header
*) NULL
)->ctx
.packet_size
);
484 static struct packet_header
*client_packet_header(struct lttng_ust_lib_ring_buffer
*buf
,
485 struct lttng_ust_shm_handle
*handle
)
487 return lib_ring_buffer_read_offset_address(&buf
->backend
, 0, handle
);
490 static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer
*buf
,
491 struct lttng_ust_shm_handle
*handle
,
492 uint64_t *timestamp_begin
)
494 struct packet_header
*header
;
496 header
= client_packet_header(buf
, handle
);
499 *timestamp_begin
= header
->ctx
.timestamp_begin
;
503 static int client_timestamp_end(struct lttng_ust_lib_ring_buffer
*buf
,
504 struct lttng_ust_shm_handle
*handle
,
505 uint64_t *timestamp_end
)
507 struct packet_header
*header
;
509 header
= client_packet_header(buf
, handle
);
512 *timestamp_end
= header
->ctx
.timestamp_end
;
516 static int client_events_discarded(struct lttng_ust_lib_ring_buffer
*buf
,
517 struct lttng_ust_shm_handle
*handle
,
518 uint64_t *events_discarded
)
520 struct packet_header
*header
;
522 header
= client_packet_header(buf
, handle
);
525 *events_discarded
= header
->ctx
.events_discarded
;
529 static int client_content_size(struct lttng_ust_lib_ring_buffer
*buf
,
530 struct lttng_ust_shm_handle
*handle
,
531 uint64_t *content_size
)
533 struct packet_header
*header
;
535 header
= client_packet_header(buf
, handle
);
538 *content_size
= header
->ctx
.content_size
;
542 static int client_packet_size(struct lttng_ust_lib_ring_buffer
*buf
,
543 struct lttng_ust_shm_handle
*handle
,
544 uint64_t *packet_size
)
546 struct packet_header
*header
;
548 header
= client_packet_header(buf
, handle
);
551 *packet_size
= header
->ctx
.packet_size
;
555 static int client_stream_id(struct lttng_ust_lib_ring_buffer
*buf
,
556 struct lttng_ust_shm_handle
*handle
,
559 struct channel
*chan
= shmp(handle
, buf
->backend
.chan
);
560 struct lttng_channel
*lttng_chan
= channel_get_private(chan
);
562 *stream_id
= lttng_chan
->id
;
567 static int client_current_timestamp(struct lttng_ust_lib_ring_buffer
*buf
,
568 struct lttng_ust_shm_handle
*handle
,
571 struct channel
*chan
;
573 chan
= shmp(handle
, handle
->chan
);
574 *ts
= client_ring_buffer_clock_read(chan
);
579 static int client_sequence_number(struct lttng_ust_lib_ring_buffer
*buf
,
580 struct lttng_ust_shm_handle
*handle
,
583 struct packet_header
*header
;
585 header
= client_packet_header(buf
, handle
);
588 *seq
= header
->ctx
.packet_seq_num
;
592 static int client_instance_id(struct lttng_ust_lib_ring_buffer
*buf
,
593 struct lttng_ust_shm_handle
*handle
,
596 *id
= buf
->backend
.cpu
;
602 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb
= {
604 .ring_buffer_clock_read
= client_ring_buffer_clock_read
,
605 .record_header_size
= client_record_header_size
,
606 .subbuffer_header_size
= client_packet_header_size
,
607 .buffer_begin
= client_buffer_begin
,
608 .buffer_end
= client_buffer_end
,
609 .buffer_create
= client_buffer_create
,
610 .buffer_finalize
= client_buffer_finalize
,
611 .content_size_field
= client_content_size_field
,
612 .packet_size_field
= client_packet_size_field
,
614 .timestamp_begin
= client_timestamp_begin
,
615 .timestamp_end
= client_timestamp_end
,
616 .events_discarded
= client_events_discarded
,
617 .content_size
= client_content_size
,
618 .packet_size
= client_packet_size
,
619 .stream_id
= client_stream_id
,
620 .current_timestamp
= client_current_timestamp
,
621 .sequence_number
= client_sequence_number
,
622 .instance_id
= client_instance_id
,
625 static const struct lttng_ust_lib_ring_buffer_config client_config
= {
626 .cb
.ring_buffer_clock_read
= client_ring_buffer_clock_read
,
627 .cb
.record_header_size
= client_record_header_size
,
628 .cb
.subbuffer_header_size
= client_packet_header_size
,
629 .cb
.buffer_begin
= client_buffer_begin
,
630 .cb
.buffer_end
= client_buffer_end
,
631 .cb
.buffer_create
= client_buffer_create
,
632 .cb
.buffer_finalize
= client_buffer_finalize
,
633 .cb
.content_size_field
= client_content_size_field
,
634 .cb
.packet_size_field
= client_packet_size_field
,
636 .tsc_bits
= LTTNG_COMPACT_TSC_BITS
,
637 .alloc
= RING_BUFFER_ALLOC_PER_CPU
,
638 .sync
= RING_BUFFER_SYNC_GLOBAL
,
639 .mode
= RING_BUFFER_MODE_TEMPLATE
,
640 .backend
= RING_BUFFER_PAGE
,
641 .output
= RING_BUFFER_MMAP
,
642 .oops
= RING_BUFFER_OOPS_CONSISTENCY
,
643 .ipi
= RING_BUFFER_NO_IPI_BARRIER
,
644 .wakeup
= LTTNG_CLIENT_WAKEUP
,
645 .client_type
= LTTNG_CLIENT_TYPE
,
647 .cb_ptr
= &client_cb
.parent
,
650 const struct lttng_ust_client_lib_ring_buffer_client_cb
*LTTNG_CLIENT_CALLBACKS
= &client_cb
;
653 struct lttng_channel
*_channel_create(const char *name
,
655 size_t subbuf_size
, size_t num_subbuf
,
656 unsigned int switch_timer_interval
,
657 unsigned int read_timer_interval
,
660 const int *stream_fds
, int nr_stream_fds
,
661 int64_t blocking_timeout
)
663 struct lttng_channel chan_priv_init
;
664 struct lttng_ust_shm_handle
*handle
;
665 struct lttng_channel
*lttng_chan
;
668 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
669 memcpy(chan_priv_init
.uuid
, uuid
, LTTNG_UST_UUID_LEN
);
670 chan_priv_init
.id
= chan_id
;
671 handle
= channel_create(&client_config
, name
,
672 &priv
, __alignof__(struct lttng_channel
),
673 sizeof(struct lttng_channel
),
675 buf_addr
, subbuf_size
, num_subbuf
,
676 switch_timer_interval
, read_timer_interval
,
677 stream_fds
, nr_stream_fds
, blocking_timeout
);
681 lttng_chan
->handle
= handle
;
682 lttng_chan
->chan
= shmp(handle
, handle
->chan
);
687 void lttng_channel_destroy(struct lttng_channel
*chan
)
689 channel_destroy(chan
->chan
, chan
->handle
, 1);
693 int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
696 struct lttng_channel
*lttng_chan
= channel_get_private(ctx
->chan
);
699 cpu
= lib_ring_buffer_get_cpu(&client_config
);
704 switch (lttng_chan
->header_type
) {
705 case 1: /* compact */
707 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
710 if (event_id
> 65534)
711 ctx
->rflags
|= LTTNG_RFLAG_EXTENDED
;
717 ret
= lib_ring_buffer_reserve(&client_config
, ctx
);
718 if (caa_unlikely(ret
))
720 if (caa_likely(ctx
->ctx_len
721 >= sizeof(struct lttng_ust_lib_ring_buffer_ctx
))) {
722 if (lib_ring_buffer_backend_get_pages(&client_config
, ctx
,
723 &ctx
->backend_pages
)) {
728 lttng_write_event_header(&client_config
, ctx
, event_id
);
731 lib_ring_buffer_put_cpu(&client_config
);
736 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx
*ctx
)
738 lib_ring_buffer_commit(&client_config
, ctx
);
739 lib_ring_buffer_put_cpu(&client_config
);
743 void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
746 lib_ring_buffer_write(&client_config
, ctx
, src
, len
);
750 void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const char *src
,
753 lib_ring_buffer_strcpy(&client_config
, ctx
, src
, len
, '#');
758 wait_queue_head_t
*lttng_get_reader_wait_queue(struct channel
*chan
)
760 return &chan
->read_wait
;
764 wait_queue_head_t
*lttng_get_hp_wait_queue(struct channel
*chan
)
766 return &chan
->hp_wait
;
771 int lttng_is_finalized(struct channel
*chan
)
773 return lib_ring_buffer_channel_is_finalized(chan
);
777 int lttng_is_disabled(struct channel
*chan
)
779 return lib_ring_buffer_channel_is_disabled(chan
);
783 int lttng_flush_buffer(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
)
785 struct lttng_ust_lib_ring_buffer
*buf
;
788 for_each_channel_cpu(cpu
, chan
) {
789 int shm_fd
, wait_fd
, wakeup_fd
;
790 uint64_t memory_map_size
;
792 buf
= channel_get_ring_buffer(&client_config
, chan
,
793 cpu
, handle
, &shm_fd
, &wait_fd
,
794 &wakeup_fd
, &memory_map_size
);
795 lib_ring_buffer_switch(&client_config
, buf
,
796 SWITCH_ACTIVE
, handle
);
801 static struct lttng_transport lttng_relay_transport
= {
802 .name
= "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap",
804 .channel_create
= _channel_create
,
805 .channel_destroy
= lttng_channel_destroy
,
807 .event_reserve
= lttng_event_reserve
,
808 .event_commit
= lttng_event_commit
,
809 .event_write
= lttng_event_write
,
810 .packet_avail_size
= NULL
, /* Would be racy anyway */
811 //.get_reader_wait_queue = lttng_get_reader_wait_queue,
812 //.get_hp_wait_queue = lttng_get_hp_wait_queue,
813 .is_finalized
= lttng_is_finalized
,
814 .is_disabled
= lttng_is_disabled
,
815 .flush_buffer
= lttng_flush_buffer
,
816 .event_strcpy
= lttng_event_strcpy
,
818 .client_config
= &client_config
,
821 void RING_BUFFER_MODE_TEMPLATE_INIT(void)
823 DBG("LTT : ltt ring buffer client \"%s\" init\n",
824 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
825 lttng_transport_register(<tng_relay_transport
);
828 void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
830 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
831 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING
"-mmap");
832 lttng_transport_unregister(<tng_relay_transport
);