Blog
Community
Development
Documentation
CNDP
22.08.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cne_cuckoo_hash.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: BSD-3-Clause
2
* Copyright (c) 2016-2022 Intel Corporation
3
* Copyright (c) 2018 Arm Limited
4
*/
5
6
#ifndef _CNE_CUCKOO_HASH_H_
7
#define _CNE_CUCKOO_HASH_H_
14
#include "
cne_cmp_x86.h
"
// for cne_hash_k112_cmp_eq, cne_hash_k128_cmp_eq
15
#include "
cne_common.h
"
// for __cne_cache_aligned, CNE_IS_POWER_OF_2
16
#include "
cne_hash.h
"
// for cne_hash_cmp_eq_t, CNE_HASH_NAMESIZE, cne_h...
17
#include "
cne_ring.h
"
// for cne_ring_t
18
#include "
cne_rwlock.h
"
// for cne_rwlock_t
19
20
/* Macro to enable/disable run-time checking of function parameters */
21
#if defined(CNE_LIBCNE_HASH_DEBUG)
22
#define RETURN_IF_TRUE(cond, retval) \
23
do { \
24
if (cond) \
25
return retval; \
26
} while (0)
27
#else
28
#define RETURN_IF_TRUE(cond, retval)
29
#endif
30
31
#if defined(CNE_LIBCNE_HASH_DEBUG)
32
#define ERR_IF_TRUE(cond, fmt, args...) \
33
do { \
34
if (cond) \
35
CNE_RET(fmt, ##args); \
36
} while (0)
37
#else
38
#define ERR_IF_TRUE(cond, fmt, args...)
39
#endif
40
41
#include <
cne_hash_crc.h
>
42
#include <
cne_jhash.h
>
43
#include <stdint.h>
// for uint32_t, uint8_t, uint16_t, uintptr_t
44
#include <string.h>
// for memcmp, NULL
45
46
/*
47
* All different options to select a key compare function,
48
* based on the key size and custom function.
49
*/
50
// clang-format off
51
enum
cmp_jump_table_case {
52
KEY_CUSTOM = 0,
53
KEY_16_BYTES,
54
KEY_32_BYTES,
55
KEY_48_BYTES,
56
KEY_64_BYTES,
57
KEY_80_BYTES,
58
KEY_96_BYTES,
59
KEY_112_BYTES,
60
KEY_128_BYTES,
61
KEY_OTHER_BYTES,
62
NUM_KEY_CMP_CASES,
63
};
64
// clang-format on
65
66
/*
67
* Table storing all different key compare functions
68
* (multi-process supported)
69
*/
70
// clang-format off
71
const
cne_hash_cmp_eq_t
cmp_jump_table[NUM_KEY_CMP_CASES] = {
72
NULL,
73
cne_hash_k16_cmp_eq,
74
cne_hash_k32_cmp_eq,
75
cne_hash_k48_cmp_eq,
76
cne_hash_k64_cmp_eq,
77
cne_hash_k80_cmp_eq,
78
cne_hash_k96_cmp_eq,
79
cne_hash_k112_cmp_eq,
80
cne_hash_k128_cmp_eq,
81
memcmp
82
};
83
// clang-format on
84
86
#define CNE_HASH_BUCKET_ENTRIES 8
87
88
#if !CNE_IS_POWER_OF_2(CNE_HASH_BUCKET_ENTRIES)
89
#error CNE_HASH_BUCKET_ENTRIES must be a power of 2
90
#endif
91
92
#define NULL_SIGNATURE 0
93
94
#define EMPTY_SLOT 0
95
96
#define KEY_ALIGNMENT 16
97
98
#define LCORE_CACHE_SIZE 64
99
100
#define CNE_HASH_BFS_QUEUE_MAX_LEN 1000
101
102
#define CNE_XABORT_CUCKOO_PATH_INVALIDED 0x4
103
104
#define CNE_HASH_TSX_MAX_RETRY 10
105
106
struct
lcore_cache {
107
unsigned
len;
108
uint32_t objs[LCORE_CACHE_SIZE];
109
}
__cne_cache_aligned
;
110
111
/* Structure that stores key-value pair */
112
struct
cne_hash_key {
113
union
{
114
uintptr_t idata;
115
void
*pdata;
116
};
117
/* Variable key size */
118
char
key[0];
119
};
120
121
/* All different signature compare functions */
122
enum
cne_hash_sig_compare_function {
123
CNE_HASH_COMPARE_SCALAR = 0,
124
CNE_HASH_COMPARE_SSE,
125
CNE_HASH_COMPARE_NEON,
126
CNE_HASH_COMPARE_NUM
127
};
128
130
struct
cne_hash_bucket
{
131
uint16_t sig_current[
CNE_HASH_BUCKET_ENTRIES
];
132
133
uint32_t key_idx[
CNE_HASH_BUCKET_ENTRIES
];
134
135
uint8_t flag[
CNE_HASH_BUCKET_ENTRIES
];
136
137
void
*next;
138
}
__cne_cache_aligned
;
139
141
struct
cne_hash
{
142
char
name
[
CNE_HASH_NAMESIZE
];
143
uint32_t
entries
;
144
uint32_t
num_buckets
;
145
146
cne_ring_t *
free_slots
;
148
149
/* Fields used in lookup */
150
uint32_t key_len
__cne_cache_aligned
;
152
uint8_t
hw_trans_mem_support
;
154
uint8_t
readwrite_concur_support
;
156
uint8_t
ext_table_support
;
157
uint8_t
no_free_on_del
;
163
uint8_t
readwrite_concur_lf_support
;
165
uint8_t
writer_takes_lock
;
167
cne_hash_function
hash_func
;
168
uint32_t
hash_func_init_val
;
169
cne_hash_cmp_eq_t
cne_hash_custom_cmp_eq
;
171
enum
cmp_jump_table_case
cmp_jump_table_idx
;
173
enum
cne_hash_sig_compare_function
sig_cmp_fn
;
175
uint32_t
bucket_bitmask
;
177
uint32_t
key_entry_size
;
178
179
void
*
key_store
;
180
struct
cne_hash_bucket
*
buckets
;
184
cne_rwlock_t
*
readwrite_lock
;
185
struct
cne_hash_bucket
*
buckets_ext
;
186
cne_ring_t *
free_ext_bkts
;
187
/* Stores index of an empty ext bkt to be recycled on calling
188
* cne_hash_del_xxx APIs. When lock free read-write concurrency is
189
* enabled, an empty ext bkt cannot be put into free list immediately
190
* (as readers might be using it still). Hence freeing of the ext bkt
191
* is piggy-backed to freeing of the key index.
192
*/
193
uint32_t *ext_bkt_to_free;
194
uint32_t *
tbl_chng_cnt
;
196
}
__cne_cache_aligned
;
197
198
struct
queue_node {
199
struct
cne_hash_bucket
*bkt;
/* Current bucket on the bfs search */
200
uint32_t cur_bkt_idx;
201
202
struct
queue_node *prev;
/* Parent(bucket) in search path */
203
int
prev_slot;
/* Parent(slot) in search path */
204
};
205
206
#endif
cne_cmp_x86.h
cne_common.h
__cne_cache_aligned
#define __cne_cache_aligned
Definition
cne_common.h:379
CNE_HASH_BUCKET_ENTRIES
#define CNE_HASH_BUCKET_ENTRIES
Definition
cne_cuckoo_hash.h:86
cne_hash.h
cne_hash_function
uint32_t(*) cne_hash_function(const void *key, uint32_t key_len, uint32_t init_val)
Definition
cne_hash.h:61
CNE_HASH_NAMESIZE
#define CNE_HASH_NAMESIZE
Definition
cne_hash.h:24
cne_hash_cmp_eq_t
int(*) cne_hash_cmp_eq_t(const void *key1, const void *key2, size_t key_len)
Definition
cne_hash.h:64
cne_hash_crc.h
cne_jhash.h
cne_ring.h
cne_rwlock.h
cne_hash_bucket
Definition
cne_cuckoo_hash.h:130
cne_hash
Definition
cne_cuckoo_hash.h:141
cne_hash::hash_func_init_val
uint32_t hash_func_init_val
Definition
cne_cuckoo_hash.h:168
cne_hash::key_store
void * key_store
Definition
cne_cuckoo_hash.h:179
cne_hash::buckets
struct cne_hash_bucket * buckets
Definition
cne_cuckoo_hash.h:180
cne_hash::readwrite_concur_support
uint8_t readwrite_concur_support
Definition
cne_cuckoo_hash.h:154
cne_hash::no_free_on_del
uint8_t no_free_on_del
Definition
cne_cuckoo_hash.h:157
cne_hash::hash_func
cne_hash_function hash_func
Definition
cne_cuckoo_hash.h:167
cne_hash::name
char name[CNE_HASH_NAMESIZE]
Definition
cne_cuckoo_hash.h:142
cne_hash::entries
uint32_t entries
Definition
cne_cuckoo_hash.h:143
cne_hash::__cne_cache_aligned
uint32_t key_len __cne_cache_aligned
Definition
cne_cuckoo_hash.h:150
cne_hash::cne_hash_custom_cmp_eq
cne_hash_cmp_eq_t cne_hash_custom_cmp_eq
Definition
cne_cuckoo_hash.h:169
cne_hash::readwrite_concur_lf_support
uint8_t readwrite_concur_lf_support
Definition
cne_cuckoo_hash.h:163
cne_hash::writer_takes_lock
uint8_t writer_takes_lock
Definition
cne_cuckoo_hash.h:165
cne_hash::free_slots
cne_ring_t * free_slots
Definition
cne_cuckoo_hash.h:146
cne_hash::readwrite_lock
cne_rwlock_t * readwrite_lock
Definition
cne_cuckoo_hash.h:184
cne_hash::tbl_chng_cnt
uint32_t * tbl_chng_cnt
Definition
cne_cuckoo_hash.h:194
cne_hash::cmp_jump_table_idx
enum cmp_jump_table_case cmp_jump_table_idx
Definition
cne_cuckoo_hash.h:171
cne_hash::num_buckets
uint32_t num_buckets
Definition
cne_cuckoo_hash.h:144
cne_hash::key_entry_size
uint32_t key_entry_size
Definition
cne_cuckoo_hash.h:177
cne_hash::sig_cmp_fn
enum cne_hash_sig_compare_function sig_cmp_fn
Definition
cne_cuckoo_hash.h:173
cne_hash::bucket_bitmask
uint32_t bucket_bitmask
Definition
cne_cuckoo_hash.h:175
cne_hash::buckets_ext
struct cne_hash_bucket * buckets_ext
Definition
cne_cuckoo_hash.h:185
cne_hash::free_ext_bkts
cne_ring_t * free_ext_bkts
Definition
cne_cuckoo_hash.h:186
cne_hash::ext_table_support
uint8_t ext_table_support
Definition
cne_cuckoo_hash.h:156
cne_hash::hw_trans_mem_support
uint8_t hw_trans_mem_support
Definition
cne_cuckoo_hash.h:152
cne_rwlock_t
Definition
cne_rwlock.h:34
lib
core
hash
cne_cuckoo_hash.h
Generated by
1.18.0