1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
7 #ifdef RTE_EXEC_ENV_WINDOWS
11 printf("lpm6_perf not supported on Windows, skipping test\n");
22 #include <rte_cycles.h>
23 #include <rte_random.h>
24 #include <rte_memory.h>
27 #include "test_lpm6_data.h"
29 #define TEST_LPM_ASSERT(cond) do { \
31 printf("Error at line %d: \n", __LINE__); \
36 #define ITERATIONS (1 << 10)
37 #define BATCH_SIZE 100000
38 #define NUMBER_TBL8S (1 << 16)
41 print_route_distribution(const struct rules_tbl_entry *table, uint32_t n)
45 printf("Route distribution per prefix width: \n");
46 printf("DEPTH QUANTITY (PERCENT)\n");
47 printf("--------------------------- \n");
50 for(i = 1; i <= 128; i++) {
51 unsigned depth_counter = 0;
54 for (j = 0; j < n; j++)
55 if (table[j].depth == (uint8_t) i)
58 percent_hits = ((double)depth_counter)/((double)n) * 100;
59 printf("%.2u%15u (%.2f)\n", i, depth_counter, percent_hits);
67 struct rte_lpm6 *lpm = NULL;
68 struct rte_lpm6_config config;
69 uint64_t begin, total_time;
71 uint32_t next_hop_add = 0xAA, next_hop_return = 0;
75 config.max_rules = 1000000;
76 config.number_tbl8s = NUMBER_TBL8S;
79 rte_srand(rte_rdtsc());
81 printf("No. routes = %u\n", (unsigned) NUM_ROUTE_ENTRIES);
83 print_route_distribution(large_route_table, (uint32_t) NUM_ROUTE_ENTRIES);
85 /* Only generate IPv6 address of each item in large IPS table,
86 * here next_hop is not needed.
88 generate_large_ips_table(0);
90 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
91 TEST_LPM_ASSERT(lpm != NULL);
96 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
97 if (rte_lpm6_add(lpm, large_route_table[i].ip,
98 large_route_table[i].depth, next_hop_add) == 0)
102 total_time = rte_rdtsc() - begin;
104 printf("Unique added entries = %d\n", status);
105 printf("Average LPM Add: %g cycles\n",
106 (double)total_time / NUM_ROUTE_ENTRIES);
108 /* Measure single Lookup */
112 for (i = 0; i < ITERATIONS; i ++) {
115 for (j = 0; j < NUM_IPS_ENTRIES; j ++) {
116 if (rte_lpm6_lookup(lpm, large_ips_table[j].ip,
117 &next_hop_return) != 0)
121 total_time += rte_rdtsc() - begin;
124 printf("Average LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
125 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
126 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
128 /* Measure bulk Lookup */
132 uint8_t ip_batch[NUM_IPS_ENTRIES][16];
133 int32_t next_hops[NUM_IPS_ENTRIES];
135 for (i = 0; i < NUM_IPS_ENTRIES; i++)
136 memcpy(ip_batch[i], large_ips_table[i].ip, 16);
138 for (i = 0; i < ITERATIONS; i ++) {
140 /* Lookup per batch */
142 rte_lpm6_lookup_bulk_func(lpm, ip_batch, next_hops, NUM_IPS_ENTRIES);
143 total_time += rte_rdtsc() - begin;
145 for (j = 0; j < NUM_IPS_ENTRIES; j++)
146 if (next_hops[j] < 0)
149 printf("BULK LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
150 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
151 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
157 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
158 /* rte_lpm_delete(lpm, ip, depth) */
159 status += rte_lpm6_delete(lpm, large_route_table[i].ip,
160 large_route_table[i].depth);
163 total_time += rte_rdtsc() - begin;
165 printf("Average LPM Delete: %g cycles\n",
166 (double)total_time / NUM_ROUTE_ENTRIES);
168 rte_lpm6_delete_all(lpm);
174 #endif /* !RTE_EXEC_ENV_WINDOWS */
176 REGISTER_TEST_COMMAND(lpm6_perf_autotest, test_lpm6_perf);