DPDK  20.11.2
rte_cuckoo_hash.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 Intel Corporation
3  * Copyright(c) 2018 Arm Limited
4  */
5 
6 /* rte_cuckoo_hash.h
7  * This file hold Cuckoo Hash private data structures to allows include from
8  * platform specific files like rte_cuckoo_hash_x86.h
9  */
10 
11 #ifndef _RTE_CUCKOO_HASH_H_
12 #define _RTE_CUCKOO_HASH_H_
13 
14 #if defined(RTE_ARCH_X86)
15 #include "rte_cmp_x86.h"
16 #endif
17 
18 #if defined(RTE_ARCH_ARM64)
19 #include "rte_cmp_arm64.h"
20 #endif
21 
22 #if defined(RTE_ARCH_LOONGARCH_64)
23 #include "rte_cmp_lsx.h"
24 #endif
25 
26 /* Macro to enable/disable run-time checking of function parameters */
27 #if defined(RTE_LIBRTE_HASH_DEBUG)
28 #define RETURN_IF_TRUE(cond, retval) do { \
29  if (cond) \
30  return retval; \
31 } while (0)
32 #else
33 #define RETURN_IF_TRUE(cond, retval)
34 #endif
35 
36 #if defined(RTE_LIBRTE_HASH_DEBUG)
37 #define ERR_IF_TRUE(cond, fmt, args...) do { \
38  if (cond) { \
39  RTE_LOG(ERR, HASH, fmt, ##args); \
40  return; \
41  } \
42 } while (0)
43 #else
44 #define ERR_IF_TRUE(cond, fmt, args...)
45 #endif
46 
47 #include <rte_hash_crc.h>
48 #include <rte_jhash.h>
49 
50 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64) || defined (RTE_ARCH_LOONGARCH_64)
51 /*
52  * All different options to select a key compare function,
53  * based on the key size and custom function.
54  */
55 enum cmp_jump_table_case {
56  KEY_CUSTOM = 0,
57  KEY_16_BYTES,
58  KEY_32_BYTES,
59  KEY_48_BYTES,
60  KEY_64_BYTES,
61  KEY_80_BYTES,
62  KEY_96_BYTES,
63  KEY_112_BYTES,
64  KEY_128_BYTES,
65  KEY_OTHER_BYTES,
66  NUM_KEY_CMP_CASES,
67 };
68 
69 /*
70  * Table storing all different key compare functions
71  * (multi-process supported)
72  */
73 const rte_hash_cmp_eq_t cmp_jump_table[NUM_KEY_CMP_CASES] = {
74  NULL,
75  rte_hash_k16_cmp_eq,
76  rte_hash_k32_cmp_eq,
77  rte_hash_k48_cmp_eq,
78  rte_hash_k64_cmp_eq,
79  rte_hash_k80_cmp_eq,
80  rte_hash_k96_cmp_eq,
81  rte_hash_k112_cmp_eq,
82  rte_hash_k128_cmp_eq,
83  memcmp
84 };
85 #else
86 /*
87  * All different options to select a key compare function,
88  * based on the key size and custom function.
89  */
90 enum cmp_jump_table_case {
91  KEY_CUSTOM = 0,
92  KEY_OTHER_BYTES,
93  NUM_KEY_CMP_CASES,
94 };
95 
96 /*
97  * Table storing all different key compare functions
98  * (multi-process supported)
99  */
100 const rte_hash_cmp_eq_t cmp_jump_table[NUM_KEY_CMP_CASES] = {
101  NULL,
102  memcmp
103 };
104 
105 #endif
106 
107 
109 #define RTE_HASH_BUCKET_ENTRIES 8
110 
111 #if !RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES)
112 #error RTE_HASH_BUCKET_ENTRIES must be a power of 2
113 #endif
114 
115 #define NULL_SIGNATURE 0
116 
117 #define EMPTY_SLOT 0
118 
119 #define KEY_ALIGNMENT 16
120 
121 #define LCORE_CACHE_SIZE 64
122 
123 #define RTE_HASH_BFS_QUEUE_MAX_LEN 1000
124 
125 #define RTE_XABORT_CUCKOO_PATH_INVALIDED 0x4
126 
127 #define RTE_HASH_TSX_MAX_RETRY 10
128 
129 struct lcore_cache {
130  unsigned len;
131  uint32_t objs[LCORE_CACHE_SIZE];
133 
134 /* Structure that stores key-value pair */
135 struct rte_hash_key {
136  union {
137  uintptr_t idata;
138  void *pdata;
139  };
140  /* Variable key size */
141  char key[0];
142 };
143 
144 /* All different signature compare functions */
145 enum rte_hash_sig_compare_function {
146  RTE_HASH_COMPARE_SCALAR = 0,
147  RTE_HASH_COMPARE_SSE,
148  RTE_HASH_COMPARE_NEON,
149  RTE_HASH_COMPARE_LSX,
150  RTE_HASH_COMPARE_NUM
151 };
152 
155  uint16_t sig_current[RTE_HASH_BUCKET_ENTRIES];
156 
157  uint32_t key_idx[RTE_HASH_BUCKET_ENTRIES];
158 
159  uint8_t flag[RTE_HASH_BUCKET_ENTRIES];
160 
161  void *next;
163 
165 struct rte_hash {
167  uint32_t entries;
168  uint32_t num_buckets;
173  struct lcore_cache *local_free_slots;
176  /* RCU config */
179  struct rte_rcu_qsbr_dq *dq;
181  /* Fields used in lookup */
182 
183  uint32_t key_len __rte_cache_aligned;
194  uint8_t no_free_on_del;
208  enum cmp_jump_table_case cmp_jump_table_idx;
210  enum rte_hash_sig_compare_function sig_cmp_fn;
212  uint32_t bucket_bitmask;
214  uint32_t key_entry_size;
216  void *key_store;
224  /* Stores index of an empty ext bkt to be recycled on calling
225  * rte_hash_del_xxx APIs. When lock free read-write concurrency is
226  * enabled, an empty ext bkt cannot be put into free list immediately
227  * (as readers might be using it still). Hence freeing of the ext bkt
228  * is piggy-backed to freeing of the key index.
229  */
230  uint32_t *ext_bkt_to_free;
231  uint32_t *tbl_chng_cnt;
234 
235 struct queue_node {
236  struct rte_hash_bucket *bkt; /* Current bucket on the bfs search */
237  uint32_t cur_bkt_idx;
238 
239  struct queue_node *prev; /* Parent(bucket) in search path */
240  int prev_slot; /* Parent(slot) in search path */
241 };
242 
244 #define RTE_HASH_RCU_DQ_RECLAIM_MAX 16
245 
246 #endif
uint8_t readwrite_concur_lf_support
uint32_t(* rte_hash_function)(const void *key, uint32_t key_len, uint32_t init_val)
Definition: rte_hash.h:66
uint8_t use_local_cache
void * key_store
enum rte_hash_sig_compare_function sig_cmp_fn
uint32_t * tbl_chng_cnt
uint8_t readwrite_concur_support
uint32_t entries
uint32_t key_len __rte_cache_aligned
struct rte_rcu_qsbr_dq * dq
rte_hash_function hash_func
uint32_t num_buckets
#define RTE_HASH_NAMESIZE
Definition: rte_hash.h:28
uint8_t no_free_on_del
char name[RTE_HASH_NAMESIZE]
struct rte_ring * free_slots
uint32_t key_entry_size
uint32_t bucket_bitmask
struct rte_ring * free_ext_bkts
int(* rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len)
Definition: rte_hash.h:70
struct lcore_cache * local_free_slots
rte_rwlock_t * readwrite_lock
#define __rte_cache_aligned
Definition: rte_common.h:400
uint8_t hw_trans_mem_support
struct rte_hash_rcu_config * hash_rcu_cfg
struct rte_hash_bucket * buckets_ext
rte_hash_cmp_eq_t rte_hash_custom_cmp_eq
uint8_t writer_takes_lock
uint8_t ext_table_support
uint32_t hash_func_init_val
struct rte_hash_bucket * buckets
enum cmp_jump_table_case cmp_jump_table_idx