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 #include <sys/types.h>
40 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
52 #include <rte_per_lcore.h>
53 #include <rte_launch.h>
54 #include <rte_atomic.h>
55 #include <rte_cycles.h>
56 #include <rte_prefetch.h>
57 #include <rte_branch_prediction.h>
58 #include <rte_interrupts.h>
60 #include <rte_random.h>
61 #include <rte_debug.h>
62 #include <rte_ether.h>
63 #include <rte_ethdev.h>
65 #include <rte_mempool.h>
71 #include <rte_malloc.h>
76 app_main_loop_rx(void) {
80 RTE_LOG(INFO, USER1, "Core %u is doing RX\n", rte_lcore_id());
82 for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
85 n_mbufs = rte_eth_rx_burst(
89 app.burst_size_rx_read);
95 ret = rte_ring_sp_enqueue_bulk(
97 (void **) app.mbuf_rx.array,
104 app_main_loop_worker(void) {
105 struct app_mbuf_array *worker_mbuf;
108 RTE_LOG(INFO, USER1, "Core %u is doing work (no pipeline)\n",
111 worker_mbuf = rte_malloc_socket(NULL, sizeof(struct app_mbuf_array),
112 RTE_CACHE_LINE_SIZE, rte_socket_id());
113 if (worker_mbuf == NULL)
114 rte_panic("Worker thread: cannot allocate buffer space\n");
116 for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
119 ret = rte_ring_sc_dequeue_bulk(
121 (void **) worker_mbuf->array,
122 app.burst_size_worker_read,
129 ret = rte_ring_sp_enqueue_bulk(
131 (void **) worker_mbuf->array,
132 app.burst_size_worker_write,
139 app_main_loop_tx(void) {
142 RTE_LOG(INFO, USER1, "Core %u is doing TX\n", rte_lcore_id());
144 for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
145 uint16_t n_mbufs, n_pkts;
148 n_mbufs = app.mbuf_tx[i].n_mbufs;
150 ret = rte_ring_sc_dequeue_bulk(
152 (void **) &app.mbuf_tx[i].array[n_mbufs],
153 app.burst_size_tx_read,
159 n_mbufs += app.burst_size_tx_read;
161 if (n_mbufs < app.burst_size_tx_write) {
162 app.mbuf_tx[i].n_mbufs = n_mbufs;
166 n_pkts = rte_eth_tx_burst(
169 app.mbuf_tx[i].array,
172 if (n_pkts < n_mbufs) {
175 for (k = n_pkts; k < n_mbufs; k++) {
176 struct rte_mbuf *pkt_to_free;
178 pkt_to_free = app.mbuf_tx[i].array[k];
179 rte_pktmbuf_free(pkt_to_free);
183 app.mbuf_tx[i].n_mbufs = 0;