xref: /dpdk/app/test-pipeline/runtime.c (revision f6897b23f70b84742129a215ea2be17c8843adb8)
1474572d2SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2474572d2SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3474572d2SBruce Richardson  */
4474572d2SBruce Richardson 
5474572d2SBruce Richardson #include <stdio.h>
6474572d2SBruce Richardson #include <stdlib.h>
7474572d2SBruce Richardson #include <stdint.h>
8474572d2SBruce Richardson #include <inttypes.h>
9474572d2SBruce Richardson #include <sys/types.h>
10474572d2SBruce Richardson #include <string.h>
11474572d2SBruce Richardson #include <sys/queue.h>
12474572d2SBruce Richardson #include <stdarg.h>
13474572d2SBruce Richardson #include <errno.h>
14474572d2SBruce Richardson #include <getopt.h>
15474572d2SBruce Richardson 
16474572d2SBruce Richardson #include <rte_common.h>
17474572d2SBruce Richardson #include <rte_byteorder.h>
18474572d2SBruce Richardson #include <rte_log.h>
19474572d2SBruce Richardson #include <rte_memory.h>
20474572d2SBruce Richardson #include <rte_memcpy.h>
21474572d2SBruce Richardson #include <rte_eal.h>
22474572d2SBruce Richardson #include <rte_per_lcore.h>
23474572d2SBruce Richardson #include <rte_launch.h>
24474572d2SBruce Richardson #include <rte_cycles.h>
25474572d2SBruce Richardson #include <rte_prefetch.h>
26474572d2SBruce Richardson #include <rte_branch_prediction.h>
27474572d2SBruce Richardson #include <rte_interrupts.h>
28474572d2SBruce Richardson #include <rte_pci.h>
29474572d2SBruce Richardson #include <rte_random.h>
30474572d2SBruce Richardson #include <rte_debug.h>
31474572d2SBruce Richardson #include <rte_ether.h>
32474572d2SBruce Richardson #include <rte_ethdev.h>
33474572d2SBruce Richardson #include <rte_ring.h>
34474572d2SBruce Richardson #include <rte_mempool.h>
35474572d2SBruce Richardson #include <rte_mbuf.h>
36474572d2SBruce Richardson #include <rte_ip.h>
37474572d2SBruce Richardson #include <rte_tcp.h>
38474572d2SBruce Richardson #include <rte_lpm.h>
39474572d2SBruce Richardson #include <rte_lpm6.h>
40474572d2SBruce Richardson #include <rte_malloc.h>
41474572d2SBruce Richardson 
42474572d2SBruce Richardson #include "main.h"
43474572d2SBruce Richardson 
44474572d2SBruce Richardson void
app_main_loop_rx(void)45474572d2SBruce Richardson app_main_loop_rx(void) {
46474572d2SBruce Richardson 	uint32_t i;
47474572d2SBruce Richardson 	int ret;
48474572d2SBruce Richardson 
49474572d2SBruce Richardson 	RTE_LOG(INFO, USER1, "Core %u is doing RX\n", rte_lcore_id());
50474572d2SBruce Richardson 
51*f6897b23SFeifei Wang 	while (!force_quit) {
52*f6897b23SFeifei Wang 		for (i = 0; i < app.n_ports; i++) {
53474572d2SBruce Richardson 			uint16_t n_mbufs;
54474572d2SBruce Richardson 
55474572d2SBruce Richardson 			n_mbufs = rte_eth_rx_burst(
56474572d2SBruce Richardson 				app.ports[i],
57474572d2SBruce Richardson 				0,
58474572d2SBruce Richardson 				app.mbuf_rx.array,
59474572d2SBruce Richardson 				app.burst_size_rx_read);
60474572d2SBruce Richardson 
61474572d2SBruce Richardson 			if (n_mbufs == 0)
62474572d2SBruce Richardson 				continue;
63474572d2SBruce Richardson 
64474572d2SBruce Richardson 			do {
65474572d2SBruce Richardson 				ret = rte_ring_sp_enqueue_bulk(
66474572d2SBruce Richardson 					app.rings_rx[i],
67474572d2SBruce Richardson 					(void **) app.mbuf_rx.array,
68474572d2SBruce Richardson 					n_mbufs, NULL);
69*f6897b23SFeifei Wang 			} while (ret == 0 && !force_quit);
70*f6897b23SFeifei Wang 		}
71474572d2SBruce Richardson 	}
72474572d2SBruce Richardson }
73474572d2SBruce Richardson 
74474572d2SBruce Richardson void
app_main_loop_worker(void)75474572d2SBruce Richardson app_main_loop_worker(void) {
76474572d2SBruce Richardson 	struct app_mbuf_array *worker_mbuf;
77474572d2SBruce Richardson 	uint32_t i;
78474572d2SBruce Richardson 
79474572d2SBruce Richardson 	RTE_LOG(INFO, USER1, "Core %u is doing work (no pipeline)\n",
80474572d2SBruce Richardson 		rte_lcore_id());
81474572d2SBruce Richardson 
82474572d2SBruce Richardson 	worker_mbuf = rte_malloc_socket(NULL, sizeof(struct app_mbuf_array),
83474572d2SBruce Richardson 			RTE_CACHE_LINE_SIZE, rte_socket_id());
84474572d2SBruce Richardson 	if (worker_mbuf == NULL)
85474572d2SBruce Richardson 		rte_panic("Worker thread: cannot allocate buffer space\n");
86474572d2SBruce Richardson 
87*f6897b23SFeifei Wang 	while (!force_quit) {
88*f6897b23SFeifei Wang 		for (i = 0; i < app.n_ports; i++) {
89474572d2SBruce Richardson 			int ret;
90474572d2SBruce Richardson 
91474572d2SBruce Richardson 			ret = rte_ring_sc_dequeue_bulk(
92474572d2SBruce Richardson 				app.rings_rx[i],
93474572d2SBruce Richardson 				(void **) worker_mbuf->array,
94474572d2SBruce Richardson 				app.burst_size_worker_read,
95474572d2SBruce Richardson 				NULL);
96474572d2SBruce Richardson 
97474572d2SBruce Richardson 			if (ret == 0)
98474572d2SBruce Richardson 				continue;
99474572d2SBruce Richardson 
100474572d2SBruce Richardson 			do {
101474572d2SBruce Richardson 				ret = rte_ring_sp_enqueue_bulk(
102474572d2SBruce Richardson 					app.rings_tx[i ^ 1],
103474572d2SBruce Richardson 					(void **) worker_mbuf->array,
104474572d2SBruce Richardson 					app.burst_size_worker_write,
105474572d2SBruce Richardson 					NULL);
106*f6897b23SFeifei Wang 			} while (ret == 0 && !force_quit);
107*f6897b23SFeifei Wang 		}
108474572d2SBruce Richardson 	}
109474572d2SBruce Richardson }
110474572d2SBruce Richardson 
111474572d2SBruce Richardson void
app_main_loop_tx(void)112474572d2SBruce Richardson app_main_loop_tx(void) {
113474572d2SBruce Richardson 	uint32_t i;
114474572d2SBruce Richardson 
115474572d2SBruce Richardson 	RTE_LOG(INFO, USER1, "Core %u is doing TX\n", rte_lcore_id());
116474572d2SBruce Richardson 
117*f6897b23SFeifei Wang 	while (!force_quit) {
118*f6897b23SFeifei Wang 		for (i = 0; i < app.n_ports; i++) {
119474572d2SBruce Richardson 			uint16_t n_mbufs, n_pkts;
120474572d2SBruce Richardson 			int ret;
121474572d2SBruce Richardson 
122474572d2SBruce Richardson 			n_mbufs = app.mbuf_tx[i].n_mbufs;
123474572d2SBruce Richardson 
124474572d2SBruce Richardson 			ret = rte_ring_sc_dequeue_bulk(
125474572d2SBruce Richardson 				app.rings_tx[i],
126474572d2SBruce Richardson 				(void **) &app.mbuf_tx[i].array[n_mbufs],
127474572d2SBruce Richardson 				app.burst_size_tx_read,
128474572d2SBruce Richardson 				NULL);
129474572d2SBruce Richardson 
130474572d2SBruce Richardson 			if (ret == 0)
131474572d2SBruce Richardson 				continue;
132474572d2SBruce Richardson 
133474572d2SBruce Richardson 			n_mbufs += app.burst_size_tx_read;
134474572d2SBruce Richardson 
135474572d2SBruce Richardson 			if (n_mbufs < app.burst_size_tx_write) {
136474572d2SBruce Richardson 				app.mbuf_tx[i].n_mbufs = n_mbufs;
137474572d2SBruce Richardson 				continue;
138474572d2SBruce Richardson 			}
139474572d2SBruce Richardson 
140474572d2SBruce Richardson 			n_pkts = rte_eth_tx_burst(
141474572d2SBruce Richardson 				app.ports[i],
142474572d2SBruce Richardson 				0,
143474572d2SBruce Richardson 				app.mbuf_tx[i].array,
144474572d2SBruce Richardson 				n_mbufs);
145474572d2SBruce Richardson 
146474572d2SBruce Richardson 			if (n_pkts < n_mbufs) {
147474572d2SBruce Richardson 				uint16_t k;
148474572d2SBruce Richardson 
149474572d2SBruce Richardson 				for (k = n_pkts; k < n_mbufs; k++) {
150474572d2SBruce Richardson 					struct rte_mbuf *pkt_to_free;
151474572d2SBruce Richardson 
152474572d2SBruce Richardson 					pkt_to_free = app.mbuf_tx[i].array[k];
153474572d2SBruce Richardson 					rte_pktmbuf_free(pkt_to_free);
154474572d2SBruce Richardson 				}
155474572d2SBruce Richardson 			}
156474572d2SBruce Richardson 
157474572d2SBruce Richardson 			app.mbuf_tx[i].n_mbufs = 0;
158474572d2SBruce Richardson 		}
159474572d2SBruce Richardson 	}
160*f6897b23SFeifei Wang }
161