2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
5 * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include <sys/types.h>
13 #include <sys/socket.h>
15 #include <lttng/ust-config.h>
16 #include <lttng/ust-ctl.h>
17 #include <lttng/ust-abi.h>
18 #include <lttng/ust-endian.h>
19 #include <lttng/ust-common.h>
20 #include <lttng/ust-sigbus.h>
21 #include <urcu/rculist.h>
23 #include "common/logging.h"
24 #include "common/ustcomm.h"
25 #include "common/macros.h"
26 #include "common/align.h"
28 #include "common/ringbuffer/backend.h"
29 #include "common/ringbuffer/frontend.h"
30 #include "common/events.h"
31 #include "common/wait.h"
32 #include "common/ringbuffer-clients/clients.h"
33 #include "common/getenv.h"
34 #include "common/tracer.h"
35 #include "common/counter-clients/clients.h"
37 #include "common/smp.h"
38 #include "common/counter/counter.h"
41 * Number of milliseconds to retry before failing metadata writes on
42 * buffer full condition. (10 seconds)
44 #define LTTNG_METADATA_TIMEOUT_MSEC 10000
47 * Channel representation within consumer.
49 struct lttng_ust_ctl_consumer_channel
{
50 struct lttng_ust_channel_buffer
*chan
; /* lttng channel buffers */
52 /* initial attributes */
53 struct lttng_ust_ctl_consumer_channel_attr attr
;
54 int wait_fd
; /* monitor close() */
55 int wakeup_fd
; /* monitor close() */
59 * Stream representation within consumer.
61 struct lttng_ust_ctl_consumer_stream
{
62 struct lttng_ust_ring_buffer
*buf
;
63 struct lttng_ust_ctl_consumer_channel
*chan
;
64 int shm_fd
, wait_fd
, wakeup_fd
;
66 uint64_t memory_map_size
;
67 void *memory_map_addr
;
70 #define LTTNG_UST_CTL_COUNTER_ATTR_DIMENSION_MAX 8
71 struct lttng_ust_ctl_counter_attr
{
72 enum lttng_ust_ctl_counter_arithmetic arithmetic
;
73 enum lttng_ust_ctl_counter_bitness bitness
;
74 uint32_t nr_dimensions
;
75 int64_t global_sum_step
;
76 struct lttng_ust_ctl_counter_dimension dimensions
[LTTNG_UST_CTL_COUNTER_ATTR_DIMENSION_MAX
];
81 * Counter representation within daemon.
83 struct lttng_ust_ctl_daemon_counter
{
84 struct lib_counter
*counter
;
85 const struct lttng_counter_ops
*ops
;
86 struct lttng_ust_ctl_counter_attr
*attr
; /* initial attributes */
90 * Evaluates to false if transaction begins, true if it has failed due to SIGBUS.
91 * The entire transaction must complete before the current function returns.
92 * A transaction can contain 0 or more tracked ranges as sigbus begin/end pairs.
94 #define sigbus_begin() \
96 assert(!lttng_ust_sigbus_state.jmp_ready); \
97 if (!lttng_ust_sigbus_state.head.next) { \
99 * Lazy init because static list initialisation is \
100 * problematic for TLS variable. \
102 CDS_INIT_LIST_HEAD(<tng_ust_sigbus_state.head); \
104 if (sigsetjmp(lttng_ust_sigbus_state.sj_env, 1)) { \
106 CMM_STORE_SHARED(lttng_ust_sigbus_state.jmp_ready, 0); \
110 CMM_STORE_SHARED(lttng_ust_sigbus_state.jmp_ready, 1); \
114 static void sigbus_end(void)
116 assert(lttng_ust_sigbus_state
.jmp_ready
);
118 CMM_STORE_SHARED(lttng_ust_sigbus_state
.jmp_ready
, 0);
122 void lttng_ust_sigbus_add_range(struct lttng_ust_sigbus_range
*range
, void *start
, size_t len
)
124 range
->start
= start
;
125 range
->end
= (char *)start
+ len
;
126 cds_list_add_rcu(&range
->node
, <tng_ust_sigbus_state
.head
);
131 void lttng_ust_sigbus_del_range(struct lttng_ust_sigbus_range
*range
)
134 cds_list_del_rcu(&range
->node
);
137 void lttng_ust_ctl_sigbus_handle(void *addr
)
139 struct lttng_ust_sigbus_range
*range
;
141 if (!CMM_LOAD_SHARED(lttng_ust_sigbus_state
.jmp_ready
))
143 cds_list_for_each_entry_rcu(range
, <tng_ust_sigbus_state
.head
, node
) {
144 if (addr
< range
->start
|| addr
>= range
->end
)
146 siglongjmp(lttng_ust_sigbus_state
.sj_env
, 1);
150 int lttng_ust_ctl_release_handle(int sock
, int handle
)
152 struct ustcomm_ust_msg lum
;
153 struct ustcomm_ust_reply lur
;
155 if (sock
< 0 || handle
< 0)
157 memset(&lum
, 0, sizeof(lum
));
159 lum
.cmd
= LTTNG_UST_ABI_RELEASE
;
160 return ustcomm_send_app_cmd(sock
, &lum
, &lur
);
164 * If sock is negative, it means we don't have to notify the other side
165 * (e.g. application has already vanished).
167 int lttng_ust_ctl_release_object(int sock
, struct lttng_ust_abi_object_data
*data
)
174 switch (data
->type
) {
175 case LTTNG_UST_ABI_OBJECT_TYPE_CHANNEL
:
176 if (data
->u
.channel
.wakeup_fd
>= 0) {
177 ret
= close(data
->u
.channel
.wakeup_fd
);
182 data
->u
.channel
.wakeup_fd
= -1;
184 free(data
->u
.channel
.data
);
185 data
->u
.channel
.data
= NULL
;
187 case LTTNG_UST_ABI_OBJECT_TYPE_STREAM
:
188 if (data
->u
.stream
.shm_fd
>= 0) {
189 ret
= close(data
->u
.stream
.shm_fd
);
194 data
->u
.stream
.shm_fd
= -1;
196 if (data
->u
.stream
.wakeup_fd
>= 0) {
197 ret
= close(data
->u
.stream
.wakeup_fd
);
202 data
->u
.stream
.wakeup_fd
= -1;
205 case LTTNG_UST_ABI_OBJECT_TYPE_EVENT
:
206 case LTTNG_UST_ABI_OBJECT_TYPE_CONTEXT
:
207 case LTTNG_UST_ABI_OBJECT_TYPE_EVENT_NOTIFIER_GROUP
:
208 case LTTNG_UST_ABI_OBJECT_TYPE_EVENT_NOTIFIER
:
210 case LTTNG_UST_ABI_OBJECT_TYPE_COUNTER
:
211 free(data
->u
.counter
.data
);
212 data
->u
.counter
.data
= NULL
;
214 case LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_GLOBAL
:
215 if (data
->u
.counter_global
.shm_fd
>= 0) {
216 ret
= close(data
->u
.counter_global
.shm_fd
);
221 data
->u
.counter_global
.shm_fd
= -1;
224 case LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_CPU
:
225 if (data
->u
.counter_cpu
.shm_fd
>= 0) {
226 ret
= close(data
->u
.counter_cpu
.shm_fd
);
231 data
->u
.counter_cpu
.shm_fd
= -1;
237 return lttng_ust_ctl_release_handle(sock
, data
->handle
);
241 * Send registration done packet to the application.
243 int lttng_ust_ctl_register_done(int sock
)
245 struct ustcomm_ust_msg lum
;
246 struct ustcomm_ust_reply lur
;
249 DBG("Sending register done command to %d", sock
);
250 memset(&lum
, 0, sizeof(lum
));
251 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
252 lum
.cmd
= LTTNG_UST_ABI_REGISTER_DONE
;
253 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
260 * returns session handle.
262 int lttng_ust_ctl_create_session(int sock
)
264 struct ustcomm_ust_msg lum
;
265 struct ustcomm_ust_reply lur
;
266 int ret
, session_handle
;
269 memset(&lum
, 0, sizeof(lum
));
270 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
271 lum
.cmd
= LTTNG_UST_ABI_SESSION
;
272 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
275 session_handle
= lur
.ret_val
;
276 DBG("received session handle %u", session_handle
);
277 return session_handle
;
280 int lttng_ust_ctl_create_event(int sock
, struct lttng_ust_abi_event
*ev
,
281 struct lttng_ust_abi_object_data
*channel_data
,
282 struct lttng_ust_abi_object_data
**_event_data
)
284 struct ustcomm_ust_msg lum
;
285 struct ustcomm_ust_reply lur
;
286 struct lttng_ust_abi_object_data
*event_data
;
289 if (!channel_data
|| !_event_data
)
292 event_data
= zmalloc(sizeof(*event_data
));
295 event_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_EVENT
;
296 memset(&lum
, 0, sizeof(lum
));
297 lum
.handle
= channel_data
->handle
;
298 lum
.cmd
= LTTNG_UST_ABI_EVENT
;
299 strncpy(lum
.u
.event
.name
, ev
->name
,
300 LTTNG_UST_ABI_SYM_NAME_LEN
);
301 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
302 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
303 lum
.u
.event
.loglevel
= ev
->loglevel
;
304 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
309 event_data
->handle
= lur
.ret_val
;
310 DBG("received event handle %u", event_data
->handle
);
311 *_event_data
= event_data
;
316 * Protocol for LTTNG_UST_ABI_CONTEXT command:
318 * - send: struct ustcomm_ust_msg
319 * - send: var len ctx_name
320 * - receive: struct ustcomm_ust_reply
322 * TODO: At the next breaking protocol bump, we should indicate the total
323 * command message length as part of a message header so that the protocol can
324 * recover from invalid command errors.
326 int lttng_ust_ctl_add_context(int sock
, struct lttng_ust_context_attr
*ctx
,
327 struct lttng_ust_abi_object_data
*obj_data
,
328 struct lttng_ust_abi_object_data
**_context_data
)
330 struct ustcomm_ust_msg lum
;
331 struct ustcomm_ust_reply lur
;
332 struct lttng_ust_abi_object_data
*context_data
= NULL
;
337 if (!obj_data
|| !_context_data
) {
342 context_data
= zmalloc(sizeof(*context_data
));
347 context_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_CONTEXT
;
348 memset(&lum
, 0, sizeof(lum
));
349 lum
.handle
= obj_data
->handle
;
350 lum
.cmd
= LTTNG_UST_ABI_CONTEXT
;
352 lum
.u
.context
.ctx
= ctx
->ctx
;
354 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER
:
355 lum
.u
.context
.u
.perf_counter
= ctx
->u
.perf_counter
;
357 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT
:
359 size_t provider_name_len
= strlen(
360 ctx
->u
.app_ctx
.provider_name
) + 1;
361 size_t ctx_name_len
= strlen(ctx
->u
.app_ctx
.ctx_name
) + 1;
363 lum
.u
.context
.u
.app_ctx
.provider_name_len
= provider_name_len
;
364 lum
.u
.context
.u
.app_ctx
.ctx_name_len
= ctx_name_len
;
366 len
= provider_name_len
+ ctx_name_len
;
372 memcpy(buf
, ctx
->u
.app_ctx
.provider_name
,
374 memcpy(buf
+ provider_name_len
, ctx
->u
.app_ctx
.ctx_name
,
381 ret
= ustcomm_send_app_msg(sock
, &lum
);
385 /* send var len ctx_name */
386 ret
= ustcomm_send_unix_sock(sock
, buf
, len
);
395 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
397 if (ret
== -EINVAL
) {
399 * Command unknown from remote end. The communication socket is
400 * now out-of-sync and needs to be shutdown.
402 (void) ustcomm_shutdown_unix_sock(sock
);
406 context_data
->handle
= -1;
407 DBG("Context created successfully");
408 *_context_data
= context_data
;
417 * Protocol for LTTNG_UST_ABI_FILTER command:
419 * - send: struct ustcomm_ust_msg
420 * - send: var len bytecode
421 * - receive: struct ustcomm_ust_reply
423 * TODO: At the next breaking protocol bump, we should indicate the total
424 * command message length as part of a message header so that the protocol can
425 * recover from invalid command errors.
427 int lttng_ust_ctl_set_filter(int sock
, struct lttng_ust_abi_filter_bytecode
*bytecode
,
428 struct lttng_ust_abi_object_data
*obj_data
)
430 struct ustcomm_ust_msg lum
;
431 struct ustcomm_ust_reply lur
;
437 memset(&lum
, 0, sizeof(lum
));
438 lum
.handle
= obj_data
->handle
;
439 lum
.cmd
= LTTNG_UST_ABI_FILTER
;
440 lum
.u
.filter
.data_size
= bytecode
->len
;
441 lum
.u
.filter
.reloc_offset
= bytecode
->reloc_offset
;
442 lum
.u
.filter
.seqnum
= bytecode
->seqnum
;
444 ret
= ustcomm_send_app_msg(sock
, &lum
);
447 /* send var len bytecode */
448 ret
= ustcomm_send_unix_sock(sock
, bytecode
->data
,
453 if (ret
!= bytecode
->len
)
455 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
456 if (ret
== -EINVAL
) {
458 * Command unknown from remote end. The communication socket is
459 * now out-of-sync and needs to be shutdown.
461 (void) ustcomm_shutdown_unix_sock(sock
);
467 * Protocol for LTTNG_UST_ABI_CAPTURE command:
469 * - send: struct ustcomm_ust_msg
470 * - receive: struct ustcomm_ust_reply
471 * - send: var len bytecode
472 * - receive: struct ustcomm_ust_reply (actual command return code)
474 int lttng_ust_ctl_set_capture(int sock
, struct lttng_ust_abi_capture_bytecode
*bytecode
,
475 struct lttng_ust_abi_object_data
*obj_data
)
477 struct ustcomm_ust_msg lum
;
478 struct ustcomm_ust_reply lur
;
484 memset(&lum
, 0, sizeof(lum
));
485 lum
.handle
= obj_data
->handle
;
486 lum
.cmd
= LTTNG_UST_ABI_CAPTURE
;
487 lum
.u
.capture
.data_size
= bytecode
->len
;
488 lum
.u
.capture
.reloc_offset
= bytecode
->reloc_offset
;
489 lum
.u
.capture
.seqnum
= bytecode
->seqnum
;
491 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
494 /* send var len bytecode */
495 ret
= ustcomm_send_unix_sock(sock
, bytecode
->data
,
500 if (ret
!= bytecode
->len
)
502 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
506 * Protocol for LTTNG_UST_ABI_EXCLUSION command:
508 * - send: struct ustcomm_ust_msg
509 * - send: var len exclusion names
510 * - receive: struct ustcomm_ust_reply
512 * TODO: At the next breaking protocol bump, we should indicate the total
513 * command message length as part of a message header so that the protocol can
514 * recover from invalid command errors.
516 int lttng_ust_ctl_set_exclusion(int sock
, struct lttng_ust_abi_event_exclusion
*exclusion
,
517 struct lttng_ust_abi_object_data
*obj_data
)
519 struct ustcomm_ust_msg lum
;
520 struct ustcomm_ust_reply lur
;
527 memset(&lum
, 0, sizeof(lum
));
528 lum
.handle
= obj_data
->handle
;
529 lum
.cmd
= LTTNG_UST_ABI_EXCLUSION
;
530 lum
.u
.exclusion
.count
= exclusion
->count
;
532 ret
= ustcomm_send_app_msg(sock
, &lum
);
537 /* send var len exclusion names */
538 ret
= ustcomm_send_unix_sock(sock
,
540 exclusion
->count
* LTTNG_UST_ABI_SYM_NAME_LEN
);
544 if (ret
!= exclusion
->count
* LTTNG_UST_ABI_SYM_NAME_LEN
) {
547 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
548 if (ret
== -EINVAL
) {
550 * Command unknown from remote end. The communication socket is
551 * now out-of-sync and needs to be shutdown.
553 (void) ustcomm_shutdown_unix_sock(sock
);
558 /* Enable event, channel and session ioctl */
559 int lttng_ust_ctl_enable(int sock
, struct lttng_ust_abi_object_data
*object
)
561 struct ustcomm_ust_msg lum
;
562 struct ustcomm_ust_reply lur
;
568 memset(&lum
, 0, sizeof(lum
));
569 lum
.handle
= object
->handle
;
570 lum
.cmd
= LTTNG_UST_ABI_ENABLE
;
571 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
574 DBG("enabled handle %u", object
->handle
);
578 /* Disable event, channel and session ioctl */
579 int lttng_ust_ctl_disable(int sock
, struct lttng_ust_abi_object_data
*object
)
581 struct ustcomm_ust_msg lum
;
582 struct ustcomm_ust_reply lur
;
588 memset(&lum
, 0, sizeof(lum
));
589 lum
.handle
= object
->handle
;
590 lum
.cmd
= LTTNG_UST_ABI_DISABLE
;
591 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
594 DBG("disable handle %u", object
->handle
);
598 int lttng_ust_ctl_start_session(int sock
, int handle
)
600 struct lttng_ust_abi_object_data obj
;
603 return lttng_ust_ctl_enable(sock
, &obj
);
606 int lttng_ust_ctl_stop_session(int sock
, int handle
)
608 struct lttng_ust_abi_object_data obj
;
611 return lttng_ust_ctl_disable(sock
, &obj
);
615 * Protocol for LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE command:
617 * - send: struct ustcomm_ust_msg
618 * - receive: struct ustcomm_ust_reply
619 * - send: file descriptor
620 * - receive: struct ustcomm_ust_reply (actual command return code)
622 int lttng_ust_ctl_create_event_notifier_group(int sock
, int pipe_fd
,
623 struct lttng_ust_abi_object_data
**_event_notifier_group_data
)
625 struct lttng_ust_abi_object_data
*event_notifier_group_data
;
626 struct ustcomm_ust_msg lum
;
627 struct ustcomm_ust_reply lur
;
631 if (!_event_notifier_group_data
)
634 event_notifier_group_data
= zmalloc(sizeof(*event_notifier_group_data
));
635 if (!event_notifier_group_data
)
638 event_notifier_group_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_EVENT_NOTIFIER_GROUP
;
640 memset(&lum
, 0, sizeof(lum
));
641 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
642 lum
.cmd
= LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE
;
644 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
648 /* Send event_notifier notification pipe. */
649 len
= ustcomm_send_fds_unix_sock(sock
, &pipe_fd
, 1);
655 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
659 event_notifier_group_data
->handle
= lur
.ret_val
;
660 DBG("received event_notifier group handle %d", event_notifier_group_data
->handle
);
662 *_event_notifier_group_data
= event_notifier_group_data
;
667 free(event_notifier_group_data
);
674 * Protocol for LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE command:
676 * - send: struct ustcomm_ust_msg
677 * - receive: struct ustcomm_ust_reply
678 * - send: struct lttng_ust_abi_event_notifier
679 * - receive: struct ustcomm_ust_reply (actual command return code)
681 int lttng_ust_ctl_create_event_notifier(int sock
, struct lttng_ust_abi_event_notifier
*event_notifier
,
682 struct lttng_ust_abi_object_data
*event_notifier_group
,
683 struct lttng_ust_abi_object_data
**_event_notifier_data
)
685 struct ustcomm_ust_msg lum
;
686 struct ustcomm_ust_reply lur
;
687 struct lttng_ust_abi_object_data
*event_notifier_data
;
691 if (!event_notifier_group
|| !_event_notifier_data
)
694 event_notifier_data
= zmalloc(sizeof(*event_notifier_data
));
695 if (!event_notifier_data
)
698 event_notifier_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_EVENT_NOTIFIER
;
700 memset(&lum
, 0, sizeof(lum
));
701 lum
.handle
= event_notifier_group
->handle
;
702 lum
.cmd
= LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE
;
703 lum
.u
.event_notifier
.len
= sizeof(*event_notifier
);
705 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
707 free(event_notifier_data
);
710 /* Send struct lttng_ust_abi_event_notifier */
711 len
= ustcomm_send_unix_sock(sock
, event_notifier
, sizeof(*event_notifier
));
712 if (len
!= sizeof(*event_notifier
)) {
713 free(event_notifier_data
);
719 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
721 free(event_notifier_data
);
724 event_notifier_data
->handle
= lur
.ret_val
;
725 DBG("received event_notifier handle %u", event_notifier_data
->handle
);
726 *_event_notifier_data
= event_notifier_data
;
731 int lttng_ust_ctl_tracepoint_list(int sock
)
733 struct ustcomm_ust_msg lum
;
734 struct ustcomm_ust_reply lur
;
735 int ret
, tp_list_handle
;
737 memset(&lum
, 0, sizeof(lum
));
738 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
739 lum
.cmd
= LTTNG_UST_ABI_TRACEPOINT_LIST
;
740 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
743 tp_list_handle
= lur
.ret_val
;
744 DBG("received tracepoint list handle %u", tp_list_handle
);
745 return tp_list_handle
;
748 int lttng_ust_ctl_tracepoint_list_get(int sock
, int tp_list_handle
,
749 struct lttng_ust_abi_tracepoint_iter
*iter
)
751 struct ustcomm_ust_msg lum
;
752 struct ustcomm_ust_reply lur
;
758 memset(&lum
, 0, sizeof(lum
));
759 lum
.handle
= tp_list_handle
;
760 lum
.cmd
= LTTNG_UST_ABI_TRACEPOINT_LIST_GET
;
761 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
764 DBG("received tracepoint list entry name %s loglevel %d",
765 lur
.u
.tracepoint
.name
,
766 lur
.u
.tracepoint
.loglevel
);
767 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
771 int lttng_ust_ctl_tracepoint_field_list(int sock
)
773 struct ustcomm_ust_msg lum
;
774 struct ustcomm_ust_reply lur
;
775 int ret
, tp_field_list_handle
;
777 memset(&lum
, 0, sizeof(lum
));
778 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
779 lum
.cmd
= LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
;
780 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
783 tp_field_list_handle
= lur
.ret_val
;
784 DBG("received tracepoint field list handle %u", tp_field_list_handle
);
785 return tp_field_list_handle
;
788 int lttng_ust_ctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
789 struct lttng_ust_abi_field_iter
*iter
)
791 struct ustcomm_ust_msg lum
;
792 struct ustcomm_ust_reply lur
;
799 memset(&lum
, 0, sizeof(lum
));
800 lum
.handle
= tp_field_list_handle
;
801 lum
.cmd
= LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST_GET
;
802 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
805 len
= ustcomm_recv_unix_sock(sock
, iter
, sizeof(*iter
));
806 if (len
!= sizeof(*iter
)) {
809 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
817 int lttng_ust_ctl_tracer_version(int sock
, struct lttng_ust_abi_tracer_version
*v
)
819 struct ustcomm_ust_msg lum
;
820 struct ustcomm_ust_reply lur
;
826 memset(&lum
, 0, sizeof(lum
));
827 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
828 lum
.cmd
= LTTNG_UST_ABI_TRACER_VERSION
;
829 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
832 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
833 DBG("received tracer version");
837 int lttng_ust_ctl_wait_quiescent(int sock
)
839 struct ustcomm_ust_msg lum
;
840 struct ustcomm_ust_reply lur
;
843 memset(&lum
, 0, sizeof(lum
));
844 lum
.handle
= LTTNG_UST_ABI_ROOT_HANDLE
;
845 lum
.cmd
= LTTNG_UST_ABI_WAIT_QUIESCENT
;
846 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
849 DBG("waited for quiescent state");
853 int lttng_ust_ctl_calibrate(int sock
__attribute__((unused
)),
854 struct lttng_ust_abi_calibrate
*calibrate
)
862 int lttng_ust_ctl_sock_flush_buffer(int sock
, struct lttng_ust_abi_object_data
*object
)
864 struct ustcomm_ust_msg lum
;
865 struct ustcomm_ust_reply lur
;
871 memset(&lum
, 0, sizeof(lum
));
872 lum
.handle
= object
->handle
;
873 lum
.cmd
= LTTNG_UST_ABI_FLUSH_BUFFER
;
874 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
877 DBG("flushed buffer handle %u", object
->handle
);
882 int lttng_ust_ctl_send_channel(int sock
,
883 enum lttng_ust_abi_chan_type type
,
893 len
= ustcomm_send_unix_sock(sock
, &size
, sizeof(size
));
894 if (len
!= sizeof(size
)) {
901 /* Send channel type */
902 len
= ustcomm_send_unix_sock(sock
, &type
, sizeof(type
));
903 if (len
!= sizeof(type
)) {
911 /* Send channel data */
912 len
= ustcomm_send_unix_sock(sock
, data
, size
);
921 len
= ustcomm_send_fds_unix_sock(sock
, &wakeup_fd
, 1);
932 int lttng_ust_ctl_send_stream(int sock
,
934 uint64_t memory_map_size
,
935 int shm_fd
, int wakeup_fd
,
943 /* finish iteration */
946 len
= ustcomm_send_unix_sock(sock
, &v
, sizeof(v
));
947 if (len
!= sizeof(v
)) {
957 len
= ustcomm_send_unix_sock(sock
, &memory_map_size
,
958 sizeof(memory_map_size
));
959 if (len
!= sizeof(memory_map_size
)) {
967 len
= ustcomm_send_unix_sock(sock
, &stream_nr
,
969 if (len
!= sizeof(stream_nr
)) {
977 /* Send shm fd and wakeup fd */
980 len
= ustcomm_send_fds_unix_sock(sock
, fds
, 2);
990 int lttng_ust_ctl_recv_channel_from_consumer(int sock
,
991 struct lttng_ust_abi_object_data
**_channel_data
)
993 struct lttng_ust_abi_object_data
*channel_data
;
998 channel_data
= zmalloc(sizeof(*channel_data
));
1003 channel_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_CHANNEL
;
1004 channel_data
->handle
= -1;
1006 /* recv mmap size */
1007 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->size
,
1008 sizeof(channel_data
->size
));
1009 if (len
!= sizeof(channel_data
->size
)) {
1017 /* recv channel type */
1018 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->u
.channel
.type
,
1019 sizeof(channel_data
->u
.channel
.type
));
1020 if (len
!= sizeof(channel_data
->u
.channel
.type
)) {
1028 /* recv channel data */
1029 channel_data
->u
.channel
.data
= zmalloc(channel_data
->size
);
1030 if (!channel_data
->u
.channel
.data
) {
1034 len
= ustcomm_recv_unix_sock(sock
, channel_data
->u
.channel
.data
,
1035 channel_data
->size
);
1036 if (len
!= channel_data
->size
) {
1041 goto error_recv_data
;
1043 /* recv wakeup fd */
1044 len
= ustcomm_recv_fds_unix_sock(sock
, &wakeup_fd
, 1);
1048 goto error_recv_data
;
1051 goto error_recv_data
;
1054 channel_data
->u
.channel
.wakeup_fd
= wakeup_fd
;
1055 *_channel_data
= channel_data
;
1059 free(channel_data
->u
.channel
.data
);
1066 int lttng_ust_ctl_recv_stream_from_consumer(int sock
,
1067 struct lttng_ust_abi_object_data
**_stream_data
)
1069 struct lttng_ust_abi_object_data
*stream_data
;
1074 stream_data
= zmalloc(sizeof(*stream_data
));
1080 stream_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_STREAM
;
1081 stream_data
->handle
= -1;
1083 /* recv mmap size */
1084 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->size
,
1085 sizeof(stream_data
->size
));
1086 if (len
!= sizeof(stream_data
->size
)) {
1093 if (stream_data
->size
== -1) {
1094 ret
= -LTTNG_UST_ERR_NOENT
;
1098 /* recv stream nr */
1099 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->u
.stream
.stream_nr
,
1100 sizeof(stream_data
->u
.stream
.stream_nr
));
1101 if (len
!= sizeof(stream_data
->u
.stream
.stream_nr
)) {
1109 /* recv shm fd and wakeup fd */
1110 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 2);
1120 stream_data
->u
.stream
.shm_fd
= fds
[0];
1121 stream_data
->u
.stream
.wakeup_fd
= fds
[1];
1122 *_stream_data
= stream_data
;
1132 * Protocol for LTTNG_UST_ABI_CHANNEL command:
1134 * - send: struct ustcomm_ust_msg
1135 * - send: file descriptors and channel data
1136 * - receive: struct ustcomm_ust_reply
1138 * TODO: At the next breaking protocol bump, we should indicate the total
1139 * command message length as part of a message header so that the protocol can
1140 * recover from invalid command errors.
1142 int lttng_ust_ctl_send_channel_to_ust(int sock
, int session_handle
,
1143 struct lttng_ust_abi_object_data
*channel_data
)
1145 struct ustcomm_ust_msg lum
;
1146 struct ustcomm_ust_reply lur
;
1152 memset(&lum
, 0, sizeof(lum
));
1153 lum
.handle
= session_handle
;
1154 lum
.cmd
= LTTNG_UST_ABI_CHANNEL
;
1155 lum
.u
.channel
.len
= channel_data
->size
;
1156 lum
.u
.channel
.type
= channel_data
->u
.channel
.type
;
1157 ret
= ustcomm_send_app_msg(sock
, &lum
);
1161 ret
= lttng_ust_ctl_send_channel(sock
,
1162 channel_data
->u
.channel
.type
,
1163 channel_data
->u
.channel
.data
,
1165 channel_data
->u
.channel
.wakeup_fd
,
1169 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
1171 channel_data
->handle
= lur
.ret_val
;
1172 } else if (ret
== -EINVAL
) {
1174 * Command unknown from remote end. The communication socket is
1175 * now out-of-sync and needs to be shutdown.
1177 (void) ustcomm_shutdown_unix_sock(sock
);
1183 * Protocol for LTTNG_UST_ABI_STREAM command:
1185 * - send: struct ustcomm_ust_msg
1186 * - send: file descriptors and stream data
1187 * - receive: struct ustcomm_ust_reply
1189 * TODO: At the next breaking protocol bump, we should indicate the total
1190 * command message length as part of a message header so that the protocol can
1191 * recover from invalid command errors.
1193 int lttng_ust_ctl_send_stream_to_ust(int sock
,
1194 struct lttng_ust_abi_object_data
*channel_data
,
1195 struct lttng_ust_abi_object_data
*stream_data
)
1197 struct ustcomm_ust_msg lum
;
1198 struct ustcomm_ust_reply lur
;
1201 memset(&lum
, 0, sizeof(lum
));
1202 lum
.handle
= channel_data
->handle
;
1203 lum
.cmd
= LTTNG_UST_ABI_STREAM
;
1204 lum
.u
.stream
.len
= stream_data
->size
;
1205 lum
.u
.stream
.stream_nr
= stream_data
->u
.stream
.stream_nr
;
1206 ret
= ustcomm_send_app_msg(sock
, &lum
);
1210 assert(stream_data
);
1211 assert(stream_data
->type
== LTTNG_UST_ABI_OBJECT_TYPE_STREAM
);
1213 ret
= lttng_ust_ctl_send_stream(sock
,
1214 stream_data
->u
.stream
.stream_nr
,
1216 stream_data
->u
.stream
.shm_fd
,
1217 stream_data
->u
.stream
.wakeup_fd
, 1);
1220 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
1221 if (ret
== -EINVAL
) {
1223 * Command unknown from remote end. The communication socket is
1224 * now out-of-sync and needs to be shutdown.
1226 (void) ustcomm_shutdown_unix_sock(sock
);
1231 int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data
**dest
,
1232 struct lttng_ust_abi_object_data
*src
)
1234 struct lttng_ust_abi_object_data
*obj
;
1237 if (src
->handle
!= -1) {
1242 obj
= zmalloc(sizeof(*obj
));
1248 obj
->type
= src
->type
;
1249 obj
->handle
= src
->handle
;
1250 obj
->size
= src
->size
;
1252 switch (obj
->type
) {
1253 case LTTNG_UST_ABI_OBJECT_TYPE_CHANNEL
:
1255 obj
->u
.channel
.type
= src
->u
.channel
.type
;
1256 if (src
->u
.channel
.wakeup_fd
>= 0) {
1257 obj
->u
.channel
.wakeup_fd
=
1258 dup(src
->u
.channel
.wakeup_fd
);
1259 if (obj
->u
.channel
.wakeup_fd
< 0) {
1261 goto chan_error_wakeup_fd
;
1264 obj
->u
.channel
.wakeup_fd
=
1265 src
->u
.channel
.wakeup_fd
;
1267 obj
->u
.channel
.data
= zmalloc(obj
->size
);
1268 if (!obj
->u
.channel
.data
) {
1270 goto chan_error_alloc
;
1272 memcpy(obj
->u
.channel
.data
, src
->u
.channel
.data
, obj
->size
);
1276 if (src
->u
.channel
.wakeup_fd
>= 0) {
1279 closeret
= close(obj
->u
.channel
.wakeup_fd
);
1284 chan_error_wakeup_fd
:
1289 case LTTNG_UST_ABI_OBJECT_TYPE_STREAM
:
1291 obj
->u
.stream
.stream_nr
= src
->u
.stream
.stream_nr
;
1292 if (src
->u
.stream
.wakeup_fd
>= 0) {
1293 obj
->u
.stream
.wakeup_fd
=
1294 dup(src
->u
.stream
.wakeup_fd
);
1295 if (obj
->u
.stream
.wakeup_fd
< 0) {
1297 goto stream_error_wakeup_fd
;
1300 obj
->u
.stream
.wakeup_fd
=
1301 src
->u
.stream
.wakeup_fd
;
1304 if (src
->u
.stream
.shm_fd
>= 0) {
1305 obj
->u
.stream
.shm_fd
=
1306 dup(src
->u
.stream
.shm_fd
);
1307 if (obj
->u
.stream
.shm_fd
< 0) {
1309 goto stream_error_shm_fd
;
1312 obj
->u
.stream
.shm_fd
=
1313 src
->u
.stream
.shm_fd
;
1317 stream_error_shm_fd
:
1318 if (src
->u
.stream
.wakeup_fd
>= 0) {
1321 closeret
= close(obj
->u
.stream
.wakeup_fd
);
1326 stream_error_wakeup_fd
:
1330 case LTTNG_UST_ABI_OBJECT_TYPE_COUNTER
:
1332 obj
->u
.counter
.data
= zmalloc(obj
->size
);
1333 if (!obj
->u
.counter
.data
) {
1337 memcpy(obj
->u
.counter
.data
, src
->u
.counter
.data
, obj
->size
);
1341 case LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_GLOBAL
:
1343 if (src
->u
.counter_global
.shm_fd
>= 0) {
1344 obj
->u
.counter_global
.shm_fd
=
1345 dup(src
->u
.counter_global
.shm_fd
);
1346 if (obj
->u
.counter_global
.shm_fd
< 0) {
1354 case LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_CPU
:
1356 obj
->u
.counter_cpu
.cpu_nr
= src
->u
.counter_cpu
.cpu_nr
;
1357 if (src
->u
.counter_cpu
.shm_fd
>= 0) {
1358 obj
->u
.counter_cpu
.shm_fd
=
1359 dup(src
->u
.counter_cpu
.shm_fd
);
1360 if (obj
->u
.counter_cpu
.shm_fd
< 0) {
1383 /* Buffer operations */
1385 int lttng_ust_ctl_get_nr_stream_per_channel(void)
1387 return num_possible_cpus();
1390 struct lttng_ust_ctl_consumer_channel
*
1391 lttng_ust_ctl_create_channel(struct lttng_ust_ctl_consumer_channel_attr
*attr
,
1392 const int *stream_fds
, int nr_stream_fds
)
1394 struct lttng_ust_ctl_consumer_channel
*chan
;
1395 const char *transport_name
;
1396 struct lttng_transport
*transport
;
1398 switch (attr
->type
) {
1399 case LTTNG_UST_ABI_CHAN_PER_CPU
:
1400 if (attr
->output
== LTTNG_UST_ABI_MMAP
) {
1401 if (attr
->overwrite
) {
1402 if (attr
->read_timer_interval
== 0) {
1403 transport_name
= "relay-overwrite-mmap";
1405 transport_name
= "relay-overwrite-rt-mmap";
1408 if (attr
->read_timer_interval
== 0) {
1409 transport_name
= "relay-discard-mmap";
1411 transport_name
= "relay-discard-rt-mmap";
1418 case LTTNG_UST_ABI_CHAN_METADATA
:
1419 if (attr
->output
== LTTNG_UST_ABI_MMAP
)
1420 transport_name
= "relay-metadata-mmap";
1425 transport_name
= "<unknown>";
1429 transport
= lttng_ust_transport_find(transport_name
);
1431 DBG("LTTng transport %s not found\n",
1436 chan
= zmalloc(sizeof(*chan
));
1440 chan
->chan
= transport
->ops
.priv
->channel_create(transport_name
, NULL
,
1441 attr
->subbuf_size
, attr
->num_subbuf
,
1442 attr
->switch_timer_interval
,
1443 attr
->read_timer_interval
,
1444 attr
->uuid
, attr
->chan_id
,
1445 stream_fds
, nr_stream_fds
,
1446 attr
->blocking_timeout
);
1450 chan
->chan
->ops
= &transport
->ops
;
1451 memcpy(&chan
->attr
, attr
, sizeof(chan
->attr
));
1452 chan
->wait_fd
= lttng_ust_ctl_channel_get_wait_fd(chan
);
1453 chan
->wakeup_fd
= lttng_ust_ctl_channel_get_wakeup_fd(chan
);
1461 void lttng_ust_ctl_destroy_channel(struct lttng_ust_ctl_consumer_channel
*chan
)
1463 (void) lttng_ust_ctl_channel_close_wait_fd(chan
);
1464 (void) lttng_ust_ctl_channel_close_wakeup_fd(chan
);
1465 chan
->chan
->ops
->priv
->channel_destroy(chan
->chan
);
1469 int lttng_ust_ctl_send_channel_to_sessiond(int sock
,
1470 struct lttng_ust_ctl_consumer_channel
*channel
)
1472 struct shm_object_table
*table
;
1474 table
= channel
->chan
->priv
->rb_chan
->handle
->table
;
1475 if (table
->size
<= 0)
1477 return lttng_ust_ctl_send_channel(sock
,
1479 table
->objects
[0].memory_map
,
1480 table
->objects
[0].memory_map_size
,
1485 int lttng_ust_ctl_send_stream_to_sessiond(int sock
,
1486 struct lttng_ust_ctl_consumer_stream
*stream
)
1489 return lttng_ust_ctl_send_stream(sock
, -1U, -1U, -1, -1, 0);
1491 return lttng_ust_ctl_send_stream(sock
,
1493 stream
->memory_map_size
,
1494 stream
->shm_fd
, stream
->wakeup_fd
,
1498 int lttng_ust_ctl_write_metadata_to_channel(
1499 struct lttng_ust_ctl_consumer_channel
*channel
,
1500 const char *metadata_str
, /* NOT null-terminated */
1501 size_t len
) /* metadata length */
1503 struct lttng_ust_ring_buffer_ctx ctx
;
1504 struct lttng_ust_channel_buffer
*lttng_chan_buf
= channel
->chan
;
1505 struct lttng_ust_ring_buffer_channel
*rb_chan
= lttng_chan_buf
->priv
->rb_chan
;
1506 const char *str
= metadata_str
;
1507 int ret
= 0, waitret
;
1508 size_t reserve_len
, pos
;
1510 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
1511 reserve_len
= min_t(size_t,
1512 lttng_chan_buf
->ops
->priv
->packet_avail_size(lttng_chan_buf
),
1514 lttng_ust_ring_buffer_ctx_init(&ctx
, rb_chan
, reserve_len
, sizeof(char), NULL
);
1516 * We don't care about metadata buffer's records lost
1517 * count, because we always retry here. Report error if
1518 * we need to bail out after timeout or being
1521 waitret
= wait_cond_interruptible_timeout(
1523 ret
= lttng_chan_buf
->ops
->event_reserve(&ctx
);
1524 ret
!= -ENOBUFS
|| !ret
;
1526 LTTNG_METADATA_TIMEOUT_MSEC
);
1527 if (waitret
== -ETIMEDOUT
|| waitret
== -EINTR
|| ret
) {
1528 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
1529 waitret
== -EINTR
? "interrupted" :
1530 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
1531 if (waitret
== -EINTR
)
1535 lttng_chan_buf
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
, 1);
1536 lttng_chan_buf
->ops
->event_commit(&ctx
);
1543 * Write at most one packet in the channel.
1544 * Returns the number of bytes written on success, < 0 on error.
1546 ssize_t
lttng_ust_ctl_write_one_packet_to_channel(
1547 struct lttng_ust_ctl_consumer_channel
*channel
,
1548 const char *metadata_str
, /* NOT null-terminated */
1549 size_t len
) /* metadata length */
1551 struct lttng_ust_ring_buffer_ctx ctx
;
1552 struct lttng_ust_channel_buffer
*lttng_chan_buf
= channel
->chan
;
1553 struct lttng_ust_ring_buffer_channel
*rb_chan
= lttng_chan_buf
->priv
->rb_chan
;
1554 const char *str
= metadata_str
;
1555 ssize_t reserve_len
;
1558 reserve_len
= min_t(ssize_t
,
1559 lttng_chan_buf
->ops
->priv
->packet_avail_size(lttng_chan_buf
),
1561 lttng_ust_ring_buffer_ctx_init(&ctx
, rb_chan
, reserve_len
, sizeof(char), NULL
);
1562 ret
= lttng_chan_buf
->ops
->event_reserve(&ctx
);
1564 DBG("LTTng: event reservation failed");
1569 lttng_chan_buf
->ops
->event_write(&ctx
, str
, reserve_len
, 1);
1570 lttng_chan_buf
->ops
->event_commit(&ctx
);
1576 int lttng_ust_ctl_channel_close_wait_fd(struct lttng_ust_ctl_consumer_channel
*consumer_chan
)
1578 struct lttng_ust_ring_buffer_channel
*chan
;
1581 chan
= consumer_chan
->chan
->priv
->rb_chan
;
1582 ret
= ring_buffer_channel_close_wait_fd(&chan
->backend
.config
,
1583 chan
, chan
->handle
);
1585 consumer_chan
->wait_fd
= -1;
1589 int lttng_ust_ctl_channel_close_wakeup_fd(struct lttng_ust_ctl_consumer_channel
*consumer_chan
)
1591 struct lttng_ust_ring_buffer_channel
*chan
;
1594 chan
= consumer_chan
->chan
->priv
->rb_chan
;
1595 ret
= ring_buffer_channel_close_wakeup_fd(&chan
->backend
.config
,
1596 chan
, chan
->handle
);
1598 consumer_chan
->wakeup_fd
= -1;
1602 int lttng_ust_ctl_stream_close_wait_fd(struct lttng_ust_ctl_consumer_stream
*stream
)
1604 struct lttng_ust_ring_buffer_channel
*chan
;
1606 chan
= stream
->chan
->chan
->priv
->rb_chan
;
1607 return ring_buffer_stream_close_wait_fd(&chan
->backend
.config
,
1608 chan
, chan
->handle
, stream
->cpu
);
1611 int lttng_ust_ctl_stream_close_wakeup_fd(struct lttng_ust_ctl_consumer_stream
*stream
)
1613 struct lttng_ust_ring_buffer_channel
*chan
;
1615 chan
= stream
->chan
->chan
->priv
->rb_chan
;
1616 return ring_buffer_stream_close_wakeup_fd(&chan
->backend
.config
,
1617 chan
, chan
->handle
, stream
->cpu
);
1620 struct lttng_ust_ctl_consumer_stream
*
1621 lttng_ust_ctl_create_stream(struct lttng_ust_ctl_consumer_channel
*channel
,
1624 struct lttng_ust_ctl_consumer_stream
*stream
;
1625 struct lttng_ust_shm_handle
*handle
;
1626 struct lttng_ust_ring_buffer_channel
*rb_chan
;
1627 int shm_fd
, wait_fd
, wakeup_fd
;
1628 uint64_t memory_map_size
;
1629 void *memory_map_addr
;
1630 struct lttng_ust_ring_buffer
*buf
;
1635 rb_chan
= channel
->chan
->priv
->rb_chan
;
1636 handle
= rb_chan
->handle
;
1640 buf
= channel_get_ring_buffer(&rb_chan
->backend
.config
,
1641 rb_chan
, cpu
, handle
, &shm_fd
, &wait_fd
,
1642 &wakeup_fd
, &memory_map_size
, &memory_map_addr
);
1645 ret
= lib_ring_buffer_open_read(buf
, handle
);
1649 stream
= zmalloc(sizeof(*stream
));
1653 stream
->chan
= channel
;
1654 stream
->shm_fd
= shm_fd
;
1655 stream
->wait_fd
= wait_fd
;
1656 stream
->wakeup_fd
= wakeup_fd
;
1657 stream
->memory_map_size
= memory_map_size
;
1658 stream
->memory_map_addr
= memory_map_addr
;
1666 void lttng_ust_ctl_destroy_stream(struct lttng_ust_ctl_consumer_stream
*stream
)
1668 struct lttng_ust_ring_buffer
*buf
;
1669 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1673 consumer_chan
= stream
->chan
;
1674 (void) lttng_ust_ctl_stream_close_wait_fd(stream
);
1675 (void) lttng_ust_ctl_stream_close_wakeup_fd(stream
);
1676 lib_ring_buffer_release_read(buf
, consumer_chan
->chan
->priv
->rb_chan
->handle
);
1680 int lttng_ust_ctl_channel_get_wait_fd(struct lttng_ust_ctl_consumer_channel
*chan
)
1684 return shm_get_wait_fd(chan
->chan
->priv
->rb_chan
->handle
,
1685 &chan
->chan
->priv
->rb_chan
->handle
->chan
._ref
);
1688 int lttng_ust_ctl_channel_get_wakeup_fd(struct lttng_ust_ctl_consumer_channel
*chan
)
1692 return shm_get_wakeup_fd(chan
->chan
->priv
->rb_chan
->handle
,
1693 &chan
->chan
->priv
->rb_chan
->handle
->chan
._ref
);
1696 int lttng_ust_ctl_stream_get_wait_fd(struct lttng_ust_ctl_consumer_stream
*stream
)
1698 struct lttng_ust_ring_buffer
*buf
;
1699 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1704 consumer_chan
= stream
->chan
;
1705 return shm_get_wait_fd(consumer_chan
->chan
->priv
->rb_chan
->handle
, &buf
->self
._ref
);
1708 int lttng_ust_ctl_stream_get_wakeup_fd(struct lttng_ust_ctl_consumer_stream
*stream
)
1710 struct lttng_ust_ring_buffer
*buf
;
1711 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1716 consumer_chan
= stream
->chan
;
1717 return shm_get_wakeup_fd(consumer_chan
->chan
->priv
->rb_chan
->handle
, &buf
->self
._ref
);
1720 /* For mmap mode, readable without "get" operation */
1722 void *lttng_ust_ctl_get_mmap_base(struct lttng_ust_ctl_consumer_stream
*stream
)
1724 struct lttng_ust_ring_buffer
*buf
;
1725 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1726 struct lttng_ust_sigbus_range range
;
1732 consumer_chan
= stream
->chan
;
1735 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1736 stream
->memory_map_size
);
1737 p
= shmp(consumer_chan
->chan
->priv
->rb_chan
->handle
, buf
->backend
.memory_map
);
1738 lttng_ust_sigbus_del_range(&range
);
1740 return p
; /* Users of this pointer should check for sigbus. */
1743 /* returns the length to mmap. */
1744 int lttng_ust_ctl_get_mmap_len(struct lttng_ust_ctl_consumer_stream
*stream
,
1747 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1748 unsigned long mmap_buf_len
;
1749 struct lttng_ust_ring_buffer_channel
*rb_chan
;
1753 consumer_chan
= stream
->chan
;
1754 rb_chan
= consumer_chan
->chan
->priv
->rb_chan
;
1755 if (rb_chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1757 mmap_buf_len
= rb_chan
->backend
.buf_size
;
1758 if (rb_chan
->backend
.extra_reader_sb
)
1759 mmap_buf_len
+= rb_chan
->backend
.subbuf_size
;
1760 if (mmap_buf_len
> INT_MAX
)
1762 *len
= mmap_buf_len
;
1766 /* returns the maximum size for sub-buffers. */
1767 int lttng_ust_ctl_get_max_subbuf_size(struct lttng_ust_ctl_consumer_stream
*stream
,
1770 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1771 struct lttng_ust_ring_buffer_channel
*rb_chan
;
1775 consumer_chan
= stream
->chan
;
1776 rb_chan
= consumer_chan
->chan
->priv
->rb_chan
;
1777 *len
= rb_chan
->backend
.subbuf_size
;
1782 * For mmap mode, operate on the current packet (between get/put or
1783 * get_next/put_next).
1786 /* returns the offset of the subbuffer belonging to the mmap reader. */
1787 int lttng_ust_ctl_get_mmap_read_offset(struct lttng_ust_ctl_consumer_stream
*stream
,
1790 struct lttng_ust_ring_buffer_channel
*rb_chan
;
1791 unsigned long sb_bindex
;
1792 struct lttng_ust_ring_buffer
*buf
;
1793 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1794 struct lttng_ust_ring_buffer_backend_pages_shmp
*barray_idx
;
1795 struct lttng_ust_ring_buffer_backend_pages
*pages
;
1796 struct lttng_ust_sigbus_range range
;
1802 consumer_chan
= stream
->chan
;
1803 rb_chan
= consumer_chan
->chan
->priv
->rb_chan
;
1804 if (rb_chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1810 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1811 stream
->memory_map_size
);
1813 sb_bindex
= subbuffer_id_get_index(&rb_chan
->backend
.config
,
1814 buf
->backend
.buf_rsb
.id
);
1815 barray_idx
= shmp_index(rb_chan
->handle
, buf
->backend
.array
,
1821 pages
= shmp(rb_chan
->handle
, barray_idx
->shmp
);
1826 *off
= pages
->mmap_offset
;
1828 lttng_ust_sigbus_del_range(&range
);
1833 /* returns the size of the current sub-buffer, without padding (for mmap). */
1834 int lttng_ust_ctl_get_subbuf_size(struct lttng_ust_ctl_consumer_stream
*stream
,
1837 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1838 struct lttng_ust_ring_buffer_channel
*rb_chan
;
1839 struct lttng_ust_ring_buffer
*buf
;
1840 struct lttng_ust_sigbus_range range
;
1846 consumer_chan
= stream
->chan
;
1847 rb_chan
= consumer_chan
->chan
->priv
->rb_chan
;
1850 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1851 stream
->memory_map_size
);
1852 *len
= lib_ring_buffer_get_read_data_size(&rb_chan
->backend
.config
, buf
,
1854 lttng_ust_sigbus_del_range(&range
);
1859 /* returns the size of the current sub-buffer, without padding (for mmap). */
1860 int lttng_ust_ctl_get_padded_subbuf_size(struct lttng_ust_ctl_consumer_stream
*stream
,
1863 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1864 struct lttng_ust_ring_buffer_channel
*rb_chan
;
1865 struct lttng_ust_ring_buffer
*buf
;
1866 struct lttng_ust_sigbus_range range
;
1871 consumer_chan
= stream
->chan
;
1872 rb_chan
= consumer_chan
->chan
->priv
->rb_chan
;
1875 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1876 stream
->memory_map_size
);
1877 *len
= lib_ring_buffer_get_read_data_size(&rb_chan
->backend
.config
, buf
,
1879 *len
= LTTNG_UST_PAGE_ALIGN(*len
);
1880 lttng_ust_sigbus_del_range(&range
);
1885 /* Get exclusive read access to the next sub-buffer that can be read. */
1886 int lttng_ust_ctl_get_next_subbuf(struct lttng_ust_ctl_consumer_stream
*stream
)
1888 struct lttng_ust_ring_buffer
*buf
;
1889 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1890 struct lttng_ust_sigbus_range range
;
1896 consumer_chan
= stream
->chan
;
1899 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1900 stream
->memory_map_size
);
1901 ret
= lib_ring_buffer_get_next_subbuf(buf
,
1902 consumer_chan
->chan
->priv
->rb_chan
->handle
);
1903 lttng_ust_sigbus_del_range(&range
);
1908 /* Release exclusive sub-buffer access, move consumer forward. */
1909 int lttng_ust_ctl_put_next_subbuf(struct lttng_ust_ctl_consumer_stream
*stream
)
1911 struct lttng_ust_ring_buffer
*buf
;
1912 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1913 struct lttng_ust_sigbus_range range
;
1918 consumer_chan
= stream
->chan
;
1921 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1922 stream
->memory_map_size
);
1923 lib_ring_buffer_put_next_subbuf(buf
, consumer_chan
->chan
->priv
->rb_chan
->handle
);
1924 lttng_ust_sigbus_del_range(&range
);
1931 /* Get a snapshot of the current ring buffer producer and consumer positions */
1932 int lttng_ust_ctl_snapshot(struct lttng_ust_ctl_consumer_stream
*stream
)
1934 struct lttng_ust_ring_buffer
*buf
;
1935 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1936 struct lttng_ust_sigbus_range range
;
1942 consumer_chan
= stream
->chan
;
1945 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1946 stream
->memory_map_size
);
1947 ret
= lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
1948 &buf
->prod_snapshot
, consumer_chan
->chan
->priv
->rb_chan
->handle
);
1949 lttng_ust_sigbus_del_range(&range
);
1955 * Get a snapshot of the current ring buffer producer and consumer positions
1956 * even if the consumed and produced positions are contained within the same
1959 int lttng_ust_ctl_snapshot_sample_positions(struct lttng_ust_ctl_consumer_stream
*stream
)
1961 struct lttng_ust_ring_buffer
*buf
;
1962 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
1963 struct lttng_ust_sigbus_range range
;
1969 consumer_chan
= stream
->chan
;
1972 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
1973 stream
->memory_map_size
);
1974 ret
= lib_ring_buffer_snapshot_sample_positions(buf
,
1975 &buf
->cons_snapshot
, &buf
->prod_snapshot
,
1976 consumer_chan
->chan
->priv
->rb_chan
->handle
);
1977 lttng_ust_sigbus_del_range(&range
);
1982 /* Get the consumer position (iteration start) */
1983 int lttng_ust_ctl_snapshot_get_consumed(struct lttng_ust_ctl_consumer_stream
*stream
,
1986 struct lttng_ust_ring_buffer
*buf
;
1991 *pos
= buf
->cons_snapshot
;
1995 /* Get the producer position (iteration end) */
1996 int lttng_ust_ctl_snapshot_get_produced(struct lttng_ust_ctl_consumer_stream
*stream
,
1999 struct lttng_ust_ring_buffer
*buf
;
2004 *pos
= buf
->prod_snapshot
;
2008 /* Get exclusive read access to the specified sub-buffer position */
2009 int lttng_ust_ctl_get_subbuf(struct lttng_ust_ctl_consumer_stream
*stream
,
2012 struct lttng_ust_ring_buffer
*buf
;
2013 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
2014 struct lttng_ust_sigbus_range range
;
2020 consumer_chan
= stream
->chan
;
2023 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2024 stream
->memory_map_size
);
2025 ret
= lib_ring_buffer_get_subbuf(buf
, *pos
,
2026 consumer_chan
->chan
->priv
->rb_chan
->handle
);
2027 lttng_ust_sigbus_del_range(&range
);
2032 /* Release exclusive sub-buffer access */
2033 int lttng_ust_ctl_put_subbuf(struct lttng_ust_ctl_consumer_stream
*stream
)
2035 struct lttng_ust_ring_buffer
*buf
;
2036 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
2037 struct lttng_ust_sigbus_range range
;
2042 consumer_chan
= stream
->chan
;
2045 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2046 stream
->memory_map_size
);
2047 lib_ring_buffer_put_subbuf(buf
, consumer_chan
->chan
->priv
->rb_chan
->handle
);
2048 lttng_ust_sigbus_del_range(&range
);
2053 int lttng_ust_ctl_flush_buffer(struct lttng_ust_ctl_consumer_stream
*stream
,
2054 int producer_active
)
2056 struct lttng_ust_ring_buffer
*buf
;
2057 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
2058 struct lttng_ust_sigbus_range range
;
2062 consumer_chan
= stream
->chan
;
2065 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2066 stream
->memory_map_size
);
2067 lib_ring_buffer_switch_slow(buf
,
2068 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,
2069 consumer_chan
->chan
->priv
->rb_chan
->handle
);
2070 lttng_ust_sigbus_del_range(&range
);
2075 int lttng_ust_ctl_clear_buffer(struct lttng_ust_ctl_consumer_stream
*stream
)
2077 struct lttng_ust_ring_buffer
*buf
;
2078 struct lttng_ust_ctl_consumer_channel
*consumer_chan
;
2079 struct lttng_ust_sigbus_range range
;
2083 consumer_chan
= stream
->chan
;
2086 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2087 stream
->memory_map_size
);
2088 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
,
2089 consumer_chan
->chan
->priv
->rb_chan
->handle
);
2090 lib_ring_buffer_clear_reader(buf
, consumer_chan
->chan
->priv
->rb_chan
->handle
);
2091 lttng_ust_sigbus_del_range(&range
);
2097 struct lttng_ust_client_lib_ring_buffer_client_cb
*get_client_cb(
2098 struct lttng_ust_ring_buffer
*buf
__attribute__((unused
)),
2099 struct lttng_ust_ring_buffer_channel
*chan
)
2101 const struct lttng_ust_ring_buffer_config
*config
;
2102 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2104 config
= &chan
->backend
.config
;
2105 if (!config
->cb_ptr
)
2107 client_cb
= caa_container_of(config
->cb_ptr
,
2108 struct lttng_ust_client_lib_ring_buffer_client_cb
,
2113 int lttng_ust_ctl_get_timestamp_begin(struct lttng_ust_ctl_consumer_stream
*stream
,
2114 uint64_t *timestamp_begin
)
2116 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2117 struct lttng_ust_ring_buffer_channel
*chan
;
2118 struct lttng_ust_ring_buffer
*buf
;
2119 struct lttng_ust_sigbus_range range
;
2122 if (!stream
|| !timestamp_begin
)
2125 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2126 client_cb
= get_client_cb(buf
, chan
);
2131 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2132 stream
->memory_map_size
);
2133 ret
= client_cb
->timestamp_begin(buf
, chan
, timestamp_begin
);
2134 lttng_ust_sigbus_del_range(&range
);
2139 int lttng_ust_ctl_get_timestamp_end(struct lttng_ust_ctl_consumer_stream
*stream
,
2140 uint64_t *timestamp_end
)
2142 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2143 struct lttng_ust_ring_buffer_channel
*chan
;
2144 struct lttng_ust_ring_buffer
*buf
;
2145 struct lttng_ust_sigbus_range range
;
2148 if (!stream
|| !timestamp_end
)
2151 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2152 client_cb
= get_client_cb(buf
, chan
);
2157 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2158 stream
->memory_map_size
);
2159 ret
= client_cb
->timestamp_end(buf
, chan
, timestamp_end
);
2160 lttng_ust_sigbus_del_range(&range
);
2165 int lttng_ust_ctl_get_events_discarded(struct lttng_ust_ctl_consumer_stream
*stream
,
2166 uint64_t *events_discarded
)
2168 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2169 struct lttng_ust_ring_buffer_channel
*chan
;
2170 struct lttng_ust_ring_buffer
*buf
;
2171 struct lttng_ust_sigbus_range range
;
2174 if (!stream
|| !events_discarded
)
2177 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2178 client_cb
= get_client_cb(buf
, chan
);
2183 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2184 stream
->memory_map_size
);
2185 ret
= client_cb
->events_discarded(buf
, chan
, events_discarded
);
2186 lttng_ust_sigbus_del_range(&range
);
2191 int lttng_ust_ctl_get_content_size(struct lttng_ust_ctl_consumer_stream
*stream
,
2192 uint64_t *content_size
)
2194 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2195 struct lttng_ust_ring_buffer_channel
*chan
;
2196 struct lttng_ust_ring_buffer
*buf
;
2197 struct lttng_ust_sigbus_range range
;
2200 if (!stream
|| !content_size
)
2203 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2204 client_cb
= get_client_cb(buf
, chan
);
2209 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2210 stream
->memory_map_size
);
2211 ret
= client_cb
->content_size(buf
, chan
, content_size
);
2212 lttng_ust_sigbus_del_range(&range
);
2217 int lttng_ust_ctl_get_packet_size(struct lttng_ust_ctl_consumer_stream
*stream
,
2218 uint64_t *packet_size
)
2220 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2221 struct lttng_ust_ring_buffer_channel
*chan
;
2222 struct lttng_ust_ring_buffer
*buf
;
2223 struct lttng_ust_sigbus_range range
;
2226 if (!stream
|| !packet_size
)
2229 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2230 client_cb
= get_client_cb(buf
, chan
);
2235 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2236 stream
->memory_map_size
);
2237 ret
= client_cb
->packet_size(buf
, chan
, packet_size
);
2238 lttng_ust_sigbus_del_range(&range
);
2243 int lttng_ust_ctl_get_stream_id(struct lttng_ust_ctl_consumer_stream
*stream
,
2244 uint64_t *stream_id
)
2246 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2247 struct lttng_ust_ring_buffer_channel
*chan
;
2248 struct lttng_ust_ring_buffer
*buf
;
2249 struct lttng_ust_sigbus_range range
;
2252 if (!stream
|| !stream_id
)
2255 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2256 client_cb
= get_client_cb(buf
, chan
);
2261 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2262 stream
->memory_map_size
);
2263 ret
= client_cb
->stream_id(buf
, chan
, stream_id
);
2264 lttng_ust_sigbus_del_range(&range
);
2269 int lttng_ust_ctl_get_current_timestamp(struct lttng_ust_ctl_consumer_stream
*stream
,
2272 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2273 struct lttng_ust_ring_buffer_channel
*chan
;
2274 struct lttng_ust_ring_buffer
*buf
;
2275 struct lttng_ust_sigbus_range range
;
2281 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2282 client_cb
= get_client_cb(buf
, chan
);
2283 if (!client_cb
|| !client_cb
->current_timestamp
)
2287 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2288 stream
->memory_map_size
);
2289 ret
= client_cb
->current_timestamp(buf
, chan
, ts
);
2290 lttng_ust_sigbus_del_range(&range
);
2295 int lttng_ust_ctl_get_sequence_number(struct lttng_ust_ctl_consumer_stream
*stream
,
2298 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2299 struct lttng_ust_ring_buffer_channel
*chan
;
2300 struct lttng_ust_ring_buffer
*buf
;
2301 struct lttng_ust_sigbus_range range
;
2304 if (!stream
|| !seq
)
2307 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2308 client_cb
= get_client_cb(buf
, chan
);
2309 if (!client_cb
|| !client_cb
->sequence_number
)
2313 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2314 stream
->memory_map_size
);
2315 ret
= client_cb
->sequence_number(buf
, chan
, seq
);
2316 lttng_ust_sigbus_del_range(&range
);
2321 int lttng_ust_ctl_get_instance_id(struct lttng_ust_ctl_consumer_stream
*stream
,
2324 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
2325 struct lttng_ust_ring_buffer_channel
*chan
;
2326 struct lttng_ust_ring_buffer
*buf
;
2327 struct lttng_ust_sigbus_range range
;
2333 chan
= stream
->chan
->chan
->priv
->rb_chan
;
2334 client_cb
= get_client_cb(buf
, chan
);
2339 lttng_ust_sigbus_add_range(&range
, stream
->memory_map_addr
,
2340 stream
->memory_map_size
);
2341 ret
= client_cb
->instance_id(buf
, chan
, id
);
2342 lttng_ust_sigbus_del_range(&range
);
2347 #ifdef HAVE_LINUX_PERF_EVENT_H
2349 int lttng_ust_ctl_has_perf_counters(void)
2356 int lttng_ust_ctl_has_perf_counters(void)
2365 * Override application pid/uid/gid with unix socket credentials. If
2366 * the application announced a pid matching our view, it means it is
2367 * within the same pid namespace, so expose the ppid provided by the
2371 int get_cred(int sock
,
2372 const struct lttng_ust_ctl_reg_msg
*reg_msg
,
2379 socklen_t ucred_len
= sizeof(struct ucred
);
2382 ret
= getsockopt(sock
, SOL_SOCKET
, SO_PEERCRED
, &ucred
, &ucred_len
);
2384 return -LTTNG_UST_ERR_PEERCRED
;
2386 DBG("Unix socket peercred [ pid: %u, uid: %u, gid: %u ], "
2387 "application registered claiming [ pid: %u, ppid: %u, uid: %u, gid: %u ]",
2388 ucred
.pid
, ucred
.uid
, ucred
.gid
,
2389 reg_msg
->pid
, reg_msg
->ppid
, reg_msg
->uid
, reg_msg
->gid
);
2391 ERR("Unix socket credential pid=0. Refusing application in distinct, non-nested pid namespace.");
2392 return -LTTNG_UST_ERR_PEERCRED_PID
;
2397 if (ucred
.pid
== reg_msg
->pid
) {
2398 *ppid
= reg_msg
->ppid
;
2404 #elif defined(__FreeBSD__)
2405 #include <sys/ucred.h>
2409 * Override application uid/gid with unix socket credentials. Use the
2410 * first group of the cr_groups.
2411 * Use the pid and ppid provided by the application on registration.
2414 int get_cred(int sock
,
2415 const struct lttng_ust_ctl_reg_msg
*reg_msg
,
2421 struct xucred xucred
;
2422 socklen_t xucred_len
= sizeof(struct xucred
);
2425 ret
= getsockopt(sock
, SOL_SOCKET
, LOCAL_PEERCRED
, &xucred
, &xucred_len
);
2427 return -LTTNG_UST_ERR_PEERCRED
;
2429 if (xucred
.cr_version
!= XUCRED_VERSION
|| xucred
.cr_ngroups
< 1) {
2430 return -LTTNG_UST_ERR_PEERCRED
;
2432 DBG("Unix socket peercred [ uid: %u, gid: %u ], "
2433 "application registered claiming [ pid: %d, ppid: %d, uid: %u, gid: %u ]",
2434 xucred
.cr_uid
, xucred
.cr_groups
[0],
2435 reg_msg
->pid
, reg_msg
->ppid
, reg_msg
->uid
, reg_msg
->gid
);
2436 *pid
= reg_msg
->pid
;
2437 *ppid
= reg_msg
->ppid
;
2438 *uid
= xucred
.cr_uid
;
2439 *gid
= xucred
.cr_groups
[0];
2443 #warning "Using insecure fallback: trusting user id provided by registered applications. Please consider implementing use of unix socket credentials on your platform."
2445 int get_cred(int sock
,
2446 const struct lttng_ust_ctl_reg_msg
*reg_msg
,
2452 DBG("Application registered claiming [ pid: %u, ppid: %d, uid: %u, gid: %u ]",
2453 reg_msg
->pid
, reg_msg
->ppid
, reg_msg
->uid
, reg_msg
->gid
);
2454 *pid
= reg_msg
->pid
;
2455 *ppid
= reg_msg
->ppid
;
2456 *uid
= reg_msg
->uid
;
2457 *gid
= reg_msg
->gid
;
2463 * Returns 0 on success, negative error value on error.
2465 int lttng_ust_ctl_recv_reg_msg(int sock
,
2466 enum lttng_ust_ctl_socket_type
*type
,
2473 uint32_t *bits_per_long
,
2474 uint32_t *uint8_t_alignment
,
2475 uint32_t *uint16_t_alignment
,
2476 uint32_t *uint32_t_alignment
,
2477 uint32_t *uint64_t_alignment
,
2478 uint32_t *long_alignment
,
2483 struct lttng_ust_ctl_reg_msg reg_msg
;
2485 len
= ustcomm_recv_unix_sock(sock
, ®_msg
, sizeof(reg_msg
));
2486 if (len
> 0 && len
!= sizeof(reg_msg
))
2493 if (reg_msg
.magic
== LTTNG_UST_ABI_COMM_MAGIC
) {
2494 *byte_order
= LTTNG_UST_BYTE_ORDER
== LTTNG_UST_BIG_ENDIAN
?
2495 LTTNG_UST_BIG_ENDIAN
: LTTNG_UST_LITTLE_ENDIAN
;
2496 } else if (reg_msg
.magic
== lttng_ust_bswap_32(LTTNG_UST_ABI_COMM_MAGIC
)) {
2497 *byte_order
= LTTNG_UST_BYTE_ORDER
== LTTNG_UST_BIG_ENDIAN
?
2498 LTTNG_UST_LITTLE_ENDIAN
: LTTNG_UST_BIG_ENDIAN
;
2500 return -LTTNG_UST_ERR_INVAL_MAGIC
;
2502 switch (reg_msg
.socket_type
) {
2503 case 0: *type
= LTTNG_UST_CTL_SOCKET_CMD
;
2505 case 1: *type
= LTTNG_UST_CTL_SOCKET_NOTIFY
;
2508 return -LTTNG_UST_ERR_INVAL_SOCKET_TYPE
;
2510 *major
= reg_msg
.major
;
2511 *minor
= reg_msg
.minor
;
2512 *bits_per_long
= reg_msg
.bits_per_long
;
2513 *uint8_t_alignment
= reg_msg
.uint8_t_alignment
;
2514 *uint16_t_alignment
= reg_msg
.uint16_t_alignment
;
2515 *uint32_t_alignment
= reg_msg
.uint32_t_alignment
;
2516 *uint64_t_alignment
= reg_msg
.uint64_t_alignment
;
2517 *long_alignment
= reg_msg
.long_alignment
;
2518 memcpy(name
, reg_msg
.name
, LTTNG_UST_ABI_PROCNAME_LEN
);
2519 if (reg_msg
.major
< LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE
||
2520 reg_msg
.major
> LTTNG_UST_ABI_MAJOR_VERSION
) {
2521 return -LTTNG_UST_ERR_UNSUP_MAJOR
;
2523 return get_cred(sock
, ®_msg
, pid
, ppid
, uid
, gid
);
2526 int lttng_ust_ctl_recv_notify(int sock
, enum lttng_ust_ctl_notify_cmd
*notify_cmd
)
2528 struct ustcomm_notify_hdr header
;
2531 len
= ustcomm_recv_unix_sock(sock
, &header
, sizeof(header
));
2532 if (len
> 0 && len
!= sizeof(header
))
2538 switch (header
.notify_cmd
) {
2540 *notify_cmd
= LTTNG_UST_CTL_NOTIFY_CMD_EVENT
;
2543 *notify_cmd
= LTTNG_UST_CTL_NOTIFY_CMD_CHANNEL
;
2546 *notify_cmd
= LTTNG_UST_CTL_NOTIFY_CMD_ENUM
;
2555 * Returns 0 on success, negative error value on error.
2557 int lttng_ust_ctl_recv_register_event(int sock
,
2564 struct lttng_ust_ctl_field
**fields
,
2565 char **model_emf_uri
)
2568 struct ustcomm_notify_event_msg msg
;
2569 size_t signature_len
, fields_len
, model_emf_uri_len
;
2570 char *a_sign
= NULL
, *a_model_emf_uri
= NULL
;
2571 struct lttng_ust_ctl_field
*a_fields
= NULL
;
2573 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
2574 if (len
> 0 && len
!= sizeof(msg
))
2581 *session_objd
= msg
.session_objd
;
2582 *channel_objd
= msg
.channel_objd
;
2583 strncpy(event_name
, msg
.event_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
2584 event_name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
2585 *loglevel
= msg
.loglevel
;
2586 signature_len
= msg
.signature_len
;
2587 fields_len
= msg
.fields_len
;
2589 if (fields_len
% sizeof(*a_fields
) != 0) {
2593 model_emf_uri_len
= msg
.model_emf_uri_len
;
2595 /* recv signature. contains at least \0. */
2596 a_sign
= zmalloc(signature_len
);
2599 len
= ustcomm_recv_unix_sock(sock
, a_sign
, signature_len
);
2600 if (len
> 0 && len
!= signature_len
) {
2602 goto signature_error
;
2606 goto signature_error
;
2609 goto signature_error
;
2611 /* Enforce end of string */
2612 a_sign
[signature_len
- 1] = '\0';
2616 a_fields
= zmalloc(fields_len
);
2619 goto signature_error
;
2621 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
2622 if (len
> 0 && len
!= fields_len
) {
2635 if (model_emf_uri_len
) {
2636 /* recv model_emf_uri_len */
2637 a_model_emf_uri
= zmalloc(model_emf_uri_len
);
2638 if (!a_model_emf_uri
) {
2642 len
= ustcomm_recv_unix_sock(sock
, a_model_emf_uri
,
2644 if (len
> 0 && len
!= model_emf_uri_len
) {
2655 /* Enforce end of string */
2656 a_model_emf_uri
[model_emf_uri_len
- 1] = '\0';
2659 *signature
= a_sign
;
2660 *nr_fields
= fields_len
/ sizeof(*a_fields
);
2662 *model_emf_uri
= a_model_emf_uri
;
2667 free(a_model_emf_uri
);
2676 * Returns 0 on success, negative error value on error.
2678 int lttng_ust_ctl_reply_register_event(int sock
,
2684 struct ustcomm_notify_hdr header
;
2685 struct ustcomm_notify_event_reply r
;
2688 memset(&reply
, 0, sizeof(reply
));
2689 reply
.header
.notify_cmd
= LTTNG_UST_CTL_NOTIFY_CMD_EVENT
;
2690 reply
.r
.ret_code
= ret_code
;
2691 reply
.r
.event_id
= id
;
2692 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
2693 if (len
> 0 && len
!= sizeof(reply
))
2701 * Returns 0 on success, negative UST or system error value on error.
2703 int lttng_ust_ctl_recv_register_enum(int sock
,
2706 struct lttng_ust_ctl_enum_entry
**entries
,
2710 struct ustcomm_notify_enum_msg msg
;
2712 struct lttng_ust_ctl_enum_entry
*a_entries
= NULL
;
2714 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
2715 if (len
> 0 && len
!= sizeof(msg
))
2722 *session_objd
= msg
.session_objd
;
2723 strncpy(enum_name
, msg
.enum_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
2724 enum_name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
2725 entries_len
= msg
.entries_len
;
2727 if (entries_len
% sizeof(*a_entries
) != 0) {
2733 a_entries
= zmalloc(entries_len
);
2736 len
= ustcomm_recv_unix_sock(sock
, a_entries
, entries_len
);
2737 if (len
> 0 && len
!= entries_len
) {
2749 *nr_entries
= entries_len
/ sizeof(*a_entries
);
2750 *entries
= a_entries
;
2760 * Returns 0 on success, negative error value on error.
2762 int lttng_ust_ctl_reply_register_enum(int sock
,
2768 struct ustcomm_notify_hdr header
;
2769 struct ustcomm_notify_enum_reply r
;
2772 memset(&reply
, 0, sizeof(reply
));
2773 reply
.header
.notify_cmd
= LTTNG_UST_CTL_NOTIFY_CMD_ENUM
;
2774 reply
.r
.ret_code
= ret_code
;
2775 reply
.r
.enum_id
= id
;
2776 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
2777 if (len
> 0 && len
!= sizeof(reply
))
2785 * Returns 0 on success, negative UST or system error value on error.
2787 int lttng_ust_ctl_recv_register_channel(int sock
,
2788 int *session_objd
, /* session descriptor (output) */
2789 int *channel_objd
, /* channel descriptor (output) */
2791 struct lttng_ust_ctl_field
**fields
)
2794 struct ustcomm_notify_channel_msg msg
;
2796 struct lttng_ust_ctl_field
*a_fields
;
2798 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
2799 if (len
> 0 && len
!= sizeof(msg
))
2806 *session_objd
= msg
.session_objd
;
2807 *channel_objd
= msg
.channel_objd
;
2808 fields_len
= msg
.ctx_fields_len
;
2810 if (fields_len
% sizeof(*a_fields
) != 0) {
2816 a_fields
= zmalloc(fields_len
);
2821 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
2822 if (len
> 0 && len
!= fields_len
) {
2837 *nr_fields
= fields_len
/ sizeof(*a_fields
);
2847 * Returns 0 on success, negative error value on error.
2849 int lttng_ust_ctl_reply_register_channel(int sock
,
2851 enum lttng_ust_ctl_channel_header header_type
,
2856 struct ustcomm_notify_hdr header
;
2857 struct ustcomm_notify_channel_reply r
;
2860 memset(&reply
, 0, sizeof(reply
));
2861 reply
.header
.notify_cmd
= LTTNG_UST_CTL_NOTIFY_CMD_CHANNEL
;
2862 reply
.r
.ret_code
= ret_code
;
2863 reply
.r
.chan_id
= chan_id
;
2864 switch (header_type
) {
2865 case LTTNG_UST_CTL_CHANNEL_HEADER_COMPACT
:
2866 reply
.r
.header_type
= 1;
2868 case LTTNG_UST_CTL_CHANNEL_HEADER_LARGE
:
2869 reply
.r
.header_type
= 2;
2872 reply
.r
.header_type
= 0;
2875 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
2876 if (len
> 0 && len
!= sizeof(reply
))
2883 /* Regenerate the statedump. */
2884 int lttng_ust_ctl_regenerate_statedump(int sock
, int handle
)
2886 struct ustcomm_ust_msg lum
;
2887 struct ustcomm_ust_reply lur
;
2890 memset(&lum
, 0, sizeof(lum
));
2891 lum
.handle
= handle
;
2892 lum
.cmd
= LTTNG_UST_ABI_SESSION_STATEDUMP
;
2893 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
2896 DBG("Regenerated statedump for handle %u", handle
);
2900 /* counter operations */
2902 int lttng_ust_ctl_get_nr_cpu_per_counter(void)
2904 return num_possible_cpus();
2907 struct lttng_ust_ctl_daemon_counter
*
2908 lttng_ust_ctl_create_counter(size_t nr_dimensions
,
2909 const struct lttng_ust_ctl_counter_dimension
*dimensions
,
2910 int64_t global_sum_step
,
2911 int global_counter_fd
,
2912 int nr_counter_cpu_fds
,
2913 const int *counter_cpu_fds
,
2914 enum lttng_ust_ctl_counter_bitness bitness
,
2915 enum lttng_ust_ctl_counter_arithmetic arithmetic
,
2916 uint32_t alloc_flags
,
2919 const char *transport_name
;
2920 struct lttng_ust_ctl_daemon_counter
*counter
;
2921 struct lttng_counter_transport
*transport
;
2922 struct lttng_counter_dimension ust_dim
[LTTNG_COUNTER_DIMENSION_MAX
];
2925 if (nr_dimensions
> LTTNG_COUNTER_DIMENSION_MAX
)
2927 /* Currently, only per-cpu allocation is supported. */
2928 switch (alloc_flags
) {
2929 case LTTNG_UST_CTL_COUNTER_ALLOC_PER_CPU
:
2932 case LTTNG_UST_CTL_COUNTER_ALLOC_PER_CPU
| LTTNG_UST_CTL_COUNTER_ALLOC_GLOBAL
:
2933 case LTTNG_UST_CTL_COUNTER_ALLOC_GLOBAL
:
2938 case LTTNG_UST_CTL_COUNTER_BITNESS_32
:
2939 switch (arithmetic
) {
2940 case LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR
:
2941 transport_name
= "counter-per-cpu-32-modular";
2943 case LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION
:
2944 transport_name
= "counter-per-cpu-32-saturation";
2950 case LTTNG_UST_CTL_COUNTER_BITNESS_64
:
2951 switch (arithmetic
) {
2952 case LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR
:
2953 transport_name
= "counter-per-cpu-64-modular";
2955 case LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION
:
2956 transport_name
= "counter-per-cpu-64-saturation";
2966 transport
= lttng_counter_transport_find(transport_name
);
2968 DBG("LTTng transport %s not found\n",
2973 counter
= zmalloc(sizeof(*counter
));
2976 counter
->attr
= zmalloc(sizeof(*counter
->attr
));
2979 counter
->attr
->bitness
= bitness
;
2980 counter
->attr
->arithmetic
= arithmetic
;
2981 counter
->attr
->nr_dimensions
= nr_dimensions
;
2982 counter
->attr
->global_sum_step
= global_sum_step
;
2983 counter
->attr
->coalesce_hits
= coalesce_hits
;
2984 for (i
= 0; i
< nr_dimensions
; i
++)
2985 counter
->attr
->dimensions
[i
] = dimensions
[i
];
2987 for (i
= 0; i
< nr_dimensions
; i
++) {
2988 ust_dim
[i
].size
= dimensions
[i
].size
;
2989 ust_dim
[i
].underflow_index
= dimensions
[i
].underflow_index
;
2990 ust_dim
[i
].overflow_index
= dimensions
[i
].overflow_index
;
2991 ust_dim
[i
].has_underflow
= dimensions
[i
].has_underflow
;
2992 ust_dim
[i
].has_overflow
= dimensions
[i
].has_overflow
;
2994 counter
->counter
= transport
->ops
.counter_create(nr_dimensions
,
2995 ust_dim
, global_sum_step
, global_counter_fd
,
2996 nr_counter_cpu_fds
, counter_cpu_fds
, true);
2997 if (!counter
->counter
)
2999 counter
->ops
= &transport
->ops
;
3003 free(counter
->attr
);
3009 int lttng_ust_ctl_create_counter_data(struct lttng_ust_ctl_daemon_counter
*counter
,
3010 struct lttng_ust_abi_object_data
**_counter_data
)
3012 struct lttng_ust_abi_object_data
*counter_data
;
3013 struct lttng_ust_abi_counter_conf counter_conf
= {0};
3017 switch (counter
->attr
->arithmetic
) {
3018 case LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR
:
3019 counter_conf
.arithmetic
= LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR
;
3021 case LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION
:
3022 counter_conf
.arithmetic
= LTTNG_UST_ABI_COUNTER_ARITHMETIC_SATURATION
;
3027 switch (counter
->attr
->bitness
) {
3028 case LTTNG_UST_CTL_COUNTER_BITNESS_32
:
3029 counter_conf
.bitness
= LTTNG_UST_ABI_COUNTER_BITNESS_32
;
3031 case LTTNG_UST_CTL_COUNTER_BITNESS_64
:
3032 counter_conf
.bitness
= LTTNG_UST_ABI_COUNTER_BITNESS_64
;
3037 counter_conf
.number_dimensions
= counter
->attr
->nr_dimensions
;
3038 counter_conf
.global_sum_step
= counter
->attr
->global_sum_step
;
3039 counter_conf
.coalesce_hits
= counter
->attr
->coalesce_hits
;
3040 for (i
= 0; i
< counter
->attr
->nr_dimensions
; i
++) {
3041 counter_conf
.dimensions
[i
].size
= counter
->attr
->dimensions
[i
].size
;
3042 counter_conf
.dimensions
[i
].underflow_index
= counter
->attr
->dimensions
[i
].underflow_index
;
3043 counter_conf
.dimensions
[i
].overflow_index
= counter
->attr
->dimensions
[i
].overflow_index
;
3044 counter_conf
.dimensions
[i
].has_underflow
= counter
->attr
->dimensions
[i
].has_underflow
;
3045 counter_conf
.dimensions
[i
].has_overflow
= counter
->attr
->dimensions
[i
].has_overflow
;
3048 counter_data
= zmalloc(sizeof(*counter_data
));
3049 if (!counter_data
) {
3053 counter_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_COUNTER
;
3054 counter_data
->handle
= -1;
3056 counter_data
->size
= sizeof(counter_conf
);
3057 counter_data
->u
.counter
.data
= zmalloc(sizeof(counter_conf
));
3058 if (!counter_data
->u
.counter
.data
) {
3060 goto error_alloc_data
;
3063 memcpy(counter_data
->u
.counter
.data
, &counter_conf
, sizeof(counter_conf
));
3064 *_counter_data
= counter_data
;
3074 int lttng_ust_ctl_create_counter_global_data(struct lttng_ust_ctl_daemon_counter
*counter
,
3075 struct lttng_ust_abi_object_data
**_counter_global_data
)
3077 struct lttng_ust_abi_object_data
*counter_global_data
;
3081 if (lttng_counter_get_global_shm(counter
->counter
, &fd
, &len
))
3083 counter_global_data
= zmalloc(sizeof(*counter_global_data
));
3084 if (!counter_global_data
) {
3088 counter_global_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_GLOBAL
;
3089 counter_global_data
->handle
= -1;
3090 counter_global_data
->size
= len
;
3091 counter_global_data
->u
.counter_global
.shm_fd
= fd
;
3092 *_counter_global_data
= counter_global_data
;
3099 int lttng_ust_ctl_create_counter_cpu_data(struct lttng_ust_ctl_daemon_counter
*counter
, int cpu
,
3100 struct lttng_ust_abi_object_data
**_counter_cpu_data
)
3102 struct lttng_ust_abi_object_data
*counter_cpu_data
;
3106 if (lttng_counter_get_cpu_shm(counter
->counter
, cpu
, &fd
, &len
))
3108 counter_cpu_data
= zmalloc(sizeof(*counter_cpu_data
));
3109 if (!counter_cpu_data
) {
3113 counter_cpu_data
->type
= LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_CPU
;
3114 counter_cpu_data
->handle
= -1;
3115 counter_cpu_data
->size
= len
;
3116 counter_cpu_data
->u
.counter_cpu
.shm_fd
= fd
;
3117 counter_cpu_data
->u
.counter_cpu
.cpu_nr
= cpu
;
3118 *_counter_cpu_data
= counter_cpu_data
;
3125 void lttng_ust_ctl_destroy_counter(struct lttng_ust_ctl_daemon_counter
*counter
)
3127 counter
->ops
->counter_destroy(counter
->counter
);
3128 free(counter
->attr
);
3133 * Protocol for LTTNG_UST_ABI_COUNTER command:
3135 * - send: struct ustcomm_ust_msg
3136 * - receive: struct ustcomm_ust_reply
3137 * - send: counter data
3138 * - receive: struct ustcomm_ust_reply (actual command return code)
3140 int lttng_ust_ctl_send_counter_data_to_ust(int sock
, int parent_handle
,
3141 struct lttng_ust_abi_object_data
*counter_data
)
3143 struct ustcomm_ust_msg lum
;
3144 struct ustcomm_ust_reply lur
;
3152 size
= counter_data
->size
;
3153 memset(&lum
, 0, sizeof(lum
));
3154 lum
.handle
= parent_handle
;
3155 lum
.cmd
= LTTNG_UST_ABI_COUNTER
;
3156 lum
.u
.counter
.len
= size
;
3157 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
3161 /* Send counter data */
3162 len
= ustcomm_send_unix_sock(sock
, counter_data
->u
.counter
.data
, size
);
3170 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
3172 counter_data
->handle
= lur
.ret_val
;
3178 * Protocol for LTTNG_UST_ABI_COUNTER_GLOBAL command:
3180 * - send: struct ustcomm_ust_msg
3181 * - receive: struct ustcomm_ust_reply
3182 * - send: file descriptor
3183 * - receive: struct ustcomm_ust_reply (actual command return code)
3185 int lttng_ust_ctl_send_counter_global_data_to_ust(int sock
,
3186 struct lttng_ust_abi_object_data
*counter_data
,
3187 struct lttng_ust_abi_object_data
*counter_global_data
)
3189 struct ustcomm_ust_msg lum
;
3190 struct ustcomm_ust_reply lur
;
3195 if (!counter_data
|| !counter_global_data
)
3198 size
= counter_global_data
->size
;
3199 memset(&lum
, 0, sizeof(lum
));
3200 lum
.handle
= counter_data
->handle
; /* parent handle */
3201 lum
.cmd
= LTTNG_UST_ABI_COUNTER_GLOBAL
;
3202 lum
.u
.counter_global
.len
= size
;
3203 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
3207 shm_fd
[0] = counter_global_data
->u
.counter_global
.shm_fd
;
3208 len
= ustcomm_send_fds_unix_sock(sock
, shm_fd
, 1);
3216 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
3218 counter_global_data
->handle
= lur
.ret_val
;
3224 * Protocol for LTTNG_UST_ABI_COUNTER_CPU command:
3226 * - send: struct ustcomm_ust_msg
3227 * - receive: struct ustcomm_ust_reply
3228 * - send: file descriptor
3229 * - receive: struct ustcomm_ust_reply (actual command return code)
3231 int lttng_ust_ctl_send_counter_cpu_data_to_ust(int sock
,
3232 struct lttng_ust_abi_object_data
*counter_data
,
3233 struct lttng_ust_abi_object_data
*counter_cpu_data
)
3235 struct ustcomm_ust_msg lum
;
3236 struct ustcomm_ust_reply lur
;
3241 if (!counter_data
|| !counter_cpu_data
)
3244 size
= counter_cpu_data
->size
;
3245 memset(&lum
, 0, sizeof(lum
));
3246 lum
.handle
= counter_data
->handle
; /* parent handle */
3247 lum
.cmd
= LTTNG_UST_ABI_COUNTER_CPU
;
3248 lum
.u
.counter_cpu
.len
= size
;
3249 lum
.u
.counter_cpu
.cpu_nr
= counter_cpu_data
->u
.counter_cpu
.cpu_nr
;
3250 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
3254 shm_fd
[0] = counter_cpu_data
->u
.counter_global
.shm_fd
;
3255 len
= ustcomm_send_fds_unix_sock(sock
, shm_fd
, 1);
3263 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
3265 counter_cpu_data
->handle
= lur
.ret_val
;
3270 int lttng_ust_ctl_counter_read(struct lttng_ust_ctl_daemon_counter
*counter
,
3271 const size_t *dimension_indexes
,
3272 int cpu
, int64_t *value
,
3273 bool *overflow
, bool *underflow
)
3275 return counter
->ops
->counter_read(counter
->counter
, dimension_indexes
, cpu
,
3276 value
, overflow
, underflow
);
3279 int lttng_ust_ctl_counter_aggregate(struct lttng_ust_ctl_daemon_counter
*counter
,
3280 const size_t *dimension_indexes
,
3282 bool *overflow
, bool *underflow
)
3284 return counter
->ops
->counter_aggregate(counter
->counter
, dimension_indexes
,
3285 value
, overflow
, underflow
);
3288 int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter
*counter
,
3289 const size_t *dimension_indexes
)
3291 return counter
->ops
->counter_clear(counter
->counter
, dimension_indexes
);
3295 void lttng_ust_ctl_ctor(void)
3296 __attribute__((constructor
));
3298 void lttng_ust_ctl_ctor(void)
3301 * Call the liblttng-ust-common constructor to ensure it runs first.
3303 lttng_ust_common_ctor();
3305 lttng_ust_ring_buffer_clients_init();
3306 lttng_ust_counter_clients_init();
3307 lib_ringbuffer_signal_init();
3311 void lttng_ust_ctl_exit(void)
3312 __attribute__((destructor
));
3314 void lttng_ust_ctl_exit(void)
3316 lttng_ust_counter_clients_exit();
3317 lttng_ust_ring_buffer_clients_exit();