1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <rte_malloc.h>
11 #include <rte_cycles.h>
12 #include <rte_ethdev.h>
13 #include <rte_memcpy.h>
14 #include <rte_byteorder.h>
15 #include <rte_branch_prediction.h>
17 #include <rte_sched.h>
21 #define APP_MODE_NONE 0
26 uint8_t interactive = APP_INTERACTIVE_DEFAULT;
27 uint32_t qavg_period = APP_QAVG_PERIOD;
28 uint32_t qavg_ntimes = APP_QAVG_NTIMES;
30 /* main processing loop */
32 app_main_loop(__attribute__((unused))void *dummy)
39 struct thread_conf *rx_confs[MAX_DATA_STREAMS];
40 struct thread_conf *wt_confs[MAX_DATA_STREAMS];
41 struct thread_conf *tx_confs[MAX_DATA_STREAMS];
43 memset(rx_confs, 0, sizeof(rx_confs));
44 memset(wt_confs, 0, sizeof(wt_confs));
45 memset(tx_confs, 0, sizeof(tx_confs));
49 lcore_id = rte_lcore_id();
51 for (i = 0; i < nb_pfc; i++) {
52 struct flow_conf *flow = &qos_conf[i];
54 if (flow->rx_core == lcore_id) {
55 flow->rx_thread.rx_port = flow->rx_port;
56 flow->rx_thread.rx_ring = flow->rx_ring;
57 flow->rx_thread.rx_queue = flow->rx_queue;
58 flow->rx_thread.sched_port = flow->sched_port;
60 rx_confs[rx_idx++] = &flow->rx_thread;
64 if (flow->tx_core == lcore_id) {
65 flow->tx_thread.tx_port = flow->tx_port;
66 flow->tx_thread.tx_ring = flow->tx_ring;
67 flow->tx_thread.tx_queue = flow->tx_queue;
69 tx_confs[tx_idx++] = &flow->tx_thread;
73 if (flow->wt_core == lcore_id) {
74 flow->wt_thread.rx_ring = flow->rx_ring;
75 flow->wt_thread.tx_ring = flow->tx_ring;
76 flow->wt_thread.tx_port = flow->tx_port;
77 flow->wt_thread.sched_port = flow->sched_port;
79 wt_confs[wt_idx++] = &flow->wt_thread;
85 if (mode == APP_MODE_NONE) {
86 RTE_LOG(INFO, APP, "lcore %u has nothing to do\n", lcore_id);
90 if (mode == (APP_RX_MODE | APP_WT_MODE)) {
91 RTE_LOG(INFO, APP, "lcore %u was configured for both RX and WT !!!\n",
96 RTE_LOG(INFO, APP, "entering main loop on lcore %u\n", lcore_id);
97 /* initialize mbuf memory */
98 if (mode == APP_RX_MODE) {
99 for (i = 0; i < rx_idx; i++) {
100 RTE_LOG(INFO, APP, "flow%u lcoreid%u reading port%u\n",
101 i, lcore_id, rx_confs[i]->rx_port);
104 app_rx_thread(rx_confs);
106 else if (mode == (APP_TX_MODE | APP_WT_MODE)) {
107 for (i = 0; i < wt_idx; i++) {
108 wt_confs[i]->m_table = rte_malloc("table_wt", sizeof(struct rte_mbuf *)
109 * burst_conf.tx_burst, RTE_CACHE_LINE_SIZE);
111 if (wt_confs[i]->m_table == NULL)
112 rte_panic("flow %u unable to allocate memory buffer\n", i);
115 "flow %u lcoreid %u sched+write port %u\n",
116 i, lcore_id, wt_confs[i]->tx_port);
119 app_mixed_thread(wt_confs);
121 else if (mode == APP_TX_MODE) {
122 for (i = 0; i < tx_idx; i++) {
123 tx_confs[i]->m_table = rte_malloc("table_tx", sizeof(struct rte_mbuf *)
124 * burst_conf.tx_burst, RTE_CACHE_LINE_SIZE);
126 if (tx_confs[i]->m_table == NULL)
127 rte_panic("flow %u unable to allocate memory buffer\n", i);
129 RTE_LOG(INFO, APP, "flow%u lcoreid%u write port%u\n",
130 i, lcore_id, tx_confs[i]->tx_port);
133 app_tx_thread(tx_confs);
135 else if (mode == APP_WT_MODE){
136 for (i = 0; i < wt_idx; i++) {
137 RTE_LOG(INFO, APP, "flow %u lcoreid %u scheduling \n", i, lcore_id);
140 app_worker_thread(wt_confs);
150 struct rte_eth_stats stats;
151 static struct rte_eth_stats rx_stats[MAX_DATA_STREAMS];
152 static struct rte_eth_stats tx_stats[MAX_DATA_STREAMS];
154 /* print statistics */
155 for(i = 0; i < nb_pfc; i++) {
156 struct flow_conf *flow = &qos_conf[i];
158 rte_eth_stats_get(flow->rx_port, &stats);
159 printf("\nRX port %"PRIu16": rx: %"PRIu64 " err: %"PRIu64
160 " no_mbuf: %"PRIu64 "\n",
162 stats.ipackets - rx_stats[i].ipackets,
163 stats.ierrors - rx_stats[i].ierrors,
164 stats.rx_nombuf - rx_stats[i].rx_nombuf);
165 memcpy(&rx_stats[i], &stats, sizeof(stats));
167 rte_eth_stats_get(flow->tx_port, &stats);
168 printf("TX port %"PRIu16": tx: %" PRIu64 " err: %" PRIu64 "\n",
170 stats.opackets - tx_stats[i].opackets,
171 stats.oerrors - tx_stats[i].oerrors);
172 memcpy(&tx_stats[i], &stats, sizeof(stats));
175 printf("-------+------------+------------+\n");
176 printf(" | received | dropped |\n");
177 printf("-------+------------+------------+\n");
178 printf(" RX | %10" PRIu64 " | %10" PRIu64 " |\n",
179 flow->rx_thread.stat.nb_rx,
180 flow->rx_thread.stat.nb_drop);
181 printf("QOS+TX | %10" PRIu64 " | %10" PRIu64 " | pps: %"PRIu64 " \n",
182 flow->wt_thread.stat.nb_rx,
183 flow->wt_thread.stat.nb_drop,
184 flow->wt_thread.stat.nb_rx - flow->wt_thread.stat.nb_drop);
185 printf("-------+------------+------------+\n");
187 memset(&flow->rx_thread.stat, 0, sizeof(struct thread_stat));
188 memset(&flow->wt_thread.stat, 0, sizeof(struct thread_stat));
194 main(int argc, char **argv)
198 ret = app_parse_args(argc, argv);
206 /* launch per-lcore init on every lcore */
207 rte_eal_mp_remote_launch(app_main_loop, NULL, SKIP_MASTER);
214 /* print statistics every second */