From ba99fbe29216df4090f308bbe805bd93db470938 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 15 Mar 2021 14:57:44 -0400 Subject: [PATCH] Refactoring: combine event recorder and notifier callback functions Signed-off-by: Mathieu Desnoyers Change-Id: I6e2c8021220072da9a8455a31e48db9d740edfe7 --- include/lttng/ust-events.h | 7 +- include/lttng/ust-tracepoint-event.h | 165 +++++++---------- liblttng-ust/lttng-events.c | 260 +++++++++++---------------- liblttng-ust/ust-events-internal.h | 8 +- 4 files changed, 182 insertions(+), 258 deletions(-) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 7abca292..8a7abd64 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -286,7 +286,6 @@ struct lttng_event_desc { union { struct { const char **model_emf_uri; - void (*event_notifier_callback)(void); } ext; char padding[LTTNG_UST_EVENT_DESC_PADDING]; } u; @@ -360,6 +359,8 @@ struct lttng_ust_event_common { struct lttng_ust_event_common_private *priv; /* Private event interface */ enum lttng_ust_event_type type; + void *child; /* Pointer to child, for inheritance by aggregation. */ + int enabled; int has_enablers_without_bytecode; /* list of struct lttng_bytecode_runtime, sorted by seqnum */ @@ -370,7 +371,7 @@ struct lttng_ust_event_recorder_private; struct lttng_ust_event_recorder { uint32_t struct_size; /* Size of this structure. */ - struct lttng_ust_event_common *parent; + struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */ struct lttng_ust_event_recorder_private *priv; /* Private event record interface */ unsigned int id; @@ -382,7 +383,7 @@ struct lttng_ust_event_notifier_private; struct lttng_ust_event_notifier { uint32_t struct_size; /* Size of this structure. */ - struct lttng_ust_event_common *parent; + struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */ struct lttng_ust_event_notifier_private *priv; /* Private event notifier interface */ void (*notification_send)(struct lttng_ust_event_notifier *event_notifier, diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index 6ad34390..5b3d9a1b 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -425,24 +425,6 @@ static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); #include TRACEPOINT_INCLUDE -/* - * Stage 2.1 of tracepoint event generation. - * - * Create probe event notifier callback prototypes. - */ - -/* Reset all macros within TRACEPOINT_EVENT */ -#include - -#undef TP_ARGS -#define TP_ARGS(...) __VA_ARGS__ - -#undef _TRACEPOINT_EVENT_CLASS -#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ -static void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); - -#include TRACEPOINT_INCLUDE - /* * Stage 3.0 of tracepoint event generation. * @@ -838,40 +820,47 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ static \ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ { \ - struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __tp_data; \ - struct lttng_channel *__chan = __event_recorder->chan; \ - struct lttng_ust_lib_ring_buffer_ctx __ctx; \ - struct lttng_stack_ctx __lttng_ctx; \ - size_t __event_len, __event_align; \ + struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \ size_t __dynamic_len_idx = 0; \ const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \ union { \ size_t __dynamic_len[__num_fields]; \ - char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ + char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ } __stackvar; \ int __ret; \ \ if (0) \ (void) __dynamic_len_idx; /* don't warn if unused */ \ - if (!_TP_SESSION_CHECK(session, __chan->session)) \ - return; \ - if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \ - return; \ - if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \ - return; \ - if (caa_unlikely(!CMM_ACCESS_ONCE(__event_recorder->parent->enabled)))\ + switch (__event->type) { \ + case LTTNG_UST_EVENT_TYPE_RECORDER: \ + { \ + struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ + struct lttng_channel *__chan = __event_recorder->chan; \ + \ + if (!_TP_SESSION_CHECK(session, __chan->session)) \ + return; \ + if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \ + return; \ + if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \ + return; \ + break; \ + } \ + case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ + break; \ + } \ + if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ return; \ if (caa_unlikely(!TP_RCU_LINK_TEST())) \ return; \ - if (caa_unlikely(!cds_list_empty(&__event_recorder->parent->filter_bytecode_runtime_head))) { \ - struct lttng_bytecode_runtime *__filter_bc_runtime; \ - int __filter_record = __event_recorder->parent->has_enablers_without_bytecode; \ + if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \ + struct lttng_bytecode_runtime *__filter_bc_runtime; \ + int __filter_record = __event->has_enablers_without_bytecode; \ \ - __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \ + __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ _TP_ARGS_DATA_VAR(_args)); \ - tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_recorder->parent->filter_bytecode_runtime_head, node) { \ + tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \ if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \ - __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ + __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ __filter_record = 1; \ break; \ } \ @@ -879,21 +868,45 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ if (caa_likely(!__filter_record)) \ return; \ } \ - __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ - _TP_ARGS_DATA_VAR(_args)); \ - __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ - memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \ - __lttng_ctx.event_recorder = __event_recorder; \ - __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \ - __lttng_ctx.event_ctx = tp_rcu_dereference(__event_recorder->ctx); \ - lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \ - __event_align, -1, __chan->handle); \ - __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \ - __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \ - if (__ret < 0) \ - return; \ - _fields \ - __chan->ops->event_commit(&__ctx); \ + switch (__event->type) { \ + case LTTNG_UST_EVENT_TYPE_RECORDER: \ + { \ + size_t __event_len, __event_align; \ + struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ + struct lttng_channel *__chan = __event_recorder->chan; \ + struct lttng_ust_lib_ring_buffer_ctx __ctx; \ + struct lttng_stack_ctx __lttng_ctx; \ + \ + __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ + _TP_ARGS_DATA_VAR(_args)); \ + __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ + memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \ + __lttng_ctx.event_recorder = __event_recorder; \ + __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \ + __lttng_ctx.event_ctx = tp_rcu_dereference(__event_recorder->ctx); \ + lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \ + __event_align, -1, __chan->handle); \ + __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \ + __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \ + if (__ret < 0) \ + return; \ + _fields \ + __chan->ops->event_commit(&__ctx); \ + break; \ + } \ + case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ + { \ + struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \ + \ + if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \ + __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ + _TP_ARGS_DATA_VAR(_args)); \ + \ + __event_notifier->notification_send(__event_notifier, \ + __stackvar.__interpreter_stack_data); \ + break; \ + } \ + } \ } #include TRACEPOINT_INCLUDE @@ -923,53 +936,6 @@ static const char __tp_event_signature___##_provider##___##_name[] = \ #undef _TP_EXTRACT_STRING2 -/* - * Stage 5.2 of tracepoint event generation. - * - * Create the event notifier probe function. - */ -#undef _TRACEPOINT_EVENT_CLASS -#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ -static lttng_ust_notrace \ -void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ -static \ -void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ -{ \ - struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __tp_data; \ - const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1;\ - union { \ - size_t __dynamic_len[__num_fields]; \ - char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ - } __stackvar; \ - \ - if (caa_unlikely(!CMM_ACCESS_ONCE(__event_notifier->parent->enabled))) \ - return; \ - if (caa_unlikely(!TP_RCU_LINK_TEST())) \ - return; \ - if (caa_unlikely(!cds_list_empty(&__event_notifier->parent->filter_bytecode_runtime_head))) { \ - struct lttng_bytecode_runtime *__filter_bc_runtime; \ - int __filter_record = __event_notifier->parent->has_enablers_without_bytecode; \ - \ - __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ - _TP_ARGS_DATA_VAR(_args)); \ - tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->parent->filter_bytecode_runtime_head, node) { \ - if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \ - __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \ - __filter_record = 1; \ - } \ - if (caa_likely(!__filter_record)) \ - return; \ - } \ - if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \ - __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ - _TP_ARGS_DATA_VAR(_args)); \ - \ - __event_notifier->notification_send(__event_notifier, \ - __stackvar.__interpreter_stack_data); \ -} - -#include TRACEPOINT_INCLUDE - /* * Stage 6 of tracepoint event generation. * @@ -1065,7 +1031,6 @@ static const struct lttng_event_desc __event_desc___##_provider##_##_name = { .u = { \ .ext = { \ .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ - .event_notifier_callback = (void (*)(void)) &__event_notifier_probe__##_provider##___##_template,\ }, \ }, \ }; diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index c74db455..5a3aae8d 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -70,9 +70,7 @@ struct cds_list_head *lttng_get_sessions(void) return &sessions; } -static void _lttng_event_recorder_destroy(struct lttng_ust_event_recorder *event_recorder); -static void _lttng_event_notifier_destroy( - struct lttng_ust_event_notifier *event_notifier); +static void _lttng_event_destroy(struct lttng_ust_event_common *event); static void _lttng_enum_destroy(struct lttng_enum *_enum); static @@ -249,85 +247,42 @@ void _lttng_channel_unmap(struct lttng_channel *lttng_chan) } static -void register_event_recorder(struct lttng_ust_event_recorder *event_recorder) +void register_event(struct lttng_ust_event_common *event) { int ret; const struct lttng_event_desc *desc; - assert(event_recorder->parent->priv->registered == 0); - desc = event_recorder->parent->priv->desc; + assert(event->priv->registered == 0); + desc = event->priv->desc; ret = __tracepoint_probe_register_queue_release(desc->name, desc->probe_callback, - event_recorder, desc->signature); + event, desc->signature); WARN_ON_ONCE(ret); if (!ret) - event_recorder->parent->priv->registered = 1; + event->priv->registered = 1; } static -void register_event_notifier(struct lttng_ust_event_notifier *event_notifier) +void unregister_event(struct lttng_ust_event_common *event) { int ret; const struct lttng_event_desc *desc; - assert(event_notifier->parent->priv->registered == 0); - desc = event_notifier->parent->priv->desc; - ret = __tracepoint_probe_register_queue_release(desc->name, - desc->u.ext.event_notifier_callback, event_notifier, desc->signature); - WARN_ON_ONCE(ret); - if (!ret) - event_notifier->parent->priv->registered = 1; -} - -static -void unregister_event_recorder(struct lttng_ust_event_recorder *event_recorder) -{ - int ret; - const struct lttng_event_desc *desc; - - assert(event_recorder->parent->priv->registered == 1); - desc = event_recorder->parent->priv->desc; + assert(event->priv->registered == 1); + desc = event->priv->desc; ret = __tracepoint_probe_unregister_queue_release(desc->name, desc->probe_callback, - event_recorder); + event); WARN_ON_ONCE(ret); if (!ret) - event_recorder->parent->priv->registered = 0; + event->priv->registered = 0; } static -void unregister_event_notifier(struct lttng_ust_event_notifier *event_notifier) +void _lttng_event_unregister(struct lttng_ust_event_common *event) { - int ret; - const struct lttng_event_desc *desc; - - assert(event_notifier->parent->priv->registered == 1); - desc = event_notifier->parent->priv->desc; - ret = __tracepoint_probe_unregister_queue_release(desc->name, - desc->u.ext.event_notifier_callback, event_notifier); - WARN_ON_ONCE(ret); - if (!ret) - event_notifier->parent->priv->registered = 0; -} - -/* - * Only used internally at session destruction. - */ -static -void _lttng_event_recorder_unregister(struct lttng_ust_event_recorder *event_recorder) -{ - if (event_recorder->parent->priv->registered) - unregister_event_recorder(event_recorder); -} - -/* - * Only used internally at session destruction. - */ -static -void _lttng_event_notifier_unregister(struct lttng_ust_event_notifier *event_notifier) -{ - if (event_notifier->parent->priv->registered) - unregister_event_notifier(event_notifier); + if (event->priv->registered) + unregister_event(event); } void lttng_session_destroy(struct lttng_session *session) @@ -339,7 +294,7 @@ void lttng_session_destroy(struct lttng_session *session) CMM_ACCESS_ONCE(session->active) = 0; cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) { - _lttng_event_recorder_unregister(event_recorder_priv->pub); + _lttng_event_unregister(event_recorder_priv->parent.pub); } lttng_ust_urcu_synchronize_rcu(); /* Wait for in-flight events to complete */ __tracepoint_probe_prune_release_queue(); @@ -348,7 +303,7 @@ void lttng_session_destroy(struct lttng_session *session) lttng_event_enabler_destroy(event_enabler); cds_list_for_each_entry_safe(event_recorder_priv, tmpevent_recorder_priv, &session->priv->events_head, node) - _lttng_event_recorder_destroy(event_recorder_priv->pub); + _lttng_event_destroy(event_recorder_priv->parent.pub); cds_list_for_each_entry_safe(_enum, tmp_enum, &session->priv->enums_head, node) _lttng_enum_destroy(_enum); @@ -365,15 +320,15 @@ void lttng_event_notifier_group_destroy( { int close_ret; struct lttng_event_notifier_enabler *notifier_enabler, *tmpnotifier_enabler; - struct lttng_ust_event_notifier_private *notifier_priv, *tmpnotifier_priv; + struct lttng_ust_event_notifier_private *event_notifier_priv, *tmpevent_notifier_priv; if (!event_notifier_group) { return; } - cds_list_for_each_entry(notifier_priv, + cds_list_for_each_entry(event_notifier_priv, &event_notifier_group->event_notifiers_head, node) - _lttng_event_notifier_unregister(notifier_priv->pub); + _lttng_event_unregister(event_notifier_priv->parent.pub); lttng_ust_urcu_synchronize_rcu(); @@ -381,9 +336,9 @@ void lttng_event_notifier_group_destroy( &event_notifier_group->enablers_head, node) lttng_event_notifier_enabler_destroy(notifier_enabler); - cds_list_for_each_entry_safe(notifier_priv, tmpnotifier_priv, + cds_list_for_each_entry_safe(event_notifier_priv, tmpevent_notifier_priv, &event_notifier_group->event_notifiers_head, node) - _lttng_event_notifier_destroy(notifier_priv->pub); + _lttng_event_destroy(event_notifier_priv->parent.pub); if (event_notifier_group->error_counter) lttng_ust_counter_destroy(event_notifier_group->error_counter); @@ -781,6 +736,7 @@ int lttng_event_recorder_create(const struct lttng_event_desc *desc, } event_recorder->parent->struct_size = sizeof(struct lttng_ust_event_common); event_recorder->parent->type = LTTNG_UST_EVENT_TYPE_RECORDER; + event_recorder->parent->child = event_recorder; event_recorder_priv = zmalloc(sizeof(struct lttng_ust_event_recorder_private)); if (!event_recorder_priv) { @@ -827,8 +783,8 @@ int lttng_event_recorder_create(const struct lttng_event_desc *desc, goto sessiond_register_error; } - cds_list_add(&event_recorder->priv->node, &chan->session->priv->events_head); - cds_hlist_add_head(&event_recorder->priv->hlist, head); + cds_list_add(&event_recorder_priv->node, &chan->session->priv->events_head); + cds_hlist_add_head(&event_recorder_priv->hlist, head); return 0; sessiond_register_error: @@ -875,6 +831,7 @@ int lttng_event_notifier_create(const struct lttng_event_desc *desc, } event_notifier->parent->struct_size = sizeof(struct lttng_ust_event_common); event_notifier->parent->type = LTTNG_UST_EVENT_TYPE_NOTIFIER; + event_notifier->parent->child = event_notifier; event_notifier_priv = zmalloc(sizeof(struct lttng_ust_event_notifier_private)); if (!event_notifier_priv) { @@ -914,27 +871,6 @@ error: return ret; } -static -void _lttng_event_notifier_destroy(struct lttng_ust_event_notifier *event_notifier) -{ - struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref; - - /* Remove from event_notifier list. */ - cds_list_del(&event_notifier->priv->node); - /* Remove from event_notifier hash table. */ - cds_hlist_del(&event_notifier->priv->hlist); - - lttng_free_event_filter_runtime(event_notifier->parent); - - /* Free event_notifier enabler refs */ - cds_list_for_each_entry_safe(enabler_ref, tmp_enabler_ref, - &event_notifier->priv->parent.enablers_ref_head, node) - free(enabler_ref); - free(event_notifier->priv); - free(event_notifier->parent); - free(event_notifier); -} - static int lttng_desc_match_star_glob_enabler(const struct lttng_event_desc *desc, struct lttng_enabler *enabler) @@ -1066,7 +1002,7 @@ struct lttng_enabler_ref *lttng_enabler_ref( * tracepoint probes. */ static -void lttng_create_event_if_missing(struct lttng_event_enabler *event_enabler) +void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_enabler) { struct lttng_session *session = event_enabler->chan->session; struct lttng_probe_desc *probe_desc; @@ -1123,9 +1059,7 @@ void lttng_create_event_if_missing(struct lttng_event_enabler *event_enabler) static void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, - void (*event_func)(struct lttng_session *session, - struct lttng_ust_event_recorder *event_recorder), - void (*event_notifier_func)(struct lttng_ust_event_notifier *event_notifier)) + void (*event_func)(struct lttng_ust_event_common *event)) { struct cds_hlist_node *node, *tmp_node; struct cds_list_head *sessionsp; @@ -1141,10 +1075,10 @@ void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, for (i = 0; i < provider_desc->nr_events; i++) { const struct lttng_event_desc *event_desc; struct lttng_event_notifier_group *event_notifier_group; + struct lttng_ust_event_recorder_private *event_recorder_priv; struct lttng_ust_event_notifier_private *event_notifier_priv; struct lttng_ust_session_private *session_priv; struct cds_hlist_head *head; - struct lttng_ust_event_recorder_private *event_recorder_priv; event_desc = provider_desc->event_desc[i]; @@ -1163,7 +1097,7 @@ void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, cds_hlist_for_each_entry_safe(event_recorder_priv, node, tmp_node, head, hlist) { if (event_desc == event_recorder_priv->parent.desc) { - event_func(session_priv->pub, event_recorder_priv->pub); + event_func(event_recorder_priv->parent.pub); break; } } @@ -1185,7 +1119,7 @@ void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, cds_hlist_for_each_entry_safe(event_notifier_priv, node, tmp_node, head, hlist) { if (event_desc == event_notifier_priv->parent.desc) { - event_notifier_func(event_notifier_priv->pub); + event_func(event_notifier_priv->parent.pub); break; } } @@ -1194,41 +1128,45 @@ void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, } static -void _unregister_event_recorder(struct lttng_session *session, - struct lttng_ust_event_recorder *event_recorder) +void _event_enum_destroy(struct lttng_ust_event_common *event) { - _lttng_event_recorder_unregister(event_recorder); -} -static -void _event_enum_destroy(struct lttng_session *session, - struct lttng_ust_event_recorder *event_recorder) -{ - unsigned int i; - - /* Destroy enums of the current event. */ - for (i = 0; i < event_recorder->parent->priv->desc->nr_fields; i++) { - const struct lttng_enum_desc *enum_desc; - const struct lttng_event_field *field; - struct lttng_enum *curr_enum; - - field = &(event_recorder->parent->priv->desc->fields[i]); - switch (field->type.atype) { - case atype_enum_nestable: - enum_desc = field->type.u.enum_nestable.desc; - break; - default: - continue; - } + switch (event->type) { + case LTTNG_UST_EVENT_TYPE_RECORDER: + { + struct lttng_ust_event_recorder *event_recorder = event->child; + struct lttng_session *session = event_recorder->chan->session; + unsigned int i; + + /* Destroy enums of the current event. */ + for (i = 0; i < event_recorder->parent->priv->desc->nr_fields; i++) { + const struct lttng_enum_desc *enum_desc; + const struct lttng_event_field *field; + struct lttng_enum *curr_enum; + + field = &(event_recorder->parent->priv->desc->fields[i]); + switch (field->type.atype) { + case atype_enum_nestable: + enum_desc = field->type.u.enum_nestable.desc; + break; + default: + continue; + } - curr_enum = lttng_ust_enum_get_from_desc(session, enum_desc); - if (curr_enum) { - _lttng_enum_destroy(curr_enum); + curr_enum = lttng_ust_enum_get_from_desc(session, enum_desc); + if (curr_enum) { + _lttng_enum_destroy(curr_enum); + } } + break; + } + case LTTNG_UST_EVENT_TYPE_NOTIFIER: + break; + default: + abort(); } - /* Destroy event. */ - _lttng_event_recorder_destroy(event_recorder); + _lttng_event_destroy(event); } /* @@ -1243,8 +1181,7 @@ void lttng_probe_provider_unregister_events( * Iterate over all events in the probe provider descriptions and sessions * to queue the unregistration of the events. */ - probe_provider_event_for_each(provider_desc, _unregister_event_recorder, - _lttng_event_notifier_unregister); + probe_provider_event_for_each(provider_desc, _lttng_event_unregister); /* Wait for grace period. */ lttng_ust_urcu_synchronize_rcu(); @@ -1255,8 +1192,7 @@ void lttng_probe_provider_unregister_events( * It is now safe to destroy the events and remove them from the event list * and hashtables. */ - probe_provider_event_for_each(provider_desc, _event_enum_destroy, - _lttng_event_notifier_destroy); + probe_provider_event_for_each(provider_desc, _event_enum_destroy); } /* @@ -1264,7 +1200,7 @@ void lttng_probe_provider_unregister_events( * and add backward reference from the event to the enabler. */ static -int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler) +int lttng_event_enabler_ref_event_recorders(struct lttng_event_enabler *event_enabler) { struct lttng_session *session = event_enabler->chan->session; struct lttng_ust_event_recorder_private *event_recorder_priv; @@ -1273,7 +1209,7 @@ int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler) goto end; /* First ensure that probe events are created for this enabler. */ - lttng_create_event_if_missing(event_enabler); + lttng_create_event_recorder_if_missing(event_enabler); /* For each event matching enabler in session event list. */ cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) { @@ -1365,28 +1301,50 @@ end: return; } -/* - * Only used internally at session destruction. - */ static -void _lttng_event_recorder_destroy(struct lttng_ust_event_recorder *event_recorder) +void _lttng_event_destroy(struct lttng_ust_event_common *event) { struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref; - /* Remove from event list. */ - cds_list_del(&event_recorder->priv->node); - /* Remove from event hash table. */ - cds_hlist_del(&event_recorder->priv->hlist); - - lttng_destroy_context(event_recorder->ctx); - lttng_free_event_filter_runtime(event_recorder->parent); + lttng_free_event_filter_runtime(event); /* Free event enabler refs */ cds_list_for_each_entry_safe(enabler_ref, tmp_enabler_ref, - &event_recorder->parent->priv->enablers_ref_head, node) + &event->priv->enablers_ref_head, node) free(enabler_ref); - free(event_recorder->priv); - free(event_recorder->parent); - free(event_recorder); + + switch (event->type) { + case LTTNG_UST_EVENT_TYPE_RECORDER: + { + struct lttng_ust_event_recorder *event_recorder = event->child; + + /* Remove from event list. */ + cds_list_del(&event_recorder->priv->node); + /* Remove from event hash table. */ + cds_hlist_del(&event_recorder->priv->hlist); + + lttng_destroy_context(event_recorder->ctx); + free(event_recorder->parent); + free(event_recorder->priv); + free(event_recorder); + break; + } + case LTTNG_UST_EVENT_TYPE_NOTIFIER: + { + struct lttng_ust_event_notifier *event_notifier = event->child; + + /* Remove from event list. */ + cds_list_del(&event_notifier->priv->node); + /* Remove from event hash table. */ + cds_hlist_del(&event_notifier->priv->hlist); + + free(event_notifier->priv); + free(event_notifier->parent); + free(event_notifier); + break; + } + default: + abort(); + } } static @@ -1688,7 +1646,7 @@ void lttng_session_sync_event_enablers(struct lttng_session *session) struct lttng_ust_event_recorder_private *event_recorder_priv; cds_list_for_each_entry(event_enabler, &session->priv->enablers_head, node) - lttng_event_enabler_ref_events(event_enabler); + lttng_event_enabler_ref_event_recorders(event_enabler); /* * For each event, if at least one of its enablers is enabled, * and its channel and session transient states are enabled, we @@ -1721,10 +1679,10 @@ void lttng_session_sync_event_enablers(struct lttng_session *session) */ if (enabled) { if (!event_recorder_priv->parent.registered) - register_event_recorder(event_recorder_priv->pub); + register_event(event_recorder_priv->parent.pub); } else { if (event_recorder_priv->parent.registered) - unregister_event_recorder(event_recorder_priv->pub); + unregister_event(event_recorder_priv->parent.pub); } /* Check if has enablers without bytecode enabled */ @@ -1933,10 +1891,10 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group */ if (enabled) { if (!event_notifier_priv->parent.registered) - register_event_notifier(event_notifier_priv->pub); + register_event(event_notifier_priv->parent.pub); } else { if (event_notifier_priv->parent.registered) - unregister_event_notifier(event_notifier_priv->pub); + unregister_event(event_notifier_priv->parent.pub); } /* Check if has enablers without bytecode enabled */ diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index ec2b8e4b..0cec2870 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -214,19 +214,19 @@ struct lttng_ust_event_recorder_private { struct lttng_ust_event_common_private parent; struct lttng_ust_event_recorder *pub; /* Public event interface */ - struct cds_list_head node; /* Event list in session */ - struct cds_hlist_node hlist; /* session ht of events */ + struct cds_list_head node; /* Event recorder list */ + struct cds_hlist_node hlist; /* Hash table of event recorders */ }; struct lttng_ust_event_notifier_private { struct lttng_ust_event_common_private parent; struct lttng_ust_event_notifier *pub; /* Public event notifier interface */ - struct cds_hlist_node hlist; /* hashtable of event_notifiers */ - struct cds_list_head node; /* event_notifier list in session */ struct lttng_event_notifier_group *group; /* weak ref */ size_t num_captures; /* Needed to allocate the msgpack array. */ uint64_t error_counter_index; + struct cds_list_head node; /* Event notifier list */ + struct cds_hlist_node hlist; /* Hash table of event notifiers */ }; struct lttng_ust_bytecode_runtime_private { -- 2.34.1