DPDK  26.07.0
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 #include <stdalign.h>
15 #include <rte_hash_crc.h>
16 #include <rte_jhash.h>
17 
25 #define RTE_HASH_BUCKET_ENTRIES 8
26 
27 static_assert(RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES),
28  "RTE_HASH_BUCKET_ENTRIES must be a power of 2");
29 
30 #define NULL_SIGNATURE 0
31 
32 #define EMPTY_SLOT 0
33 
34 #define KEY_ALIGNMENT 16
35 
36 #define LCORE_CACHE_SIZE 64
37 
38 #define RTE_HASH_BFS_QUEUE_MAX_LEN 1000
39 
40 #define RTE_XABORT_CUCKOO_PATH_INVALIDED 0x4
41 
42 #define RTE_HASH_TSX_MAX_RETRY 10
43 
44 struct __rte_cache_aligned lcore_cache {
45  unsigned len;
46  uint32_t objs[LCORE_CACHE_SIZE];
47 };
48 
49 /* Structure that stores key-value pair */
50 struct rte_hash_key {
51  union {
52  uintptr_t idata;
53  RTE_ATOMIC(void *) pdata;
54  };
55  /* Variable key size */
56  char key[];
57 };
58 
61  uint16_t sig_current[RTE_HASH_BUCKET_ENTRIES];
62 
63  RTE_ATOMIC(uint32_t) key_idx[RTE_HASH_BUCKET_ENTRIES];
64 
65  uint8_t flag[RTE_HASH_BUCKET_ENTRIES];
66 
67  void *next;
68 };
69 
72  char name[RTE_HASH_NAMESIZE];
73  uint32_t entries;
74  uint32_t num_buckets;
79  struct lcore_cache *local_free_slots;
82  /* RCU config */
85  struct rte_rcu_qsbr_dq *dq;
87  /* Fields used in lookup */
88 
89  alignas(RTE_CACHE_LINE_SIZE) uint32_t key_len;
93  uint8_t use_local_cache;
100  uint8_t no_free_on_del;
114  unsigned int cmp_jump_table_idx;
116  unsigned int sig_cmp_fn;
118  uint32_t bucket_bitmask;
120  uint32_t key_entry_size;
122  void *key_store;
127  rte_rwlock_t *readwrite_lock;
130  /* Stores index of an empty ext bkt to be recycled on calling
131  * rte_hash_del_xxx APIs. When lock free read-write concurrency is
132  * enabled, an empty ext bkt cannot be put into free list immediately
133  * (as readers might be using it still). Hence freeing of the ext bkt
134  * is piggy-backed to freeing of the key index.
135  */
136  uint32_t *ext_bkt_to_free;
137  RTE_ATOMIC(uint32_t) *tbl_chng_cnt;
139 };
140 
141 struct queue_node {
142  struct rte_hash_bucket *bkt; /* Current bucket on the bfs search */
143  uint32_t cur_bkt_idx;
144 
145  struct queue_node *prev; /* Parent(bucket) in search path */
146  int prev_slot; /* Parent(slot) in search path */
147 };
148 
150 #define RTE_HASH_RCU_DQ_RECLAIM_MAX 16
151 
152 #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
#define RTE_IS_POWER_OF_2(n)
Definition: rte_bitops.h:1302
uint32_t * tbl_chng_cnt
uint8_t readwrite_concur_support
uint32_t entries
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
#define __rte_cache_aligned
Definition: rte_common.h:773
unsigned int sig_cmp_fn
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
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
unsigned int cmp_jump_table_idx
struct rte_hash_bucket * buckets