4 * Holds LTTng per-session event registry.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
35 #include <lttng/ust-endian.h>
39 #include <urcu/compiler.h>
40 #include <urcu/uatomic.h>
41 #include <urcu/arch.h>
43 #include <lttng/tracepoint.h>
44 #include <lttng/ust-events.h>
46 #include <usterr-signal-safe.h>
48 #include <lttng/ust-ctl.h>
52 #include "lttng-ust-uuid.h"
54 #include "tracepoint-internal.h"
55 #include "lttng-tracer.h"
56 #include "lttng-tracer-core.h"
57 #include "lttng-ust-statedump.h"
59 #include "../libringbuffer/shm.h"
63 * All operations within this file are called by the communication
64 * thread, under ust_lock protection.
67 static CDS_LIST_HEAD(sessions
);
69 struct cds_list_head
*_lttng_get_sessions(void)
74 static void _lttng_event_destroy(struct lttng_event
*event
);
75 static void _lttng_enum_destroy(struct lttng_enum
*_enum
);
78 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
);
80 void lttng_session_sync_enablers(struct lttng_session
*session
);
82 void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
85 * Called with ust lock held.
87 int lttng_session_active(void)
89 struct lttng_session
*iter
;
91 cds_list_for_each_entry(iter
, &sessions
, node
) {
99 int lttng_loglevel_match(int loglevel
,
100 unsigned int has_loglevel
,
101 enum lttng_ust_loglevel_type req_type
,
105 loglevel
= TRACE_DEFAULT
;
107 case LTTNG_UST_LOGLEVEL_RANGE
:
108 if (loglevel
<= req_loglevel
109 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
113 case LTTNG_UST_LOGLEVEL_SINGLE
:
114 if (loglevel
== req_loglevel
115 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
119 case LTTNG_UST_LOGLEVEL_ALL
:
121 if (loglevel
<= TRACE_DEBUG
)
128 void synchronize_trace(void)
133 struct lttng_session
*lttng_session_create(void)
135 struct lttng_session
*session
;
138 session
= zmalloc(sizeof(struct lttng_session
));
141 CDS_INIT_LIST_HEAD(&session
->chan_head
);
142 CDS_INIT_LIST_HEAD(&session
->events_head
);
143 CDS_INIT_LIST_HEAD(&session
->enums_head
);
144 CDS_INIT_LIST_HEAD(&session
->enablers_head
);
145 for (i
= 0; i
< LTTNG_UST_EVENT_HT_SIZE
; i
++)
146 CDS_INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
147 for (i
= 0; i
< LTTNG_UST_ENUM_HT_SIZE
; i
++)
148 CDS_INIT_HLIST_HEAD(&session
->enums_ht
.table
[i
]);
149 cds_list_add(&session
->node
, &sessions
);
154 * Only used internally at session destruction.
157 void _lttng_channel_unmap(struct lttng_channel
*lttng_chan
)
159 struct channel
*chan
;
160 struct lttng_ust_shm_handle
*handle
;
162 cds_list_del(<tng_chan
->node
);
163 lttng_destroy_context(lttng_chan
->ctx
);
164 chan
= lttng_chan
->chan
;
165 handle
= lttng_chan
->handle
;
167 * note: lttng_chan is private data contained within handle. It
168 * will be freed along with the handle.
170 channel_destroy(chan
, handle
, 0);
174 void register_event(struct lttng_event
*event
)
177 const struct lttng_event_desc
*desc
;
179 assert(event
->registered
== 0);
181 ret
= __tracepoint_probe_register(desc
->name
,
182 desc
->probe_callback
,
183 event
, desc
->signature
);
186 event
->registered
= 1;
190 void unregister_event(struct lttng_event
*event
)
193 const struct lttng_event_desc
*desc
;
195 assert(event
->registered
== 1);
197 ret
= __tracepoint_probe_unregister(desc
->name
,
198 desc
->probe_callback
,
202 event
->registered
= 0;
206 * Only used internally at session destruction.
209 void _lttng_event_unregister(struct lttng_event
*event
)
211 if (event
->registered
)
212 unregister_event(event
);
215 void lttng_session_destroy(struct lttng_session
*session
)
217 struct lttng_channel
*chan
, *tmpchan
;
218 struct lttng_event
*event
, *tmpevent
;
219 struct lttng_enum
*_enum
, *tmp_enum
;
220 struct lttng_enabler
*enabler
, *tmpenabler
;
222 CMM_ACCESS_ONCE(session
->active
) = 0;
223 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
224 _lttng_event_unregister(event
);
226 synchronize_trace(); /* Wait for in-flight events to complete */
227 cds_list_for_each_entry_safe(enabler
, tmpenabler
,
228 &session
->enablers_head
, node
)
229 lttng_enabler_destroy(enabler
);
230 cds_list_for_each_entry_safe(event
, tmpevent
,
231 &session
->events_head
, node
)
232 _lttng_event_destroy(event
);
233 cds_list_for_each_entry_safe(_enum
, tmp_enum
,
234 &session
->enums_head
, node
)
235 _lttng_enum_destroy(_enum
);
236 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->chan_head
, node
)
237 _lttng_channel_unmap(chan
);
238 cds_list_del(&session
->node
);
242 int lttng_session_enable(struct lttng_session
*session
)
245 struct lttng_channel
*chan
;
248 if (session
->active
) {
253 notify_socket
= lttng_get_notify_socket(session
->owner
);
254 if (notify_socket
< 0)
255 return notify_socket
;
257 /* Set transient enabler state to "enabled" */
261 * Snapshot the number of events per channel to know the type of header
264 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
265 const struct lttng_ctx
*ctx
;
266 const struct lttng_ctx_field
*fields
= NULL
;
267 size_t nr_fields
= 0;
270 /* don't change it if session stop/restart */
271 if (chan
->header_type
)
275 nr_fields
= ctx
->nr_fields
;
276 fields
= ctx
->fields
;
278 ret
= ustcomm_register_channel(notify_socket
,
286 DBG("Error (%d) registering channel to sessiond", ret
);
289 if (chan_id
!= chan
->id
) {
290 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
296 /* We need to sync enablers with session before activation. */
297 lttng_session_sync_enablers(session
);
299 /* Set atomically the state to "active" */
300 CMM_ACCESS_ONCE(session
->active
) = 1;
301 CMM_ACCESS_ONCE(session
->been_active
) = 1;
303 session
->statedump_pending
= 1;
304 lttng_ust_sockinfo_session_enabled(session
->owner
);
309 int lttng_session_disable(struct lttng_session
*session
)
313 if (!session
->active
) {
317 /* Set atomically the state to "inactive" */
318 CMM_ACCESS_ONCE(session
->active
) = 0;
320 /* Set transient enabler state to "disabled" */
322 lttng_session_sync_enablers(session
);
327 int lttng_channel_enable(struct lttng_channel
*channel
)
331 if (channel
->enabled
) {
335 /* Set transient enabler state to "enabled" */
337 lttng_session_sync_enablers(channel
->session
);
338 /* Set atomically the state to "enabled" */
339 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
344 int lttng_channel_disable(struct lttng_channel
*channel
)
348 if (!channel
->enabled
) {
352 /* Set atomically the state to "disabled" */
353 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
354 /* Set transient enabler state to "enabled" */
356 lttng_session_sync_enablers(channel
->session
);
362 int lttng_enum_create(const struct lttng_enum_desc
*desc
,
363 struct lttng_session
*session
)
365 const char *enum_name
= desc
->name
;
366 struct lttng_enum
*_enum
;
367 struct cds_hlist_head
*head
;
368 struct cds_hlist_node
*node
;
370 size_t name_len
= strlen(enum_name
);
374 hash
= jhash(enum_name
, name_len
, 0);
375 head
= &session
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
376 cds_hlist_for_each_entry(_enum
, node
, head
, hlist
) {
378 if (!strncmp(_enum
->desc
->name
, desc
->name
,
379 LTTNG_UST_SYM_NAME_LEN
- 1)) {
385 notify_socket
= lttng_get_notify_socket(session
->owner
);
386 if (notify_socket
< 0) {
391 _enum
= zmalloc(sizeof(*_enum
));
396 _enum
->session
= session
;
399 ret
= ustcomm_register_enum(notify_socket
,
406 DBG("Error (%d) registering enumeration to sessiond", ret
);
407 goto sessiond_register_error
;
409 cds_list_add(&_enum
->node
, &session
->enums_head
);
410 cds_hlist_add_head(&_enum
->hlist
, head
);
413 sessiond_register_error
:
422 int lttng_event_create_all_enums(const struct lttng_event_desc
*desc
,
423 struct lttng_session
*session
)
425 unsigned int nr_fields
, i
;
426 const struct lttng_event_field
*fields
;
428 /* For each field, ensure enum is part of the session. */
429 nr_fields
= desc
->nr_fields
;
430 fields
= desc
->fields
;
431 for (i
= 0; i
< nr_fields
; i
++) {
432 const struct lttng_type
*type
= &fields
[i
].type
;
434 switch (type
->atype
) {
437 const struct lttng_enum_desc
*enum_desc
;
440 enum_desc
= type
->u
.basic
.enumeration
.desc
;
441 ret
= lttng_enum_create(enum_desc
, session
);
442 if (ret
&& ret
!= -EEXIST
) {
443 DBG("Unable to create enum error: (%d)", ret
);
449 /* TODO: nested types when they become supported. */
457 * Supports event creation while tracing session is active.
460 int lttng_event_create(const struct lttng_event_desc
*desc
,
461 struct lttng_channel
*chan
)
463 const char *event_name
= desc
->name
;
464 struct lttng_event
*event
;
465 struct lttng_session
*session
= chan
->session
;
466 struct cds_hlist_head
*head
;
467 struct cds_hlist_node
*node
;
469 size_t name_len
= strlen(event_name
);
471 int notify_socket
, loglevel
;
474 hash
= jhash(event_name
, name_len
, 0);
475 head
= &chan
->session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
476 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
478 if (!strncmp(event
->desc
->name
, desc
->name
,
479 LTTNG_UST_SYM_NAME_LEN
- 1)
480 && chan
== event
->chan
) {
486 notify_socket
= lttng_get_notify_socket(session
->owner
);
487 if (notify_socket
< 0) {
492 ret
= lttng_event_create_all_enums(desc
, session
);
494 DBG("Error (%d) adding enum to session", ret
);
495 goto create_enum_error
;
499 * Check if loglevel match. Refuse to connect event if not.
501 event
= zmalloc(sizeof(struct lttng_event
));
508 /* Event will be enabled by enabler sync. */
510 event
->registered
= 0;
511 CDS_INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
512 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
516 loglevel
= *(*event
->desc
->loglevel
);
518 loglevel
= TRACE_DEFAULT
;
519 if (desc
->u
.ext
.model_emf_uri
)
520 uri
= *(desc
->u
.ext
.model_emf_uri
);
524 /* Fetch event ID from sessiond */
525 ret
= ustcomm_register_event(notify_socket
,
537 DBG("Error (%d) registering event to sessiond", ret
);
538 goto sessiond_register_error
;
541 /* Populate lttng_event structure before tracepoint registration. */
543 cds_list_add(&event
->node
, &chan
->session
->events_head
);
544 cds_hlist_add_head(&event
->hlist
, head
);
547 sessiond_register_error
:
557 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc
*desc
,
558 struct lttng_enabler
*enabler
)
561 unsigned int has_loglevel
= 0;
563 assert(enabler
->type
== LTTNG_ENABLER_WILDCARD
);
564 /* Compare excluding final '*' */
565 if (strncmp(desc
->name
, enabler
->event_param
.name
,
566 strlen(enabler
->event_param
.name
) - 1))
568 if (desc
->loglevel
) {
569 loglevel
= *(*desc
->loglevel
);
572 if (!lttng_loglevel_match(loglevel
,
574 enabler
->event_param
.loglevel_type
,
575 enabler
->event_param
.loglevel
))
581 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
582 struct lttng_enabler
*enabler
)
585 unsigned int has_loglevel
= 0;
587 assert(enabler
->type
== LTTNG_ENABLER_EVENT
);
588 if (strcmp(desc
->name
, enabler
->event_param
.name
))
590 if (desc
->loglevel
) {
591 loglevel
= *(*desc
->loglevel
);
594 if (!lttng_loglevel_match(loglevel
,
596 enabler
->event_param
.loglevel_type
,
597 enabler
->event_param
.loglevel
))
603 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
604 struct lttng_enabler
*enabler
)
606 struct lttng_ust_excluder_node
*excluder
;
608 /* If event matches with an excluder, return 'does not match' */
609 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
612 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
616 excluder_name
= (char *) (excluder
->excluder
.names
)
617 + count
* LTTNG_UST_SYM_NAME_LEN
;
618 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
619 if (len
> 0 && excluder_name
[len
- 1] == '*') {
620 found
= !strncmp(desc
->name
, excluder_name
,
623 found
= !strncmp(desc
->name
, excluder_name
,
624 LTTNG_UST_SYM_NAME_LEN
- 1);
631 switch (enabler
->type
) {
632 case LTTNG_ENABLER_WILDCARD
:
633 return lttng_desc_match_wildcard_enabler(desc
, enabler
);
634 case LTTNG_ENABLER_EVENT
:
635 return lttng_desc_match_event_enabler(desc
, enabler
);
642 int lttng_event_match_enabler(struct lttng_event
*event
,
643 struct lttng_enabler
*enabler
)
645 if (lttng_desc_match_enabler(event
->desc
, enabler
)
646 && event
->chan
== enabler
->chan
)
653 struct lttng_enabler_ref
* lttng_event_enabler_ref(struct lttng_event
*event
,
654 struct lttng_enabler
*enabler
)
656 struct lttng_enabler_ref
*enabler_ref
;
658 cds_list_for_each_entry(enabler_ref
,
659 &event
->enablers_ref_head
, node
) {
660 if (enabler_ref
->ref
== enabler
)
667 * Create struct lttng_event if it is missing and present in the list of
671 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
673 struct lttng_session
*session
= enabler
->chan
->session
;
674 struct lttng_probe_desc
*probe_desc
;
675 const struct lttng_event_desc
*desc
;
676 struct lttng_event
*event
;
678 struct cds_list_head
*probe_list
;
680 probe_list
= lttng_get_probe_list_head();
682 * For each probe event, if we find that a probe event matches
683 * our enabler, create an associated lttng_event if not
686 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
687 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
689 struct cds_hlist_head
*head
;
690 struct cds_hlist_node
*node
;
691 const char *event_name
;
695 desc
= probe_desc
->event_desc
[i
];
696 if (!lttng_desc_match_enabler(desc
, enabler
))
698 event_name
= desc
->name
;
699 name_len
= strlen(event_name
);
702 * Check if already created.
704 hash
= jhash(event_name
, name_len
, 0);
705 head
= &session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
706 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
707 if (event
->desc
== desc
708 && event
->chan
== enabler
->chan
)
715 * We need to create an event for this
718 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
721 DBG("Unable to create event %s, error %d\n",
722 probe_desc
->event_desc
[i
]->name
, ret
);
729 * Create events associated with an enabler (if not already present),
730 * and add backward reference from the event to the enabler.
733 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
735 struct lttng_session
*session
= enabler
->chan
->session
;
736 struct lttng_event
*event
;
738 /* First ensure that probe events are created for this enabler. */
739 lttng_create_event_if_missing(enabler
);
741 /* For each event matching enabler in session event list. */
742 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
743 struct lttng_enabler_ref
*enabler_ref
;
745 if (!lttng_event_match_enabler(event
, enabler
))
748 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
751 * If no backward ref, create it.
752 * Add backward ref from event to enabler.
754 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
757 enabler_ref
->ref
= enabler
;
758 cds_list_add(&enabler_ref
->node
,
759 &event
->enablers_ref_head
);
763 * Link filter bytecodes if not linked yet.
765 lttng_enabler_event_link_bytecode(event
, enabler
);
767 /* TODO: merge event context. */
773 * Called at library load: connect the probe on all enablers matching
775 * Called with session mutex held.
777 int lttng_fix_pending_events(void)
779 struct lttng_session
*session
;
781 cds_list_for_each_entry(session
, &sessions
, node
) {
782 lttng_session_lazy_sync_enablers(session
);
788 * For each session of the owner thread, execute pending statedump.
789 * Only dump state for the sessions owned by the caller thread, because
790 * we don't keep ust_lock across the entire iteration.
792 void lttng_handle_pending_statedump(void *owner
)
794 struct lttng_session
*session
;
796 /* Execute state dump */
797 do_lttng_ust_statedump(owner
);
799 /* Clear pending state dump */
803 cds_list_for_each_entry(session
, &sessions
, node
) {
804 if (session
->owner
!= owner
)
806 if (!session
->statedump_pending
)
808 session
->statedump_pending
= 0;
816 * Only used internally at session destruction.
819 void _lttng_event_destroy(struct lttng_event
*event
)
821 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
823 cds_list_del(&event
->node
);
824 lttng_destroy_context(event
->ctx
);
825 lttng_free_event_filter_runtime(event
);
826 /* Free event enabler refs */
827 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
828 &event
->enablers_ref_head
, node
)
834 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
836 cds_list_del(&_enum
->node
);
840 void lttng_ust_events_exit(void)
842 struct lttng_session
*session
, *tmpsession
;
844 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
845 lttng_session_destroy(session
);
849 * Enabler management.
851 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
852 struct lttng_ust_event
*event_param
,
853 struct lttng_channel
*chan
)
855 struct lttng_enabler
*enabler
;
857 enabler
= zmalloc(sizeof(*enabler
));
860 enabler
->type
= type
;
861 CDS_INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
862 CDS_INIT_LIST_HEAD(&enabler
->excluder_head
);
863 memcpy(&enabler
->event_param
, event_param
,
864 sizeof(enabler
->event_param
));
865 enabler
->chan
= chan
;
867 enabler
->enabled
= 0;
868 cds_list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
869 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
873 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
875 enabler
->enabled
= 1;
876 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
880 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
882 enabler
->enabled
= 0;
883 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
887 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
888 struct lttng_ust_filter_bytecode_node
*bytecode
)
890 bytecode
->enabler
= enabler
;
891 cds_list_add_tail(&bytecode
->node
, &enabler
->filter_bytecode_head
);
892 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
896 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
897 struct lttng_ust_excluder_node
*excluder
)
899 excluder
->enabler
= enabler
;
900 cds_list_add_tail(&excluder
->node
, &enabler
->excluder_head
);
901 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
905 int lttng_attach_context(struct lttng_ust_context
*context_param
,
906 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
909 * We cannot attach a context after trace has been started for a
910 * session because the metadata does not allow expressing this
911 * information outside of the original channel scope.
913 if (session
->been_active
)
916 switch (context_param
->ctx
) {
917 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
918 return lttng_add_pthread_id_to_ctx(ctx
);
919 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
921 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
923 perf_ctx_param
= &context_param
->u
.perf_counter
;
924 return lttng_add_perf_counter_to_ctx(
925 perf_ctx_param
->type
,
926 perf_ctx_param
->config
,
927 perf_ctx_param
->name
,
930 case LTTNG_UST_CONTEXT_VTID
:
931 return lttng_add_vtid_to_ctx(ctx
);
932 case LTTNG_UST_CONTEXT_VPID
:
933 return lttng_add_vpid_to_ctx(ctx
);
934 case LTTNG_UST_CONTEXT_PROCNAME
:
935 return lttng_add_procname_to_ctx(ctx
);
936 case LTTNG_UST_CONTEXT_IP
:
937 return lttng_add_ip_to_ctx(ctx
);
938 case LTTNG_UST_CONTEXT_CPU_ID
:
939 return lttng_add_cpu_id_to_ctx(ctx
);
945 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
946 struct lttng_ust_context
*context_param
)
948 #if 0 // disabled for now.
949 struct lttng_session
*session
= enabler
->chan
->session
;
952 ret
= lttng_attach_context(context_param
, &enabler
->ctx
,
956 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
962 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
964 struct lttng_ust_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
965 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
967 /* Destroy filter bytecode */
968 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
969 &enabler
->filter_bytecode_head
, node
) {
973 /* Destroy excluders */
974 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
975 &enabler
->excluder_head
, node
) {
979 /* Destroy contexts */
980 lttng_destroy_context(enabler
->ctx
);
982 cds_list_del(&enabler
->node
);
987 * lttng_session_sync_enablers should be called just before starting a
991 void lttng_session_sync_enablers(struct lttng_session
*session
)
993 struct lttng_enabler
*enabler
;
994 struct lttng_event
*event
;
996 cds_list_for_each_entry(enabler
, &session
->enablers_head
, node
)
997 lttng_enabler_ref_events(enabler
);
999 * For each event, if at least one of its enablers is enabled,
1000 * and its channel and session transient states are enabled, we
1001 * enable the event, else we disable it.
1003 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1004 struct lttng_enabler_ref
*enabler_ref
;
1005 struct lttng_bytecode_runtime
*runtime
;
1006 int enabled
= 0, has_enablers_without_bytecode
= 0;
1009 cds_list_for_each_entry(enabler_ref
,
1010 &event
->enablers_ref_head
, node
) {
1011 if (enabler_ref
->ref
->enabled
) {
1017 * Enabled state is based on union of enablers, with
1018 * intesection of session and channel transient enable
1021 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1023 CMM_STORE_SHARED(event
->enabled
, enabled
);
1025 * Sync tracepoint registration with event enabled
1029 if (!event
->registered
)
1030 register_event(event
);
1032 if (event
->registered
)
1033 unregister_event(event
);
1036 /* Check if has enablers without bytecode enabled */
1037 cds_list_for_each_entry(enabler_ref
,
1038 &event
->enablers_ref_head
, node
) {
1039 if (enabler_ref
->ref
->enabled
1040 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1041 has_enablers_without_bytecode
= 1;
1045 event
->has_enablers_without_bytecode
=
1046 has_enablers_without_bytecode
;
1048 /* Enable filters */
1049 cds_list_for_each_entry(runtime
,
1050 &event
->bytecode_runtime_head
, node
) {
1051 lttng_filter_sync_state(runtime
);
1057 * Apply enablers to session events, adding events to session if need
1058 * be. It is required after each modification applied to an active
1059 * session, and right before session "start".
1060 * "lazy" sync means we only sync if required.
1063 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1065 /* We can skip if session is not active */
1066 if (!session
->active
)
1068 lttng_session_sync_enablers(session
);