Refactoring: combine hlist_node into common event structure
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 20:42:52 +0000 (16:42 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 20:42:52 +0000 (16:42 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I998d4ff59f51da8e1c6068f0a4dbb52a759e2c3f

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

index 30f56e150b7355f94d36697a7a2e869a4a4b324e..3c741e66171ff3291f0835204c798ba46c2c4c8e 100644 (file)
@@ -77,6 +77,9 @@ struct lttng_kernel_event_common_private {
        int has_enablers_without_filter_bytecode;
        /* list of struct lttng_kernel_bytecode_runtime, sorted by seqnum */
        struct list_head filter_bytecode_runtime_head;
+
+       struct hlist_node hlist_node;                   /* node in events hash table */
+
        enum lttng_kernel_abi_instrumentation instrumentation;
        /* Selected by instrumentation */
        union {
@@ -100,7 +103,6 @@ struct lttng_kernel_event_recorder_private {
 
        struct lttng_kernel_event_recorder *pub;        /* Public event interface */
        struct list_head node;                          /* Event recorder list */
-       struct hlist_node hlist;                        /* Hash table of event recorders */
        struct lttng_kernel_ctx *ctx;
        unsigned int id;
        unsigned int metadata_dumped:1;
@@ -114,9 +116,7 @@ struct lttng_kernel_event_notifier_private {
        size_t num_captures;                            /* Needed to allocate the msgpack array. */
        uint64_t error_counter_index;
        struct list_head node;                          /* Event notifier list */
-       struct hlist_node hlist;                        /* Hash table of event notifiers */
        struct list_head capture_bytecode_runtime_head;
-
 };
 
 struct lttng_kernel_syscall_table {
index 78ee916f0258283b2f92b29f932d4508af6c05b2..b6fbd3470d3bacaed00f070c450085d6d062f89d 100644 (file)
@@ -881,6 +881,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
        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;
        const char *event_name;
        struct hlist_head *head;
        int ret;
@@ -917,9 +918,11 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
 
        head = utils_borrow_hash_table_bucket(session->priv->events_ht.table,
                LTTNG_EVENT_HT_SIZE, event_name);
-       lttng_hlist_for_each_entry(event_recorder_priv, head, hlist) {
-               WARN_ON_ONCE(!event_recorder_priv->parent.desc);
-               if (!strncmp(event_recorder_priv->parent.desc->event_name, 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);
+
+               WARN_ON_ONCE(!event_priv->desc);
+               if (!strncmp(event_priv->desc->event_name, event_name,
                                        LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1)
                                && chan == event_recorder_priv->pub->chan) {
                        ret = -EEXIST;
@@ -1134,7 +1137,7 @@ struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct l
        if (ret) {
                goto statedump_error;
        }
-       hlist_add_head(&event_recorder->priv->hlist, head);
+       hlist_add_head(&event_recorder->priv->parent.hlist_node, head);
        list_add(&event_recorder->priv->node, &chan->parent.session->priv->events);
        return event_recorder;
 
@@ -1160,6 +1163,7 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_ev
        enum lttng_kernel_abi_instrumentation itype = event_param->instrumentation;
        struct lttng_kernel_event_notifier *event_notifier;
        struct lttng_kernel_event_notifier_private *event_notifier_priv;
+       struct lttng_kernel_event_common_private *event_priv;
        struct lttng_counter *error_counter;
        const char *event_name;
        struct hlist_head *head;
@@ -1192,12 +1196,14 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_ev
 
        head = utils_borrow_hash_table_bucket(event_notifier_group->events_ht.table,
                LTTNG_EVENT_HT_SIZE, event_name);
-       lttng_hlist_for_each_entry(event_notifier_priv, head, hlist) {
-               WARN_ON_ONCE(!event_notifier_priv->parent.desc);
-               if (!strncmp(event_notifier_priv->parent.desc->event_name, 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);
+
+               WARN_ON_ONCE(!event_priv->desc);
+               if (!strncmp(event_priv->desc->event_name, event_name,
                                        LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1)
                                && event_notifier_group == event_notifier_priv->group
-                               && token == event_notifier_priv->parent.user_token) {
+                               && token == event_priv->user_token) {
                        ret = -EEXIST;
                        goto exist;
                }
@@ -1342,7 +1348,7 @@ struct lttng_kernel_event_notifier *_lttng_event_notifier_create(struct lttng_ev
        }
 
        list_add(&event_notifier->priv->node, &event_notifier_group->event_notifiers_head);
-       hlist_add_head(&event_notifier->priv->hlist, head);
+       hlist_add_head(&event_notifier->priv->parent.hlist_node, head);
 
        /*
         * Clear the error counter bucket. The sessiond keeps track of which
@@ -2071,8 +2077,9 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enable
                for (i = 0; i < probe_desc->nr_events; i++) {
                        int found = 0;
                        struct hlist_head *head;
-                       struct lttng_kernel_event_recorder_private *event_recorder_private;
+                       struct lttng_kernel_event_recorder_private *event_recorder_priv;
                        struct lttng_kernel_event_recorder *event_recorder;
+                       struct lttng_kernel_event_common_private *event_priv;
 
                        desc = probe_desc->event_desc[i];
                        if (!lttng_desc_match_enabler(desc,
@@ -2085,9 +2092,10 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_recorder_enable
                        head = utils_borrow_hash_table_bucket(
                                session->priv->events_ht.table, LTTNG_EVENT_HT_SIZE,
                                desc->event_name);
-                       lttng_hlist_for_each_entry(event_recorder_private, head, hlist) {
-                               if (event_recorder_private->parent.desc == desc
-                                               && event_recorder_private->pub->chan == event_enabler->chan)
+                       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
+                                               && event_recorder_priv->pub->chan == event_enabler->chan)
                                        found = 1;
                        }
                        if (found)
@@ -2125,8 +2133,8 @@ void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifi
                for (i = 0; i < probe_desc->nr_events; i++) {
                        int found = 0;
                        struct hlist_head *head;
-                       struct lttng_kernel_event_notifier_private *event_notifier_priv;
                        struct lttng_kernel_event_notifier *event_notifier;
+                       struct lttng_kernel_event_common_private *event_priv;
 
                        desc = probe_desc->event_desc[i];
                        if (!lttng_desc_match_enabler(desc,
@@ -2139,9 +2147,9 @@ void lttng_create_tracepoint_event_notifier_if_missing(struct lttng_event_notifi
                        head = utils_borrow_hash_table_bucket(
                                event_notifier_group->events_ht.table,
                                LTTNG_EVENT_HT_SIZE, desc->event_name);
-                       lttng_hlist_for_each_entry(event_notifier_priv, head, hlist) {
-                               if (event_notifier_priv->parent.desc == desc
-                                               && event_notifier_priv->parent.user_token == event_notifier_enabler->parent.user_token)
+                       lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
+                               if (event_priv->desc == desc
+                                               && event_priv->user_token == event_notifier_enabler->parent.user_token)
                                        found = 1;
                        }
                        if (found)
index 360f12b4b28a9d203e384230f5e8dd466158a650..7fa6d7e517299924ac98d792c1ea7a760e8b9c9f 100644 (file)
@@ -546,8 +546,8 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl
                const struct lttng_kernel_event_desc *desc = table[i].desc;
                struct lttng_event_recorder_enabler *event_enabler;
                struct lttng_kernel_abi_event ev;
-               struct lttng_kernel_event_recorder_private *event_recorder_priv;
                struct lttng_kernel_event_recorder *event_recorder;
+               struct lttng_kernel_event_common_private *event_priv;
                struct hlist_head *head;
                bool found = false;
 
@@ -564,9 +564,9 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl
                head = utils_borrow_hash_table_bucket(
                        session->priv->events_ht.table, LTTNG_EVENT_HT_SIZE,
                        desc->event_name);
-               lttng_hlist_for_each_entry(event_recorder_priv, head, hlist) {
-                       if (event_recorder_priv->parent.desc == desc
-                               && get_syscall_table_from_event(event_recorder_priv->parent.pub) == syscall_table)
+               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)
                                found = true;
                }
                if (found)
@@ -832,7 +832,7 @@ int create_unknown_event_notifier(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
                enum sc_type type)
 {
-       struct lttng_kernel_event_notifier_private *event_notifier_priv;
+       struct lttng_kernel_event_common_private *event_priv;
        struct lttng_kernel_event_notifier *event_notifier;
        const struct lttng_kernel_event_desc *desc;
        struct lttng_event_notifier_group *group = event_notifier_enabler->group;
@@ -883,9 +883,9 @@ int create_unknown_event_notifier(
         */
        head = utils_borrow_hash_table_bucket(group->events_ht.table,
                LTTNG_EVENT_HT_SIZE, desc->event_name);
-       lttng_hlist_for_each_entry(event_notifier_priv, head, hlist) {
-               if (event_notifier_priv->parent.desc == desc &&
-                               event_notifier_priv->parent.user_token == base_enabler->user_token)
+       lttng_hlist_for_each_entry(event_priv, head, hlist_node) {
+               if (event_priv->desc == desc &&
+                               event_priv->user_token == base_enabler->user_token)
                        found = true;
        }
        if (found)
@@ -936,7 +936,7 @@ static int create_matching_event_notifiers(
        /* iterate over all syscall and create event_notifier that match */
        for (i = 0; i < table_len; i++) {
                struct lttng_event_notifier_enabler *event_notifier_enabler;
-               struct lttng_kernel_event_notifier_private *event_notifier_priv;
+               struct lttng_kernel_event_common_private *event_priv;
                struct lttng_kernel_event_notifier *event_notifier;
                struct lttng_kernel_abi_event_notifier event_notifier_param;
                struct hlist_head *head;
@@ -957,9 +957,9 @@ static int create_matching_event_notifiers(
                 */
                head = utils_borrow_hash_table_bucket(group->events_ht.table,
                        LTTNG_EVENT_HT_SIZE, desc->event_name);
-               lttng_hlist_for_each_entry(event_notifier_priv, head, hlist) {
-                       if (event_notifier_priv->parent.desc == desc
-                               && event_notifier_priv->parent.user_token == syscall_event_notifier_enabler->parent.user_token)
+               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)
                                found = 1;
                }
                if (found)
This page took 0.033354 seconds and 4 git commands to generate.