2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Mimic system calls for:
9 * - session creation, returns an object descriptor or failure.
10 * - channel creation, returns an object descriptor or failure.
11 * - Operates on a session object descriptor
12 * - Takes all channel options as parameters.
13 * - stream get, returns an object descriptor or failure.
14 * - Operates on a channel object descriptor.
15 * - stream notifier get, returns an object descriptor or failure.
16 * - Operates on a channel object descriptor.
17 * - event creation, returns an object descriptor or failure.
18 * - Operates on a channel object descriptor
19 * - Takes an event name as parameter
20 * - Takes an instrumentation source as parameter
21 * - e.g. tracepoints, dynamic_probes...
22 * - Takes instrumentation source specific arguments.
30 #include <urcu/compiler.h>
31 #include <urcu/list.h>
33 #include <lttng/tracepoint.h>
34 #include <lttng/ust-abi.h>
35 #include <lttng/ust-error.h>
36 #include <lttng/ust-events.h>
37 #include <lttng/ust-version.h>
39 #include "common/ust-fd.h"
40 #include "common/logging.h"
42 #include "common/ringbuffer/frontend_types.h"
43 #include "common/ringbuffer/frontend.h"
44 #include "common/ringbuffer/shm.h"
45 #include "common/counter/counter.h"
46 #include "common/tracepoint.h"
47 #include "lttng-tracer.h"
48 #include "common/strutils.h"
49 #include "lib/lttng-ust/events.h"
50 #include "context-internal.h"
51 #include "common/macros.h"
53 #define OBJ_NAME_LEN 16
55 static int lttng_ust_abi_close_in_progress
;
58 int lttng_abi_tracepoint_list(void *owner
);
60 int lttng_abi_tracepoint_field_list(void *owner
);
63 * Object descriptor table. Should be protected from concurrent access
67 struct lttng_ust_abi_obj
{
71 const struct lttng_ust_abi_objd_ops
*ops
;
73 int owner_ref
; /* has ref from owner */
75 char name
[OBJ_NAME_LEN
];
77 int freelist_next
; /* offset freelist. end is -1. */
81 struct lttng_ust_abi_objd_table
{
82 struct lttng_ust_abi_obj
*array
;
83 unsigned int len
, allocated_len
;
84 int freelist_head
; /* offset freelist head. end is -1 */
87 static struct lttng_ust_abi_objd_table objd_table
= {
92 int objd_alloc(void *private_data
, const struct lttng_ust_abi_objd_ops
*ops
,
93 void *owner
, const char *name
)
95 struct lttng_ust_abi_obj
*obj
;
97 if (objd_table
.freelist_head
!= -1) {
98 obj
= &objd_table
.array
[objd_table
.freelist_head
];
99 objd_table
.freelist_head
= obj
->u
.freelist_next
;
103 if (objd_table
.len
>= objd_table
.allocated_len
) {
104 unsigned int new_allocated_len
, old_allocated_len
;
105 struct lttng_ust_abi_obj
*new_table
, *old_table
;
107 old_allocated_len
= objd_table
.allocated_len
;
108 old_table
= objd_table
.array
;
109 if (!old_allocated_len
)
110 new_allocated_len
= 1;
112 new_allocated_len
= old_allocated_len
<< 1;
113 new_table
= zmalloc(sizeof(struct lttng_ust_abi_obj
) * new_allocated_len
);
116 memcpy(new_table
, old_table
,
117 sizeof(struct lttng_ust_abi_obj
) * old_allocated_len
);
119 objd_table
.array
= new_table
;
120 objd_table
.allocated_len
= new_allocated_len
;
122 obj
= &objd_table
.array
[objd_table
.len
];
125 obj
->u
.s
.private_data
= private_data
;
127 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
128 /* count == 2 : allocated + hold ref */
129 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
130 obj
->u
.s
.owner
= owner
;
131 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
132 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
133 return obj
- objd_table
.array
;
137 struct lttng_ust_abi_obj
*_objd_get(int id
)
139 if (id
>= objd_table
.len
)
141 if (!objd_table
.array
[id
].u
.s
.f_count
)
143 return &objd_table
.array
[id
];
147 void *objd_private(int id
)
149 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
151 return obj
->u
.s
.private_data
;
155 void objd_set_private(int id
, void *private_data
)
157 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
159 obj
->u
.s
.private_data
= private_data
;
162 const struct lttng_ust_abi_objd_ops
*lttng_ust_abi_objd_ops(int id
)
164 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
172 void objd_free(int id
)
174 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
177 obj
->u
.freelist_next
= objd_table
.freelist_head
;
178 objd_table
.freelist_head
= obj
- objd_table
.array
;
179 assert(obj
->u
.s
.f_count
== 1);
180 obj
->u
.s
.f_count
= 0; /* deallocated */
184 void objd_ref(int id
)
186 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
191 int lttng_ust_abi_objd_unref(int id
, int is_owner
)
193 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
197 if (obj
->u
.s
.f_count
== 1) {
198 ERR("Reference counting error\n");
202 if (!obj
->u
.s
.owner_ref
) {
203 ERR("Error decrementing owner reference");
206 obj
->u
.s
.owner_ref
--;
208 if ((--obj
->u
.s
.f_count
) == 1) {
209 const struct lttng_ust_abi_objd_ops
*ops
= lttng_ust_abi_objd_ops(id
);
219 void objd_table_destroy(void)
223 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
224 struct lttng_ust_abi_obj
*obj
;
229 if (!obj
->u
.s
.owner_ref
)
230 continue; /* only unref owner ref. */
231 (void) lttng_ust_abi_objd_unref(i
, 1);
233 free(objd_table
.array
);
234 objd_table
.array
= NULL
;
236 objd_table
.allocated_len
= 0;
237 objd_table
.freelist_head
= -1;
240 const char *lttng_ust_obj_get_name(int id
)
242 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
246 return obj
->u
.s
.name
;
249 void lttng_ust_abi_objd_table_owner_cleanup(void *owner
)
253 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
254 struct lttng_ust_abi_obj
*obj
;
260 continue; /* skip root handles */
261 if (!obj
->u
.s
.owner_ref
)
262 continue; /* only unref owner ref. */
263 if (obj
->u
.s
.owner
== owner
)
264 (void) lttng_ust_abi_objd_unref(i
, 1);
269 * This is LTTng's own personal way to create an ABI for sessiond.
270 * We send commands over a socket.
273 static const struct lttng_ust_abi_objd_ops lttng_ops
;
274 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops
;
275 static const struct lttng_ust_abi_objd_ops lttng_session_ops
;
276 static const struct lttng_ust_abi_objd_ops lttng_channel_ops
;
277 static const struct lttng_ust_abi_objd_ops lttng_event_enabler_ops
;
278 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_enabler_ops
;
279 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops
;
280 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops
;
282 int lttng_abi_create_root_handle(void)
286 /* root handles have NULL owners */
287 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
292 int lttng_is_channel_ready(struct lttng_ust_channel_buffer
*lttng_chan
)
294 struct lttng_ust_lib_ring_buffer_channel
*chan
;
295 unsigned int nr_streams
, exp_streams
;
297 chan
= lttng_chan
->priv
->rb_chan
;
298 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->priv
->rb_chan
->handle
);
299 exp_streams
= chan
->nr_streams
;
300 return nr_streams
== exp_streams
;
304 int lttng_abi_create_session(void *owner
)
306 struct lttng_ust_session
*session
;
307 int session_objd
, ret
;
309 session
= lttng_session_create();
312 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
313 if (session_objd
< 0) {
317 session
->priv
->objd
= session_objd
;
318 session
->priv
->owner
= owner
;
322 lttng_session_destroy(session
);
327 long lttng_abi_tracer_version(int objd
__attribute__((unused
)),
328 struct lttng_ust_abi_tracer_version
*v
)
330 v
->major
= LTTNG_UST_MAJOR_VERSION
;
331 v
->minor
= LTTNG_UST_MINOR_VERSION
;
332 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
337 int lttng_abi_event_notifier_send_fd(void *owner
, int *event_notifier_notif_fd
)
339 struct lttng_event_notifier_group
*event_notifier_group
;
340 int event_notifier_group_objd
, ret
, fd_flag
;
342 event_notifier_group
= lttng_event_notifier_group_create();
343 if (!event_notifier_group
)
347 * Set this file descriptor as NON-BLOCKING.
349 fd_flag
= fcntl(*event_notifier_notif_fd
, F_GETFL
);
351 fd_flag
|= O_NONBLOCK
;
353 ret
= fcntl(*event_notifier_notif_fd
, F_SETFL
, fd_flag
);
359 event_notifier_group_objd
= objd_alloc(event_notifier_group
,
360 <tng_event_notifier_group_ops
, owner
, "event_notifier_group");
361 if (event_notifier_group_objd
< 0) {
362 ret
= event_notifier_group_objd
;
366 event_notifier_group
->objd
= event_notifier_group_objd
;
367 event_notifier_group
->owner
= owner
;
368 event_notifier_group
->notification_fd
= *event_notifier_notif_fd
;
369 /* Object descriptor takes ownership of notification fd. */
370 *event_notifier_notif_fd
= -1;
372 return event_notifier_group_objd
;
375 lttng_event_notifier_group_destroy(event_notifier_group
);
381 long lttng_abi_add_context(int objd
__attribute__((unused
)),
382 struct lttng_ust_abi_context
*context_param
,
383 union lttng_ust_abi_args
*uargs
,
384 struct lttng_ust_ctx
**ctx
, struct lttng_ust_session
*session
)
386 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
390 * lttng_cmd - lttng control through socket commands
392 * @objd: the object descriptor
395 * @uargs: UST arguments (internal)
398 * This descriptor implements lttng commands:
399 * LTTNG_UST_ABI_SESSION
400 * Returns a LTTng trace session object descriptor
401 * LTTNG_UST_ABI_TRACER_VERSION
402 * Returns the LTTng kernel tracer version
403 * LTTNG_UST_ABI_TRACEPOINT_LIST
404 * Returns a file descriptor listing available tracepoints
405 * LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
406 * Returns a file descriptor listing available tracepoint fields
407 * LTTNG_UST_ABI_WAIT_QUIESCENT
408 * Returns after all previously running probes have completed
410 * The returned session will be deleted when its file descriptor is closed.
413 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
414 union lttng_ust_abi_args
*uargs
, void *owner
)
417 case LTTNG_UST_ABI_SESSION
:
418 return lttng_abi_create_session(owner
);
419 case LTTNG_UST_ABI_TRACER_VERSION
:
420 return lttng_abi_tracer_version(objd
,
421 (struct lttng_ust_abi_tracer_version
*) arg
);
422 case LTTNG_UST_ABI_TRACEPOINT_LIST
:
423 return lttng_abi_tracepoint_list(owner
);
424 case LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
:
425 return lttng_abi_tracepoint_field_list(owner
);
426 case LTTNG_UST_ABI_WAIT_QUIESCENT
:
427 lttng_ust_urcu_synchronize_rcu();
429 case LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE
:
430 return lttng_abi_event_notifier_send_fd(owner
,
431 &uargs
->event_notifier_handle
.event_notifier_notif_fd
);
437 static const struct lttng_ust_abi_objd_ops lttng_ops
= {
442 int lttng_abi_map_channel(int session_objd
,
443 struct lttng_ust_abi_channel
*ust_chan
,
444 union lttng_ust_abi_args
*uargs
,
447 struct lttng_ust_session
*session
= objd_private(session_objd
);
448 const char *transport_name
;
449 struct lttng_transport
*transport
;
450 const char *chan_name
;
452 struct lttng_ust_shm_handle
*channel_handle
;
453 struct lttng_ust_abi_channel_config
*lttng_chan_config
;
454 struct lttng_ust_channel_buffer
*lttng_chan_buf
;
455 struct lttng_ust_lib_ring_buffer_channel
*chan
;
456 struct lttng_ust_lib_ring_buffer_config
*config
;
461 enum lttng_ust_abi_chan_type type
;
463 chan_data
= uargs
->channel
.chan_data
;
464 wakeup_fd
= uargs
->channel
.wakeup_fd
;
466 type
= ust_chan
->type
;
469 case LTTNG_UST_ABI_CHAN_PER_CPU
:
476 if (session
->priv
->been_active
) {
478 goto active
; /* Refuse to add channel to active session */
481 lttng_chan_buf
= lttng_ust_alloc_channel_buffer();
482 if (!lttng_chan_buf
) {
484 goto lttng_chan_buf_error
;
487 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
488 if (!channel_handle
) {
493 /* Ownership of chan_data and wakeup_fd taken by channel handle. */
494 uargs
->channel
.chan_data
= NULL
;
495 uargs
->channel
.wakeup_fd
= -1;
497 chan
= shmp(channel_handle
, channel_handle
->chan
);
499 chan
->handle
= channel_handle
;
500 config
= &chan
->backend
.config
;
501 lttng_chan_config
= channel_get_private_config(chan
);
502 if (!lttng_chan_config
) {
507 if (lttng_ust_session_uuid_validate(session
, lttng_chan_config
->uuid
)) {
512 /* Lookup transport name */
514 case LTTNG_UST_ABI_CHAN_PER_CPU
:
515 if (config
->output
== RING_BUFFER_MMAP
) {
516 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
517 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
518 transport_name
= "relay-overwrite-mmap";
520 transport_name
= "relay-overwrite-rt-mmap";
523 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
524 transport_name
= "relay-discard-mmap";
526 transport_name
= "relay-discard-rt-mmap";
533 chan_name
= "channel";
539 transport
= lttng_ust_transport_find(transport_name
);
541 DBG("LTTng transport %s not found\n",
547 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
553 /* Initialize our lttng chan */
554 lttng_chan_buf
->parent
->enabled
= 1;
555 lttng_chan_buf
->parent
->session
= session
;
557 lttng_chan_buf
->priv
->parent
.tstate
= 1;
558 lttng_chan_buf
->priv
->ctx
= NULL
;
559 lttng_chan_buf
->priv
->rb_chan
= chan
;
561 lttng_chan_buf
->ops
= &transport
->ops
;
563 memcpy(&chan
->backend
.config
,
564 transport
->client_config
,
565 sizeof(chan
->backend
.config
));
566 cds_list_add(<tng_chan_buf
->priv
->node
, &session
->priv
->chan_head
);
567 lttng_chan_buf
->priv
->header_type
= 0;
568 lttng_chan_buf
->priv
->type
= type
;
569 /* Copy fields from lttng ust chan config. */
570 lttng_chan_buf
->priv
->id
= lttng_chan_config
->id
;
571 memcpy(lttng_chan_buf
->priv
->uuid
, lttng_chan_config
->uuid
, LTTNG_UST_UUID_LEN
);
572 channel_set_private(chan
, lttng_chan_buf
);
575 * We tolerate no failure path after channel creation. It will stay
576 * invariant for the rest of the session.
578 objd_set_private(chan_objd
, lttng_chan_buf
);
579 lttng_chan_buf
->priv
->parent
.objd
= chan_objd
;
580 /* The channel created holds a reference on the session */
581 objd_ref(session_objd
);
584 /* error path after channel was created */
589 channel_destroy(chan
, channel_handle
, 0);
590 lttng_ust_free_channel_common(lttng_chan_buf
->parent
);
594 lttng_ust_free_channel_common(lttng_chan_buf
->parent
);
595 lttng_chan_buf_error
:
602 * lttng_session_cmd - lttng session object command
607 * @uargs: UST arguments (internal)
610 * This descriptor implements lttng commands:
611 * LTTNG_UST_ABI_CHANNEL
612 * Returns a LTTng channel object descriptor
613 * LTTNG_UST_ABI_ENABLE
614 * Enables tracing for a session (weak enable)
615 * LTTNG_UST_ABI_DISABLE
616 * Disables tracing for a session (strong disable)
618 * The returned channel will be deleted when its file descriptor is closed.
621 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
622 union lttng_ust_abi_args
*uargs
, void *owner
)
624 struct lttng_ust_session
*session
= objd_private(objd
);
627 case LTTNG_UST_ABI_CHANNEL
:
628 return lttng_abi_map_channel(objd
,
629 (struct lttng_ust_abi_channel
*) arg
,
631 case LTTNG_UST_ABI_SESSION_START
:
632 case LTTNG_UST_ABI_ENABLE
:
633 return lttng_session_enable(session
);
634 case LTTNG_UST_ABI_SESSION_STOP
:
635 case LTTNG_UST_ABI_DISABLE
:
636 return lttng_session_disable(session
);
637 case LTTNG_UST_ABI_SESSION_STATEDUMP
:
638 return lttng_session_statedump(session
);
639 case LTTNG_UST_ABI_COUNTER
:
640 case LTTNG_UST_ABI_COUNTER_GLOBAL
:
641 case LTTNG_UST_ABI_COUNTER_CPU
:
642 /* Not implemented yet. */
650 * Called when the last file reference is dropped.
652 * Big fat note: channels and events are invariant for the whole session after
653 * their creation. So this session destruction also destroys all channel and
654 * event structures specific to this session (they are not destroyed when their
655 * individual file is released).
658 int lttng_release_session(int objd
)
660 struct lttng_ust_session
*session
= objd_private(objd
);
663 lttng_session_destroy(session
);
670 static const struct lttng_ust_abi_objd_ops lttng_session_ops
= {
671 .release
= lttng_release_session
,
672 .cmd
= lttng_session_cmd
,
675 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj
,
676 void *owner
, struct lttng_ust_abi_event_notifier
*event_notifier_param
,
677 enum lttng_enabler_format_type type
)
679 struct lttng_event_notifier_group
*event_notifier_group
=
680 objd_private(event_notifier_group_obj
);
681 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
682 int event_notifier_objd
, ret
;
684 event_notifier_param
->event
.name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
685 event_notifier_objd
= objd_alloc(NULL
, <tng_event_notifier_enabler_ops
, owner
,
686 "event_notifier enabler");
687 if (event_notifier_objd
< 0) {
688 ret
= event_notifier_objd
;
692 event_notifier_enabler
= lttng_event_notifier_enabler_create(
693 event_notifier_group
, type
, event_notifier_param
);
694 if (!event_notifier_enabler
) {
696 goto event_notifier_error
;
699 objd_set_private(event_notifier_objd
, event_notifier_enabler
);
700 /* The event_notifier holds a reference on the event_notifier group. */
701 objd_ref(event_notifier_enabler
->group
->objd
);
703 return event_notifier_objd
;
705 event_notifier_error
:
709 err
= lttng_ust_abi_objd_unref(event_notifier_objd
, 1);
717 long lttng_event_notifier_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
718 union lttng_ust_abi_args
*uargs
__attribute__((unused
)),
719 void *owner
__attribute__((unused
)))
721 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
723 case LTTNG_UST_ABI_FILTER
:
724 return lttng_event_notifier_enabler_attach_filter_bytecode(
725 event_notifier_enabler
,
726 (struct lttng_ust_bytecode_node
**) arg
);
727 case LTTNG_UST_ABI_EXCLUSION
:
728 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
729 (struct lttng_ust_excluder_node
**) arg
);
730 case LTTNG_UST_ABI_CAPTURE
:
731 return lttng_event_notifier_enabler_attach_capture_bytecode(
732 event_notifier_enabler
,
733 (struct lttng_ust_bytecode_node
**) arg
);
734 case LTTNG_UST_ABI_ENABLE
:
735 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
736 case LTTNG_UST_ABI_DISABLE
:
737 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
744 * lttng_event_notifier_group_error_counter_cmd - lttng event_notifier group error counter object command
749 * @uargs: UST arguments (internal)
752 * This descriptor implements lttng commands:
753 * LTTNG_UST_ABI_COUNTER_GLOBAL
754 * Return negative error code on error, 0 on success.
755 * LTTNG_UST_ABI_COUNTER_CPU
756 * Return negative error code on error, 0 on success.
759 long lttng_event_notifier_group_error_counter_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
760 union lttng_ust_abi_args
*uargs
, void *owner
__attribute__((unused
)))
763 struct lttng_counter
*counter
= objd_private(objd
);
766 case LTTNG_UST_ABI_COUNTER_GLOBAL
:
767 ret
= -EINVAL
; /* Unimplemented. */
769 case LTTNG_UST_ABI_COUNTER_CPU
:
771 struct lttng_ust_abi_counter_cpu
*counter_cpu
=
772 (struct lttng_ust_abi_counter_cpu
*)arg
;
774 ret
= lttng_counter_set_cpu_shm(counter
->counter
,
775 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
777 /* Take ownership of the shm_fd. */
778 uargs
->counter_shm
.shm_fd
= -1;
790 int lttng_release_event_notifier_group_error_counter(int objd
)
791 __attribute__((visibility("hidden")));
792 int lttng_release_event_notifier_group_error_counter(int objd
)
794 struct lttng_counter
*counter
= objd_private(objd
);
797 return lttng_ust_abi_objd_unref(counter
->event_notifier_group
->objd
, 0);
803 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_error_counter_ops
= {
804 .release
= lttng_release_event_notifier_group_error_counter
,
805 .cmd
= lttng_event_notifier_group_error_counter_cmd
,
809 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd
, void *owner
,
810 struct lttng_ust_abi_counter_conf
*error_counter_conf
)
812 const char *counter_transport_name
;
813 struct lttng_event_notifier_group
*event_notifier_group
=
814 objd_private(event_notifier_group_objd
);
815 struct lttng_counter
*counter
;
816 int counter_objd
, ret
;
817 struct lttng_counter_dimension dimensions
[1];
820 if (event_notifier_group
->error_counter
)
823 if (error_counter_conf
->arithmetic
!= LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR
)
826 if (error_counter_conf
->number_dimensions
!= 1)
829 switch (error_counter_conf
->bitness
) {
830 case LTTNG_UST_ABI_COUNTER_BITNESS_64
:
831 counter_transport_name
= "counter-per-cpu-64-modular";
833 case LTTNG_UST_ABI_COUNTER_BITNESS_32
:
834 counter_transport_name
= "counter-per-cpu-32-modular";
840 counter_objd
= objd_alloc(NULL
, <tng_event_notifier_group_error_counter_ops
, owner
,
841 "event_notifier group error counter");
842 if (counter_objd
< 0) {
847 counter_len
= error_counter_conf
->dimensions
[0].size
;
848 dimensions
[0].size
= counter_len
;
849 dimensions
[0].underflow_index
= 0;
850 dimensions
[0].overflow_index
= 0;
851 dimensions
[0].has_underflow
= 0;
852 dimensions
[0].has_overflow
= 0;
854 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
860 event_notifier_group
->error_counter_len
= counter_len
;
862 * store-release to publish error counter matches load-acquire
863 * in record_error. Ensures the counter is created and the
864 * error_counter_len is set before they are used.
865 * Currently a full memory barrier is used, which could be
866 * turned into acquire-release barriers.
869 CMM_STORE_SHARED(event_notifier_group
->error_counter
, counter
);
871 counter
->objd
= counter_objd
;
872 counter
->event_notifier_group
= event_notifier_group
; /* owner */
874 objd_set_private(counter_objd
, counter
);
875 /* The error counter holds a reference on the event_notifier group. */
876 objd_ref(event_notifier_group
->objd
);
884 err
= lttng_ust_abi_objd_unref(counter_objd
, 1);
892 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
893 union lttng_ust_abi_args
*uargs
, void *owner
)
896 case LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE
:
898 struct lttng_ust_abi_event_notifier
*event_notifier_param
=
899 (struct lttng_ust_abi_event_notifier
*) arg
;
900 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
902 * If the event name is a star globbing pattern,
903 * we create the special star globbing enabler.
905 return lttng_ust_event_notifier_enabler_create(objd
,
906 owner
, event_notifier_param
,
907 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
909 return lttng_ust_event_notifier_enabler_create(objd
,
910 owner
, event_notifier_param
,
911 LTTNG_ENABLER_FORMAT_EVENT
);
914 case LTTNG_UST_ABI_COUNTER
:
916 struct lttng_ust_abi_counter_conf
*counter_conf
=
917 (struct lttng_ust_abi_counter_conf
*) uargs
->counter
.counter_data
;
918 return lttng_ust_event_notifier_group_create_error_counter(
919 objd
, owner
, counter_conf
);
927 int lttng_event_notifier_enabler_release(int objd
)
929 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
931 if (event_notifier_enabler
)
932 return lttng_ust_abi_objd_unref(event_notifier_enabler
->group
->objd
, 0);
936 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_enabler_ops
= {
937 .release
= lttng_event_notifier_enabler_release
,
938 .cmd
= lttng_event_notifier_enabler_cmd
,
942 int lttng_release_event_notifier_group(int objd
)
944 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
946 if (event_notifier_group
) {
947 lttng_event_notifier_group_destroy(event_notifier_group
);
954 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops
= {
955 .release
= lttng_release_event_notifier_group
,
956 .cmd
= lttng_event_notifier_group_cmd
,
960 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
961 union lttng_ust_abi_args
*uargs
__attribute__((unused
)),
962 void *owner
__attribute__((unused
)))
964 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
965 struct lttng_ust_abi_tracepoint_iter
*tp
=
966 (struct lttng_ust_abi_tracepoint_iter
*) arg
;
967 struct lttng_ust_abi_tracepoint_iter
*iter
;
970 case LTTNG_UST_ABI_TRACEPOINT_LIST_GET
:
972 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
974 return -LTTNG_UST_ERR_NOENT
;
975 memcpy(tp
, iter
, sizeof(*tp
));
984 int lttng_abi_tracepoint_list(void *owner
)
987 struct lttng_ust_tracepoint_list
*list
;
989 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
994 list
= zmalloc(sizeof(*list
));
999 objd_set_private(list_objd
, list
);
1001 /* populate list by walking on all registered probes. */
1002 ret
= lttng_probes_get_event_list(list
);
1014 err
= lttng_ust_abi_objd_unref(list_objd
, 1);
1022 int lttng_release_tracepoint_list(int objd
)
1024 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
1027 lttng_probes_prune_event_list(list
);
1035 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops
= {
1036 .release
= lttng_release_tracepoint_list
,
1037 .cmd
= lttng_tracepoint_list_cmd
,
1041 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1042 unsigned long arg
__attribute__((unused
)), union lttng_ust_abi_args
*uargs
,
1043 void *owner
__attribute__((unused
)))
1045 struct lttng_ust_field_list
*list
= objd_private(objd
);
1046 struct lttng_ust_abi_field_iter
*tp
= &uargs
->field_list
.entry
;
1047 struct lttng_ust_abi_field_iter
*iter
;
1050 case LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST_GET
:
1052 iter
= lttng_ust_field_list_get_iter_next(list
);
1054 return -LTTNG_UST_ERR_NOENT
;
1055 memcpy(tp
, iter
, sizeof(*tp
));
1064 int lttng_abi_tracepoint_field_list(void *owner
)
1067 struct lttng_ust_field_list
*list
;
1069 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1071 if (list_objd
< 0) {
1075 list
= zmalloc(sizeof(*list
));
1080 objd_set_private(list_objd
, list
);
1082 /* populate list by walking on all registered probes. */
1083 ret
= lttng_probes_get_field_list(list
);
1095 err
= lttng_ust_abi_objd_unref(list_objd
, 1);
1103 int lttng_release_tracepoint_field_list(int objd
)
1105 struct lttng_ust_field_list
*list
= objd_private(objd
);
1108 lttng_probes_prune_field_list(list
);
1116 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops
= {
1117 .release
= lttng_release_tracepoint_field_list
,
1118 .cmd
= lttng_tracepoint_field_list_cmd
,
1122 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_abi_stream
*info
,
1123 union lttng_ust_abi_args
*uargs
, void *owner
__attribute__((unused
)))
1125 struct lttng_ust_channel_buffer
*lttng_chan_buf
= objd_private(channel_objd
);
1128 ret
= channel_handle_add_stream(lttng_chan_buf
->priv
->rb_chan
->handle
,
1129 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1130 info
->stream_nr
, info
->len
);
1132 goto error_add_stream
;
1133 /* Take ownership of shm_fd and wakeup_fd. */
1134 uargs
->stream
.shm_fd
= -1;
1135 uargs
->stream
.wakeup_fd
= -1;
1144 int lttng_abi_create_event_enabler(int channel_objd
,
1145 struct lttng_ust_abi_event
*event_param
,
1147 enum lttng_enabler_format_type format_type
)
1149 struct lttng_ust_channel_buffer
*channel
= objd_private(channel_objd
);
1150 struct lttng_event_enabler
*enabler
;
1151 int event_objd
, ret
;
1153 event_param
->name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
1154 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1156 if (event_objd
< 0) {
1161 * We tolerate no failure path after event creation. It will stay
1162 * invariant for the rest of the session.
1164 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1169 objd_set_private(event_objd
, enabler
);
1170 /* The event holds a reference on the channel */
1171 objd_ref(channel_objd
);
1178 err
= lttng_ust_abi_objd_unref(event_objd
, 1);
1186 * lttng_channel_cmd - lttng control through object descriptors
1188 * @objd: the object descriptor
1191 * @uargs: UST arguments (internal)
1192 * @owner: objd owner
1194 * This object descriptor implements lttng commands:
1195 * LTTNG_UST_ABI_STREAM
1196 * Returns an event stream object descriptor or failure.
1197 * (typically, one event stream records events from one CPU)
1198 * LTTNG_UST_ABI_EVENT
1199 * Returns an event object descriptor or failure.
1200 * LTTNG_UST_ABI_CONTEXT
1201 * Prepend a context field to each event in the channel
1202 * LTTNG_UST_ABI_ENABLE
1203 * Enable recording for events in this channel (weak enable)
1204 * LTTNG_UST_ABI_DISABLE
1205 * Disable recording for events in this channel (strong disable)
1207 * Channel and event file descriptors also hold a reference on the session.
1210 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1211 union lttng_ust_abi_args
*uargs
, void *owner
)
1213 struct lttng_ust_channel_buffer
*lttng_chan_buf
= objd_private(objd
);
1215 if (cmd
!= LTTNG_UST_ABI_STREAM
) {
1217 * Check if channel received all streams.
1219 if (!lttng_is_channel_ready(lttng_chan_buf
))
1224 case LTTNG_UST_ABI_STREAM
:
1226 struct lttng_ust_abi_stream
*stream
;
1228 stream
= (struct lttng_ust_abi_stream
*) arg
;
1229 /* stream used as output */
1230 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1232 case LTTNG_UST_ABI_EVENT
:
1234 struct lttng_ust_abi_event
*event_param
=
1235 (struct lttng_ust_abi_event
*) arg
;
1237 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1239 * If the event name is a star globbing pattern,
1240 * we create the special star globbing enabler.
1242 return lttng_abi_create_event_enabler(objd
, event_param
,
1243 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1245 return lttng_abi_create_event_enabler(objd
, event_param
,
1246 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1249 case LTTNG_UST_ABI_CONTEXT
:
1250 return lttng_abi_add_context(objd
,
1251 (struct lttng_ust_abi_context
*) arg
, uargs
,
1252 <tng_chan_buf
->priv
->ctx
,
1253 lttng_chan_buf
->parent
->session
);
1254 case LTTNG_UST_ABI_ENABLE
:
1255 return lttng_channel_enable(lttng_chan_buf
->parent
);
1256 case LTTNG_UST_ABI_DISABLE
:
1257 return lttng_channel_disable(lttng_chan_buf
->parent
);
1258 case LTTNG_UST_ABI_FLUSH_BUFFER
:
1259 return lttng_chan_buf
->ops
->priv
->flush_buffer(lttng_chan_buf
);
1266 int lttng_channel_release(int objd
)
1268 struct lttng_ust_channel_buffer
*lttng_chan_buf
= objd_private(objd
);
1271 return lttng_ust_abi_objd_unref(lttng_chan_buf
->parent
->session
->priv
->objd
, 0);
1275 static const struct lttng_ust_abi_objd_ops lttng_channel_ops
= {
1276 .release
= lttng_channel_release
,
1277 .cmd
= lttng_channel_cmd
,
1281 * lttng_enabler_cmd - lttng control through object descriptors
1283 * @objd: the object descriptor
1286 * @uargs: UST arguments (internal)
1287 * @owner: objd owner
1289 * This object descriptor implements lttng commands:
1290 * LTTNG_UST_ABI_CONTEXT
1291 * Prepend a context field to each record of events of this
1293 * LTTNG_UST_ABI_ENABLE
1294 * Enable recording for this enabler
1295 * LTTNG_UST_ABI_DISABLE
1296 * Disable recording for this enabler
1297 * LTTNG_UST_ABI_FILTER
1298 * Attach a filter to an enabler.
1299 * LTTNG_UST_ABI_EXCLUSION
1300 * Attach exclusions to an enabler.
1303 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1304 union lttng_ust_abi_args
*uargs
__attribute__((unused
)),
1305 void *owner
__attribute__((unused
)))
1307 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1310 case LTTNG_UST_ABI_CONTEXT
:
1311 return lttng_event_enabler_attach_context(enabler
,
1312 (struct lttng_ust_abi_context
*) arg
);
1313 case LTTNG_UST_ABI_ENABLE
:
1314 return lttng_event_enabler_enable(enabler
);
1315 case LTTNG_UST_ABI_DISABLE
:
1316 return lttng_event_enabler_disable(enabler
);
1317 case LTTNG_UST_ABI_FILTER
:
1321 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1322 (struct lttng_ust_bytecode_node
**) arg
);
1327 case LTTNG_UST_ABI_EXCLUSION
:
1329 return lttng_event_enabler_attach_exclusion(enabler
,
1330 (struct lttng_ust_excluder_node
**) arg
);
1338 int lttng_event_enabler_release(int objd
)
1340 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1343 return lttng_ust_abi_objd_unref(event_enabler
->chan
->priv
->parent
.objd
, 0);
1348 static const struct lttng_ust_abi_objd_ops lttng_event_enabler_ops
= {
1349 .release
= lttng_event_enabler_release
,
1350 .cmd
= lttng_event_enabler_cmd
,
1353 void lttng_ust_abi_exit(void)
1355 lttng_ust_abi_close_in_progress
= 1;
1357 objd_table_destroy();
1359 lttng_ust_abi_close_in_progress
= 0;