Refactoring: introduce lttng_get_event_ht_from_enabler
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 20:58:34 +0000 (16:58 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 20:58:34 +0000 (16:58 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I82759291c892c0d0c8b7a7c6be4a32ec8fac0dcd

include/lttng/events-internal.h
src/lttng-events.c
src/lttng-syscalls.c

index 3c741e66171ff3291f0835204c798ba46c2c4c8e..8bfe094a21df14f622093ca2327f7413e394ea50 100644 (file)
@@ -594,6 +594,27 @@ struct lttng_event_enabler_common *lttng_event_notifier_enabler_as_enabler(
        return &event_notifier_enabler->parent;
 }
 
+static inline
+struct lttng_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common *event_enabler)
+{
+       switch (event_enabler->enabler_type) {
+       case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
+       {
+               struct lttng_event_recorder_enabler *event_recorder_enabler =
+                       container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
+               return &event_recorder_enabler->chan->parent.session->priv->events_ht;
+       }
+       case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
+       {
+               struct lttng_event_notifier_enabler *event_notifier_enabler =
+                       container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
+               return &event_notifier_enabler->group->events_ht;
+       }
+       default:
+               return NULL;
+       }
+}
+
 int lttng_context_init(void);
 void lttng_context_exit(void);
 int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
index b6fbd3470d3bacaed00f070c450085d6d062f89d..039b43e6ffb21f82c9dc864a5c89652aba200a93 100644 (file)
@@ -875,10 +875,10 @@ void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream)
 struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_event_recorder_enabler *event_enabler,
                                const struct lttng_kernel_event_desc *event_desc)
 {
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_enabler->parent);
        struct lttng_kernel_channel_buffer *chan = event_enabler->chan;
        struct lttng_kernel_abi_event *event_param = &event_enabler->parent.event_param;
        enum lttng_kernel_abi_instrumentation itype = event_param->instrumentation;
-       struct lttng_kernel_session *session = chan->parent.session;
        struct lttng_kernel_event_recorder *event_recorder;
        struct lttng_kernel_event_recorder_private *event_recorder_priv;
        struct lttng_kernel_event_common_private *event_priv;
@@ -916,8 +916,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
                goto type_error;
        }
 
-       head = utils_borrow_hash_table_bucket(session->priv->events_ht.table,
-               LTTNG_EVENT_HT_SIZE, event_name);
+       head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, event_name);
        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                event_recorder_priv = container_of(event_priv, struct lttng_kernel_event_recorder_private, parent);
 
@@ -1157,6 +1156,7 @@ full:
 struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_event_notifier_enabler *event_enabler,
                const struct lttng_kernel_event_desc *event_desc)
 {
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_enabler->parent);
        struct lttng_event_notifier_group *event_notifier_group = event_enabler->group;
        struct lttng_kernel_abi_event *event_param = &event_enabler->parent.event_param;
        uint64_t token = event_enabler->parent.user_token;
@@ -1194,8 +1194,7 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_ev
                goto type_error;
        }
 
-       head = utils_borrow_hash_table_bucket(event_notifier_group->events_ht.table,
-               LTTNG_EVENT_HT_SIZE, event_name);
+       head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, event_name);
        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                event_notifier_priv = container_of(event_priv, struct lttng_kernel_event_notifier_private, parent);
 
@@ -2061,7 +2060,7 @@ struct lttng_enabler_ref *lttng_enabler_ref(
 static
 void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enabler *event_enabler)
 {
-       struct lttng_kernel_session *session = event_enabler->chan->parent.session;
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_enabler->parent);
        struct lttng_kernel_probe_desc *probe_desc;
        const struct lttng_kernel_event_desc *desc;
        int i;
@@ -2089,9 +2088,7 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enable
                        /*
                         * Check if already created.
                         */
-                       head = utils_borrow_hash_table_bucket(
-                               session->priv->events_ht.table, LTTNG_EVENT_HT_SIZE,
-                               desc->event_name);
+                       head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name);
                        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                                event_recorder_priv = container_of(event_priv, struct lttng_kernel_event_recorder_private, parent);
                                if (event_priv->desc == desc
@@ -2117,7 +2114,7 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enable
 static
 void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifier_enabler *event_notifier_enabler)
 {
-       struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group;
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_notifier_enabler->parent);
        struct lttng_kernel_probe_desc *probe_desc;
        const struct lttng_kernel_event_desc *desc;
        int i;
@@ -2144,8 +2141,7 @@ void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifi
                        /*
                         * Check if already created.
                         */
-                       head = utils_borrow_hash_table_bucket(
-                               event_notifier_group->events_ht.table,
+                       head = utils_borrow_hash_table_bucket(events_ht->table,
                                LTTNG_EVENT_HT_SIZE, desc->event_name);
                        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                                if (event_priv->desc == desc
index 7fa6d7e517299924ac98d792c1ea7a760e8b9c9f..82829dcbda09cf97595760d42ac9b653623bc43e 100644 (file)
@@ -536,9 +536,9 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl
        struct hlist_head *chan_table, struct lttng_event_recorder_enabler *syscall_event_enabler,
        enum sc_type type)
 {
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&syscall_event_enabler->parent);
        struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(&syscall_event_enabler->parent);
        struct lttng_kernel_channel_buffer *chan = syscall_event_enabler->chan;
-       struct lttng_kernel_session *session = chan->parent.session;
        unsigned int i;
 
        /* Allocate events for each syscall matching enabler, insert into table */
@@ -561,9 +561,7 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl
                /*
                 * Check if already created.
                 */
-               head = utils_borrow_hash_table_bucket(
-                       session->priv->events_ht.table, LTTNG_EVENT_HT_SIZE,
-                       desc->event_name);
+               head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name);
                lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                        if (event_priv->desc == desc
                                && get_syscall_table_from_event(event_priv->pub) == syscall_table)
@@ -832,6 +830,7 @@ int create_unknown_event_notifier(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
                enum sc_type type)
 {
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_notifier_enabler->parent);
        struct lttng_kernel_event_common_private *event_priv;
        struct lttng_kernel_event_notifier *event_notifier;
        const struct lttng_kernel_event_desc *desc;
@@ -881,8 +880,7 @@ int create_unknown_event_notifier(
        /*
         * Check if already created.
         */
-       head = utils_borrow_hash_table_bucket(group->events_ht.table,
-               LTTNG_EVENT_HT_SIZE, desc->event_name);
+       head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name);
        lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                if (event_priv->desc == desc &&
                                event_priv->user_token == base_enabler->user_token)
@@ -926,6 +924,7 @@ static int create_matching_event_notifiers(
                const struct trace_syscall_entry *table,
                size_t table_len, enum sc_type type)
 {
+       struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&syscall_event_notifier_enabler->parent);
        struct lttng_event_notifier_group *group = syscall_event_notifier_enabler->group;
        const struct lttng_kernel_event_desc *desc;
        uint64_t user_token = syscall_event_notifier_enabler->parent.user_token;
@@ -955,8 +954,7 @@ static int create_matching_event_notifiers(
                /*
                 * Check if already created.
                 */
-               head = utils_borrow_hash_table_bucket(group->events_ht.table,
-                       LTTNG_EVENT_HT_SIZE, desc->event_name);
+               head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name);
                lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
                        if (event_priv->desc == desc
                                && event_priv->user_token == syscall_event_notifier_enabler->parent.user_token)
This page took 0.031172 seconds and 4 git commands to generate.