Add stream instance id to the packet header
[lttng-ust.git] / liblttng-ust / lttng-ring-buffer-client.h
1 /*
2 * lttng-ring-buffer-client.h
3 *
4 * LTTng lib ring buffer client template.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include <stdint.h>
24 #include <lttng/ust-events.h>
25 #include "lttng/bitfield.h"
26 #include "clock.h"
27 #include "lttng-tracer.h"
28 #include "../libringbuffer/frontend_types.h"
29
30 #define LTTNG_COMPACT_EVENT_BITS 5
31 #define LTTNG_COMPACT_TSC_BITS 27
32
33 /*
34 * Keep the natural field alignment for _each field_ within this structure if
35 * you ever add/remove a field from this header. Packed attribute is not used
36 * because gcc generates poor code on at least powerpc and mips. Don't ever
37 * let gcc add padding between the structure elements.
38 */
39
40 struct packet_header {
41 /* Trace packet header */
42 uint32_t magic; /*
43 * Trace magic number.
44 * contains endianness information.
45 */
46 uint8_t uuid[LTTNG_UST_UUID_LEN];
47 uint32_t stream_id;
48 uint64_t stream_instance_id;
49
50 struct {
51 /* Stream packet context */
52 uint64_t timestamp_begin; /* Cycle count at subbuffer start */
53 uint64_t timestamp_end; /* Cycle count at subbuffer end */
54 uint64_t content_size; /* Size of data in subbuffer */
55 uint64_t packet_size; /* Subbuffer size (include padding) */
56 unsigned long events_discarded; /*
57 * Events lost in this subbuffer since
58 * the beginning of the trace.
59 * (may overflow)
60 */
61 uint32_t cpu_id; /* CPU id associated with stream */
62 uint8_t header_end; /* End of header */
63 } ctx;
64 };
65
66
67 static inline uint64_t lib_ring_buffer_clock_read(struct channel *chan)
68 {
69 return trace_clock_read64();
70 }
71
72 static inline
73 size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx)
74 {
75 int i;
76 size_t orig_offset = offset;
77
78 if (caa_likely(!ctx))
79 return 0;
80 offset += lib_ring_buffer_align(offset, ctx->largest_align);
81 for (i = 0; i < ctx->nr_fields; i++)
82 offset += ctx->fields[i].get_size(&ctx->fields[i], offset);
83 return offset - orig_offset;
84 }
85
86 static inline
87 void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx,
88 struct lttng_channel *chan,
89 struct lttng_ctx *ctx)
90 {
91 int i;
92
93 if (caa_likely(!ctx))
94 return;
95 lib_ring_buffer_align_ctx(bufctx, ctx->largest_align);
96 for (i = 0; i < ctx->nr_fields; i++)
97 ctx->fields[i].record(&ctx->fields[i], bufctx, chan);
98 }
99
100 /*
101 * record_header_size - Calculate the header size and padding necessary.
102 * @config: ring buffer instance configuration
103 * @chan: channel
104 * @offset: offset in the write buffer
105 * @pre_header_padding: padding to add before the header (output)
106 * @ctx: reservation context
107 *
108 * Returns the event header size (including padding).
109 *
110 * The payload must itself determine its own alignment from the biggest type it
111 * contains.
112 */
113 static __inline__
114 size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
115 struct channel *chan, size_t offset,
116 size_t *pre_header_padding,
117 struct lttng_ust_lib_ring_buffer_ctx *ctx)
118 {
119 struct lttng_channel *lttng_chan = channel_get_private(chan);
120 struct lttng_event *event = ctx->priv;
121 size_t orig_offset = offset;
122 size_t padding;
123
124 switch (lttng_chan->header_type) {
125 case 1: /* compact */
126 padding = lib_ring_buffer_align(offset, lttng_alignof(uint32_t));
127 offset += padding;
128 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
129 offset += sizeof(uint32_t); /* id and timestamp */
130 } else {
131 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
132 offset += (LTTNG_COMPACT_EVENT_BITS + CHAR_BIT - 1) / CHAR_BIT;
133 /* Align extended struct on largest member */
134 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
135 offset += sizeof(uint32_t); /* id */
136 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
137 offset += sizeof(uint64_t); /* timestamp */
138 }
139 break;
140 case 2: /* large */
141 padding = lib_ring_buffer_align(offset, lttng_alignof(uint16_t));
142 offset += padding;
143 offset += sizeof(uint16_t);
144 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
145 offset += lib_ring_buffer_align(offset, lttng_alignof(uint32_t));
146 offset += sizeof(uint32_t); /* timestamp */
147 } else {
148 /* Align extended struct on largest member */
149 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
150 offset += sizeof(uint32_t); /* id */
151 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
152 offset += sizeof(uint64_t); /* timestamp */
153 }
154 break;
155 default:
156 padding = 0;
157 WARN_ON_ONCE(1);
158 }
159 offset += ctx_get_size(offset, event->ctx);
160 offset += ctx_get_size(offset, lttng_chan->ctx);
161
162 *pre_header_padding = padding;
163 return offset - orig_offset;
164 }
165
166 #include "../libringbuffer/api.h"
167 #include "lttng-rb-clients.h"
168
169 static
170 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config,
171 struct lttng_ust_lib_ring_buffer_ctx *ctx,
172 uint32_t event_id);
173
174 /*
175 * lttng_write_event_header
176 *
177 * Writes the event header to the offset (already aligned on 32-bits).
178 *
179 * @config: ring buffer instance configuration
180 * @ctx: reservation context
181 * @event_id: event ID
182 */
183 static __inline__
184 void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *config,
185 struct lttng_ust_lib_ring_buffer_ctx *ctx,
186 uint32_t event_id)
187 {
188 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
189 struct lttng_stack_ctx *lttng_ctx = ctx->priv2;
190
191 if (caa_unlikely(ctx->rflags))
192 goto slow_path;
193
194 switch (lttng_chan->header_type) {
195 case 1: /* compact */
196 {
197 uint32_t id_time = 0;
198
199 bt_bitfield_write(&id_time, uint32_t,
200 0,
201 LTTNG_COMPACT_EVENT_BITS,
202 event_id);
203 bt_bitfield_write(&id_time, uint32_t,
204 LTTNG_COMPACT_EVENT_BITS,
205 LTTNG_COMPACT_TSC_BITS,
206 ctx->tsc);
207 lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
208 break;
209 }
210 case 2: /* large */
211 {
212 uint32_t timestamp = (uint32_t) ctx->tsc;
213 uint16_t id = event_id;
214
215 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
216 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint32_t));
217 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
218 break;
219 }
220 default:
221 WARN_ON_ONCE(1);
222 }
223
224 ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx);
225 ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx);
226 lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
227
228 return;
229
230 slow_path:
231 lttng_write_event_header_slow(config, ctx, event_id);
232 }
233
234 static
235 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config,
236 struct lttng_ust_lib_ring_buffer_ctx *ctx,
237 uint32_t event_id)
238 {
239 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
240 struct lttng_stack_ctx *lttng_ctx = ctx->priv2;
241
242 switch (lttng_chan->header_type) {
243 case 1: /* compact */
244 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
245 uint32_t id_time = 0;
246
247 bt_bitfield_write(&id_time, uint32_t,
248 0,
249 LTTNG_COMPACT_EVENT_BITS,
250 event_id);
251 bt_bitfield_write(&id_time, uint32_t,
252 LTTNG_COMPACT_EVENT_BITS,
253 LTTNG_COMPACT_TSC_BITS,
254 ctx->tsc);
255 lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
256 } else {
257 uint8_t id = 0;
258 uint64_t timestamp = ctx->tsc;
259
260 bt_bitfield_write(&id, uint8_t,
261 0,
262 LTTNG_COMPACT_EVENT_BITS,
263 31);
264 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
265 /* Align extended struct on largest member */
266 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
267 lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
268 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
269 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
270 }
271 break;
272 case 2: /* large */
273 {
274 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
275 uint32_t timestamp = (uint32_t) ctx->tsc;
276 uint16_t id = event_id;
277
278 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
279 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint32_t));
280 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
281 } else {
282 uint16_t id = 65535;
283 uint64_t timestamp = ctx->tsc;
284
285 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
286 /* Align extended struct on largest member */
287 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
288 lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
289 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
290 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
291 }
292 break;
293 }
294 default:
295 WARN_ON_ONCE(1);
296 }
297 ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx);
298 ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx);
299 lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
300 }
301
302 static const struct lttng_ust_lib_ring_buffer_config client_config;
303
304 static uint64_t client_ring_buffer_clock_read(struct channel *chan)
305 {
306 return lib_ring_buffer_clock_read(chan);
307 }
308
309 static
310 size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
311 struct channel *chan, size_t offset,
312 size_t *pre_header_padding,
313 struct lttng_ust_lib_ring_buffer_ctx *ctx)
314 {
315 return record_header_size(config, chan, offset,
316 pre_header_padding, ctx);
317 }
318
319 /**
320 * client_packet_header_size - called on buffer-switch to a new sub-buffer
321 *
322 * Return header size without padding after the structure. Don't use packed
323 * structure because gcc generates inefficient code on some architectures
324 * (powerpc, mips..)
325 */
326 static size_t client_packet_header_size(void)
327 {
328 return offsetof(struct packet_header, ctx.header_end);
329 }
330
331 static void client_buffer_begin(struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
332 unsigned int subbuf_idx,
333 struct lttng_ust_shm_handle *handle)
334 {
335 struct channel *chan = shmp(handle, buf->backend.chan);
336 struct packet_header *header =
337 (struct packet_header *)
338 lib_ring_buffer_offset_address(&buf->backend,
339 subbuf_idx * chan->backend.subbuf_size,
340 handle);
341 struct lttng_channel *lttng_chan = channel_get_private(chan);
342
343 assert(header);
344 if (!header)
345 return;
346 header->magic = CTF_MAGIC_NUMBER;
347 memcpy(header->uuid, lttng_chan->uuid, sizeof(lttng_chan->uuid));
348 header->stream_id = lttng_chan->id;
349 header->stream_instance_id = buf->backend.cpu;
350 header->ctx.timestamp_begin = tsc;
351 header->ctx.timestamp_end = 0;
352 header->ctx.content_size = ~0ULL; /* for debugging */
353 header->ctx.packet_size = ~0ULL;
354 header->ctx.events_discarded = 0;
355 header->ctx.cpu_id = buf->backend.cpu;
356 }
357
358 /*
359 * offset is assumed to never be 0 here : never deliver a completely empty
360 * subbuffer. data_size is between 1 and subbuf_size.
361 */
362 static void client_buffer_end(struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
363 unsigned int subbuf_idx, unsigned long data_size,
364 struct lttng_ust_shm_handle *handle)
365 {
366 struct channel *chan = shmp(handle, buf->backend.chan);
367 struct packet_header *header =
368 (struct packet_header *)
369 lib_ring_buffer_offset_address(&buf->backend,
370 subbuf_idx * chan->backend.subbuf_size,
371 handle);
372 unsigned long records_lost = 0;
373
374 assert(header);
375 if (!header)
376 return;
377 header->ctx.timestamp_end = tsc;
378 header->ctx.content_size =
379 (uint64_t) data_size * CHAR_BIT; /* in bits */
380 header->ctx.packet_size =
381 (uint64_t) PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
382
383 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
384 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
385 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
386 header->ctx.events_discarded = records_lost;
387 }
388
389 static int client_buffer_create(struct lttng_ust_lib_ring_buffer *buf, void *priv,
390 int cpu, const char *name, struct lttng_ust_shm_handle *handle)
391 {
392 return 0;
393 }
394
395 static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf, void *priv, int cpu, struct lttng_ust_shm_handle *handle)
396 {
397 }
398
399 static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config *config,
400 size_t *offset, size_t *length)
401 {
402 *offset = offsetof(struct packet_header, ctx.content_size);
403 *length = sizeof(((struct packet_header *) NULL)->ctx.content_size);
404 }
405
406 static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config *config,
407 size_t *offset, size_t *length)
408 {
409 *offset = offsetof(struct packet_header, ctx.packet_size);
410 *length = sizeof(((struct packet_header *) NULL)->ctx.packet_size);
411 }
412
413 static struct packet_header *client_packet_header(struct lttng_ust_lib_ring_buffer *buf,
414 struct lttng_ust_shm_handle *handle)
415 {
416 return lib_ring_buffer_read_offset_address(&buf->backend, 0, handle);
417 }
418
419 static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer *buf,
420 struct lttng_ust_shm_handle *handle,
421 uint64_t *timestamp_begin)
422 {
423 struct packet_header *header;
424
425 header = client_packet_header(buf, handle);
426 if (!header)
427 return -1;
428 *timestamp_begin = header->ctx.timestamp_begin;
429 return 0;
430 }
431
432 static int client_timestamp_end(struct lttng_ust_lib_ring_buffer *buf,
433 struct lttng_ust_shm_handle *handle,
434 uint64_t *timestamp_end)
435 {
436 struct packet_header *header;
437
438 header = client_packet_header(buf, handle);
439 if (!header)
440 return -1;
441 *timestamp_end = header->ctx.timestamp_end;
442 return 0;
443 }
444
445 static int client_events_discarded(struct lttng_ust_lib_ring_buffer *buf,
446 struct lttng_ust_shm_handle *handle,
447 uint64_t *events_discarded)
448 {
449 struct packet_header *header;
450
451 header = client_packet_header(buf, handle);
452 if (!header)
453 return -1;
454 *events_discarded = header->ctx.events_discarded;
455 return 0;
456 }
457
458 static int client_content_size(struct lttng_ust_lib_ring_buffer *buf,
459 struct lttng_ust_shm_handle *handle,
460 uint64_t *content_size)
461 {
462 struct packet_header *header;
463
464 header = client_packet_header(buf, handle);
465 if (!header)
466 return -1;
467 *content_size = header->ctx.content_size;
468 return 0;
469 }
470
471 static int client_packet_size(struct lttng_ust_lib_ring_buffer *buf,
472 struct lttng_ust_shm_handle *handle,
473 uint64_t *packet_size)
474 {
475 struct packet_header *header;
476
477 header = client_packet_header(buf, handle);
478 if (!header)
479 return -1;
480 *packet_size = header->ctx.packet_size;
481 return 0;
482 }
483
484 static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf,
485 struct lttng_ust_shm_handle *handle,
486 uint64_t *stream_id)
487 {
488 struct packet_header *header;
489
490 header = client_packet_header(buf, handle);
491 if (!header)
492 return -1;
493 *stream_id = header->stream_id;
494 return 0;
495 }
496
497 static int client_current_timestamp(struct lttng_ust_lib_ring_buffer *buf,
498 struct lttng_ust_shm_handle *handle,
499 uint64_t *ts)
500 {
501 struct channel *chan;
502
503 chan = shmp(handle, handle->chan);
504 *ts = client_ring_buffer_clock_read(chan);
505
506 return 0;
507 }
508
509 static const
510 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
511 .parent = {
512 .ring_buffer_clock_read = client_ring_buffer_clock_read,
513 .record_header_size = client_record_header_size,
514 .subbuffer_header_size = client_packet_header_size,
515 .buffer_begin = client_buffer_begin,
516 .buffer_end = client_buffer_end,
517 .buffer_create = client_buffer_create,
518 .buffer_finalize = client_buffer_finalize,
519 .content_size_field = client_content_size_field,
520 .packet_size_field = client_packet_size_field,
521 },
522 .timestamp_begin = client_timestamp_begin,
523 .timestamp_end = client_timestamp_end,
524 .events_discarded = client_events_discarded,
525 .content_size = client_content_size,
526 .packet_size = client_packet_size,
527 .stream_id = client_stream_id,
528 .current_timestamp = client_current_timestamp,
529 };
530
531 static const struct lttng_ust_lib_ring_buffer_config client_config = {
532 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
533 .cb.record_header_size = client_record_header_size,
534 .cb.subbuffer_header_size = client_packet_header_size,
535 .cb.buffer_begin = client_buffer_begin,
536 .cb.buffer_end = client_buffer_end,
537 .cb.buffer_create = client_buffer_create,
538 .cb.buffer_finalize = client_buffer_finalize,
539 .cb.content_size_field = client_content_size_field,
540 .cb.packet_size_field = client_packet_size_field,
541
542 .tsc_bits = LTTNG_COMPACT_TSC_BITS,
543 .alloc = RING_BUFFER_ALLOC_PER_CPU,
544 .sync = RING_BUFFER_SYNC_GLOBAL,
545 .mode = RING_BUFFER_MODE_TEMPLATE,
546 .backend = RING_BUFFER_PAGE,
547 .output = RING_BUFFER_MMAP,
548 .oops = RING_BUFFER_OOPS_CONSISTENCY,
549 .ipi = RING_BUFFER_NO_IPI_BARRIER,
550 .wakeup = LTTNG_CLIENT_WAKEUP,
551 .client_type = LTTNG_CLIENT_TYPE,
552
553 .cb_ptr = &client_cb.parent,
554 };
555
556 const struct lttng_ust_client_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_cb;
557
558 static
559 struct lttng_channel *_channel_create(const char *name,
560 void *buf_addr,
561 size_t subbuf_size, size_t num_subbuf,
562 unsigned int switch_timer_interval,
563 unsigned int read_timer_interval,
564 unsigned char *uuid,
565 uint32_t chan_id,
566 const int *stream_fds, int nr_stream_fds)
567 {
568 struct lttng_channel chan_priv_init;
569 struct lttng_ust_shm_handle *handle;
570 struct lttng_channel *lttng_chan;
571 void *priv;
572
573 memset(&chan_priv_init, 0, sizeof(chan_priv_init));
574 memcpy(chan_priv_init.uuid, uuid, LTTNG_UST_UUID_LEN);
575 chan_priv_init.id = chan_id;
576 handle = channel_create(&client_config, name,
577 &priv, __alignof__(struct lttng_channel),
578 sizeof(struct lttng_channel),
579 &chan_priv_init,
580 buf_addr, subbuf_size, num_subbuf,
581 switch_timer_interval, read_timer_interval,
582 stream_fds, nr_stream_fds);
583 if (!handle)
584 return NULL;
585 lttng_chan = priv;
586 lttng_chan->handle = handle;
587 lttng_chan->chan = shmp(handle, handle->chan);
588 return lttng_chan;
589 }
590
591 static
592 void lttng_channel_destroy(struct lttng_channel *chan)
593 {
594 channel_destroy(chan->chan, chan->handle, 1);
595 }
596
597 static
598 int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
599 uint32_t event_id)
600 {
601 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
602 int ret, cpu;
603
604 cpu = lib_ring_buffer_get_cpu(&client_config);
605 if (cpu < 0)
606 return -EPERM;
607 ctx->cpu = cpu;
608
609 switch (lttng_chan->header_type) {
610 case 1: /* compact */
611 if (event_id > 30)
612 ctx->rflags |= LTTNG_RFLAG_EXTENDED;
613 break;
614 case 2: /* large */
615 if (event_id > 65534)
616 ctx->rflags |= LTTNG_RFLAG_EXTENDED;
617 break;
618 default:
619 WARN_ON_ONCE(1);
620 }
621
622 ret = lib_ring_buffer_reserve(&client_config, ctx);
623 if (ret)
624 goto put;
625 lttng_write_event_header(&client_config, ctx, event_id);
626 return 0;
627 put:
628 lib_ring_buffer_put_cpu(&client_config);
629 return ret;
630 }
631
632 static
633 void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx *ctx)
634 {
635 lib_ring_buffer_commit(&client_config, ctx);
636 lib_ring_buffer_put_cpu(&client_config);
637 }
638
639 static
640 void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
641 size_t len)
642 {
643 lib_ring_buffer_write(&client_config, ctx, src, len);
644 }
645
646 static
647 void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx *ctx, const char *src,
648 size_t len)
649 {
650 lib_ring_buffer_strcpy(&client_config, ctx, src, len, '#');
651 }
652
653 #if 0
654 static
655 wait_queue_head_t *lttng_get_reader_wait_queue(struct channel *chan)
656 {
657 return &chan->read_wait;
658 }
659
660 static
661 wait_queue_head_t *lttng_get_hp_wait_queue(struct channel *chan)
662 {
663 return &chan->hp_wait;
664 }
665 #endif //0
666
667 static
668 int lttng_is_finalized(struct channel *chan)
669 {
670 return lib_ring_buffer_channel_is_finalized(chan);
671 }
672
673 static
674 int lttng_is_disabled(struct channel *chan)
675 {
676 return lib_ring_buffer_channel_is_disabled(chan);
677 }
678
679 static
680 int lttng_flush_buffer(struct channel *chan, struct lttng_ust_shm_handle *handle)
681 {
682 struct lttng_ust_lib_ring_buffer *buf;
683 int cpu;
684
685 for_each_channel_cpu(cpu, chan) {
686 int shm_fd, wait_fd, wakeup_fd;
687 uint64_t memory_map_size;
688
689 buf = channel_get_ring_buffer(&client_config, chan,
690 cpu, handle, &shm_fd, &wait_fd,
691 &wakeup_fd, &memory_map_size);
692 lib_ring_buffer_switch(&client_config, buf,
693 SWITCH_ACTIVE, handle);
694 }
695 return 0;
696 }
697
698 static struct lttng_transport lttng_relay_transport = {
699 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap",
700 .ops = {
701 .channel_create = _channel_create,
702 .channel_destroy = lttng_channel_destroy,
703 .u.has_strcpy = 1,
704 .event_reserve = lttng_event_reserve,
705 .event_commit = lttng_event_commit,
706 .event_write = lttng_event_write,
707 .packet_avail_size = NULL, /* Would be racy anyway */
708 //.get_reader_wait_queue = lttng_get_reader_wait_queue,
709 //.get_hp_wait_queue = lttng_get_hp_wait_queue,
710 .is_finalized = lttng_is_finalized,
711 .is_disabled = lttng_is_disabled,
712 .flush_buffer = lttng_flush_buffer,
713 .event_strcpy = lttng_event_strcpy,
714 },
715 .client_config = &client_config,
716 };
717
718 void RING_BUFFER_MODE_TEMPLATE_INIT(void)
719 {
720 DBG("LTT : ltt ring buffer client \"%s\" init\n",
721 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
722 lttng_transport_register(&lttng_relay_transport);
723 }
724
725 void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
726 {
727 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
728 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
729 lttng_transport_unregister(&lttng_relay_transport);
730 }
This page took 0.044188 seconds and 5 git commands to generate.