2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License only.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <lttng/ust-ctl.h>
22 #include <lttng/ust-abi.h>
23 #include <lttng/ust-events.h>
26 #include <usterr-signal-safe.h>
29 #include "../libringbuffer/backend.h"
30 #include "../libringbuffer/frontend.h"
32 volatile enum ust_loglevel ust_loglevel
;
35 void init_object(struct lttng_ust_object_data
*data
)
39 data
->shm_path
= NULL
;
41 data
->wait_pipe_path
= NULL
;
42 data
->memory_map_size
= 0;
45 int ustctl_release_handle(int sock
, int handle
)
47 struct ustcomm_ust_msg lum
;
48 struct ustcomm_ust_reply lur
;
52 memset(&lum
, 0, sizeof(lum
));
54 lum
.cmd
= LTTNG_UST_RELEASE
;
55 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
63 * If sock is negative, it means we don't have to notify the other side
64 * (e.g. application has already vanished).
66 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
73 if (data
->shm_fd
>= 0) {
74 ret
= close(data
->shm_fd
);
84 if (data
->wait_fd
>= 0) {
85 ret
= close(data
->wait_fd
);
91 if (data
->wait_pipe_path
) {
92 free(data
->wait_pipe_path
);
95 return ustctl_release_handle(sock
, data
->handle
);
99 * Send registration done packet to the application.
101 int ustctl_register_done(int sock
)
103 struct ustcomm_ust_msg lum
;
104 struct ustcomm_ust_reply lur
;
107 DBG("Sending register done command to %d", sock
);
108 memset(&lum
, 0, sizeof(lum
));
109 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
110 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
111 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
114 if (lur
.ret_code
!= USTCOMM_OK
) {
115 DBG("Return code: %s", ustcomm_get_readable_code(lur
.ret_code
));
125 * returns session handle.
127 int ustctl_create_session(int sock
)
129 struct ustcomm_ust_msg lum
;
130 struct ustcomm_ust_reply lur
;
131 int ret
, session_handle
;
134 memset(&lum
, 0, sizeof(lum
));
135 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
136 lum
.cmd
= LTTNG_UST_SESSION
;
137 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
140 session_handle
= lur
.ret_val
;
141 DBG("received session handle %u", session_handle
);
142 return session_handle
;
145 /* open the metadata global channel */
146 int ustctl_open_metadata(int sock
, int session_handle
,
147 struct lttng_ust_channel_attr
*chops
,
148 struct lttng_ust_object_data
**_metadata_data
)
150 struct ustcomm_ust_msg lum
;
151 struct ustcomm_ust_reply lur
;
152 struct lttng_ust_object_data
*metadata_data
;
154 char *shm_path
, *wait_pipe_path
;
156 if (!chops
|| !_metadata_data
)
159 metadata_data
= malloc(sizeof(*metadata_data
));
162 init_object(metadata_data
);
163 /* Create metadata channel */
164 memset(&lum
, 0, sizeof(lum
));
165 lum
.handle
= session_handle
;
166 lum
.cmd
= LTTNG_UST_METADATA
;
167 lum
.u
.channel
.overwrite
= chops
->overwrite
;
168 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
169 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
170 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
171 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
172 lum
.u
.channel
.output
= chops
->output
;
173 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
178 if (lur
.ret_code
!= USTCOMM_OK
) {
182 metadata_data
->handle
= lur
.ret_val
;
183 DBG("received metadata handle %u", metadata_data
->handle
);
184 metadata_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
186 shm_path
= ustcomm_recv_string(sock
);
190 DBG("Received shm path: %s\n", shm_path
);
191 metadata_data
->shm_fd
= -1;
192 metadata_data
->shm_path
= shm_path
;
196 * We need to get the second FD even if the first fails, because
197 * libust expects us to read the two FDs.
200 /* get wait pipe path */
201 wait_pipe_path
= ustcomm_recv_string(sock
);
202 if (!wait_pipe_path
) {
206 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
207 metadata_data
->wait_fd
= -1;
208 metadata_data
->wait_pipe_path
= wait_pipe_path
;
214 *_metadata_data
= metadata_data
;
218 (void) ustctl_release_object(sock
, metadata_data
);
223 int ustctl_create_channel(int sock
, int session_handle
,
224 struct lttng_ust_channel_attr
*chops
,
225 struct lttng_ust_object_data
**_channel_data
)
227 struct ustcomm_ust_msg lum
;
228 struct ustcomm_ust_reply lur
;
229 struct lttng_ust_object_data
*channel_data
;
231 char *shm_path
, *wait_pipe_path
;
233 if (!chops
|| !_channel_data
)
236 channel_data
= malloc(sizeof(*channel_data
));
239 init_object(channel_data
);
240 /* Create metadata channel */
241 memset(&lum
, 0, sizeof(lum
));
242 lum
.handle
= session_handle
;
243 lum
.cmd
= LTTNG_UST_CHANNEL
;
244 lum
.u
.channel
.overwrite
= chops
->overwrite
;
245 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
246 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
247 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
248 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
249 lum
.u
.channel
.output
= chops
->output
;
250 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
255 if (lur
.ret_code
!= USTCOMM_OK
) {
259 channel_data
->handle
= lur
.ret_val
;
260 DBG("received channel handle %u", channel_data
->handle
);
261 channel_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
263 shm_path
= ustcomm_recv_string(sock
);
267 DBG("Received shm path: %s\n", shm_path
);
268 channel_data
->shm_fd
= -1;
269 channel_data
->shm_path
= shm_path
;
273 * We need to get the second FD even if the first fails, because
274 * libust expects us to read the two FDs.
276 /* get wait pipe path */
277 wait_pipe_path
= ustcomm_recv_string(sock
);
278 if (!wait_pipe_path
) {
282 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
283 channel_data
->wait_fd
= -1;
284 channel_data
->wait_pipe_path
= wait_pipe_path
;
289 *_channel_data
= channel_data
;
293 (void) ustctl_release_object(sock
, channel_data
);
299 * Return -ENOENT if no more stream is available for creation.
300 * Return 0 on success.
301 * Return negative error value on error.
303 int ustctl_create_stream(int sock
, struct lttng_ust_object_data
*channel_data
,
304 struct lttng_ust_object_data
**_stream_data
)
306 struct ustcomm_ust_msg lum
;
307 struct ustcomm_ust_reply lur
;
308 struct lttng_ust_object_data
*stream_data
;
310 char *shm_path
, *wait_pipe_path
;
312 if (!channel_data
|| !_stream_data
)
315 stream_data
= malloc(sizeof(*stream_data
));
318 init_object(stream_data
);
319 memset(&lum
, 0, sizeof(lum
));
320 lum
.handle
= channel_data
->handle
;
321 lum
.cmd
= LTTNG_UST_STREAM
;
322 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
327 if (lur
.ret_code
!= USTCOMM_OK
) {
332 stream_data
->handle
= lur
.ret_val
;
333 DBG("received stream handle %u", stream_data
->handle
);
334 stream_data
->memory_map_size
= lur
.u
.stream
.memory_map_size
;
336 shm_path
= ustcomm_recv_string(sock
);
340 DBG("Received shm path: %s\n", shm_path
);
341 stream_data
->shm_fd
= -1;
342 stream_data
->shm_path
= shm_path
;
346 * We need to get the second FD even if the first fails, because
347 * libust expects us to read the two FDs.
349 /* get wait pipe path */
350 wait_pipe_path
= ustcomm_recv_string(sock
);
351 if (!wait_pipe_path
) {
355 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
356 stream_data
->wait_fd
= -1;
357 stream_data
->wait_pipe_path
= wait_pipe_path
;
362 *_stream_data
= stream_data
;
366 (void) ustctl_release_object(sock
, stream_data
);
371 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
372 struct lttng_ust_object_data
*channel_data
,
373 struct lttng_ust_object_data
**_event_data
)
375 struct ustcomm_ust_msg lum
;
376 struct ustcomm_ust_reply lur
;
377 struct lttng_ust_object_data
*event_data
;
380 if (!channel_data
|| !_event_data
)
383 event_data
= malloc(sizeof(*event_data
));
386 init_object(event_data
);
387 memset(&lum
, 0, sizeof(lum
));
388 lum
.handle
= channel_data
->handle
;
389 lum
.cmd
= LTTNG_UST_EVENT
;
390 strncpy(lum
.u
.event
.name
, ev
->name
,
391 LTTNG_UST_SYM_NAME_LEN
);
392 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
393 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
394 lum
.u
.event
.loglevel
= ev
->loglevel
;
395 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
400 event_data
->handle
= lur
.ret_val
;
401 DBG("received event handle %u", event_data
->handle
);
402 *_event_data
= event_data
;
406 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
407 struct lttng_ust_object_data
*obj_data
,
408 struct lttng_ust_object_data
**_context_data
)
410 struct ustcomm_ust_msg lum
;
411 struct ustcomm_ust_reply lur
;
412 struct lttng_ust_object_data
*context_data
;
415 if (!obj_data
|| !_context_data
)
418 context_data
= malloc(sizeof(*context_data
));
421 init_object(context_data
);
422 memset(&lum
, 0, sizeof(lum
));
423 lum
.handle
= obj_data
->handle
;
424 lum
.cmd
= LTTNG_UST_CONTEXT
;
425 lum
.u
.context
.ctx
= ctx
->ctx
;
426 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
431 context_data
->handle
= lur
.ret_val
;
432 DBG("received context handle %u", context_data
->handle
);
433 *_context_data
= context_data
;
437 /* Enable event, channel and session ioctl */
438 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
440 struct ustcomm_ust_msg lum
;
441 struct ustcomm_ust_reply lur
;
447 memset(&lum
, 0, sizeof(lum
));
448 lum
.handle
= object
->handle
;
449 lum
.cmd
= LTTNG_UST_ENABLE
;
450 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
453 DBG("enabled handle %u", object
->handle
);
457 /* Disable event, channel and session ioctl */
458 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
460 struct ustcomm_ust_msg lum
;
461 struct ustcomm_ust_reply lur
;
467 memset(&lum
, 0, sizeof(lum
));
468 lum
.handle
= object
->handle
;
469 lum
.cmd
= LTTNG_UST_DISABLE
;
470 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
473 DBG("disable handle %u", object
->handle
);
477 int ustctl_start_session(int sock
, int handle
)
479 struct lttng_ust_object_data obj
;
482 return ustctl_enable(sock
, &obj
);
485 int ustctl_stop_session(int sock
, int handle
)
487 struct lttng_ust_object_data obj
;
490 return ustctl_disable(sock
, &obj
);
493 int ustctl_tracepoint_list(int sock
)
495 struct ustcomm_ust_msg lum
;
496 struct ustcomm_ust_reply lur
;
497 int ret
, tp_list_handle
;
499 memset(&lum
, 0, sizeof(lum
));
500 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
501 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
502 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
505 tp_list_handle
= lur
.ret_val
;
506 DBG("received tracepoint list handle %u", tp_list_handle
);
507 return tp_list_handle
;
510 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
511 struct lttng_ust_tracepoint_iter
*iter
)
513 struct ustcomm_ust_msg lum
;
514 struct ustcomm_ust_reply lur
;
520 memset(&lum
, 0, sizeof(lum
));
521 lum
.handle
= tp_list_handle
;
522 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
523 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
526 DBG("received tracepoint list entry name %s loglevel %d",
527 lur
.u
.tracepoint
.name
,
528 lur
.u
.tracepoint
.loglevel
);
529 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
533 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
535 struct ustcomm_ust_msg lum
;
536 struct ustcomm_ust_reply lur
;
542 memset(&lum
, 0, sizeof(lum
));
543 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
544 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
545 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
548 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
549 DBG("received tracer version");
553 int ustctl_wait_quiescent(int sock
)
555 struct ustcomm_ust_msg lum
;
556 struct ustcomm_ust_reply lur
;
559 memset(&lum
, 0, sizeof(lum
));
560 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
561 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
562 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
565 DBG("waited for quiescent state");
569 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
577 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
579 struct ustcomm_ust_msg lum
;
580 struct ustcomm_ust_reply lur
;
586 memset(&lum
, 0, sizeof(lum
));
587 lum
.handle
= object
->handle
;
588 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
589 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
592 DBG("flushed buffer handle %u", object
->handle
);
596 /* Buffer operations */
598 /* Map channel shm into process memory */
599 struct lttng_ust_shm_handle
*ustctl_map_channel(struct lttng_ust_object_data
*chan_data
)
601 struct lttng_ust_shm_handle
*handle
;
602 struct channel
*chan
;
604 struct lttng_ust_lib_ring_buffer_config
*config
;
610 handle
= channel_handle_create(chan_data
->shm_fd
,
612 chan_data
->memory_map_size
);
614 ERR("create handle error");
618 * Set to -1, and then close the shm fd, and set the handle shm
619 * fd to -1 too. We don't need the shm fds after they have been
621 * The wait_fd is set to -1 in chan_data because it is now owned
624 chan_data
->shm_fd
= -1;
625 chan_data
->wait_fd
= -1;
627 /* chan is object 0. This is hardcoded. */
628 if (handle
->table
->objects
[0].shm_fd
>= 0) {
629 ret
= close(handle
->table
->objects
[0].shm_fd
);
631 perror("Error closing shm_fd");
633 handle
->table
->objects
[0].shm_fd
= -1;
637 * TODO: add consistency checks to be resilient if the
638 * application try to feed us with incoherent channel structure
641 chan
= shmp(handle
, handle
->chan
);
642 /* chan is object 0. This is hardcoded. */
643 chan_size
= handle
->table
->objects
[0].allocated_len
;
644 handle
->shadow_chan
= malloc(chan_size
);
645 if (!handle
->shadow_chan
) {
646 channel_destroy(chan
, handle
, 1);
649 memcpy(handle
->shadow_chan
, chan
, chan_size
);
651 * The callback pointers in the producer are invalid in the
652 * consumer. We need to look them up here.
654 config
= &handle
->shadow_chan
->backend
.config
;
655 switch (config
->client_type
) {
656 case LTTNG_CLIENT_METADATA
:
657 memcpy(&config
->cb
, lttng_client_callbacks_metadata
,
660 case LTTNG_CLIENT_DISCARD
:
661 memcpy(&config
->cb
, lttng_client_callbacks_discard
,
664 case LTTNG_CLIENT_OVERWRITE
:
665 memcpy(&config
->cb
, lttng_client_callbacks_overwrite
,
669 ERR("Unknown client type %d", config
->client_type
);
670 channel_destroy(chan
, handle
, 1);
673 /* Replace the object table pointer. */
674 ret
= munmap(handle
->table
->objects
[0].memory_map
,
675 handle
->table
->objects
[0].memory_map_size
);
680 handle
->table
->objects
[0].memory_map
= (char *) handle
->shadow_chan
;
681 handle
->table
->objects
[0].is_shadow
= 1;
685 /* Add stream to channel shm and map its shm into process memory */
686 int ustctl_add_stream(struct lttng_ust_shm_handle
*handle
,
687 struct lttng_ust_object_data
*stream_data
)
691 if (!handle
|| !stream_data
)
694 if (!stream_data
->handle
)
697 ret
= channel_handle_add_stream(handle
,
699 stream_data
->wait_fd
,
700 stream_data
->memory_map_size
);
702 ERR("add stream error\n");
706 * Set to -1 because the lttng_ust_shm_handle destruction will take care
707 * of closing shm_fd and wait_fd.
709 stream_data
->shm_fd
= -1;
710 stream_data
->wait_fd
= -1;
714 void ustctl_unmap_channel(struct lttng_ust_shm_handle
*handle
)
716 struct channel
*chan
;
719 chan
= shmp(handle
, handle
->chan
);
720 channel_destroy(chan
, handle
, 1);
724 * ustctl closes the shm_fd fds after mapping it.
726 struct lttng_ust_lib_ring_buffer
*ustctl_open_stream_read(struct lttng_ust_shm_handle
*handle
,
729 struct channel
*chan
;
730 int *shm_fd
, *wait_fd
;
731 char *shm_path
, *wait_pipe_path
;
732 uint64_t *memory_map_size
;
733 struct lttng_ust_lib_ring_buffer
*buf
;
739 chan
= handle
->shadow_chan
;
740 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
743 &wait_fd
, &wait_pipe_path
,
747 ret
= lib_ring_buffer_open_read(buf
, handle
, 1);
751 * We can close shm_fd early, right after is has been mapped.
754 ret
= close(*shm_fd
);
756 perror("Error closing shm_fd");
763 void ustctl_close_stream_read(struct lttng_ust_shm_handle
*handle
,
764 struct lttng_ust_lib_ring_buffer
*buf
)
766 assert(handle
&& buf
);
767 lib_ring_buffer_release_read(buf
, handle
, 1);
770 /* For mmap mode, readable without "get" operation */
772 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle
*handle
,
773 struct lttng_ust_lib_ring_buffer
*buf
)
777 return shmp(handle
, buf
->backend
.memory_map
);
780 /* returns the length to mmap. */
781 int ustctl_get_mmap_len(struct lttng_ust_shm_handle
*handle
,
782 struct lttng_ust_lib_ring_buffer
*buf
,
785 unsigned long mmap_buf_len
;
786 struct channel
*chan
;
788 if (!handle
|| !buf
|| !len
)
791 chan
= handle
->shadow_chan
;
792 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
794 mmap_buf_len
= chan
->backend
.buf_size
;
795 if (chan
->backend
.extra_reader_sb
)
796 mmap_buf_len
+= chan
->backend
.subbuf_size
;
797 if (mmap_buf_len
> INT_MAX
)
803 /* returns the maximum size for sub-buffers. */
804 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle
*handle
,
805 struct lttng_ust_lib_ring_buffer
*buf
,
808 struct channel
*chan
;
810 if (!handle
|| !buf
|| !len
)
813 chan
= handle
->shadow_chan
;
814 *len
= chan
->backend
.subbuf_size
;
819 * For mmap mode, operate on the current packet (between get/put or
820 * get_next/put_next).
823 /* returns the offset of the subbuffer belonging to the mmap reader. */
824 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle
*handle
,
825 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *off
)
827 struct channel
*chan
;
828 unsigned long sb_bindex
;
830 if (!handle
|| !buf
|| !off
)
833 chan
= handle
->shadow_chan
;
834 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
836 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
837 buf
->backend
.buf_rsb
.id
);
838 *off
= shmp(handle
, shmp_index(handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
842 /* returns the size of the current sub-buffer, without padding (for mmap). */
843 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle
*handle
,
844 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
846 struct channel
*chan
;
848 if (!handle
|| !buf
|| !len
)
851 chan
= handle
->shadow_chan
;
852 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
857 /* returns the size of the current sub-buffer, without padding (for mmap). */
858 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle
*handle
,
859 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
861 struct channel
*chan
;
863 if (!handle
|| !buf
|| !len
)
866 chan
= handle
->shadow_chan
;
867 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
869 *len
= PAGE_ALIGN(*len
);
873 /* Get exclusive read access to the next sub-buffer that can be read. */
874 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle
*handle
,
875 struct lttng_ust_lib_ring_buffer
*buf
)
880 return lib_ring_buffer_get_next_subbuf(buf
, handle
);
884 /* Release exclusive sub-buffer access, move consumer forward. */
885 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle
*handle
,
886 struct lttng_ust_lib_ring_buffer
*buf
)
891 lib_ring_buffer_put_next_subbuf(buf
, handle
);
897 /* Get a snapshot of the current ring buffer producer and consumer positions */
898 int ustctl_snapshot(struct lttng_ust_shm_handle
*handle
,
899 struct lttng_ust_lib_ring_buffer
*buf
)
904 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
905 &buf
->prod_snapshot
, handle
);
908 /* Get the consumer position (iteration start) */
909 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle
*handle
,
910 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
912 if (!handle
|| !buf
|| !pos
)
915 *pos
= buf
->cons_snapshot
;
919 /* Get the producer position (iteration end) */
920 int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle
*handle
,
921 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
923 if (!handle
|| !buf
|| !pos
)
926 *pos
= buf
->prod_snapshot
;
930 /* Get exclusive read access to the specified sub-buffer position */
931 int ustctl_get_subbuf(struct lttng_ust_shm_handle
*handle
,
932 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
934 if (!handle
|| !buf
|| !pos
)
937 return lib_ring_buffer_get_subbuf(buf
, *pos
, handle
);
940 /* Release exclusive sub-buffer access */
941 int ustctl_put_subbuf(struct lttng_ust_shm_handle
*handle
,
942 struct lttng_ust_lib_ring_buffer
*buf
)
947 lib_ring_buffer_put_subbuf(buf
, handle
);
951 void ustctl_flush_buffer(struct lttng_ust_shm_handle
*handle
,
952 struct lttng_ust_lib_ring_buffer
*buf
,
955 assert(handle
&& buf
);
956 lib_ring_buffer_switch_slow(buf
,
957 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,