]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/test/test/test_pmd_ring_perf.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / dpdk / test / test / test_pmd_ring_perf.c
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
14 #include "test.h"
15
16 #define RING_NAME "RING_PERF"
17 #define RING_SIZE 4096
18 #define MAX_BURST 32
19
20 /*
21 * the sizes to enqueue and dequeue in testing
22 * (marked volatile so they won't be seen as compile-time constants)
23 */
24 static const volatile unsigned bulk_sizes[] = { 1, 8, 32 };
25
26 /* The ring structure used for tests */
27 static struct rte_ring *r;
28 static uint16_t ring_ethdev_port;
29
30 /* Get cycle counts for dequeuing from an empty ring. Should be 2 or 3 cycles */
31 static void
32 test_empty_dequeue(void)
33 {
34 const unsigned iter_shift = 26;
35 const unsigned iterations = 1 << iter_shift;
36 unsigned i = 0;
37 void *burst[MAX_BURST];
38
39 const uint64_t sc_start = rte_rdtsc();
40 for (i = 0; i < iterations; i++)
41 rte_ring_sc_dequeue_bulk(r, burst, bulk_sizes[0], NULL);
42 const uint64_t sc_end = rte_rdtsc();
43
44 const uint64_t eth_start = rte_rdtsc();
45 for (i = 0; i < iterations; i++)
46 rte_eth_rx_burst(ring_ethdev_port, 0, (void *)burst,
47 bulk_sizes[0]);
48 const uint64_t eth_end = rte_rdtsc();
49
50 printf("Ring empty dequeue : %.1F\n",
51 (double)(sc_end - sc_start) / iterations);
52 printf("Ethdev empty dequeue: %.1F\n",
53 (double)(eth_end - eth_start) / iterations);
54 }
55
56 /*
57 * Test function that determines how long an enqueue + dequeue of a single item
58 * takes on a single lcore. Result is for comparison with the bulk enq+deq.
59 */
60 static void
61 test_single_enqueue_dequeue(void)
62 {
63 const unsigned iter_shift = 24;
64 const unsigned iterations = 1 << iter_shift;
65 unsigned i = 0;
66 void *burst = NULL;
67 struct rte_mbuf *mburst[1] = { NULL };
68
69 const uint64_t sc_start = rte_rdtsc_precise();
70 rte_compiler_barrier();
71 for (i = 0; i < iterations; i++) {
72 rte_ring_enqueue_bulk(r, &burst, 1, NULL);
73 rte_ring_dequeue_bulk(r, &burst, 1, NULL);
74 }
75 const uint64_t sc_end = rte_rdtsc_precise();
76 rte_compiler_barrier();
77
78 const uint64_t eth_start = rte_rdtsc_precise();
79 rte_compiler_barrier();
80 for (i = 0; i < iterations; i++) {
81 rte_eth_tx_burst(ring_ethdev_port, 0, mburst, 1);
82 rte_eth_rx_burst(ring_ethdev_port, 0, mburst, 1);
83 }
84 const uint64_t eth_end = rte_rdtsc_precise();
85 rte_compiler_barrier();
86
87 printf("Ring single enq/dequeue : %"PRIu64"\n",
88 (sc_end-sc_start) >> iter_shift);
89 printf("Ethdev single enq/dequeue: %"PRIu64"\n",
90 (eth_end-eth_start) >> iter_shift);
91 }
92
93 /* Times enqueue and dequeue on a single lcore */
94 static void
95 test_bulk_enqueue_dequeue(void)
96 {
97 const unsigned iter_shift = 23;
98 const unsigned iterations = 1 << iter_shift;
99 unsigned sz, i = 0;
100 struct rte_mbuf *burst[MAX_BURST] = {0};
101
102 for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
103 const uint64_t sc_start = rte_rdtsc();
104 for (i = 0; i < iterations; i++) {
105 rte_ring_sp_enqueue_bulk(r, (void *)burst,
106 bulk_sizes[sz], NULL);
107 rte_ring_sc_dequeue_bulk(r, (void *)burst,
108 bulk_sizes[sz], NULL);
109 }
110 const uint64_t sc_end = rte_rdtsc();
111
112 const uint64_t eth_start = rte_rdtsc_precise();
113 rte_compiler_barrier();
114 for (i = 0; i < iterations; i++) {
115 rte_eth_tx_burst(ring_ethdev_port, 0, burst, bulk_sizes[sz]);
116 rte_eth_rx_burst(ring_ethdev_port, 0, burst, bulk_sizes[sz]);
117 }
118 const uint64_t eth_end = rte_rdtsc_precise();
119 rte_compiler_barrier();
120
121 double sc_avg = ((double)(sc_end-sc_start) /
122 (iterations * bulk_sizes[sz]));
123 double eth_avg = ((double)(eth_end-eth_start) /
124 (iterations * bulk_sizes[sz]));
125
126 printf("ring bulk enq/deq (size: %u) : %.1F\n", bulk_sizes[sz],
127 sc_avg);
128 printf("ethdev bulk enq/deq (size:%u): %.1F\n", bulk_sizes[sz],
129 eth_avg);
130
131 printf("\n");
132 }
133 }
134
135 static int
136 test_ring_pmd_perf(void)
137 {
138 r = rte_ring_create(RING_NAME, RING_SIZE, rte_socket_id(),
139 RING_F_SP_ENQ|RING_F_SC_DEQ);
140 if (r == NULL && (r = rte_ring_lookup(RING_NAME)) == NULL)
141 return -1;
142
143 ring_ethdev_port = rte_eth_from_ring(r);
144
145 printf("\n### Testing const single element enq/deq ###\n");
146 test_single_enqueue_dequeue();
147
148 printf("\n### Testing empty dequeue ###\n");
149 test_empty_dequeue();
150
151 printf("\n### Testing using a single lcore ###\n");
152 test_bulk_enqueue_dequeue();
153
154 return 0;
155 }
156
157 REGISTER_TEST_COMMAND(ring_pmd_perf_autotest, test_ring_pmd_perf);