DPDK  21.11.7
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 /* Macro to enable/disable run-time checking of function parameters */
23 #if defined(RTE_LIBRTE_HASH_DEBUG)
24 #define RETURN_IF_TRUE(cond, retval) do { \
25  if (cond) \
26  return retval; \
27 } while (0)
28 #else
29 #define RETURN_IF_TRUE(cond, retval)
30 #endif
31 
32 #include <rte_hash_crc.h>
33 #include <rte_jhash.h>
34 
35 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
36 /*
37  * All different options to select a key compare function,
38  * based on the key size and custom function.
39  */
40 enum cmp_jump_table_case {
41  KEY_CUSTOM = 0,
42  KEY_16_BYTES,
43  KEY_32_BYTES,
44  KEY_48_BYTES,
45  KEY_64_BYTES,
46  KEY_80_BYTES,
47  KEY_96_BYTES,
48  KEY_112_BYTES,
49  KEY_128_BYTES,
50  KEY_OTHER_BYTES,
51  NUM_KEY_CMP_CASES,
52 };
53 
54 /*
55  * Table storing all different key compare functions
56  * (multi-process supported)
57  */
58 const rte_hash_cmp_eq_t cmp_jump_table[NUM_KEY_CMP_CASES] = {
59  NULL,
60  rte_hash_k16_cmp_eq,
61  rte_hash_k32_cmp_eq,
62  rte_hash_k48_cmp_eq,
63  rte_hash_k64_cmp_eq,
64  rte_hash_k80_cmp_eq,
65  rte_hash_k96_cmp_eq,
66  rte_hash_k112_cmp_eq,
67  rte_hash_k128_cmp_eq,
68  memcmp
69 };
70 #else
71 /*
72  * All different options to select a key compare function,
73  * based on the key size and custom function.
74  */
75 enum cmp_jump_table_case {
76  KEY_CUSTOM = 0,
77  KEY_OTHER_BYTES,
78  NUM_KEY_CMP_CASES,
79 };
80 
81 /*
82  * Table storing all different key compare functions
83  * (multi-process supported)
84  */
85 const rte_hash_cmp_eq_t cmp_jump_table[NUM_KEY_CMP_CASES] = {
86  NULL,
87  memcmp
88 };
89 
90 #endif
91 
92 
100 #define RTE_HASH_BUCKET_ENTRIES 8
101 
102 #if !RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES)
103 #error RTE_HASH_BUCKET_ENTRIES must be a power of 2
104 #endif
105 
106 #define NULL_SIGNATURE 0
107 
108 #define EMPTY_SLOT 0
109 
110 #define KEY_ALIGNMENT 16
111 
112 #define LCORE_CACHE_SIZE 64
113 
114 #define RTE_HASH_BFS_QUEUE_MAX_LEN 1000
115 
116 #define RTE_XABORT_CUCKOO_PATH_INVALIDED 0x4
117 
118 #define RTE_HASH_TSX_MAX_RETRY 10
119 
120 struct lcore_cache {
121  unsigned len;
122  uint32_t objs[LCORE_CACHE_SIZE];
124 
125 /* Structure that stores key-value pair */
126 struct rte_hash_key {
127  union {
128  uintptr_t idata;
129  void *pdata;
130  };
131  /* Variable key size */
132  char key[0];
133 };
134 
135 /* All different signature compare functions */
136 enum rte_hash_sig_compare_function {
137  RTE_HASH_COMPARE_SCALAR = 0,
138  RTE_HASH_COMPARE_SSE,
139  RTE_HASH_COMPARE_NEON,
140  RTE_HASH_COMPARE_NUM
141 };
142 
145  uint16_t sig_current[RTE_HASH_BUCKET_ENTRIES];
146 
147  uint32_t key_idx[RTE_HASH_BUCKET_ENTRIES];
148 
149  uint8_t flag[RTE_HASH_BUCKET_ENTRIES];
150 
151  void *next;
153 
155 struct rte_hash {
156  char name[RTE_HASH_NAMESIZE];
157  uint32_t entries;
158  uint32_t num_buckets;
163  struct lcore_cache *local_free_slots;
166  /* RCU config */
169  struct rte_rcu_qsbr_dq *dq;
171  /* Fields used in lookup */
172 
173  uint32_t key_len __rte_cache_aligned;
184  uint8_t no_free_on_del;
198  enum cmp_jump_table_case cmp_jump_table_idx;
200  enum rte_hash_sig_compare_function sig_cmp_fn;
202  uint32_t bucket_bitmask;
204  uint32_t key_entry_size;
206  void *key_store;
214  /* Stores index of an empty ext bkt to be recycled on calling
215  * rte_hash_del_xxx APIs. When lock free read-write concurrency is
216  * enabled, an empty ext bkt cannot be put into free list immediately
217  * (as readers might be using it still). Hence freeing of the ext bkt
218  * is piggy-backed to freeing of the key index.
219  */
220  uint32_t *ext_bkt_to_free;
221  uint32_t *tbl_chng_cnt;
224 
225 struct queue_node {
226  struct rte_hash_bucket *bkt; /* Current bucket on the bfs search */
227  uint32_t cur_bkt_idx;
228 
229  struct queue_node *prev; /* Parent(bucket) in search path */
230  int prev_slot; /* Parent(slot) in search path */
231 };
232 
234 #define RTE_HASH_RCU_DQ_RECLAIM_MAX 16
235 
236 #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
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
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:420
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