Cleanup: extract function to borrow hashlist bucket
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 18 Dec 2019 22:10:32 +0000 (17:10 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 18 Nov 2020 17:59:17 +0000 (12:59 -0500)
This is going to reused by the trigger system.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie6d032374c3991d0a75ad4737e7f082fbc1a74b1

include/lttng/utils.h [new file with mode: 0644]
src/lttng-events.c

diff --git a/include/lttng/utils.h b/include/lttng/utils.h
new file mode 100644 (file)
index 0000000..c01b648
--- /dev/null
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) */
+#ifndef _LTTNG_UTILS_H
+#define _LTTNG_UTILS_H
+
+/*
+ * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
+ */
+
+#include <linux/jhash.h>
+#include <linux/string.h>
+#include <linux/types.h>
+
+static inline
+struct hlist_head *utils_borrow_hash_table_bucket(
+               struct hlist_head *hash_table,
+               unsigned int hash_table_size,
+               const char *event_name)
+{
+       size_t name_len;
+       uint32_t hash;
+
+       name_len = strlen(event_name);
+
+       hash = jhash(event_name, name_len, 0);
+       return &hash_table[hash & (hash_table_size - 1)];
+}
+#endif /* _LTTNG_UTILS_H */
index 34e5fe9d98e657aaba9de8cac0f250614b6eaff0..e9967984093591711040fd7887304529c6a5744d 100644 (file)
@@ -24,7 +24,6 @@
 #include <linux/file.h>
 #include <linux/anon_inodes.h>
 #include <wrapper/file.h>
-#include <linux/jhash.h>
 #include <linux/uaccess.h>
 #include <linux/vmalloc.h>
 #include <linux/dmi.h>
@@ -41,6 +40,7 @@
 #include <lttng/abi-old.h>
 #include <lttng/endian.h>
 #include <lttng/string-utils.h>
+#include <lttng/utils.h>
 #include <ringbuffer/backend.h>
 #include <ringbuffer/frontend.h>
 #include <wrapper/time.h>
@@ -596,8 +596,6 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
        struct lttng_event *event;
        const char *event_name;
        struct hlist_head *head;
-       size_t name_len;
-       uint32_t hash;
        int ret;
 
        if (chan->free_event_id == -1U) {
@@ -622,9 +620,9 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
                ret = -EINVAL;
                goto type_error;
        }
-       name_len = strlen(event_name);
-       hash = jhash(event_name, name_len, 0);
-       head = &session->events_ht.table[hash & (LTTNG_EVENT_HT_SIZE - 1)];
+
+       head = utils_borrow_hash_table_bucket(session->events_ht.table,
+               LTTNG_EVENT_HT_SIZE, event_name);
        lttng_hlist_for_each_entry(event, head, hlist) {
                WARN_ON_ONCE(!event->desc);
                if (!strncmp(event->desc->name, event_name,
@@ -1363,23 +1361,19 @@ void lttng_create_tracepoint_event_if_missing(struct lttng_event_enabler *event_
                for (i = 0; i < probe_desc->nr_events; i++) {
                        int found = 0;
                        struct hlist_head *head;
-                       const char *event_name;
-                       size_t name_len;
-                       uint32_t hash;
                        struct lttng_event *event;
 
                        desc = probe_desc->event_desc[i];
                        if (!lttng_desc_match_enabler(desc,
                                        lttng_event_enabler_as_enabler(event_enabler)))
                                continue;
-                       event_name = desc->name;
-                       name_len = strlen(event_name);
 
                        /*
                         * Check if already created.
                         */
-                       hash = jhash(event_name, name_len, 0);
-                       head = &session->events_ht.table[hash & (LTTNG_EVENT_HT_SIZE - 1)];
+                       head = utils_borrow_hash_table_bucket(
+                               session->events_ht.table, LTTNG_EVENT_HT_SIZE,
+                               desc->name);
                        lttng_hlist_for_each_entry(event, head, hlist) {
                                if (event->desc == desc
                                                && event->chan == event_enabler->chan)
This page took 0.028145 seconds and 4 git commands to generate.