DPDK  17.02.1
rte_efd.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_EFD_H_
35 #define _RTE_EFD_H_
36 
43 #include <stdint.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /*************************************************************************
50  * User selectable constants
51  *************************************************************************/
52 
53 /*
54  * If possible, best lookup performance will be achieved by ensuring that
55  * the entire table fits in the L3 cache.
56  *
57  * Some formulas for calculating various sizes are listed below:
58  *
59  * # of chunks =
60  * 2 ^ (ceiling(log2((requested # of rules) /
61  * (EFD_CHUNK_NUM_GROUPS * EFD_TARGET_GROUP_NUM_RULES))))
62  *
63  * Target # of rules = (# of chunks) * EFD_CHUNK_NUM_GROUPS *
64  * EFD_TARGET_GROUP_NUM_RULES
65  *
66  * Group Size (in bytes) = 4 (per value bit)
67  *
68  * Table size (in bytes) = RTE_EFD_VALUE_NUM_BITS * (# of chunks) *
69  * EFD_CHUNK_NUM_GROUPS * (group size)
70  */
71 
93 #ifndef RTE_EFD_VALUE_NUM_BITS
94 #define RTE_EFD_VALUE_NUM_BITS (8)
95 #endif
96 
97 /*
98  * EFD_TARGET_GROUP_NUM_RULES:
99  * Adjusts how many groups/chunks are allocated at table creation time
100  * to support the requested number of rules. Higher values pack entries
101  * more tightly in memory, resulting in a smaller memory footprint
102  * for the online table.
103  * This comes at the cost of lower insert/update performance.
104  *
105  * EFD_MAX_GROUP_NUM_RULES:
106  * This adjusts the amount of offline memory allocated to store key/value
107  * pairs for the table. The recommended numbers are upper-bounds for
108  * this parameter
109  * - any higher and it becomes very unlikely that a perfect hash function
110  * can be found for that group size. This value should be at
111  * least 40% larger than EFD_TARGET_GROUP_NUM_RULES
112  *
113  * Recommended values for various lookuptable and hashfunc sizes are:
114  *
115  * HASH_FUNC_SIZE = 16, LOOKUPTBL_SIZE = 16:
116  * EFD_TARGET_GROUP_NUM_RULES = 22
117  * EFD_MAX_GROUP_NUM_RULES = 28
118  */
119 #define EFD_TARGET_GROUP_NUM_RULES (22)
120 #define EFD_MAX_GROUP_NUM_RULES (28LU)
121 
122 #define EFD_MIN_BALANCED_NUM_RULES 5
123 
127 #ifndef RTE_EFD_BURST_MAX
128 #define RTE_EFD_BURST_MAX (32)
129 #endif
130 
132 #define RTE_EFD_NAMESIZE 32
133 
134 #if (RTE_EFD_VALUE_NUM_BITS > 0 && RTE_EFD_VALUE_NUM_BITS <= 8)
135 typedef uint8_t efd_value_t;
136 #elif (RTE_EFD_VALUE_NUM_BITS > 8 && RTE_EFD_VALUE_NUM_BITS <= 16)
137 typedef uint16_t efd_value_t;
138 #elif (RTE_EFD_VALUE_NUM_BITS > 16 && RTE_EFD_VALUE_NUM_BITS <= 32)
139 typedef uint32_t efd_value_t;
140 #else
141 #error("RTE_EFD_VALUE_NUM_BITS must be in the range [1:32]")
142 #endif
143 
144 #define EFD_LOOKUPTBL_SHIFT (32 - 4)
145 typedef uint16_t efd_lookuptbl_t;
146 typedef uint16_t efd_hashfunc_t;
147 
169 struct rte_efd_table *
170 rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
171  uint8_t online_cpu_socket_bitmask, uint8_t offline_cpu_socket);
172 
179 void
180 rte_efd_free(struct rte_efd_table *table);
181 
192 struct rte_efd_table*
193 rte_efd_find_existing(const char *name);
194 
195 #define RTE_EFD_UPDATE_WARN_GROUP_FULL (1)
196 #define RTE_EFD_UPDATE_NO_CHANGE (2)
197 #define RTE_EFD_UPDATE_FAILED (3)
198 
228 int
229 rte_efd_update(struct rte_efd_table *table, unsigned int socket_id,
230  const void *key, efd_value_t value);
231 
250 int
251 rte_efd_delete(struct rte_efd_table *table, unsigned int socket_id,
252  const void *key, efd_value_t *prev_value);
253 
274 efd_value_t
275 rte_efd_lookup(const struct rte_efd_table *table, unsigned int socket_id,
276  const void *key);
277 
299 void
300 rte_efd_lookup_bulk(const struct rte_efd_table *table, unsigned int socket_id,
301  int num_keys, const void **key_list,
302  efd_value_t *value_list);
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif /* _RTE_EFD_H_ */