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 16
47 #define RTE_BUCKET_ENTRY_VALID 0x1LLU
49 struct rte_bucket_4_16 {
51 uint64_t signature[4 + 1];
53 struct rte_bucket_4_16 *next;
63 struct rte_table_hash {
64 /* Input parameters */
66 uint32_t n_entries_per_bucket;
70 uint32_t signature_offset;
72 rte_table_hash_op_hash f_hash;
75 /* Extendible buckets */
76 uint32_t n_buckets_ext;
81 uint8_t memory[0] __rte_cache_aligned;
85 check_params_create_lru(struct rte_table_hash_key16_lru_params *params) {
87 if (params->n_entries == 0) {
88 RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
92 /* signature offset */
93 if ((params->signature_offset & 0x3) != 0) {
94 RTE_LOG(ERR, TABLE, "%s: invalid signature_offset\n", __func__);
99 if ((params->key_offset & 0x7) != 0) {
100 RTE_LOG(ERR, TABLE, "%s: invalid key_offset\n", __func__);
105 if (params->f_hash == NULL) {
107 "%s: f_hash function pointer is NULL\n", __func__);
115 rte_table_hash_create_key16_lru(void *params,
119 struct rte_table_hash_key16_lru_params *p =
120 (struct rte_table_hash_key16_lru_params *) params;
121 struct rte_table_hash *f;
122 uint32_t n_buckets, n_entries_per_bucket,
123 key_size, bucket_size_cl, total_size, i;
125 /* Check input parameters */
126 if ((check_params_create_lru(p) != 0) ||
127 ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
128 ((sizeof(struct rte_bucket_4_16) % RTE_CACHE_LINE_SIZE) != 0))
130 n_entries_per_bucket = 4;
133 /* Memory allocation */
134 n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
135 n_entries_per_bucket);
136 bucket_size_cl = (sizeof(struct rte_bucket_4_16) + n_entries_per_bucket
137 * entry_size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE;
138 total_size = sizeof(struct rte_table_hash) + n_buckets *
139 bucket_size_cl * RTE_CACHE_LINE_SIZE;
141 f = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE, socket_id);
144 "%s: Cannot allocate %u bytes for hash table\n",
145 __func__, total_size);
149 "%s: Hash table memory footprint is %u bytes\n",
150 __func__, total_size);
152 /* Memory initialization */
153 f->n_buckets = n_buckets;
154 f->n_entries_per_bucket = n_entries_per_bucket;
155 f->key_size = key_size;
156 f->entry_size = entry_size;
157 f->bucket_size = bucket_size_cl * RTE_CACHE_LINE_SIZE;
158 f->signature_offset = p->signature_offset;
159 f->key_offset = p->key_offset;
160 f->f_hash = p->f_hash;
163 for (i = 0; i < n_buckets; i++) {
164 struct rte_bucket_4_16 *bucket;
166 bucket = (struct rte_bucket_4_16 *) &f->memory[i *
175 rte_table_hash_free_key16_lru(void *table)
177 struct rte_table_hash *f = (struct rte_table_hash *) table;
179 /* Check input parameters */
181 RTE_LOG(ERR, TABLE, "%s: table parameter is NULL\n", __func__);
190 rte_table_hash_entry_add_key16_lru(
197 struct rte_table_hash *f = (struct rte_table_hash *) table;
198 struct rte_bucket_4_16 *bucket;
199 uint64_t signature, pos;
200 uint32_t bucket_index, i;
202 signature = f->f_hash(key, f->key_size, f->seed);
203 bucket_index = signature & (f->n_buckets - 1);
204 bucket = (struct rte_bucket_4_16 *)
205 &f->memory[bucket_index * f->bucket_size];
206 signature |= RTE_BUCKET_ENTRY_VALID;
208 /* Key is present in the bucket */
209 for (i = 0; i < 4; i++) {
210 uint64_t bucket_signature = bucket->signature[i];
211 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
213 if ((bucket_signature == signature) &&
214 (memcmp(key, bucket_key, f->key_size) == 0)) {
215 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
217 memcpy(bucket_data, entry, f->entry_size);
218 lru_update(bucket, i);
220 *entry_ptr = (void *) bucket_data;
225 /* Key is not present in the bucket */
226 for (i = 0; i < 4; i++) {
227 uint64_t bucket_signature = bucket->signature[i];
228 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
230 if (bucket_signature == 0) {
231 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
233 bucket->signature[i] = signature;
234 memcpy(bucket_key, key, f->key_size);
235 memcpy(bucket_data, entry, f->entry_size);
236 lru_update(bucket, i);
238 *entry_ptr = (void *) bucket_data;
244 /* Bucket full: replace LRU entry */
245 pos = lru_pos(bucket);
246 bucket->signature[pos] = signature;
247 memcpy(bucket->key[pos], key, f->key_size);
248 memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
249 lru_update(bucket, pos);
251 *entry_ptr = (void *) &bucket->data[pos * f->entry_size];
257 rte_table_hash_entry_delete_key16_lru(
263 struct rte_table_hash *f = (struct rte_table_hash *) table;
264 struct rte_bucket_4_16 *bucket;
266 uint32_t bucket_index, i;
268 signature = f->f_hash(key, f->key_size, f->seed);
269 bucket_index = signature & (f->n_buckets - 1);
270 bucket = (struct rte_bucket_4_16 *)
271 &f->memory[bucket_index * f->bucket_size];
272 signature |= RTE_BUCKET_ENTRY_VALID;
274 /* Key is present in the bucket */
275 for (i = 0; i < 4; i++) {
276 uint64_t bucket_signature = bucket->signature[i];
277 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
279 if ((bucket_signature == signature) &&
280 (memcmp(key, bucket_key, f->key_size) == 0)) {
281 uint8_t *bucket_data = &bucket->data[i * f->entry_size];
283 bucket->signature[i] = 0;
286 memcpy(entry, bucket_data, f->entry_size);
291 /* Key is not present in the bucket */
297 check_params_create_ext(struct rte_table_hash_key16_ext_params *params) {
299 if (params->n_entries == 0) {
300 RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
305 if (params->n_entries_ext == 0) {
306 RTE_LOG(ERR, TABLE, "%s: n_entries_ext is zero\n", __func__);
310 /* signature offset */
311 if ((params->signature_offset & 0x3) != 0) {
312 RTE_LOG(ERR, TABLE, "%s: invalid signature offset\n", __func__);
317 if ((params->key_offset & 0x7) != 0) {
318 RTE_LOG(ERR, TABLE, "%s: invalid key offset\n", __func__);
323 if (params->f_hash == NULL) {
325 "%s: f_hash function pointer is NULL\n", __func__);
333 rte_table_hash_create_key16_ext(void *params,
337 struct rte_table_hash_key16_ext_params *p =
338 (struct rte_table_hash_key16_ext_params *) params;
339 struct rte_table_hash *f;
340 uint32_t n_buckets, n_buckets_ext, n_entries_per_bucket, key_size,
341 bucket_size_cl, stack_size_cl, total_size, i;
343 /* Check input parameters */
344 if ((check_params_create_ext(p) != 0) ||
345 ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
346 ((sizeof(struct rte_bucket_4_16) % RTE_CACHE_LINE_SIZE) != 0))
349 n_entries_per_bucket = 4;
352 /* Memory allocation */
353 n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
354 n_entries_per_bucket);
355 n_buckets_ext = (p->n_entries_ext + n_entries_per_bucket - 1) /
356 n_entries_per_bucket;
357 bucket_size_cl = (sizeof(struct rte_bucket_4_16) + n_entries_per_bucket
358 * entry_size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE;
359 stack_size_cl = (n_buckets_ext * sizeof(uint32_t) + RTE_CACHE_LINE_SIZE - 1)
360 / RTE_CACHE_LINE_SIZE;
361 total_size = sizeof(struct rte_table_hash) +
362 ((n_buckets + n_buckets_ext) * bucket_size_cl + stack_size_cl) *
365 f = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE, socket_id);
368 "%s: Cannot allocate %u bytes for hash table\n",
369 __func__, total_size);
373 "%s: Hash table memory footprint is %u bytes\n",
374 __func__, total_size);
376 /* Memory initialization */
377 f->n_buckets = n_buckets;
378 f->n_entries_per_bucket = n_entries_per_bucket;
379 f->key_size = key_size;
380 f->entry_size = entry_size;
381 f->bucket_size = bucket_size_cl * RTE_CACHE_LINE_SIZE;
382 f->signature_offset = p->signature_offset;
383 f->key_offset = p->key_offset;
384 f->f_hash = p->f_hash;
387 f->n_buckets_ext = n_buckets_ext;
388 f->stack_pos = n_buckets_ext;
389 f->stack = (uint32_t *)
390 &f->memory[(n_buckets + n_buckets_ext) * f->bucket_size];
392 for (i = 0; i < n_buckets_ext; i++)
399 rte_table_hash_free_key16_ext(void *table)
401 struct rte_table_hash *f = (struct rte_table_hash *) table;
403 /* Check input parameters */
405 RTE_LOG(ERR, TABLE, "%s: table parameter is NULL\n", __func__);
414 rte_table_hash_entry_add_key16_ext(
421 struct rte_table_hash *f = (struct rte_table_hash *) table;
422 struct rte_bucket_4_16 *bucket0, *bucket, *bucket_prev;
424 uint32_t bucket_index, i;
426 signature = f->f_hash(key, f->key_size, f->seed);
427 bucket_index = signature & (f->n_buckets - 1);
428 bucket0 = (struct rte_bucket_4_16 *)
429 &f->memory[bucket_index * f->bucket_size];
430 signature |= RTE_BUCKET_ENTRY_VALID;
432 /* Key is present in the bucket */
433 for (bucket = bucket0; bucket != NULL; bucket = bucket->next)
434 for (i = 0; i < 4; i++) {
435 uint64_t bucket_signature = bucket->signature[i];
436 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
438 if ((bucket_signature == signature) &&
439 (memcmp(key, bucket_key, f->key_size) == 0)) {
440 uint8_t *bucket_data = &bucket->data[i *
443 memcpy(bucket_data, entry, f->entry_size);
445 *entry_ptr = (void *) bucket_data;
450 /* Key is not present in the bucket */
451 for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
452 bucket_prev = bucket, bucket = bucket->next)
453 for (i = 0; i < 4; i++) {
454 uint64_t bucket_signature = bucket->signature[i];
455 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
457 if (bucket_signature == 0) {
458 uint8_t *bucket_data = &bucket->data[i *
461 bucket->signature[i] = signature;
462 memcpy(bucket_key, key, f->key_size);
463 memcpy(bucket_data, entry, f->entry_size);
465 *entry_ptr = (void *) bucket_data;
471 /* Bucket full: extend bucket */
472 if (f->stack_pos > 0) {
473 bucket_index = f->stack[--f->stack_pos];
475 bucket = (struct rte_bucket_4_16 *) &f->memory[(f->n_buckets +
476 bucket_index) * f->bucket_size];
477 bucket_prev->next = bucket;
478 bucket_prev->next_valid = 1;
480 bucket->signature[0] = signature;
481 memcpy(bucket->key[0], key, f->key_size);
482 memcpy(&bucket->data[0], entry, f->entry_size);
484 *entry_ptr = (void *) &bucket->data[0];
492 rte_table_hash_entry_delete_key16_ext(
498 struct rte_table_hash *f = (struct rte_table_hash *) table;
499 struct rte_bucket_4_16 *bucket0, *bucket, *bucket_prev;
501 uint32_t bucket_index, i;
503 signature = f->f_hash(key, f->key_size, f->seed);
504 bucket_index = signature & (f->n_buckets - 1);
505 bucket0 = (struct rte_bucket_4_16 *)
506 &f->memory[bucket_index * f->bucket_size];
507 signature |= RTE_BUCKET_ENTRY_VALID;
509 /* Key is present in the bucket */
510 for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
511 bucket_prev = bucket, bucket = bucket->next)
512 for (i = 0; i < 4; i++) {
513 uint64_t bucket_signature = bucket->signature[i];
514 uint8_t *bucket_key = (uint8_t *) bucket->key[i];
516 if ((bucket_signature == signature) &&
517 (memcmp(key, bucket_key, f->key_size) == 0)) {
518 uint8_t *bucket_data = &bucket->data[i *
521 bucket->signature[i] = 0;
524 memcpy(entry, bucket_data,
527 if ((bucket->signature[0] == 0) &&
528 (bucket->signature[1] == 0) &&
529 (bucket->signature[2] == 0) &&
530 (bucket->signature[3] == 0) &&
531 (bucket_prev != NULL)) {
532 bucket_prev->next = bucket->next;
533 bucket_prev->next_valid =
537 sizeof(struct rte_bucket_4_16));
538 bucket_index = (((uint8_t *)bucket -
539 (uint8_t *)f->memory)/f->bucket_size) - 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) + RTE_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) + RTE_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) + RTE_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) + RTE_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 goto grind_next_buckets;
978 /* Pipeline stage 0 */
979 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
985 pkt10_index = pkt00_index;
986 pkt11_index = pkt01_index;
988 /* Pipeline stage 0 */
989 lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
992 /* Pipeline stage 1 */
993 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
999 for ( ; pkts_mask; ) {
1001 bucket20 = bucket10;
1002 bucket21 = bucket11;
1007 pkt20_index = pkt10_index;
1008 pkt21_index = pkt11_index;
1009 pkt10_index = pkt00_index;
1010 pkt11_index = pkt01_index;
1012 /* Pipeline stage 0 */
1013 lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1014 mbuf00, mbuf01, pkts, pkts_mask);
1016 /* Pipeline stage 1 */
1017 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1019 /* Pipeline stage 2 */
1020 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1021 bucket20, bucket21, pkts_mask_out, entries,
1022 buckets_mask, buckets, keys, f);
1030 bucket20 = bucket10;
1031 bucket21 = bucket11;
1036 pkt20_index = pkt10_index;
1037 pkt21_index = pkt11_index;
1038 pkt10_index = pkt00_index;
1039 pkt11_index = pkt01_index;
1041 /* Pipeline stage 1 */
1042 lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1044 /* Pipeline stage 2 */
1045 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1046 bucket20, bucket21, pkts_mask_out, entries,
1047 buckets_mask, buckets, keys, f);
1050 bucket20 = bucket10;
1051 bucket21 = bucket11;
1054 pkt20_index = pkt10_index;
1055 pkt21_index = pkt11_index;
1057 /* Pipeline stage 2 */
1058 lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
1059 bucket20, bucket21, pkts_mask_out, entries,
1060 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,