Add sock flush buffer ctl API
[lttng-ust.git] / liblttng-ust-ctl / ustctl.c
1 /*
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
8 * of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #include <string.h>
21 #include <lttng/ust-ctl.h>
22 #include <lttng/ust-abi.h>
23 #include <lttng/ust-events.h>
24 #include <sys/mman.h>
25
26 #include <usterr-signal-safe.h>
27 #include <ust-comm.h>
28
29 #include "../libringbuffer/backend.h"
30 #include "../libringbuffer/frontend.h"
31
32 volatile enum ust_loglevel ust_loglevel;
33
34 static
35 void init_object(struct lttng_ust_object_data *data)
36 {
37 data->handle = -1;
38 data->shm_fd = -1;
39 data->wait_fd = -1;
40 data->memory_map_size = 0;
41 }
42
43 /*
44 * If sock is negative, it means we don't have to notify the other side
45 * (e.g. application has already vanished).
46 */
47 int ustctl_release_object(int sock, struct lttng_ust_object_data *data)
48 {
49 struct ustcomm_ust_msg lum;
50 struct ustcomm_ust_reply lur;
51 int ret;
52
53 if (data->shm_fd >= 0) {
54 ret = close(data->shm_fd);
55 if (ret < 0) {
56 return ret;
57 }
58 }
59 if (data->wait_fd >= 0) {
60 ret = close(data->wait_fd);
61 if (ret < 0) {
62 return ret;
63 }
64 }
65 if (sock >= 0) {
66 memset(&lum, 0, sizeof(lum));
67 lum.handle = data->handle;
68 lum.cmd = LTTNG_UST_RELEASE;
69 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
70 if (ret < 0) {
71 return ret;
72 }
73 }
74 return 0;
75 }
76
77 /*
78 * Send registration done packet to the application.
79 */
80 int ustctl_register_done(int sock)
81 {
82 struct ustcomm_ust_msg lum;
83 struct ustcomm_ust_reply lur;
84 int ret;
85
86 DBG("Sending register done command to %d", sock);
87 memset(&lum, 0, sizeof(lum));
88 lum.handle = LTTNG_UST_ROOT_HANDLE;
89 lum.cmd = LTTNG_UST_REGISTER_DONE;
90 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
91 if (ret)
92 return ret;
93 if (lur.ret_code != USTCOMM_OK) {
94 DBG("Return code: %s", ustcomm_get_readable_code(lur.ret_code));
95 goto error;
96 }
97 return 0;
98
99 error:
100 return -1;
101 }
102
103 /*
104 * returns session handle.
105 */
106 int ustctl_create_session(int sock)
107 {
108 struct ustcomm_ust_msg lum;
109 struct ustcomm_ust_reply lur;
110 int ret, session_handle;
111
112 /* Create session */
113 memset(&lum, 0, sizeof(lum));
114 lum.handle = LTTNG_UST_ROOT_HANDLE;
115 lum.cmd = LTTNG_UST_SESSION;
116 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
117 if (ret)
118 return ret;
119 session_handle = lur.ret_val;
120 DBG("received session handle %u", session_handle);
121 return session_handle;
122 }
123
124 /* open the metadata global channel */
125 int ustctl_open_metadata(int sock, int session_handle,
126 struct lttng_ust_channel_attr *chops,
127 struct lttng_ust_object_data **_metadata_data)
128 {
129 struct ustcomm_ust_msg lum;
130 struct ustcomm_ust_reply lur;
131 struct lttng_ust_object_data *metadata_data;
132 int ret;
133
134 metadata_data = malloc(sizeof(*metadata_data));
135 if (!metadata_data)
136 return -ENOMEM;
137 init_object(metadata_data);
138 /* Create metadata channel */
139 memset(&lum, 0, sizeof(lum));
140 lum.handle = session_handle;
141 lum.cmd = LTTNG_UST_METADATA;
142 lum.u.channel.overwrite = chops->overwrite;
143 lum.u.channel.subbuf_size = chops->subbuf_size;
144 lum.u.channel.num_subbuf = chops->num_subbuf;
145 lum.u.channel.switch_timer_interval = chops->switch_timer_interval;
146 lum.u.channel.read_timer_interval = chops->read_timer_interval;
147 lum.u.channel.output = chops->output;
148 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
149 if (ret) {
150 free(metadata_data);
151 return ret;
152 }
153 if (lur.ret_code != USTCOMM_OK) {
154 free(metadata_data);
155 return lur.ret_code;
156 }
157 metadata_data->handle = lur.ret_val;
158 DBG("received metadata handle %u", metadata_data->handle);
159 metadata_data->memory_map_size = lur.u.channel.memory_map_size;
160 /* get shm fd */
161 ret = ustcomm_recv_fd(sock);
162 if (ret < 0)
163 goto error;
164 metadata_data->shm_fd = ret;
165 /* get wait fd */
166 ret = ustcomm_recv_fd(sock);
167 if (ret < 0)
168 goto error;
169 metadata_data->wait_fd = ret;
170 *_metadata_data = metadata_data;
171 return 0;
172
173 error:
174 (void) ustctl_release_object(sock, metadata_data);
175 free(metadata_data);
176 return -EINVAL;
177 }
178
179 int ustctl_create_channel(int sock, int session_handle,
180 struct lttng_ust_channel_attr *chops,
181 struct lttng_ust_object_data **_channel_data)
182 {
183 struct ustcomm_ust_msg lum;
184 struct ustcomm_ust_reply lur;
185 struct lttng_ust_object_data *channel_data;
186 int ret;
187
188 channel_data = malloc(sizeof(*channel_data));
189 if (!channel_data)
190 return -ENOMEM;
191 init_object(channel_data);
192 /* Create metadata channel */
193 memset(&lum, 0, sizeof(lum));
194 lum.handle = session_handle;
195 lum.cmd = LTTNG_UST_CHANNEL;
196 lum.u.channel.overwrite = chops->overwrite;
197 lum.u.channel.subbuf_size = chops->subbuf_size;
198 lum.u.channel.num_subbuf = chops->num_subbuf;
199 lum.u.channel.switch_timer_interval = chops->switch_timer_interval;
200 lum.u.channel.read_timer_interval = chops->read_timer_interval;
201 lum.u.channel.output = chops->output;
202 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
203 if (ret) {
204 free(channel_data);
205 return ret;
206 }
207 if (lur.ret_code != USTCOMM_OK) {
208 free(channel_data);
209 return lur.ret_code;
210 }
211 channel_data->handle = lur.ret_val;
212 DBG("received channel handle %u", channel_data->handle);
213 channel_data->memory_map_size = lur.u.channel.memory_map_size;
214 /* get shm fd */
215 ret = ustcomm_recv_fd(sock);
216 if (ret < 0)
217 goto error;
218 channel_data->shm_fd = ret;
219 /* get wait fd */
220 ret = ustcomm_recv_fd(sock);
221 if (ret < 0)
222 goto error;
223 channel_data->wait_fd = ret;
224 *_channel_data = channel_data;
225 return 0;
226
227 error:
228 (void) ustctl_release_object(sock, channel_data);
229 free(channel_data);
230 return -EINVAL;
231 }
232
233 /*
234 * Return -ENOENT if no more stream is available for creation.
235 * Return 0 on success.
236 * Return negative error value on error.
237 */
238 int ustctl_create_stream(int sock, struct lttng_ust_object_data *channel_data,
239 struct lttng_ust_object_data **_stream_data)
240 {
241 struct ustcomm_ust_msg lum;
242 struct ustcomm_ust_reply lur;
243 struct lttng_ust_object_data *stream_data;
244 int ret, fd;
245
246 stream_data = malloc(sizeof(*stream_data));
247 if (!stream_data)
248 return -ENOMEM;
249 init_object(stream_data);
250 memset(&lum, 0, sizeof(lum));
251 lum.handle = channel_data->handle;
252 lum.cmd = LTTNG_UST_STREAM;
253 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
254 if (ret) {
255 free(stream_data);
256 return ret;
257 }
258 if (lur.ret_code != USTCOMM_OK) {
259 free(stream_data);
260 return lur.ret_code;
261 }
262
263 stream_data->handle = lur.ret_val;
264 DBG("received stream handle %u", stream_data->handle);
265 stream_data->memory_map_size = lur.u.stream.memory_map_size;
266 /* get shm fd */
267 fd = ustcomm_recv_fd(sock);
268 if (fd < 0)
269 goto error;
270 stream_data->shm_fd = fd;
271 /* get wait fd */
272 fd = ustcomm_recv_fd(sock);
273 if (fd < 0)
274 goto error;
275 stream_data->wait_fd = fd;
276 *_stream_data = stream_data;
277 return ret;
278
279 error:
280 (void) ustctl_release_object(sock, stream_data);
281 free(stream_data);
282 return -EINVAL;
283 }
284
285 int ustctl_create_event(int sock, struct lttng_ust_event *ev,
286 struct lttng_ust_object_data *channel_data,
287 struct lttng_ust_object_data **_event_data)
288 {
289 struct ustcomm_ust_msg lum;
290 struct ustcomm_ust_reply lur;
291 struct lttng_ust_object_data *event_data;
292 int ret;
293
294 event_data = malloc(sizeof(*event_data));
295 if (!event_data)
296 return -ENOMEM;
297 init_object(event_data);
298 memset(&lum, 0, sizeof(lum));
299 lum.handle = channel_data->handle;
300 lum.cmd = LTTNG_UST_EVENT;
301 strncpy(lum.u.event.name, ev->name,
302 LTTNG_UST_SYM_NAME_LEN);
303 lum.u.event.instrumentation = ev->instrumentation;
304 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
305 if (ret) {
306 free(event_data);
307 return ret;
308 }
309 event_data->handle = lur.ret_val;
310 DBG("received event handle %u", event_data->handle);
311 *_event_data = event_data;
312 return 0;
313 }
314
315 int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
316 struct lttng_ust_object_data *obj_data,
317 struct lttng_ust_object_data **_context_data)
318 {
319 struct ustcomm_ust_msg lum;
320 struct ustcomm_ust_reply lur;
321 struct lttng_ust_object_data *context_data;
322 int ret;
323
324 context_data = malloc(sizeof(*context_data));
325 if (!context_data)
326 return -ENOMEM;
327 init_object(context_data);
328 memset(&lum, 0, sizeof(lum));
329 lum.handle = obj_data->handle;
330 lum.cmd = LTTNG_UST_CONTEXT;
331 lum.u.context.ctx = ctx->ctx;
332 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
333 if (ret) {
334 free(context_data);
335 return ret;
336 }
337 context_data->handle = lur.ret_val;
338 DBG("received context handle %u", context_data->handle);
339 *_context_data = context_data;
340 return ret;
341 }
342
343 /* Enable event, channel and session ioctl */
344 int ustctl_enable(int sock, struct lttng_ust_object_data *object)
345 {
346 struct ustcomm_ust_msg lum;
347 struct ustcomm_ust_reply lur;
348 int ret;
349
350 memset(&lum, 0, sizeof(lum));
351 lum.handle = object->handle;
352 lum.cmd = LTTNG_UST_ENABLE;
353 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
354 if (ret)
355 return ret;
356 DBG("enabled handle %u", object->handle);
357 return 0;
358 }
359
360 /* Disable event, channel and session ioctl */
361 int ustctl_disable(int sock, struct lttng_ust_object_data *object)
362 {
363 struct ustcomm_ust_msg lum;
364 struct ustcomm_ust_reply lur;
365 int ret;
366
367 memset(&lum, 0, sizeof(lum));
368 lum.handle = object->handle;
369 lum.cmd = LTTNG_UST_DISABLE;
370 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
371 if (ret)
372 return ret;
373 DBG("disable handle %u", object->handle);
374 return 0;
375 }
376
377 int ustctl_start_session(int sock, int handle)
378 {
379 struct lttng_ust_object_data obj;
380
381 obj.handle = handle;
382 return ustctl_enable(sock, &obj);
383 }
384
385 int ustctl_stop_session(int sock, int handle)
386 {
387 struct lttng_ust_object_data obj;
388
389 obj.handle = handle;
390 return ustctl_disable(sock, &obj);
391 }
392
393 int ustctl_tracepoint_list(int sock)
394 {
395 struct ustcomm_ust_msg lum;
396 struct ustcomm_ust_reply lur;
397 int ret, tp_list_handle;
398
399 memset(&lum, 0, sizeof(lum));
400 lum.handle = LTTNG_UST_ROOT_HANDLE;
401 lum.cmd = LTTNG_UST_TRACEPOINT_LIST;
402 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
403 if (ret)
404 return ret;
405 tp_list_handle = lur.ret_val;
406 DBG("received tracepoint list handle %u", tp_list_handle);
407 return tp_list_handle;
408 }
409
410 int ustctl_tracepoint_list_get(int sock, int tp_list_handle,
411 struct lttng_ust_tracepoint_iter *iter)
412 {
413 struct ustcomm_ust_msg lum;
414 struct ustcomm_ust_reply lur;
415 int ret;
416
417 memset(&lum, 0, sizeof(lum));
418 lum.handle = tp_list_handle;
419 lum.cmd = LTTNG_UST_TRACEPOINT_LIST_GET;
420 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
421 if (ret)
422 return ret;
423 DBG("received tracepoint list entry name %s loglevel %s loglevel_value %lld",
424 lur.u.tracepoint.name,
425 lur.u.tracepoint.loglevel,
426 (unsigned long long) lur.u.tracepoint.loglevel_value);
427 memcpy(iter, &lur.u.tracepoint, sizeof(*iter));
428 return 0;
429 }
430
431 int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v)
432 {
433 struct ustcomm_ust_msg lum;
434 struct ustcomm_ust_reply lur;
435 int ret;
436
437 memset(&lum, 0, sizeof(lum));
438 lum.handle = LTTNG_UST_ROOT_HANDLE;
439 lum.cmd = LTTNG_UST_TRACER_VERSION;
440 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
441 if (ret)
442 return ret;
443 memcpy(v, &lur.u.version, sizeof(*v));
444 DBG("received tracer version");
445 return 0;
446 }
447
448 int ustctl_wait_quiescent(int sock)
449 {
450 struct ustcomm_ust_msg lum;
451 struct ustcomm_ust_reply lur;
452 int ret;
453
454 memset(&lum, 0, sizeof(lum));
455 lum.handle = LTTNG_UST_ROOT_HANDLE;
456 lum.cmd = LTTNG_UST_WAIT_QUIESCENT;
457 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
458 if (ret)
459 return ret;
460 DBG("waited for quiescent state");
461 return 0;
462 }
463
464 int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate)
465 {
466 return -ENOSYS;
467 }
468
469 int ustctl_sock_flush_buffer(int sock, struct lttng_ust_object_data *object)
470 {
471 struct ustcomm_ust_msg lum;
472 struct ustcomm_ust_reply lur;
473 int ret;
474
475 memset(&lum, 0, sizeof(lum));
476 lum.handle = object->handle;
477 lum.cmd = LTTNG_UST_FLUSH_BUFFER;
478 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
479 if (ret)
480 return ret;
481 DBG("flushed buffer handle %u", object->handle);
482 return 0;
483 }
484
485 /* Buffer operations */
486
487 /* Map channel shm into process memory */
488 struct lttng_ust_shm_handle *ustctl_map_channel(struct lttng_ust_object_data *chan_data)
489 {
490 struct lttng_ust_shm_handle *handle;
491 struct channel *chan;
492 size_t chan_size;
493 struct lttng_ust_lib_ring_buffer_config *config;
494 int ret;
495
496 handle = channel_handle_create(chan_data->shm_fd,
497 chan_data->wait_fd,
498 chan_data->memory_map_size);
499 if (!handle) {
500 ERR("create handle error");
501 return NULL;
502 }
503 /*
504 * Set to -1 because the lttng_ust_shm_handle destruction will take care
505 * of closing shm_fd and wait_fd.
506 */
507 chan_data->shm_fd = -1;
508 chan_data->wait_fd = -1;
509
510 /*
511 * TODO: add consistency checks to be resilient if the
512 * application try to feed us with incoherent channel structure
513 * values.
514 */
515 chan = shmp(handle, handle->chan);
516 /* chan is object 0. This is hardcoded. */
517 chan_size = handle->table->objects[0].allocated_len;
518 handle->shadow_chan = malloc(chan_size);
519 if (!handle->shadow_chan) {
520 channel_destroy(chan, handle, 1);
521 return NULL;
522 }
523 memcpy(handle->shadow_chan, chan, chan_size);
524 /*
525 * The callback pointers in the producer are invalid in the
526 * consumer. We need to look them up here.
527 */
528 config = &handle->shadow_chan->backend.config;
529 switch (config->client_type) {
530 case LTTNG_CLIENT_METADATA:
531 memcpy(&config->cb, lttng_client_callbacks_metadata,
532 sizeof(config->cb));
533 break;
534 case LTTNG_CLIENT_DISCARD:
535 memcpy(&config->cb, lttng_client_callbacks_discard,
536 sizeof(config->cb));
537 break;
538 case LTTNG_CLIENT_OVERWRITE:
539 memcpy(&config->cb, lttng_client_callbacks_overwrite,
540 sizeof(config->cb));
541 break;
542 default:
543 ERR("Unknown client type %d", config->client_type);
544 channel_destroy(chan, handle, 1);
545 return NULL;
546 }
547 /* Replace the object table pointer. */
548 ret = munmap(handle->table->objects[0].memory_map,
549 handle->table->objects[0].memory_map_size);
550 if (ret) {
551 perror("munmap");
552 assert(0);
553 }
554 handle->table->objects[0].memory_map = (char *) handle->shadow_chan;
555 handle->table->objects[0].is_shadow = 1;
556 return handle;
557 }
558
559 /* Add stream to channel shm and map its shm into process memory */
560 int ustctl_add_stream(struct lttng_ust_shm_handle *handle,
561 struct lttng_ust_object_data *stream_data)
562 {
563 int ret;
564
565 if (!stream_data->handle)
566 return -ENOENT;
567 /* map stream */
568 ret = channel_handle_add_stream(handle,
569 stream_data->shm_fd,
570 stream_data->wait_fd,
571 stream_data->memory_map_size);
572 if (ret) {
573 ERR("add stream error\n");
574 return ret;
575 }
576 /*
577 * Set to -1 because the lttng_ust_shm_handle destruction will take care
578 * of closing shm_fd and wait_fd.
579 */
580 stream_data->shm_fd = -1;
581 stream_data->wait_fd = -1;
582 return 0;
583 }
584
585 void ustctl_unmap_channel(struct lttng_ust_shm_handle *handle)
586 {
587 struct channel *chan;
588
589 chan = shmp(handle, handle->chan);
590 channel_destroy(chan, handle, 1);
591 }
592
593 struct lttng_ust_lib_ring_buffer *ustctl_open_stream_read(struct lttng_ust_shm_handle *handle,
594 int cpu)
595 {
596 struct channel *chan = handle->shadow_chan;
597 int shm_fd, wait_fd;
598 uint64_t memory_map_size;
599 struct lttng_ust_lib_ring_buffer *buf;
600 int ret;
601
602 buf = channel_get_ring_buffer(&chan->backend.config,
603 chan, cpu, handle, &shm_fd, &wait_fd, &memory_map_size);
604 if (!buf)
605 return NULL;
606 ret = lib_ring_buffer_open_read(buf, handle, 1);
607 if (ret)
608 return NULL;
609 return buf;
610 }
611
612 void ustctl_close_stream_read(struct lttng_ust_shm_handle *handle,
613 struct lttng_ust_lib_ring_buffer *buf)
614 {
615 lib_ring_buffer_release_read(buf, handle, 1);
616 }
617
618 /* For mmap mode, readable without "get" operation */
619
620 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle *handle,
621 struct lttng_ust_lib_ring_buffer *buf)
622 {
623 return shmp(handle, buf->backend.memory_map);
624 }
625
626 /* returns the length to mmap. */
627 int ustctl_get_mmap_len(struct lttng_ust_shm_handle *handle,
628 struct lttng_ust_lib_ring_buffer *buf,
629 unsigned long *len)
630 {
631 unsigned long mmap_buf_len;
632 struct channel *chan = handle->shadow_chan;
633
634 if (chan->backend.config.output != RING_BUFFER_MMAP)
635 return -EINVAL;
636 mmap_buf_len = chan->backend.buf_size;
637 if (chan->backend.extra_reader_sb)
638 mmap_buf_len += chan->backend.subbuf_size;
639 if (mmap_buf_len > INT_MAX)
640 return -EFBIG;
641 *len = mmap_buf_len;
642 return 0;
643 }
644
645 /* returns the maximum size for sub-buffers. */
646 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle *handle,
647 struct lttng_ust_lib_ring_buffer *buf,
648 unsigned long *len)
649 {
650 struct channel *chan = handle->shadow_chan;
651
652 *len = chan->backend.subbuf_size;
653 return 0;
654 }
655
656 /*
657 * For mmap mode, operate on the current packet (between get/put or
658 * get_next/put_next).
659 */
660
661 /* returns the offset of the subbuffer belonging to the mmap reader. */
662 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle *handle,
663 struct lttng_ust_lib_ring_buffer *buf, unsigned long *off)
664 {
665 struct channel *chan = handle->shadow_chan;
666 unsigned long sb_bindex;
667
668 if (chan->backend.config.output != RING_BUFFER_MMAP)
669 return -EINVAL;
670 sb_bindex = subbuffer_id_get_index(&chan->backend.config,
671 buf->backend.buf_rsb.id);
672 *off = shmp(handle, shmp_index(handle, buf->backend.array, sb_bindex)->shmp)->mmap_offset;
673 return 0;
674 }
675
676 /* returns the size of the current sub-buffer, without padding (for mmap). */
677 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle *handle,
678 struct lttng_ust_lib_ring_buffer *buf, unsigned long *len)
679 {
680 struct channel *chan = handle->shadow_chan;
681
682 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
683 handle);
684 return 0;
685 }
686
687 /* returns the size of the current sub-buffer, without padding (for mmap). */
688 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle *handle,
689 struct lttng_ust_lib_ring_buffer *buf, unsigned long *len)
690 {
691 struct channel *chan = handle->shadow_chan;
692
693 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
694 handle);
695 *len = PAGE_ALIGN(*len);
696 return 0;
697 }
698
699 /* Get exclusive read access to the next sub-buffer that can be read. */
700 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle *handle,
701 struct lttng_ust_lib_ring_buffer *buf)
702 {
703 return lib_ring_buffer_get_next_subbuf(buf, handle);
704 }
705
706
707 /* Release exclusive sub-buffer access, move consumer forward. */
708 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle *handle,
709 struct lttng_ust_lib_ring_buffer *buf)
710 {
711 lib_ring_buffer_put_next_subbuf(buf, handle);
712 return 0;
713 }
714
715 /* snapshot */
716
717 /* Get a snapshot of the current ring buffer producer and consumer positions */
718 int ustctl_snapshot(struct lttng_ust_shm_handle *handle,
719 struct lttng_ust_lib_ring_buffer *buf)
720 {
721 return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
722 &buf->prod_snapshot, handle);
723 }
724
725 /* Get the consumer position (iteration start) */
726 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle *handle,
727 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
728 {
729 *pos = buf->cons_snapshot;
730 return 0;
731 }
732
733 /* Get the producer position (iteration end) */
734 int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle *handle,
735 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
736 {
737 *pos = buf->prod_snapshot;
738 return 0;
739 }
740
741 /* Get exclusive read access to the specified sub-buffer position */
742 int ustctl_get_subbuf(struct lttng_ust_shm_handle *handle,
743 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
744 {
745 return lib_ring_buffer_get_subbuf(buf, *pos, handle);
746 }
747
748 /* Release exclusive sub-buffer access */
749 int ustctl_put_subbuf(struct lttng_ust_shm_handle *handle,
750 struct lttng_ust_lib_ring_buffer *buf)
751 {
752 lib_ring_buffer_put_subbuf(buf, handle);
753 return 0;
754 }
755
756 void ustctl_flush_buffer(struct lttng_ust_shm_handle *handle,
757 struct lttng_ust_lib_ring_buffer *buf,
758 int producer_active)
759 {
760 lib_ring_buffer_switch_slow(buf,
761 producer_active ? SWITCH_ACTIVE : SWITCH_FLUSH,
762 handle);
763 }
This page took 0.044837 seconds and 5 git commands to generate.