4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
36 #include <rte_common.h>
38 #include <rte_malloc.h>
41 #include "rte_table_hash.h"
44 #define RTE_TABLE_HASH_KEY_SIZE 16
46 #define RTE_BUCKET_ENTRY_VALID 0x1LLU
48 struct rte_bucket_4_16 {
50 uint64_t signature[4 + 1];
52 struct rte_bucket_4_16 *next;
62 struct rte_table_hash {
63 /* Input parameters */
65 uint32_t n_entries_per_bucket;
69 uint32_t signature_offset;
71 rte_table_hash_op_hash f_hash;
74 /* Extendible buckets */
75 uint32_t n_buckets_ext;
80 uint8_t memory[0] __rte_cache_aligned;
84 check_params_create_lru(struct rte_table_hash_key16_lru_params *params) {
86 if (params->n_entries == 0) {
87 RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
91 /* signature offset */
92 if ((params->signature_offset & 0x3) != 0) {
93 RTE_LOG(ERR, TABLE, "%s: invalid signature_offset\n", __func__);
98 if ((params->key_offset & 0x7) != 0) {
99 RTE_LOG(ERR, TABLE, "%s: invalid key_offset\n", __func__);
104 if (params->f_hash == NULL) {
106 "%s: f_hash function pointer is NULL\n", __func__);
114 rte_table_hash_create_key16_lru(void *params,
118 struct rte_table_hash_key16_lru_params *p =
119 (struct rte_table_hash_key16_lru_params *) params;
120 struct rte_table_hash *f;
121 uint32_t n_buckets, n_entries_per_bucket,
122 key_size, bucket_size_cl, total_size, i;
124 /* Check input parameters */
125 if ((check_params_create_lru(p) != 0) ||
126 ((sizeof(struct rte_table_hash) % CACHE_LINE_SIZE) != 0) ||
127 ((sizeof(struct rte_bucket_4_16) % CACHE_LINE_SIZE) != 0))
129 n_entries_per_bucket = 4;
132 /* Memory allocation */
133 n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
134 n_entries_per_bucket);
135 bucket_size_cl = (sizeof(struct rte_bucket_4_16) + n_entries_per_bucket
136 * entry_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
137 total_size = sizeof(struct rte_table_hash) + n_buckets *
138 bucket_size_cl * CACHE_LINE_SIZE;
140 f = rte_zmalloc_socket("TABLE", total_size, CACHE_LINE_SIZE, socket_id);
143 "%s: Cannot allocate %u bytes for hash table\n",
144 __func__, total_size);
148 "%s: Hash table memory footprint is %u bytes\n",
149 __func__, total_size);
151 /* Memory initialization */
152 f->n_buckets = n_buckets;
153 f->n_entries_per_bucket = n_entries_per_bucket;
154 f->key_size = key_size;
155 f->entry_size = entry_size;
156 f->bucket_size = bucket_size_cl * CACHE_LINE_SIZE;
157 f->signature_offset = p->signature_offset;
158 f->key_offset = p->key_offset;
159 f->f_hash = p->f_hash;
162 for (i = 0; i < n_buckets; i++) {
163 struct rte_bucket_4_16 *bucket;
165 bucket = (struct rte_bucket_4_16 *) &f->memory[i *
174 rte_table_hash_free_key16_lru(void *table)
176 struct rte_table_hash *f = (struct rte_table_hash *) table;
178 /* Check input parameters */
180 RTE_LOG(ERR, TABLE, "%s: table parameter is NULL\n", __func__);
189 rte_table_hash_entry_add_key16_lru(
196 struct rte_table_hash *f = (struct rte_table_hash *) table;
197 struct rte_bucket_4_16 *bucket;
198 uint64_t signature, pos;
199 uint32_t bucket_index, i;
201 signature = f->f_hash(key, f->key_size, f->seed);
202 bucket_index = signature & (f->n_buckets - 1);
203 bucket = (struct rte_bucket_4_16 *)
204 &f->memory[bucket_index * f->bucket_size];
205 signature |= RTE_BUCKET_ENTRY_VALID;
207 /* Key is present in the bucket */
208 for (i = 0; i < 4; i++) {
209 uint64_t bucket_signature = bucket->signature[i];
210 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
212 if ((bucket_signature == signature) &&
213 (memcmp(key, bucket_key, f->key_size) == 0)) {
214 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
216 memcpy(bucket_data, entry, f->entry_size);
217 lru_update(bucket, i);
219 *entry_ptr = (void *) bucket_data;
224 /* Key is not present in the bucket */
225 for (i = 0; i < 4; i++) {
226 uint64_t bucket_signature = bucket->signature[i];
227 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
229 if (bucket_signature == 0) {
230 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
232 bucket->signature[i] = signature;
233 memcpy(bucket_key, key, f->key_size);
234 memcpy(bucket_data, entry, f->entry_size);
235 lru_update(bucket, i);
237 *entry_ptr = (void *) bucket_data;
243 /* Bucket full: replace LRU entry */
244 pos = lru_pos(bucket);
245 bucket->signature[pos] = signature;
246 memcpy(bucket->key[pos], key, f->key_size);
247 memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
248 lru_update(bucket, pos);
250 *entry_ptr = (void *) &bucket->data[pos * f->entry_size];
256 rte_table_hash_entry_delete_key16_lru(
262 struct rte_table_hash *f = (struct rte_table_hash *) table;
263 struct rte_bucket_4_16 *bucket;
265 uint32_t bucket_index, i;
267 signature = f->f_hash(key, f->key_size, f->seed);
268 bucket_index = signature & (f->n_buckets - 1);
269 bucket = (struct rte_bucket_4_16 *)
270 &f->memory[bucket_index * f->bucket_size];
271 signature |= RTE_BUCKET_ENTRY_VALID;
273 /* Key is present in the bucket */
274 for (i = 0; i < 4; i++) {
275 uint64_t bucket_signature = bucket->signature[i];
276 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
278 if ((bucket_signature == signature) &&
279 (memcmp(key, bucket_key, f->key_size) == 0)) {
280 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
282 bucket->signature[i] = 0;
285 memcpy(entry, bucket_data, f->entry_size);
290 /* Key is not present in the bucket */
296 check_params_create_ext(struct rte_table_hash_key16_ext_params *params) {
298 if (params->n_entries == 0) {
299 RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
304 if (params->n_entries_ext == 0) {
305 RTE_LOG(ERR, TABLE, "%s: n_entries_ext is zero\n", __func__);
309 /* signature offset */
310 if ((params->signature_offset & 0x3) != 0) {
311 RTE_LOG(ERR, TABLE, "%s: invalid signature offset\n", __func__);
316 if ((params->key_offset & 0x7) != 0) {
317 RTE_LOG(ERR, TABLE, "%s: invalid key offset\n", __func__);
322 if (params->f_hash == NULL) {
324 "%s: f_hash function pointer is NULL\n", __func__);
332 rte_table_hash_create_key16_ext(void *params,
336 struct rte_table_hash_key16_ext_params *p =
337 (struct rte_table_hash_key16_ext_params *) params;
338 struct rte_table_hash *f;
339 uint32_t n_buckets, n_buckets_ext, n_entries_per_bucket, key_size,
340 bucket_size_cl, stack_size_cl, total_size, i;
342 /* Check input parameters */
343 if ((check_params_create_ext(p) != 0) ||
344 ((sizeof(struct rte_table_hash) % CACHE_LINE_SIZE) != 0) ||
345 ((sizeof(struct rte_bucket_4_16) % CACHE_LINE_SIZE) != 0))
348 n_entries_per_bucket = 4;
351 /* Memory allocation */
352 n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
353 n_entries_per_bucket);
354 n_buckets_ext = (p->n_entries_ext + n_entries_per_bucket - 1) /
355 n_entries_per_bucket;
356 bucket_size_cl = (sizeof(struct rte_bucket_4_16) + n_entries_per_bucket
357 * entry_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
358 stack_size_cl = (n_buckets_ext * sizeof(uint32_t) + CACHE_LINE_SIZE - 1)
360 total_size = sizeof(struct rte_table_hash) +
361 ((n_buckets + n_buckets_ext) * bucket_size_cl + stack_size_cl) *
364 f = rte_zmalloc_socket("TABLE", total_size, CACHE_LINE_SIZE, socket_id);
367 "%s: Cannot allocate %u bytes for hash table\n",
368 __func__, total_size);
372 "%s: Hash table memory footprint is %u bytes\n",
373 __func__, total_size);
375 /* Memory initialization */
376 f->n_buckets = n_buckets;
377 f->n_entries_per_bucket = n_entries_per_bucket;
378 f->key_size = key_size;
379 f->entry_size = entry_size;
380 f->bucket_size = bucket_size_cl * CACHE_LINE_SIZE;
381 f->signature_offset = p->signature_offset;
382 f->key_offset = p->key_offset;
383 f->f_hash = p->f_hash;
386 f->n_buckets_ext = n_buckets_ext;
387 f->stack_pos = n_buckets_ext;
388 f->stack = (uint32_t *)
389 &f->memory[(n_buckets + n_buckets_ext) * f->bucket_size];
391 for (i = 0; i < n_buckets_ext; i++)
398 rte_table_hash_free_key16_ext(void *table)
400 struct rte_table_hash *f = (struct rte_table_hash *) table;
402 /* Check input parameters */
404 RTE_LOG(ERR, TABLE, "%s: table parameter is NULL\n", __func__);
413 rte_table_hash_entry_add_key16_ext(
420 struct rte_table_hash *f = (struct rte_table_hash *) table;
421 struct rte_bucket_4_16 *bucket0, *bucket, *bucket_prev;
423 uint32_t bucket_index, i;
425 signature = f->f_hash(key, f->key_size, f->seed);
426 bucket_index = signature & (f->n_buckets - 1);
427 bucket0 = (struct rte_bucket_4_16 *)
428 &f->memory[bucket_index * f->bucket_size];
429 signature |= RTE_BUCKET_ENTRY_VALID;
431 /* Key is present in the bucket */
432 for (bucket = bucket0; bucket != NULL; bucket = bucket->next)
433 for (i = 0; i < 4; i++) {
434 uint64_t bucket_signature = bucket->signature[i];
435 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
437 if ((bucket_signature == signature) &&
438 (memcmp(key, bucket_key, f->key_size) == 0)) {
439 uint8_t *bucket_data = &bucket->data[i *
442 memcpy(bucket_data, entry, f->entry_size);
444 *entry_ptr = (void *) bucket_data;
449 /* Key is not present in the bucket */
450 for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
451 bucket_prev = bucket, bucket = bucket->next)
452 for (i = 0; i < 4; i++) {
453 uint64_t bucket_signature = bucket->signature[i];
454 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
456 if (bucket_signature == 0) {
457 uint8_t *bucket_data = &bucket->data[i *
460 bucket->signature[i] = signature;
461 memcpy(bucket_key, key, f->key_size);
462 memcpy(bucket_data, entry, f->entry_size);
464 *entry_ptr = (void *) bucket_data;
470 /* Bucket full: extend bucket */
471 if (f->stack_pos > 0) {
472 bucket_index = f->stack[--f->stack_pos];
474 bucket = (struct rte_bucket_4_16 *) &f->memory[(f->n_buckets +
475 bucket_index) * f->bucket_size];
476 bucket_prev->next = bucket;
477 bucket_prev->next_valid = 1;
479 bucket->signature[0] = signature;
480 memcpy(bucket->key[0], key, f->key_size);
481 memcpy(&bucket->data[0], entry, f->entry_size);
483 *entry_ptr = (void *) &bucket->data[0];
491 rte_table_hash_entry_delete_key16_ext(
497 struct rte_table_hash *f = (struct rte_table_hash *) table;
498 struct rte_bucket_4_16 *bucket0, *bucket, *bucket_prev;
500 uint32_t bucket_index, i;
502 signature = f->f_hash(key, f->key_size, f->seed);
503 bucket_index = signature & (f->n_buckets - 1);
504 bucket0 = (struct rte_bucket_4_16 *)
505 &f->memory[bucket_index * f->bucket_size];
506 signature |= RTE_BUCKET_ENTRY_VALID;
508 /* Key is present in the bucket */
509 for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
510 bucket_prev = bucket, bucket = bucket->next)
511 for (i = 0; i < 4; i++) {
512 uint64_t bucket_signature = bucket->signature[i];
513 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
515 if ((bucket_signature == signature) &&
516 (memcmp(key, bucket_key, f->key_size) == 0)) {
517 uint8_t *bucket_data = &bucket->data[i *
520 bucket->signature[i] = 0;
523 memcpy(entry, bucket_data,
526 if ((bucket->signature[0] == 0) &&
527 (bucket->signature[1] == 0) &&
528 (bucket->signature[2] == 0) &&
529 (bucket->signature[3] == 0) &&
530 (bucket_prev != NULL)) {
531 bucket_prev->next = bucket->next;
532 bucket_prev->next_valid =
536 sizeof(struct rte_bucket_4_16));
537 bucket_index = (bucket -
538 ((struct rte_bucket_4_16 *)
539 f->memory)) - f->n_buckets;
540 f->stack[f->stack_pos++] = bucket_index;
547 /* Key is not present in the bucket */
552 #define lookup_key16_cmp(key_in, bucket, pos) \
554 uint64_t xor[4][2], or[4], signature[4]; \
556 signature[0] = (~bucket->signature[0]) & 1; \
557 signature[1] = (~bucket->signature[1]) & 1; \
558 signature[2] = (~bucket->signature[2]) & 1; \
559 signature[3] = (~bucket->signature[3]) & 1; \
561 xor[0][0] = key_in[0] ^ bucket->key[0][0]; \
562 xor[0][1] = key_in[1] ^ bucket->key[0][1]; \
564 xor[1][0] = key_in[0] ^ bucket->key[1][0]; \
565 xor[1][1] = key_in[1] ^ bucket->key[1][1]; \
567 xor[2][0] = key_in[0] ^ bucket->key[2][0]; \
568 xor[2][1] = key_in[1] ^ bucket->key[2][1]; \
570 xor[3][0] = key_in[0] ^ bucket->key[3][0]; \
571 xor[3][1] = key_in[1] ^ bucket->key[3][1]; \
573 or[0] = xor[0][0] | xor[0][1] | signature[0]; \
574 or[1] = xor[1][0] | xor[1][1] | signature[1]; \
575 or[2] = xor[2][0] | xor[2][1] | signature[2]; \
576 or[3] = xor[3][0] | xor[3][1] | signature[3]; \
589 #define lookup1_stage0(pkt0_index, mbuf0, pkts, pkts_mask) \
593 pkt0_index = __builtin_ctzll(pkts_mask); \
594 pkt_mask = 1LLU << pkt0_index; \
595 pkts_mask &= ~pkt_mask; \
597 mbuf0 = pkts[pkt0_index]; \
598 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf0, 0)); \
601 #define lookup1_stage1(mbuf1, bucket1, f) \
603 uint64_t signature; \
604 uint32_t bucket_index; \
606 signature = RTE_MBUF_METADATA_UINT32(mbuf1, f->signature_offset);\
607 bucket_index = signature & (f->n_buckets - 1); \
608 bucket1 = (struct rte_bucket_4_16 *) \
609 &f->memory[bucket_index * f->bucket_size]; \
610 rte_prefetch0(bucket1); \
611 rte_prefetch0((void *)(((uintptr_t) bucket1) + CACHE_LINE_SIZE));\
614 #define lookup1_stage2_lru(pkt2_index, mbuf2, bucket2, \
615 pkts_mask_out, entries, f) \
622 key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
624 lookup_key16_cmp(key, bucket2, pos); \
626 pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
627 pkts_mask_out |= pkt_mask; \
629 a = (void *) &bucket2->data[pos * f->entry_size]; \
631 entries[pkt2_index] = a; \
632 lru_update(bucket2, pos); \
635 #define lookup1_stage2_ext(pkt2_index, mbuf2, bucket2, pkts_mask_out, entries, \
636 buckets_mask, buckets, keys, f) \
638 struct rte_bucket_4_16 *bucket_next; \
640 uint64_t pkt_mask, bucket_mask; \
644 key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
646 lookup_key16_cmp(key, bucket2, pos); \
648 pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
649 pkts_mask_out |= pkt_mask; \
651 a = (void *) &bucket2->data[pos * f->entry_size]; \
653 entries[pkt2_index] = a; \
655 bucket_mask = (~pkt_mask) & (bucket2->next_valid << pkt2_index);\
656 buckets_mask |= bucket_mask; \
657 bucket_next = bucket2->next; \
658 buckets[pkt2_index] = bucket_next; \
659 keys[pkt2_index] = key; \
662 #define lookup_grinder(pkt_index, buckets, keys, pkts_mask_out, entries,\
665 struct rte_bucket_4_16 *bucket, *bucket_next; \
667 uint64_t pkt_mask, bucket_mask; \
671 bucket = buckets[pkt_index]; \
672 key = keys[pkt_index]; \
674 lookup_key16_cmp(key, bucket, pos); \
676 pkt_mask = (bucket->signature[pos] & 1LLU) << pkt_index;\
677 pkts_mask_out |= pkt_mask; \
679 a = (void *) &bucket->data[pos * f->entry_size]; \
681 entries[pkt_index] = a; \
683 bucket_mask = (~pkt_mask) & (bucket->next_valid << pkt_index);\
684 buckets_mask |= bucket_mask; \
685 bucket_next = bucket->next; \
686 rte_prefetch0(bucket_next); \
687 rte_prefetch0((void *)(((uintptr_t) bucket_next) + CACHE_LINE_SIZE));\
688 buckets[pkt_index] = bucket_next; \
689 keys[pkt_index] = key; \
692 #define lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01,\
695 uint64_t pkt00_mask, pkt01_mask; \
697 pkt00_index = __builtin_ctzll(pkts_mask); \
698 pkt00_mask = 1LLU << pkt00_index; \
699 pkts_mask &= ~pkt00_mask; \
701 mbuf00 = pkts[pkt00_index]; \
702 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, 0)); \
704 pkt01_index = __builtin_ctzll(pkts_mask); \
705 pkt01_mask = 1LLU << pkt01_index; \
706 pkts_mask &= ~pkt01_mask; \
708 mbuf01 = pkts[pkt01_index]; \
709 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, 0)); \
712 #define lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,\
713 mbuf00, mbuf01, pkts, pkts_mask) \
715 uint64_t pkt00_mask, pkt01_mask; \
717 pkt00_index = __builtin_ctzll(pkts_mask); \
718 pkt00_mask = 1LLU << pkt00_index; \
719 pkts_mask &= ~pkt00_mask; \
721 mbuf00 = pkts[pkt00_index]; \
722 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, 0)); \
724 pkt01_index = __builtin_ctzll(pkts_mask); \
725 if (pkts_mask == 0) \
726 pkt01_index = pkt00_index; \
727 pkt01_mask = 1LLU << pkt01_index; \
728 pkts_mask &= ~pkt01_mask; \
730 mbuf01 = pkts[pkt01_index]; \
731 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, 0)); \
734 #define lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f) \
736 uint64_t signature10, signature11; \
737 uint32_t bucket10_index, bucket11_index; \
739 signature10 = RTE_MBUF_METADATA_UINT32(mbuf10, f->signature_offset);\
740 bucket10_index = signature10 & (f->n_buckets - 1); \
741 bucket10 = (struct rte_bucket_4_16 *) \
742 &f->memory[bucket10_index * f->bucket_size]; \
743 rte_prefetch0(bucket10); \
744 rte_prefetch0((void *)(((uintptr_t) bucket10) + CACHE_LINE_SIZE));\
746 signature11 = RTE_MBUF_METADATA_UINT32(mbuf11, f->signature_offset);\
747 bucket11_index = signature11 & (f->n_buckets - 1); \
748 bucket11 = (struct rte_bucket_4_16 *) \
749 &f->memory[bucket11_index * f->bucket_size]; \
750 rte_prefetch0(bucket11); \
751 rte_prefetch0((void *)(((uintptr_t) bucket11) + CACHE_LINE_SIZE));\
754 #define lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,\
755 bucket20, bucket21, pkts_mask_out, entries, f) \
758 uint64_t pkt20_mask, pkt21_mask; \
759 uint64_t *key20, *key21; \
760 uint32_t pos20, pos21; \
762 key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
763 key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
765 lookup_key16_cmp(key20, bucket20, pos20); \
766 lookup_key16_cmp(key21, bucket21, pos21); \
768 pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
769 pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
770 pkts_mask_out |= pkt20_mask | pkt21_mask; \
772 a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
773 a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
774 rte_prefetch0(a20); \
775 rte_prefetch0(a21); \
776 entries[pkt20_index] = a20; \
777 entries[pkt21_index] = a21; \
778 lru_update(bucket20, pos20); \
779 lru_update(bucket21, pos21); \
782 #define lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21, bucket20, \
783 bucket21, pkts_mask_out, entries, buckets_mask, buckets, keys, f) \
785 struct rte_bucket_4_16 *bucket20_next, *bucket21_next; \
787 uint64_t pkt20_mask, pkt21_mask, bucket20_mask, bucket21_mask;\
788 uint64_t *key20, *key21; \
789 uint32_t pos20, pos21; \
791 key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
792 key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
794 lookup_key16_cmp(key20, bucket20, pos20); \
795 lookup_key16_cmp(key21, bucket21, pos21); \
797 pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
798 pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
799 pkts_mask_out |= pkt20_mask | pkt21_mask; \
801 a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
802 a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
803 rte_prefetch0(a20); \
804 rte_prefetch0(a21); \
805 entries[pkt20_index] = a20; \
806 entries[pkt21_index] = a21; \
808 bucket20_mask = (~pkt20_mask) & (bucket20->next_valid << pkt20_index);\
809 bucket21_mask = (~pkt21_mask) & (bucket21->next_valid << pkt21_index);\
810 buckets_mask |= bucket20_mask | bucket21_mask; \
811 bucket20_next = bucket20->next; \
812 bucket21_next = bucket21->next; \
813 buckets[pkt20_index] = bucket20_next; \
814 buckets[pkt21_index] = bucket21_next; \
815 keys[pkt20_index] = key20; \
816 keys[pkt21_index] = key21; \
820 rte_table_hash_lookup_key16_lru(
822 struct rte_mbuf **pkts,
824 uint64_t *lookup_hit_mask,
827 struct rte_table_hash *f = (struct rte_table_hash *) table;
828 struct rte_bucket_4_16 *bucket10, *bucket11, *bucket20, *bucket21;
829 struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
830 uint32_t pkt00_index, pkt01_index, pkt10_index;
831 uint32_t pkt11_index, pkt20_index, pkt21_index;
832 uint64_t pkts_mask_out = 0;
834 /* Cannot run the pipeline with less than 5 packets */
835 if (__builtin_popcountll(pkts_mask) < 5) {
836 for ( ; pkts_mask; ) {
837 struct rte_bucket_4_16 *bucket;
838 struct rte_mbuf *mbuf;
841 lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask);
842 lookup1_stage1(mbuf, bucket, f);
843 lookup1_stage2_lru(pkt_index, mbuf, bucket,
844 pkts_mask_out, entries, f);
847 *lookup_hit_mask = pkts_mask_out;
855 /* Pipeline stage 0 */
856 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
862 pkt10_index = pkt00_index;
863 pkt11_index = pkt01_index;
865 /* Pipeline stage 0 */
866 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
869 /* Pipeline stage 1 */
870 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
876 for ( ; pkts_mask; ) {
884 pkt20_index = pkt10_index;
885 pkt21_index = pkt11_index;
886 pkt10_index = pkt00_index;
887 pkt11_index = pkt01_index;
889 /* Pipeline stage 0 */
890 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
891 mbuf00, mbuf01, pkts, pkts_mask);
893 /* Pipeline stage 1 */
894 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
896 /* Pipeline stage 2 */
897 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
898 bucket20, bucket21, pkts_mask_out, entries, f);
912 pkt20_index = pkt10_index;
913 pkt21_index = pkt11_index;
914 pkt10_index = pkt00_index;
915 pkt11_index = pkt01_index;
917 /* Pipeline stage 1 */
918 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
920 /* Pipeline stage 2 */
921 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
922 bucket20, bucket21, pkts_mask_out, entries, f);
929 pkt20_index = pkt10_index;
930 pkt21_index = pkt11_index;
932 /* Pipeline stage 2 */
933 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
934 bucket20, bucket21, pkts_mask_out, entries, f);
936 *lookup_hit_mask = pkts_mask_out;
938 } /* rte_table_hash_lookup_key16_lru() */
941 rte_table_hash_lookup_key16_ext(
943 struct rte_mbuf **pkts,
945 uint64_t *lookup_hit_mask,
948 struct rte_table_hash *f = (struct rte_table_hash *) table;
949 struct rte_bucket_4_16 *bucket10, *bucket11, *bucket20, *bucket21;
950 struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
951 uint32_t pkt00_index, pkt01_index, pkt10_index;
952 uint32_t pkt11_index, pkt20_index, pkt21_index;
953 uint64_t pkts_mask_out = 0, buckets_mask = 0;
954 struct rte_bucket_4_16 *buckets[RTE_PORT_IN_BURST_SIZE_MAX];
955 uint64_t *keys[RTE_PORT_IN_BURST_SIZE_MAX];
957 /* Cannot run the pipeline with less than 5 packets */
958 if (__builtin_popcountll(pkts_mask) < 5) {
959 for ( ; pkts_mask; ) {
960 struct rte_bucket_4_16 *bucket;
961 struct rte_mbuf *mbuf;
964 lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask);
965 lookup1_stage1(mbuf, bucket, f);
966 lookup1_stage2_ext(pkt_index, mbuf, bucket,
967 pkts_mask_out, entries, buckets_mask,
971 *lookup_hit_mask = pkts_mask_out;
979 /* Pipeline stage 0 */
980 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
986 pkt10_index = pkt00_index;
987 pkt11_index = pkt01_index;
989 /* Pipeline stage 0 */
990 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
993 /* Pipeline stage 1 */
994 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1000 for ( ; pkts_mask; ) {
1002 bucket20 = bucket10;
1003 bucket21 = bucket11;
1008 pkt20_index = pkt10_index;
1009 pkt21_index = pkt11_index;
1010 pkt10_index = pkt00_index;
1011 pkt11_index = pkt01_index;
1013 /* Pipeline stage 0 */
1014 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1015 mbuf00, mbuf01, pkts, pkts_mask);
1017 /* Pipeline stage 1 */
1018 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1020 /* Pipeline stage 2 */
1021 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1022 bucket20, bucket21, pkts_mask_out, entries,
1023 buckets_mask, buckets, keys, f);
1031 bucket20 = bucket10;
1032 bucket21 = bucket11;
1037 pkt20_index = pkt10_index;
1038 pkt21_index = pkt11_index;
1039 pkt10_index = pkt00_index;
1040 pkt11_index = pkt01_index;
1042 /* Pipeline stage 1 */
1043 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1045 /* Pipeline stage 2 */
1046 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1047 bucket20, bucket21, pkts_mask_out, entries,
1048 buckets_mask, buckets, keys, f);
1051 bucket20 = bucket10;
1052 bucket21 = bucket11;
1055 pkt20_index = pkt10_index;
1056 pkt21_index = pkt11_index;
1058 /* Pipeline stage 2 */
1059 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1060 bucket20, bucket21, pkts_mask_out, entries,
1061 buckets_mask, buckets, keys, f);
1063 /* Grind next buckets */
1064 for ( ; buckets_mask; ) {
1065 uint64_t buckets_mask_next = 0;
1067 for ( ; buckets_mask; ) {
1071 pkt_index = __builtin_ctzll(buckets_mask);
1072 pkt_mask = 1LLU << pkt_index;
1073 buckets_mask &= ~pkt_mask;
1075 lookup_grinder(pkt_index, buckets, keys, pkts_mask_out,
1076 entries, buckets_mask_next, f);
1079 buckets_mask = buckets_mask_next;
1082 *lookup_hit_mask = pkts_mask_out;
1084 } /* rte_table_hash_lookup_key16_ext() */
1086 struct rte_table_ops rte_table_hash_key16_lru_ops = {
1087 .f_create = rte_table_hash_create_key16_lru,
1088 .f_free = rte_table_hash_free_key16_lru,
1089 .f_add = rte_table_hash_entry_add_key16_lru,
1090 .f_delete = rte_table_hash_entry_delete_key16_lru,
1091 .f_lookup = rte_table_hash_lookup_key16_lru,
1094 struct rte_table_ops rte_table_hash_key16_ext_ops = {
1095 .f_create = rte_table_hash_create_key16_ext,
1096 .f_free = rte_table_hash_free_key16_ext,
1097 .f_add = rte_table_hash_entry_add_key16_ext,
1098 .f_delete = rte_table_hash_entry_delete_key16_ext,
1099 .f_lookup = rte_table_hash_lookup_key16_ext,