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_memory.h>
39 #include <rte_malloc.h>
42 #include "rte_table_hash.h"
45 #define RTE_TABLE_HASH_KEY_SIZE 8
47 struct rte_bucket_4_8 {
51 struct rte_bucket_4_8 *next;
60 struct rte_table_hash {
61 /* Input parameters */
63 uint32_t n_entries_per_bucket;
67 uint32_t signature_offset;
69 rte_table_hash_op_hash f_hash;
72 /* Extendible buckets */
73 uint32_t n_buckets_ext;
78 uint8_t memory[0] __rte_cache_aligned;
82 check_params_create_lru(struct rte_table_hash_key8_lru_params *params) {
84 if (params->n_entries == 0) {
85 RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
90 if (params->f_hash == NULL) {
91 RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n",
100 rte_table_hash_create_key8_lru(void *params, int socket_id, uint32_t entry_size)
102 struct rte_table_hash_key8_lru_params *p =
103 (struct rte_table_hash_key8_lru_params *) params;
104 struct rte_table_hash *f;
105 uint32_t n_buckets, n_entries_per_bucket, key_size, bucket_size_cl;
106 uint32_t total_size, i;
108 /* Check input parameters */
109 if ((check_params_create_lru(p) != 0) ||
110 ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
111 ((sizeof(struct rte_bucket_4_8) % RTE_CACHE_LINE_SIZE) != 0)) {
114 n_entries_per_bucket = 4;
117 /* Memory allocation */
118 n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
119 n_entries_per_bucket);
120 bucket_size_cl = (sizeof(struct rte_bucket_4_8) + n_entries_per_bucket *
121 entry_size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE;
122 total_size = sizeof(struct rte_table_hash) + n_buckets *
123 bucket_size_cl * RTE_CACHE_LINE_SIZE;
125 f = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE, socket_id);
128 "%s: Cannot allocate %u bytes for hash table\n",
129 __func__, total_size);
133 "%s: Hash table memory footprint is %u bytes\n",
134 __func__, total_size);
136 /* Memory initialization */
137 f->n_buckets = n_buckets;
138 f->n_entries_per_bucket = n_entries_per_bucket;
139 f->key_size = key_size;
140 f->entry_size = entry_size;
141 f->bucket_size = bucket_size_cl * RTE_CACHE_LINE_SIZE;
142 f->signature_offset = p->signature_offset;
143 f->key_offset = p->key_offset;
144 f->f_hash = p->f_hash;
147 for (i = 0; i < n_buckets; i++) {
148 struct rte_bucket_4_8 *bucket;
150 bucket = (struct rte_bucket_4_8 *) &f->memory[i *
152 bucket->lru_list = 0x0000000100020003LLU;
159 rte_table_hash_free_key8_lru(void *table)
161 struct rte_table_hash *f = (struct rte_table_hash *) table;
163 /* Check input parameters */
165 RTE_LOG(ERR, TABLE, "%s: table parameter is NULL\n", __func__);
174 rte_table_hash_entry_add_key8_lru(
181 struct rte_table_hash *f = (struct rte_table_hash *) table;
182 struct rte_bucket_4_8 *bucket;
183 uint64_t signature, mask, pos;
184 uint32_t bucket_index, i;
186 signature = f->f_hash(key, f->key_size, f->seed);
187 bucket_index = signature & (f->n_buckets - 1);
188 bucket = (struct rte_bucket_4_8 *)
189 &f->memory[bucket_index * f->bucket_size];
191 /* Key is present in the bucket */
192 for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
193 uint64_t bucket_signature = bucket->signature;
194 uint64_t bucket_key = bucket->key[i];
196 if ((bucket_signature & mask) &&
197 (*((uint64_t *) key) == bucket_key)) {
198 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
200 memcpy(bucket_data, entry, f->entry_size);
201 lru_update(bucket, i);
203 *entry_ptr = (void *) bucket_data;
208 /* Key is not present in the bucket */
209 for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
210 uint64_t bucket_signature = bucket->signature;
212 if ((bucket_signature & mask) == 0) {
213 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
215 bucket->signature |= mask;
216 bucket->key[i] = *((uint64_t *) key);
217 memcpy(bucket_data, entry, f->entry_size);
218 lru_update(bucket, i);
220 *entry_ptr = (void *) bucket_data;
226 /* Bucket full: replace LRU entry */
227 pos = lru_pos(bucket);
228 bucket->key[pos] = *((uint64_t *) key);
229 memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
230 lru_update(bucket, pos);
232 *entry_ptr = (void *) &bucket->data[pos * f->entry_size];
238 rte_table_hash_entry_delete_key8_lru(
244 struct rte_table_hash *f = (struct rte_table_hash *) table;
245 struct rte_bucket_4_8 *bucket;
246 uint64_t signature, mask;
247 uint32_t bucket_index, i;
249 signature = f->f_hash(key, f->key_size, f->seed);
250 bucket_index = signature & (f->n_buckets - 1);
251 bucket = (struct rte_bucket_4_8 *)
252 &f->memory[bucket_index * f->bucket_size];
254 /* Key is present in the bucket */
255 for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
256 uint64_t bucket_signature = bucket->signature;
257 uint64_t bucket_key = bucket->key[i];
259 if ((bucket_signature & mask) &&
260 (*((uint64_t *) key) == bucket_key)) {
261 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
263 bucket->signature &= ~mask;
266 memcpy(entry, bucket_data, f->entry_size);
272 /* Key is not present in the bucket */
278 check_params_create_ext(struct rte_table_hash_key8_ext_params *params) {
280 if (params->n_entries == 0) {
281 RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
286 if (params->n_entries_ext == 0) {
287 RTE_LOG(ERR, TABLE, "%s: n_entries_ext is zero\n", __func__);
292 if (params->f_hash == NULL) {
293 RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n",
302 rte_table_hash_create_key8_ext(void *params, int socket_id, uint32_t entry_size)
304 struct rte_table_hash_key8_ext_params *p =
305 (struct rte_table_hash_key8_ext_params *) params;
306 struct rte_table_hash *f;
307 uint32_t n_buckets, n_buckets_ext, n_entries_per_bucket, key_size;
308 uint32_t bucket_size_cl, stack_size_cl, total_size, i;
310 /* Check input parameters */
311 if ((check_params_create_ext(p) != 0) ||
312 ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
313 ((sizeof(struct rte_bucket_4_8) % RTE_CACHE_LINE_SIZE) != 0))
316 n_entries_per_bucket = 4;
319 /* Memory allocation */
320 n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
321 n_entries_per_bucket);
322 n_buckets_ext = (p->n_entries_ext + n_entries_per_bucket - 1) /
323 n_entries_per_bucket;
324 bucket_size_cl = (sizeof(struct rte_bucket_4_8) + n_entries_per_bucket *
325 entry_size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE;
326 stack_size_cl = (n_buckets_ext * sizeof(uint32_t) + RTE_CACHE_LINE_SIZE - 1)
327 / RTE_CACHE_LINE_SIZE;
328 total_size = sizeof(struct rte_table_hash) + ((n_buckets +
329 n_buckets_ext) * bucket_size_cl + stack_size_cl) *
332 f = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE, socket_id);
335 "%s: Cannot allocate %u bytes for hash table\n",
336 __func__, total_size);
340 "%s: Hash table memory footprint is %u bytes\n",
341 __func__, total_size);
343 /* Memory initialization */
344 f->n_buckets = n_buckets;
345 f->n_entries_per_bucket = n_entries_per_bucket;
346 f->key_size = key_size;
347 f->entry_size = entry_size;
348 f->bucket_size = bucket_size_cl * RTE_CACHE_LINE_SIZE;
349 f->signature_offset = p->signature_offset;
350 f->key_offset = p->key_offset;
351 f->f_hash = p->f_hash;
354 f->n_buckets_ext = n_buckets_ext;
355 f->stack_pos = n_buckets_ext;
356 f->stack = (uint32_t *)
357 &f->memory[(n_buckets + n_buckets_ext) * f->bucket_size];
359 for (i = 0; i < n_buckets_ext; i++)
366 rte_table_hash_free_key8_ext(void *table)
368 struct rte_table_hash *f = (struct rte_table_hash *) table;
370 /* Check input parameters */
372 RTE_LOG(ERR, TABLE, "%s: table parameter is NULL\n", __func__);
381 rte_table_hash_entry_add_key8_ext(
388 struct rte_table_hash *f = (struct rte_table_hash *) table;
389 struct rte_bucket_4_8 *bucket0, *bucket, *bucket_prev;
391 uint32_t bucket_index, i;
393 signature = f->f_hash(key, f->key_size, f->seed);
394 bucket_index = signature & (f->n_buckets - 1);
395 bucket0 = (struct rte_bucket_4_8 *)
396 &f->memory[bucket_index * f->bucket_size];
398 /* Key is present in the bucket */
399 for (bucket = bucket0; bucket != NULL; bucket = bucket->next) {
402 for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
403 uint64_t bucket_signature = bucket->signature;
404 uint64_t bucket_key = bucket->key[i];
406 if ((bucket_signature & mask) &&
407 (*((uint64_t *) key) == bucket_key)) {
408 uint8_t *bucket_data = &bucket->data[i *
411 memcpy(bucket_data, entry, f->entry_size);
413 *entry_ptr = (void *) bucket_data;
419 /* Key is not present in the bucket */
420 for (bucket_prev = NULL, bucket = bucket0;
421 bucket != NULL; bucket_prev = bucket, bucket = bucket->next) {
424 for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
425 uint64_t bucket_signature = bucket->signature;
427 if ((bucket_signature & mask) == 0) {
428 uint8_t *bucket_data = &bucket->data[i *
431 bucket->signature |= mask;
432 bucket->key[i] = *((uint64_t *) key);
433 memcpy(bucket_data, entry, f->entry_size);
435 *entry_ptr = (void *) bucket_data;
442 /* Bucket full: extend bucket */
443 if (f->stack_pos > 0) {
444 bucket_index = f->stack[--f->stack_pos];
446 bucket = (struct rte_bucket_4_8 *) &f->memory[(f->n_buckets +
447 bucket_index) * f->bucket_size];
448 bucket_prev->next = bucket;
449 bucket_prev->next_valid = 1;
451 bucket->signature = 1;
452 bucket->key[0] = *((uint64_t *) key);
453 memcpy(&bucket->data[0], entry, f->entry_size);
455 *entry_ptr = (void *) &bucket->data[0];
463 rte_table_hash_entry_delete_key8_ext(
469 struct rte_table_hash *f = (struct rte_table_hash *) table;
470 struct rte_bucket_4_8 *bucket0, *bucket, *bucket_prev;
472 uint32_t bucket_index, i;
474 signature = f->f_hash(key, f->key_size, f->seed);
475 bucket_index = signature & (f->n_buckets - 1);
476 bucket0 = (struct rte_bucket_4_8 *)
477 &f->memory[bucket_index * f->bucket_size];
479 /* Key is present in the bucket */
480 for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
481 bucket_prev = bucket, bucket = bucket->next) {
484 for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
485 uint64_t bucket_signature = bucket->signature;
486 uint64_t bucket_key = bucket->key[i];
488 if ((bucket_signature & mask) &&
489 (*((uint64_t *) key) == bucket_key)) {
490 uint8_t *bucket_data = &bucket->data[i *
493 bucket->signature &= ~mask;
496 memcpy(entry, bucket_data,
499 if ((bucket->signature == 0) &&
500 (bucket_prev != NULL)) {
501 bucket_prev->next = bucket->next;
502 bucket_prev->next_valid =
506 sizeof(struct rte_bucket_4_8));
507 bucket_index = (((uint8_t *)bucket -
508 (uint8_t *)f->memory)/f->bucket_size) - f->n_buckets;
509 f->stack[f->stack_pos++] = bucket_index;
517 /* Key is not present in the bucket */
522 #define lookup_key8_cmp(key_in, bucket, pos) \
524 uint64_t xor[4], signature; \
526 signature = ~bucket->signature; \
528 xor[0] = (key_in[0] ^ bucket->key[0]) | (signature & 1);\
529 xor[1] = (key_in[0] ^ bucket->key[1]) | (signature & 2);\
530 xor[2] = (key_in[0] ^ bucket->key[2]) | (signature & 4);\
531 xor[3] = (key_in[0] ^ bucket->key[3]) | (signature & 8);\
544 #define lookup1_stage0(pkt0_index, mbuf0, pkts, pkts_mask) \
548 pkt0_index = __builtin_ctzll(pkts_mask); \
549 pkt_mask = 1LLU << pkt0_index; \
550 pkts_mask &= ~pkt_mask; \
552 mbuf0 = pkts[pkt0_index]; \
553 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf0, 0)); \
556 #define lookup1_stage1(mbuf1, bucket1, f) \
558 uint64_t signature; \
559 uint32_t bucket_index; \
561 signature = RTE_MBUF_METADATA_UINT32(mbuf1, f->signature_offset);\
562 bucket_index = signature & (f->n_buckets - 1); \
563 bucket1 = (struct rte_bucket_4_8 *) \
564 &f->memory[bucket_index * f->bucket_size]; \
565 rte_prefetch0(bucket1); \
568 #define lookup1_stage1_dosig(mbuf1, bucket1, f) \
571 uint64_t signature; \
572 uint32_t bucket_index; \
574 key = RTE_MBUF_METADATA_UINT64_PTR(mbuf1, f->key_offset);\
575 signature = f->f_hash(key, RTE_TABLE_HASH_KEY_SIZE, f->seed);\
576 bucket_index = signature & (f->n_buckets - 1); \
577 bucket1 = (struct rte_bucket_4_8 *) \
578 &f->memory[bucket_index * f->bucket_size]; \
579 rte_prefetch0(bucket1); \
582 #define lookup1_stage2_lru(pkt2_index, mbuf2, bucket2, \
583 pkts_mask_out, entries, f) \
590 key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
592 lookup_key8_cmp(key, bucket2, pos); \
594 pkt_mask = ((bucket2->signature >> pos) & 1LLU) << pkt2_index;\
595 pkts_mask_out |= pkt_mask; \
597 a = (void *) &bucket2->data[pos * f->entry_size]; \
599 entries[pkt2_index] = a; \
600 lru_update(bucket2, pos); \
603 #define lookup1_stage2_ext(pkt2_index, mbuf2, bucket2, pkts_mask_out,\
604 entries, buckets_mask, buckets, keys, f) \
606 struct rte_bucket_4_8 *bucket_next; \
608 uint64_t pkt_mask, bucket_mask; \
612 key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
614 lookup_key8_cmp(key, bucket2, pos); \
616 pkt_mask = ((bucket2->signature >> pos) & 1LLU) << pkt2_index;\
617 pkts_mask_out |= pkt_mask; \
619 a = (void *) &bucket2->data[pos * f->entry_size]; \
621 entries[pkt2_index] = a; \
623 bucket_mask = (~pkt_mask) & (bucket2->next_valid << pkt2_index);\
624 buckets_mask |= bucket_mask; \
625 bucket_next = bucket2->next; \
626 buckets[pkt2_index] = bucket_next; \
627 keys[pkt2_index] = key; \
630 #define lookup_grinder(pkt_index, buckets, keys, pkts_mask_out, entries,\
633 struct rte_bucket_4_8 *bucket, *bucket_next; \
635 uint64_t pkt_mask, bucket_mask; \
639 bucket = buckets[pkt_index]; \
640 key = keys[pkt_index]; \
642 lookup_key8_cmp(key, bucket, pos); \
644 pkt_mask = ((bucket->signature >> pos) & 1LLU) << pkt_index;\
645 pkts_mask_out |= pkt_mask; \
647 a = (void *) &bucket->data[pos * f->entry_size]; \
649 entries[pkt_index] = a; \
651 bucket_mask = (~pkt_mask) & (bucket->next_valid << pkt_index);\
652 buckets_mask |= bucket_mask; \
653 bucket_next = bucket->next; \
654 rte_prefetch0(bucket_next); \
655 buckets[pkt_index] = bucket_next; \
656 keys[pkt_index] = key; \
659 #define lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01,\
662 uint64_t pkt00_mask, pkt01_mask; \
664 pkt00_index = __builtin_ctzll(pkts_mask); \
665 pkt00_mask = 1LLU << pkt00_index; \
666 pkts_mask &= ~pkt00_mask; \
668 mbuf00 = pkts[pkt00_index]; \
669 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, 0)); \
671 pkt01_index = __builtin_ctzll(pkts_mask); \
672 pkt01_mask = 1LLU << pkt01_index; \
673 pkts_mask &= ~pkt01_mask; \
675 mbuf01 = pkts[pkt01_index]; \
676 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, 0)); \
679 #define lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,\
680 mbuf00, mbuf01, pkts, pkts_mask) \
682 uint64_t pkt00_mask, pkt01_mask; \
684 pkt00_index = __builtin_ctzll(pkts_mask); \
685 pkt00_mask = 1LLU << pkt00_index; \
686 pkts_mask &= ~pkt00_mask; \
688 mbuf00 = pkts[pkt00_index]; \
689 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, 0)); \
691 pkt01_index = __builtin_ctzll(pkts_mask); \
692 if (pkts_mask == 0) \
693 pkt01_index = pkt00_index; \
695 pkt01_mask = 1LLU << pkt01_index; \
696 pkts_mask &= ~pkt01_mask; \
698 mbuf01 = pkts[pkt01_index]; \
699 rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, 0)); \
702 #define lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f) \
704 uint64_t signature10, signature11; \
705 uint32_t bucket10_index, bucket11_index; \
707 signature10 = RTE_MBUF_METADATA_UINT32(mbuf10, f->signature_offset);\
708 bucket10_index = signature10 & (f->n_buckets - 1); \
709 bucket10 = (struct rte_bucket_4_8 *) \
710 &f->memory[bucket10_index * f->bucket_size]; \
711 rte_prefetch0(bucket10); \
713 signature11 = RTE_MBUF_METADATA_UINT32(mbuf11, f->signature_offset);\
714 bucket11_index = signature11 & (f->n_buckets - 1); \
715 bucket11 = (struct rte_bucket_4_8 *) \
716 &f->memory[bucket11_index * f->bucket_size]; \
717 rte_prefetch0(bucket11); \
720 #define lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f)\
722 uint64_t *key10, *key11; \
723 uint64_t signature10, signature11; \
724 uint32_t bucket10_index, bucket11_index; \
725 rte_table_hash_op_hash f_hash = f->f_hash; \
726 uint64_t seed = f->seed; \
727 uint32_t key_offset = f->key_offset; \
729 key10 = RTE_MBUF_METADATA_UINT64_PTR(mbuf10, key_offset);\
730 key11 = RTE_MBUF_METADATA_UINT64_PTR(mbuf11, key_offset);\
732 signature10 = f_hash(key10, RTE_TABLE_HASH_KEY_SIZE, seed);\
733 bucket10_index = signature10 & (f->n_buckets - 1); \
734 bucket10 = (struct rte_bucket_4_8 *) \
735 &f->memory[bucket10_index * f->bucket_size]; \
736 rte_prefetch0(bucket10); \
738 signature11 = f_hash(key11, RTE_TABLE_HASH_KEY_SIZE, seed);\
739 bucket11_index = signature11 & (f->n_buckets - 1); \
740 bucket11 = (struct rte_bucket_4_8 *) \
741 &f->memory[bucket11_index * f->bucket_size]; \
742 rte_prefetch0(bucket11); \
745 #define lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,\
746 bucket20, bucket21, pkts_mask_out, entries, f) \
749 uint64_t pkt20_mask, pkt21_mask; \
750 uint64_t *key20, *key21; \
751 uint32_t pos20, pos21; \
753 key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
754 key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
756 lookup_key8_cmp(key20, bucket20, pos20); \
757 lookup_key8_cmp(key21, bucket21, pos21); \
759 pkt20_mask = ((bucket20->signature >> pos20) & 1LLU) << pkt20_index;\
760 pkt21_mask = ((bucket21->signature >> pos21) & 1LLU) << pkt21_index;\
761 pkts_mask_out |= pkt20_mask | pkt21_mask; \
763 a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
764 a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
765 rte_prefetch0(a20); \
766 rte_prefetch0(a21); \
767 entries[pkt20_index] = a20; \
768 entries[pkt21_index] = a21; \
769 lru_update(bucket20, pos20); \
770 lru_update(bucket21, pos21); \
773 #define lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21, bucket20, \
774 bucket21, pkts_mask_out, entries, buckets_mask, buckets, keys, f)\
776 struct rte_bucket_4_8 *bucket20_next, *bucket21_next; \
778 uint64_t pkt20_mask, pkt21_mask, bucket20_mask, bucket21_mask;\
779 uint64_t *key20, *key21; \
780 uint32_t pos20, pos21; \
782 key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
783 key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
785 lookup_key8_cmp(key20, bucket20, pos20); \
786 lookup_key8_cmp(key21, bucket21, pos21); \
788 pkt20_mask = ((bucket20->signature >> pos20) & 1LLU) << pkt20_index;\
789 pkt21_mask = ((bucket21->signature >> pos21) & 1LLU) << pkt21_index;\
790 pkts_mask_out |= pkt20_mask | pkt21_mask; \
792 a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
793 a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
794 rte_prefetch0(a20); \
795 rte_prefetch0(a21); \
796 entries[pkt20_index] = a20; \
797 entries[pkt21_index] = a21; \
799 bucket20_mask = (~pkt20_mask) & (bucket20->next_valid << pkt20_index);\
800 bucket21_mask = (~pkt21_mask) & (bucket21->next_valid << pkt21_index);\
801 buckets_mask |= bucket20_mask | bucket21_mask; \
802 bucket20_next = bucket20->next; \
803 bucket21_next = bucket21->next; \
804 buckets[pkt20_index] = bucket20_next; \
805 buckets[pkt21_index] = bucket21_next; \
806 keys[pkt20_index] = key20; \
807 keys[pkt21_index] = key21; \
811 rte_table_hash_lookup_key8_lru(
813 struct rte_mbuf **pkts,
815 uint64_t *lookup_hit_mask,
818 struct rte_table_hash *f = (struct rte_table_hash *) table;
819 struct rte_bucket_4_8 *bucket10, *bucket11, *bucket20, *bucket21;
820 struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
821 uint32_t pkt00_index, pkt01_index, pkt10_index,
822 pkt11_index, pkt20_index, pkt21_index;
823 uint64_t pkts_mask_out = 0;
825 /* Cannot run the pipeline with less than 5 packets */
826 if (__builtin_popcountll(pkts_mask) < 5) {
827 for ( ; pkts_mask; ) {
828 struct rte_bucket_4_8 *bucket;
829 struct rte_mbuf *mbuf;
832 lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask);
833 lookup1_stage1(mbuf, bucket, f);
834 lookup1_stage2_lru(pkt_index, mbuf, bucket,
835 pkts_mask_out, entries, f);
838 *lookup_hit_mask = pkts_mask_out;
846 /* Pipeline stage 0 */
847 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
853 pkt10_index = pkt00_index;
854 pkt11_index = pkt01_index;
856 /* Pipeline stage 0 */
857 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
860 /* Pipeline stage 1 */
861 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
867 for ( ; pkts_mask; ) {
875 pkt20_index = pkt10_index;
876 pkt21_index = pkt11_index;
877 pkt10_index = pkt00_index;
878 pkt11_index = pkt01_index;
880 /* Pipeline stage 0 */
881 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
882 mbuf00, mbuf01, pkts, pkts_mask);
884 /* Pipeline stage 1 */
885 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
887 /* Pipeline stage 2 */
888 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
889 bucket20, bucket21, pkts_mask_out, entries, f);
903 pkt20_index = pkt10_index;
904 pkt21_index = pkt11_index;
905 pkt10_index = pkt00_index;
906 pkt11_index = pkt01_index;
908 /* Pipeline stage 1 */
909 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
911 /* Pipeline stage 2 */
912 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
913 bucket20, bucket21, pkts_mask_out, entries, f);
920 pkt20_index = pkt10_index;
921 pkt21_index = pkt11_index;
923 /* Pipeline stage 2 */
924 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
925 bucket20, bucket21, pkts_mask_out, entries, f);
927 *lookup_hit_mask = pkts_mask_out;
929 } /* rte_table_hash_lookup_key8_lru() */
932 rte_table_hash_lookup_key8_lru_dosig(
934 struct rte_mbuf **pkts,
936 uint64_t *lookup_hit_mask,
939 struct rte_table_hash *f = (struct rte_table_hash *) table;
940 struct rte_bucket_4_8 *bucket10, *bucket11, *bucket20, *bucket21;
941 struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
942 uint32_t pkt00_index, pkt01_index, pkt10_index;
943 uint32_t pkt11_index, pkt20_index, pkt21_index;
944 uint64_t pkts_mask_out = 0;
946 /* Cannot run the pipeline with less than 5 packets */
947 if (__builtin_popcountll(pkts_mask) < 5) {
948 for ( ; pkts_mask; ) {
949 struct rte_bucket_4_8 *bucket;
950 struct rte_mbuf *mbuf;
953 lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask);
954 lookup1_stage1_dosig(mbuf, bucket, f);
955 lookup1_stage2_lru(pkt_index, mbuf, bucket,
956 pkts_mask_out, entries, f);
959 *lookup_hit_mask = pkts_mask_out;
967 /* Pipeline stage 0 */
968 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
974 pkt10_index = pkt00_index;
975 pkt11_index = pkt01_index;
977 /* Pipeline stage 0 */
978 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
981 /* Pipeline stage 1 */
982 lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f);
988 for ( ; pkts_mask; ) {
996 pkt20_index = pkt10_index;
997 pkt21_index = pkt11_index;
998 pkt10_index = pkt00_index;
999 pkt11_index = pkt01_index;
1001 /* Pipeline stage 0 */
1002 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1003 mbuf00, mbuf01, pkts, pkts_mask);
1005 /* Pipeline stage 1 */
1006 lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f);
1008 /* Pipeline stage 2 */
1009 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
1010 bucket20, bucket21, pkts_mask_out, entries, f);
1018 bucket20 = bucket10;
1019 bucket21 = bucket11;
1024 pkt20_index = pkt10_index;
1025 pkt21_index = pkt11_index;
1026 pkt10_index = pkt00_index;
1027 pkt11_index = pkt01_index;
1029 /* Pipeline stage 1 */
1030 lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f);
1032 /* Pipeline stage 2 */
1033 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
1034 bucket20, bucket21, pkts_mask_out, entries, f);
1037 bucket20 = bucket10;
1038 bucket21 = bucket11;
1041 pkt20_index = pkt10_index;
1042 pkt21_index = pkt11_index;
1044 /* Pipeline stage 2 */
1045 lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
1046 bucket20, bucket21, pkts_mask_out, entries, f);
1048 *lookup_hit_mask = pkts_mask_out;
1050 } /* rte_table_hash_lookup_key8_lru_dosig() */
1053 rte_table_hash_lookup_key8_ext(
1055 struct rte_mbuf **pkts,
1057 uint64_t *lookup_hit_mask,
1060 struct rte_table_hash *f = (struct rte_table_hash *) table;
1061 struct rte_bucket_4_8 *bucket10, *bucket11, *bucket20, *bucket21;
1062 struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
1063 uint32_t pkt00_index, pkt01_index, pkt10_index;
1064 uint32_t pkt11_index, pkt20_index, pkt21_index;
1065 uint64_t pkts_mask_out = 0, buckets_mask = 0;
1066 struct rte_bucket_4_8 *buckets[RTE_PORT_IN_BURST_SIZE_MAX];
1067 uint64_t *keys[RTE_PORT_IN_BURST_SIZE_MAX];
1069 /* Cannot run the pipeline with less than 5 packets */
1070 if (__builtin_popcountll(pkts_mask) < 5) {
1071 for ( ; pkts_mask; ) {
1072 struct rte_bucket_4_8 *bucket;
1073 struct rte_mbuf *mbuf;
1076 lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask);
1077 lookup1_stage1(mbuf, bucket, f);
1078 lookup1_stage2_ext(pkt_index, mbuf, bucket,
1079 pkts_mask_out, entries, buckets_mask, buckets,
1083 goto grind_next_buckets;
1090 /* Pipeline stage 0 */
1091 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1097 pkt10_index = pkt00_index;
1098 pkt11_index = pkt01_index;
1100 /* Pipeline stage 0 */
1101 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1104 /* Pipeline stage 1 */
1105 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1111 for ( ; pkts_mask; ) {
1113 bucket20 = bucket10;
1114 bucket21 = bucket11;
1119 pkt20_index = pkt10_index;
1120 pkt21_index = pkt11_index;
1121 pkt10_index = pkt00_index;
1122 pkt11_index = pkt01_index;
1124 /* Pipeline stage 0 */
1125 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1126 mbuf00, mbuf01, pkts, pkts_mask);
1128 /* Pipeline stage 1 */
1129 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1131 /* Pipeline stage 2 */
1132 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1133 bucket20, bucket21, pkts_mask_out, entries,
1134 buckets_mask, buckets, keys, f);
1142 bucket20 = bucket10;
1143 bucket21 = bucket11;
1148 pkt20_index = pkt10_index;
1149 pkt21_index = pkt11_index;
1150 pkt10_index = pkt00_index;
1151 pkt11_index = pkt01_index;
1153 /* Pipeline stage 1 */
1154 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1156 /* Pipeline stage 2 */
1157 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1158 bucket20, bucket21, pkts_mask_out, entries,
1159 buckets_mask, buckets, keys, f);
1162 bucket20 = bucket10;
1163 bucket21 = bucket11;
1166 pkt20_index = pkt10_index;
1167 pkt21_index = pkt11_index;
1169 /* Pipeline stage 2 */
1170 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1171 bucket20, bucket21, pkts_mask_out, entries,
1172 buckets_mask, buckets, keys, f);
1175 /* Grind next buckets */
1176 for ( ; buckets_mask; ) {
1177 uint64_t buckets_mask_next = 0;
1179 for ( ; buckets_mask; ) {
1183 pkt_index = __builtin_ctzll(buckets_mask);
1184 pkt_mask = 1LLU << pkt_index;
1185 buckets_mask &= ~pkt_mask;
1187 lookup_grinder(pkt_index, buckets, keys, pkts_mask_out,
1188 entries, buckets_mask_next, f);
1191 buckets_mask = buckets_mask_next;
1194 *lookup_hit_mask = pkts_mask_out;
1196 } /* rte_table_hash_lookup_key8_ext() */
1199 rte_table_hash_lookup_key8_ext_dosig(
1201 struct rte_mbuf **pkts,
1203 uint64_t *lookup_hit_mask,
1206 struct rte_table_hash *f = (struct rte_table_hash *) table;
1207 struct rte_bucket_4_8 *bucket10, *bucket11, *bucket20, *bucket21;
1208 struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
1209 uint32_t pkt00_index, pkt01_index, pkt10_index;
1210 uint32_t pkt11_index, pkt20_index, pkt21_index;
1211 uint64_t pkts_mask_out = 0, buckets_mask = 0;
1212 struct rte_bucket_4_8 *buckets[RTE_PORT_IN_BURST_SIZE_MAX];
1213 uint64_t *keys[RTE_PORT_IN_BURST_SIZE_MAX];
1215 /* Cannot run the pipeline with less than 5 packets */
1216 if (__builtin_popcountll(pkts_mask) < 5) {
1217 for ( ; pkts_mask; ) {
1218 struct rte_bucket_4_8 *bucket;
1219 struct rte_mbuf *mbuf;
1222 lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask);
1223 lookup1_stage1_dosig(mbuf, bucket, f);
1224 lookup1_stage2_ext(pkt_index, mbuf, bucket,
1225 pkts_mask_out, entries, buckets_mask,
1229 goto grind_next_buckets;
1236 /* Pipeline stage 0 */
1237 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1243 pkt10_index = pkt00_index;
1244 pkt11_index = pkt01_index;
1246 /* Pipeline stage 0 */
1247 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1250 /* Pipeline stage 1 */
1251 lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f);
1257 for ( ; pkts_mask; ) {
1259 bucket20 = bucket10;
1260 bucket21 = bucket11;
1265 pkt20_index = pkt10_index;
1266 pkt21_index = pkt11_index;
1267 pkt10_index = pkt00_index;
1268 pkt11_index = pkt01_index;
1270 /* Pipeline stage 0 */
1271 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1272 mbuf00, mbuf01, pkts, pkts_mask);
1274 /* Pipeline stage 1 */
1275 lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f);
1277 /* Pipeline stage 2 */
1278 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1279 bucket20, bucket21, pkts_mask_out, entries,
1280 buckets_mask, buckets, keys, f);
1288 bucket20 = bucket10;
1289 bucket21 = bucket11;
1294 pkt20_index = pkt10_index;
1295 pkt21_index = pkt11_index;
1296 pkt10_index = pkt00_index;
1297 pkt11_index = pkt01_index;
1299 /* Pipeline stage 1 */
1300 lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f);
1302 /* Pipeline stage 2 */
1303 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1304 bucket20, bucket21, pkts_mask_out, entries,
1305 buckets_mask, buckets, keys, f);
1308 bucket20 = bucket10;
1309 bucket21 = bucket11;
1312 pkt20_index = pkt10_index;
1313 pkt21_index = pkt11_index;
1315 /* Pipeline stage 2 */
1316 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1317 bucket20, bucket21, pkts_mask_out, entries,
1318 buckets_mask, buckets, keys, f);
1321 /* Grind next buckets */
1322 for ( ; buckets_mask; ) {
1323 uint64_t buckets_mask_next = 0;
1325 for ( ; buckets_mask; ) {
1329 pkt_index = __builtin_ctzll(buckets_mask);
1330 pkt_mask = 1LLU << pkt_index;
1331 buckets_mask &= ~pkt_mask;
1333 lookup_grinder(pkt_index, buckets, keys, pkts_mask_out,
1334 entries, buckets_mask_next, f);
1337 buckets_mask = buckets_mask_next;
1340 *lookup_hit_mask = pkts_mask_out;
1342 } /* rte_table_hash_lookup_key8_dosig_ext() */
1344 struct rte_table_ops rte_table_hash_key8_lru_ops = {
1345 .f_create = rte_table_hash_create_key8_lru,
1346 .f_free = rte_table_hash_free_key8_lru,
1347 .f_add = rte_table_hash_entry_add_key8_lru,
1348 .f_delete = rte_table_hash_entry_delete_key8_lru,
1349 .f_lookup = rte_table_hash_lookup_key8_lru,
1352 struct rte_table_ops rte_table_hash_key8_lru_dosig_ops = {
1353 .f_create = rte_table_hash_create_key8_lru,
1354 .f_free = rte_table_hash_free_key8_lru,
1355 .f_add = rte_table_hash_entry_add_key8_lru,
1356 .f_delete = rte_table_hash_entry_delete_key8_lru,
1357 .f_lookup = rte_table_hash_lookup_key8_lru_dosig,
1360 struct rte_table_ops rte_table_hash_key8_ext_ops = {
1361 .f_create = rte_table_hash_create_key8_ext,
1362 .f_free = rte_table_hash_free_key8_ext,
1363 .f_add = rte_table_hash_entry_add_key8_ext,
1364 .f_delete = rte_table_hash_entry_delete_key8_ext,
1365 .f_lookup = rte_table_hash_lookup_key8_ext,
1368 struct rte_table_ops rte_table_hash_key8_ext_dosig_ops = {
1369 .f_create = rte_table_hash_create_key8_ext,
1370 .f_free = rte_table_hash_free_key8_ext,
1371 .f_add = rte_table_hash_entry_add_key8_ext,
1372 .f_delete = rte_table_hash_entry_delete_key8_ext,
1373 .f_lookup = rte_table_hash_lookup_key8_ext_dosig,