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_event
*event
);
74 static void _lttng_event_notifier_destroy(
75 struct lttng_event_notifier
*event_notifier
);
76 static void _lttng_enum_destroy(struct lttng_enum
*_enum
);
79 void lttng_session_lazy_sync_event_enablers(struct lttng_session
*session
);
81 void lttng_session_sync_event_enablers(struct lttng_session
*session
);
83 void lttng_event_notifier_group_sync_enablers(
84 struct lttng_event_notifier_group
*event_notifier_group
);
86 void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
89 * Called with ust lock held.
91 int lttng_session_active(void)
93 struct lttng_session
*iter
;
95 cds_list_for_each_entry(iter
, &sessions
, node
) {
103 int lttng_loglevel_match(int loglevel
,
104 unsigned int has_loglevel
,
105 enum lttng_ust_loglevel_type req_type
,
109 loglevel
= TRACE_DEFAULT
;
111 case LTTNG_UST_LOGLEVEL_RANGE
:
112 if (loglevel
<= req_loglevel
113 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
117 case LTTNG_UST_LOGLEVEL_SINGLE
:
118 if (loglevel
== req_loglevel
119 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
123 case LTTNG_UST_LOGLEVEL_ALL
:
125 if (loglevel
<= TRACE_DEBUG
)
132 struct lttng_session
*lttng_session_create(void)
134 struct lttng_session
*session
;
137 session
= zmalloc(sizeof(struct lttng_session
));
140 if (lttng_context_init_all(&session
->ctx
)) {
144 CDS_INIT_LIST_HEAD(&session
->chan_head
);
145 CDS_INIT_LIST_HEAD(&session
->events_head
);
146 CDS_INIT_LIST_HEAD(&session
->enums_head
);
147 CDS_INIT_LIST_HEAD(&session
->enablers_head
);
148 for (i
= 0; i
< LTTNG_UST_EVENT_HT_SIZE
; i
++)
149 CDS_INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
150 for (i
= 0; i
< LTTNG_UST_ENUM_HT_SIZE
; i
++)
151 CDS_INIT_HLIST_HEAD(&session
->enums_ht
.table
[i
]);
152 cds_list_add(&session
->node
, &sessions
);
156 struct lttng_counter
*lttng_ust_counter_create(
157 const char *counter_transport_name
,
158 size_t number_dimensions
, const struct lttng_counter_dimension
*dimensions
)
160 struct lttng_counter_transport
*counter_transport
= NULL
;
161 struct lttng_counter
*counter
= NULL
;
163 counter_transport
= lttng_counter_transport_find(counter_transport_name
);
164 if (!counter_transport
)
166 counter
= zmalloc(sizeof(struct lttng_counter
));
170 counter
->ops
= &counter_transport
->ops
;
171 counter
->transport
= counter_transport
;
173 counter
->counter
= counter
->ops
->counter_create(
174 number_dimensions
, dimensions
, 0,
176 if (!counter
->counter
) {
190 void lttng_ust_counter_destroy(struct lttng_counter
*counter
)
192 counter
->ops
->counter_destroy(counter
->counter
);
196 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void)
198 struct lttng_event_notifier_group
*event_notifier_group
;
201 event_notifier_group
= zmalloc(sizeof(struct lttng_event_notifier_group
));
202 if (!event_notifier_group
)
205 /* Add all contexts. */
206 if (lttng_context_init_all(&event_notifier_group
->ctx
)) {
207 free(event_notifier_group
);
211 CDS_INIT_LIST_HEAD(&event_notifier_group
->enablers_head
);
212 CDS_INIT_LIST_HEAD(&event_notifier_group
->event_notifiers_head
);
213 for (i
= 0; i
< LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
; i
++)
214 CDS_INIT_HLIST_HEAD(&event_notifier_group
->event_notifiers_ht
.table
[i
]);
216 cds_list_add(&event_notifier_group
->node
, &event_notifier_groups
);
218 return event_notifier_group
;
222 * Only used internally at session destruction.
225 void _lttng_channel_unmap(struct lttng_channel
*lttng_chan
)
227 struct channel
*chan
;
228 struct lttng_ust_shm_handle
*handle
;
230 cds_list_del(<tng_chan
->node
);
231 lttng_destroy_context(lttng_chan
->ctx
);
232 chan
= lttng_chan
->chan
;
233 handle
= lttng_chan
->handle
;
235 * note: lttng_chan is private data contained within handle. It
236 * will be freed along with the handle.
238 channel_destroy(chan
, handle
, 0);
242 void register_event(struct lttng_event
*event
)
245 const struct lttng_event_desc
*desc
;
247 assert(event
->registered
== 0);
249 ret
= __tracepoint_probe_register_queue_release(desc
->name
,
250 desc
->probe_callback
,
251 event
, desc
->signature
);
254 event
->registered
= 1;
258 void register_event_notifier(struct lttng_event_notifier
*event_notifier
)
261 const struct lttng_event_desc
*desc
;
263 assert(event_notifier
->registered
== 0);
264 desc
= event_notifier
->desc
;
265 ret
= __tracepoint_probe_register_queue_release(desc
->name
,
266 desc
->u
.ext
.event_notifier_callback
, event_notifier
, desc
->signature
);
269 event_notifier
->registered
= 1;
273 void unregister_event(struct lttng_event
*event
)
276 const struct lttng_event_desc
*desc
;
278 assert(event
->registered
== 1);
280 ret
= __tracepoint_probe_unregister_queue_release(desc
->name
,
281 desc
->probe_callback
,
285 event
->registered
= 0;
289 void unregister_event_notifier(struct lttng_event_notifier
*event_notifier
)
292 const struct lttng_event_desc
*desc
;
294 assert(event_notifier
->registered
== 1);
295 desc
= event_notifier
->desc
;
296 ret
= __tracepoint_probe_unregister_queue_release(desc
->name
,
297 desc
->u
.ext
.event_notifier_callback
, event_notifier
);
300 event_notifier
->registered
= 0;
304 * Only used internally at session destruction.
307 void _lttng_event_unregister(struct lttng_event
*event
)
309 if (event
->registered
)
310 unregister_event(event
);
314 * Only used internally at session destruction.
317 void _lttng_event_notifier_unregister(struct lttng_event_notifier
*event_notifier
)
319 if (event_notifier
->registered
)
320 unregister_event_notifier(event_notifier
);
323 void lttng_session_destroy(struct lttng_session
*session
)
325 struct lttng_channel
*chan
, *tmpchan
;
326 struct lttng_event
*event
, *tmpevent
;
327 struct lttng_enum
*_enum
, *tmp_enum
;
328 struct lttng_event_enabler
*event_enabler
, *event_tmpenabler
;
330 CMM_ACCESS_ONCE(session
->active
) = 0;
331 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
332 _lttng_event_unregister(event
);
334 lttng_ust_synchronize_trace(); /* Wait for in-flight events to complete */
335 __tracepoint_probe_prune_release_queue();
336 cds_list_for_each_entry_safe(event_enabler
, event_tmpenabler
,
337 &session
->enablers_head
, node
)
338 lttng_event_enabler_destroy(event_enabler
);
339 cds_list_for_each_entry_safe(event
, tmpevent
,
340 &session
->events_head
, node
)
341 _lttng_event_destroy(event
);
342 cds_list_for_each_entry_safe(_enum
, tmp_enum
,
343 &session
->enums_head
, node
)
344 _lttng_enum_destroy(_enum
);
345 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->chan_head
, node
)
346 _lttng_channel_unmap(chan
);
347 cds_list_del(&session
->node
);
348 lttng_destroy_context(session
->ctx
);
352 void lttng_event_notifier_group_destroy(
353 struct lttng_event_notifier_group
*event_notifier_group
)
356 struct lttng_event_notifier_enabler
*notifier_enabler
, *tmpnotifier_enabler
;
357 struct lttng_event_notifier
*notifier
, *tmpnotifier
;
359 if (!event_notifier_group
) {
363 cds_list_for_each_entry(notifier
,
364 &event_notifier_group
->event_notifiers_head
, node
)
365 _lttng_event_notifier_unregister(notifier
);
367 lttng_ust_synchronize_trace();
369 cds_list_for_each_entry_safe(notifier_enabler
, tmpnotifier_enabler
,
370 &event_notifier_group
->enablers_head
, node
)
371 lttng_event_notifier_enabler_destroy(notifier_enabler
);
373 cds_list_for_each_entry_safe(notifier
, tmpnotifier
,
374 &event_notifier_group
->event_notifiers_head
, node
)
375 _lttng_event_notifier_destroy(notifier
);
377 if (event_notifier_group
->error_counter
)
378 lttng_ust_counter_destroy(event_notifier_group
->error_counter
);
380 /* Close the notification fd to the listener of event_notifiers. */
382 lttng_ust_lock_fd_tracker();
383 close_ret
= close(event_notifier_group
->notification_fd
);
385 lttng_ust_delete_fd_from_tracker(
386 event_notifier_group
->notification_fd
);
391 lttng_ust_unlock_fd_tracker();
393 cds_list_del(&event_notifier_group
->node
);
395 free(event_notifier_group
);
399 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
401 struct lttng_ust_bytecode_node
*filter_node
, *tmp_filter_node
;
402 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
408 /* Destroy filter bytecode */
409 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
410 &enabler
->filter_bytecode_head
, node
) {
414 /* Destroy excluders */
415 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
416 &enabler
->excluder_head
, node
) {
421 void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler
*event_notifier_enabler
)
423 if (!event_notifier_enabler
) {
427 cds_list_del(&event_notifier_enabler
->node
);
429 lttng_enabler_destroy(lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
));
431 free(event_notifier_enabler
);
435 int lttng_enum_create(const struct lttng_enum_desc
*desc
,
436 struct lttng_session
*session
)
438 const char *enum_name
= desc
->name
;
439 struct lttng_enum
*_enum
;
440 struct cds_hlist_head
*head
;
442 size_t name_len
= strlen(enum_name
);
446 /* Check if this enum is already registered for this session. */
447 hash
= jhash(enum_name
, name_len
, 0);
448 head
= &session
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
450 _enum
= lttng_ust_enum_get_from_desc(session
, desc
);
456 notify_socket
= lttng_get_notify_socket(session
->owner
);
457 if (notify_socket
< 0) {
462 _enum
= zmalloc(sizeof(*_enum
));
467 _enum
->session
= session
;
470 ret
= ustcomm_register_enum(notify_socket
,
477 DBG("Error (%d) registering enumeration to sessiond", ret
);
478 goto sessiond_register_error
;
480 cds_list_add(&_enum
->node
, &session
->enums_head
);
481 cds_hlist_add_head(&_enum
->hlist
, head
);
484 sessiond_register_error
:
493 int lttng_create_enum_check(const struct lttng_type
*type
,
494 struct lttng_session
*session
)
496 switch (type
->atype
) {
499 const struct lttng_enum_desc
*enum_desc
;
502 enum_desc
= type
->u
.legacy
.basic
.enumeration
.desc
;
503 ret
= lttng_enum_create(enum_desc
, session
);
504 if (ret
&& ret
!= -EEXIST
) {
505 DBG("Unable to create enum error: (%d)", ret
);
510 case atype_enum_nestable
:
512 const struct lttng_enum_desc
*enum_desc
;
515 enum_desc
= type
->u
.enum_nestable
.desc
;
516 ret
= lttng_enum_create(enum_desc
, session
);
517 if (ret
&& ret
!= -EEXIST
) {
518 DBG("Unable to create enum error: (%d)", ret
);
525 const struct lttng_event_field
*tag_field_generic
;
526 const struct lttng_enum_desc
*enum_desc
;
529 tag_field_generic
= lttng_ust_dynamic_type_tag_field();
530 enum_desc
= tag_field_generic
->type
.u
.enum_nestable
.desc
;
531 ret
= lttng_enum_create(enum_desc
, session
);
532 if (ret
&& ret
!= -EEXIST
) {
533 DBG("Unable to create enum error: (%d)", ret
);
539 /* TODO: nested types when they become supported. */
546 int lttng_create_all_event_enums(size_t nr_fields
,
547 const struct lttng_event_field
*event_fields
,
548 struct lttng_session
*session
)
553 /* For each field, ensure enum is part of the session. */
554 for (i
= 0; i
< nr_fields
; i
++) {
555 const struct lttng_type
*type
= &event_fields
[i
].type
;
557 ret
= lttng_create_enum_check(type
, session
);
565 int lttng_create_all_ctx_enums(size_t nr_fields
,
566 const struct lttng_ctx_field
*ctx_fields
,
567 struct lttng_session
*session
)
572 /* For each field, ensure enum is part of the session. */
573 for (i
= 0; i
< nr_fields
; i
++) {
574 const struct lttng_type
*type
= &ctx_fields
[i
].event_field
.type
;
576 ret
= lttng_create_enum_check(type
, session
);
584 * Ensure that a state-dump will be performed for this session at the end
585 * of the current handle_message().
587 int lttng_session_statedump(struct lttng_session
*session
)
589 session
->statedump_pending
= 1;
590 lttng_ust_sockinfo_session_enabled(session
->owner
);
594 int lttng_session_enable(struct lttng_session
*session
)
597 struct lttng_channel
*chan
;
600 if (session
->active
) {
605 notify_socket
= lttng_get_notify_socket(session
->owner
);
606 if (notify_socket
< 0)
607 return notify_socket
;
609 /* Set transient enabler state to "enabled" */
612 /* We need to sync enablers with session before activation. */
613 lttng_session_sync_event_enablers(session
);
616 * Snapshot the number of events per channel to know the type of header
619 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
620 const struct lttng_ctx
*ctx
;
621 const struct lttng_ctx_field
*fields
= NULL
;
622 size_t nr_fields
= 0;
625 /* don't change it if session stop/restart */
626 if (chan
->header_type
)
630 nr_fields
= ctx
->nr_fields
;
631 fields
= ctx
->fields
;
632 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
635 DBG("Error (%d) adding enum to session", ret
);
639 ret
= ustcomm_register_channel(notify_socket
,
648 DBG("Error (%d) registering channel to sessiond", ret
);
651 if (chan_id
!= chan
->id
) {
652 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
658 /* Set atomically the state to "active" */
659 CMM_ACCESS_ONCE(session
->active
) = 1;
660 CMM_ACCESS_ONCE(session
->been_active
) = 1;
662 ret
= lttng_session_statedump(session
);
669 int lttng_session_disable(struct lttng_session
*session
)
673 if (!session
->active
) {
677 /* Set atomically the state to "inactive" */
678 CMM_ACCESS_ONCE(session
->active
) = 0;
680 /* Set transient enabler state to "disabled" */
682 lttng_session_sync_event_enablers(session
);
687 int lttng_channel_enable(struct lttng_channel
*channel
)
691 if (channel
->enabled
) {
695 /* Set transient enabler state to "enabled" */
697 lttng_session_sync_event_enablers(channel
->session
);
698 /* Set atomically the state to "enabled" */
699 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
704 int lttng_channel_disable(struct lttng_channel
*channel
)
708 if (!channel
->enabled
) {
712 /* Set atomically the state to "disabled" */
713 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
714 /* Set transient enabler state to "enabled" */
716 lttng_session_sync_event_enablers(channel
->session
);
722 struct cds_hlist_head
*borrow_hash_table_bucket(
723 struct cds_hlist_head
*hash_table
,
724 unsigned int hash_table_size
,
725 const struct lttng_event_desc
*desc
)
727 const char *event_name
;
731 event_name
= desc
->name
;
732 name_len
= strlen(event_name
);
734 hash
= jhash(event_name
, name_len
, 0);
735 return &hash_table
[hash
& (hash_table_size
- 1)];
739 * Supports event creation while tracing session is active.
742 int lttng_event_create(const struct lttng_event_desc
*desc
,
743 struct lttng_channel
*chan
)
745 struct lttng_event
*event
;
746 struct lttng_session
*session
= chan
->session
;
747 struct cds_hlist_head
*head
;
749 int notify_socket
, loglevel
;
752 head
= borrow_hash_table_bucket(chan
->session
->events_ht
.table
,
753 LTTNG_UST_EVENT_HT_SIZE
, desc
);
755 notify_socket
= lttng_get_notify_socket(session
->owner
);
756 if (notify_socket
< 0) {
761 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
764 DBG("Error (%d) adding enum to session", ret
);
765 goto create_enum_error
;
769 * Check if loglevel match. Refuse to connect event if not.
771 event
= zmalloc(sizeof(struct lttng_event
));
778 /* Event will be enabled by enabler sync. */
780 event
->registered
= 0;
781 CDS_INIT_LIST_HEAD(&event
->filter_bytecode_runtime_head
);
782 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
786 loglevel
= *(*event
->desc
->loglevel
);
788 loglevel
= TRACE_DEFAULT
;
789 if (desc
->u
.ext
.model_emf_uri
)
790 uri
= *(desc
->u
.ext
.model_emf_uri
);
794 /* Fetch event ID from sessiond */
795 ret
= ustcomm_register_event(notify_socket
,
807 DBG("Error (%d) registering event to sessiond", ret
);
808 goto sessiond_register_error
;
811 cds_list_add(&event
->node
, &chan
->session
->events_head
);
812 cds_hlist_add_head(&event
->hlist
, head
);
815 sessiond_register_error
:
824 int lttng_event_notifier_create(const struct lttng_event_desc
*desc
,
825 uint64_t token
, uint64_t error_counter_index
,
826 struct lttng_event_notifier_group
*event_notifier_group
)
828 struct lttng_event_notifier
*event_notifier
;
829 struct cds_hlist_head
*head
;
833 * Get the hashtable bucket the created lttng_event_notifier object
834 * should be inserted.
836 head
= borrow_hash_table_bucket(
837 event_notifier_group
->event_notifiers_ht
.table
,
838 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
, desc
);
840 event_notifier
= zmalloc(sizeof(struct lttng_event_notifier
));
841 if (!event_notifier
) {
846 event_notifier
->group
= event_notifier_group
;
847 event_notifier
->user_token
= token
;
848 event_notifier
->error_counter_index
= error_counter_index
;
850 /* Event notifier will be enabled by enabler sync. */
851 event_notifier
->enabled
= 0;
852 event_notifier
->registered
= 0;
854 CDS_INIT_LIST_HEAD(&event_notifier
->filter_bytecode_runtime_head
);
855 CDS_INIT_LIST_HEAD(&event_notifier
->capture_bytecode_runtime_head
);
856 CDS_INIT_LIST_HEAD(&event_notifier
->enablers_ref_head
);
857 event_notifier
->desc
= desc
;
858 event_notifier
->notification_send
= lttng_event_notifier_notification_send
;
860 cds_list_add(&event_notifier
->node
,
861 &event_notifier_group
->event_notifiers_head
);
862 cds_hlist_add_head(&event_notifier
->hlist
, head
);
871 void _lttng_event_notifier_destroy(struct lttng_event_notifier
*event_notifier
)
873 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
875 /* Remove from event_notifier list. */
876 cds_list_del(&event_notifier
->node
);
877 /* Remove from event_notifier hash table. */
878 cds_hlist_del(&event_notifier
->hlist
);
880 lttng_free_event_notifier_filter_runtime(event_notifier
);
882 /* Free event_notifier enabler refs */
883 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
884 &event_notifier
->enablers_ref_head
, node
)
886 free(event_notifier
);
890 int lttng_desc_match_star_glob_enabler(const struct lttng_event_desc
*desc
,
891 struct lttng_enabler
*enabler
)
894 unsigned int has_loglevel
= 0;
896 assert(enabler
->format_type
== LTTNG_ENABLER_FORMAT_STAR_GLOB
);
897 if (!strutils_star_glob_match(enabler
->event_param
.name
, SIZE_MAX
,
898 desc
->name
, SIZE_MAX
))
900 if (desc
->loglevel
) {
901 loglevel
= *(*desc
->loglevel
);
904 if (!lttng_loglevel_match(loglevel
,
906 enabler
->event_param
.loglevel_type
,
907 enabler
->event_param
.loglevel
))
913 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
914 struct lttng_enabler
*enabler
)
917 unsigned int has_loglevel
= 0;
919 assert(enabler
->format_type
== LTTNG_ENABLER_FORMAT_EVENT
);
920 if (strcmp(desc
->name
, enabler
->event_param
.name
))
922 if (desc
->loglevel
) {
923 loglevel
= *(*desc
->loglevel
);
926 if (!lttng_loglevel_match(loglevel
,
928 enabler
->event_param
.loglevel_type
,
929 enabler
->event_param
.loglevel
))
935 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
936 struct lttng_enabler
*enabler
)
938 switch (enabler
->format_type
) {
939 case LTTNG_ENABLER_FORMAT_STAR_GLOB
:
941 struct lttng_ust_excluder_node
*excluder
;
943 if (!lttng_desc_match_star_glob_enabler(desc
, enabler
)) {
948 * If the matching event matches with an excluder,
949 * return 'does not match'
951 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
954 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
958 excluder_name
= (char *) (excluder
->excluder
.names
)
959 + count
* LTTNG_UST_SYM_NAME_LEN
;
960 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
961 if (len
> 0 && strutils_star_glob_match(excluder_name
, len
, desc
->name
, SIZE_MAX
))
967 case LTTNG_ENABLER_FORMAT_EVENT
:
968 return lttng_desc_match_event_enabler(desc
, enabler
);
975 int lttng_event_enabler_match_event(struct lttng_event_enabler
*event_enabler
,
976 struct lttng_event
*event
)
978 if (lttng_desc_match_enabler(event
->desc
,
979 lttng_event_enabler_as_enabler(event_enabler
))
980 && event
->chan
== event_enabler
->chan
)
987 int lttng_event_notifier_enabler_match_event_notifier(
988 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
989 struct lttng_event_notifier
*event_notifier
)
991 int desc_matches
= lttng_desc_match_enabler(event_notifier
->desc
,
992 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
));
994 if (desc_matches
&& event_notifier
->group
== event_notifier_enabler
->group
&&
995 event_notifier
->user_token
== event_notifier_enabler
->user_token
)
1002 struct lttng_enabler_ref
*lttng_enabler_ref(
1003 struct cds_list_head
*enabler_ref_list
,
1004 struct lttng_enabler
*enabler
)
1006 struct lttng_enabler_ref
*enabler_ref
;
1008 cds_list_for_each_entry(enabler_ref
, enabler_ref_list
, node
) {
1009 if (enabler_ref
->ref
== enabler
)
1016 * Create struct lttng_event if it is missing and present in the list of
1017 * tracepoint probes.
1020 void lttng_create_event_if_missing(struct lttng_event_enabler
*event_enabler
)
1022 struct lttng_session
*session
= event_enabler
->chan
->session
;
1023 struct lttng_probe_desc
*probe_desc
;
1024 const struct lttng_event_desc
*desc
;
1025 struct lttng_event
*event
;
1027 struct cds_list_head
*probe_list
;
1029 probe_list
= lttng_get_probe_list_head();
1031 * For each probe event, if we find that a probe event matches
1032 * our enabler, create an associated lttng_event if not
1035 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
1036 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1039 struct cds_hlist_head
*head
;
1040 struct cds_hlist_node
*node
;
1042 desc
= probe_desc
->event_desc
[i
];
1043 if (!lttng_desc_match_enabler(desc
,
1044 lttng_event_enabler_as_enabler(event_enabler
)))
1047 head
= borrow_hash_table_bucket(
1048 session
->events_ht
.table
,
1049 LTTNG_UST_EVENT_HT_SIZE
, desc
);
1051 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
1052 if (event
->desc
== desc
1053 && event
->chan
== event_enabler
->chan
) {
1062 * We need to create an event for this
1065 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
1066 event_enabler
->chan
);
1068 DBG("Unable to create event %s, error %d\n",
1069 probe_desc
->event_desc
[i
]->name
, ret
);
1076 void probe_provider_event_for_each(struct lttng_probe_desc
*provider_desc
,
1077 void (*event_func
)(struct lttng_session
*session
,
1078 struct lttng_event
*event
),
1079 void (*event_notifier_func
)(struct lttng_event_notifier
*event_notifier
))
1081 struct cds_hlist_node
*node
, *tmp_node
;
1082 struct cds_list_head
*sessionsp
;
1085 /* Get handle on list of sessions. */
1086 sessionsp
= _lttng_get_sessions();
1089 * Iterate over all events in the probe provider descriptions and
1090 * sessions to queue the unregistration of the events.
1092 for (i
= 0; i
< provider_desc
->nr_events
; i
++) {
1093 const struct lttng_event_desc
*event_desc
;
1094 struct lttng_event_notifier_group
*event_notifier_group
;
1095 struct lttng_event_notifier
*event_notifier
;
1096 struct lttng_session
*session
;
1097 struct cds_hlist_head
*head
;
1098 struct lttng_event
*event
;
1100 event_desc
= provider_desc
->event_desc
[i
];
1103 * Iterate over all session to find the current event
1106 cds_list_for_each_entry(session
, sessionsp
, node
) {
1108 * Get the list of events in the hashtable bucket and
1109 * iterate to find the event matching this descriptor.
1111 head
= borrow_hash_table_bucket(
1112 session
->events_ht
.table
,
1113 LTTNG_UST_EVENT_HT_SIZE
, event_desc
);
1115 cds_hlist_for_each_entry_safe(event
, node
, tmp_node
, head
, hlist
) {
1116 if (event_desc
== event
->desc
) {
1117 event_func(session
, event
);
1124 * Iterate over all event_notifier groups to find the current event
1127 cds_list_for_each_entry(event_notifier_group
, &event_notifier_groups
, node
) {
1129 * Get the list of event_notifiers in the hashtable bucket and
1130 * iterate to find the event_notifier matching this
1133 head
= borrow_hash_table_bucket(
1134 event_notifier_group
->event_notifiers_ht
.table
,
1135 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
, event_desc
);
1137 cds_hlist_for_each_entry_safe(event_notifier
, node
, tmp_node
, head
, hlist
) {
1138 if (event_desc
== event_notifier
->desc
) {
1139 event_notifier_func(event_notifier
);
1148 void _unregister_event(struct lttng_session
*session
,
1149 struct lttng_event
*event
)
1151 _lttng_event_unregister(event
);
1155 void _event_enum_destroy(struct lttng_session
*session
,
1156 struct lttng_event
*event
)
1160 /* Destroy enums of the current event. */
1161 for (i
= 0; i
< event
->desc
->nr_fields
; i
++) {
1162 const struct lttng_enum_desc
*enum_desc
;
1163 const struct lttng_event_field
*field
;
1164 struct lttng_enum
*curr_enum
;
1166 field
= &(event
->desc
->fields
[i
]);
1167 switch (field
->type
.atype
) {
1169 enum_desc
= field
->type
.u
.legacy
.basic
.enumeration
.desc
;
1171 case atype_enum_nestable
:
1172 enum_desc
= field
->type
.u
.enum_nestable
.desc
;
1178 curr_enum
= lttng_ust_enum_get_from_desc(session
, enum_desc
);
1180 _lttng_enum_destroy(curr_enum
);
1184 /* Destroy event. */
1185 _lttng_event_destroy(event
);
1189 * Iterate over all the UST sessions to unregister and destroy all probes from
1190 * the probe provider descriptor received as argument. Must me called with the
1193 void lttng_probe_provider_unregister_events(
1194 struct lttng_probe_desc
*provider_desc
)
1197 * Iterate over all events in the probe provider descriptions and sessions
1198 * to queue the unregistration of the events.
1200 probe_provider_event_for_each(provider_desc
, _unregister_event
,
1201 _lttng_event_notifier_unregister
);
1203 /* Wait for grace period. */
1204 lttng_ust_synchronize_trace();
1205 /* Prune the unregistration queue. */
1206 __tracepoint_probe_prune_release_queue();
1209 * It is now safe to destroy the events and remove them from the event list
1212 probe_provider_event_for_each(provider_desc
, _event_enum_destroy
,
1213 _lttng_event_notifier_destroy
);
1217 * Create events associated with an event enabler (if not already present),
1218 * and add backward reference from the event to the enabler.
1221 int lttng_event_enabler_ref_events(struct lttng_event_enabler
*event_enabler
)
1223 struct lttng_session
*session
= event_enabler
->chan
->session
;
1224 struct lttng_event
*event
;
1226 if (!lttng_event_enabler_as_enabler(event_enabler
)->enabled
)
1229 /* First ensure that probe events are created for this enabler. */
1230 lttng_create_event_if_missing(event_enabler
);
1232 /* For each event matching enabler in session event list. */
1233 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1234 struct lttng_enabler_ref
*enabler_ref
;
1236 if (!lttng_event_enabler_match_event(event_enabler
, event
))
1239 enabler_ref
= lttng_enabler_ref(&event
->enablers_ref_head
,
1240 lttng_event_enabler_as_enabler(event_enabler
));
1243 * If no backward ref, create it.
1244 * Add backward ref from event to enabler.
1246 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
1249 enabler_ref
->ref
= lttng_event_enabler_as_enabler(
1251 cds_list_add(&enabler_ref
->node
,
1252 &event
->enablers_ref_head
);
1256 * Link filter bytecodes if not linked yet.
1258 lttng_enabler_link_bytecode(event
->desc
,
1260 &event
->filter_bytecode_runtime_head
,
1261 <tng_event_enabler_as_enabler(event_enabler
)->filter_bytecode_head
);
1263 /* TODO: merge event context. */
1270 * Called at library load: connect the probe on all enablers matching
1272 * Called with session mutex held.
1274 int lttng_fix_pending_events(void)
1276 struct lttng_session
*session
;
1278 cds_list_for_each_entry(session
, &sessions
, node
) {
1279 lttng_session_lazy_sync_event_enablers(session
);
1284 int lttng_fix_pending_event_notifiers(void)
1286 struct lttng_event_notifier_group
*event_notifier_group
;
1288 cds_list_for_each_entry(event_notifier_group
, &event_notifier_groups
, node
) {
1289 lttng_event_notifier_group_sync_enablers(event_notifier_group
);
1295 * For each session of the owner thread, execute pending statedump.
1296 * Only dump state for the sessions owned by the caller thread, because
1297 * we don't keep ust_lock across the entire iteration.
1299 void lttng_handle_pending_statedump(void *owner
)
1301 struct lttng_session
*session
;
1303 /* Execute state dump */
1304 do_lttng_ust_statedump(owner
);
1306 /* Clear pending state dump */
1310 cds_list_for_each_entry(session
, &sessions
, node
) {
1311 if (session
->owner
!= owner
)
1313 if (!session
->statedump_pending
)
1315 session
->statedump_pending
= 0;
1323 * Only used internally at session destruction.
1326 void _lttng_event_destroy(struct lttng_event
*event
)
1328 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
1330 /* Remove from event list. */
1331 cds_list_del(&event
->node
);
1332 /* Remove from event hash table. */
1333 cds_hlist_del(&event
->hlist
);
1335 lttng_destroy_context(event
->ctx
);
1336 lttng_free_event_filter_runtime(event
);
1337 /* Free event enabler refs */
1338 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
1339 &event
->enablers_ref_head
, node
)
1345 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
1347 cds_list_del(&_enum
->node
);
1348 cds_hlist_del(&_enum
->hlist
);
1352 void lttng_ust_events_exit(void)
1354 struct lttng_session
*session
, *tmpsession
;
1356 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
1357 lttng_session_destroy(session
);
1361 * Enabler management.
1363 struct lttng_event_enabler
*lttng_event_enabler_create(
1364 enum lttng_enabler_format_type format_type
,
1365 struct lttng_ust_event
*event_param
,
1366 struct lttng_channel
*chan
)
1368 struct lttng_event_enabler
*event_enabler
;
1370 event_enabler
= zmalloc(sizeof(*event_enabler
));
1373 event_enabler
->base
.format_type
= format_type
;
1374 CDS_INIT_LIST_HEAD(&event_enabler
->base
.filter_bytecode_head
);
1375 CDS_INIT_LIST_HEAD(&event_enabler
->base
.excluder_head
);
1376 memcpy(&event_enabler
->base
.event_param
, event_param
,
1377 sizeof(event_enabler
->base
.event_param
));
1378 event_enabler
->chan
= chan
;
1380 event_enabler
->base
.enabled
= 0;
1381 cds_list_add(&event_enabler
->node
, &event_enabler
->chan
->session
->enablers_head
);
1382 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1384 return event_enabler
;
1387 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
1388 struct lttng_event_notifier_group
*event_notifier_group
,
1389 enum lttng_enabler_format_type format_type
,
1390 struct lttng_ust_event_notifier
*event_notifier_param
)
1392 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
1394 event_notifier_enabler
= zmalloc(sizeof(*event_notifier_enabler
));
1395 if (!event_notifier_enabler
)
1397 event_notifier_enabler
->base
.format_type
= format_type
;
1398 CDS_INIT_LIST_HEAD(&event_notifier_enabler
->base
.filter_bytecode_head
);
1399 CDS_INIT_LIST_HEAD(&event_notifier_enabler
->capture_bytecode_head
);
1400 CDS_INIT_LIST_HEAD(&event_notifier_enabler
->base
.excluder_head
);
1402 event_notifier_enabler
->user_token
= event_notifier_param
->event
.token
;
1403 event_notifier_enabler
->error_counter_index
= event_notifier_param
->error_counter_index
;
1404 event_notifier_enabler
->num_captures
= 0;
1406 memcpy(&event_notifier_enabler
->base
.event_param
.name
,
1407 event_notifier_param
->event
.name
,
1408 sizeof(event_notifier_enabler
->base
.event_param
.name
));
1409 event_notifier_enabler
->base
.event_param
.instrumentation
=
1410 event_notifier_param
->event
.instrumentation
;
1411 event_notifier_enabler
->base
.event_param
.loglevel
=
1412 event_notifier_param
->event
.loglevel
;
1413 event_notifier_enabler
->base
.event_param
.loglevel_type
=
1414 event_notifier_param
->event
.loglevel_type
;
1416 event_notifier_enabler
->base
.enabled
= 0;
1417 event_notifier_enabler
->group
= event_notifier_group
;
1419 cds_list_add(&event_notifier_enabler
->node
,
1420 &event_notifier_group
->enablers_head
);
1422 lttng_event_notifier_group_sync_enablers(event_notifier_group
);
1424 return event_notifier_enabler
;
1427 int lttng_event_enabler_enable(struct lttng_event_enabler
*event_enabler
)
1429 lttng_event_enabler_as_enabler(event_enabler
)->enabled
= 1;
1430 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1435 int lttng_event_enabler_disable(struct lttng_event_enabler
*event_enabler
)
1437 lttng_event_enabler_as_enabler(event_enabler
)->enabled
= 0;
1438 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1444 void _lttng_enabler_attach_filter_bytecode(struct lttng_enabler
*enabler
,
1445 struct lttng_ust_bytecode_node
**bytecode
)
1447 (*bytecode
)->enabler
= enabler
;
1448 cds_list_add_tail(&(*bytecode
)->node
, &enabler
->filter_bytecode_head
);
1449 /* Take ownership of bytecode */
1453 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler
*event_enabler
,
1454 struct lttng_ust_bytecode_node
**bytecode
)
1456 _lttng_enabler_attach_filter_bytecode(
1457 lttng_event_enabler_as_enabler(event_enabler
), bytecode
);
1459 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1464 void _lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
1465 struct lttng_ust_excluder_node
**excluder
)
1467 (*excluder
)->enabler
= enabler
;
1468 cds_list_add_tail(&(*excluder
)->node
, &enabler
->excluder_head
);
1469 /* Take ownership of excluder */
1473 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler
*event_enabler
,
1474 struct lttng_ust_excluder_node
**excluder
)
1476 _lttng_enabler_attach_exclusion(
1477 lttng_event_enabler_as_enabler(event_enabler
), excluder
);
1479 lttng_session_lazy_sync_event_enablers(event_enabler
->chan
->session
);
1483 int lttng_event_notifier_enabler_enable(
1484 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1486 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->enabled
= 1;
1487 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1492 int lttng_event_notifier_enabler_disable(
1493 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1495 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->enabled
= 0;
1496 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1501 int lttng_event_notifier_enabler_attach_filter_bytecode(
1502 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
1503 struct lttng_ust_bytecode_node
**bytecode
)
1505 _lttng_enabler_attach_filter_bytecode(
1506 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
),
1509 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1513 int lttng_event_notifier_enabler_attach_capture_bytecode(
1514 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
1515 struct lttng_ust_bytecode_node
**bytecode
)
1517 (*bytecode
)->enabler
= lttng_event_notifier_enabler_as_enabler(
1518 event_notifier_enabler
);
1519 cds_list_add_tail(&(*bytecode
)->node
,
1520 &event_notifier_enabler
->capture_bytecode_head
);
1521 /* Take ownership of bytecode */
1523 event_notifier_enabler
->num_captures
++;
1525 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1529 int lttng_event_notifier_enabler_attach_exclusion(
1530 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
1531 struct lttng_ust_excluder_node
**excluder
)
1533 _lttng_enabler_attach_exclusion(
1534 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
),
1537 lttng_event_notifier_group_sync_enablers(event_notifier_enabler
->group
);
1541 int lttng_attach_context(struct lttng_ust_context
*context_param
,
1542 union ust_args
*uargs
,
1543 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
1546 * We cannot attach a context after trace has been started for a
1547 * session because the metadata does not allow expressing this
1548 * information outside of the original channel scope.
1550 if (session
->been_active
)
1553 switch (context_param
->ctx
) {
1554 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
1555 return lttng_add_pthread_id_to_ctx(ctx
);
1556 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
1558 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
1560 perf_ctx_param
= &context_param
->u
.perf_counter
;
1561 return lttng_add_perf_counter_to_ctx(
1562 perf_ctx_param
->type
,
1563 perf_ctx_param
->config
,
1564 perf_ctx_param
->name
,
1567 case LTTNG_UST_CONTEXT_VTID
:
1568 return lttng_add_vtid_to_ctx(ctx
);
1569 case LTTNG_UST_CONTEXT_VPID
:
1570 return lttng_add_vpid_to_ctx(ctx
);
1571 case LTTNG_UST_CONTEXT_PROCNAME
:
1572 return lttng_add_procname_to_ctx(ctx
);
1573 case LTTNG_UST_CONTEXT_IP
:
1574 return lttng_add_ip_to_ctx(ctx
);
1575 case LTTNG_UST_CONTEXT_CPU_ID
:
1576 return lttng_add_cpu_id_to_ctx(ctx
);
1577 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1578 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1580 case LTTNG_UST_CONTEXT_CGROUP_NS
:
1581 return lttng_add_cgroup_ns_to_ctx(ctx
);
1582 case LTTNG_UST_CONTEXT_IPC_NS
:
1583 return lttng_add_ipc_ns_to_ctx(ctx
);
1584 case LTTNG_UST_CONTEXT_MNT_NS
:
1585 return lttng_add_mnt_ns_to_ctx(ctx
);
1586 case LTTNG_UST_CONTEXT_NET_NS
:
1587 return lttng_add_net_ns_to_ctx(ctx
);
1588 case LTTNG_UST_CONTEXT_PID_NS
:
1589 return lttng_add_pid_ns_to_ctx(ctx
);
1590 case LTTNG_UST_CONTEXT_TIME_NS
:
1591 return lttng_add_time_ns_to_ctx(ctx
);
1592 case LTTNG_UST_CONTEXT_USER_NS
:
1593 return lttng_add_user_ns_to_ctx(ctx
);
1594 case LTTNG_UST_CONTEXT_UTS_NS
:
1595 return lttng_add_uts_ns_to_ctx(ctx
);
1596 case LTTNG_UST_CONTEXT_VUID
:
1597 return lttng_add_vuid_to_ctx(ctx
);
1598 case LTTNG_UST_CONTEXT_VEUID
:
1599 return lttng_add_veuid_to_ctx(ctx
);
1600 case LTTNG_UST_CONTEXT_VSUID
:
1601 return lttng_add_vsuid_to_ctx(ctx
);
1602 case LTTNG_UST_CONTEXT_VGID
:
1603 return lttng_add_vgid_to_ctx(ctx
);
1604 case LTTNG_UST_CONTEXT_VEGID
:
1605 return lttng_add_vegid_to_ctx(ctx
);
1606 case LTTNG_UST_CONTEXT_VSGID
:
1607 return lttng_add_vsgid_to_ctx(ctx
);
1613 int lttng_event_enabler_attach_context(struct lttng_event_enabler
*enabler
,
1614 struct lttng_ust_context
*context_param
)
1619 void lttng_event_enabler_destroy(struct lttng_event_enabler
*event_enabler
)
1621 if (!event_enabler
) {
1624 cds_list_del(&event_enabler
->node
);
1626 lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler
));
1628 lttng_destroy_context(event_enabler
->ctx
);
1629 free(event_enabler
);
1633 * lttng_session_sync_event_enablers should be called just before starting a
1637 void lttng_session_sync_event_enablers(struct lttng_session
*session
)
1639 struct lttng_event_enabler
*event_enabler
;
1640 struct lttng_event
*event
;
1642 cds_list_for_each_entry(event_enabler
, &session
->enablers_head
, node
)
1643 lttng_event_enabler_ref_events(event_enabler
);
1645 * For each event, if at least one of its enablers is enabled,
1646 * and its channel and session transient states are enabled, we
1647 * enable the event, else we disable it.
1649 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1650 struct lttng_enabler_ref
*enabler_ref
;
1651 struct lttng_bytecode_runtime
*runtime
;
1652 int enabled
= 0, has_enablers_without_bytecode
= 0;
1655 cds_list_for_each_entry(enabler_ref
,
1656 &event
->enablers_ref_head
, node
) {
1657 if (enabler_ref
->ref
->enabled
) {
1663 * Enabled state is based on union of enablers, with
1664 * intesection of session and channel transient enable
1667 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1669 CMM_STORE_SHARED(event
->enabled
, enabled
);
1671 * Sync tracepoint registration with event enabled
1675 if (!event
->registered
)
1676 register_event(event
);
1678 if (event
->registered
)
1679 unregister_event(event
);
1682 /* Check if has enablers without bytecode enabled */
1683 cds_list_for_each_entry(enabler_ref
,
1684 &event
->enablers_ref_head
, node
) {
1685 if (enabler_ref
->ref
->enabled
1686 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1687 has_enablers_without_bytecode
= 1;
1691 event
->has_enablers_without_bytecode
=
1692 has_enablers_without_bytecode
;
1694 /* Enable filters */
1695 cds_list_for_each_entry(runtime
,
1696 &event
->filter_bytecode_runtime_head
, node
) {
1697 lttng_bytecode_filter_sync_state(runtime
);
1700 __tracepoint_probe_prune_release_queue();
1703 /* Support for event notifier is introduced by probe provider major version 2. */
1705 bool lttng_ust_probe_supports_event_notifier(struct lttng_probe_desc
*probe_desc
)
1707 return probe_desc
->major
>= 2;
1711 void lttng_create_event_notifier_if_missing(
1712 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1714 struct lttng_event_notifier_group
*event_notifier_group
= event_notifier_enabler
->group
;
1715 struct lttng_probe_desc
*probe_desc
;
1716 struct cds_list_head
*probe_list
;
1719 probe_list
= lttng_get_probe_list_head();
1721 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
1722 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
1725 const struct lttng_event_desc
*desc
;
1726 struct lttng_event_notifier
*event_notifier
;
1727 struct cds_hlist_head
*head
;
1728 struct cds_hlist_node
*node
;
1730 desc
= probe_desc
->event_desc
[i
];
1732 if (!lttng_desc_match_enabler(desc
,
1733 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)))
1737 * Given the current event_notifier group, get the bucket that
1738 * the target event_notifier would be if it was already
1741 head
= borrow_hash_table_bucket(
1742 event_notifier_group
->event_notifiers_ht
.table
,
1743 LTTNG_UST_EVENT_NOTIFIER_HT_SIZE
, desc
);
1745 cds_hlist_for_each_entry(event_notifier
, node
, head
, hlist
) {
1747 * Check if event_notifier already exists by checking
1748 * if the event_notifier and enabler share the same
1749 * description and id.
1751 if (event_notifier
->desc
== desc
&&
1752 event_notifier
->user_token
== event_notifier_enabler
->user_token
) {
1761 /* Check that the probe supports event notifiers, else report the error. */
1762 if (!lttng_ust_probe_supports_event_notifier(probe_desc
)) {
1763 ERR("Probe \"%s\" contains event \"%s\" which matches an enabled event notifier, "
1764 "but its version (%u.%u) is too old and does not implement event notifiers. "
1765 "It needs to be recompiled against a newer version of LTTng-UST, otherwise "
1766 "this event will not generate any notification.",
1767 probe_desc
->provider
,
1774 * We need to create a event_notifier for this event probe.
1776 ret
= lttng_event_notifier_create(desc
,
1777 event_notifier_enabler
->user_token
,
1778 event_notifier_enabler
->error_counter_index
,
1779 event_notifier_group
);
1781 DBG("Unable to create event_notifier %s, error %d\n",
1782 probe_desc
->event_desc
[i
]->name
, ret
);
1789 * Create event_notifiers associated with a event_notifier enabler (if not already present).
1792 int lttng_event_notifier_enabler_ref_event_notifiers(
1793 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
1795 struct lttng_event_notifier_group
*event_notifier_group
= event_notifier_enabler
->group
;
1796 struct lttng_event_notifier
*event_notifier
;
1799 * Only try to create event_notifiers for enablers that are enabled, the user
1800 * might still be attaching filter or exclusion to the
1801 * event_notifier_enabler.
1803 if (!lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->enabled
)
1806 /* First, ensure that probe event_notifiers are created for this enabler. */
1807 lttng_create_event_notifier_if_missing(event_notifier_enabler
);
1809 /* Link the created event_notifier with its associated enabler. */
1810 cds_list_for_each_entry(event_notifier
, &event_notifier_group
->event_notifiers_head
, node
) {
1811 struct lttng_enabler_ref
*enabler_ref
;
1813 if (!lttng_event_notifier_enabler_match_event_notifier(event_notifier_enabler
, event_notifier
))
1816 enabler_ref
= lttng_enabler_ref(&event_notifier
->enablers_ref_head
,
1817 lttng_event_notifier_enabler_as_enabler(event_notifier_enabler
));
1820 * If no backward ref, create it.
1821 * Add backward ref from event_notifier to enabler.
1823 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
1827 enabler_ref
->ref
= lttng_event_notifier_enabler_as_enabler(
1828 event_notifier_enabler
);
1829 cds_list_add(&enabler_ref
->node
,
1830 &event_notifier
->enablers_ref_head
);
1834 * Link filter bytecodes if not linked yet.
1836 lttng_enabler_link_bytecode(event_notifier
->desc
,
1837 &event_notifier_group
->ctx
,
1838 &event_notifier
->filter_bytecode_runtime_head
,
1839 <tng_event_notifier_enabler_as_enabler(event_notifier_enabler
)->filter_bytecode_head
);
1842 * Link capture bytecodes if not linked yet.
1844 lttng_enabler_link_bytecode(event_notifier
->desc
,
1845 &event_notifier_group
->ctx
, &event_notifier
->capture_bytecode_runtime_head
,
1846 &event_notifier_enabler
->capture_bytecode_head
);
1848 event_notifier
->num_captures
= event_notifier_enabler
->num_captures
;
1855 void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group
*event_notifier_group
)
1857 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
1858 struct lttng_event_notifier
*event_notifier
;
1860 cds_list_for_each_entry(event_notifier_enabler
, &event_notifier_group
->enablers_head
, node
)
1861 lttng_event_notifier_enabler_ref_event_notifiers(event_notifier_enabler
);
1864 * For each event_notifier, if at least one of its enablers is enabled,
1865 * we enable the event_notifier, else we disable it.
1867 cds_list_for_each_entry(event_notifier
, &event_notifier_group
->event_notifiers_head
, node
) {
1868 struct lttng_enabler_ref
*enabler_ref
;
1869 struct lttng_bytecode_runtime
*runtime
;
1870 int enabled
= 0, has_enablers_without_bytecode
= 0;
1872 /* Enable event_notifiers */
1873 cds_list_for_each_entry(enabler_ref
,
1874 &event_notifier
->enablers_ref_head
, node
) {
1875 if (enabler_ref
->ref
->enabled
) {
1881 CMM_STORE_SHARED(event_notifier
->enabled
, enabled
);
1883 * Sync tracepoint registration with event_notifier enabled
1887 if (!event_notifier
->registered
)
1888 register_event_notifier(event_notifier
);
1890 if (event_notifier
->registered
)
1891 unregister_event_notifier(event_notifier
);
1894 /* Check if has enablers without bytecode enabled */
1895 cds_list_for_each_entry(enabler_ref
,
1896 &event_notifier
->enablers_ref_head
, node
) {
1897 if (enabler_ref
->ref
->enabled
1898 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1899 has_enablers_without_bytecode
= 1;
1903 event_notifier
->has_enablers_without_bytecode
=
1904 has_enablers_without_bytecode
;
1906 /* Enable filters */
1907 cds_list_for_each_entry(runtime
,
1908 &event_notifier
->filter_bytecode_runtime_head
, node
) {
1909 lttng_bytecode_filter_sync_state(runtime
);
1912 /* Enable captures. */
1913 cds_list_for_each_entry(runtime
,
1914 &event_notifier
->capture_bytecode_runtime_head
, node
) {
1915 lttng_bytecode_capture_sync_state(runtime
);
1918 __tracepoint_probe_prune_release_queue();
1922 * Apply enablers to session events, adding events to session if need
1923 * be. It is required after each modification applied to an active
1924 * session, and right before session "start".
1925 * "lazy" sync means we only sync if required.
1928 void lttng_session_lazy_sync_event_enablers(struct lttng_session
*session
)
1930 /* We can skip if session is not active */
1931 if (!session
->active
)
1933 lttng_session_sync_event_enablers(session
);
1937 * Update all sessions with the given app context.
1938 * Called with ust lock held.
1939 * This is invoked when an application context gets loaded/unloaded. It
1940 * ensures the context callbacks are in sync with the application
1941 * context (either app context callbacks, or dummy callbacks).
1943 void lttng_ust_context_set_session_provider(const char *name
,
1944 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1945 void (*record
)(struct lttng_ctx_field
*field
,
1946 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1947 struct lttng_channel
*chan
),
1948 void (*get_value
)(struct lttng_ctx_field
*field
,
1949 struct lttng_ctx_value
*value
))
1951 struct lttng_session
*session
;
1953 cds_list_for_each_entry(session
, &sessions
, node
) {
1954 struct lttng_channel
*chan
;
1955 struct lttng_event
*event
;
1958 ret
= lttng_ust_context_set_provider_rcu(&session
->ctx
,
1959 name
, get_size
, record
, get_value
);
1962 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
1963 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1964 name
, get_size
, record
, get_value
);
1968 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1969 ret
= lttng_ust_context_set_provider_rcu(&event
->ctx
,
1970 name
, get_size
, record
, get_value
);
1978 * Update all event_notifier groups with the given app context.
1979 * Called with ust lock held.
1980 * This is invoked when an application context gets loaded/unloaded. It
1981 * ensures the context callbacks are in sync with the application
1982 * context (either app context callbacks, or dummy callbacks).
1984 void lttng_ust_context_set_event_notifier_group_provider(const char *name
,
1985 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1986 void (*record
)(struct lttng_ctx_field
*field
,
1987 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1988 struct lttng_channel
*chan
),
1989 void (*get_value
)(struct lttng_ctx_field
*field
,
1990 struct lttng_ctx_value
*value
))
1992 struct lttng_event_notifier_group
*event_notifier_group
;
1994 cds_list_for_each_entry(event_notifier_group
, &event_notifier_groups
, node
) {
1997 ret
= lttng_ust_context_set_provider_rcu(
1998 &event_notifier_group
->ctx
,
1999 name
, get_size
, record
, get_value
);