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
)
40 data
->memory_map_size
= 0;
43 int ustctl_release_handle(int sock
, int handle
)
45 struct ustcomm_ust_msg lum
;
46 struct ustcomm_ust_reply lur
;
50 memset(&lum
, 0, sizeof(lum
));
52 lum
.cmd
= LTTNG_UST_RELEASE
;
53 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
61 * If sock is negative, it means we don't have to notify the other side
62 * (e.g. application has already vanished).
64 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
71 if (data
->shm_fd
>= 0) {
72 ret
= close(data
->shm_fd
);
77 if (data
->wait_fd
>= 0) {
78 ret
= close(data
->wait_fd
);
83 return ustctl_release_handle(sock
, data
->handle
);
87 * Send registration done packet to the application.
89 int ustctl_register_done(int sock
)
91 struct ustcomm_ust_msg lum
;
92 struct ustcomm_ust_reply lur
;
95 DBG("Sending register done command to %d", sock
);
96 memset(&lum
, 0, sizeof(lum
));
97 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
98 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
99 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
102 if (lur
.ret_code
!= USTCOMM_OK
) {
103 DBG("Return code: %s", ustcomm_get_readable_code(lur
.ret_code
));
113 * returns session handle.
115 int ustctl_create_session(int sock
)
117 struct ustcomm_ust_msg lum
;
118 struct ustcomm_ust_reply lur
;
119 int ret
, session_handle
;
122 memset(&lum
, 0, sizeof(lum
));
123 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
124 lum
.cmd
= LTTNG_UST_SESSION
;
125 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
128 session_handle
= lur
.ret_val
;
129 DBG("received session handle %u", session_handle
);
130 return session_handle
;
133 /* open the metadata global channel */
134 int ustctl_open_metadata(int sock
, int session_handle
,
135 struct lttng_ust_channel_attr
*chops
,
136 struct lttng_ust_object_data
**_metadata_data
)
138 struct ustcomm_ust_msg lum
;
139 struct ustcomm_ust_reply lur
;
140 struct lttng_ust_object_data
*metadata_data
;
143 if (!chops
|| !_metadata_data
)
146 metadata_data
= malloc(sizeof(*metadata_data
));
149 init_object(metadata_data
);
150 /* Create metadata channel */
151 memset(&lum
, 0, sizeof(lum
));
152 lum
.handle
= session_handle
;
153 lum
.cmd
= LTTNG_UST_METADATA
;
154 lum
.u
.channel
.overwrite
= chops
->overwrite
;
155 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
156 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
157 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
158 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
159 lum
.u
.channel
.output
= chops
->output
;
160 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
165 if (lur
.ret_code
!= USTCOMM_OK
) {
169 metadata_data
->handle
= lur
.ret_val
;
170 DBG("received metadata handle %u", metadata_data
->handle
);
171 metadata_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
173 ret
= ustcomm_recv_fd(sock
);
177 metadata_data
->shm_fd
= ret
;
179 * We need to get the second FD even if the first fails, because
180 * libust expects us to read the two FDs.
183 ret
= ustcomm_recv_fd(sock
);
187 metadata_data
->wait_fd
= ret
;
190 *_metadata_data
= metadata_data
;
194 (void) ustctl_release_object(sock
, metadata_data
);
199 int ustctl_create_channel(int sock
, int session_handle
,
200 struct lttng_ust_channel_attr
*chops
,
201 struct lttng_ust_object_data
**_channel_data
)
203 struct ustcomm_ust_msg lum
;
204 struct ustcomm_ust_reply lur
;
205 struct lttng_ust_object_data
*channel_data
;
208 if (!chops
|| !_channel_data
)
211 channel_data
= malloc(sizeof(*channel_data
));
214 init_object(channel_data
);
215 /* Create metadata channel */
216 memset(&lum
, 0, sizeof(lum
));
217 lum
.handle
= session_handle
;
218 lum
.cmd
= LTTNG_UST_CHANNEL
;
219 lum
.u
.channel
.overwrite
= chops
->overwrite
;
220 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
221 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
222 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
223 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
224 lum
.u
.channel
.output
= chops
->output
;
225 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
230 if (lur
.ret_code
!= USTCOMM_OK
) {
234 channel_data
->handle
= lur
.ret_val
;
235 DBG("received channel handle %u", channel_data
->handle
);
236 channel_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
238 ret
= ustcomm_recv_fd(sock
);
242 channel_data
->shm_fd
= ret
;
244 * We need to get the second FD even if the first fails, because
245 * libust expects us to read the two FDs.
248 ret
= ustcomm_recv_fd(sock
);
252 channel_data
->wait_fd
= ret
;
255 *_channel_data
= channel_data
;
259 (void) ustctl_release_object(sock
, channel_data
);
265 * Return -ENOENT if no more stream is available for creation.
266 * Return 0 on success.
267 * Return negative error value on error.
269 int ustctl_create_stream(int sock
, struct lttng_ust_object_data
*channel_data
,
270 struct lttng_ust_object_data
**_stream_data
)
272 struct ustcomm_ust_msg lum
;
273 struct ustcomm_ust_reply lur
;
274 struct lttng_ust_object_data
*stream_data
;
275 int ret
, fd
, err
= 0;
277 if (!channel_data
|| !_stream_data
)
280 stream_data
= malloc(sizeof(*stream_data
));
283 init_object(stream_data
);
284 memset(&lum
, 0, sizeof(lum
));
285 lum
.handle
= channel_data
->handle
;
286 lum
.cmd
= LTTNG_UST_STREAM
;
287 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
292 if (lur
.ret_code
!= USTCOMM_OK
) {
297 stream_data
->handle
= lur
.ret_val
;
298 DBG("received stream handle %u", stream_data
->handle
);
299 stream_data
->memory_map_size
= lur
.u
.stream
.memory_map_size
;
301 fd
= ustcomm_recv_fd(sock
);
305 stream_data
->shm_fd
= fd
;
307 * We need to get the second FD even if the first fails, because
308 * libust expects us to read the two FDs.
311 fd
= ustcomm_recv_fd(sock
);
315 stream_data
->wait_fd
= fd
;
318 *_stream_data
= stream_data
;
322 (void) ustctl_release_object(sock
, stream_data
);
327 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
328 struct lttng_ust_object_data
*channel_data
,
329 struct lttng_ust_object_data
**_event_data
)
331 struct ustcomm_ust_msg lum
;
332 struct ustcomm_ust_reply lur
;
333 struct lttng_ust_object_data
*event_data
;
336 if (!channel_data
|| !_event_data
)
339 event_data
= malloc(sizeof(*event_data
));
342 init_object(event_data
);
343 memset(&lum
, 0, sizeof(lum
));
344 lum
.handle
= channel_data
->handle
;
345 lum
.cmd
= LTTNG_UST_EVENT
;
346 strncpy(lum
.u
.event
.name
, ev
->name
,
347 LTTNG_UST_SYM_NAME_LEN
);
348 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
349 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
350 lum
.u
.event
.loglevel
= ev
->loglevel
;
351 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
356 event_data
->handle
= lur
.ret_val
;
357 DBG("received event handle %u", event_data
->handle
);
358 *_event_data
= event_data
;
362 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
363 struct lttng_ust_object_data
*obj_data
,
364 struct lttng_ust_object_data
**_context_data
)
366 struct ustcomm_ust_msg lum
;
367 struct ustcomm_ust_reply lur
;
368 struct lttng_ust_object_data
*context_data
;
371 if (!obj_data
|| !_context_data
)
374 context_data
= malloc(sizeof(*context_data
));
377 init_object(context_data
);
378 memset(&lum
, 0, sizeof(lum
));
379 lum
.handle
= obj_data
->handle
;
380 lum
.cmd
= LTTNG_UST_CONTEXT
;
381 lum
.u
.context
.ctx
= ctx
->ctx
;
382 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
387 context_data
->handle
= lur
.ret_val
;
388 DBG("received context handle %u", context_data
->handle
);
389 *_context_data
= context_data
;
393 int ustctl_set_filter(int sock
, struct lttng_ust_filter_bytecode
*bytecode
,
394 struct lttng_ust_object_data
*obj_data
)
396 struct ustcomm_ust_msg lum
;
397 struct ustcomm_ust_reply lur
;
403 memset(&lum
, 0, sizeof(lum
));
404 lum
.handle
= obj_data
->handle
;
405 lum
.cmd
= LTTNG_UST_FILTER
;
406 lum
.u
.filter
.data_size
= bytecode
->len
;
407 lum
.u
.filter
.reloc_offset
= bytecode
->reloc_offset
;
409 ret
= ustcomm_send_app_msg(sock
, &lum
);
415 /* send var len bytecode */
416 ret
= ustcomm_send_unix_sock(sock
, bytecode
->data
,
421 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
427 /* Enable event, channel and session ioctl */
428 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
430 struct ustcomm_ust_msg lum
;
431 struct ustcomm_ust_reply lur
;
437 memset(&lum
, 0, sizeof(lum
));
438 lum
.handle
= object
->handle
;
439 lum
.cmd
= LTTNG_UST_ENABLE
;
440 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
443 DBG("enabled handle %u", object
->handle
);
447 /* Disable event, channel and session ioctl */
448 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
450 struct ustcomm_ust_msg lum
;
451 struct ustcomm_ust_reply lur
;
457 memset(&lum
, 0, sizeof(lum
));
458 lum
.handle
= object
->handle
;
459 lum
.cmd
= LTTNG_UST_DISABLE
;
460 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
463 DBG("disable handle %u", object
->handle
);
467 int ustctl_start_session(int sock
, int handle
)
469 struct lttng_ust_object_data obj
;
472 return ustctl_enable(sock
, &obj
);
475 int ustctl_stop_session(int sock
, int handle
)
477 struct lttng_ust_object_data obj
;
480 return ustctl_disable(sock
, &obj
);
483 int ustctl_tracepoint_list(int sock
)
485 struct ustcomm_ust_msg lum
;
486 struct ustcomm_ust_reply lur
;
487 int ret
, tp_list_handle
;
489 memset(&lum
, 0, sizeof(lum
));
490 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
491 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
492 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
495 tp_list_handle
= lur
.ret_val
;
496 DBG("received tracepoint list handle %u", tp_list_handle
);
497 return tp_list_handle
;
500 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
501 struct lttng_ust_tracepoint_iter
*iter
)
503 struct ustcomm_ust_msg lum
;
504 struct ustcomm_ust_reply lur
;
510 memset(&lum
, 0, sizeof(lum
));
511 lum
.handle
= tp_list_handle
;
512 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
513 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
516 DBG("received tracepoint list entry name %s loglevel %d",
517 lur
.u
.tracepoint
.name
,
518 lur
.u
.tracepoint
.loglevel
);
519 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
523 int ustctl_tracepoint_field_list(int sock
)
525 struct ustcomm_ust_msg lum
;
526 struct ustcomm_ust_reply lur
;
527 int ret
, tp_field_list_handle
;
529 memset(&lum
, 0, sizeof(lum
));
530 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
531 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST
;
532 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
535 tp_field_list_handle
= lur
.ret_val
;
536 DBG("received tracepoint field list handle %u", tp_field_list_handle
);
537 return tp_field_list_handle
;
540 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
541 struct lttng_ust_field_iter
*iter
)
543 struct ustcomm_ust_msg lum
;
544 struct ustcomm_ust_reply lur
;
551 memset(&lum
, 0, sizeof(lum
));
552 lum
.handle
= tp_field_list_handle
;
553 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
;
554 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
557 if (lur
.ret_code
!= USTCOMM_OK
) {
558 DBG("Return code: %s", ustcomm_get_readable_code(lur
.ret_code
));
561 len
= ustcomm_recv_unix_sock(sock
, iter
, sizeof(*iter
));
562 if (len
!= sizeof(*iter
)) {
565 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
573 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
575 struct ustcomm_ust_msg lum
;
576 struct ustcomm_ust_reply lur
;
582 memset(&lum
, 0, sizeof(lum
));
583 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
584 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
585 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
588 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
589 DBG("received tracer version");
593 int ustctl_wait_quiescent(int sock
)
595 struct ustcomm_ust_msg lum
;
596 struct ustcomm_ust_reply lur
;
599 memset(&lum
, 0, sizeof(lum
));
600 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
601 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
602 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
605 DBG("waited for quiescent state");
609 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
617 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
619 struct ustcomm_ust_msg lum
;
620 struct ustcomm_ust_reply lur
;
626 memset(&lum
, 0, sizeof(lum
));
627 lum
.handle
= object
->handle
;
628 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
629 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
632 DBG("flushed buffer handle %u", object
->handle
);
636 /* Buffer operations */
638 /* Map channel shm into process memory */
639 struct lttng_ust_shm_handle
*ustctl_map_channel(struct lttng_ust_object_data
*chan_data
)
641 struct lttng_ust_shm_handle
*handle
;
642 struct channel
*chan
;
644 struct lttng_ust_lib_ring_buffer_config
*config
;
650 handle
= channel_handle_create(chan_data
->shm_fd
,
652 chan_data
->memory_map_size
);
654 ERR("create handle error");
658 * Set to -1, and then close the shm fd, and set the handle shm
659 * fd to -1 too. We don't need the shm fds after they have been
661 * The wait_fd is set to -1 in chan_data because it is now owned
664 chan_data
->shm_fd
= -1;
665 chan_data
->wait_fd
= -1;
667 /* chan is object 0. This is hardcoded. */
668 if (handle
->table
->objects
[0].shm_fd
>= 0) {
669 ret
= close(handle
->table
->objects
[0].shm_fd
);
671 perror("Error closing shm_fd");
673 handle
->table
->objects
[0].shm_fd
= -1;
677 * TODO: add consistency checks to be resilient if the
678 * application try to feed us with incoherent channel structure
681 chan
= shmp(handle
, handle
->chan
);
682 /* chan is object 0. This is hardcoded. */
683 chan_size
= handle
->table
->objects
[0].allocated_len
;
684 handle
->shadow_chan
= malloc(chan_size
);
685 if (!handle
->shadow_chan
) {
686 channel_destroy(chan
, handle
, 1);
689 memcpy(handle
->shadow_chan
, chan
, chan_size
);
691 * The callback pointers in the producer are invalid in the
692 * consumer. We need to look them up here.
694 config
= &handle
->shadow_chan
->backend
.config
;
695 switch (config
->client_type
) {
696 case LTTNG_CLIENT_METADATA
:
697 memcpy(&config
->cb
, lttng_client_callbacks_metadata
,
700 case LTTNG_CLIENT_DISCARD
:
701 memcpy(&config
->cb
, lttng_client_callbacks_discard
,
704 case LTTNG_CLIENT_OVERWRITE
:
705 memcpy(&config
->cb
, lttng_client_callbacks_overwrite
,
709 ERR("Unknown client type %d", config
->client_type
);
710 channel_destroy(chan
, handle
, 1);
713 /* Replace the object table pointer. */
714 ret
= munmap(handle
->table
->objects
[0].memory_map
,
715 handle
->table
->objects
[0].memory_map_size
);
720 handle
->table
->objects
[0].memory_map
= (char *) handle
->shadow_chan
;
721 handle
->table
->objects
[0].is_shadow
= 1;
725 /* Add stream to channel shm and map its shm into process memory */
726 int ustctl_add_stream(struct lttng_ust_shm_handle
*handle
,
727 struct lttng_ust_object_data
*stream_data
)
731 if (!handle
|| !stream_data
)
734 if (!stream_data
->handle
)
737 ret
= channel_handle_add_stream(handle
,
739 stream_data
->wait_fd
,
740 stream_data
->memory_map_size
);
742 ERR("add stream error\n");
746 * Set to -1 because the lttng_ust_shm_handle destruction will take care
747 * of closing shm_fd and wait_fd.
749 stream_data
->shm_fd
= -1;
750 stream_data
->wait_fd
= -1;
754 void ustctl_unmap_channel(struct lttng_ust_shm_handle
*handle
)
756 struct channel
*chan
;
759 chan
= shmp(handle
, handle
->chan
);
760 channel_destroy(chan
, handle
, 1);
764 * ustctl closes the shm_fd fds after mapping it.
766 struct lttng_ust_lib_ring_buffer
*ustctl_open_stream_read(struct lttng_ust_shm_handle
*handle
,
769 struct channel
*chan
;
770 int *shm_fd
, *wait_fd
;
771 uint64_t *memory_map_size
;
772 struct lttng_ust_lib_ring_buffer
*buf
;
778 chan
= handle
->shadow_chan
;
779 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
780 chan
, cpu
, handle
, &shm_fd
, &wait_fd
, &memory_map_size
);
783 ret
= lib_ring_buffer_open_read(buf
, handle
, 1);
787 * We can close shm_fd early, right after is has been mapped.
790 ret
= close(*shm_fd
);
792 perror("Error closing shm_fd");
799 void ustctl_close_stream_read(struct lttng_ust_shm_handle
*handle
,
800 struct lttng_ust_lib_ring_buffer
*buf
)
802 assert(handle
&& buf
);
803 lib_ring_buffer_release_read(buf
, handle
, 1);
806 /* For mmap mode, readable without "get" operation */
808 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle
*handle
,
809 struct lttng_ust_lib_ring_buffer
*buf
)
813 return shmp(handle
, buf
->backend
.memory_map
);
816 /* returns the length to mmap. */
817 int ustctl_get_mmap_len(struct lttng_ust_shm_handle
*handle
,
818 struct lttng_ust_lib_ring_buffer
*buf
,
821 unsigned long mmap_buf_len
;
822 struct channel
*chan
;
824 if (!handle
|| !buf
|| !len
)
827 chan
= handle
->shadow_chan
;
828 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
830 mmap_buf_len
= chan
->backend
.buf_size
;
831 if (chan
->backend
.extra_reader_sb
)
832 mmap_buf_len
+= chan
->backend
.subbuf_size
;
833 if (mmap_buf_len
> INT_MAX
)
839 /* returns the maximum size for sub-buffers. */
840 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle
*handle
,
841 struct lttng_ust_lib_ring_buffer
*buf
,
844 struct channel
*chan
;
846 if (!handle
|| !buf
|| !len
)
849 chan
= handle
->shadow_chan
;
850 *len
= chan
->backend
.subbuf_size
;
855 * For mmap mode, operate on the current packet (between get/put or
856 * get_next/put_next).
859 /* returns the offset of the subbuffer belonging to the mmap reader. */
860 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle
*handle
,
861 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *off
)
863 struct channel
*chan
;
864 unsigned long sb_bindex
;
866 if (!handle
|| !buf
|| !off
)
869 chan
= handle
->shadow_chan
;
870 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
872 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
873 buf
->backend
.buf_rsb
.id
);
874 *off
= shmp(handle
, shmp_index(handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
878 /* returns the size of the current sub-buffer, without padding (for mmap). */
879 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle
*handle
,
880 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
882 struct channel
*chan
;
884 if (!handle
|| !buf
|| !len
)
887 chan
= handle
->shadow_chan
;
888 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
893 /* returns the size of the current sub-buffer, without padding (for mmap). */
894 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle
*handle
,
895 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
897 struct channel
*chan
;
899 if (!handle
|| !buf
|| !len
)
902 chan
= handle
->shadow_chan
;
903 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
905 *len
= PAGE_ALIGN(*len
);
909 /* Get exclusive read access to the next sub-buffer that can be read. */
910 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle
*handle
,
911 struct lttng_ust_lib_ring_buffer
*buf
)
916 return lib_ring_buffer_get_next_subbuf(buf
, handle
);
920 /* Release exclusive sub-buffer access, move consumer forward. */
921 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle
*handle
,
922 struct lttng_ust_lib_ring_buffer
*buf
)
927 lib_ring_buffer_put_next_subbuf(buf
, handle
);
933 /* Get a snapshot of the current ring buffer producer and consumer positions */
934 int ustctl_snapshot(struct lttng_ust_shm_handle
*handle
,
935 struct lttng_ust_lib_ring_buffer
*buf
)
940 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
941 &buf
->prod_snapshot
, handle
);
944 /* Get the consumer position (iteration start) */
945 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle
*handle
,
946 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
948 if (!handle
|| !buf
|| !pos
)
951 *pos
= buf
->cons_snapshot
;
955 /* Get the producer position (iteration end) */
956 int ustctl_snapshot_get_produced(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
->prod_snapshot
;
966 /* Get exclusive read access to the specified sub-buffer position */
967 int ustctl_get_subbuf(struct lttng_ust_shm_handle
*handle
,
968 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
970 if (!handle
|| !buf
|| !pos
)
973 return lib_ring_buffer_get_subbuf(buf
, *pos
, handle
);
976 /* Release exclusive sub-buffer access */
977 int ustctl_put_subbuf(struct lttng_ust_shm_handle
*handle
,
978 struct lttng_ust_lib_ring_buffer
*buf
)
983 lib_ring_buffer_put_subbuf(buf
, handle
);
987 void ustctl_flush_buffer(struct lttng_ust_shm_handle
*handle
,
988 struct lttng_ust_lib_ring_buffer
*buf
,
991 assert(handle
&& buf
);
992 lib_ring_buffer_switch_slow(buf
,
993 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,