]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/app/test/test_lpm6_perf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <rte_cycles.h>
11 #include <rte_random.h>
12 #include <rte_memory.h>
16 #include "test_lpm6_data.h"
18 #define TEST_LPM_ASSERT(cond) do { \
20 printf("Error at line %d: \n", __LINE__); \
25 #define ITERATIONS (1 << 10)
26 #define BATCH_SIZE 100000
27 #define NUMBER_TBL8S (1 << 16)
30 print_route_distribution(const struct rules_tbl_entry
*table
, uint32_t n
)
34 printf("Route distribution per prefix width: \n");
35 printf("DEPTH QUANTITY (PERCENT)\n");
36 printf("--------------------------- \n");
39 for(i
= 1; i
<= 128; i
++) {
40 unsigned depth_counter
= 0;
43 for (j
= 0; j
< n
; j
++)
44 if (table
[j
].depth
== (uint8_t) i
)
47 percent_hits
= ((double)depth_counter
)/((double)n
) * 100;
48 printf("%.2u%15u (%.2f)\n", i
, depth_counter
, percent_hits
);
56 struct rte_lpm6
*lpm
= NULL
;
57 struct rte_lpm6_config config
;
58 uint64_t begin
, total_time
;
60 uint32_t next_hop_add
= 0xAA, next_hop_return
= 0;
64 config
.max_rules
= 1000000;
65 config
.number_tbl8s
= NUMBER_TBL8S
;
68 rte_srand(rte_rdtsc());
70 printf("No. routes = %u\n", (unsigned) NUM_ROUTE_ENTRIES
);
72 print_route_distribution(large_route_table
, (uint32_t) NUM_ROUTE_ENTRIES
);
74 /* Only generate IPv6 address of each item in large IPS table,
75 * here next_hop is not needed.
77 generate_large_ips_table(0);
79 lpm
= rte_lpm6_create(__func__
, SOCKET_ID_ANY
, &config
);
80 TEST_LPM_ASSERT(lpm
!= NULL
);
85 for (i
= 0; i
< NUM_ROUTE_ENTRIES
; i
++) {
86 if (rte_lpm6_add(lpm
, large_route_table
[i
].ip
,
87 large_route_table
[i
].depth
, next_hop_add
) == 0)
91 total_time
= rte_rdtsc() - begin
;
93 printf("Unique added entries = %d\n", status
);
94 printf("Average LPM Add: %g cycles\n",
95 (double)total_time
/ NUM_ROUTE_ENTRIES
);
97 /* Measure single Lookup */
101 for (i
= 0; i
< ITERATIONS
; i
++) {
104 for (j
= 0; j
< NUM_IPS_ENTRIES
; j
++) {
105 if (rte_lpm6_lookup(lpm
, large_ips_table
[j
].ip
,
106 &next_hop_return
) != 0)
110 total_time
+= rte_rdtsc() - begin
;
113 printf("Average LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
114 (double)total_time
/ ((double)ITERATIONS
* BATCH_SIZE
),
115 (count
* 100.0) / (double)(ITERATIONS
* BATCH_SIZE
));
117 /* Measure bulk Lookup */
121 uint8_t ip_batch
[NUM_IPS_ENTRIES
][16];
122 int32_t next_hops
[NUM_IPS_ENTRIES
];
124 for (i
= 0; i
< NUM_IPS_ENTRIES
; i
++)
125 memcpy(ip_batch
[i
], large_ips_table
[i
].ip
, 16);
127 for (i
= 0; i
< ITERATIONS
; i
++) {
129 /* Lookup per batch */
131 rte_lpm6_lookup_bulk_func(lpm
, ip_batch
, next_hops
, NUM_IPS_ENTRIES
);
132 total_time
+= rte_rdtsc() - begin
;
134 for (j
= 0; j
< NUM_IPS_ENTRIES
; j
++)
135 if (next_hops
[j
] < 0)
138 printf("BULK LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
139 (double)total_time
/ ((double)ITERATIONS
* BATCH_SIZE
),
140 (count
* 100.0) / (double)(ITERATIONS
* BATCH_SIZE
));
146 for (i
= 0; i
< NUM_ROUTE_ENTRIES
; i
++) {
147 /* rte_lpm_delete(lpm, ip, depth) */
148 status
+= rte_lpm6_delete(lpm
, large_route_table
[i
].ip
,
149 large_route_table
[i
].depth
);
152 total_time
+= rte_rdtsc() - begin
;
154 printf("Average LPM Delete: %g cycles\n",
155 (double)total_time
/ NUM_ROUTE_ENTRIES
);
157 rte_lpm6_delete_all(lpm
);
163 REGISTER_TEST_COMMAND(lpm6_perf_autotest
, test_lpm6_perf
);