Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <stdint.h> 7 : : #include <stdlib.h> 8 : : #include <string.h> 9 : : 10 : : #include <rte_cycles.h> 11 : : #include <rte_random.h> 12 : : #include <rte_memory.h> 13 : : #include <rte_fib6.h> 14 : : 15 : : #include "test.h" 16 : : 17 : : #include "test_lpm6_data.h" 18 : : 19 : : #define TEST_FIB_ASSERT(cond) do { \ 20 : : if (!(cond)) { \ 21 : : printf("Error at line %d:\n", __LINE__); \ 22 : : return -1; \ 23 : : } \ 24 : : } while (0) 25 : : 26 : : #define ITERATIONS (1 << 10) 27 : : #define BATCH_SIZE 100000 28 : : #define NUMBER_TBL8S (1 << 16) 29 : : 30 : : static void 31 : 0 : print_route_distribution(const struct rules_tbl_entry *table, uint32_t n) 32 : : { 33 : : unsigned int i, j; 34 : : 35 : : printf("Route distribution per prefix width:\n"); 36 : : printf("DEPTH QUANTITY (PERCENT)\n"); 37 : : printf("---------------------------\n"); 38 : : 39 : : /* Count depths. */ 40 [ # # ]: 0 : for (i = 1; i <= 128; i++) { 41 : : unsigned int depth_counter = 0; 42 : : double percent_hits; 43 : : 44 [ # # ]: 0 : for (j = 0; j < n; j++) 45 [ # # ]: 0 : if (table[j].depth == (uint8_t) i) 46 : 0 : depth_counter++; 47 : : 48 : 0 : percent_hits = ((double)depth_counter)/((double)n) * 100; 49 : : printf("%.2u%15u (%.2f)\n", i, depth_counter, percent_hits); 50 : : } 51 : : printf("\n"); 52 : 0 : } 53 : : 54 : : static inline uint8_t 55 : : bits_in_nh(uint8_t nh_sz) 56 : : { 57 : : return 8 * (1 << nh_sz); 58 : : } 59 : : 60 : : static inline uint64_t 61 : : get_max_nh(uint8_t nh_sz) 62 : : { 63 : : return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1); 64 : : } 65 : : 66 : : static int 67 : 0 : test_fib6_perf(void) 68 : : { 69 : : struct rte_fib6 *fib = NULL; 70 : : struct rte_fib6_conf conf; 71 : : uint64_t begin, total_time; 72 : : unsigned int i, j; 73 : : uint64_t next_hop_add; 74 : : int status = 0; 75 : : int64_t count = 0; 76 : : uint8_t ip_batch[NUM_IPS_ENTRIES][16]; 77 : : uint64_t next_hops[NUM_IPS_ENTRIES]; 78 : : 79 : 0 : conf.type = RTE_FIB6_TRIE; 80 : 0 : conf.default_nh = 0; 81 : 0 : conf.max_routes = 1000000; 82 : 0 : conf.rib_ext_sz = 0; 83 : 0 : conf.trie.nh_sz = RTE_FIB6_TRIE_4B; 84 : 0 : conf.trie.num_tbl8 = RTE_MIN(get_max_nh(conf.trie.nh_sz), 1000000U); 85 : : 86 : 0 : rte_srand(rte_rdtsc()); 87 : : 88 : : printf("No. routes = %u\n", (unsigned int) NUM_ROUTE_ENTRIES); 89 : : 90 : 0 : print_route_distribution(large_route_table, 91 : : (uint32_t)NUM_ROUTE_ENTRIES); 92 : : 93 : : /* Only generate IPv6 address of each item in large IPS table, 94 : : * here next_hop is not needed. 95 : : */ 96 : 0 : generate_large_ips_table(0); 97 : : 98 : 0 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &conf); 99 [ # # ]: 0 : TEST_FIB_ASSERT(fib != NULL); 100 : : 101 : : /* Measure add. */ 102 : : begin = rte_rdtsc(); 103 : : 104 [ # # ]: 0 : for (i = 0; i < NUM_ROUTE_ENTRIES; i++) { 105 : 0 : next_hop_add = (i & ((1 << 14) - 1)) + 1; 106 [ # # ]: 0 : if (rte_fib6_add(fib, large_route_table[i].ip, 107 : 0 : large_route_table[i].depth, next_hop_add) == 0) 108 : 0 : status++; 109 : : } 110 : : /* End Timer. */ 111 : 0 : total_time = rte_rdtsc() - begin; 112 : : 113 : : printf("Unique added entries = %d\n", status); 114 : 0 : printf("Average FIB Add: %g cycles\n", 115 : 0 : (double)total_time / NUM_ROUTE_ENTRIES); 116 : : 117 : : /* Measure bulk Lookup */ 118 : : total_time = 0; 119 : : count = 0; 120 : : 121 [ # # ]: 0 : for (i = 0; i < NUM_IPS_ENTRIES; i++) 122 : 0 : memcpy(ip_batch[i], large_ips_table[i].ip, 16); 123 : : 124 [ # # ]: 0 : for (i = 0; i < ITERATIONS; i++) { 125 : : 126 : : /* Lookup per batch */ 127 : : begin = rte_rdtsc(); 128 : 0 : rte_fib6_lookup_bulk(fib, ip_batch, next_hops, NUM_IPS_ENTRIES); 129 : 0 : total_time += rte_rdtsc() - begin; 130 : : 131 [ # # ]: 0 : for (j = 0; j < NUM_IPS_ENTRIES; j++) 132 [ # # ]: 0 : if (next_hops[j] == 0) 133 : 0 : count++; 134 : : } 135 : 0 : printf("BULK FIB Lookup: %.1f cycles (fails = %.1f%%)\n", 136 : 0 : (double)total_time / ((double)ITERATIONS * BATCH_SIZE), 137 : 0 : (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE)); 138 : : 139 : : /* Delete */ 140 : : status = 0; 141 : : begin = rte_rdtsc(); 142 : : 143 [ # # ]: 0 : for (i = 0; i < NUM_ROUTE_ENTRIES; i++) { 144 : : /* rte_fib_delete(fib, ip, depth) */ 145 : 0 : status += rte_fib6_delete(fib, large_route_table[i].ip, 146 : 0 : large_route_table[i].depth); 147 : : } 148 : : 149 : 0 : total_time = rte_rdtsc() - begin; 150 : : 151 : 0 : printf("Average FIB Delete: %g cycles\n", 152 : 0 : (double)total_time / NUM_ROUTE_ENTRIES); 153 : : 154 : 0 : rte_fib6_free(fib); 155 : : 156 : 0 : return 0; 157 : : } 158 : : 159 : 235 : REGISTER_PERF_TEST(fib6_perf_autotest, test_fib6_perf);