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",
457 pthread_mutex_unlock(&lpm_mutex);
460 /* Delete all the entries */
461 for (j = si; j < ei; j++) {
462 pthread_mutex_lock(&lpm_mutex);
463 if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
464 large_ldepth_route_table[j].depth) != 0) {
465 printf("Failed to delete iteration %d, route# %d\n",
468 pthread_mutex_unlock(&lpm_mutex);
472 total_cycles = rte_rdtsc_precise() - begin;
474 __atomic_fetch_add(&gwrite_cycles, total_cycles, __ATOMIC_RELAXED);
481 * 2 writers, rest are readers
484 test_lpm_rcu_perf_multi_writer(void)
486 struct rte_lpm_config config;
490 struct rte_lpm_rcu_config rcu_cfg = {0};
492 if (rte_lcore_count() < 3) {
493 printf("Not enough cores for lpm_rcu_perf_autotest, expecting at least 3\n");
498 RTE_LCORE_FOREACH_WORKER(core_id) {
499 enabled_core_ids[num_cores] = core_id;
503 printf("\nPerf test: 2 writers, %d readers, RCU integration enabled\n",
506 /* Create LPM table */
507 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
508 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
510 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
511 TEST_LPM_ASSERT(lpm != NULL);
513 /* Init RCU variable */
514 sz = rte_rcu_qsbr_get_memsize(num_cores);
515 rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz,
516 RTE_CACHE_LINE_SIZE);
517 rte_rcu_qsbr_init(rv, num_cores);
520 /* Assign the RCU variable to LPM */
521 if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) {
522 printf("RCU variable assignment failed\n");
527 __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED);
529 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
531 /* Launch reader threads */
532 for (i = 2; i < num_cores; i++)
533 rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL,
534 enabled_core_ids[i]);
536 /* Launch writer threads */
537 for (i = 0; i < 2; i++)
538 rte_eal_remote_launch(test_lpm_rcu_qsbr_writer,
539 (void *)(uintptr_t)i,
540 enabled_core_ids[i]);
542 /* Wait for writer threads */
543 for (i = 0; i < 2; i++)
544 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
547 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
548 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
549 printf("Average LPM Add/Del: %"PRIu64" cycles\n",
550 __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED)
553 /* Wait and check return value from reader threads */
555 for (i = 2; i < num_cores; i++)
556 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
564 /* Test without RCU integration */
565 printf("\nPerf test: 2 writers, %d readers, RCU integration disabled\n",
568 /* Create LPM table */
569 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
570 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
572 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
573 TEST_LPM_ASSERT(lpm != NULL);
576 __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED);
577 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
579 /* Launch reader threads */
580 for (i = 2; i < num_cores; i++)
581 rte_eal_remote_launch(test_lpm_reader, NULL,
582 enabled_core_ids[i]);
584 /* Launch writer threads */
585 for (i = 0; i < 2; i++)
586 rte_eal_remote_launch(test_lpm_rcu_qsbr_writer,
587 (void *)(uintptr_t)i,
588 enabled_core_ids[i]);
590 /* Wait for writer threads */
591 for (i = 0; i < 2; i++)
592 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
595 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
596 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
597 printf("Average LPM Add/Del: %"PRIu64" cycles\n",
598 __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED)
602 /* Wait and check return value from reader threads */
603 for (i = 2; i < num_cores; i++)
604 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
613 /* Wait until all readers have exited */
614 rte_eal_mp_wait_lcore();
624 * Single writer, rest are readers
627 test_lpm_rcu_perf(void)
629 struct rte_lpm_config config;
630 uint64_t begin, total_cycles;
634 uint32_t next_hop_add = 0xAA;
635 struct rte_lpm_rcu_config rcu_cfg = {0};
637 if (rte_lcore_count() < 2) {
638 printf("Not enough cores for lpm_rcu_perf_autotest, expecting at least 2\n");
643 RTE_LCORE_FOREACH_WORKER(core_id) {
644 enabled_core_ids[num_cores] = core_id;
648 printf("\nPerf test: 1 writer, %d readers, RCU integration enabled\n",
651 /* Create LPM table */
652 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
653 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
655 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
656 TEST_LPM_ASSERT(lpm != NULL);
658 /* Init RCU variable */
659 sz = rte_rcu_qsbr_get_memsize(num_cores);
660 rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz,
661 RTE_CACHE_LINE_SIZE);
662 rte_rcu_qsbr_init(rv, num_cores);
665 /* Assign the RCU variable to LPM */
666 if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) {
667 printf("RCU variable assignment failed\n");
672 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
674 /* Launch reader threads */
675 for (i = 0; i < num_cores; i++)
676 rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL,
677 enabled_core_ids[i]);
679 /* Measure add/delete. */
680 begin = rte_rdtsc_precise();
681 for (i = 0; i < RCU_ITERATIONS; i++) {
682 /* Add all the entries */
683 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
684 if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip,
685 large_ldepth_route_table[j].depth,
686 next_hop_add) != 0) {
687 printf("Failed to add iteration %d, route# %d\n",
692 /* Delete all the entries */
693 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
694 if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
695 large_ldepth_route_table[j].depth) != 0) {
696 printf("Failed to delete iteration %d, route# %d\n",
701 total_cycles = rte_rdtsc_precise() - begin;
703 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
704 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
705 printf("Average LPM Add/Del: %g cycles\n",
706 (double)total_cycles / TOTAL_WRITES);
709 /* Wait and check return value from reader threads */
710 for (i = 0; i < num_cores; i++)
711 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
719 /* Test without RCU integration */
720 printf("\nPerf test: 1 writer, %d readers, RCU integration disabled\n",
723 /* Create LPM table */
724 config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES;
725 config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES;
727 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
728 TEST_LPM_ASSERT(lpm != NULL);
731 __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST);
733 /* Launch reader threads */
734 for (i = 0; i < num_cores; i++)
735 rte_eal_remote_launch(test_lpm_reader, NULL,
736 enabled_core_ids[i]);
738 /* Measure add/delete. */
739 begin = rte_rdtsc_precise();
740 for (i = 0; i < RCU_ITERATIONS; i++) {
741 /* Add all the entries */
742 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
743 if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip,
744 large_ldepth_route_table[j].depth,
745 next_hop_add) != 0) {
746 printf("Failed to add iteration %d, route# %d\n",
751 /* Delete all the entries */
752 for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++)
753 if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
754 large_ldepth_route_table[j].depth) != 0) {
755 printf("Failed to delete iteration %d, route# %d\n",
760 total_cycles = rte_rdtsc_precise() - begin;
762 printf("Total LPM Adds: %d\n", TOTAL_WRITES);
763 printf("Total LPM Deletes: %d\n", TOTAL_WRITES);
764 printf("Average LPM Add/Del: %g cycles\n",
765 (double)total_cycles / TOTAL_WRITES);
768 /* Wait and check return value from reader threads */
769 for (i = 0; i < num_cores; i++)
770 if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0)
771 printf("Warning: lcore %u not finished.\n",
772 enabled_core_ids[i]);
780 /* Wait until all readers have exited */
781 rte_eal_mp_wait_lcore();
792 struct rte_lpm_config config;
794 config.max_rules = 2000000;
795 config.number_tbl8s = 2048;
797 uint64_t begin, total_time, lpm_used_entries = 0;
799 uint32_t next_hop_add = 0xAA, next_hop_return = 0;
801 uint64_t cache_line_counter = 0;
804 rte_srand(rte_rdtsc());
806 generate_large_route_rule_table();
808 printf("No. routes = %u\n", (unsigned) NUM_ROUTE_ENTRIES);
810 print_route_distribution(large_route_table, (uint32_t) NUM_ROUTE_ENTRIES);
812 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
813 TEST_LPM_ASSERT(lpm != NULL);
818 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
819 if (rte_lpm_add(lpm, large_route_table[i].ip,
820 large_route_table[i].depth, next_hop_add) == 0)
824 total_time = rte_rdtsc() - begin;
826 printf("Unique added entries = %d\n", status);
827 /* Obtain add statistics. */
828 for (i = 0; i < RTE_LPM_TBL24_NUM_ENTRIES; i++) {
829 if (lpm->tbl24[i].valid)
833 if ((uint64_t)count < lpm_used_entries) {
834 cache_line_counter++;
835 count = lpm_used_entries;
840 printf("Used table 24 entries = %u (%g%%)\n",
841 (unsigned) lpm_used_entries,
842 (lpm_used_entries * 100.0) / RTE_LPM_TBL24_NUM_ENTRIES);
843 printf("64 byte Cache entries used = %u (%u bytes)\n",
844 (unsigned) cache_line_counter, (unsigned) cache_line_counter * 64);
846 printf("Average LPM Add: %g cycles\n",
847 (double)total_time / NUM_ROUTE_ENTRIES);
849 /* Measure single Lookup */
853 for (i = 0; i < ITERATIONS; i++) {
854 static uint32_t ip_batch[BATCH_SIZE];
856 for (j = 0; j < BATCH_SIZE; j++)
857 ip_batch[j] = rte_rand();
859 /* Lookup per batch */
862 for (j = 0; j < BATCH_SIZE; j++) {
863 if (rte_lpm_lookup(lpm, ip_batch[j], &next_hop_return) != 0)
867 total_time += rte_rdtsc() - begin;
870 printf("Average LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
871 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
872 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
874 /* Measure bulk Lookup */
877 for (i = 0; i < ITERATIONS; i++) {
878 static uint32_t ip_batch[BATCH_SIZE];
879 uint32_t next_hops[BULK_SIZE];
881 /* Create array of random IP addresses */
882 for (j = 0; j < BATCH_SIZE; j++)
883 ip_batch[j] = rte_rand();
885 /* Lookup per batch */
887 for (j = 0; j < BATCH_SIZE; j += BULK_SIZE) {
889 rte_lpm_lookup_bulk(lpm, &ip_batch[j], next_hops, BULK_SIZE);
890 for (k = 0; k < BULK_SIZE; k++)
891 if (unlikely(!(next_hops[k] & RTE_LPM_LOOKUP_SUCCESS)))
895 total_time += rte_rdtsc() - begin;
897 printf("BULK LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
898 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
899 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
901 /* Measure LookupX4 */
904 for (i = 0; i < ITERATIONS; i++) {
905 static uint32_t ip_batch[BATCH_SIZE];
906 uint32_t next_hops[4];
908 /* Create array of random IP addresses */
909 for (j = 0; j < BATCH_SIZE; j++)
910 ip_batch[j] = rte_rand();
912 /* Lookup per batch */
914 for (j = 0; j < BATCH_SIZE; j += RTE_DIM(next_hops)) {
918 ipx4 = vect_loadu_sil128((xmm_t *)(ip_batch + j));
919 ipx4 = *(xmm_t *)(ip_batch + j);
920 rte_lpm_lookupx4(lpm, ipx4, next_hops, UINT32_MAX);
921 for (k = 0; k < RTE_DIM(next_hops); k++)
922 if (unlikely(next_hops[k] == UINT32_MAX))
926 total_time += rte_rdtsc() - begin;
928 printf("LPM LookupX4: %.1f cycles (fails = %.1f%%)\n",
929 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
930 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
936 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
937 /* rte_lpm_delete(lpm, ip, depth) */
938 status += rte_lpm_delete(lpm, large_route_table[i].ip,
939 large_route_table[i].depth);
942 total_time = rte_rdtsc() - begin;
944 printf("Average LPM Delete: %g cycles\n",
945 (double)total_time / NUM_ROUTE_ENTRIES);
947 rte_lpm_delete_all(lpm);
952 test_lpm_rcu_perf_multi_writer();
957 REGISTER_TEST_COMMAND(lpm_perf_autotest, test_lpm_perf);