1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 * Copyright(c) 2020 Arm Limited
11 #include <rte_cycles.h>
12 #include <rte_random.h>
13 #include <rte_branch_prediction.h>
14 #include <rte_malloc.h>
19 #include "test_xmmt_ops.h"
22 static struct rte_rcu_qsbr *rv;
23 static volatile uint8_t writer_done;
24 static volatile uint32_t thr_id;
25 static uint64_t gwrite_cycles;
26 /* LPM APIs are not thread safe, use mutex to provide thread safety */
27 static pthread_mutex_t lpm_mutex = PTHREAD_MUTEX_INITIALIZER;
29 /* Report quiescent state interval every 1024 lookups. Larger critical
30 * sections in reader will result in writer polling multiple times.
32 #define QSBR_REPORTING_INTERVAL 1024
34 #define TEST_LPM_ASSERT(cond) do { \
36 printf("Error at line %d: \n", __LINE__); \
41 #define ITERATIONS (1 << 10)
42 #define RCU_ITERATIONS 10
43 #define BATCH_SIZE (1 << 12)
46 #define MAX_RULE_NUM (1200000)
53 static struct route_rule large_route_table[MAX_RULE_NUM];
54 /* Route table for routes with depth > 24 */
55 struct route_rule large_ldepth_route_table[MAX_RULE_NUM];
57 static uint32_t num_route_entries;
58 static uint32_t num_ldepth_route_entries;
59 #define NUM_ROUTE_ENTRIES num_route_entries
60 #define NUM_LDEPTH_ROUTE_ENTRIES num_ldepth_route_entries
62 #define TOTAL_WRITES (RCU_ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES)
70 /* struct route_rule_count defines the total number of rules in following a/b/c
71 * each item in a[]/b[]/c[] is the number of common IP address class A/B/C, not
72 * including the ones for private local network.
74 struct route_rule_count {
75 uint32_t a[RTE_LPM_MAX_DEPTH];
76 uint32_t b[RTE_LPM_MAX_DEPTH];
77 uint32_t c[RTE_LPM_MAX_DEPTH];
80 /* All following numbers of each depth of each common IP class are just
81 * got from previous large constant table in app/test/test_lpm_routes.h .
82 * In order to match similar performance, they keep same depth and IP
83 * address coverage as previous constant table. These numbers don't
84 * include any private local IP address. As previous large const rule
85 * table was just dumped from a real router, there are no any IP address
88 static struct route_rule_count rule_count = {
89 .a = { /* IP class A in which the most significant bit is 0 */
101 144, /* depth = 12 */
102 233, /* depth = 13 */
103 528, /* depth = 14 */
104 866, /* depth = 15 */
105 3856, /* depth = 16 */
106 3268, /* depth = 17 */
107 5662, /* depth = 18 */
108 17301, /* depth = 19 */
109 22226, /* depth = 20 */
110 11147, /* depth = 21 */
111 16746, /* depth = 22 */
112 17120, /* depth = 23 */
113 77578, /* depth = 24 */
114 401, /* depth = 25 */
115 656, /* depth = 26 */
116 1107, /* depth = 27 */
117 1121, /* depth = 28 */
118 2316, /* depth = 29 */
119 717, /* depth = 30 */
123 .b = { /* IP class A in which the most 2 significant bits are 10 */
135 168, /* depth = 12 */
136 305, /* depth = 13 */
137 569, /* depth = 14 */
138 1129, /* depth = 15 */
139 50800, /* depth = 16 */
140 1645, /* depth = 17 */
141 1820, /* depth = 18 */
142 3506, /* depth = 19 */
143 3258, /* depth = 20 */
144 3424, /* depth = 21 */
145 4971, /* depth = 22 */
146 6885, /* depth = 23 */
147 39771, /* depth = 24 */
148 424, /* depth = 25 */
149 170, /* depth = 26 */
150 433, /* depth = 27 */
152 366, /* depth = 29 */
153 377, /* depth = 30 */
157 .c = { /* IP class A in which the most 3 significant bits are 110 */
170 237, /* depth = 13 */
171 1007, /* depth = 14 */
172 1717, /* depth = 15 */
173 14663, /* depth = 16 */
174 8070, /* depth = 17 */
175 16185, /* depth = 18 */
176 48261, /* depth = 19 */
177 36870, /* depth = 20 */
178 33960, /* depth = 21 */
179 50638, /* depth = 22 */
180 61422, /* depth = 23 */
181 466549, /* depth = 24 */
182 1829, /* depth = 25 */
183 4824, /* depth = 26 */
184 4927, /* depth = 27 */
185 5914, /* depth = 28 */
186 10254, /* depth = 29 */
187 4905, /* depth = 30 */
193 static void generate_random_rule_prefix(uint32_t ip_class, uint8_t depth)
195 /* IP address class A, the most significant bit is 0 */
196 #define IP_HEAD_MASK_A 0x00000000
197 #define IP_HEAD_BIT_NUM_A 1
199 /* IP address class B, the most significant 2 bits are 10 */
200 #define IP_HEAD_MASK_B 0x80000000
201 #define IP_HEAD_BIT_NUM_B 2
203 /* IP address class C, the most significant 3 bits are 110 */
204 #define IP_HEAD_MASK_C 0xC0000000
205 #define IP_HEAD_BIT_NUM_C 3
207 uint32_t class_depth;
212 uint32_t fixed_bit_num;
213 uint32_t ip_head_mask;
216 struct route_rule *ptr_rule, *ptr_ldepth_rule;
218 if (ip_class == IP_CLASS_A) { /* IP Address class A */
219 fixed_bit_num = IP_HEAD_BIT_NUM_A;
220 ip_head_mask = IP_HEAD_MASK_A;
221 rule_num = rule_count.a[depth - 1];
222 } else if (ip_class == IP_CLASS_B) { /* IP Address class B */
223 fixed_bit_num = IP_HEAD_BIT_NUM_B;
224 ip_head_mask = IP_HEAD_MASK_B;
225 rule_num = rule_count.b[depth - 1];
226 } else { /* IP Address class C */
227 fixed_bit_num = IP_HEAD_BIT_NUM_C;
228 ip_head_mask = IP_HEAD_MASK_C;
229 rule_num = rule_count.c[depth - 1];
235 /* the number of rest bits which don't include the most significant
236 * fixed bits for this IP address class
238 class_depth = depth - fixed_bit_num;
240 /* range is the maximum number of rules for this depth and
241 * this IP address class
243 range = 1 << class_depth;
245 /* only mask the most depth significant generated bits
246 * except fixed bits for IP address class
250 /* Widen coverage of IP address in generated rules */
251 if (range <= rule_num)
254 step = round((double)range / rule_num);
256 /* Only generate rest bits except the most significant
257 * fixed bits for IP address class
259 start = lrand48() & mask;
260 ptr_rule = &large_route_table[num_route_entries];
261 ptr_ldepth_rule = &large_ldepth_route_table[num_ldepth_route_entries];
262 for (k = 0; k < rule_num; k++) {
263 ptr_rule->ip = (start << (RTE_LPM_MAX_DEPTH - depth))
265 ptr_rule->depth = depth;
266 /* If the depth of the route is more than 24, store it
267 * in another table as well.
270 ptr_ldepth_rule->ip = ptr_rule->ip;
271 ptr_ldepth_rule->depth = ptr_rule->depth;
273 num_ldepth_route_entries++;
276 start = (start + step) & mask;
278 num_route_entries += rule_num;
281 static void insert_rule_in_random_pos(uint32_t ip, uint8_t depth)
285 struct route_rule tmp;
290 } while ((try_count < 10) && (pos > num_route_entries));
292 if ((pos > num_route_entries) || (pos >= MAX_RULE_NUM))
293 pos = num_route_entries >> 1;
295 tmp = large_route_table[pos];
296 large_route_table[pos].ip = ip;
297 large_route_table[pos].depth = depth;
298 if (num_route_entries < MAX_RULE_NUM)
299 large_route_table[num_route_entries++] = tmp;
302 static void generate_large_route_rule_table(void)
307 num_route_entries = 0;
308 num_ldepth_route_entries = 0;
309 memset(large_route_table, 0, sizeof(large_route_table));
311 for (ip_class = IP_CLASS_A; ip_class <= IP_CLASS_C; ip_class++) {
312 for (depth = 1; depth <= RTE_LPM_MAX_DEPTH; depth++) {
313 generate_random_rule_prefix(ip_class, depth);
317 /* Add following rules to keep same as previous large constant table,
318 * they are 4 rules with private local IP address and 1 all-zeros prefix
321 insert_rule_in_random_pos(RTE_IPV4(0, 0, 0, 0), 8);
322 insert_rule_in_random_pos(RTE_IPV4(10, 2, 23, 147), 32);
323 insert_rule_in_random_pos(RTE_IPV4(192, 168, 100, 10), 24);
324 insert_rule_in_random_pos(RTE_IPV4(192, 168, 25, 100), 24);
325 insert_rule_in_random_pos(RTE_IPV4(192, 168, 129, 124), 32);
329 print_route_distribution(const struct route_rule *table, uint32_t n)
333 printf("Route distribution per prefix width: \n");
334 printf("DEPTH QUANTITY (PERCENT)\n");
335 printf("--------------------------- \n");
338 for (i = 1; i <= 32; i++) {
339 unsigned depth_counter = 0;
342 for (j = 0; j < n; j++)
343 if (table[j].depth == (uint8_t) i)
346 percent_hits = ((double)depth_counter)/((double)n) * 100;
347 printf("%.2u%15u (%.2f)\n", i, depth_counter, percent_hits);
352 /* Check condition and return an error if true. */
353 static uint16_t enabled_core_ids[RTE_MAX_LCORE];
354 static unsigned int num_cores;
356 /* Simple way to allocate thread ids in 0 to RTE_MAX_LCORE space */
357 static inline uint32_t
358 alloc_thread_id(void)
362 tmp_thr_id = __atomic_fetch_add(&thr_id, 1, __ATOMIC_RELAXED);
363 if (tmp_thr_id >= RTE_MAX_LCORE)
364 printf("Invalid thread id %u\n", tmp_thr_id);
370 * Reader thread using rte_lpm data structure without RCU.
373 test_lpm_reader(void *arg)
376 uint32_t ip_batch[QSBR_REPORTING_INTERVAL];
377 uint32_t next_hop_return = 0;
381 for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
382 ip_batch[i] = rte_rand();
384 for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
385 rte_lpm_lookup(lpm, ip_batch[i], &next_hop_return);
387 } while (!writer_done);
393 * Reader thread using rte_lpm data structure with RCU.
396 test_lpm_rcu_qsbr_reader(void *arg)
399 uint32_t thread_id = alloc_thread_id();
400 uint32_t ip_batch[QSBR_REPORTING_INTERVAL];
401 uint32_t next_hop_return = 0;
404 /* Register this thread to report quiescent state */
405 rte_rcu_qsbr_thread_register(rv, thread_id);
406 rte_rcu_qsbr_thread_online(rv, thread_id);
409 for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
410 ip_batch[i] = rte_rand();
412 for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
413 rte_lpm_lookup(lpm, ip_batch[i], &next_hop_return);
415 /* Update quiescent state */
416 rte_rcu_qsbr_quiescent(rv, thread_id);
417 } while (!writer_done);
419 rte_rcu_qsbr_thread_offline(rv, thread_id);
420 rte_rcu_qsbr_thread_unregister(rv, thread_id);
426 * Writer thread using rte_lpm data structure with RCU.
429 test_lpm_rcu_qsbr_writer(void *arg)
431 unsigned int i, j, si, ei;
432 uint64_t begin, total_cycles;
433 uint8_t core_id = (uint8_t)((uintptr_t)arg);
434 uint32_t next_hop_add = 0xAA;
436 /* 2 writer threads are used */
437 if (core_id % 2 == 0) {
439 ei = NUM_LDEPTH_ROUTE_ENTRIES / 2;
441 si = NUM_LDEPTH_ROUTE_ENTRIES / 2;
442 ei = NUM_LDEPTH_ROUTE_ENTRIES;
445 /* Measure add/delete. */
446 begin = rte_rdtsc_precise();
447 for (i = 0; i < RCU_ITERATIONS; i++) {
448 /* Add all the entries */
449 for (j = si; j < ei; j++) {
450 pthread_mutex_lock(&lpm_mutex);
451 if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip,
452 large_ldepth_route_table[j].depth,
453 next_hop_add) != 0) {
454 printf("Failed to add iteration %d, route# %d\n",
458 pthread_mutex_unlock(&lpm_mutex);
461 /* Delete all the entries */
462 for (j = si; j < ei; j++) {
463 pthread_mutex_lock(&lpm_mutex);
464 if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
465 large_ldepth_route_table[j].depth) != 0) {
466 printf("Failed to delete iteration %d, route# %d\n",
470 pthread_mutex_unlock(&lpm_mutex);
474 total_cycles = rte_rdtsc_precise() - begin;
476 __atomic_fetch_add(&gwrite_cycles, total_cycles, __ATOMIC_RELAXED);
481 pthread_mutex_unlock(&lpm_mutex);
487 * 2 writers, rest are readers
490 test_lpm_rcu_perf_multi_writer(void)
492 struct rte_lpm_config config;
496 struct rte_lpm_rcu_config rcu_cfg = {0};
498 if (rte_lcore_count() < 3) {
499 printf("Not enough cores for lpm_rcu_perf_autotest, expecting at least 3\n");
504 RTE_LCORE_FOREACH_WORKER(core_id) {
505 enabled_core_ids[num_cores] = core_id;
509 printf("\nPerf test: 2 writers, %d readers, RCU integration enabled\n",
512 /* Create LPM table */
513 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
514 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
516 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
517 TEST_LPM_ASSERT(lpm != NULL);
519 /* Init RCU variable */
520 sz = rte_rcu_qsbr_get_memsize(num_cores);
521 rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz,
522 RTE_CACHE_LINE_SIZE);
523 rte_rcu_qsbr_init(rv, num_cores);
526 /* Assign the RCU variable to LPM */
527 if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) {
528 printf("RCU variable assignment failed\n");
533 __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED);
535 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
537 /* Launch reader threads */
538 for (i = 2; i < num_cores; i++)
539 rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL,
540 enabled_core_ids[i]);
542 /* Launch writer threads */
543 for (i = 0; i < 2; i++)
544 rte_eal_remote_launch(test_lpm_rcu_qsbr_writer,
545 (void *)(uintptr_t)i,
546 enabled_core_ids[i]);
548 /* Wait for writer threads */
549 for (i = 0; i < 2; i++)
550 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
553 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
554 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
555 printf("Average LPM Add/Del: %"PRIu64" cycles\n",
556 __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED)
560 /* Wait until all readers have exited */
561 for (i = 2; i < num_cores; i++)
562 rte_eal_wait_lcore(enabled_core_ids[i]);
569 /* Test without RCU integration */
570 printf("\nPerf test: 2 writers, %d readers, RCU integration disabled\n",
573 /* Create LPM table */
574 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
575 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
577 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
578 TEST_LPM_ASSERT(lpm != NULL);
581 __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED);
582 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
584 /* Launch reader threads */
585 for (i = 2; i < num_cores; i++)
586 rte_eal_remote_launch(test_lpm_reader, NULL,
587 enabled_core_ids[i]);
589 /* Launch writer threads */
590 for (i = 0; i < 2; i++)
591 rte_eal_remote_launch(test_lpm_rcu_qsbr_writer,
592 (void *)(uintptr_t)i,
593 enabled_core_ids[i]);
595 /* Wait for writer threads */
596 for (i = 0; i < 2; i++)
597 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
600 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
601 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
602 printf("Average LPM Add/Del: %"PRIu64" cycles\n",
603 __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED)
607 /* Wait until all readers have exited */
608 for (i = 2; i < num_cores; i++)
609 rte_eal_wait_lcore(enabled_core_ids[i]);
617 /* Wait until all readers have exited */
618 rte_eal_mp_wait_lcore();
628 * Single writer, rest are readers
631 test_lpm_rcu_perf(void)
633 struct rte_lpm_config config;
634 uint64_t begin, total_cycles;
638 uint32_t next_hop_add = 0xAA;
639 struct rte_lpm_rcu_config rcu_cfg = {0};
641 if (rte_lcore_count() < 2) {
642 printf("Not enough cores for lpm_rcu_perf_autotest, expecting at least 2\n");
647 RTE_LCORE_FOREACH_WORKER(core_id) {
648 enabled_core_ids[num_cores] = core_id;
652 printf("\nPerf test: 1 writer, %d readers, RCU integration enabled\n",
655 /* Create LPM table */
656 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
657 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
659 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
660 TEST_LPM_ASSERT(lpm != NULL);
662 /* Init RCU variable */
663 sz = rte_rcu_qsbr_get_memsize(num_cores);
664 rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz,
665 RTE_CACHE_LINE_SIZE);
666 rte_rcu_qsbr_init(rv, num_cores);
669 /* Assign the RCU variable to LPM */
670 if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) {
671 printf("RCU variable assignment failed\n");
676 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
678 /* Launch reader threads */
679 for (i = 0; i < num_cores; i++)
680 rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL,
681 enabled_core_ids[i]);
683 /* Measure add/delete. */
684 begin = rte_rdtsc_precise();
685 for (i = 0; i < RCU_ITERATIONS; i++) {
686 /* Add all the entries */
687 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
688 if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip,
689 large_ldepth_route_table[j].depth,
690 next_hop_add) != 0) {
691 printf("Failed to add iteration %d, route# %d\n",
696 /* Delete all the entries */
697 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
698 if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
699 large_ldepth_route_table[j].depth) != 0) {
700 printf("Failed to delete iteration %d, route# %d\n",
705 total_cycles = rte_rdtsc_precise() - begin;
707 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
708 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
709 printf("Average LPM Add/Del: %g cycles\n",
710 (double)total_cycles / TOTAL_WRITES);
713 /* Wait until all readers have exited */
714 for (i = 0; i < num_cores; i++)
715 rte_eal_wait_lcore(enabled_core_ids[i]);
722 /* Test without RCU integration */
723 printf("\nPerf test: 1 writer, %d readers, RCU integration disabled\n",
726 /* Create LPM table */
727 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
728 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
730 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
731 TEST_LPM_ASSERT(lpm != NULL);
734 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
736 /* Launch reader threads */
737 for (i = 0; i < num_cores; i++)
738 rte_eal_remote_launch(test_lpm_reader, NULL,
739 enabled_core_ids[i]);
741 /* Measure add/delete. */
742 begin = rte_rdtsc_precise();
743 for (i = 0; i < RCU_ITERATIONS; i++) {
744 /* Add all the entries */
745 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
746 if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip,
747 large_ldepth_route_table[j].depth,
748 next_hop_add) != 0) {
749 printf("Failed to add iteration %d, route# %d\n",
754 /* Delete all the entries */
755 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
756 if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
757 large_ldepth_route_table[j].depth) != 0) {
758 printf("Failed to delete iteration %d, route# %d\n",
763 total_cycles = rte_rdtsc_precise() - begin;
765 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
766 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
767 printf("Average LPM Add/Del: %g cycles\n",
768 (double)total_cycles / TOTAL_WRITES);
771 /* Wait until all readers have exited */
772 for (i = 0; i < num_cores; i++)
773 rte_eal_wait_lcore(enabled_core_ids[i]);
781 /* Wait until all readers have exited */
782 rte_eal_mp_wait_lcore();
793 struct rte_lpm_config config;
795 config.max_rules = 2000000;
796 config.number_tbl8s = 2048;
798 uint64_t begin, total_time, lpm_used_entries = 0;
800 uint32_t next_hop_add = 0xAA, next_hop_return = 0;
802 uint64_t cache_line_counter = 0;
805 rte_srand(rte_rdtsc());
807 generate_large_route_rule_table();
809 printf("No. routes = %u\n", (unsigned) NUM_ROUTE_ENTRIES);
811 print_route_distribution(large_route_table, (uint32_t) NUM_ROUTE_ENTRIES);
813 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
814 TEST_LPM_ASSERT(lpm != NULL);
819 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
820 if (rte_lpm_add(lpm, large_route_table[i].ip,
821 large_route_table[i].depth, next_hop_add) == 0)
825 total_time = rte_rdtsc() - begin;
827 printf("Unique added entries = %d\n", status);
828 /* Obtain add statistics. */
829 for (i = 0; i < RTE_LPM_TBL24_NUM_ENTRIES; i++) {
830 if (lpm->tbl24[i].valid)
834 if ((uint64_t)count < lpm_used_entries) {
835 cache_line_counter++;
836 count = lpm_used_entries;
841 printf("Used table 24 entries = %u (%g%%)\n",
842 (unsigned) lpm_used_entries,
843 (lpm_used_entries * 100.0) / RTE_LPM_TBL24_NUM_ENTRIES);
844 printf("64 byte Cache entries used = %u (%u bytes)\n",
845 (unsigned) cache_line_counter, (unsigned) cache_line_counter * 64);
847 printf("Average LPM Add: %g cycles\n",
848 (double)total_time / NUM_ROUTE_ENTRIES);
850 /* Measure single Lookup */
854 for (i = 0; i < ITERATIONS; i++) {
855 static uint32_t ip_batch[BATCH_SIZE];
857 for (j = 0; j < BATCH_SIZE; j++)
858 ip_batch[j] = rte_rand();
860 /* Lookup per batch */
863 for (j = 0; j < BATCH_SIZE; j++) {
864 if (rte_lpm_lookup(lpm, ip_batch[j], &next_hop_return) != 0)
868 total_time += rte_rdtsc() - begin;
871 printf("Average LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
872 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
873 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
875 /* Measure bulk Lookup */
878 for (i = 0; i < ITERATIONS; i++) {
879 static uint32_t ip_batch[BATCH_SIZE];
880 uint32_t next_hops[BULK_SIZE];
882 /* Create array of random IP addresses */
883 for (j = 0; j < BATCH_SIZE; j++)
884 ip_batch[j] = rte_rand();
886 /* Lookup per batch */
888 for (j = 0; j < BATCH_SIZE; j += BULK_SIZE) {
890 rte_lpm_lookup_bulk(lpm, &ip_batch[j], next_hops, BULK_SIZE);
891 for (k = 0; k < BULK_SIZE; k++)
892 if (unlikely(!(next_hops[k] & RTE_LPM_LOOKUP_SUCCESS)))
896 total_time += rte_rdtsc() - begin;
898 printf("BULK LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
899 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
900 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
902 /* Measure LookupX4 */
905 for (i = 0; i < ITERATIONS; i++) {
906 static uint32_t ip_batch[BATCH_SIZE];
907 uint32_t next_hops[4];
909 /* Create array of random IP addresses */
910 for (j = 0; j < BATCH_SIZE; j++)
911 ip_batch[j] = rte_rand();
913 /* Lookup per batch */
915 for (j = 0; j < BATCH_SIZE; j += RTE_DIM(next_hops)) {
919 ipx4 = vect_loadu_sil128((xmm_t *)(ip_batch + j));
920 ipx4 = *(xmm_t *)(ip_batch + j);
921 rte_lpm_lookupx4(lpm, ipx4, next_hops, UINT32_MAX);
922 for (k = 0; k < RTE_DIM(next_hops); k++)
923 if (unlikely(next_hops[k] == UINT32_MAX))
927 total_time += rte_rdtsc() - begin;
929 printf("LPM LookupX4: %.1f cycles (fails = %.1f%%)\n",
930 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
931 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
937 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
938 /* rte_lpm_delete(lpm, ip, depth) */
939 status += rte_lpm_delete(lpm, large_route_table[i].ip,
940 large_route_table[i].depth);
943 total_time = rte_rdtsc() - begin;
945 printf("Average LPM Delete: %g cycles\n",
946 (double)total_time / NUM_ROUTE_ENTRIES);
948 rte_lpm_delete_all(lpm);
951 if (test_lpm_rcu_perf() < 0)
954 if (test_lpm_rcu_perf_multi_writer() < 0)
960 REGISTER_TEST_COMMAND(lpm_perf_autotest, test_lpm_perf);