Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015 Intel Corporation
3 : : */
4 : :
5 : :
6 : : #include <stdio.h>
7 : : #include <inttypes.h>
8 : : #include <rte_ring.h>
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>
14 : :
15 : : #include "test.h"
16 : :
17 : : #define RING_NAME "RING_PERF"
18 : : #define RING_SIZE 4096
19 : : #define MAX_BURST 32
20 : :
21 : : /*
22 : : * the sizes to enqueue and dequeue in testing
23 : : * (marked volatile so they won't be seen as compile-time constants)
24 : : */
25 : : static const volatile unsigned bulk_sizes[] = { 1, 8, 32 };
26 : :
27 : : /* The ring structure used for tests */
28 : : static struct rte_ring *r;
29 : : static uint16_t ring_ethdev_port;
30 : :
31 : : /* Get cycle counts for dequeuing from an empty ring. Should be 2 or 3 cycles */
32 : : static void
33 : 0 : test_empty_dequeue(void)
34 : : {
35 : : const unsigned iter_shift = 26;
36 : : const unsigned iterations = 1 << iter_shift;
37 : : unsigned i = 0;
38 : : void *burst[MAX_BURST];
39 : :
40 : : const uint64_t sc_start = rte_rdtsc();
41 [ # # ]: 0 : for (i = 0; i < iterations; i++)
42 : 0 : rte_ring_sc_dequeue_bulk(r, burst, bulk_sizes[0], NULL);
43 : : const uint64_t sc_end = rte_rdtsc();
44 : :
45 : : const uint64_t eth_start = rte_rdtsc();
46 [ # # ]: 0 : for (i = 0; i < iterations; i++)
47 : 0 : rte_eth_rx_burst(ring_ethdev_port, 0, (void *)burst,
48 : 0 : bulk_sizes[0]);
49 : : const uint64_t eth_end = rte_rdtsc();
50 : :
51 : 0 : printf("Ring empty dequeue : %.1F\n",
52 : 0 : (double)(sc_end - sc_start) / iterations);
53 : 0 : printf("Ethdev empty dequeue: %.1F\n",
54 : 0 : (double)(eth_end - eth_start) / iterations);
55 : 0 : }
56 : :
57 : : /*
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.
60 : : */
61 : : static void
62 : 0 : test_single_enqueue_dequeue(void)
63 : : {
64 : : const unsigned iter_shift = 24;
65 : : const unsigned iterations = 1 << iter_shift;
66 : : unsigned i = 0;
67 : 0 : void *burst = NULL;
68 : 0 : struct rte_mbuf *mburst[1] = { NULL };
69 : :
70 : : const uint64_t sc_start = rte_rdtsc_precise();
71 : 0 : rte_compiler_barrier();
72 [ # # ]: 0 : for (i = 0; i < iterations; i++) {
73 [ # # # # : 0 : rte_ring_enqueue_bulk(r, &burst, 1, NULL);
# ]
74 [ # # # # : 0 : rte_ring_dequeue_bulk(r, &burst, 1, NULL);
# ]
75 : : }
76 : : const uint64_t sc_end = rte_rdtsc_precise();
77 : 0 : rte_compiler_barrier();
78 : :
79 : : const uint64_t eth_start = rte_rdtsc_precise();
80 : 0 : rte_compiler_barrier();
81 [ # # ]: 0 : for (i = 0; i < iterations; i++) {
82 : 0 : rte_eth_tx_burst(ring_ethdev_port, 0, mburst, 1);
83 : 0 : rte_eth_rx_burst(ring_ethdev_port, 0, mburst, 1);
84 : : }
85 : : const uint64_t eth_end = rte_rdtsc_precise();
86 : 0 : rte_compiler_barrier();
87 : :
88 : 0 : printf("Ring single enq/dequeue : %"PRIu64"\n",
89 : 0 : (sc_end-sc_start) >> iter_shift);
90 : 0 : printf("Ethdev single enq/dequeue: %"PRIu64"\n",
91 : 0 : (eth_end-eth_start) >> iter_shift);
92 : 0 : }
93 : :
94 : : /* Times enqueue and dequeue on a single lcore */
95 : : static void
96 : 0 : test_bulk_enqueue_dequeue(void)
97 : : {
98 : : const unsigned iter_shift = 23;
99 : : const unsigned iterations = 1 << iter_shift;
100 : : unsigned sz, i = 0;
101 : 0 : struct rte_mbuf *burst[MAX_BURST] = {0};
102 : :
103 [ # # ]: 0 : for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
104 : : const uint64_t sc_start = rte_rdtsc();
105 [ # # ]: 0 : for (i = 0; i < iterations; i++) {
106 : 0 : rte_ring_sp_enqueue_bulk(r, (void *)burst,
107 : 0 : bulk_sizes[sz], NULL);
108 : 0 : rte_ring_sc_dequeue_bulk(r, (void *)burst,
109 : 0 : bulk_sizes[sz], NULL);
110 : : }
111 : : const uint64_t sc_end = rte_rdtsc();
112 : :
113 : : const uint64_t eth_start = rte_rdtsc_precise();
114 : 0 : rte_compiler_barrier();
115 [ # # ]: 0 : for (i = 0; i < iterations; i++) {
116 : 0 : rte_eth_tx_burst(ring_ethdev_port, 0, burst, bulk_sizes[sz]);
117 : 0 : rte_eth_rx_burst(ring_ethdev_port, 0, burst, bulk_sizes[sz]);
118 : : }
119 : : const uint64_t eth_end = rte_rdtsc_precise();
120 : 0 : rte_compiler_barrier();
121 : :
122 : 0 : double sc_avg = ((double)(sc_end-sc_start) /
123 : 0 : (iterations * bulk_sizes[sz]));
124 : 0 : double eth_avg = ((double)(eth_end-eth_start) /
125 : 0 : (iterations * bulk_sizes[sz]));
126 : :
127 : 0 : printf("ring bulk enq/deq (size: %u) : %.1F\n", bulk_sizes[sz],
128 : : sc_avg);
129 : 0 : printf("ethdev bulk enq/deq (size:%u): %.1F\n", bulk_sizes[sz],
130 : : eth_avg);
131 : :
132 : : printf("\n");
133 : : }
134 : 0 : }
135 : :
136 : : static int
137 : 0 : test_ring_pmd_perf(void)
138 : : {
139 : : char name[RTE_ETH_NAME_MAX_LEN];
140 : :
141 : 0 : r = rte_ring_create(RING_NAME, RING_SIZE, rte_socket_id(),
142 : : RING_F_SP_ENQ|RING_F_SC_DEQ);
143 [ # # # # ]: 0 : if (r == NULL && (r = rte_ring_lookup(RING_NAME)) == NULL)
144 : : return -1;
145 : :
146 : 0 : ring_ethdev_port = rte_eth_from_ring(r);
147 : :
148 : : printf("\n### Testing const single element enq/deq ###\n");
149 : 0 : test_single_enqueue_dequeue();
150 : :
151 : : printf("\n### Testing empty dequeue ###\n");
152 : 0 : test_empty_dequeue();
153 : :
154 : : printf("\n### Testing using a single lcore ###\n");
155 : 0 : test_bulk_enqueue_dequeue();
156 : :
157 : : /* release port and ring resources */
158 [ # # ]: 0 : if (rte_eth_dev_stop(ring_ethdev_port) != 0)
159 : : return -1;
160 : 0 : rte_eth_dev_get_name_by_port(ring_ethdev_port, name);
161 : 0 : rte_vdev_uninit(name);
162 : 0 : rte_ring_free(r);
163 : 0 : return 0;
164 : : }
165 : :
166 : 251 : REGISTER_PERF_TEST(ring_pmd_perf_autotest, test_ring_pmd_perf);
|