X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest-pipeline%2Fpipeline_hash.c;h=25fb2e0dabea0cd0fb7b3f0ecb752ff36b8de7f6;hb=a7c528e5d71ff3f569898d268f9de129fdfc152b;hp=4598ad4bb83c38762e21daab4a0f65a9346c579c;hpb=48f31ca50cc4b1c4e1b2dc073189f3603aae85cc;p=dpdk.git diff --git a/app/test-pipeline/pipeline_hash.c b/app/test-pipeline/pipeline_hash.c index 4598ad4bb8..25fb2e0dab 100644 --- a/app/test-pipeline/pipeline_hash.c +++ b/app/test-pipeline/pipeline_hash.c @@ -1,34 +1,5 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2016 Intel Corporation */ #include @@ -43,6 +14,8 @@ #include #include +#include +#include #include #include "main.h" @@ -77,6 +50,25 @@ translate_options(uint32_t *special, uint32_t *ext, uint32_t *key_size) case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: *special = 1; *ext = 0; *key_size = 32; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY8: + *special = 0; *ext = 0; *key_size = 8; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY16: + *special = 0; *ext = 0; *key_size = 16; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY32: + *special = 0; *ext = 0; *key_size = 32; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY48: + *special = 0; *ext = 0; *key_size = 48; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY64: + *special = 0; *ext = 0; *key_size = 64; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY80: + *special = 0; *ext = 0; *key_size = 80; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY96: + *special = 0; *ext = 0; *key_size = 96; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY112: + *special = 0; *ext = 0; *key_size = 112; return; + case e_APP_PIPELINE_HASH_CUCKOO_KEY128: + *special = 0; *ext = 0; *key_size = 128; return; + default: rte_panic("Invalid hash table type or key size\n"); } @@ -140,7 +132,6 @@ app_main_loop_worker_pipeline_hash(void) { .ops = &rte_port_ring_writer_ops, .arg_create = (void *) &port_ring_params, .f_action = NULL, - .f_action_bulk = NULL, .arg_ah = NULL, }; @@ -150,23 +141,34 @@ app_main_loop_worker_pipeline_hash(void) { "ring %d\n", i); } + struct rte_table_hash_params table_hash_params = { + .name = "TABLE", + .key_size = key_size, + .key_offset = APP_METADATA_OFFSET(32), + .key_mask = NULL, + .n_keys = 1 << 24, + .n_buckets = 1 << 22, + .f_hash = test_hash, + .seed = 0, + }; + + struct rte_table_hash_cuckoo_params table_hash_cuckoo_params = { + .name = "TABLE", + .key_size = key_size, + .key_offset = APP_METADATA_OFFSET(32), + .key_mask = NULL, + .n_keys = 1 << 24, + .n_buckets = 1 << 22, + .f_hash = test_hash_cuckoo, + .seed = 0, + }; + /* Table configuration */ switch (app.pipeline_type) { case e_APP_PIPELINE_HASH_KEY8_EXT: case e_APP_PIPELINE_HASH_KEY16_EXT: case e_APP_PIPELINE_HASH_KEY32_EXT: { - struct rte_table_hash_ext_params table_hash_params = { - .key_size = key_size, - .n_keys = 1 << 24, - .n_buckets = 1 << 22, - .n_buckets_ext = 1 << 21, - .f_hash = test_hash, - .seed = 0, - .signature_offset = 0, - .key_offset = 32, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_ext_ops, .arg_create = &table_hash_params, @@ -185,16 +187,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_KEY16_LRU: case e_APP_PIPELINE_HASH_KEY32_LRU: { - struct rte_table_hash_lru_params table_hash_params = { - .key_size = key_size, - .n_keys = 1 << 24, - .n_buckets = 1 << 22, - .f_hash = test_hash, - .seed = 0, - .signature_offset = 0, - .key_offset = 32, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_lru_ops, .arg_create = &table_hash_params, @@ -211,15 +203,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT: { - struct rte_table_hash_key8_ext_params table_hash_params = { - .n_entries = 1 << 24, - .n_entries_ext = 1 << 23, - .signature_offset = 0, - .key_offset = 32, - .f_hash = test_hash, - .seed = 0, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_key8_ext_ops, .arg_create = &table_hash_params, @@ -236,14 +219,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU: { - struct rte_table_hash_key8_lru_params table_hash_params = { - .n_entries = 1 << 24, - .signature_offset = 0, - .key_offset = 32, - .f_hash = test_hash, - .seed = 0, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_key8_lru_ops, .arg_create = &table_hash_params, @@ -260,15 +235,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT: { - struct rte_table_hash_key16_ext_params table_hash_params = { - .n_entries = 1 << 24, - .n_entries_ext = 1 << 23, - .signature_offset = 0, - .key_offset = 32, - .f_hash = test_hash, - .seed = 0, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_key16_ext_ops, .arg_create = &table_hash_params, @@ -285,14 +251,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU: { - struct rte_table_hash_key16_lru_params table_hash_params = { - .n_entries = 1 << 24, - .signature_offset = 0, - .key_offset = 32, - .f_hash = test_hash, - .seed = 0, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_key16_lru_ops, .arg_create = &table_hash_params, @@ -309,15 +267,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT: { - struct rte_table_hash_key32_ext_params table_hash_params = { - .n_entries = 1 << 24, - .n_entries_ext = 1 << 23, - .signature_offset = 0, - .key_offset = 32, - .f_hash = test_hash, - .seed = 0, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_key32_ext_ops, .arg_create = &table_hash_params, @@ -335,14 +284,6 @@ app_main_loop_worker_pipeline_hash(void) { case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: { - struct rte_table_hash_key32_lru_params table_hash_params = { - .n_entries = 1 << 24, - .signature_offset = 0, - .key_offset = 32, - .f_hash = test_hash, - .seed = 0, - }; - struct rte_pipeline_table_params table_params = { .ops = &rte_table_hash_key32_lru_ops, .arg_create = &table_hash_params, @@ -357,6 +298,30 @@ app_main_loop_worker_pipeline_hash(void) { } break; + case e_APP_PIPELINE_HASH_CUCKOO_KEY8: + case e_APP_PIPELINE_HASH_CUCKOO_KEY16: + case e_APP_PIPELINE_HASH_CUCKOO_KEY32: + case e_APP_PIPELINE_HASH_CUCKOO_KEY48: + case e_APP_PIPELINE_HASH_CUCKOO_KEY64: + case e_APP_PIPELINE_HASH_CUCKOO_KEY80: + case e_APP_PIPELINE_HASH_CUCKOO_KEY96: + case e_APP_PIPELINE_HASH_CUCKOO_KEY112: + case e_APP_PIPELINE_HASH_CUCKOO_KEY128: + { + struct rte_pipeline_table_params table_params = { + .ops = &rte_table_hash_cuckoo_ops, + .arg_create = &table_hash_cuckoo_params, + .f_action_hit = NULL, + .f_action_miss = NULL, + .arg_ah = NULL, + .action_data_size = 0, + }; + + if (rte_pipeline_table_create(p, &table_params, &table_id)) + rte_panic("Unable to configure the hash table\n"); + } + break; + default: rte_panic("Invalid hash table type or key size\n"); } @@ -415,16 +380,29 @@ app_main_loop_worker_pipeline_hash(void) { uint64_t test_hash( void *key, + __attribute__((unused)) void *key_mask, __attribute__((unused)) uint32_t key_size, __attribute__((unused)) uint64_t seed) { - uint32_t *k32 = (uint32_t *) key; + uint32_t *k32 = key; uint32_t ip_dst = rte_be_to_cpu_32(k32[0]); uint64_t signature = (ip_dst >> 2) | ((ip_dst & 0x3) << 30); return signature; } +uint32_t test_hash_cuckoo( + const void *key, + __attribute__((unused)) uint32_t key_size, + __attribute__((unused)) uint32_t seed) +{ + const uint32_t *k32 = key; + uint32_t ip_dst = rte_be_to_cpu_32(k32[0]); + uint32_t signature = (ip_dst >> 2) | ((ip_dst & 0x3) << 30); + + return signature; +} + void app_main_loop_rx_metadata(void) { uint32_t i, j; @@ -448,40 +426,44 @@ app_main_loop_rx_metadata(void) { for (j = 0; j < n_mbufs; j++) { struct rte_mbuf *m; uint8_t *m_data, *key; - struct ipv4_hdr *ip_hdr; - struct ipv6_hdr *ipv6_hdr; + struct rte_ipv4_hdr *ip_hdr; + struct rte_ipv6_hdr *ipv6_hdr; uint32_t ip_dst; uint8_t *ipv6_dst; uint32_t *signature, *k32; m = app.mbuf_rx.array[j]; m_data = rte_pktmbuf_mtod(m, uint8_t *); - signature = RTE_MBUF_METADATA_UINT32_PTR(m, 0); - key = RTE_MBUF_METADATA_UINT8_PTR(m, 32); - - if (m->ol_flags & PKT_RX_IPV4_HDR) { - ip_hdr = (struct ipv4_hdr *) - &m_data[sizeof(struct ether_hdr)]; + signature = RTE_MBUF_METADATA_UINT32_PTR(m, + APP_METADATA_OFFSET(0)); + key = RTE_MBUF_METADATA_UINT8_PTR(m, + APP_METADATA_OFFSET(32)); + + if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) { + ip_hdr = (struct rte_ipv4_hdr *) + &m_data[sizeof(struct rte_ether_hdr)]; ip_dst = ip_hdr->dst_addr; k32 = (uint32_t *) key; k32[0] = ip_dst & 0xFFFFFF00; - } else { - ipv6_hdr = (struct ipv6_hdr *) - &m_data[sizeof(struct ether_hdr)]; + } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) { + ipv6_hdr = (struct rte_ipv6_hdr *) + &m_data[sizeof(struct rte_ether_hdr)]; ipv6_dst = ipv6_hdr->dst_addr; memcpy(key, ipv6_dst, 16); - } + } else + continue; - *signature = test_hash(key, 0, 0); + *signature = test_hash(key, NULL, 0, 0); } do { ret = rte_ring_sp_enqueue_bulk( app.rings_rx[i], (void **) app.mbuf_rx.array, - n_mbufs); - } while (ret < 0); + n_mbufs, + NULL); + } while (ret == 0); } }