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