From: Francis Deslauriers Date: Wed, 18 Dec 2019 22:10:32 +0000 (-0500) Subject: Cleanup: extract function to borrow hashlist bucket X-Git-Tag: v2.13.0-rc1~152 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4a11ef1c368c8b794a2d89d73e15e327becf9013;p=lttng-modules.git Cleanup: extract function to borrow hashlist bucket This is going to reused by the trigger system. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: Ie6d032374c3991d0a75ad4737e7f082fbc1a74b1 --- diff --git a/include/lttng/utils.h b/include/lttng/utils.h new file mode 100644 index 00000000..c01b6488 --- /dev/null +++ b/include/lttng/utils.h @@ -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 + */ + +#include +#include +#include + +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 */ diff --git a/src/lttng-events.c b/src/lttng-events.c index 34e5fe9d..e9967984 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -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)