Remove useless else clause
[lttng-ust.git] / liblttng-ust / lttng-ring-buffer-client.h
CommitLineData
3d1fc7fd 1/*
7dd08bec 2 * lttng-ring-buffer-client.h
3d1fc7fd 3 *
3d1fc7fd
MD
4 * LTTng lib ring buffer client template.
5 *
e92f3e28
MD
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
3d1fc7fd
MD
21 */
22
9f3fdbc6 23#include <stdint.h>
4318ae1b
MD
24#include <lttng/ust-events.h>
25#include "lttng/bitfield.h"
b728d87e 26#include "clock.h"
7dd08bec 27#include "lttng-tracer.h"
9f3fdbc6 28#include "../libringbuffer/frontend_types.h"
3d1fc7fd 29
79dfbf42
MD
30#define LTTNG_COMPACT_EVENT_BITS 5
31#define LTTNG_COMPACT_TSC_BITS 27
32
3d1fc7fd
MD
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
40struct packet_header {
41 /* Trace packet header */
42 uint32_t magic; /*
43 * Trace magic number.
44 * contains endianness information.
45 */
19d8b1b3 46 uint8_t uuid[LTTNG_UST_UUID_LEN];
3d1fc7fd
MD
47 uint32_t stream_id;
48
49 struct {
50 /* Stream packet context */
51 uint64_t timestamp_begin; /* Cycle count at subbuffer start */
52 uint64_t timestamp_end; /* Cycle count at subbuffer end */
0c00a107
MD
53 uint64_t content_size; /* Size of data in subbuffer */
54 uint64_t packet_size; /* Subbuffer size (include padding) */
18fc8d71 55 unsigned long events_discarded; /*
3d1fc7fd
MD
56 * Events lost in this subbuffer since
57 * the beginning of the trace.
58 * (may overflow)
59 */
3d1fc7fd
MD
60 uint32_t cpu_id; /* CPU id associated with stream */
61 uint8_t header_end; /* End of header */
62 } ctx;
63};
64
65
23c8854a 66static inline uint64_t lib_ring_buffer_clock_read(struct channel *chan)
3d1fc7fd
MD
67{
68 return trace_clock_read64();
69}
70
71static inline
72size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx)
73{
74 int i;
75 size_t orig_offset = offset;
76
b5a3dfa5 77 if (caa_likely(!ctx))
3d1fc7fd
MD
78 return 0;
79 for (i = 0; i < ctx->nr_fields; i++)
80 offset += ctx->fields[i].get_size(offset);
81 return offset - orig_offset;
82}
83
84static inline
4cfec15c 85void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx,
7dd08bec 86 struct lttng_channel *chan,
3d1fc7fd
MD
87 struct lttng_ctx *ctx)
88{
89 int i;
90
b5a3dfa5 91 if (caa_likely(!ctx))
3d1fc7fd
MD
92 return;
93 for (i = 0; i < ctx->nr_fields; i++)
94 ctx->fields[i].record(&ctx->fields[i], bufctx, chan);
95}
96
97/*
98 * record_header_size - Calculate the header size and padding necessary.
99 * @config: ring buffer instance configuration
100 * @chan: channel
101 * @offset: offset in the write buffer
102 * @pre_header_padding: padding to add before the header (output)
103 * @ctx: reservation context
104 *
105 * Returns the event header size (including padding).
106 *
107 * The payload must itself determine its own alignment from the biggest type it
108 * contains.
109 */
110static __inline__
4cfec15c 111unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
3d1fc7fd
MD
112 struct channel *chan, size_t offset,
113 size_t *pre_header_padding,
4cfec15c 114 struct lttng_ust_lib_ring_buffer_ctx *ctx)
3d1fc7fd 115{
7dd08bec
MD
116 struct lttng_channel *lttng_chan = channel_get_private(chan);
117 struct lttng_event *event = ctx->priv;
3d1fc7fd
MD
118 size_t orig_offset = offset;
119 size_t padding;
120
7dd08bec 121 switch (lttng_chan->header_type) {
3d1fc7fd 122 case 1: /* compact */
1dbfff0c 123 padding = lib_ring_buffer_align(offset, lttng_alignof(uint32_t));
3d1fc7fd 124 offset += padding;
7dd08bec 125 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
3d1fc7fd
MD
126 offset += sizeof(uint32_t); /* id and timestamp */
127 } else {
79dfbf42
MD
128 /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
129 offset += (LTTNG_COMPACT_EVENT_BITS + CHAR_BIT - 1) / CHAR_BIT;
3d1fc7fd 130 /* Align extended struct on largest member */
1dbfff0c 131 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
3d1fc7fd 132 offset += sizeof(uint32_t); /* id */
1dbfff0c 133 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
3d1fc7fd
MD
134 offset += sizeof(uint64_t); /* timestamp */
135 }
136 break;
137 case 2: /* large */
1dbfff0c 138 padding = lib_ring_buffer_align(offset, lttng_alignof(uint16_t));
3d1fc7fd
MD
139 offset += padding;
140 offset += sizeof(uint16_t);
7dd08bec 141 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
1dbfff0c 142 offset += lib_ring_buffer_align(offset, lttng_alignof(uint32_t));
3d1fc7fd
MD
143 offset += sizeof(uint32_t); /* timestamp */
144 } else {
145 /* Align extended struct on largest member */
1dbfff0c 146 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
3d1fc7fd 147 offset += sizeof(uint32_t); /* id */
1dbfff0c 148 offset += lib_ring_buffer_align(offset, lttng_alignof(uint64_t));
3d1fc7fd
MD
149 offset += sizeof(uint64_t); /* timestamp */
150 }
151 break;
152 default:
9f3fdbc6 153 padding = 0;
3d1fc7fd
MD
154 WARN_ON_ONCE(1);
155 }
156 offset += ctx_get_size(offset, event->ctx);
7dd08bec 157 offset += ctx_get_size(offset, lttng_chan->ctx);
3d1fc7fd
MD
158
159 *pre_header_padding = padding;
160 return offset - orig_offset;
161}
162
9f3fdbc6 163#include "../libringbuffer/api.h"
3d1fc7fd 164
9f3fdbc6 165static
7dd08bec 166void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config,
4cfec15c 167 struct lttng_ust_lib_ring_buffer_ctx *ctx,
3d1fc7fd
MD
168 uint32_t event_id);
169
170/*
7dd08bec 171 * lttng_write_event_header
3d1fc7fd
MD
172 *
173 * Writes the event header to the offset (already aligned on 32-bits).
174 *
175 * @config: ring buffer instance configuration
176 * @ctx: reservation context
177 * @event_id: event ID
178 */
179static __inline__
7dd08bec 180void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *config,
4cfec15c 181 struct lttng_ust_lib_ring_buffer_ctx *ctx,
3d1fc7fd
MD
182 uint32_t event_id)
183{
7dd08bec
MD
184 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
185 struct lttng_event *event = ctx->priv;
3d1fc7fd 186
b5a3dfa5 187 if (caa_unlikely(ctx->rflags))
3d1fc7fd
MD
188 goto slow_path;
189
7dd08bec 190 switch (lttng_chan->header_type) {
3d1fc7fd
MD
191 case 1: /* compact */
192 {
193 uint32_t id_time = 0;
194
79dfbf42
MD
195 bt_bitfield_write(&id_time, uint32_t,
196 0,
197 LTTNG_COMPACT_EVENT_BITS,
198 event_id);
199 bt_bitfield_write(&id_time, uint32_t,
200 LTTNG_COMPACT_EVENT_BITS,
201 LTTNG_COMPACT_TSC_BITS,
202 ctx->tsc);
3d1fc7fd
MD
203 lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
204 break;
205 }
206 case 2: /* large */
207 {
208 uint32_t timestamp = (uint32_t) ctx->tsc;
209 uint16_t id = event_id;
210
211 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
1dbfff0c 212 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint32_t));
3d1fc7fd
MD
213 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
214 break;
215 }
216 default:
217 WARN_ON_ONCE(1);
218 }
219
7dd08bec
MD
220 ctx_record(ctx, lttng_chan, lttng_chan->ctx);
221 ctx_record(ctx, lttng_chan, event->ctx);
d3b2c3e0 222 lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
3d1fc7fd
MD
223
224 return;
225
226slow_path:
7dd08bec 227 lttng_write_event_header_slow(config, ctx, event_id);
3d1fc7fd
MD
228}
229
9f3fdbc6 230static
7dd08bec 231void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config,
4cfec15c 232 struct lttng_ust_lib_ring_buffer_ctx *ctx,
3d1fc7fd
MD
233 uint32_t event_id)
234{
7dd08bec
MD
235 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
236 struct lttng_event *event = ctx->priv;
3d1fc7fd 237
7dd08bec 238 switch (lttng_chan->header_type) {
3d1fc7fd 239 case 1: /* compact */
7dd08bec 240 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
3d1fc7fd
MD
241 uint32_t id_time = 0;
242
79dfbf42
MD
243 bt_bitfield_write(&id_time, uint32_t,
244 0,
245 LTTNG_COMPACT_EVENT_BITS,
246 event_id);
247 bt_bitfield_write(&id_time, uint32_t,
248 LTTNG_COMPACT_EVENT_BITS,
249 LTTNG_COMPACT_TSC_BITS,
250 ctx->tsc);
3d1fc7fd
MD
251 lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
252 } else {
253 uint8_t id = 0;
254 uint64_t timestamp = ctx->tsc;
255
79dfbf42
MD
256 bt_bitfield_write(&id, uint8_t,
257 0,
258 LTTNG_COMPACT_EVENT_BITS,
259 31);
3d1fc7fd
MD
260 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
261 /* Align extended struct on largest member */
1dbfff0c 262 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
3d1fc7fd 263 lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
1dbfff0c 264 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
3d1fc7fd
MD
265 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
266 }
267 break;
268 case 2: /* large */
269 {
7dd08bec 270 if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
3d1fc7fd
MD
271 uint32_t timestamp = (uint32_t) ctx->tsc;
272 uint16_t id = event_id;
273
274 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
1dbfff0c 275 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint32_t));
3d1fc7fd
MD
276 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
277 } else {
278 uint16_t id = 65535;
279 uint64_t timestamp = ctx->tsc;
280
281 lib_ring_buffer_write(config, ctx, &id, sizeof(id));
282 /* Align extended struct on largest member */
1dbfff0c 283 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
3d1fc7fd 284 lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
1dbfff0c 285 lib_ring_buffer_align_ctx(ctx, lttng_alignof(uint64_t));
3d1fc7fd
MD
286 lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
287 }
288 break;
289 }
290 default:
291 WARN_ON_ONCE(1);
292 }
7dd08bec
MD
293 ctx_record(ctx, lttng_chan, lttng_chan->ctx);
294 ctx_record(ctx, lttng_chan, event->ctx);
d3b2c3e0 295 lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
3d1fc7fd
MD
296}
297
4cfec15c 298static const struct lttng_ust_lib_ring_buffer_config client_config;
3d1fc7fd 299
23c8854a 300static uint64_t client_ring_buffer_clock_read(struct channel *chan)
3d1fc7fd
MD
301{
302 return lib_ring_buffer_clock_read(chan);
303}
304
305static
4cfec15c 306size_t client_record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
3d1fc7fd
MD
307 struct channel *chan, size_t offset,
308 size_t *pre_header_padding,
4cfec15c 309 struct lttng_ust_lib_ring_buffer_ctx *ctx)
3d1fc7fd
MD
310{
311 return record_header_size(config, chan, offset,
312 pre_header_padding, ctx);
313}
314
315/**
316 * client_packet_header_size - called on buffer-switch to a new sub-buffer
317 *
318 * Return header size without padding after the structure. Don't use packed
319 * structure because gcc generates inefficient code on some architectures
320 * (powerpc, mips..)
321 */
322static size_t client_packet_header_size(void)
323{
324 return offsetof(struct packet_header, ctx.header_end);
325}
326
23c8854a 327static void client_buffer_begin(struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
1d498196 328 unsigned int subbuf_idx,
38fae1d3 329 struct lttng_ust_shm_handle *handle)
3d1fc7fd 330{
1d498196 331 struct channel *chan = shmp(handle, buf->backend.chan);
3d1fc7fd
MD
332 struct packet_header *header =
333 (struct packet_header *)
334 lib_ring_buffer_offset_address(&buf->backend,
1d498196
MD
335 subbuf_idx * chan->backend.subbuf_size,
336 handle);
7dd08bec 337 struct lttng_channel *lttng_chan = channel_get_private(chan);
3d1fc7fd
MD
338
339 header->magic = CTF_MAGIC_NUMBER;
7dd08bec
MD
340 memcpy(header->uuid, lttng_chan->uuid, sizeof(lttng_chan->uuid));
341 header->stream_id = lttng_chan->id;
3d1fc7fd
MD
342 header->ctx.timestamp_begin = tsc;
343 header->ctx.timestamp_end = 0;
0c00a107
MD
344 header->ctx.content_size = ~0ULL; /* for debugging */
345 header->ctx.packet_size = ~0ULL;
3d1fc7fd 346 header->ctx.events_discarded = 0;
3d1fc7fd
MD
347 header->ctx.cpu_id = buf->backend.cpu;
348}
349
350/*
351 * offset is assumed to never be 0 here : never deliver a completely empty
352 * subbuffer. data_size is between 1 and subbuf_size.
353 */
23c8854a 354static void client_buffer_end(struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
1d498196 355 unsigned int subbuf_idx, unsigned long data_size,
38fae1d3 356 struct lttng_ust_shm_handle *handle)
3d1fc7fd 357{
1d498196 358 struct channel *chan = shmp(handle, buf->backend.chan);
3d1fc7fd
MD
359 struct packet_header *header =
360 (struct packet_header *)
361 lib_ring_buffer_offset_address(&buf->backend,
1d498196
MD
362 subbuf_idx * chan->backend.subbuf_size,
363 handle);
3d1fc7fd
MD
364 unsigned long records_lost = 0;
365
366 header->ctx.timestamp_end = tsc;
b1830883
MD
367 header->ctx.content_size =
368 (uint64_t) data_size * CHAR_BIT; /* in bits */
369 header->ctx.packet_size =
370 (uint64_t) PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
04489ab4
MD
371
372 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
3d1fc7fd
MD
373 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
374 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
375 header->ctx.events_discarded = records_lost;
376}
377
4cfec15c 378static int client_buffer_create(struct lttng_ust_lib_ring_buffer *buf, void *priv,
38fae1d3 379 int cpu, const char *name, struct lttng_ust_shm_handle *handle)
3d1fc7fd
MD
380{
381 return 0;
382}
383
4cfec15c 384static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf, void *priv, int cpu, struct lttng_ust_shm_handle *handle)
3d1fc7fd
MD
385{
386}
387
4cfec15c 388static const struct lttng_ust_lib_ring_buffer_config client_config = {
3d1fc7fd
MD
389 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
390 .cb.record_header_size = client_record_header_size,
391 .cb.subbuffer_header_size = client_packet_header_size,
392 .cb.buffer_begin = client_buffer_begin,
393 .cb.buffer_end = client_buffer_end,
394 .cb.buffer_create = client_buffer_create,
395 .cb.buffer_finalize = client_buffer_finalize,
396
79dfbf42 397 .tsc_bits = LTTNG_COMPACT_TSC_BITS,
3d1fc7fd 398 .alloc = RING_BUFFER_ALLOC_PER_CPU,
5d61a504 399 .sync = RING_BUFFER_SYNC_GLOBAL,
3d1fc7fd
MD
400 .mode = RING_BUFFER_MODE_TEMPLATE,
401 .backend = RING_BUFFER_PAGE,
5d61a504 402 .output = RING_BUFFER_MMAP,
3d1fc7fd 403 .oops = RING_BUFFER_OOPS_CONSISTENCY,
5d61a504 404 .ipi = RING_BUFFER_NO_IPI_BARRIER,
34a91bdb 405 .wakeup = LTTNG_CLIENT_WAKEUP,
c1fca457 406 .client_type = LTTNG_CLIENT_TYPE,
3d1fc7fd
MD
407};
408
7a784989 409const struct lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_config.cb;
c1fca457 410
3d1fc7fd 411static
7dd08bec 412struct lttng_channel *_channel_create(const char *name,
a3f61e7f 413 void *buf_addr,
3d1fc7fd
MD
414 size_t subbuf_size, size_t num_subbuf,
415 unsigned int switch_timer_interval,
193183fb 416 unsigned int read_timer_interval,
74d81a6c 417 unsigned char *uuid)
3d1fc7fd 418{
74d81a6c 419 struct lttng_channel chan_priv_init;
a3f61e7f 420 struct lttng_ust_shm_handle *handle;
74d81a6c
MD
421 struct lttng_channel *lttng_chan;
422 void *priv;
a3f61e7f 423
74d81a6c
MD
424 memset(&chan_priv_init, 0, sizeof(chan_priv_init));
425 memcpy(chan_priv_init.uuid, uuid, LTTNG_UST_UUID_LEN);
a3f61e7f 426 handle = channel_create(&client_config, name,
7dd08bec 427 &priv, __alignof__(*lttng_chan), sizeof(*lttng_chan),
74d81a6c 428 &chan_priv_init,
a3f61e7f 429 buf_addr, subbuf_size, num_subbuf,
74d81a6c 430 switch_timer_interval, read_timer_interval);
a3f61e7f 431 if (!handle)
afdf9825 432 return NULL;
7dd08bec
MD
433 lttng_chan = priv;
434 lttng_chan->handle = handle;
74d81a6c 435 lttng_chan->chan = shmp(handle, handle->chan);
7dd08bec 436 return lttng_chan;
3d1fc7fd
MD
437}
438
439static
74d81a6c 440void lttng_channel_destroy(struct lttng_channel *chan)
3d1fc7fd 441{
74d81a6c 442 channel_destroy(chan->chan, chan->handle, 1);
3d1fc7fd
MD
443}
444
445static
7dd08bec 446int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
3d1fc7fd
MD
447 uint32_t event_id)
448{
7dd08bec 449 struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
3d1fc7fd
MD
450 int ret, cpu;
451
452 cpu = lib_ring_buffer_get_cpu(&client_config);
453 if (cpu < 0)
454 return -EPERM;
455 ctx->cpu = cpu;
456
7dd08bec 457 switch (lttng_chan->header_type) {
3d1fc7fd
MD
458 case 1: /* compact */
459 if (event_id > 30)
7dd08bec 460 ctx->rflags |= LTTNG_RFLAG_EXTENDED;
3d1fc7fd
MD
461 break;
462 case 2: /* large */
463 if (event_id > 65534)
7dd08bec 464 ctx->rflags |= LTTNG_RFLAG_EXTENDED;
3d1fc7fd
MD
465 break;
466 default:
467 WARN_ON_ONCE(1);
468 }
469
470 ret = lib_ring_buffer_reserve(&client_config, ctx);
471 if (ret)
472 goto put;
7dd08bec 473 lttng_write_event_header(&client_config, ctx, event_id);
3d1fc7fd
MD
474 return 0;
475put:
476 lib_ring_buffer_put_cpu(&client_config);
477 return ret;
478}
479
480static
7dd08bec 481void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx *ctx)
3d1fc7fd
MD
482{
483 lib_ring_buffer_commit(&client_config, ctx);
484 lib_ring_buffer_put_cpu(&client_config);
485}
486
487static
7dd08bec 488void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
3d1fc7fd
MD
489 size_t len)
490{
491 lib_ring_buffer_write(&client_config, ctx, src, len);
492}
493
9f3fdbc6 494#if 0
3d1fc7fd 495static
7dd08bec 496wait_queue_head_t *lttng_get_reader_wait_queue(struct channel *chan)
3d1fc7fd
MD
497{
498 return &chan->read_wait;
499}
500
501static
7dd08bec 502wait_queue_head_t *lttng_get_hp_wait_queue(struct channel *chan)
3d1fc7fd
MD
503{
504 return &chan->hp_wait;
505}
9f3fdbc6 506#endif //0
3d1fc7fd
MD
507
508static
7dd08bec 509int lttng_is_finalized(struct channel *chan)
3d1fc7fd
MD
510{
511 return lib_ring_buffer_channel_is_finalized(chan);
512}
513
514static
7dd08bec 515int lttng_is_disabled(struct channel *chan)
3d1fc7fd
MD
516{
517 return lib_ring_buffer_channel_is_disabled(chan);
518}
519
43861eab 520static
7dd08bec 521int lttng_flush_buffer(struct channel *chan, struct lttng_ust_shm_handle *handle)
43861eab 522{
4cfec15c 523 struct lttng_ust_lib_ring_buffer *buf;
43861eab
MD
524 int cpu;
525
526 for_each_channel_cpu(cpu, chan) {
74d81a6c
MD
527 int shm_fd, wait_fd, wakeup_fd;
528 uint64_t memory_map_size;
43861eab
MD
529
530 buf = channel_get_ring_buffer(&client_config, chan,
531 cpu, handle, &shm_fd, &wait_fd,
74d81a6c 532 &wakeup_fd, &memory_map_size);
43861eab
MD
533 lib_ring_buffer_switch(&client_config, buf,
534 SWITCH_ACTIVE, handle);
535 }
536 return 0;
537}
538
7dd08bec 539static struct lttng_transport lttng_relay_transport = {
818173b9 540 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap",
3d1fc7fd
MD
541 .ops = {
542 .channel_create = _channel_create,
7dd08bec 543 .channel_destroy = lttng_channel_destroy,
7dd08bec
MD
544 .event_reserve = lttng_event_reserve,
545 .event_commit = lttng_event_commit,
546 .event_write = lttng_event_write,
3d1fc7fd 547 .packet_avail_size = NULL, /* Would be racy anyway */
7dd08bec
MD
548 //.get_reader_wait_queue = lttng_get_reader_wait_queue,
549 //.get_hp_wait_queue = lttng_get_hp_wait_queue,
550 .is_finalized = lttng_is_finalized,
551 .is_disabled = lttng_is_disabled,
552 .flush_buffer = lttng_flush_buffer,
3d1fc7fd 553 },
74d81a6c 554 .client_config = &client_config,
3d1fc7fd
MD
555};
556
edaa1431 557void RING_BUFFER_MODE_TEMPLATE_INIT(void)
3d1fc7fd 558{
34a91bdb
MD
559 DBG("LTT : ltt ring buffer client \"%s\" init\n",
560 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
7dd08bec 561 lttng_transport_register(&lttng_relay_transport);
3d1fc7fd
MD
562}
563
edaa1431 564void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
3d1fc7fd 565{
34a91bdb
MD
566 DBG("LTT : ltt ring buffer client \"%s\" exit\n",
567 "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
7dd08bec 568 lttng_transport_unregister(&lttng_relay_transport);
3d1fc7fd 569}
This page took 0.056573 seconds and 4 git commands to generate.