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