4 * Copyright(c) 2010-2015 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.
40 #include <sys/queue.h>
42 #include <rte_cycles.h>
43 #include <rte_random.h>
45 #include <rte_jhash.h>
46 #include <rte_hash_crc.h>
50 /*******************************************************************************
51 * Hash function performance test configuration section. Each performance test
52 * will be performed HASHTEST_ITERATIONS times.
54 * The three arrays below control what tests are performed. Every combination
55 * from the array entries is tested.
57 #define HASHTEST_ITERATIONS 1000000
59 static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc};
60 static uint32_t hashtest_initvals[] = {0};
61 static uint32_t hashtest_key_lens[] = {2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21, 31, 32, 33, 63, 64};
62 /******************************************************************************/
65 * To help print out name of hash functions.
68 get_hash_name(rte_hash_function f)
73 if (f == rte_hash_crc)
74 return "rte_hash_crc";
80 * Test a hash function.
83 run_hash_func_perf_test(rte_hash_function f, uint32_t init_val,
86 static uint8_t key[HASHTEST_ITERATIONS][RTE_HASH_KEY_LENGTH_MAX];
87 uint64_t ticks, start, end;
90 for (i = 0; i < HASHTEST_ITERATIONS; i++) {
91 for (j = 0; j < key_len; j++)
92 key[i][j] = (uint8_t) rte_rand();
96 for (i = 0; i < HASHTEST_ITERATIONS; i++)
97 f(key[i], key_len, init_val);
101 printf("%-12s, %-18u, %-13u, %.02f\n", get_hash_name(f), (unsigned) key_len,
102 (unsigned) init_val, (double)ticks / HASHTEST_ITERATIONS);
106 * Test all hash functions.
109 run_hash_func_perf_tests(void)
113 printf(" *** Hash function performance test results ***\n");
114 printf(" Number of iterations for each test = %d\n",
115 HASHTEST_ITERATIONS);
116 printf("Hash Func. , Key Length (bytes), Initial value, Ticks/Op.\n");
119 i < sizeof(hashtest_funcs) / sizeof(rte_hash_function);
122 j < sizeof(hashtest_initvals) / sizeof(uint32_t);
125 k < sizeof(hashtest_key_lens) / sizeof(uint32_t);
127 run_hash_func_perf_test(hashtest_funcs[i],
128 hashtest_initvals[j],
129 hashtest_key_lens[k]);
136 test_hash_functions(void)
138 run_hash_func_perf_tests();
143 static struct test_command hash_functions_cmd = {
144 .command = "hash_functions_autotest",
145 .callback = test_hash_functions,
147 REGISTER_TEST_COMMAND(hash_functions_cmd);