1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
11 #include <sys/queue.h>
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
19 #include <rte_memory.h>
20 #include <rte_memcpy.h>
22 #include <rte_per_lcore.h>
23 #include <rte_launch.h>
24 #include <rte_atomic.h>
25 #include <rte_cycles.h>
26 #include <rte_prefetch.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_interrupts.h>
30 #include <rte_random.h>
31 #include <rte_debug.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
35 #include <rte_mempool.h>
41 #include <rte_malloc.h>
46 app_main_loop_rx(void) {
50 RTE_LOG(INFO, USER1, "Core %u is doing RX\n", rte_lcore_id());
52 for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
55 n_mbufs = rte_eth_rx_burst(
59 app.burst_size_rx_read);
65 ret = rte_ring_sp_enqueue_bulk(
67 (void **) app.mbuf_rx.array,
74 app_main_loop_worker(void) {
75 struct app_mbuf_array *worker_mbuf;
78 RTE_LOG(INFO, USER1, "Core %u is doing work (no pipeline)\n",
81 worker_mbuf = rte_malloc_socket(NULL, sizeof(struct app_mbuf_array),
82 RTE_CACHE_LINE_SIZE, rte_socket_id());
83 if (worker_mbuf == NULL)
84 rte_panic("Worker thread: cannot allocate buffer space\n");
86 for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
89 ret = rte_ring_sc_dequeue_bulk(
91 (void **) worker_mbuf->array,
92 app.burst_size_worker_read,
99 ret = rte_ring_sp_enqueue_bulk(
101 (void **) worker_mbuf->array,
102 app.burst_size_worker_write,
109 app_main_loop_tx(void) {
112 RTE_LOG(INFO, USER1, "Core %u is doing TX\n", rte_lcore_id());
114 for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
115 uint16_t n_mbufs, n_pkts;
118 n_mbufs = app.mbuf_tx[i].n_mbufs;
120 ret = rte_ring_sc_dequeue_bulk(
122 (void **) &app.mbuf_tx[i].array[n_mbufs],
123 app.burst_size_tx_read,
129 n_mbufs += app.burst_size_tx_read;
131 if (n_mbufs < app.burst_size_tx_write) {
132 app.mbuf_tx[i].n_mbufs = n_mbufs;
136 n_pkts = rte_eth_tx_burst(
139 app.mbuf_tx[i].array,
142 if (n_pkts < n_mbufs) {
145 for (k = n_pkts; k < n_mbufs; k++) {
146 struct rte_mbuf *pkt_to_free;
148 pkt_to_free = app.mbuf_tx[i].array[k];
149 rte_pktmbuf_free(pkt_to_free);
153 app.mbuf_tx[i].n_mbufs = 0;