Skip to content

Commit 391dda1

Browse files
Sasha Levinrostedt
authored andcommitted
tracing: Use hashtable.h for event_hash
Convert the event_hash array in trace_output.c to use the generic hashtable implementation from hashtable.h instead of the manually implemented hash table. This simplifies the code and makes it more maintainable by using the standard hashtable API defined in hashtable.h. Rename EVENT_HASHSIZE to EVENT_HASH_BITS to properly reflect its new meaning as the number of bits for the hashtable size. Link: https://lore.kernel.org/20250323132800.3010783-1-sashal@kernel.org Link: https://lore.kernel.org/20250319190545.3058319-1-sashal@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 7f81f27 commit 391dda1

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

kernel/trace/trace_output.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
#include <linux/idr.h>
1515
#include <linux/btf.h>
1616
#include <linux/bpf.h>
17+
#include <linux/hashtable.h>
1718

1819
#include "trace_output.h"
1920
#include "trace_btf.h"
2021

21-
/* must be a power of 2 */
22-
#define EVENT_HASHSIZE 128
22+
/* 2^7 = 128 */
23+
#define EVENT_HASH_BITS 7
2324

2425
DECLARE_RWSEM(trace_event_sem);
2526

26-
static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
27+
static DEFINE_HASHTABLE(event_hash, EVENT_HASH_BITS);
2728

2829
enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
2930
{
@@ -779,11 +780,8 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
779780
struct trace_event *ftrace_find_event(int type)
780781
{
781782
struct trace_event *event;
782-
unsigned key;
783783

784-
key = type & (EVENT_HASHSIZE - 1);
785-
786-
hlist_for_each_entry(event, &event_hash[key], node) {
784+
hash_for_each_possible(event_hash, event, node, type) {
787785
if (event->type == type)
788786
return event;
789787
}
@@ -838,7 +836,6 @@ void trace_event_read_unlock(void)
838836
*/
839837
int register_trace_event(struct trace_event *event)
840838
{
841-
unsigned key;
842839
int ret = 0;
843840

844841
down_write(&trace_event_sem);
@@ -871,9 +868,7 @@ int register_trace_event(struct trace_event *event)
871868
if (event->funcs->binary == NULL)
872869
event->funcs->binary = trace_nop_print;
873870

874-
key = event->type & (EVENT_HASHSIZE - 1);
875-
876-
hlist_add_head(&event->node, &event_hash[key]);
871+
hash_add(event_hash, &event->node, event->type);
877872

878873
ret = event->type;
879874
out:
@@ -888,7 +883,7 @@ EXPORT_SYMBOL_GPL(register_trace_event);
888883
*/
889884
int __unregister_trace_event(struct trace_event *event)
890885
{
891-
hlist_del(&event->node);
886+
hash_del(&event->node);
892887
free_trace_event_type(event->type);
893888
return 0;
894889
}

0 commit comments

Comments
 (0)