Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <stdalign.h>
6 : : #include <stdio.h>
7 : : #include <string.h>
8 : :
9 : : #include <eal_export.h>
10 : : #include <rte_common.h>
11 : : #include <rte_malloc.h>
12 : : #include <rte_log.h>
13 : :
14 : : #include "rte_table_hash.h"
15 : : #include "rte_lru.h"
16 : :
17 : : #include "table_log.h"
18 : :
19 : : #define KEY_SIZE 16
20 : :
21 : : #define KEYS_PER_BUCKET 4
22 : :
23 : : #define RTE_BUCKET_ENTRY_VALID 0x1LLU
24 : :
25 : : #ifdef RTE_TABLE_STATS_COLLECT
26 : :
27 : : #define RTE_TABLE_HASH_KEY16_STATS_PKTS_IN_ADD(table, val) \
28 : : table->stats.n_pkts_in += val
29 : : #define RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(table, val) \
30 : : table->stats.n_pkts_lookup_miss += val
31 : :
32 : : #else
33 : :
34 : : #define RTE_TABLE_HASH_KEY16_STATS_PKTS_IN_ADD(table, val)
35 : : #define RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(table, val)
36 : :
37 : : #endif
38 : :
39 : : #ifdef RTE_ARCH_64
40 : : struct rte_bucket_4_16 {
41 : : /* Cache line 0 */
42 : : uint64_t signature[4 + 1];
43 : : uint64_t lru_list;
44 : : struct rte_bucket_4_16 *next;
45 : : uint64_t next_valid;
46 : :
47 : : /* Cache line 1 */
48 : : uint64_t key[4][2];
49 : :
50 : : /* Cache line 2 */
51 : : uint8_t data[];
52 : : };
53 : : #else
54 : : struct rte_bucket_4_16 {
55 : : /* Cache line 0 */
56 : : uint64_t signature[4 + 1];
57 : : uint64_t lru_list;
58 : : struct rte_bucket_4_16 *next;
59 : : uint32_t pad;
60 : : uint64_t next_valid;
61 : :
62 : : /* Cache line 1 */
63 : : uint64_t key[4][2];
64 : :
65 : : /* Cache line 2 */
66 : : uint8_t data[];
67 : : };
68 : : #endif
69 : :
70 : : struct rte_table_hash {
71 : : struct rte_table_stats stats;
72 : :
73 : : /* Input parameters */
74 : : uint32_t n_buckets;
75 : : uint32_t key_size;
76 : : uint32_t entry_size;
77 : : uint32_t bucket_size;
78 : : uint32_t key_offset;
79 : : uint64_t key_mask[2];
80 : : rte_table_hash_op_hash f_hash;
81 : : uint64_t seed;
82 : :
83 : : /* Extendible buckets */
84 : : uint32_t n_buckets_ext;
85 : : uint32_t stack_pos;
86 : : uint32_t *stack;
87 : :
88 : : /* Lookup table */
89 : : alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[];
90 : : };
91 : :
92 : : static int
93 : : keycmp(void *a, void *b, void *b_mask)
94 : : {
95 : : uint64_t *a64 = a, *b64 = b, *b_mask64 = b_mask;
96 : :
97 [ + - + - : 6 : return (a64[0] != (b64[0] & b_mask64[0])) ||
+ - + - ]
98 [ + - + - : 6 : (a64[1] != (b64[1] & b_mask64[1]));
+ - + - ]
99 : : }
100 : :
101 : : static void
102 : : keycpy(void *dst, void *src, void *src_mask)
103 : : {
104 : : uint64_t *dst64 = dst, *src64 = src, *src_mask64 = src_mask;
105 : :
106 : 6 : dst64[0] = src64[0] & src_mask64[0];
107 : 6 : dst64[1] = src64[1] & src_mask64[1];
108 : : }
109 : :
110 : : static int
111 : 15 : check_params_create(struct rte_table_hash_params *params)
112 : : {
113 : : /* name */
114 [ - + ]: 15 : if (params->name == NULL) {
115 : 0 : TABLE_LOG(ERR, "%s: name invalid value", __func__);
116 : 0 : return -EINVAL;
117 : : }
118 : :
119 : : /* key_size */
120 [ - + ]: 15 : if (params->key_size != KEY_SIZE) {
121 : 0 : TABLE_LOG(ERR, "%s: key_size invalid value", __func__);
122 : 0 : return -EINVAL;
123 : : }
124 : :
125 : : /* n_keys */
126 [ + + ]: 15 : if (params->n_keys == 0) {
127 : 4 : TABLE_LOG(ERR, "%s: n_keys is zero", __func__);
128 : 4 : return -EINVAL;
129 : : }
130 : :
131 : : /* n_buckets */
132 [ + - ]: 11 : if ((params->n_buckets == 0) ||
133 : : (!rte_is_power_of_2(params->n_buckets))) {
134 : 0 : TABLE_LOG(ERR, "%s: n_buckets invalid value", __func__);
135 : 0 : return -EINVAL;
136 : : }
137 : :
138 : : /* f_hash */
139 [ + + ]: 11 : if (params->f_hash == NULL) {
140 : 4 : TABLE_LOG(ERR, "%s: f_hash function pointer is NULL",
141 : : __func__);
142 : 4 : return -EINVAL;
143 : : }
144 : :
145 : : return 0;
146 : : }
147 : :
148 : : static void *
149 : 7 : rte_table_hash_create_key16_lru(void *params,
150 : : int socket_id,
151 : : uint32_t entry_size)
152 : : {
153 : : struct rte_table_hash_params *p = params;
154 : : struct rte_table_hash *f;
155 : : uint64_t bucket_size, total_size;
156 : : uint32_t n_buckets, i;
157 : :
158 : : /* Check input parameters */
159 [ + + ]: 7 : if ((check_params_create(p) != 0) ||
160 : : ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
161 : : ((sizeof(struct rte_bucket_4_16) % 64) != 0))
162 : : return NULL;
163 : :
164 : : /*
165 : : * Table dimensioning
166 : : *
167 : : * Objective: Pick the number of buckets (n_buckets) so that there a chance
168 : : * to store n_keys keys in the table.
169 : : *
170 : : * Note: Since the buckets do not get extended, it is not possible to
171 : : * guarantee that n_keys keys can be stored in the table at any time. In the
172 : : * worst case scenario when all the n_keys fall into the same bucket, only
173 : : * a maximum of KEYS_PER_BUCKET keys will be stored in the table. This case
174 : : * defeats the purpose of the hash table. It indicates unsuitable f_hash or
175 : : * n_keys to n_buckets ratio.
176 : : *
177 : : * MIN(n_buckets) = (n_keys + KEYS_PER_BUCKET - 1) / KEYS_PER_BUCKET
178 : : */
179 : 3 : n_buckets = rte_align32pow2(
180 : 3 : (p->n_keys + KEYS_PER_BUCKET - 1) / KEYS_PER_BUCKET);
181 : 3 : n_buckets = RTE_MAX(n_buckets, p->n_buckets);
182 : :
183 : : /* Memory allocation */
184 : 3 : bucket_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_bucket_4_16) +
185 : : KEYS_PER_BUCKET * entry_size);
186 : 3 : total_size = sizeof(struct rte_table_hash) + n_buckets * bucket_size;
187 : :
188 : : if (total_size > SIZE_MAX) {
189 : : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
190 : : "for hash table %s",
191 : : __func__, total_size, p->name);
192 : : return NULL;
193 : : }
194 : :
195 : 3 : f = rte_zmalloc_socket(p->name,
196 : : (size_t)total_size,
197 : : RTE_CACHE_LINE_SIZE,
198 : : socket_id);
199 [ - + ]: 3 : if (f == NULL) {
200 : 0 : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
201 : : "for hash table %s",
202 : : __func__, total_size, p->name);
203 : 0 : return NULL;
204 : : }
205 : 3 : TABLE_LOG(INFO, "%s: Hash table %s memory footprint "
206 : : "is %" PRIu64 " bytes",
207 : : __func__, p->name, total_size);
208 : :
209 : : /* Memory initialization */
210 : 3 : f->n_buckets = n_buckets;
211 : 3 : f->key_size = KEY_SIZE;
212 : 3 : f->entry_size = entry_size;
213 : 3 : f->bucket_size = bucket_size;
214 : 3 : f->key_offset = p->key_offset;
215 : 3 : f->f_hash = p->f_hash;
216 : 3 : f->seed = p->seed;
217 : :
218 [ - + ]: 3 : if (p->key_mask != NULL) {
219 : 0 : f->key_mask[0] = ((uint64_t *)p->key_mask)[0];
220 : 0 : f->key_mask[1] = ((uint64_t *)p->key_mask)[1];
221 : : } else {
222 : 3 : f->key_mask[0] = 0xFFFFFFFFFFFFFFFFLLU;
223 : 3 : f->key_mask[1] = 0xFFFFFFFFFFFFFFFFLLU;
224 : : }
225 : :
226 [ + + ]: 67587 : for (i = 0; i < n_buckets; i++) {
227 : : struct rte_bucket_4_16 *bucket;
228 : :
229 : 67584 : bucket = (struct rte_bucket_4_16 *) &f->memory[i *
230 : : f->bucket_size];
231 : 67584 : lru_init(bucket);
232 : : }
233 : :
234 : : return f;
235 : : }
236 : :
237 : : static int
238 : 4 : rte_table_hash_free_key16_lru(void *table)
239 : : {
240 : : struct rte_table_hash *f = table;
241 : :
242 : : /* Check input parameters */
243 [ + + ]: 4 : if (f == NULL) {
244 : 1 : TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
245 : 1 : return -EINVAL;
246 : : }
247 : :
248 : 3 : rte_free(f);
249 : 3 : return 0;
250 : : }
251 : :
252 : : static int
253 : 4 : rte_table_hash_entry_add_key16_lru(
254 : : void *table,
255 : : void *key,
256 : : void *entry,
257 : : int *key_found,
258 : : void **entry_ptr)
259 : : {
260 : : struct rte_table_hash *f = table;
261 : : struct rte_bucket_4_16 *bucket;
262 : : uint64_t signature, pos;
263 : : uint32_t bucket_index, i;
264 : :
265 : 4 : signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
266 : 4 : bucket_index = signature & (f->n_buckets - 1);
267 : 4 : bucket = (struct rte_bucket_4_16 *)
268 : 4 : &f->memory[bucket_index * f->bucket_size];
269 : 4 : signature |= RTE_BUCKET_ENTRY_VALID;
270 : :
271 : : /* Key is present in the bucket */
272 [ + + ]: 16 : for (i = 0; i < 4; i++) {
273 : 13 : uint64_t bucket_signature = bucket->signature[i];
274 : 13 : uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
275 : :
276 [ + + ]: 13 : if ((bucket_signature == signature) &&
277 : : (keycmp(bucket_key, key, f->key_mask) == 0)) {
278 : 1 : uint8_t *bucket_data = &bucket->data[i * f->entry_size];
279 : :
280 : 1 : memcpy(bucket_data, entry, f->entry_size);
281 : 1 : lru_update(bucket, i);
282 : 1 : *key_found = 1;
283 : 1 : *entry_ptr = (void *) bucket_data;
284 : 1 : return 0;
285 : : }
286 : : }
287 : :
288 : : /* Key is not present in the bucket */
289 [ + - ]: 3 : for (i = 0; i < 4; i++) {
290 : 3 : uint64_t bucket_signature = bucket->signature[i];
291 : 3 : uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
292 : :
293 [ + - ]: 3 : if (bucket_signature == 0) {
294 : 3 : uint8_t *bucket_data = &bucket->data[i * f->entry_size];
295 : :
296 : 3 : bucket->signature[i] = signature;
297 : : keycpy(bucket_key, key, f->key_mask);
298 : 3 : memcpy(bucket_data, entry, f->entry_size);
299 : 3 : lru_update(bucket, i);
300 : 3 : *key_found = 0;
301 : 3 : *entry_ptr = (void *) bucket_data;
302 : :
303 : 3 : return 0;
304 : : }
305 : : }
306 : :
307 : : /* Bucket full: replace LRU entry */
308 : 0 : pos = lru_pos(bucket);
309 : 0 : bucket->signature[pos] = signature;
310 : 0 : keycpy(&bucket->key[pos], key, f->key_mask);
311 : 0 : memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
312 : 0 : lru_update(bucket, pos);
313 : 0 : *key_found = 0;
314 : 0 : *entry_ptr = (void *) &bucket->data[pos * f->entry_size];
315 : :
316 : 0 : return 0;
317 : : }
318 : :
319 : : static int
320 : 3 : rte_table_hash_entry_delete_key16_lru(
321 : : void *table,
322 : : void *key,
323 : : int *key_found,
324 : : void *entry)
325 : : {
326 : : struct rte_table_hash *f = table;
327 : : struct rte_bucket_4_16 *bucket;
328 : : uint64_t signature;
329 : : uint32_t bucket_index, i;
330 : :
331 : 3 : signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
332 : 3 : bucket_index = signature & (f->n_buckets - 1);
333 : 3 : bucket = (struct rte_bucket_4_16 *)
334 : 3 : &f->memory[bucket_index * f->bucket_size];
335 : 3 : signature |= RTE_BUCKET_ENTRY_VALID;
336 : :
337 : : /* Key is present in the bucket */
338 [ + + ]: 7 : for (i = 0; i < 4; i++) {
339 : 6 : uint64_t bucket_signature = bucket->signature[i];
340 : 6 : uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
341 : :
342 [ + + ]: 6 : if ((bucket_signature == signature) &&
343 : : (keycmp(bucket_key, key, f->key_mask) == 0)) {
344 : 2 : uint8_t *bucket_data = &bucket->data[i * f->entry_size];
345 : :
346 : 2 : bucket->signature[i] = 0;
347 : 2 : *key_found = 1;
348 [ - + ]: 2 : if (entry)
349 : 0 : memcpy(entry, bucket_data, f->entry_size);
350 : 2 : return 0;
351 : : }
352 : : }
353 : :
354 : : /* Key is not present in the bucket */
355 : 1 : *key_found = 0;
356 : 1 : return 0;
357 : : }
358 : :
359 : : static void *
360 : 8 : rte_table_hash_create_key16_ext(void *params,
361 : : int socket_id,
362 : : uint32_t entry_size)
363 : : {
364 : : struct rte_table_hash_params *p = params;
365 : : struct rte_table_hash *f;
366 : : uint64_t bucket_size, stack_size, total_size;
367 : : uint32_t n_buckets_ext, i;
368 : :
369 : : /* Check input parameters */
370 [ + + ]: 8 : if ((check_params_create(p) != 0) ||
371 : : ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
372 : : ((sizeof(struct rte_bucket_4_16) % 64) != 0))
373 : : return NULL;
374 : :
375 : : /*
376 : : * Table dimensioning
377 : : *
378 : : * Objective: Pick the number of bucket extensions (n_buckets_ext) so that
379 : : * it is guaranteed that n_keys keys can be stored in the table at any time.
380 : : *
381 : : * The worst case scenario takes place when all the n_keys keys fall into
382 : : * the same bucket. Actually, due to the KEYS_PER_BUCKET scheme, the worst
383 : : * case takes place when (n_keys - KEYS_PER_BUCKET + 1) keys fall into the
384 : : * same bucket, while the remaining (KEYS_PER_BUCKET - 1) keys each fall
385 : : * into a different bucket. This case defeats the purpose of the hash table.
386 : : * It indicates unsuitable f_hash or n_keys to n_buckets ratio.
387 : : *
388 : : * n_buckets_ext = n_keys / KEYS_PER_BUCKET + KEYS_PER_BUCKET - 1
389 : : */
390 : 4 : n_buckets_ext = p->n_keys / KEYS_PER_BUCKET + KEYS_PER_BUCKET - 1;
391 : :
392 : : /* Memory allocation */
393 : 4 : bucket_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_bucket_4_16) +
394 : : KEYS_PER_BUCKET * entry_size);
395 : 4 : stack_size = RTE_CACHE_LINE_ROUNDUP(n_buckets_ext * sizeof(uint32_t));
396 : 4 : total_size = sizeof(struct rte_table_hash) +
397 : 4 : (p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
398 : : if (total_size > SIZE_MAX) {
399 : : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
400 : : "for hash table %s",
401 : : __func__, total_size, p->name);
402 : : return NULL;
403 : : }
404 : :
405 : 4 : f = rte_zmalloc_socket(p->name,
406 : : (size_t)total_size,
407 : : RTE_CACHE_LINE_SIZE,
408 : : socket_id);
409 [ - + ]: 4 : if (f == NULL) {
410 : 0 : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
411 : : "for hash table %s",
412 : : __func__, total_size, p->name);
413 : 0 : return NULL;
414 : : }
415 : 4 : TABLE_LOG(INFO, "%s: Hash table %s memory footprint "
416 : : "is %" PRIu64 " bytes",
417 : : __func__, p->name, total_size);
418 : :
419 : : /* Memory initialization */
420 : 4 : f->n_buckets = p->n_buckets;
421 : 4 : f->key_size = KEY_SIZE;
422 : 4 : f->entry_size = entry_size;
423 : 4 : f->bucket_size = bucket_size;
424 : 4 : f->key_offset = p->key_offset;
425 : 4 : f->f_hash = p->f_hash;
426 : 4 : f->seed = p->seed;
427 : :
428 : 4 : f->n_buckets_ext = n_buckets_ext;
429 : 4 : f->stack_pos = n_buckets_ext;
430 : 4 : f->stack = (uint32_t *)
431 : 4 : &f->memory[(p->n_buckets + n_buckets_ext) * f->bucket_size];
432 : :
433 [ - + ]: 4 : if (p->key_mask != NULL) {
434 : 0 : f->key_mask[0] = (((uint64_t *)p->key_mask)[0]);
435 : 0 : f->key_mask[1] = (((uint64_t *)p->key_mask)[1]);
436 : : } else {
437 : 4 : f->key_mask[0] = 0xFFFFFFFFFFFFFFFFLLU;
438 : 4 : f->key_mask[1] = 0xFFFFFFFFFFFFFFFFLLU;
439 : : }
440 : :
441 [ + + ]: 17168 : for (i = 0; i < n_buckets_ext; i++)
442 : 17164 : f->stack[i] = i;
443 : :
444 : : return f;
445 : : }
446 : :
447 : : static int
448 : 4 : rte_table_hash_free_key16_ext(void *table)
449 : : {
450 : : struct rte_table_hash *f = table;
451 : :
452 : : /* Check input parameters */
453 [ + + ]: 4 : if (f == NULL) {
454 : 1 : TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
455 : 1 : return -EINVAL;
456 : : }
457 : :
458 : 3 : rte_free(f);
459 : 3 : return 0;
460 : : }
461 : :
462 : : static int
463 : 4 : rte_table_hash_entry_add_key16_ext(
464 : : void *table,
465 : : void *key,
466 : : void *entry,
467 : : int *key_found,
468 : : void **entry_ptr)
469 : : {
470 : : struct rte_table_hash *f = table;
471 : : struct rte_bucket_4_16 *bucket0, *bucket, *bucket_prev;
472 : : uint64_t signature;
473 : : uint32_t bucket_index, i;
474 : :
475 : 4 : signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
476 : 4 : bucket_index = signature & (f->n_buckets - 1);
477 : 4 : bucket0 = (struct rte_bucket_4_16 *)
478 : 4 : &f->memory[bucket_index * f->bucket_size];
479 : 4 : signature |= RTE_BUCKET_ENTRY_VALID;
480 : :
481 : : /* Key is present in the bucket */
482 [ + + ]: 7 : for (bucket = bucket0; bucket != NULL; bucket = bucket->next)
483 [ + + ]: 16 : for (i = 0; i < 4; i++) {
484 : 13 : uint64_t bucket_signature = bucket->signature[i];
485 : 13 : uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
486 : :
487 [ + + ]: 13 : if ((bucket_signature == signature) &&
488 : : (keycmp(bucket_key, key, f->key_mask) == 0)) {
489 : 1 : uint8_t *bucket_data = &bucket->data[i *
490 : 1 : f->entry_size];
491 : :
492 : 1 : memcpy(bucket_data, entry, f->entry_size);
493 : 1 : *key_found = 1;
494 : 1 : *entry_ptr = (void *) bucket_data;
495 : 1 : return 0;
496 : : }
497 : : }
498 : :
499 : : /* Key is not present in the bucket */
500 [ + - ]: 3 : for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
501 : 0 : bucket_prev = bucket, bucket = bucket->next)
502 [ + - ]: 3 : for (i = 0; i < 4; i++) {
503 : 3 : uint64_t bucket_signature = bucket->signature[i];
504 : 3 : uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
505 : :
506 [ + - ]: 3 : if (bucket_signature == 0) {
507 : 3 : uint8_t *bucket_data = &bucket->data[i *
508 : 3 : f->entry_size];
509 : :
510 : 3 : bucket->signature[i] = signature;
511 : : keycpy(bucket_key, key, f->key_mask);
512 : 3 : memcpy(bucket_data, entry, f->entry_size);
513 : 3 : *key_found = 0;
514 : 3 : *entry_ptr = (void *) bucket_data;
515 : :
516 : 3 : return 0;
517 : : }
518 : : }
519 : :
520 : : /* Bucket full: extend bucket */
521 [ # # ]: 0 : if (f->stack_pos > 0) {
522 : 0 : bucket_index = f->stack[--f->stack_pos];
523 : :
524 : 0 : bucket = (struct rte_bucket_4_16 *) &f->memory[(f->n_buckets +
525 : 0 : bucket_index) * f->bucket_size];
526 : 0 : bucket_prev->next = bucket;
527 : 0 : bucket_prev->next_valid = 1;
528 : :
529 : 0 : bucket->signature[0] = signature;
530 : : keycpy(&bucket->key[0], key, f->key_mask);
531 : 0 : memcpy(&bucket->data[0], entry, f->entry_size);
532 : 0 : *key_found = 0;
533 : 0 : *entry_ptr = (void *) &bucket->data[0];
534 : 0 : return 0;
535 : : }
536 : :
537 : : return -ENOSPC;
538 : : }
539 : :
540 : : static int
541 : 3 : rte_table_hash_entry_delete_key16_ext(
542 : : void *table,
543 : : void *key,
544 : : int *key_found,
545 : : void *entry)
546 : : {
547 : : struct rte_table_hash *f = table;
548 : : struct rte_bucket_4_16 *bucket0, *bucket, *bucket_prev;
549 : : uint64_t signature;
550 : : uint32_t bucket_index, i;
551 : :
552 : 3 : signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
553 : 3 : bucket_index = signature & (f->n_buckets - 1);
554 : 3 : bucket0 = (struct rte_bucket_4_16 *)
555 : 3 : &f->memory[bucket_index * f->bucket_size];
556 : 3 : signature |= RTE_BUCKET_ENTRY_VALID;
557 : :
558 : : /* Key is present in the bucket */
559 [ + + ]: 4 : for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
560 : 1 : bucket_prev = bucket, bucket = bucket->next)
561 [ + + ]: 7 : for (i = 0; i < 4; i++) {
562 : 6 : uint64_t bucket_signature = bucket->signature[i];
563 : 6 : uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
564 : :
565 [ + + ]: 6 : if ((bucket_signature == signature) &&
566 : : (keycmp(bucket_key, key, f->key_mask) == 0)) {
567 : 2 : uint8_t *bucket_data = &bucket->data[i *
568 : 2 : f->entry_size];
569 : :
570 : 2 : bucket->signature[i] = 0;
571 : 2 : *key_found = 1;
572 [ - + ]: 2 : if (entry)
573 : 0 : memcpy(entry, bucket_data, f->entry_size);
574 : :
575 [ + - ]: 2 : if ((bucket->signature[0] == 0) &&
576 [ + - ]: 2 : (bucket->signature[1] == 0) &&
577 [ + - ]: 2 : (bucket->signature[2] == 0) &&
578 [ + - - + ]: 2 : (bucket->signature[3] == 0) &&
579 : : (bucket_prev != NULL)) {
580 : 0 : bucket_prev->next = bucket->next;
581 : 0 : bucket_prev->next_valid =
582 : 0 : bucket->next_valid;
583 : :
584 : : memset(bucket, 0,
585 : : sizeof(struct rte_bucket_4_16));
586 : 0 : bucket_index = (((uint8_t *)bucket -
587 : 0 : (uint8_t *)f->memory)/f->bucket_size) - f->n_buckets;
588 : 0 : f->stack[f->stack_pos++] = bucket_index;
589 : : }
590 : :
591 : 2 : return 0;
592 : : }
593 : : }
594 : :
595 : : /* Key is not present in the bucket */
596 : 1 : *key_found = 0;
597 : 1 : return 0;
598 : : }
599 : :
600 : : #define lookup_key16_cmp(key_in, bucket, pos, f) \
601 : : { \
602 : : uint64_t xor[4][2], or[4], signature[4], k[2]; \
603 : : \
604 : : k[0] = key_in[0] & f->key_mask[0]; \
605 : : k[1] = key_in[1] & f->key_mask[1]; \
606 : : signature[0] = (~bucket->signature[0]) & 1; \
607 : : signature[1] = (~bucket->signature[1]) & 1; \
608 : : signature[2] = (~bucket->signature[2]) & 1; \
609 : : signature[3] = (~bucket->signature[3]) & 1; \
610 : : \
611 : : xor[0][0] = k[0] ^ bucket->key[0][0]; \
612 : : xor[0][1] = k[1] ^ bucket->key[0][1]; \
613 : : \
614 : : xor[1][0] = k[0] ^ bucket->key[1][0]; \
615 : : xor[1][1] = k[1] ^ bucket->key[1][1]; \
616 : : \
617 : : xor[2][0] = k[0] ^ bucket->key[2][0]; \
618 : : xor[2][1] = k[1] ^ bucket->key[2][1]; \
619 : : \
620 : : xor[3][0] = k[0] ^ bucket->key[3][0]; \
621 : : xor[3][1] = k[1] ^ bucket->key[3][1]; \
622 : : \
623 : : or[0] = xor[0][0] | xor[0][1] | signature[0]; \
624 : : or[1] = xor[1][0] | xor[1][1] | signature[1]; \
625 : : or[2] = xor[2][0] | xor[2][1] | signature[2]; \
626 : : or[3] = xor[3][0] | xor[3][1] | signature[3]; \
627 : : \
628 : : pos = 4; \
629 : : if (or[0] == 0) \
630 : : pos = 0; \
631 : : if (or[1] == 0) \
632 : : pos = 1; \
633 : : if (or[2] == 0) \
634 : : pos = 2; \
635 : : if (or[3] == 0) \
636 : : pos = 3; \
637 : : }
638 : :
639 : : #define lookup1_stage0(pkt0_index, mbuf0, pkts, pkts_mask, f) \
640 : : { \
641 : : uint64_t pkt_mask; \
642 : : uint32_t key_offset = f->key_offset;\
643 : : \
644 : : pkt0_index = rte_ctz64(pkts_mask); \
645 : : pkt_mask = 1LLU << pkt0_index; \
646 : : pkts_mask &= ~pkt_mask; \
647 : : \
648 : : mbuf0 = pkts[pkt0_index]; \
649 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf0, key_offset));\
650 : : }
651 : :
652 : : #define lookup1_stage1(mbuf1, bucket1, f) \
653 : : { \
654 : : uint64_t *key; \
655 : : uint64_t signature = 0; \
656 : : uint32_t bucket_index; \
657 : : \
658 : : key = RTE_MBUF_METADATA_UINT64_PTR(mbuf1, f->key_offset);\
659 : : signature = f->f_hash(key, f->key_mask, KEY_SIZE, f->seed); \
660 : : \
661 : : bucket_index = signature & (f->n_buckets - 1); \
662 : : bucket1 = (struct rte_bucket_4_16 *) \
663 : : &f->memory[bucket_index * f->bucket_size]; \
664 : : rte_prefetch0(bucket1); \
665 : : rte_prefetch0((void *)(((uintptr_t) bucket1) + RTE_CACHE_LINE_SIZE));\
666 : : }
667 : :
668 : : #define lookup1_stage2_lru(pkt2_index, mbuf2, bucket2, \
669 : : pkts_mask_out, entries, f) \
670 : : { \
671 : : void *a; \
672 : : uint64_t pkt_mask; \
673 : : uint64_t *key; \
674 : : uint32_t pos; \
675 : : \
676 : : key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
677 : : lookup_key16_cmp(key, bucket2, pos, f); \
678 : : \
679 : : pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
680 : : pkts_mask_out |= pkt_mask; \
681 : : \
682 : : a = (void *) &bucket2->data[pos * f->entry_size]; \
683 : : rte_prefetch0(a); \
684 : : entries[pkt2_index] = a; \
685 : : lru_update(bucket2, pos); \
686 : : }
687 : :
688 : : #define lookup1_stage2_ext(pkt2_index, mbuf2, bucket2, pkts_mask_out, entries, \
689 : : buckets_mask, buckets, keys, f) \
690 : : { \
691 : : struct rte_bucket_4_16 *bucket_next; \
692 : : void *a; \
693 : : uint64_t pkt_mask, bucket_mask; \
694 : : uint64_t *key; \
695 : : uint32_t pos; \
696 : : \
697 : : key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
698 : : lookup_key16_cmp(key, bucket2, pos, f); \
699 : : \
700 : : pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
701 : : pkts_mask_out |= pkt_mask; \
702 : : \
703 : : a = (void *) &bucket2->data[pos * f->entry_size]; \
704 : : rte_prefetch0(a); \
705 : : entries[pkt2_index] = a; \
706 : : \
707 : : bucket_mask = (~pkt_mask) & (bucket2->next_valid << pkt2_index);\
708 : : buckets_mask |= bucket_mask; \
709 : : bucket_next = bucket2->next; \
710 : : buckets[pkt2_index] = bucket_next; \
711 : : keys[pkt2_index] = key; \
712 : : }
713 : :
714 : : #define lookup_grinder(pkt_index, buckets, keys, pkts_mask_out, entries,\
715 : : buckets_mask, f) \
716 : : { \
717 : : struct rte_bucket_4_16 *bucket, *bucket_next; \
718 : : void *a; \
719 : : uint64_t pkt_mask, bucket_mask; \
720 : : uint64_t *key; \
721 : : uint32_t pos; \
722 : : \
723 : : bucket = buckets[pkt_index]; \
724 : : key = keys[pkt_index]; \
725 : : lookup_key16_cmp(key, bucket, pos, f); \
726 : : \
727 : : pkt_mask = (bucket->signature[pos] & 1LLU) << pkt_index;\
728 : : pkts_mask_out |= pkt_mask; \
729 : : \
730 : : a = (void *) &bucket->data[pos * f->entry_size]; \
731 : : rte_prefetch0(a); \
732 : : entries[pkt_index] = a; \
733 : : \
734 : : bucket_mask = (~pkt_mask) & (bucket->next_valid << pkt_index);\
735 : : buckets_mask |= bucket_mask; \
736 : : bucket_next = bucket->next; \
737 : : rte_prefetch0(bucket_next); \
738 : : rte_prefetch0((void *)(((uintptr_t) bucket_next) + RTE_CACHE_LINE_SIZE));\
739 : : buckets[pkt_index] = bucket_next; \
740 : : keys[pkt_index] = key; \
741 : : }
742 : :
743 : : #define lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01,\
744 : : pkts, pkts_mask, f) \
745 : : { \
746 : : uint64_t pkt00_mask, pkt01_mask; \
747 : : uint32_t key_offset = f->key_offset; \
748 : : \
749 : : pkt00_index = rte_ctz64(pkts_mask); \
750 : : pkt00_mask = 1LLU << pkt00_index; \
751 : : pkts_mask &= ~pkt00_mask; \
752 : : \
753 : : mbuf00 = pkts[pkt00_index]; \
754 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, key_offset));\
755 : : \
756 : : pkt01_index = rte_ctz64(pkts_mask); \
757 : : pkt01_mask = 1LLU << pkt01_index; \
758 : : pkts_mask &= ~pkt01_mask; \
759 : : \
760 : : mbuf01 = pkts[pkt01_index]; \
761 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, key_offset));\
762 : : }
763 : :
764 : : #define lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,\
765 : : mbuf00, mbuf01, pkts, pkts_mask, f) \
766 : : { \
767 : : uint64_t pkt00_mask, pkt01_mask; \
768 : : uint32_t key_offset = f->key_offset; \
769 : : \
770 : : pkt00_index = rte_ctz64(pkts_mask); \
771 : : pkt00_mask = 1LLU << pkt00_index; \
772 : : pkts_mask &= ~pkt00_mask; \
773 : : \
774 : : mbuf00 = pkts[pkt00_index]; \
775 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, key_offset)); \
776 : : \
777 : : pkt01_index = rte_ctz64(pkts_mask); \
778 : : if (pkts_mask == 0) \
779 : : pkt01_index = pkt00_index; \
780 : : pkt01_mask = 1LLU << pkt01_index; \
781 : : pkts_mask &= ~pkt01_mask; \
782 : : \
783 : : mbuf01 = pkts[pkt01_index]; \
784 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, key_offset)); \
785 : : }
786 : :
787 : : #define lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f) \
788 : : { \
789 : : uint64_t *key10, *key11; \
790 : : uint64_t signature10, signature11; \
791 : : uint32_t bucket10_index, bucket11_index; \
792 : : \
793 : : key10 = RTE_MBUF_METADATA_UINT64_PTR(mbuf10, f->key_offset);\
794 : : signature10 = f->f_hash(key10, f->key_mask, KEY_SIZE, f->seed);\
795 : : bucket10_index = signature10 & (f->n_buckets - 1); \
796 : : bucket10 = (struct rte_bucket_4_16 *) \
797 : : &f->memory[bucket10_index * f->bucket_size]; \
798 : : rte_prefetch0(bucket10); \
799 : : rte_prefetch0((void *)(((uintptr_t) bucket10) + RTE_CACHE_LINE_SIZE));\
800 : : \
801 : : key11 = RTE_MBUF_METADATA_UINT64_PTR(mbuf11, f->key_offset);\
802 : : signature11 = f->f_hash(key11, f->key_mask, KEY_SIZE, f->seed);\
803 : : bucket11_index = signature11 & (f->n_buckets - 1); \
804 : : bucket11 = (struct rte_bucket_4_16 *) \
805 : : &f->memory[bucket11_index * f->bucket_size]; \
806 : : rte_prefetch0(bucket11); \
807 : : rte_prefetch0((void *)(((uintptr_t) bucket11) + RTE_CACHE_LINE_SIZE));\
808 : : }
809 : :
810 : : #define lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,\
811 : : bucket20, bucket21, pkts_mask_out, entries, f) \
812 : : { \
813 : : void *a20, *a21; \
814 : : uint64_t pkt20_mask, pkt21_mask; \
815 : : uint64_t *key20, *key21; \
816 : : uint32_t pos20, pos21; \
817 : : \
818 : : key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
819 : : key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
820 : : \
821 : : lookup_key16_cmp(key20, bucket20, pos20, f); \
822 : : lookup_key16_cmp(key21, bucket21, pos21, f); \
823 : : \
824 : : pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
825 : : pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
826 : : pkts_mask_out |= pkt20_mask | pkt21_mask; \
827 : : \
828 : : a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
829 : : a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
830 : : rte_prefetch0(a20); \
831 : : rte_prefetch0(a21); \
832 : : entries[pkt20_index] = a20; \
833 : : entries[pkt21_index] = a21; \
834 : : lru_update(bucket20, pos20); \
835 : : lru_update(bucket21, pos21); \
836 : : }
837 : :
838 : : #define lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21, bucket20, \
839 : : bucket21, pkts_mask_out, entries, buckets_mask, buckets, keys, f) \
840 : : { \
841 : : struct rte_bucket_4_16 *bucket20_next, *bucket21_next; \
842 : : void *a20, *a21; \
843 : : uint64_t pkt20_mask, pkt21_mask, bucket20_mask, bucket21_mask;\
844 : : uint64_t *key20, *key21; \
845 : : uint32_t pos20, pos21; \
846 : : \
847 : : key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
848 : : key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
849 : : \
850 : : lookup_key16_cmp(key20, bucket20, pos20, f); \
851 : : lookup_key16_cmp(key21, bucket21, pos21, f); \
852 : : \
853 : : pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
854 : : pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
855 : : pkts_mask_out |= pkt20_mask | pkt21_mask; \
856 : : \
857 : : a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
858 : : a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
859 : : rte_prefetch0(a20); \
860 : : rte_prefetch0(a21); \
861 : : entries[pkt20_index] = a20; \
862 : : entries[pkt21_index] = a21; \
863 : : \
864 : : bucket20_mask = (~pkt20_mask) & (bucket20->next_valid << pkt20_index);\
865 : : bucket21_mask = (~pkt21_mask) & (bucket21->next_valid << pkt21_index);\
866 : : buckets_mask |= bucket20_mask | bucket21_mask; \
867 : : bucket20_next = bucket20->next; \
868 : : bucket21_next = bucket21->next; \
869 : : buckets[pkt20_index] = bucket20_next; \
870 : : buckets[pkt21_index] = bucket21_next; \
871 : : keys[pkt20_index] = key20; \
872 : : keys[pkt21_index] = key21; \
873 : : }
874 : :
875 : : static int
876 [ + + ]: 7 : rte_table_hash_lookup_key16_lru(
877 : : void *table,
878 : : struct rte_mbuf **pkts,
879 : : uint64_t pkts_mask,
880 : : uint64_t *lookup_hit_mask,
881 : : void **entries)
882 : : {
883 : : struct rte_table_hash *f = (struct rte_table_hash *) table;
884 : : struct rte_bucket_4_16 *bucket10, *bucket11, *bucket20, *bucket21;
885 : : struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
886 : : uint32_t pkt00_index, pkt01_index, pkt10_index;
887 : : uint32_t pkt11_index, pkt20_index, pkt21_index;
888 : : uint64_t pkts_mask_out = 0;
889 : :
890 : : __rte_unused uint32_t n_pkts_in = rte_popcount64(pkts_mask);
891 : :
892 : : RTE_TABLE_HASH_KEY16_STATS_PKTS_IN_ADD(f, n_pkts_in);
893 : :
894 : : /* Cannot run the pipeline with less than 5 packets */
895 [ + + ]: 7 : if (rte_popcount64(pkts_mask) < 5) {
896 [ + + ]: 4 : for ( ; pkts_mask; ) {
897 : : struct rte_bucket_4_16 *bucket;
898 : : struct rte_mbuf *mbuf;
899 : : uint32_t pkt_index;
900 : :
901 : 2 : lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask, f);
902 : 2 : lookup1_stage1(mbuf, bucket, f);
903 [ + + - + : 3 : lookup1_stage2_lru(pkt_index, mbuf, bucket,
- + - + ]
904 : : pkts_mask_out, entries, f);
905 : : }
906 : :
907 : 2 : *lookup_hit_mask = pkts_mask_out;
908 : : RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in -
909 : : rte_popcount64(pkts_mask_out));
910 : 2 : return 0;
911 : : }
912 : :
913 : : /*
914 : : * Pipeline fill
915 : : *
916 : : */
917 : : /* Pipeline stage 0 */
918 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
919 : : pkts_mask, f);
920 : :
921 : : /* Pipeline feed */
922 : : mbuf10 = mbuf00;
923 : : mbuf11 = mbuf01;
924 : : pkt10_index = pkt00_index;
925 : : pkt11_index = pkt01_index;
926 : :
927 : : /* Pipeline stage 0 */
928 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
929 : : pkts_mask, f);
930 : :
931 : : /* Pipeline stage 1 */
932 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
933 : :
934 : : /*
935 : : * Pipeline run
936 : : *
937 : : */
938 [ + + ]: 127 : for ( ; pkts_mask; ) {
939 : : /* Pipeline feed */
940 : : bucket20 = bucket10;
941 : : bucket21 = bucket11;
942 : : mbuf20 = mbuf10;
943 : : mbuf21 = mbuf11;
944 : : mbuf10 = mbuf00;
945 : : mbuf11 = mbuf01;
946 : : pkt20_index = pkt10_index;
947 : : pkt21_index = pkt11_index;
948 : : pkt10_index = pkt00_index;
949 : : pkt11_index = pkt01_index;
950 : :
951 : : /* Pipeline stage 0 */
952 [ - + ]: 122 : lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
953 : : mbuf00, mbuf01, pkts, pkts_mask, f);
954 : :
955 : : /* Pipeline stage 1 */
956 : 122 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
957 : :
958 : : /* Pipeline stage 2 */
959 [ + + - + : 391 : lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
960 : : bucket20, bucket21, pkts_mask_out, entries, f);
961 : : }
962 : :
963 : : /*
964 : : * Pipeline flush
965 : : *
966 : : */
967 : : /* Pipeline feed */
968 : : bucket20 = bucket10;
969 : : bucket21 = bucket11;
970 : : mbuf20 = mbuf10;
971 : : mbuf21 = mbuf11;
972 : : mbuf10 = mbuf00;
973 : : mbuf11 = mbuf01;
974 : : pkt20_index = pkt10_index;
975 : : pkt21_index = pkt11_index;
976 : : pkt10_index = pkt00_index;
977 : : pkt11_index = pkt01_index;
978 : :
979 : : /* Pipeline stage 1 */
980 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
981 : :
982 : : /* Pipeline stage 2 */
983 [ + + - + : 15 : lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + + + ]
984 : : bucket20, bucket21, pkts_mask_out, entries, f);
985 : :
986 : : /* Pipeline feed */
987 : : bucket20 = bucket10;
988 : : bucket21 = bucket11;
989 : : mbuf20 = mbuf10;
990 : : mbuf21 = mbuf11;
991 : : pkt20_index = pkt10_index;
992 : : pkt21_index = pkt11_index;
993 : :
994 : : /* Pipeline stage 2 */
995 [ + + - + : 15 : lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
996 : : bucket20, bucket21, pkts_mask_out, entries, f);
997 : :
998 : 5 : *lookup_hit_mask = pkts_mask_out;
999 : : RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in -
1000 : : rte_popcount64(pkts_mask_out));
1001 : 5 : return 0;
1002 : : } /* lookup LRU */
1003 : :
1004 : : static int
1005 [ + + ]: 7 : rte_table_hash_lookup_key16_ext(
1006 : : void *table,
1007 : : struct rte_mbuf **pkts,
1008 : : uint64_t pkts_mask,
1009 : : uint64_t *lookup_hit_mask,
1010 : : void **entries)
1011 : : {
1012 : : struct rte_table_hash *f = (struct rte_table_hash *) table;
1013 : : struct rte_bucket_4_16 *bucket10, *bucket11, *bucket20, *bucket21;
1014 : : struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
1015 : : uint32_t pkt00_index, pkt01_index, pkt10_index;
1016 : : uint32_t pkt11_index, pkt20_index, pkt21_index;
1017 : : uint64_t pkts_mask_out = 0, buckets_mask = 0;
1018 : : struct rte_bucket_4_16 *buckets[RTE_PORT_IN_BURST_SIZE_MAX];
1019 : : uint64_t *keys[RTE_PORT_IN_BURST_SIZE_MAX];
1020 : :
1021 : : __rte_unused uint32_t n_pkts_in = rte_popcount64(pkts_mask);
1022 : :
1023 : : RTE_TABLE_HASH_KEY16_STATS_PKTS_IN_ADD(f, n_pkts_in);
1024 : :
1025 : : /* Cannot run the pipeline with less than 5 packets */
1026 [ + + ]: 7 : if (rte_popcount64(pkts_mask) < 5) {
1027 [ + + ]: 4 : for ( ; pkts_mask; ) {
1028 : : struct rte_bucket_4_16 *bucket;
1029 : : struct rte_mbuf *mbuf;
1030 : : uint32_t pkt_index;
1031 : :
1032 : 2 : lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask, f);
1033 : 2 : lookup1_stage1(mbuf, bucket, f);
1034 [ + + - + : 3 : lookup1_stage2_ext(pkt_index, mbuf, bucket,
- + - + ]
1035 : : pkts_mask_out, entries, buckets_mask,
1036 : : buckets, keys, f);
1037 : : }
1038 : :
1039 : 2 : goto grind_next_buckets;
1040 : : }
1041 : :
1042 : : /*
1043 : : * Pipeline fill
1044 : : *
1045 : : */
1046 : : /* Pipeline stage 0 */
1047 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1048 : : pkts_mask, f);
1049 : :
1050 : : /* Pipeline feed */
1051 : : mbuf10 = mbuf00;
1052 : : mbuf11 = mbuf01;
1053 : : pkt10_index = pkt00_index;
1054 : : pkt11_index = pkt01_index;
1055 : :
1056 : : /* Pipeline stage 0 */
1057 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1058 : : pkts_mask, f);
1059 : :
1060 : : /* Pipeline stage 1 */
1061 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1062 : :
1063 : : /*
1064 : : * Pipeline run
1065 : : *
1066 : : */
1067 [ + + ]: 127 : for ( ; pkts_mask; ) {
1068 : : /* Pipeline feed */
1069 : : bucket20 = bucket10;
1070 : : bucket21 = bucket11;
1071 : : mbuf20 = mbuf10;
1072 : : mbuf21 = mbuf11;
1073 : : mbuf10 = mbuf00;
1074 : : mbuf11 = mbuf01;
1075 : : pkt20_index = pkt10_index;
1076 : : pkt21_index = pkt11_index;
1077 : : pkt10_index = pkt00_index;
1078 : : pkt11_index = pkt01_index;
1079 : :
1080 : : /* Pipeline stage 0 */
1081 [ - + ]: 122 : lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1082 : : mbuf00, mbuf01, pkts, pkts_mask, f);
1083 : :
1084 : : /* Pipeline stage 1 */
1085 : 122 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1086 : :
1087 : : /* Pipeline stage 2 */
1088 [ + + - + : 391 : lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
1089 : : bucket20, bucket21, pkts_mask_out, entries,
1090 : : buckets_mask, buckets, keys, f);
1091 : : }
1092 : :
1093 : : /*
1094 : : * Pipeline flush
1095 : : *
1096 : : */
1097 : : /* Pipeline feed */
1098 : : bucket20 = bucket10;
1099 : : bucket21 = bucket11;
1100 : : mbuf20 = mbuf10;
1101 : : mbuf21 = mbuf11;
1102 : : mbuf10 = mbuf00;
1103 : : mbuf11 = mbuf01;
1104 : : pkt20_index = pkt10_index;
1105 : : pkt21_index = pkt11_index;
1106 : : pkt10_index = pkt00_index;
1107 : : pkt11_index = pkt01_index;
1108 : :
1109 : : /* Pipeline stage 1 */
1110 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1111 : :
1112 : : /* Pipeline stage 2 */
1113 [ + + - + : 10 : lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
1114 : : bucket20, bucket21, pkts_mask_out, entries,
1115 : : buckets_mask, buckets, keys, f);
1116 : :
1117 : : /* Pipeline feed */
1118 : : bucket20 = bucket10;
1119 : : bucket21 = bucket11;
1120 : : mbuf20 = mbuf10;
1121 : : mbuf21 = mbuf11;
1122 : : pkt20_index = pkt10_index;
1123 : : pkt21_index = pkt11_index;
1124 : :
1125 : : /* Pipeline stage 2 */
1126 [ + + - + : 15 : lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
1127 : : bucket20, bucket21, pkts_mask_out, entries,
1128 : : buckets_mask, buckets, keys, f);
1129 : :
1130 : : grind_next_buckets:
1131 : : /* Grind next buckets */
1132 [ - + ]: 7 : for ( ; buckets_mask; ) {
1133 : : uint64_t buckets_mask_next = 0;
1134 : :
1135 [ # # ]: 0 : for ( ; buckets_mask; ) {
1136 : : uint64_t pkt_mask;
1137 : : uint32_t pkt_index;
1138 : :
1139 : : pkt_index = rte_ctz64(buckets_mask);
1140 : 0 : pkt_mask = 1LLU << pkt_index;
1141 : 0 : buckets_mask &= ~pkt_mask;
1142 : :
1143 [ # # # # : 0 : lookup_grinder(pkt_index, buckets, keys, pkts_mask_out,
# # # # ]
1144 : : entries, buckets_mask_next, f);
1145 : : }
1146 : :
1147 : : buckets_mask = buckets_mask_next;
1148 : : }
1149 : :
1150 : 7 : *lookup_hit_mask = pkts_mask_out;
1151 : : RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in -
1152 : : rte_popcount64(pkts_mask_out));
1153 : 7 : return 0;
1154 : : } /* lookup EXT */
1155 : :
1156 : : static int
1157 : 0 : rte_table_hash_key16_stats_read(void *table, struct rte_table_stats *stats, int clear)
1158 : : {
1159 : : struct rte_table_hash *t = table;
1160 : :
1161 [ # # ]: 0 : if (stats != NULL)
1162 : 0 : memcpy(stats, &t->stats, sizeof(t->stats));
1163 : :
1164 [ # # ]: 0 : if (clear)
1165 : 0 : memset(&t->stats, 0, sizeof(t->stats));
1166 : :
1167 : 0 : return 0;
1168 : : }
1169 : :
1170 : : RTE_EXPORT_SYMBOL(rte_table_hash_key16_lru_ops)
1171 : : struct rte_table_ops rte_table_hash_key16_lru_ops = {
1172 : : .f_create = rte_table_hash_create_key16_lru,
1173 : : .f_free = rte_table_hash_free_key16_lru,
1174 : : .f_add = rte_table_hash_entry_add_key16_lru,
1175 : : .f_delete = rte_table_hash_entry_delete_key16_lru,
1176 : : .f_add_bulk = NULL,
1177 : : .f_delete_bulk = NULL,
1178 : : .f_lookup = rte_table_hash_lookup_key16_lru,
1179 : : .f_stats = rte_table_hash_key16_stats_read,
1180 : : };
1181 : :
1182 : : RTE_EXPORT_SYMBOL(rte_table_hash_key16_ext_ops)
1183 : : struct rte_table_ops rte_table_hash_key16_ext_ops = {
1184 : : .f_create = rte_table_hash_create_key16_ext,
1185 : : .f_free = rte_table_hash_free_key16_ext,
1186 : : .f_add = rte_table_hash_entry_add_key16_ext,
1187 : : .f_delete = rte_table_hash_entry_delete_key16_ext,
1188 : : .f_add_bulk = NULL,
1189 : : .f_delete_bulk = NULL,
1190 : : .f_lookup = rte_table_hash_lookup_key16_ext,
1191 : : .f_stats = rte_table_hash_key16_stats_read,
1192 : : };
|