4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #ifndef APP_MAX_SOCKETS
39 #define APP_MAX_SOCKETS 2
42 #ifndef APP_MAX_LCORES
43 #define APP_MAX_LCORES RTE_MAX_LCORE
46 #ifndef APP_MAX_NIC_PORTS
47 #define APP_MAX_NIC_PORTS RTE_MAX_ETHPORTS
50 #ifndef APP_MAX_RX_QUEUES_PER_NIC_PORT
51 #define APP_MAX_RX_QUEUES_PER_NIC_PORT 128
54 #ifndef APP_MAX_TX_QUEUES_PER_NIC_PORT
55 #define APP_MAX_TX_QUEUES_PER_NIC_PORT 128
58 #ifndef APP_MAX_IO_LCORES
59 #define APP_MAX_IO_LCORES 16
61 #if (APP_MAX_IO_LCORES > APP_MAX_LCORES)
62 #error "APP_MAX_IO_LCORES is too big"
65 #ifndef APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE
66 #define APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE 16
69 #ifndef APP_MAX_NIC_TX_PORTS_PER_IO_LCORE
70 #define APP_MAX_NIC_TX_PORTS_PER_IO_LCORE 16
72 #if (APP_MAX_NIC_TX_PORTS_PER_IO_LCORE > APP_MAX_NIC_PORTS)
73 #error "APP_MAX_NIC_TX_PORTS_PER_IO_LCORE too big"
76 #ifndef APP_MAX_WORKER_LCORES
77 #define APP_MAX_WORKER_LCORES 16
79 #if (APP_MAX_WORKER_LCORES > APP_MAX_LCORES)
80 #error "APP_MAX_WORKER_LCORES is too big"
85 #ifndef APP_DEFAULT_MBUF_DATA_SIZE
86 #define APP_DEFAULT_MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE
89 #ifndef APP_DEFAULT_MEMPOOL_BUFFERS
90 #define APP_DEFAULT_MEMPOOL_BUFFERS 8192 * 4
93 #ifndef APP_DEFAULT_MEMPOOL_CACHE_SIZE
94 #define APP_DEFAULT_MEMPOOL_CACHE_SIZE 256
98 #ifndef APP_MAX_LPM_RULES
99 #define APP_MAX_LPM_RULES 1024
103 #ifndef APP_DEFAULT_NIC_RX_RING_SIZE
104 #define APP_DEFAULT_NIC_RX_RING_SIZE 1024
108 * RX and TX Prefetch, Host, and Write-back threshold values should be
109 * carefully set for optimal performance. Consult the network
110 * controller's datasheet and supporting DPDK documentation for guidance
111 * on how these parameters should be set.
113 #ifndef APP_DEFAULT_NIC_RX_PTHRESH
114 #define APP_DEFAULT_NIC_RX_PTHRESH 8
117 #ifndef APP_DEFAULT_NIC_RX_HTHRESH
118 #define APP_DEFAULT_NIC_RX_HTHRESH 8
121 #ifndef APP_DEFAULT_NIC_RX_WTHRESH
122 #define APP_DEFAULT_NIC_RX_WTHRESH 4
125 #ifndef APP_DEFAULT_NIC_RX_FREE_THRESH
126 #define APP_DEFAULT_NIC_RX_FREE_THRESH 64
129 #ifndef APP_DEFAULT_NIC_RX_DROP_EN
130 #define APP_DEFAULT_NIC_RX_DROP_EN 0
134 #ifndef APP_DEFAULT_NIC_TX_RING_SIZE
135 #define APP_DEFAULT_NIC_TX_RING_SIZE 1024
139 * These default values are optimized for use with the Intel(R) 82599 10 GbE
140 * Controller and the DPDK ixgbe PMD. Consider using other values for other
141 * network controllers and/or network drivers.
143 #ifndef APP_DEFAULT_NIC_TX_PTHRESH
144 #define APP_DEFAULT_NIC_TX_PTHRESH 36
147 #ifndef APP_DEFAULT_NIC_TX_HTHRESH
148 #define APP_DEFAULT_NIC_TX_HTHRESH 0
151 #ifndef APP_DEFAULT_NIC_TX_WTHRESH
152 #define APP_DEFAULT_NIC_TX_WTHRESH 0
155 #ifndef APP_DEFAULT_NIC_TX_FREE_THRESH
156 #define APP_DEFAULT_NIC_TX_FREE_THRESH 0
159 #ifndef APP_DEFAULT_NIC_TX_RS_THRESH
160 #define APP_DEFAULT_NIC_TX_RS_THRESH 0
164 #ifndef APP_DEFAULT_RING_RX_SIZE
165 #define APP_DEFAULT_RING_RX_SIZE 1024
168 #ifndef APP_DEFAULT_RING_TX_SIZE
169 #define APP_DEFAULT_RING_TX_SIZE 1024
173 #ifndef APP_MBUF_ARRAY_SIZE
174 #define APP_MBUF_ARRAY_SIZE 512
177 #ifndef APP_DEFAULT_BURST_SIZE_IO_RX_READ
178 #define APP_DEFAULT_BURST_SIZE_IO_RX_READ 144
180 #if (APP_DEFAULT_BURST_SIZE_IO_RX_READ > APP_MBUF_ARRAY_SIZE)
181 #error "APP_DEFAULT_BURST_SIZE_IO_RX_READ is too big"
184 #ifndef APP_DEFAULT_BURST_SIZE_IO_RX_WRITE
185 #define APP_DEFAULT_BURST_SIZE_IO_RX_WRITE 144
187 #if (APP_DEFAULT_BURST_SIZE_IO_RX_WRITE > APP_MBUF_ARRAY_SIZE)
188 #error "APP_DEFAULT_BURST_SIZE_IO_RX_WRITE is too big"
191 #ifndef APP_DEFAULT_BURST_SIZE_IO_TX_READ
192 #define APP_DEFAULT_BURST_SIZE_IO_TX_READ 144
194 #if (APP_DEFAULT_BURST_SIZE_IO_TX_READ > APP_MBUF_ARRAY_SIZE)
195 #error "APP_DEFAULT_BURST_SIZE_IO_TX_READ is too big"
198 #ifndef APP_DEFAULT_BURST_SIZE_IO_TX_WRITE
199 #define APP_DEFAULT_BURST_SIZE_IO_TX_WRITE 144
201 #if (APP_DEFAULT_BURST_SIZE_IO_TX_WRITE > APP_MBUF_ARRAY_SIZE)
202 #error "APP_DEFAULT_BURST_SIZE_IO_TX_WRITE is too big"
205 #ifndef APP_DEFAULT_BURST_SIZE_WORKER_READ
206 #define APP_DEFAULT_BURST_SIZE_WORKER_READ 144
208 #if ((2 * APP_DEFAULT_BURST_SIZE_WORKER_READ) > APP_MBUF_ARRAY_SIZE)
209 #error "APP_DEFAULT_BURST_SIZE_WORKER_READ is too big"
212 #ifndef APP_DEFAULT_BURST_SIZE_WORKER_WRITE
213 #define APP_DEFAULT_BURST_SIZE_WORKER_WRITE 144
215 #if (APP_DEFAULT_BURST_SIZE_WORKER_WRITE > APP_MBUF_ARRAY_SIZE)
216 #error "APP_DEFAULT_BURST_SIZE_WORKER_WRITE is too big"
219 /* Load balancing logic */
220 #ifndef APP_DEFAULT_IO_RX_LB_POS
221 #define APP_DEFAULT_IO_RX_LB_POS 29
223 #if (APP_DEFAULT_IO_RX_LB_POS >= 64)
224 #error "APP_DEFAULT_IO_RX_LB_POS is too big"
227 struct app_mbuf_array {
228 struct rte_mbuf *array[APP_MBUF_ARRAY_SIZE];
232 enum app_lcore_type {
233 e_APP_LCORE_DISABLED = 0,
238 struct app_lcore_params_io {
245 } nic_queues[APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE];
246 uint32_t n_nic_queues;
249 struct rte_ring *rings[APP_MAX_WORKER_LCORES];
252 /* Internal buffers */
253 struct app_mbuf_array mbuf_in;
254 struct app_mbuf_array mbuf_out[APP_MAX_WORKER_LCORES];
255 uint8_t mbuf_out_flush[APP_MAX_WORKER_LCORES];
258 uint32_t nic_queues_count[APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE];
259 uint32_t nic_queues_iters[APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE];
260 uint32_t rings_count[APP_MAX_WORKER_LCORES];
261 uint32_t rings_iters[APP_MAX_WORKER_LCORES];
267 struct rte_ring *rings[APP_MAX_NIC_PORTS][APP_MAX_WORKER_LCORES];
270 uint8_t nic_ports[APP_MAX_NIC_TX_PORTS_PER_IO_LCORE];
271 uint32_t n_nic_ports;
273 /* Internal buffers */
274 struct app_mbuf_array mbuf_out[APP_MAX_NIC_TX_PORTS_PER_IO_LCORE];
275 uint8_t mbuf_out_flush[APP_MAX_NIC_TX_PORTS_PER_IO_LCORE];
278 uint32_t rings_count[APP_MAX_NIC_PORTS][APP_MAX_WORKER_LCORES];
279 uint32_t rings_iters[APP_MAX_NIC_PORTS][APP_MAX_WORKER_LCORES];
280 uint32_t nic_ports_count[APP_MAX_NIC_TX_PORTS_PER_IO_LCORE];
281 uint32_t nic_ports_iters[APP_MAX_NIC_TX_PORTS_PER_IO_LCORE];
285 struct app_lcore_params_worker {
287 struct rte_ring *rings_in[APP_MAX_IO_LCORES];
289 struct rte_ring *rings_out[APP_MAX_NIC_PORTS];
292 struct rte_lpm *lpm_table;
295 /* Internal buffers */
296 struct app_mbuf_array mbuf_in;
297 struct app_mbuf_array mbuf_out[APP_MAX_NIC_PORTS];
298 uint8_t mbuf_out_flush[APP_MAX_NIC_PORTS];
301 uint32_t rings_in_count[APP_MAX_IO_LCORES];
302 uint32_t rings_in_iters[APP_MAX_IO_LCORES];
303 uint32_t rings_out_count[APP_MAX_NIC_PORTS];
304 uint32_t rings_out_iters[APP_MAX_NIC_PORTS];
307 struct app_lcore_params {
309 struct app_lcore_params_io io;
310 struct app_lcore_params_worker worker;
312 enum app_lcore_type type;
313 struct rte_mempool *pool;
314 } __rte_cache_aligned;
316 struct app_lpm_rule {
324 struct app_lcore_params lcore_params[APP_MAX_LCORES];
327 uint8_t nic_rx_queue_mask[APP_MAX_NIC_PORTS][APP_MAX_RX_QUEUES_PER_NIC_PORT];
328 uint8_t nic_tx_port_mask[APP_MAX_NIC_PORTS];
331 struct rte_mempool *pools[APP_MAX_SOCKETS];
334 struct rte_lpm *lpm_tables[APP_MAX_SOCKETS];
335 struct app_lpm_rule lpm_rules[APP_MAX_LPM_RULES];
336 uint32_t n_lpm_rules;
339 uint32_t nic_rx_ring_size;
340 uint32_t nic_tx_ring_size;
341 uint32_t ring_rx_size;
342 uint32_t ring_tx_size;
345 uint32_t burst_size_io_rx_read;
346 uint32_t burst_size_io_rx_write;
347 uint32_t burst_size_io_tx_read;
348 uint32_t burst_size_io_tx_write;
349 uint32_t burst_size_worker_read;
350 uint32_t burst_size_worker_write;
354 } __rte_cache_aligned;
356 extern struct app_params app;
358 int app_parse_args(int argc, char **argv);
359 void app_print_usage(void);
361 int app_lcore_main_loop(void *arg);
363 int app_get_nic_rx_queues_per_port(uint8_t port);
364 int app_get_lcore_for_nic_rx(uint8_t port, uint8_t queue, uint32_t *lcore_out);
365 int app_get_lcore_for_nic_tx(uint8_t port, uint32_t *lcore_out);
366 int app_is_socket_used(uint32_t socket);
367 uint32_t app_get_lcores_io_rx(void);
368 uint32_t app_get_lcores_worker(void);
369 void app_print_params(void);
371 #endif /* _MAIN_H_ */