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 "common/tracer.h"
48 #include "common/strutils.h"
49 #include "lib/lttng-ust/events.h"
50 #include "lib/lttng-ust/lttng-tracer-core.h"
51 #include "context-internal.h"
52 #include "common/macros.h"
54 #define OBJ_NAME_LEN 16
56 static int lttng_ust_abi_close_in_progress
;
59 int lttng_abi_tracepoint_list(void *owner
);
61 int lttng_abi_tracepoint_field_list(void *owner
);
64 * Object descriptor table. Should be protected from concurrent access
68 struct lttng_ust_abi_obj
{
72 const struct lttng_ust_abi_objd_ops
*ops
;
74 int owner_ref
; /* has ref from owner */
76 char name
[OBJ_NAME_LEN
];
78 int freelist_next
; /* offset freelist. end is -1. */
82 struct lttng_ust_abi_objd_table
{
83 struct lttng_ust_abi_obj
*array
;
84 unsigned int len
, allocated_len
;
85 int freelist_head
; /* offset freelist head. end is -1 */
88 static struct lttng_ust_abi_objd_table objd_table
= {
93 int objd_alloc(void *private_data
, const struct lttng_ust_abi_objd_ops
*ops
,
94 void *owner
, const char *name
)
96 struct lttng_ust_abi_obj
*obj
;
98 if (objd_table
.freelist_head
!= -1) {
99 obj
= &objd_table
.array
[objd_table
.freelist_head
];
100 objd_table
.freelist_head
= obj
->u
.freelist_next
;
104 if (objd_table
.len
>= objd_table
.allocated_len
) {
105 unsigned int new_allocated_len
, old_allocated_len
;
106 struct lttng_ust_abi_obj
*new_table
, *old_table
;
108 old_allocated_len
= objd_table
.allocated_len
;
109 old_table
= objd_table
.array
;
110 if (!old_allocated_len
)
111 new_allocated_len
= 1;
113 new_allocated_len
= old_allocated_len
<< 1;
114 new_table
= zmalloc(sizeof(struct lttng_ust_abi_obj
) * new_allocated_len
);
117 memcpy(new_table
, old_table
,
118 sizeof(struct lttng_ust_abi_obj
) * old_allocated_len
);
120 objd_table
.array
= new_table
;
121 objd_table
.allocated_len
= new_allocated_len
;
123 obj
= &objd_table
.array
[objd_table
.len
];
126 obj
->u
.s
.private_data
= private_data
;
128 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
129 /* count == 2 : allocated + hold ref */
130 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
131 obj
->u
.s
.owner
= owner
;
132 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
133 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
134 return obj
- objd_table
.array
;
138 struct lttng_ust_abi_obj
*_objd_get(int id
)
140 if (id
>= objd_table
.len
)
142 if (!objd_table
.array
[id
].u
.s
.f_count
)
144 return &objd_table
.array
[id
];
148 void *objd_private(int id
)
150 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
152 return obj
->u
.s
.private_data
;
156 void objd_set_private(int id
, void *private_data
)
158 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
160 obj
->u
.s
.private_data
= private_data
;
163 const struct lttng_ust_abi_objd_ops
*lttng_ust_abi_objd_ops(int id
)
165 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
173 void objd_free(int id
)
175 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
178 obj
->u
.freelist_next
= objd_table
.freelist_head
;
179 objd_table
.freelist_head
= obj
- objd_table
.array
;
180 assert(obj
->u
.s
.f_count
== 1);
181 obj
->u
.s
.f_count
= 0; /* deallocated */
185 void objd_ref(int id
)
187 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
192 int lttng_ust_abi_objd_unref(int id
, int is_owner
)
194 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
198 if (obj
->u
.s
.f_count
== 1) {
199 ERR("Reference counting error\n");
203 if (!obj
->u
.s
.owner_ref
) {
204 ERR("Error decrementing owner reference");
207 obj
->u
.s
.owner_ref
--;
209 if ((--obj
->u
.s
.f_count
) == 1) {
210 const struct lttng_ust_abi_objd_ops
*ops
= lttng_ust_abi_objd_ops(id
);
220 void objd_table_destroy(void)
224 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
225 struct lttng_ust_abi_obj
*obj
;
230 if (!obj
->u
.s
.owner_ref
)
231 continue; /* only unref owner ref. */
232 (void) lttng_ust_abi_objd_unref(i
, 1);
234 free(objd_table
.array
);
235 objd_table
.array
= NULL
;
237 objd_table
.allocated_len
= 0;
238 objd_table
.freelist_head
= -1;
241 const char *lttng_ust_obj_get_name(int id
)
243 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
247 return obj
->u
.s
.name
;
250 void lttng_ust_abi_objd_table_owner_cleanup(void *owner
)
254 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
255 struct lttng_ust_abi_obj
*obj
;
261 continue; /* skip root handles */
262 if (!obj
->u
.s
.owner_ref
)
263 continue; /* only unref owner ref. */
264 if (obj
->u
.s
.owner
== owner
)
265 (void) lttng_ust_abi_objd_unref(i
, 1);
270 * This is LTTng's own personal way to create an ABI for sessiond.
271 * We send commands over a socket.
274 static const struct lttng_ust_abi_objd_ops lttng_ops
;
275 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops
;
276 static const struct lttng_ust_abi_objd_ops lttng_session_ops
;
277 static const struct lttng_ust_abi_objd_ops lttng_channel_ops
;
278 static const struct lttng_ust_abi_objd_ops lttng_event_enabler_ops
;
279 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_enabler_ops
;
280 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops
;
281 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops
;
283 int lttng_abi_create_root_handle(void)
287 /* root handles have NULL owners */
288 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
293 int lttng_is_channel_ready(struct lttng_ust_channel_buffer
*lttng_chan
)
295 struct lttng_ust_ring_buffer_channel
*chan
;
296 unsigned int nr_streams
, exp_streams
;
298 chan
= lttng_chan
->priv
->rb_chan
;
299 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->priv
->rb_chan
->handle
);
300 exp_streams
= chan
->nr_streams
;
301 return nr_streams
== exp_streams
;
305 int lttng_abi_create_session(void *owner
)
307 struct lttng_ust_session
*session
;
308 int session_objd
, ret
;
310 session
= lttng_session_create();
313 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
314 if (session_objd
< 0) {
318 session
->priv
->objd
= session_objd
;
319 session
->priv
->owner
= owner
;
323 lttng_session_destroy(session
);
328 long lttng_abi_tracer_version(int objd
__attribute__((unused
)),
329 struct lttng_ust_abi_tracer_version
*v
)
331 v
->major
= LTTNG_UST_MAJOR_VERSION
;
332 v
->minor
= LTTNG_UST_MINOR_VERSION
;
333 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
338 int lttng_abi_event_notifier_send_fd(void *owner
, int *event_notifier_notif_fd
)
340 struct lttng_event_notifier_group
*event_notifier_group
;
341 int event_notifier_group_objd
, ret
, fd_flag
;
343 event_notifier_group
= lttng_event_notifier_group_create();
344 if (!event_notifier_group
)
348 * Set this file descriptor as NON-BLOCKING.
350 fd_flag
= fcntl(*event_notifier_notif_fd
, F_GETFL
);
352 fd_flag
|= O_NONBLOCK
;
354 ret
= fcntl(*event_notifier_notif_fd
, F_SETFL
, fd_flag
);
360 event_notifier_group_objd
= objd_alloc(event_notifier_group
,
361 <tng_event_notifier_group_ops
, owner
, "event_notifier_group");
362 if (event_notifier_group_objd
< 0) {
363 ret
= event_notifier_group_objd
;
367 event_notifier_group
->objd
= event_notifier_group_objd
;
368 event_notifier_group
->owner
= owner
;
369 event_notifier_group
->notification_fd
= *event_notifier_notif_fd
;
370 /* Object descriptor takes ownership of notification fd. */
371 *event_notifier_notif_fd
= -1;
373 return event_notifier_group_objd
;
376 lttng_event_notifier_group_destroy(event_notifier_group
);
382 long lttng_abi_add_context(int objd
__attribute__((unused
)),
383 struct lttng_ust_abi_context
*context_param
,
384 union lttng_ust_abi_args
*uargs
,
385 struct lttng_ust_ctx
**ctx
, struct lttng_ust_session
*session
)
387 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
391 * lttng_cmd - lttng control through socket commands
393 * @objd: the object descriptor
396 * @uargs: UST arguments (internal)
399 * This descriptor implements lttng commands:
400 * LTTNG_UST_ABI_SESSION
401 * Returns a LTTng trace session object descriptor
402 * LTTNG_UST_ABI_TRACER_VERSION
403 * Returns the LTTng kernel tracer version
404 * LTTNG_UST_ABI_TRACEPOINT_LIST
405 * Returns a file descriptor listing available tracepoints
406 * LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
407 * Returns a file descriptor listing available tracepoint fields
408 * LTTNG_UST_ABI_WAIT_QUIESCENT
409 * Returns after all previously running probes have completed
411 * The returned session will be deleted when its file descriptor is closed.
414 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
415 union lttng_ust_abi_args
*uargs
, void *owner
)
418 case LTTNG_UST_ABI_SESSION
:
419 return lttng_abi_create_session(owner
);
420 case LTTNG_UST_ABI_TRACER_VERSION
:
421 return lttng_abi_tracer_version(objd
,
422 (struct lttng_ust_abi_tracer_version
*) arg
);
423 case LTTNG_UST_ABI_TRACEPOINT_LIST
:
424 return lttng_abi_tracepoint_list(owner
);
425 case LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
:
426 return lttng_abi_tracepoint_field_list(owner
);
427 case LTTNG_UST_ABI_WAIT_QUIESCENT
:
428 lttng_ust_urcu_synchronize_rcu();
430 case LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE
:
431 return lttng_abi_event_notifier_send_fd(owner
,
432 &uargs
->event_notifier_handle
.event_notifier_notif_fd
);
438 static const struct lttng_ust_abi_objd_ops lttng_ops
= {
443 int lttng_abi_map_channel(int session_objd
,
444 struct lttng_ust_abi_channel
*ust_chan
,
445 union lttng_ust_abi_args
*uargs
,
448 struct lttng_ust_session
*session
= objd_private(session_objd
);
449 const char *transport_name
;
450 struct lttng_transport
*transport
;
451 const char *chan_name
;
453 struct lttng_ust_shm_handle
*channel_handle
;
454 struct lttng_ust_abi_channel_config
*lttng_chan_config
;
455 struct lttng_ust_channel_buffer
*lttng_chan_buf
;
456 struct lttng_ust_ring_buffer_channel
*chan
;
457 struct lttng_ust_ring_buffer_config
*config
;
462 enum lttng_ust_abi_chan_type type
;
464 chan_data
= uargs
->channel
.chan_data
;
465 wakeup_fd
= uargs
->channel
.wakeup_fd
;
467 type
= ust_chan
->type
;
470 case LTTNG_UST_ABI_CHAN_PER_CPU
:
477 if (session
->priv
->been_active
) {
479 goto active
; /* Refuse to add channel to active session */
482 lttng_chan_buf
= lttng_ust_alloc_channel_buffer();
483 if (!lttng_chan_buf
) {
485 goto lttng_chan_buf_error
;
488 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
489 if (!channel_handle
) {
494 /* Ownership of chan_data and wakeup_fd taken by channel handle. */
495 uargs
->channel
.chan_data
= NULL
;
496 uargs
->channel
.wakeup_fd
= -1;
498 chan
= shmp(channel_handle
, channel_handle
->chan
);
500 chan
->handle
= channel_handle
;
501 config
= &chan
->backend
.config
;
502 lttng_chan_config
= channel_get_private_config(chan
);
503 if (!lttng_chan_config
) {
508 if (lttng_ust_session_uuid_validate(session
, lttng_chan_config
->uuid
)) {
513 /* Lookup transport name */
515 case LTTNG_UST_ABI_CHAN_PER_CPU
:
516 if (config
->output
== RING_BUFFER_MMAP
) {
517 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
518 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
519 transport_name
= "relay-overwrite-mmap";
521 transport_name
= "relay-overwrite-rt-mmap";
524 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
525 transport_name
= "relay-discard-mmap";
527 transport_name
= "relay-discard-rt-mmap";
534 chan_name
= "channel";
540 transport
= lttng_ust_transport_find(transport_name
);
542 DBG("LTTng transport %s not found\n",
548 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
554 /* Initialize our lttng chan */
555 lttng_chan_buf
->parent
->enabled
= 1;
556 lttng_chan_buf
->parent
->session
= session
;
558 lttng_chan_buf
->priv
->parent
.tstate
= 1;
559 lttng_chan_buf
->priv
->ctx
= NULL
;
560 lttng_chan_buf
->priv
->rb_chan
= chan
;
562 lttng_chan_buf
->ops
= &transport
->ops
;
564 memcpy(&chan
->backend
.config
,
565 transport
->client_config
,
566 sizeof(chan
->backend
.config
));
567 cds_list_add(<tng_chan_buf
->priv
->node
, &session
->priv
->chan_head
);
568 lttng_chan_buf
->priv
->header_type
= 0;
569 lttng_chan_buf
->priv
->type
= type
;
570 /* Copy fields from lttng ust chan config. */
571 lttng_chan_buf
->priv
->id
= lttng_chan_config
->id
;
572 memcpy(lttng_chan_buf
->priv
->uuid
, lttng_chan_config
->uuid
, LTTNG_UST_UUID_LEN
);
573 channel_set_private(chan
, lttng_chan_buf
);
576 * We tolerate no failure path after channel creation. It will stay
577 * invariant for the rest of the session.
579 objd_set_private(chan_objd
, lttng_chan_buf
);
580 lttng_chan_buf
->priv
->parent
.objd
= chan_objd
;
581 /* The channel created holds a reference on the session */
582 objd_ref(session_objd
);
585 /* error path after channel was created */
590 channel_destroy(chan
, channel_handle
, 0);
591 lttng_ust_free_channel_common(lttng_chan_buf
->parent
);
595 lttng_ust_free_channel_common(lttng_chan_buf
->parent
);
596 lttng_chan_buf_error
:
603 * lttng_session_cmd - lttng session object command
608 * @uargs: UST arguments (internal)
611 * This descriptor implements lttng commands:
612 * LTTNG_UST_ABI_CHANNEL
613 * Returns a LTTng channel object descriptor
614 * LTTNG_UST_ABI_ENABLE
615 * Enables tracing for a session (weak enable)
616 * LTTNG_UST_ABI_DISABLE
617 * Disables tracing for a session (strong disable)
619 * The returned channel will be deleted when its file descriptor is closed.
622 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
623 union lttng_ust_abi_args
*uargs
, void *owner
)
625 struct lttng_ust_session
*session
= objd_private(objd
);
628 case LTTNG_UST_ABI_CHANNEL
:
629 return lttng_abi_map_channel(objd
,
630 (struct lttng_ust_abi_channel
*) arg
,
632 case LTTNG_UST_ABI_SESSION_START
:
633 case LTTNG_UST_ABI_ENABLE
:
634 return lttng_session_enable(session
);
635 case LTTNG_UST_ABI_SESSION_STOP
:
636 case LTTNG_UST_ABI_DISABLE
:
637 return lttng_session_disable(session
);
638 case LTTNG_UST_ABI_SESSION_STATEDUMP
:
639 return lttng_session_statedump(session
);
640 case LTTNG_UST_ABI_COUNTER
:
641 case LTTNG_UST_ABI_COUNTER_GLOBAL
:
642 case LTTNG_UST_ABI_COUNTER_CPU
:
643 /* Not implemented yet. */
651 * Called when the last file reference is dropped.
653 * Big fat note: channels and events are invariant for the whole session after
654 * their creation. So this session destruction also destroys all channel and
655 * event structures specific to this session (they are not destroyed when their
656 * individual file is released).
659 int lttng_release_session(int objd
)
661 struct lttng_ust_session
*session
= objd_private(objd
);
664 lttng_session_destroy(session
);
671 static const struct lttng_ust_abi_objd_ops lttng_session_ops
= {
672 .release
= lttng_release_session
,
673 .cmd
= lttng_session_cmd
,
676 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj
,
677 void *owner
, struct lttng_ust_abi_event_notifier
*event_notifier_param
,
678 enum lttng_enabler_format_type type
)
680 struct lttng_event_notifier_group
*event_notifier_group
=
681 objd_private(event_notifier_group_obj
);
682 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
683 int event_notifier_objd
, ret
;
685 event_notifier_param
->event
.name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
686 event_notifier_objd
= objd_alloc(NULL
, <tng_event_notifier_enabler_ops
, owner
,
687 "event_notifier enabler");
688 if (event_notifier_objd
< 0) {
689 ret
= event_notifier_objd
;
693 event_notifier_enabler
= lttng_event_notifier_enabler_create(
694 event_notifier_group
, type
, event_notifier_param
);
695 if (!event_notifier_enabler
) {
697 goto event_notifier_error
;
700 objd_set_private(event_notifier_objd
, event_notifier_enabler
);
701 /* The event_notifier holds a reference on the event_notifier group. */
702 objd_ref(event_notifier_enabler
->group
->objd
);
704 return event_notifier_objd
;
706 event_notifier_error
:
710 err
= lttng_ust_abi_objd_unref(event_notifier_objd
, 1);
718 long lttng_event_notifier_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
719 union lttng_ust_abi_args
*uargs
__attribute__((unused
)),
720 void *owner
__attribute__((unused
)))
722 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
724 case LTTNG_UST_ABI_FILTER
:
725 return lttng_event_notifier_enabler_attach_filter_bytecode(
726 event_notifier_enabler
,
727 (struct lttng_ust_bytecode_node
**) arg
);
728 case LTTNG_UST_ABI_EXCLUSION
:
729 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
730 (struct lttng_ust_excluder_node
**) arg
);
731 case LTTNG_UST_ABI_CAPTURE
:
732 return lttng_event_notifier_enabler_attach_capture_bytecode(
733 event_notifier_enabler
,
734 (struct lttng_ust_bytecode_node
**) arg
);
735 case LTTNG_UST_ABI_ENABLE
:
736 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
737 case LTTNG_UST_ABI_DISABLE
:
738 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
745 * lttng_event_notifier_group_error_counter_cmd - lttng event_notifier group error counter object command
750 * @uargs: UST arguments (internal)
753 * This descriptor implements lttng commands:
754 * LTTNG_UST_ABI_COUNTER_GLOBAL
755 * Return negative error code on error, 0 on success.
756 * LTTNG_UST_ABI_COUNTER_CPU
757 * Return negative error code on error, 0 on success.
760 long lttng_event_notifier_group_error_counter_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
761 union lttng_ust_abi_args
*uargs
, void *owner
__attribute__((unused
)))
764 struct lttng_counter
*counter
= objd_private(objd
);
767 case LTTNG_UST_ABI_COUNTER_GLOBAL
:
768 ret
= -EINVAL
; /* Unimplemented. */
770 case LTTNG_UST_ABI_COUNTER_CPU
:
772 struct lttng_ust_abi_counter_cpu
*counter_cpu
=
773 (struct lttng_ust_abi_counter_cpu
*)arg
;
775 ret
= lttng_counter_set_cpu_shm(counter
->counter
,
776 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
778 /* Take ownership of the shm_fd. */
779 uargs
->counter_shm
.shm_fd
= -1;
791 int lttng_release_event_notifier_group_error_counter(int objd
)
792 __attribute__((visibility("hidden")));
793 int lttng_release_event_notifier_group_error_counter(int objd
)
795 struct lttng_counter
*counter
= objd_private(objd
);
798 return lttng_ust_abi_objd_unref(counter
->event_notifier_group
->objd
, 0);
804 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_error_counter_ops
= {
805 .release
= lttng_release_event_notifier_group_error_counter
,
806 .cmd
= lttng_event_notifier_group_error_counter_cmd
,
810 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd
, void *owner
,
811 struct lttng_ust_abi_counter_conf
*error_counter_conf
)
813 const char *counter_transport_name
;
814 struct lttng_event_notifier_group
*event_notifier_group
=
815 objd_private(event_notifier_group_objd
);
816 struct lttng_counter
*counter
;
817 int counter_objd
, ret
;
818 struct lttng_counter_dimension dimensions
[1];
821 if (event_notifier_group
->error_counter
)
824 if (error_counter_conf
->arithmetic
!= LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR
)
827 if (error_counter_conf
->number_dimensions
!= 1)
830 switch (error_counter_conf
->bitness
) {
831 case LTTNG_UST_ABI_COUNTER_BITNESS_64
:
832 counter_transport_name
= "counter-per-cpu-64-modular";
834 case LTTNG_UST_ABI_COUNTER_BITNESS_32
:
835 counter_transport_name
= "counter-per-cpu-32-modular";
841 counter_objd
= objd_alloc(NULL
, <tng_event_notifier_group_error_counter_ops
, owner
,
842 "event_notifier group error counter");
843 if (counter_objd
< 0) {
848 counter_len
= error_counter_conf
->dimensions
[0].size
;
849 dimensions
[0].size
= counter_len
;
850 dimensions
[0].underflow_index
= 0;
851 dimensions
[0].overflow_index
= 0;
852 dimensions
[0].has_underflow
= 0;
853 dimensions
[0].has_overflow
= 0;
855 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
861 event_notifier_group
->error_counter_len
= counter_len
;
863 * store-release to publish error counter matches load-acquire
864 * in record_error. Ensures the counter is created and the
865 * error_counter_len is set before they are used.
866 * Currently a full memory barrier is used, which could be
867 * turned into acquire-release barriers.
870 CMM_STORE_SHARED(event_notifier_group
->error_counter
, counter
);
872 counter
->objd
= counter_objd
;
873 counter
->event_notifier_group
= event_notifier_group
; /* owner */
875 objd_set_private(counter_objd
, counter
);
876 /* The error counter holds a reference on the event_notifier group. */
877 objd_ref(event_notifier_group
->objd
);
885 err
= lttng_ust_abi_objd_unref(counter_objd
, 1);
893 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
894 union lttng_ust_abi_args
*uargs
, void *owner
)
897 case LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE
:
899 struct lttng_ust_abi_event_notifier
*event_notifier_param
=
900 (struct lttng_ust_abi_event_notifier
*) arg
;
901 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
903 * If the event name is a star globbing pattern,
904 * we create the special star globbing enabler.
906 return lttng_ust_event_notifier_enabler_create(objd
,
907 owner
, event_notifier_param
,
908 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
910 return lttng_ust_event_notifier_enabler_create(objd
,
911 owner
, event_notifier_param
,
912 LTTNG_ENABLER_FORMAT_EVENT
);
915 case LTTNG_UST_ABI_COUNTER
:
917 struct lttng_ust_abi_counter_conf
*counter_conf
=
918 (struct lttng_ust_abi_counter_conf
*) uargs
->counter
.counter_data
;
919 return lttng_ust_event_notifier_group_create_error_counter(
920 objd
, owner
, counter_conf
);
928 int lttng_event_notifier_enabler_release(int objd
)
930 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
932 if (event_notifier_enabler
)
933 return lttng_ust_abi_objd_unref(event_notifier_enabler
->group
->objd
, 0);
937 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_enabler_ops
= {
938 .release
= lttng_event_notifier_enabler_release
,
939 .cmd
= lttng_event_notifier_enabler_cmd
,
943 int lttng_release_event_notifier_group(int objd
)
945 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
947 if (event_notifier_group
) {
948 lttng_event_notifier_group_destroy(event_notifier_group
);
955 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops
= {
956 .release
= lttng_release_event_notifier_group
,
957 .cmd
= lttng_event_notifier_group_cmd
,
961 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
962 union lttng_ust_abi_args
*uargs
__attribute__((unused
)),
963 void *owner
__attribute__((unused
)))
965 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
966 struct lttng_ust_abi_tracepoint_iter
*tp
=
967 (struct lttng_ust_abi_tracepoint_iter
*) arg
;
968 struct lttng_ust_abi_tracepoint_iter
*iter
;
971 case LTTNG_UST_ABI_TRACEPOINT_LIST_GET
:
973 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
975 return -LTTNG_UST_ERR_NOENT
;
976 memcpy(tp
, iter
, sizeof(*tp
));
985 int lttng_abi_tracepoint_list(void *owner
)
988 struct lttng_ust_tracepoint_list
*list
;
990 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
995 list
= zmalloc(sizeof(*list
));
1000 objd_set_private(list_objd
, list
);
1002 /* populate list by walking on all registered probes. */
1003 ret
= lttng_probes_get_event_list(list
);
1015 err
= lttng_ust_abi_objd_unref(list_objd
, 1);
1023 int lttng_release_tracepoint_list(int objd
)
1025 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
1028 lttng_probes_prune_event_list(list
);
1036 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops
= {
1037 .release
= lttng_release_tracepoint_list
,
1038 .cmd
= lttng_tracepoint_list_cmd
,
1042 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1043 unsigned long arg
__attribute__((unused
)), union lttng_ust_abi_args
*uargs
,
1044 void *owner
__attribute__((unused
)))
1046 struct lttng_ust_field_list
*list
= objd_private(objd
);
1047 struct lttng_ust_abi_field_iter
*tp
= &uargs
->field_list
.entry
;
1048 struct lttng_ust_abi_field_iter
*iter
;
1051 case LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST_GET
:
1053 iter
= lttng_ust_field_list_get_iter_next(list
);
1055 return -LTTNG_UST_ERR_NOENT
;
1056 memcpy(tp
, iter
, sizeof(*tp
));
1065 int lttng_abi_tracepoint_field_list(void *owner
)
1068 struct lttng_ust_field_list
*list
;
1070 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1072 if (list_objd
< 0) {
1076 list
= zmalloc(sizeof(*list
));
1081 objd_set_private(list_objd
, list
);
1083 /* populate list by walking on all registered probes. */
1084 ret
= lttng_probes_get_field_list(list
);
1096 err
= lttng_ust_abi_objd_unref(list_objd
, 1);
1104 int lttng_release_tracepoint_field_list(int objd
)
1106 struct lttng_ust_field_list
*list
= objd_private(objd
);
1109 lttng_probes_prune_field_list(list
);
1117 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops
= {
1118 .release
= lttng_release_tracepoint_field_list
,
1119 .cmd
= lttng_tracepoint_field_list_cmd
,
1123 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_abi_stream
*info
,
1124 union lttng_ust_abi_args
*uargs
, void *owner
__attribute__((unused
)))
1126 struct lttng_ust_channel_buffer
*lttng_chan_buf
= objd_private(channel_objd
);
1129 ret
= channel_handle_add_stream(lttng_chan_buf
->priv
->rb_chan
->handle
,
1130 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1131 info
->stream_nr
, info
->len
);
1133 goto error_add_stream
;
1134 /* Take ownership of shm_fd and wakeup_fd. */
1135 uargs
->stream
.shm_fd
= -1;
1136 uargs
->stream
.wakeup_fd
= -1;
1145 int lttng_abi_create_event_enabler(int channel_objd
,
1146 struct lttng_ust_abi_event
*event_param
,
1148 enum lttng_enabler_format_type format_type
)
1150 struct lttng_ust_channel_buffer
*channel
= objd_private(channel_objd
);
1151 struct lttng_event_enabler
*enabler
;
1152 int event_objd
, ret
;
1154 event_param
->name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
1155 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1157 if (event_objd
< 0) {
1162 * We tolerate no failure path after event creation. It will stay
1163 * invariant for the rest of the session.
1165 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1170 objd_set_private(event_objd
, enabler
);
1171 /* The event holds a reference on the channel */
1172 objd_ref(channel_objd
);
1179 err
= lttng_ust_abi_objd_unref(event_objd
, 1);
1187 * lttng_channel_cmd - lttng control through object descriptors
1189 * @objd: the object descriptor
1192 * @uargs: UST arguments (internal)
1193 * @owner: objd owner
1195 * This object descriptor implements lttng commands:
1196 * LTTNG_UST_ABI_STREAM
1197 * Returns an event stream object descriptor or failure.
1198 * (typically, one event stream records events from one CPU)
1199 * LTTNG_UST_ABI_EVENT
1200 * Returns an event object descriptor or failure.
1201 * LTTNG_UST_ABI_CONTEXT
1202 * Prepend a context field to each event in the channel
1203 * LTTNG_UST_ABI_ENABLE
1204 * Enable recording for events in this channel (weak enable)
1205 * LTTNG_UST_ABI_DISABLE
1206 * Disable recording for events in this channel (strong disable)
1208 * Channel and event file descriptors also hold a reference on the session.
1211 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1212 union lttng_ust_abi_args
*uargs
, void *owner
)
1214 struct lttng_ust_channel_buffer
*lttng_chan_buf
= objd_private(objd
);
1216 if (cmd
!= LTTNG_UST_ABI_STREAM
) {
1218 * Check if channel received all streams.
1220 if (!lttng_is_channel_ready(lttng_chan_buf
))
1225 case LTTNG_UST_ABI_STREAM
:
1227 struct lttng_ust_abi_stream
*stream
;
1229 stream
= (struct lttng_ust_abi_stream
*) arg
;
1230 /* stream used as output */
1231 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1233 case LTTNG_UST_ABI_EVENT
:
1235 struct lttng_ust_abi_event
*event_param
=
1236 (struct lttng_ust_abi_event
*) arg
;
1238 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1240 * If the event name is a star globbing pattern,
1241 * we create the special star globbing enabler.
1243 return lttng_abi_create_event_enabler(objd
, event_param
,
1244 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1246 return lttng_abi_create_event_enabler(objd
, event_param
,
1247 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1250 case LTTNG_UST_ABI_CONTEXT
:
1251 return lttng_abi_add_context(objd
,
1252 (struct lttng_ust_abi_context
*) arg
, uargs
,
1253 <tng_chan_buf
->priv
->ctx
,
1254 lttng_chan_buf
->parent
->session
);
1255 case LTTNG_UST_ABI_ENABLE
:
1256 return lttng_channel_enable(lttng_chan_buf
->parent
);
1257 case LTTNG_UST_ABI_DISABLE
:
1258 return lttng_channel_disable(lttng_chan_buf
->parent
);
1259 case LTTNG_UST_ABI_FLUSH_BUFFER
:
1260 return lttng_chan_buf
->ops
->priv
->flush_buffer(lttng_chan_buf
);
1267 int lttng_channel_release(int objd
)
1269 struct lttng_ust_channel_buffer
*lttng_chan_buf
= objd_private(objd
);
1272 return lttng_ust_abi_objd_unref(lttng_chan_buf
->parent
->session
->priv
->objd
, 0);
1276 static const struct lttng_ust_abi_objd_ops lttng_channel_ops
= {
1277 .release
= lttng_channel_release
,
1278 .cmd
= lttng_channel_cmd
,
1282 * lttng_enabler_cmd - lttng control through object descriptors
1284 * @objd: the object descriptor
1287 * @uargs: UST arguments (internal)
1288 * @owner: objd owner
1290 * This object descriptor implements lttng commands:
1291 * LTTNG_UST_ABI_CONTEXT
1292 * Prepend a context field to each record of events of this
1294 * LTTNG_UST_ABI_ENABLE
1295 * Enable recording for this enabler
1296 * LTTNG_UST_ABI_DISABLE
1297 * Disable recording for this enabler
1298 * LTTNG_UST_ABI_FILTER
1299 * Attach a filter to an enabler.
1300 * LTTNG_UST_ABI_EXCLUSION
1301 * Attach exclusions to an enabler.
1304 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1305 union lttng_ust_abi_args
*uargs
__attribute__((unused
)),
1306 void *owner
__attribute__((unused
)))
1308 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1311 case LTTNG_UST_ABI_CONTEXT
:
1312 return lttng_event_enabler_attach_context(enabler
,
1313 (struct lttng_ust_abi_context
*) arg
);
1314 case LTTNG_UST_ABI_ENABLE
:
1315 return lttng_event_enabler_enable(enabler
);
1316 case LTTNG_UST_ABI_DISABLE
:
1317 return lttng_event_enabler_disable(enabler
);
1318 case LTTNG_UST_ABI_FILTER
:
1322 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1323 (struct lttng_ust_bytecode_node
**) arg
);
1328 case LTTNG_UST_ABI_EXCLUSION
:
1330 return lttng_event_enabler_attach_exclusion(enabler
,
1331 (struct lttng_ust_excluder_node
**) arg
);
1339 int lttng_event_enabler_release(int objd
)
1341 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1344 return lttng_ust_abi_objd_unref(event_enabler
->chan
->priv
->parent
.objd
, 0);
1349 static const struct lttng_ust_abi_objd_ops lttng_event_enabler_ops
= {
1350 .release
= lttng_event_enabler_release
,
1351 .cmd
= lttng_event_enabler_cmd
,
1354 void lttng_ust_abi_exit(void)
1356 lttng_ust_abi_close_in_progress
= 1;
1358 objd_table_destroy();
1360 lttng_ust_abi_close_in_progress
= 0;