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
;
34 static int dummy_pipe
[2];
37 void __attribute__((constructor
)) setup_dummy_pipe(void)
40 /* Only dummy_pipe[0] is used */
42 /* FIXME: Handle pipe() failure */
46 inline int get_dummy_fd(void)
48 return dup(dummy_pipe
[0]);
52 void init_object(struct lttng_ust_object_data
*data
)
56 data
->shm_path
= NULL
;
58 data
->wait_pipe_path
= NULL
;
59 data
->memory_map_size
= 0;
62 int ustctl_release_handle(int sock
, int handle
)
64 struct ustcomm_ust_msg lum
;
65 struct ustcomm_ust_reply lur
;
69 memset(&lum
, 0, sizeof(lum
));
71 lum
.cmd
= LTTNG_UST_RELEASE
;
72 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
80 * If sock is negative, it means we don't have to notify the other side
81 * (e.g. application has already vanished).
83 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
90 if (data
->shm_fd
>= 0) {
91 ret
= close(data
->shm_fd
);
101 if (data
->wait_fd
>= 0) {
102 ret
= close(data
->wait_fd
);
108 if (data
->wait_pipe_path
) {
109 free(data
->wait_pipe_path
);
112 return ustctl_release_handle(sock
, data
->handle
);
116 * Send registration done packet to the application.
118 int ustctl_register_done(int sock
)
120 struct ustcomm_ust_msg lum
;
121 struct ustcomm_ust_reply lur
;
124 DBG("Sending register done command to %d", sock
);
125 memset(&lum
, 0, sizeof(lum
));
126 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
127 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
128 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
131 if (lur
.ret_code
!= USTCOMM_OK
) {
132 DBG("Return code: %s", ustcomm_get_readable_code(lur
.ret_code
));
142 * returns session handle.
144 int ustctl_create_session(int sock
)
146 struct ustcomm_ust_msg lum
;
147 struct ustcomm_ust_reply lur
;
148 int ret
, session_handle
;
151 memset(&lum
, 0, sizeof(lum
));
152 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
153 lum
.cmd
= LTTNG_UST_SESSION
;
154 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
157 session_handle
= lur
.ret_val
;
158 DBG("received session handle %u", session_handle
);
159 return session_handle
;
162 /* open the metadata global channel */
163 int ustctl_open_metadata(int sock
, int session_handle
,
164 struct lttng_ust_channel_attr
*chops
,
165 struct lttng_ust_object_data
**_metadata_data
)
167 struct ustcomm_ust_msg lum
;
168 struct ustcomm_ust_reply lur
;
169 struct lttng_ust_object_data
*metadata_data
;
171 char *shm_path
, *wait_pipe_path
;
173 if (!chops
|| !_metadata_data
)
176 metadata_data
= malloc(sizeof(*metadata_data
));
179 init_object(metadata_data
);
180 /* Create metadata channel */
181 memset(&lum
, 0, sizeof(lum
));
182 lum
.handle
= session_handle
;
183 lum
.cmd
= LTTNG_UST_METADATA
;
184 lum
.u
.channel
.overwrite
= chops
->overwrite
;
185 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
186 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
187 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
188 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
189 lum
.u
.channel
.output
= chops
->output
;
190 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
195 if (lur
.ret_code
!= USTCOMM_OK
) {
199 metadata_data
->handle
= lur
.ret_val
;
200 DBG("received metadata handle %u", metadata_data
->handle
);
201 metadata_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
203 shm_path
= ustcomm_recv_string(sock
);
207 DBG("Received shm path: %s\n", shm_path
);
208 metadata_data
->shm_fd
= get_dummy_fd();
209 metadata_data
->shm_path
= shm_path
;
213 * We need to get the second FD even if the first fails, because
214 * libust expects us to read the two FDs.
217 /* get wait pipe path */
218 wait_pipe_path
= ustcomm_recv_string(sock
);
219 if (!wait_pipe_path
) {
223 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
224 metadata_data
->wait_fd
= get_dummy_fd();
225 metadata_data
->wait_pipe_path
= wait_pipe_path
;
231 *_metadata_data
= metadata_data
;
235 (void) ustctl_release_object(sock
, metadata_data
);
240 int ustctl_open_wait_pipe(int sock
,
241 struct lttng_ust_object_data
*channel_data
)
243 struct ustcomm_ust_msg lum
;
244 struct ustcomm_ust_reply lur
;
250 /* Create metadata channel */
251 memset(&lum
, 0, sizeof(lum
));
252 lum
.handle
= channel_data
->handle
;
253 lum
.cmd
= LTTNG_UST_STREAM_PIPE
;
254 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
259 if (lur
.ret_code
!= USTCOMM_OK
) {
270 int ustctl_create_channel(int sock
, int session_handle
,
271 struct lttng_ust_channel_attr
*chops
,
272 struct lttng_ust_object_data
**_channel_data
)
274 struct ustcomm_ust_msg lum
;
275 struct ustcomm_ust_reply lur
;
276 struct lttng_ust_object_data
*channel_data
;
278 char *shm_path
, *wait_pipe_path
;
280 if (!chops
|| !_channel_data
)
283 channel_data
= malloc(sizeof(*channel_data
));
286 init_object(channel_data
);
287 /* Create metadata channel */
288 memset(&lum
, 0, sizeof(lum
));
289 lum
.handle
= session_handle
;
290 lum
.cmd
= LTTNG_UST_CHANNEL
;
291 lum
.u
.channel
.overwrite
= chops
->overwrite
;
292 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
293 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
294 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
295 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
296 lum
.u
.channel
.output
= chops
->output
;
297 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
302 if (lur
.ret_code
!= USTCOMM_OK
) {
306 channel_data
->handle
= lur
.ret_val
;
307 DBG("received channel handle %u", channel_data
->handle
);
308 channel_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
310 shm_path
= ustcomm_recv_string(sock
);
314 DBG("Received shm path: %s\n", shm_path
);
315 channel_data
->shm_fd
= get_dummy_fd();
316 channel_data
->shm_path
= shm_path
;
320 * We need to get the second FD even if the first fails, because
321 * libust expects us to read the two FDs.
323 /* get wait pipe path */
324 wait_pipe_path
= ustcomm_recv_string(sock
);
325 if (!wait_pipe_path
) {
329 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
330 channel_data
->wait_fd
= get_dummy_fd();
331 channel_data
->wait_pipe_path
= wait_pipe_path
;
336 *_channel_data
= channel_data
;
340 (void) ustctl_release_object(sock
, channel_data
);
346 * Return -ENOENT if no more stream is available for creation.
347 * Return 0 on success.
348 * Return negative error value on error.
350 int ustctl_create_stream(int sock
, struct lttng_ust_object_data
*channel_data
,
351 struct lttng_ust_object_data
**_stream_data
)
353 struct ustcomm_ust_msg lum
;
354 struct ustcomm_ust_reply lur
;
355 struct lttng_ust_object_data
*stream_data
;
357 char *shm_path
, *wait_pipe_path
;
359 if (!channel_data
|| !_stream_data
)
362 stream_data
= malloc(sizeof(*stream_data
));
365 init_object(stream_data
);
366 memset(&lum
, 0, sizeof(lum
));
367 lum
.handle
= channel_data
->handle
;
368 lum
.cmd
= LTTNG_UST_STREAM
;
369 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
374 if (lur
.ret_code
!= USTCOMM_OK
) {
379 stream_data
->handle
= lur
.ret_val
;
380 DBG("received stream handle %u", stream_data
->handle
);
381 stream_data
->memory_map_size
= lur
.u
.stream
.memory_map_size
;
383 shm_path
= ustcomm_recv_string(sock
);
387 DBG("Received shm path: %s\n", shm_path
);
388 stream_data
->shm_fd
= get_dummy_fd();
389 stream_data
->shm_path
= shm_path
;
393 * We need to get the second FD even if the first fails, because
394 * libust expects us to read the two FDs.
396 /* get wait pipe path */
397 wait_pipe_path
= ustcomm_recv_string(sock
);
398 if (!wait_pipe_path
) {
402 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
403 stream_data
->wait_fd
= get_dummy_fd();
404 stream_data
->wait_pipe_path
= wait_pipe_path
;
409 *_stream_data
= stream_data
;
413 (void) ustctl_release_object(sock
, stream_data
);
418 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
419 struct lttng_ust_object_data
*channel_data
,
420 struct lttng_ust_object_data
**_event_data
)
422 struct ustcomm_ust_msg lum
;
423 struct ustcomm_ust_reply lur
;
424 struct lttng_ust_object_data
*event_data
;
427 if (!channel_data
|| !_event_data
)
430 event_data
= malloc(sizeof(*event_data
));
433 init_object(event_data
);
434 memset(&lum
, 0, sizeof(lum
));
435 lum
.handle
= channel_data
->handle
;
436 lum
.cmd
= LTTNG_UST_EVENT
;
437 strncpy(lum
.u
.event
.name
, ev
->name
,
438 LTTNG_UST_SYM_NAME_LEN
);
439 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
440 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
441 lum
.u
.event
.loglevel
= ev
->loglevel
;
442 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
447 event_data
->handle
= lur
.ret_val
;
448 DBG("received event handle %u", event_data
->handle
);
449 *_event_data
= event_data
;
453 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
454 struct lttng_ust_object_data
*obj_data
,
455 struct lttng_ust_object_data
**_context_data
)
457 struct ustcomm_ust_msg lum
;
458 struct ustcomm_ust_reply lur
;
459 struct lttng_ust_object_data
*context_data
;
462 if (!obj_data
|| !_context_data
)
465 context_data
= malloc(sizeof(*context_data
));
468 init_object(context_data
);
469 memset(&lum
, 0, sizeof(lum
));
470 lum
.handle
= obj_data
->handle
;
471 lum
.cmd
= LTTNG_UST_CONTEXT
;
472 lum
.u
.context
.ctx
= ctx
->ctx
;
473 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
478 context_data
->handle
= lur
.ret_val
;
479 DBG("received context handle %u", context_data
->handle
);
480 *_context_data
= context_data
;
484 /* Enable event, channel and session ioctl */
485 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
487 struct ustcomm_ust_msg lum
;
488 struct ustcomm_ust_reply lur
;
494 memset(&lum
, 0, sizeof(lum
));
495 lum
.handle
= object
->handle
;
496 lum
.cmd
= LTTNG_UST_ENABLE
;
497 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
500 DBG("enabled handle %u", object
->handle
);
504 /* Disable event, channel and session ioctl */
505 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
507 struct ustcomm_ust_msg lum
;
508 struct ustcomm_ust_reply lur
;
514 memset(&lum
, 0, sizeof(lum
));
515 lum
.handle
= object
->handle
;
516 lum
.cmd
= LTTNG_UST_DISABLE
;
517 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
520 DBG("disable handle %u", object
->handle
);
524 int ustctl_start_session(int sock
, int handle
)
526 struct lttng_ust_object_data obj
;
529 return ustctl_enable(sock
, &obj
);
532 int ustctl_stop_session(int sock
, int handle
)
534 struct lttng_ust_object_data obj
;
537 return ustctl_disable(sock
, &obj
);
540 int ustctl_tracepoint_list(int sock
)
542 struct ustcomm_ust_msg lum
;
543 struct ustcomm_ust_reply lur
;
544 int ret
, tp_list_handle
;
546 memset(&lum
, 0, sizeof(lum
));
547 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
548 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
549 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
552 tp_list_handle
= lur
.ret_val
;
553 DBG("received tracepoint list handle %u", tp_list_handle
);
554 return tp_list_handle
;
557 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
558 struct lttng_ust_tracepoint_iter
*iter
)
560 struct ustcomm_ust_msg lum
;
561 struct ustcomm_ust_reply lur
;
567 memset(&lum
, 0, sizeof(lum
));
568 lum
.handle
= tp_list_handle
;
569 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
570 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
573 DBG("received tracepoint list entry name %s loglevel %d",
574 lur
.u
.tracepoint
.name
,
575 lur
.u
.tracepoint
.loglevel
);
576 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
580 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
582 struct ustcomm_ust_msg lum
;
583 struct ustcomm_ust_reply lur
;
589 memset(&lum
, 0, sizeof(lum
));
590 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
591 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
592 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
595 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
596 DBG("received tracer version");
600 int ustctl_wait_quiescent(int sock
)
602 struct ustcomm_ust_msg lum
;
603 struct ustcomm_ust_reply lur
;
606 memset(&lum
, 0, sizeof(lum
));
607 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
608 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
609 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
612 DBG("waited for quiescent state");
616 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
624 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
626 struct ustcomm_ust_msg lum
;
627 struct ustcomm_ust_reply lur
;
633 memset(&lum
, 0, sizeof(lum
));
634 lum
.handle
= object
->handle
;
635 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
636 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
639 DBG("flushed buffer handle %u", object
->handle
);
643 /* Buffer operations */
645 /* Map channel shm into process memory */
646 struct lttng_ust_shm_handle
*ustctl_map_channel(struct lttng_ust_object_data
*chan_data
)
648 struct lttng_ust_shm_handle
*handle
;
649 struct channel
*chan
;
651 struct lttng_ust_lib_ring_buffer_config
*config
;
657 handle
= channel_handle_create(chan_data
->shm_fd
,
659 chan_data
->memory_map_size
);
661 ERR("create handle error");
665 * Set to -1, and then close the shm fd, and set the handle shm
666 * fd to -1 too. We don't need the shm fds after they have been
668 * The wait_fd is set to -1 in chan_data because it is now owned
671 chan_data
->shm_fd
= -1;
672 chan_data
->wait_fd
= -1;
674 /* chan is object 0. This is hardcoded. */
675 if (handle
->table
->objects
[0].shm_fd
>= 0) {
676 ret
= close(handle
->table
->objects
[0].shm_fd
);
678 perror("Error closing shm_fd");
680 handle
->table
->objects
[0].shm_fd
= -1;
684 * TODO: add consistency checks to be resilient if the
685 * application try to feed us with incoherent channel structure
688 chan
= shmp(handle
, handle
->chan
);
689 /* chan is object 0. This is hardcoded. */
690 chan_size
= handle
->table
->objects
[0].allocated_len
;
691 handle
->shadow_chan
= malloc(chan_size
);
692 if (!handle
->shadow_chan
) {
693 channel_destroy(chan
, handle
, 1);
696 memcpy(handle
->shadow_chan
, chan
, chan_size
);
698 * The callback pointers in the producer are invalid in the
699 * consumer. We need to look them up here.
701 config
= &handle
->shadow_chan
->backend
.config
;
702 switch (config
->client_type
) {
703 case LTTNG_CLIENT_METADATA
:
704 memcpy(&config
->cb
, lttng_client_callbacks_metadata
,
707 case LTTNG_CLIENT_DISCARD
:
708 memcpy(&config
->cb
, lttng_client_callbacks_discard
,
711 case LTTNG_CLIENT_OVERWRITE
:
712 memcpy(&config
->cb
, lttng_client_callbacks_overwrite
,
716 ERR("Unknown client type %d", config
->client_type
);
717 channel_destroy(chan
, handle
, 1);
720 /* Replace the object table pointer. */
721 ret
= munmap(handle
->table
->objects
[0].memory_map
,
722 handle
->table
->objects
[0].memory_map_size
);
727 handle
->table
->objects
[0].memory_map
= (char *) handle
->shadow_chan
;
728 handle
->table
->objects
[0].is_shadow
= 1;
732 /* Add stream to channel shm and map its shm into process memory */
733 int ustctl_add_stream(struct lttng_ust_shm_handle
*handle
,
734 struct lttng_ust_object_data
*stream_data
)
738 if (!handle
|| !stream_data
)
741 if (!stream_data
->handle
)
744 ret
= channel_handle_add_stream(handle
,
746 stream_data
->wait_fd
,
747 stream_data
->memory_map_size
);
749 ERR("add stream error\n");
753 * Set to -1 because the lttng_ust_shm_handle destruction will take care
754 * of closing shm_fd and wait_fd.
756 stream_data
->shm_fd
= -1;
757 stream_data
->wait_fd
= -1;
761 void ustctl_unmap_channel(struct lttng_ust_shm_handle
*handle
)
763 struct channel
*chan
;
766 chan
= shmp(handle
, handle
->chan
);
767 channel_destroy(chan
, handle
, 1);
771 * ustctl closes the shm_fd fds after mapping it.
773 struct lttng_ust_lib_ring_buffer
*ustctl_open_stream_read(struct lttng_ust_shm_handle
*handle
,
776 struct channel
*chan
;
777 int *shm_fd
, *wait_fd
;
778 char *shm_path
, *wait_pipe_path
;
779 uint64_t *memory_map_size
;
780 struct lttng_ust_lib_ring_buffer
*buf
;
786 chan
= handle
->shadow_chan
;
787 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
790 &wait_fd
, &wait_pipe_path
,
794 ret
= lib_ring_buffer_open_read(buf
, handle
, 1);
798 * We can close shm_fd early, right after is has been mapped.
801 ret
= close(*shm_fd
);
803 perror("Error closing shm_fd");
810 void ustctl_close_stream_read(struct lttng_ust_shm_handle
*handle
,
811 struct lttng_ust_lib_ring_buffer
*buf
)
813 assert(handle
&& buf
);
814 lib_ring_buffer_release_read(buf
, handle
, 1);
817 /* For mmap mode, readable without "get" operation */
819 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle
*handle
,
820 struct lttng_ust_lib_ring_buffer
*buf
)
824 return shmp(handle
, buf
->backend
.memory_map
);
827 /* returns the length to mmap. */
828 int ustctl_get_mmap_len(struct lttng_ust_shm_handle
*handle
,
829 struct lttng_ust_lib_ring_buffer
*buf
,
832 unsigned long mmap_buf_len
;
833 struct channel
*chan
;
835 if (!handle
|| !buf
|| !len
)
838 chan
= handle
->shadow_chan
;
839 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
841 mmap_buf_len
= chan
->backend
.buf_size
;
842 if (chan
->backend
.extra_reader_sb
)
843 mmap_buf_len
+= chan
->backend
.subbuf_size
;
844 if (mmap_buf_len
> INT_MAX
)
850 /* returns the maximum size for sub-buffers. */
851 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle
*handle
,
852 struct lttng_ust_lib_ring_buffer
*buf
,
855 struct channel
*chan
;
857 if (!handle
|| !buf
|| !len
)
860 chan
= handle
->shadow_chan
;
861 *len
= chan
->backend
.subbuf_size
;
866 * For mmap mode, operate on the current packet (between get/put or
867 * get_next/put_next).
870 /* returns the offset of the subbuffer belonging to the mmap reader. */
871 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle
*handle
,
872 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *off
)
874 struct channel
*chan
;
875 unsigned long sb_bindex
;
877 if (!handle
|| !buf
|| !off
)
880 chan
= handle
->shadow_chan
;
881 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
883 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
884 buf
->backend
.buf_rsb
.id
);
885 *off
= shmp(handle
, shmp_index(handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
889 /* returns the size of the current sub-buffer, without padding (for mmap). */
890 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle
*handle
,
891 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
893 struct channel
*chan
;
895 if (!handle
|| !buf
|| !len
)
898 chan
= handle
->shadow_chan
;
899 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
904 /* returns the size of the current sub-buffer, without padding (for mmap). */
905 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle
*handle
,
906 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
908 struct channel
*chan
;
910 if (!handle
|| !buf
|| !len
)
913 chan
= handle
->shadow_chan
;
914 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
916 *len
= PAGE_ALIGN(*len
);
920 /* Get exclusive read access to the next sub-buffer that can be read. */
921 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle
*handle
,
922 struct lttng_ust_lib_ring_buffer
*buf
)
927 return lib_ring_buffer_get_next_subbuf(buf
, handle
);
931 /* Release exclusive sub-buffer access, move consumer forward. */
932 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle
*handle
,
933 struct lttng_ust_lib_ring_buffer
*buf
)
938 lib_ring_buffer_put_next_subbuf(buf
, handle
);
944 /* Get a snapshot of the current ring buffer producer and consumer positions */
945 int ustctl_snapshot(struct lttng_ust_shm_handle
*handle
,
946 struct lttng_ust_lib_ring_buffer
*buf
)
951 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
952 &buf
->prod_snapshot
, handle
);
955 /* Get the consumer position (iteration start) */
956 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle
*handle
,
957 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
959 if (!handle
|| !buf
|| !pos
)
962 *pos
= buf
->cons_snapshot
;
966 /* Get the producer position (iteration end) */
967 int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle
*handle
,
968 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
970 if (!handle
|| !buf
|| !pos
)
973 *pos
= buf
->prod_snapshot
;
977 /* Get exclusive read access to the specified sub-buffer position */
978 int ustctl_get_subbuf(struct lttng_ust_shm_handle
*handle
,
979 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
981 if (!handle
|| !buf
|| !pos
)
984 return lib_ring_buffer_get_subbuf(buf
, *pos
, handle
);
987 /* Release exclusive sub-buffer access */
988 int ustctl_put_subbuf(struct lttng_ust_shm_handle
*handle
,
989 struct lttng_ust_lib_ring_buffer
*buf
)
994 lib_ring_buffer_put_subbuf(buf
, handle
);
998 void ustctl_flush_buffer(struct lttng_ust_shm_handle
*handle
,
999 struct lttng_ust_lib_ring_buffer
*buf
,
1000 int producer_active
)
1002 assert(handle
&& buf
);
1003 lib_ring_buffer_switch_slow(buf
,
1004 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,