2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
24 #include <lttng/ust-endian.h>
26 #include <urcu/arch.h>
27 #include <urcu/compiler.h>
28 #include <urcu/hlist.h>
29 #include <urcu/list.h>
30 #include <urcu/uatomic.h>
32 #include <lttng/tracepoint.h>
33 #include <lttng/ust-events.h>
35 #include <usterr-signal-safe.h>
36 #include <ust-helper.h>
37 #include <lttng/ust-ctl.h>
40 #include <ust-dynamic-type.h>
41 #include <ust-context-provider.h>
44 #include "lttng-ust-uuid.h"
46 #include "tracepoint-internal.h"
47 #include "string-utils.h"
48 #include "lttng-bytecode.h"
49 #include "lttng-tracer.h"
50 #include "lttng-tracer-core.h"
51 #include "lttng-ust-statedump.h"
52 #include "context-internal.h"
53 #include "ust-events-internal.h"
55 #include "../libringbuffer/shm.h"
56 #include "../libcounter/counter.h"
58 #include <lttng/ust-abi.h>
61 * All operations within this file are called by the communication
62 * thread, under ust_lock protection.
65 static CDS_LIST_HEAD(sessions
);
66 static CDS_LIST_HEAD(event_notifier_groups
);
68 struct cds_list_head
*lttng_get_sessions(void)
73 static void _lttng_event_destroy(struct lttng_ust_event_common
*event
);
74 static void _lttng_enum_destroy(struct lttng_enum
*_enum
);
77 void lttng_session_lazy_sync_event_enablers(struct lttng_session
*session
);
79 void lttng_session_sync_event_enablers(struct lttng_session
*session
);
81 void lttng_event_notifier_group_sync_enablers(
82 struct lttng_event_notifier_group
*event_notifier_group
);
84 void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
87 * Called with ust lock held.
89 int lttng_session_active(void)
91 struct lttng_ust_session_private
*iter
;
93 cds_list_for_each_entry(iter
, &sessions
, node
) {
94 if (iter
->pub
->active
)
101 int lttng_loglevel_match(int loglevel
,
102 unsigned int has_loglevel
,
103 enum lttng_ust_abi_loglevel_type req_type
,
107 loglevel
= TRACE_DEFAULT
;
109 case LTTNG_UST_ABI_LOGLEVEL_RANGE
:
110 if (loglevel
<= req_loglevel
111 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
115 case LTTNG_UST_ABI_LOGLEVEL_SINGLE
:
116 if (loglevel
== req_loglevel
117 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
121 case LTTNG_UST_ABI_LOGLEVEL_ALL
:
123 if (loglevel
<= TRACE_DEBUG
)
130 struct lttng_session
*lttng_session_create(void)
132 struct lttng_session
*session
;
133 struct lttng_ust_session_private
*session_priv
;
136 session
= zmalloc(sizeof(struct lttng_session
));
139 session
->struct_size
= sizeof(struct lttng_session
);
140 session_priv
= zmalloc(sizeof(struct lttng_ust_session_private
));
145 session
->priv
= session_priv
;
146 session_priv
->pub
= session
;
147 if (lttng_context_init_all(&session
->priv
->ctx
)) {
152 CDS_INIT_LIST_HEAD(&session
->priv
->chan_head
);
153 CDS_INIT_LIST_HEAD(&session
->priv
->events_head
);
154 CDS_INIT_LIST_HEAD(&session
->priv
->enums_head
);
155 CDS_INIT_LIST_HEAD(&session
->priv
->enablers_head
);
156 for (i
= 0; i
< LTTNG_UST_EVENT_HT_SIZE
; i
++)
157 CDS_INIT_HLIST_HEAD(&session
->priv
->events_ht
.table
[i
]);
158 for (i
= 0; i
< LTTNG_UST_ENUM_HT_SIZE
; i
++)
159 CDS_INIT_HLIST_HEAD(&session
->priv
->enums_ht
.table
[i
]);
160 cds_list_add(&session
->priv
->node
, &sessions
);
164 struct lttng_counter
*lttng_ust_counter_create(
165 const char *counter_transport_name
,
166 size_t number_dimensions
, const struct lttng_counter_dimension
*dimensions
)
168 struct lttng_counter_transport
*counter_transport
= NULL
;
169 struct lttng_counter
*counter
= NULL
;
171 counter_transport
= lttng_counter_transport_find(counter_transport_name
);
172 if (!counter_transport
)
174 counter
= zmalloc(sizeof(struct lttng_counter
));
178 counter
->ops
= &counter_transport
->ops
;
179 counter
->transport
= counter_transport
;
181 counter
->counter
= counter
->ops
->counter_create(
182 number_dimensions
, dimensions
, 0,
184 if (!counter
->counter
) {
198 void lttng_ust_counter_destroy(struct lttng_counter
*counter
)
200 counter
->ops
->counter_destroy(counter
->counter
);
204 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void)
206 struct lttng_event_notifier_group
*event_notifier_group
;
209 event_notifier_group
= zmalloc(sizeof(struct lttng_event_notifier_group
));
210 if (!event_notifier_group
)
213 /* Add all contexts. */
214 if (lttng_context_init_all(&event_notifier_group
->ctx
)) {
215 free(event_notifier_group
);
219 CDS_INIT_LIST_HEAD(&event_notifier_group
->enablers_head
);
220 CDS_INIT_LIST_HEAD(&event_notifier_group
->event_notifiers_head
);
221 for (i
= 0; i
< LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
; i
++)
222 CDS_INIT_HLIST_HEAD(&event_notifier_group
->event_notifiers_ht
.table
[i
]);
224 cds_list_add(&event_notifier_group
->node
, &event_notifier_groups
);
226 return event_notifier_group
;
230 * Only used internally at session destruction.
233 void _lttng_channel_unmap(struct lttng_channel
*lttng_chan
)
235 struct lttng_ust_lib_ring_buffer_channel
*chan
;
236 struct lttng_ust_shm_handle
*handle
;
238 cds_list_del(<tng_chan
->node
);
239 lttng_destroy_context(lttng_chan
->ctx
);
240 chan
= lttng_chan
->chan
;
241 handle
= lttng_chan
->handle
;
243 * note: lttng_chan is private data contained within handle. It
244 * will be freed along with the handle.
246 channel_destroy(chan
, handle
, 0);
250 void register_event(struct lttng_ust_event_common
*event
)
253 const struct lttng_ust_event_desc
*desc
;
255 assert(event
->priv
->registered
== 0);
256 desc
= event
->priv
->desc
;
257 ret
= lttng_ust_tp_probe_register_queue_release(desc
->name
,
258 desc
->probe_callback
,
259 event
, desc
->signature
);
262 event
->priv
->registered
= 1;
266 void unregister_event(struct lttng_ust_event_common
*event
)
269 const struct lttng_ust_event_desc
*desc
;
271 assert(event
->priv
->registered
== 1);
272 desc
= event
->priv
->desc
;
273 ret
= lttng_ust_tp_probe_unregister_queue_release(desc
->name
,
274 desc
->probe_callback
,
278 event
->priv
->registered
= 0;
282 void _lttng_event_unregister(struct lttng_ust_event_common
*event
)
284 if (event
->priv
->registered
)
285 unregister_event(event
);
288 void lttng_session_destroy(struct lttng_session
*session
)
290 struct lttng_channel
*chan
, *tmpchan
;
291 struct lttng_ust_event_recorder_private
*event_recorder_priv
, *tmpevent_recorder_priv
;
292 struct lttng_enum
*_enum
, *tmp_enum
;
293 struct lttng_event_enabler
*event_enabler
, *event_tmpenabler
;
295 CMM_ACCESS_ONCE(session
->active
) = 0;
296 cds_list_for_each_entry(event_recorder_priv
, &session
->priv
->events_head
, node
) {
297 _lttng_event_unregister(event_recorder_priv
->parent
.pub
);
299 lttng_ust_urcu_synchronize_rcu(); /* Wait for in-flight events to complete */
300 lttng_ust_tp_probe_prune_release_queue();
301 cds_list_for_each_entry_safe(event_enabler
, event_tmpenabler
,
302 &session
->priv
->enablers_head
, node
)
303 lttng_event_enabler_destroy(event_enabler
);
304 cds_list_for_each_entry_safe(event_recorder_priv
, tmpevent_recorder_priv
,
305 &session
->priv
->events_head
, node
)
306 _lttng_event_destroy(event_recorder_priv
->parent
.pub
);
307 cds_list_for_each_entry_safe(_enum
, tmp_enum
,
308 &session
->priv
->enums_head
, node
)
309 _lttng_enum_destroy(_enum
);
310 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->priv
->chan_head
, node
)
311 _lttng_channel_unmap(chan
);
312 cds_list_del(&session
->priv
->node
);
313 lttng_destroy_context(session
->priv
->ctx
);
318 void lttng_event_notifier_group_destroy(
319 struct lttng_event_notifier_group
*event_notifier_group
)
322 struct lttng_event_notifier_enabler
*notifier_enabler
, *tmpnotifier_enabler
;
323 struct lttng_ust_event_notifier_private
*event_notifier_priv
, *tmpevent_notifier_priv
;
325 if (!event_notifier_group
) {
329 cds_list_for_each_entry(event_notifier_priv
,
330 &event_notifier_group
->event_notifiers_head
, node
)
331 _lttng_event_unregister(event_notifier_priv
->parent
.pub
);
333 lttng_ust_urcu_synchronize_rcu();
335 cds_list_for_each_entry_safe(notifier_enabler
, tmpnotifier_enabler
,
336 &event_notifier_group
->enablers_head
, node
)
337 lttng_event_notifier_enabler_destroy(notifier_enabler
);
339 cds_list_for_each_entry_safe(event_notifier_priv
, tmpevent_notifier_priv
,
340 &event_notifier_group
->event_notifiers_head
, node
)
341 _lttng_event_destroy(event_notifier_priv
->parent
.pub
);
343 if (event_notifier_group
->error_counter
)
344 lttng_ust_counter_destroy(event_notifier_group
->error_counter
);
346 /* Close the notification fd to the listener of event_notifiers. */
348 lttng_ust_lock_fd_tracker();
349 close_ret
= close(event_notifier_group
->notification_fd
);
351 lttng_ust_delete_fd_from_tracker(
352 event_notifier_group
->notification_fd
);
357 lttng_ust_unlock_fd_tracker();
359 cds_list_del(&event_notifier_group
->node
);
361 free(event_notifier_group
);
365 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
367 struct lttng_ust_bytecode_node
*filter_node
, *tmp_filter_node
;
368 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
374 /* Destroy filter bytecode */
375 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
376 &enabler
->filter_bytecode_head
, node
) {
380 /* Destroy excluders */
381 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
382 &enabler
->excluder_head
, node
) {
387 void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler
*event_notifier_enabler
)
389 if (!event_notifier_enabler
) {
393 cds_list_del(&event_notifier_enabler
->node
);
395 lttng_enabler_destroy(lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
));
397 free(event_notifier_enabler
);
401 int lttng_enum_create(const struct lttng_ust_enum_desc
*desc
,
402 struct lttng_session
*session
)
404 const char *enum_name
= desc
->name
;
405 struct lttng_enum
*_enum
;
406 struct cds_hlist_head
*head
;
408 size_t name_len
= strlen(enum_name
);
412 /* Check if this enum is already registered for this session. */
413 hash
= jhash(enum_name
, name_len
, 0);
414 head
= &session
->priv
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
416 _enum
= lttng_ust_enum_get_from_desc(session
, desc
);
422 notify_socket
= lttng_get_notify_socket(session
->priv
->owner
);
423 if (notify_socket
< 0) {
428 _enum
= zmalloc(sizeof(*_enum
));
433 _enum
->session
= session
;
436 ret
= ustcomm_register_enum(notify_socket
,
443 DBG("Error (%d) registering enumeration to sessiond", ret
);
444 goto sessiond_register_error
;
446 cds_list_add(&_enum
->node
, &session
->priv
->enums_head
);
447 cds_hlist_add_head(&_enum
->hlist
, head
);
450 sessiond_register_error
:
459 int lttng_create_enum_check(const struct lttng_type
*type
,
460 struct lttng_session
*session
)
462 switch (type
->atype
) {
463 case atype_enum_nestable
:
465 const struct lttng_ust_enum_desc
*enum_desc
;
468 enum_desc
= type
->u
.enum_nestable
.desc
;
469 ret
= lttng_enum_create(enum_desc
, session
);
470 if (ret
&& ret
!= -EEXIST
) {
471 DBG("Unable to create enum error: (%d)", ret
);
478 const struct lttng_ust_event_field
*tag_field_generic
;
479 const struct lttng_ust_enum_desc
*enum_desc
;
482 tag_field_generic
= lttng_ust_dynamic_type_tag_field();
483 enum_desc
= tag_field_generic
->type
.u
.enum_nestable
.desc
;
484 ret
= lttng_enum_create(enum_desc
, session
);
485 if (ret
&& ret
!= -EEXIST
) {
486 DBG("Unable to create enum error: (%d)", ret
);
492 /* TODO: nested types when they become supported. */
499 int lttng_create_all_event_enums(size_t nr_fields
,
500 const struct lttng_ust_event_field
**event_fields
,
501 struct lttng_session
*session
)
506 /* For each field, ensure enum is part of the session. */
507 for (i
= 0; i
< nr_fields
; i
++) {
508 const struct lttng_type
*type
= &event_fields
[i
]->type
;
510 ret
= lttng_create_enum_check(type
, session
);
518 int lttng_create_all_ctx_enums(size_t nr_fields
,
519 const struct lttng_ctx_field
*ctx_fields
,
520 struct lttng_session
*session
)
525 /* For each field, ensure enum is part of the session. */
526 for (i
= 0; i
< nr_fields
; i
++) {
527 const struct lttng_type
*type
= &ctx_fields
[i
].event_field
.type
;
529 ret
= lttng_create_enum_check(type
, session
);
537 * Ensure that a state-dump will be performed for this session at the end
538 * of the current handle_message().
540 int lttng_session_statedump(struct lttng_session
*session
)
542 session
->priv
->statedump_pending
= 1;
543 lttng_ust_sockinfo_session_enabled(session
->priv
->owner
);
547 int lttng_session_enable(struct lttng_session
*session
)
550 struct lttng_channel
*chan
;
553 if (session
->active
) {
558 notify_socket
= lttng_get_notify_socket(session
->priv
->owner
);
559 if (notify_socket
< 0)
560 return notify_socket
;
562 /* Set transient enabler state to "enabled" */
563 session
->priv
->tstate
= 1;
565 /* We need to sync enablers with session before activation. */
566 lttng_session_sync_event_enablers(session
);
569 * Snapshot the number of events per channel to know the type of header
572 cds_list_for_each_entry(chan
, &session
->priv
->chan_head
, node
) {
573 const struct lttng_ctx
*ctx
;
574 const struct lttng_ctx_field
*fields
= NULL
;
575 size_t nr_fields
= 0;
578 /* don't change it if session stop/restart */
579 if (chan
->header_type
)
583 nr_fields
= ctx
->nr_fields
;
584 fields
= ctx
->fields
;
585 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
588 DBG("Error (%d) adding enum to session", ret
);
592 ret
= ustcomm_register_channel(notify_socket
,
601 DBG("Error (%d) registering channel to sessiond", ret
);
604 if (chan_id
!= chan
->id
) {
605 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
611 /* Set atomically the state to "active" */
612 CMM_ACCESS_ONCE(session
->active
) = 1;
613 CMM_ACCESS_ONCE(session
->priv
->been_active
) = 1;
615 ret
= lttng_session_statedump(session
);
622 int lttng_session_disable(struct lttng_session
*session
)
626 if (!session
->active
) {
630 /* Set atomically the state to "inactive" */
631 CMM_ACCESS_ONCE(session
->active
) = 0;
633 /* Set transient enabler state to "disabled" */
634 session
->priv
->tstate
= 0;
635 lttng_session_sync_event_enablers(session
);
640 int lttng_channel_enable(struct lttng_channel
*channel
)
644 if (channel
->enabled
) {
648 /* Set transient enabler state to "enabled" */
650 lttng_session_sync_event_enablers(channel
->session
);
651 /* Set atomically the state to "enabled" */
652 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
657 int lttng_channel_disable(struct lttng_channel
*channel
)
661 if (!channel
->enabled
) {
665 /* Set atomically the state to "disabled" */
666 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
667 /* Set transient enabler state to "enabled" */
669 lttng_session_sync_event_enablers(channel
->session
);
675 struct cds_hlist_head
*borrow_hash_table_bucket(
676 struct cds_hlist_head
*hash_table
,
677 unsigned int hash_table_size
,
678 const struct lttng_ust_event_desc
*desc
)
680 const char *event_name
;
684 event_name
= desc
->name
;
685 name_len
= strlen(event_name
);
687 hash
= jhash(event_name
, name_len
, 0);
688 return &hash_table
[hash
& (hash_table_size
- 1)];
692 * Supports event creation while tracing session is active.
695 int lttng_event_recorder_create(const struct lttng_ust_event_desc
*desc
,
696 struct lttng_channel
*chan
)
698 struct lttng_ust_event_recorder
*event_recorder
;
699 struct lttng_ust_event_recorder_private
*event_recorder_priv
;
700 struct lttng_session
*session
= chan
->session
;
701 struct cds_hlist_head
*head
;
703 int notify_socket
, loglevel
;
706 head
= borrow_hash_table_bucket(chan
->session
->priv
->events_ht
.table
,
707 LTTNG_UST_EVENT_HT_SIZE
, desc
);
709 notify_socket
= lttng_get_notify_socket(session
->priv
->owner
);
710 if (notify_socket
< 0) {
715 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
718 DBG("Error (%d) adding enum to session", ret
);
719 goto create_enum_error
;
723 * Check if loglevel match. Refuse to connect event if not.
725 event_recorder
= zmalloc(sizeof(struct lttng_ust_event_recorder
));
726 if (!event_recorder
) {
730 event_recorder
->struct_size
= sizeof(struct lttng_ust_event_recorder
);
732 event_recorder
->parent
= zmalloc(sizeof(struct lttng_ust_event_common
));
733 if (!event_recorder
->parent
) {
737 event_recorder
->parent
->struct_size
= sizeof(struct lttng_ust_event_common
);
738 event_recorder
->parent
->type
= LTTNG_UST_EVENT_TYPE_RECORDER
;
739 event_recorder
->parent
->child
= event_recorder
;
741 event_recorder_priv
= zmalloc(sizeof(struct lttng_ust_event_recorder_private
));
742 if (!event_recorder_priv
) {
746 event_recorder
->priv
= event_recorder_priv
;
747 event_recorder_priv
->pub
= event_recorder
;
748 event_recorder
->parent
->priv
= &event_recorder_priv
->parent
;
749 event_recorder_priv
->parent
.pub
= event_recorder
->parent
;
751 event_recorder
->chan
= chan
;
753 /* Event will be enabled by enabler sync. */
754 event_recorder
->parent
->enabled
= 0;
755 event_recorder
->parent
->priv
->registered
= 0;
756 CDS_INIT_LIST_HEAD(&event_recorder
->parent
->filter_bytecode_runtime_head
);
757 CDS_INIT_LIST_HEAD(&event_recorder
->parent
->priv
->enablers_ref_head
);
758 event_recorder
->parent
->priv
->desc
= desc
;
761 loglevel
= *(*event_recorder
->parent
->priv
->desc
->loglevel
);
763 loglevel
= TRACE_DEFAULT
;
764 if (desc
->model_emf_uri
)
765 uri
= *(desc
->model_emf_uri
);
769 /* Fetch event ID from sessiond */
770 ret
= ustcomm_register_event(notify_socket
,
780 &event_recorder
->id
);
782 DBG("Error (%d) registering event to sessiond", ret
);
783 goto sessiond_register_error
;
786 cds_list_add(&event_recorder_priv
->node
, &chan
->session
->priv
->events_head
);
787 cds_hlist_add_head(&event_recorder_priv
->hlist
, head
);
790 sessiond_register_error
:
791 free(event_recorder_priv
);
793 free(event_recorder
->parent
);
795 free(event_recorder
);
803 int lttng_event_notifier_create(const struct lttng_ust_event_desc
*desc
,
804 uint64_t token
, uint64_t error_counter_index
,
805 struct lttng_event_notifier_group
*event_notifier_group
)
807 struct lttng_ust_event_notifier
*event_notifier
;
808 struct lttng_ust_event_notifier_private
*event_notifier_priv
;
809 struct cds_hlist_head
*head
;
813 * Get the hashtable bucket the created lttng_event_notifier object
814 * should be inserted.
816 head
= borrow_hash_table_bucket(
817 event_notifier_group
->event_notifiers_ht
.table
,
818 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
, desc
);
820 event_notifier
= zmalloc(sizeof(struct lttng_ust_event_notifier
));
821 if (!event_notifier
) {
825 event_notifier
->struct_size
= sizeof(struct lttng_ust_event_notifier
);
827 event_notifier
->parent
= zmalloc(sizeof(struct lttng_ust_event_common
));
828 if (!event_notifier
->parent
) {
832 event_notifier
->parent
->struct_size
= sizeof(struct lttng_ust_event_common
);
833 event_notifier
->parent
->type
= LTTNG_UST_EVENT_TYPE_NOTIFIER
;
834 event_notifier
->parent
->child
= event_notifier
;
836 event_notifier_priv
= zmalloc(sizeof(struct lttng_ust_event_notifier_private
));
837 if (!event_notifier_priv
) {
841 event_notifier
->priv
= event_notifier_priv
;
842 event_notifier_priv
->pub
= event_notifier
;
843 event_notifier
->parent
->priv
= &event_notifier_priv
->parent
;
844 event_notifier_priv
->parent
.pub
= event_notifier
->parent
;
846 event_notifier_priv
->group
= event_notifier_group
;
847 event_notifier_priv
->parent
.user_token
= token
;
848 event_notifier_priv
->error_counter_index
= error_counter_index
;
850 /* Event notifier will be enabled by enabler sync. */
851 event_notifier
->parent
->enabled
= 0;
852 event_notifier_priv
->parent
.registered
= 0;
854 CDS_INIT_LIST_HEAD(&event_notifier
->parent
->filter_bytecode_runtime_head
);
855 CDS_INIT_LIST_HEAD(&event_notifier
->capture_bytecode_runtime_head
);
856 CDS_INIT_LIST_HEAD(&event_notifier_priv
->parent
.enablers_ref_head
);
857 event_notifier_priv
->parent
.desc
= desc
;
858 event_notifier
->notification_send
= lttng_event_notifier_notification_send
;
860 cds_list_add(&event_notifier_priv
->node
,
861 &event_notifier_group
->event_notifiers_head
);
862 cds_hlist_add_head(&event_notifier_priv
->hlist
, head
);
867 free(event_notifier
->parent
);
869 free(event_notifier
);
875 int lttng_desc_match_star_glob_enabler(const struct lttng_ust_event_desc
*desc
,
876 struct lttng_enabler
*enabler
)
879 unsigned int has_loglevel
= 0;
881 assert(enabler
->format_type
== LTTNG_ENABLER_FORMAT_STAR_GLOB
);
882 if (!strutils_star_glob_match(enabler
->event_param
.name
, SIZE_MAX
,
883 desc
->name
, SIZE_MAX
))
885 if (desc
->loglevel
) {
886 loglevel
= *(*desc
->loglevel
);
889 if (!lttng_loglevel_match(loglevel
,
891 enabler
->event_param
.loglevel_type
,
892 enabler
->event_param
.loglevel
))
898 int lttng_desc_match_event_enabler(const struct lttng_ust_event_desc
*desc
,
899 struct lttng_enabler
*enabler
)
902 unsigned int has_loglevel
= 0;
904 assert(enabler
->format_type
== LTTNG_ENABLER_FORMAT_EVENT
);
905 if (strcmp(desc
->name
, enabler
->event_param
.name
))
907 if (desc
->loglevel
) {
908 loglevel
= *(*desc
->loglevel
);
911 if (!lttng_loglevel_match(loglevel
,
913 enabler
->event_param
.loglevel_type
,
914 enabler
->event_param
.loglevel
))
920 int lttng_desc_match_enabler(const struct lttng_ust_event_desc
*desc
,
921 struct lttng_enabler
*enabler
)
923 switch (enabler
->format_type
) {
924 case LTTNG_ENABLER_FORMAT_STAR_GLOB
:
926 struct lttng_ust_excluder_node
*excluder
;
928 if (!lttng_desc_match_star_glob_enabler(desc
, enabler
)) {
933 * If the matching event matches with an excluder,
934 * return 'does not match'
936 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
939 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
943 excluder_name
= (char *) (excluder
->excluder
.names
)
944 + count
* LTTNG_UST_ABI_SYM_NAME_LEN
;
945 len
= strnlen(excluder_name
, LTTNG_UST_ABI_SYM_NAME_LEN
);
946 if (len
> 0 && strutils_star_glob_match(excluder_name
, len
, desc
->name
, SIZE_MAX
))
952 case LTTNG_ENABLER_FORMAT_EVENT
:
953 return lttng_desc_match_event_enabler(desc
, enabler
);
960 int lttng_event_enabler_match_event(struct lttng_event_enabler
*event_enabler
,
961 struct lttng_ust_event_recorder
*event_recorder
)
963 if (lttng_desc_match_enabler(event_recorder
->parent
->priv
->desc
,
964 lttng_event_enabler_as_enabler(event_enabler
))
965 && event_recorder
->chan
== event_enabler
->chan
)
972 int lttng_event_notifier_enabler_match_event_notifier(
973 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
974 struct lttng_ust_event_notifier
*event_notifier
)
976 int desc_matches
= lttng_desc_match_enabler(event_notifier
->priv
->parent
.desc
,
977 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
));
979 if (desc_matches
&& event_notifier
->priv
->group
== event_notifier_enabler
->group
&&
980 event_notifier
->priv
->parent
.user_token
== event_notifier_enabler
->user_token
)
987 struct lttng_enabler_ref
*lttng_enabler_ref(
988 struct cds_list_head
*enabler_ref_list
,
989 struct lttng_enabler
*enabler
)
991 struct lttng_enabler_ref
*enabler_ref
;
993 cds_list_for_each_entry(enabler_ref
, enabler_ref_list
, node
) {
994 if (enabler_ref
->ref
== enabler
)
1001 * Create struct lttng_event if it is missing and present in the list of
1002 * tracepoint probes.
1005 void lttng_create_event_recorder_if_missing(struct lttng_event_enabler
*event_enabler
)
1007 struct lttng_session
*session
= event_enabler
->chan
->session
;
1008 struct lttng_ust_probe_desc
*probe_desc
;
1009 const struct lttng_ust_event_desc
*desc
;
1010 struct lttng_ust_event_recorder_private
*event_recorder_priv
;
1012 struct cds_list_head
*probe_list
;
1014 probe_list
= lttng_get_probe_list_head();
1016 * For each probe event, if we find that a probe event matches
1017 * our enabler, create an associated lttng_event if not
1020 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
1021 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1024 struct cds_hlist_head
*head
;
1025 struct cds_hlist_node
*node
;
1027 desc
= probe_desc
->event_desc
[i
];
1028 if (!lttng_desc_match_enabler(desc
,
1029 lttng_event_enabler_as_enabler(event_enabler
)))
1032 head
= borrow_hash_table_bucket(
1033 session
->priv
->events_ht
.table
,
1034 LTTNG_UST_EVENT_HT_SIZE
, desc
);
1036 cds_hlist_for_each_entry(event_recorder_priv
, node
, head
, hlist
) {
1037 if (event_recorder_priv
->parent
.desc
== desc
1038 && event_recorder_priv
->pub
->chan
== event_enabler
->chan
) {
1047 * We need to create an event for this
1050 ret
= lttng_event_recorder_create(probe_desc
->event_desc
[i
],
1051 event_enabler
->chan
);
1053 DBG("Unable to create event %s, error %d\n",
1054 probe_desc
->event_desc
[i
]->name
, ret
);
1061 void probe_provider_event_for_each(struct lttng_ust_probe_desc
*provider_desc
,
1062 void (*event_func
)(struct lttng_ust_event_common
*event
))
1064 struct cds_hlist_node
*node
, *tmp_node
;
1065 struct cds_list_head
*sessionsp
;
1068 /* Get handle on list of sessions. */
1069 sessionsp
= lttng_get_sessions();
1072 * Iterate over all events in the probe provider descriptions and
1073 * sessions to queue the unregistration of the events.
1075 for (i
= 0; i
< provider_desc
->nr_events
; i
++) {
1076 const struct lttng_ust_event_desc
*event_desc
;
1077 struct lttng_event_notifier_group
*event_notifier_group
;
1078 struct lttng_ust_event_recorder_private
*event_recorder_priv
;
1079 struct lttng_ust_event_notifier_private
*event_notifier_priv
;
1080 struct lttng_ust_session_private
*session_priv
;
1081 struct cds_hlist_head
*head
;
1083 event_desc
= provider_desc
->event_desc
[i
];
1086 * Iterate over all session to find the current event
1089 cds_list_for_each_entry(session_priv
, sessionsp
, node
) {
1091 * Get the list of events in the hashtable bucket and
1092 * iterate to find the event matching this descriptor.
1094 head
= borrow_hash_table_bucket(
1095 session_priv
->events_ht
.table
,
1096 LTTNG_UST_EVENT_HT_SIZE
, event_desc
);
1098 cds_hlist_for_each_entry_safe(event_recorder_priv
, node
, tmp_node
, head
, hlist
) {
1099 if (event_desc
== event_recorder_priv
->parent
.desc
) {
1100 event_func(event_recorder_priv
->parent
.pub
);
1107 * Iterate over all event_notifier groups to find the current event
1110 cds_list_for_each_entry(event_notifier_group
, &event_notifier_groups
, node
) {
1112 * Get the list of event_notifiers in the hashtable bucket and
1113 * iterate to find the event_notifier matching this
1116 head
= borrow_hash_table_bucket(
1117 event_notifier_group
->event_notifiers_ht
.table
,
1118 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
, event_desc
);
1120 cds_hlist_for_each_entry_safe(event_notifier_priv
, node
, tmp_node
, head
, hlist
) {
1121 if (event_desc
== event_notifier_priv
->parent
.desc
) {
1122 event_func(event_notifier_priv
->parent
.pub
);
1131 void _event_enum_destroy(struct lttng_ust_event_common
*event
)
1134 switch (event
->type
) {
1135 case LTTNG_UST_EVENT_TYPE_RECORDER
:
1137 struct lttng_ust_event_recorder
*event_recorder
= event
->child
;
1138 struct lttng_session
*session
= event_recorder
->chan
->session
;
1141 /* Destroy enums of the current event. */
1142 for (i
= 0; i
< event_recorder
->parent
->priv
->desc
->nr_fields
; i
++) {
1143 const struct lttng_ust_enum_desc
*enum_desc
;
1144 const struct lttng_ust_event_field
*field
;
1145 struct lttng_enum
*curr_enum
;
1147 field
= event_recorder
->parent
->priv
->desc
->fields
[i
];
1148 switch (field
->type
.atype
) {
1149 case atype_enum_nestable
:
1150 enum_desc
= field
->type
.u
.enum_nestable
.desc
;
1156 curr_enum
= lttng_ust_enum_get_from_desc(session
, enum_desc
);
1158 _lttng_enum_destroy(curr_enum
);
1163 case LTTNG_UST_EVENT_TYPE_NOTIFIER
:
1168 /* Destroy event. */
1169 _lttng_event_destroy(event
);
1173 * Iterate over all the UST sessions to unregister and destroy all probes from
1174 * the probe provider descriptor received as argument. Must me called with the
1177 void lttng_probe_provider_unregister_events(
1178 struct lttng_ust_probe_desc
*provider_desc
)
1181 * Iterate over all events in the probe provider descriptions and sessions
1182 * to queue the unregistration of the events.
1184 probe_provider_event_for_each(provider_desc
, _lttng_event_unregister
);
1186 /* Wait for grace period. */
1187 lttng_ust_urcu_synchronize_rcu();
1188 /* Prune the unregistration queue. */
1189 lttng_ust_tp_probe_prune_release_queue();
1192 * It is now safe to destroy the events and remove them from the event list
1195 probe_provider_event_for_each(provider_desc
, _event_enum_destroy
);
1199 * Create events associated with an event enabler (if not already present),
1200 * and add backward reference from the event to the enabler.
1203 int lttng_event_enabler_ref_event_recorders(struct lttng_event_enabler
*event_enabler
)
1205 struct lttng_session
*session
= event_enabler
->chan
->session
;
1206 struct lttng_ust_event_recorder_private
*event_recorder_priv
;
1208 if (!lttng_event_enabler_as_enabler(event_enabler
)->enabled
)
1211 /* First ensure that probe events are created for this enabler. */
1212 lttng_create_event_recorder_if_missing(event_enabler
);
1214 /* For each event matching enabler in session event list. */
1215 cds_list_for_each_entry(event_recorder_priv
, &session
->priv
->events_head
, node
) {
1216 struct lttng_enabler_ref
*enabler_ref
;
1218 if (!lttng_event_enabler_match_event(event_enabler
, event_recorder_priv
->pub
))
1221 enabler_ref
= lttng_enabler_ref(&event_recorder_priv
->parent
.enablers_ref_head
,
1222 lttng_event_enabler_as_enabler(event_enabler
));
1225 * If no backward ref, create it.
1226 * Add backward ref from event to enabler.
1228 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
1231 enabler_ref
->ref
= lttng_event_enabler_as_enabler(
1233 cds_list_add(&enabler_ref
->node
,
1234 &event_recorder_priv
->parent
.enablers_ref_head
);
1238 * Link filter bytecodes if not linked yet.
1240 lttng_enabler_link_bytecode(event_recorder_priv
->parent
.desc
,
1241 &session
->priv
->ctx
,
1242 &event_recorder_priv
->pub
->parent
->filter_bytecode_runtime_head
,
1243 <tng_event_enabler_as_enabler(event_enabler
)->filter_bytecode_head
);
1245 /* TODO: merge event context. */
1252 * Called at library load: connect the probe on all enablers matching
1254 * Called with session mutex held.
1256 int lttng_fix_pending_events(void)
1258 struct lttng_ust_session_private
*session_priv
;
1260 cds_list_for_each_entry(session_priv
, &sessions
, node
) {
1261 lttng_session_lazy_sync_event_enablers(session_priv
->pub
);
1266 int lttng_fix_pending_event_notifiers(void)
1268 struct lttng_event_notifier_group
*event_notifier_group
;
1270 cds_list_for_each_entry(event_notifier_group
, &event_notifier_groups
, node
) {
1271 lttng_event_notifier_group_sync_enablers(event_notifier_group
);
1277 * For each session of the owner thread, execute pending statedump.
1278 * Only dump state for the sessions owned by the caller thread, because
1279 * we don't keep ust_lock across the entire iteration.
1281 void lttng_handle_pending_statedump(void *owner
)
1283 struct lttng_ust_session_private
*session_priv
;
1285 /* Execute state dump */
1286 do_lttng_ust_statedump(owner
);
1288 /* Clear pending state dump */
1292 cds_list_for_each_entry(session_priv
, &sessions
, node
) {
1293 if (session_priv
->owner
!= owner
)
1295 if (!session_priv
->statedump_pending
)
1297 session_priv
->statedump_pending
= 0;
1305 void _lttng_event_destroy(struct lttng_ust_event_common
*event
)
1307 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
1309 lttng_free_event_filter_runtime(event
);
1310 /* Free event enabler refs */
1311 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
1312 &event
->priv
->enablers_ref_head
, node
)
1315 switch (event
->type
) {
1316 case LTTNG_UST_EVENT_TYPE_RECORDER
:
1318 struct lttng_ust_event_recorder
*event_recorder
= event
->child
;
1320 /* Remove from event list. */
1321 cds_list_del(&event_recorder
->priv
->node
);
1322 /* Remove from event hash table. */
1323 cds_hlist_del(&event_recorder
->priv
->hlist
);
1325 lttng_destroy_context(event_recorder
->ctx
);
1326 free(event_recorder
->parent
);
1327 free(event_recorder
->priv
);
1328 free(event_recorder
);
1331 case LTTNG_UST_EVENT_TYPE_NOTIFIER
:
1333 struct lttng_ust_event_notifier
*event_notifier
= event
->child
;
1335 /* Remove from event list. */
1336 cds_list_del(&event_notifier
->priv
->node
);
1337 /* Remove from event hash table. */
1338 cds_hlist_del(&event_notifier
->priv
->hlist
);
1340 free(event_notifier
->priv
);
1341 free(event_notifier
->parent
);
1342 free(event_notifier
);
1351 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
1353 cds_list_del(&_enum
->node
);
1354 cds_hlist_del(&_enum
->hlist
);
1358 void lttng_ust_abi_events_exit(void)
1360 struct lttng_ust_session_private
*session_priv
, *tmpsession_priv
;
1362 cds_list_for_each_entry_safe(session_priv
, tmpsession_priv
, &sessions
, node
)
1363 lttng_session_destroy(session_priv
->pub
);
1367 * Enabler management.
1369 struct lttng_event_enabler
*lttng_event_enabler_create(
1370 enum lttng_enabler_format_type format_type
,
1371 struct lttng_ust_abi_event
*event_param
,
1372 struct lttng_channel
*chan
)
1374 struct lttng_event_enabler
*event_enabler
;
1376 event_enabler
= zmalloc(sizeof(*event_enabler
));
1379 event_enabler
->base
.format_type
= format_type
;
1380 CDS_INIT_LIST_HEAD(&event_enabler
->base
.filter_bytecode_head
);
1381 CDS_INIT_LIST_HEAD(&event_enabler
->base
.excluder_head
);
1382 memcpy(&event_enabler
->base
.event_param
, event_param
,
1383 sizeof(event_enabler
->base
.event_param
));
1384 event_enabler
->chan
= chan
;
1386 event_enabler
->base
.enabled
= 0;
1387 cds_list_add(&event_enabler
->node
, &event_enabler
->chan
->session
->priv
->enablers_head
);
1388 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1390 return event_enabler
;
1393 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
1394 struct lttng_event_notifier_group
*event_notifier_group
,
1395 enum lttng_enabler_format_type format_type
,
1396 struct lttng_ust_abi_event_notifier
*event_notifier_param
)
1398 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
1400 event_notifier_enabler
= zmalloc(sizeof(*event_notifier_enabler
));
1401 if (!event_notifier_enabler
)
1403 event_notifier_enabler
->base
.format_type
= format_type
;
1404 CDS_INIT_LIST_HEAD(&event_notifier_enabler
->base
.filter_bytecode_head
);
1405 CDS_INIT_LIST_HEAD(&event_notifier_enabler
->capture_bytecode_head
);
1406 CDS_INIT_LIST_HEAD(&event_notifier_enabler
->base
.excluder_head
);
1408 event_notifier_enabler
->user_token
= event_notifier_param
->event
.token
;
1409 event_notifier_enabler
->error_counter_index
= event_notifier_param
->error_counter_index
;
1410 event_notifier_enabler
->num_captures
= 0;
1412 memcpy(&event_notifier_enabler
->base
.event_param
.name
,
1413 event_notifier_param
->event
.name
,
1414 sizeof(event_notifier_enabler
->base
.event_param
.name
));
1415 event_notifier_enabler
->base
.event_param
.instrumentation
=
1416 event_notifier_param
->event
.instrumentation
;
1417 event_notifier_enabler
->base
.event_param
.loglevel
=
1418 event_notifier_param
->event
.loglevel
;
1419 event_notifier_enabler
->base
.event_param
.loglevel_type
=
1420 event_notifier_param
->event
.loglevel_type
;
1422 event_notifier_enabler
->base
.enabled
= 0;
1423 event_notifier_enabler
->group
= event_notifier_group
;
1425 cds_list_add(&event_notifier_enabler
->node
,
1426 &event_notifier_group
->enablers_head
);
1428 lttng_event_notifier_group_sync_enablers(event_notifier_group
);
1430 return event_notifier_enabler
;
1433 int lttng_event_enabler_enable(struct lttng_event_enabler
*event_enabler
)
1435 lttng_event_enabler_as_enabler(event_enabler
)->enabled
= 1;
1436 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1441 int lttng_event_enabler_disable(struct lttng_event_enabler
*event_enabler
)
1443 lttng_event_enabler_as_enabler(event_enabler
)->enabled
= 0;
1444 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1450 void _lttng_enabler_attach_filter_bytecode(struct lttng_enabler
*enabler
,
1451 struct lttng_ust_bytecode_node
**bytecode
)
1453 (*bytecode
)->enabler
= enabler
;
1454 cds_list_add_tail(&(*bytecode
)->node
, &enabler
->filter_bytecode_head
);
1455 /* Take ownership of bytecode */
1459 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler
*event_enabler
,
1460 struct lttng_ust_bytecode_node
**bytecode
)
1462 _lttng_enabler_attach_filter_bytecode(
1463 lttng_event_enabler_as_enabler(event_enabler
), bytecode
);
1465 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1470 void _lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
1471 struct lttng_ust_excluder_node
**excluder
)
1473 (*excluder
)->enabler
= enabler
;
1474 cds_list_add_tail(&(*excluder
)->node
, &enabler
->excluder_head
);
1475 /* Take ownership of excluder */
1479 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler
*event_enabler
,
1480 struct lttng_ust_excluder_node
**excluder
)
1482 _lttng_enabler_attach_exclusion(
1483 lttng_event_enabler_as_enabler(event_enabler
), excluder
);
1485 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1489 int lttng_event_notifier_enabler_enable(
1490 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1492 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->enabled
= 1;
1493 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1498 int lttng_event_notifier_enabler_disable(
1499 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1501 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->enabled
= 0;
1502 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1507 int lttng_event_notifier_enabler_attach_filter_bytecode(
1508 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
1509 struct lttng_ust_bytecode_node
**bytecode
)
1511 _lttng_enabler_attach_filter_bytecode(
1512 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
),
1515 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1519 int lttng_event_notifier_enabler_attach_capture_bytecode(
1520 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
1521 struct lttng_ust_bytecode_node
**bytecode
)
1523 (*bytecode
)->enabler
= lttng_event_notifier_enabler_as_enabler(
1524 event_notifier_enabler
);
1525 cds_list_add_tail(&(*bytecode
)->node
,
1526 &event_notifier_enabler
->capture_bytecode_head
);
1527 /* Take ownership of bytecode */
1529 event_notifier_enabler
->num_captures
++;
1531 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1535 int lttng_event_notifier_enabler_attach_exclusion(
1536 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
1537 struct lttng_ust_excluder_node
**excluder
)
1539 _lttng_enabler_attach_exclusion(
1540 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
),
1543 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1547 int lttng_attach_context(struct lttng_ust_abi_context
*context_param
,
1548 union lttng_ust_abi_args
*uargs
,
1549 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
1552 * We cannot attach a context after trace has been started for a
1553 * session because the metadata does not allow expressing this
1554 * information outside of the original channel scope.
1556 if (session
->priv
->been_active
)
1559 switch (context_param
->ctx
) {
1560 case LTTNG_UST_ABI_CONTEXT_PTHREAD_ID
:
1561 return lttng_add_pthread_id_to_ctx(ctx
);
1562 case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER
:
1564 struct lttng_ust_abi_perf_counter_ctx
*perf_ctx_param
;
1566 perf_ctx_param
= &context_param
->u
.perf_counter
;
1567 return lttng_add_perf_counter_to_ctx(
1568 perf_ctx_param
->type
,
1569 perf_ctx_param
->config
,
1570 perf_ctx_param
->name
,
1573 case LTTNG_UST_ABI_CONTEXT_VTID
:
1574 return lttng_add_vtid_to_ctx(ctx
);
1575 case LTTNG_UST_ABI_CONTEXT_VPID
:
1576 return lttng_add_vpid_to_ctx(ctx
);
1577 case LTTNG_UST_ABI_CONTEXT_PROCNAME
:
1578 return lttng_add_procname_to_ctx(ctx
);
1579 case LTTNG_UST_ABI_CONTEXT_IP
:
1580 return lttng_add_ip_to_ctx(ctx
);
1581 case LTTNG_UST_ABI_CONTEXT_CPU_ID
:
1582 return lttng_add_cpu_id_to_ctx(ctx
);
1583 case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT
:
1584 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1586 case LTTNG_UST_ABI_CONTEXT_CGROUP_NS
:
1587 return lttng_add_cgroup_ns_to_ctx(ctx
);
1588 case LTTNG_UST_ABI_CONTEXT_IPC_NS
:
1589 return lttng_add_ipc_ns_to_ctx(ctx
);
1590 case LTTNG_UST_ABI_CONTEXT_MNT_NS
:
1591 return lttng_add_mnt_ns_to_ctx(ctx
);
1592 case LTTNG_UST_ABI_CONTEXT_NET_NS
:
1593 return lttng_add_net_ns_to_ctx(ctx
);
1594 case LTTNG_UST_ABI_CONTEXT_PID_NS
:
1595 return lttng_add_pid_ns_to_ctx(ctx
);
1596 case LTTNG_UST_ABI_CONTEXT_TIME_NS
:
1597 return lttng_add_time_ns_to_ctx(ctx
);
1598 case LTTNG_UST_ABI_CONTEXT_USER_NS
:
1599 return lttng_add_user_ns_to_ctx(ctx
);
1600 case LTTNG_UST_ABI_CONTEXT_UTS_NS
:
1601 return lttng_add_uts_ns_to_ctx(ctx
);
1602 case LTTNG_UST_ABI_CONTEXT_VUID
:
1603 return lttng_add_vuid_to_ctx(ctx
);
1604 case LTTNG_UST_ABI_CONTEXT_VEUID
:
1605 return lttng_add_veuid_to_ctx(ctx
);
1606 case LTTNG_UST_ABI_CONTEXT_VSUID
:
1607 return lttng_add_vsuid_to_ctx(ctx
);
1608 case LTTNG_UST_ABI_CONTEXT_VGID
:
1609 return lttng_add_vgid_to_ctx(ctx
);
1610 case LTTNG_UST_ABI_CONTEXT_VEGID
:
1611 return lttng_add_vegid_to_ctx(ctx
);
1612 case LTTNG_UST_ABI_CONTEXT_VSGID
:
1613 return lttng_add_vsgid_to_ctx(ctx
);
1619 int lttng_event_enabler_attach_context(struct lttng_event_enabler
*enabler
,
1620 struct lttng_ust_abi_context
*context_param
)
1625 void lttng_event_enabler_destroy(struct lttng_event_enabler
*event_enabler
)
1627 if (!event_enabler
) {
1630 cds_list_del(&event_enabler
->node
);
1632 lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler
));
1634 lttng_destroy_context(event_enabler
->ctx
);
1635 free(event_enabler
);
1639 * lttng_session_sync_event_enablers should be called just before starting a
1643 void lttng_session_sync_event_enablers(struct lttng_session
*session
)
1645 struct lttng_event_enabler
*event_enabler
;
1646 struct lttng_ust_event_recorder_private
*event_recorder_priv
;
1648 cds_list_for_each_entry(event_enabler
, &session
->priv
->enablers_head
, node
)
1649 lttng_event_enabler_ref_event_recorders(event_enabler
);
1651 * For each event, if at least one of its enablers is enabled,
1652 * and its channel and session transient states are enabled, we
1653 * enable the event, else we disable it.
1655 cds_list_for_each_entry(event_recorder_priv
, &session
->priv
->events_head
, node
) {
1656 struct lttng_enabler_ref
*enabler_ref
;
1657 struct lttng_ust_bytecode_runtime
*runtime
;
1658 int enabled
= 0, has_enablers_without_bytecode
= 0;
1661 cds_list_for_each_entry(enabler_ref
,
1662 &event_recorder_priv
->parent
.enablers_ref_head
, node
) {
1663 if (enabler_ref
->ref
->enabled
) {
1669 * Enabled state is based on union of enablers, with
1670 * intesection of session and channel transient enable
1673 enabled
= enabled
&& session
->priv
->tstate
&& event_recorder_priv
->pub
->chan
->tstate
;
1675 CMM_STORE_SHARED(event_recorder_priv
->pub
->parent
->enabled
, enabled
);
1677 * Sync tracepoint registration with event enabled
1681 if (!event_recorder_priv
->parent
.registered
)
1682 register_event(event_recorder_priv
->parent
.pub
);
1684 if (event_recorder_priv
->parent
.registered
)
1685 unregister_event(event_recorder_priv
->parent
.pub
);
1688 /* Check if has enablers without bytecode enabled */
1689 cds_list_for_each_entry(enabler_ref
,
1690 &event_recorder_priv
->parent
.enablers_ref_head
, node
) {
1691 if (enabler_ref
->ref
->enabled
1692 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1693 has_enablers_without_bytecode
= 1;
1697 event_recorder_priv
->pub
->parent
->has_enablers_without_bytecode
=
1698 has_enablers_without_bytecode
;
1700 /* Enable filters */
1701 cds_list_for_each_entry(runtime
,
1702 &event_recorder_priv
->pub
->parent
->filter_bytecode_runtime_head
, node
) {
1703 lttng_bytecode_filter_sync_state(runtime
);
1706 lttng_ust_tp_probe_prune_release_queue();
1709 /* Support for event notifier is introduced by probe provider major version 2. */
1711 bool lttng_ust_probe_supports_event_notifier(struct lttng_ust_probe_desc
*probe_desc
)
1713 return probe_desc
->major
>= 2;
1717 void lttng_create_event_notifier_if_missing(
1718 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1720 struct lttng_event_notifier_group
*event_notifier_group
= event_notifier_enabler
->group
;
1721 struct lttng_ust_probe_desc
*probe_desc
;
1722 struct cds_list_head
*probe_list
;
1725 probe_list
= lttng_get_probe_list_head();
1727 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
1728 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1731 const struct lttng_ust_event_desc
*desc
;
1732 struct lttng_ust_event_notifier_private
*event_notifier_priv
;
1733 struct cds_hlist_head
*head
;
1734 struct cds_hlist_node
*node
;
1736 desc
= probe_desc
->event_desc
[i
];
1738 if (!lttng_desc_match_enabler(desc
,
1739 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)))
1743 * Given the current event_notifier group, get the bucket that
1744 * the target event_notifier would be if it was already
1747 head
= borrow_hash_table_bucket(
1748 event_notifier_group
->event_notifiers_ht
.table
,
1749 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
, desc
);
1751 cds_hlist_for_each_entry(event_notifier_priv
, node
, head
, hlist
) {
1753 * Check if event_notifier already exists by checking
1754 * if the event_notifier and enabler share the same
1755 * description and id.
1757 if (event_notifier_priv
->parent
.desc
== desc
&&
1758 event_notifier_priv
->parent
.user_token
== event_notifier_enabler
->user_token
) {
1767 /* Check that the probe supports event notifiers, else report the error. */
1768 if (!lttng_ust_probe_supports_event_notifier(probe_desc
)) {
1769 ERR("Probe \"%s\" contains event \"%s\" which matches an enabled event notifier, "
1770 "but its version (%u.%u) is too old and does not implement event notifiers. "
1771 "It needs to be recompiled against a newer version of LTTng-UST, otherwise "
1772 "this event will not generate any notification.",
1773 probe_desc
->provider
,
1780 * We need to create a event_notifier for this event probe.
1782 ret
= lttng_event_notifier_create(desc
,
1783 event_notifier_enabler
->user_token
,
1784 event_notifier_enabler
->error_counter_index
,
1785 event_notifier_group
);
1787 DBG("Unable to create event_notifier %s, error %d\n",
1788 probe_desc
->event_desc
[i
]->name
, ret
);
1795 * Create event_notifiers associated with a event_notifier enabler (if not already present).
1798 int lttng_event_notifier_enabler_ref_event_notifiers(
1799 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1801 struct lttng_event_notifier_group
*event_notifier_group
= event_notifier_enabler
->group
;
1802 struct lttng_ust_event_notifier_private
*event_notifier_priv
;
1805 * Only try to create event_notifiers for enablers that are enabled, the user
1806 * might still be attaching filter or exclusion to the
1807 * event_notifier_enabler.
1809 if (!lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->enabled
)
1812 /* First, ensure that probe event_notifiers are created for this enabler. */
1813 lttng_create_event_notifier_if_missing(event_notifier_enabler
);
1815 /* Link the created event_notifier with its associated enabler. */
1816 cds_list_for_each_entry(event_notifier_priv
, &event_notifier_group
->event_notifiers_head
, node
) {
1817 struct lttng_enabler_ref
*enabler_ref
;
1819 if (!lttng_event_notifier_enabler_match_event_notifier(event_notifier_enabler
, event_notifier_priv
->pub
))
1822 enabler_ref
= lttng_enabler_ref(&event_notifier_priv
->parent
.enablers_ref_head
,
1823 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
));
1826 * If no backward ref, create it.
1827 * Add backward ref from event_notifier to enabler.
1829 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
1833 enabler_ref
->ref
= lttng_event_notifier_enabler_as_enabler(
1834 event_notifier_enabler
);
1835 cds_list_add(&enabler_ref
->node
,
1836 &event_notifier_priv
->parent
.enablers_ref_head
);
1840 * Link filter bytecodes if not linked yet.
1842 lttng_enabler_link_bytecode(event_notifier_priv
->parent
.desc
,
1843 &event_notifier_group
->ctx
,
1844 &event_notifier_priv
->pub
->parent
->filter_bytecode_runtime_head
,
1845 <tng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->filter_bytecode_head
);
1848 * Link capture bytecodes if not linked yet.
1850 lttng_enabler_link_bytecode(event_notifier_priv
->parent
.desc
,
1851 &event_notifier_group
->ctx
, &event_notifier_priv
->pub
->capture_bytecode_runtime_head
,
1852 &event_notifier_enabler
->capture_bytecode_head
);
1854 event_notifier_priv
->num_captures
= event_notifier_enabler
->num_captures
;
1861 void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group
*event_notifier_group
)
1863 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
1864 struct lttng_ust_event_notifier_private
*event_notifier_priv
;
1866 cds_list_for_each_entry(event_notifier_enabler
, &event_notifier_group
->enablers_head
, node
)
1867 lttng_event_notifier_enabler_ref_event_notifiers(event_notifier_enabler
);
1870 * For each event_notifier, if at least one of its enablers is enabled,
1871 * we enable the event_notifier, else we disable it.
1873 cds_list_for_each_entry(event_notifier_priv
, &event_notifier_group
->event_notifiers_head
, node
) {
1874 struct lttng_enabler_ref
*enabler_ref
;
1875 struct lttng_ust_bytecode_runtime
*runtime
;
1876 int enabled
= 0, has_enablers_without_bytecode
= 0;
1878 /* Enable event_notifiers */
1879 cds_list_for_each_entry(enabler_ref
,
1880 &event_notifier_priv
->parent
.enablers_ref_head
, node
) {
1881 if (enabler_ref
->ref
->enabled
) {
1887 CMM_STORE_SHARED(event_notifier_priv
->pub
->parent
->enabled
, enabled
);
1889 * Sync tracepoint registration with event_notifier enabled
1893 if (!event_notifier_priv
->parent
.registered
)
1894 register_event(event_notifier_priv
->parent
.pub
);
1896 if (event_notifier_priv
->parent
.registered
)
1897 unregister_event(event_notifier_priv
->parent
.pub
);
1900 /* Check if has enablers without bytecode enabled */
1901 cds_list_for_each_entry(enabler_ref
,
1902 &event_notifier_priv
->parent
.enablers_ref_head
, node
) {
1903 if (enabler_ref
->ref
->enabled
1904 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1905 has_enablers_without_bytecode
= 1;
1909 event_notifier_priv
->pub
->parent
->has_enablers_without_bytecode
=
1910 has_enablers_without_bytecode
;
1912 /* Enable filters */
1913 cds_list_for_each_entry(runtime
,
1914 &event_notifier_priv
->pub
->parent
->filter_bytecode_runtime_head
, node
) {
1915 lttng_bytecode_filter_sync_state(runtime
);
1918 /* Enable captures. */
1919 cds_list_for_each_entry(runtime
,
1920 &event_notifier_priv
->pub
->capture_bytecode_runtime_head
, node
) {
1921 lttng_bytecode_capture_sync_state(runtime
);
1924 lttng_ust_tp_probe_prune_release_queue();
1928 * Apply enablers to session events, adding events to session if need
1929 * be. It is required after each modification applied to an active
1930 * session, and right before session "start".
1931 * "lazy" sync means we only sync if required.
1934 void lttng_session_lazy_sync_event_enablers(struct lttng_session
*session
)
1936 /* We can skip if session is not active */
1937 if (!session
->active
)
1939 lttng_session_sync_event_enablers(session
);
1943 * Update all sessions with the given app context.
1944 * Called with ust lock held.
1945 * This is invoked when an application context gets loaded/unloaded. It
1946 * ensures the context callbacks are in sync with the application
1947 * context (either app context callbacks, or dummy callbacks).
1949 void lttng_ust_context_set_session_provider(const char *name
,
1950 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1951 void (*record
)(struct lttng_ctx_field
*field
,
1952 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1953 struct lttng_channel
*chan
),
1954 void (*get_value
)(struct lttng_ctx_field
*field
,
1955 struct lttng_ctx_value
*value
))
1957 struct lttng_ust_session_private
*session_priv
;
1959 cds_list_for_each_entry(session_priv
, &sessions
, node
) {
1960 struct lttng_channel
*chan
;
1961 struct lttng_ust_event_recorder_private
*event_recorder_priv
;
1964 ret
= lttng_ust_context_set_provider_rcu(&session_priv
->ctx
,
1965 name
, get_size
, record
, get_value
);
1968 cds_list_for_each_entry(chan
, &session_priv
->chan_head
, node
) {
1969 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1970 name
, get_size
, record
, get_value
);
1974 cds_list_for_each_entry(event_recorder_priv
, &session_priv
->events_head
, node
) {
1975 ret
= lttng_ust_context_set_provider_rcu(&event_recorder_priv
->pub
->ctx
,
1976 name
, get_size
, record
, get_value
);
1984 * Update all event_notifier groups with the given app context.
1985 * Called with ust lock held.
1986 * This is invoked when an application context gets loaded/unloaded. It
1987 * ensures the context callbacks are in sync with the application
1988 * context (either app context callbacks, or dummy callbacks).
1990 void lttng_ust_context_set_event_notifier_group_provider(const char *name
,
1991 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1992 void (*record
)(struct lttng_ctx_field
*field
,
1993 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1994 struct lttng_channel
*chan
),
1995 void (*get_value
)(struct lttng_ctx_field
*field
,
1996 struct lttng_ctx_value
*value
))
1998 struct lttng_event_notifier_group
*event_notifier_group
;
2000 cds_list_for_each_entry(event_notifier_group
, &event_notifier_groups
, node
) {
2003 ret
= lttng_ust_context_set_provider_rcu(
2004 &event_notifier_group
->ctx
,
2005 name
, get_size
, record
, get_value
);