1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 Intel Corporation
9 #include <rte_cycles.h>
10 #include <rte_launch.h>
11 #include <rte_ethdev.h>
12 #include <rte_eth_ring.h>
13 #include <rte_bus_vdev.h>
17 #define RING_NAME "RING_PERF"
18 #define RING_SIZE 4096
22 * the sizes to enqueue and dequeue in testing
23 * (marked volatile so they won't be seen as compile-time constants)
25 static const volatile unsigned bulk_sizes[] = { 1, 8, 32 };
27 /* The ring structure used for tests */
28 static struct rte_ring *r;
29 static uint16_t ring_ethdev_port;
31 /* Get cycle counts for dequeuing from an empty ring. Should be 2 or 3 cycles */
33 test_empty_dequeue(void)
35 const unsigned iter_shift = 26;
36 const unsigned iterations = 1 << iter_shift;
38 void *burst[MAX_BURST];
40 const uint64_t sc_start = rte_rdtsc();
41 for (i = 0; i < iterations; i++)
42 rte_ring_sc_dequeue_bulk(r, burst, bulk_sizes[0], NULL);
43 const uint64_t sc_end = rte_rdtsc();
45 const uint64_t eth_start = rte_rdtsc();
46 for (i = 0; i < iterations; i++)
47 rte_eth_rx_burst(ring_ethdev_port, 0, (void *)burst,
49 const uint64_t eth_end = rte_rdtsc();
51 printf("Ring empty dequeue : %.1F\n",
52 (double)(sc_end - sc_start) / iterations);
53 printf("Ethdev empty dequeue: %.1F\n",
54 (double)(eth_end - eth_start) / iterations);
58 * Test function that determines how long an enqueue + dequeue of a single item
59 * takes on a single lcore. Result is for comparison with the bulk enq+deq.
62 test_single_enqueue_dequeue(void)
64 const unsigned iter_shift = 24;
65 const unsigned iterations = 1 << iter_shift;
68 struct rte_mbuf *mburst[1] = { NULL };
70 const uint64_t sc_start = rte_rdtsc_precise();
71 rte_compiler_barrier();
72 for (i = 0; i < iterations; i++) {
73 rte_ring_enqueue_bulk(r, &burst, 1, NULL);
74 rte_ring_dequeue_bulk(r, &burst, 1, NULL);
76 const uint64_t sc_end = rte_rdtsc_precise();
77 rte_compiler_barrier();
79 const uint64_t eth_start = rte_rdtsc_precise();
80 rte_compiler_barrier();
81 for (i = 0; i < iterations; i++) {
82 rte_eth_tx_burst(ring_ethdev_port, 0, mburst, 1);
83 rte_eth_rx_burst(ring_ethdev_port, 0, mburst, 1);
85 const uint64_t eth_end = rte_rdtsc_precise();
86 rte_compiler_barrier();
88 printf("Ring single enq/dequeue : %"PRIu64"\n",
89 (sc_end-sc_start) >> iter_shift);
90 printf("Ethdev single enq/dequeue: %"PRIu64"\n",
91 (eth_end-eth_start) >> iter_shift);
94 /* Times enqueue and dequeue on a single lcore */
96 test_bulk_enqueue_dequeue(void)
98 const unsigned iter_shift = 23;
99 const unsigned iterations = 1 << iter_shift;
101 struct rte_mbuf *burst[MAX_BURST] = {0};
103 for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
104 const uint64_t sc_start = rte_rdtsc();
105 for (i = 0; i < iterations; i++) {
106 rte_ring_sp_enqueue_bulk(r, (void *)burst,
107 bulk_sizes[sz], NULL);
108 rte_ring_sc_dequeue_bulk(r, (void *)burst,
109 bulk_sizes[sz], NULL);
111 const uint64_t sc_end = rte_rdtsc();
113 const uint64_t eth_start = rte_rdtsc_precise();
114 rte_compiler_barrier();
115 for (i = 0; i < iterations; i++) {
116 rte_eth_tx_burst(ring_ethdev_port, 0, burst, bulk_sizes[sz]);
117 rte_eth_rx_burst(ring_ethdev_port, 0, burst, bulk_sizes[sz]);
119 const uint64_t eth_end = rte_rdtsc_precise();
120 rte_compiler_barrier();
122 double sc_avg = ((double)(sc_end-sc_start) /
123 (iterations * bulk_sizes[sz]));
124 double eth_avg = ((double)(eth_end-eth_start) /
125 (iterations * bulk_sizes[sz]));
127 printf("ring bulk enq/deq (size: %u) : %.1F\n", bulk_sizes[sz],
129 printf("ethdev bulk enq/deq (size:%u): %.1F\n", bulk_sizes[sz],
137 test_ring_pmd_perf(void)
139 char name[RTE_ETH_NAME_MAX_LEN];
141 r = rte_ring_create(RING_NAME, RING_SIZE, rte_socket_id(),
142 RING_F_SP_ENQ|RING_F_SC_DEQ);
143 if (r == NULL && (r = rte_ring_lookup(RING_NAME)) == NULL)
146 ring_ethdev_port = rte_eth_from_ring(r);
148 printf("\n### Testing const single element enq/deq ###\n");
149 test_single_enqueue_dequeue();
151 printf("\n### Testing empty dequeue ###\n");
152 test_empty_dequeue();
154 printf("\n### Testing using a single lcore ###\n");
155 test_bulk_enqueue_dequeue();
157 /* release port and ring resources */
158 rte_eth_dev_stop(ring_ethdev_port);
159 rte_eth_dev_get_name_by_port(ring_ethdev_port, name);
160 rte_vdev_uninit(name);
165 REGISTER_TEST_COMMAND(ring_pmd_perf_autotest, test_ring_pmd_perf);