1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #include <unistd.h> 6 #include <stdint.h> 7 8 #include <rte_log.h> 9 #include <rte_mbuf.h> 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> 16 17 #include <rte_sched.h> 18 19 #include "main.h" 20 21 #define APP_MODE_NONE 0 22 #define APP_RX_MODE 1 23 #define APP_WT_MODE 2 24 #define APP_TX_MODE 4 25 26 uint8_t interactive = APP_INTERACTIVE_DEFAULT; 27 uint32_t qavg_period = APP_QAVG_PERIOD; 28 uint32_t qavg_ntimes = APP_QAVG_NTIMES; 29 30 /* main processing loop */ 31 static int 32 app_main_loop(__rte_unused void *dummy) 33 { 34 uint32_t lcore_id; 35 uint32_t i, mode; 36 uint32_t rx_idx = 0; 37 uint32_t wt_idx = 0; 38 uint32_t tx_idx = 0; 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]; 42 43 memset(rx_confs, 0, sizeof(rx_confs)); 44 memset(wt_confs, 0, sizeof(wt_confs)); 45 memset(tx_confs, 0, sizeof(tx_confs)); 46 47 48 mode = APP_MODE_NONE; 49 lcore_id = rte_lcore_id(); 50 51 for (i = 0; i < nb_pfc; i++) { 52 struct flow_conf *flow = &qos_conf[i]; 53 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; 59 60 rx_confs[rx_idx++] = &flow->rx_thread; 61 62 mode |= APP_RX_MODE; 63 } 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; 68 69 tx_confs[tx_idx++] = &flow->tx_thread; 70 71 mode |= APP_TX_MODE; 72 } 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; 78 79 wt_confs[wt_idx++] = &flow->wt_thread; 80 81 mode |= APP_WT_MODE; 82 } 83 } 84 85 if (mode == APP_MODE_NONE) { 86 RTE_LOG(INFO, APP, "lcore %u has nothing to do\n", lcore_id); 87 return -1; 88 } 89 90 if (mode == (APP_RX_MODE | APP_WT_MODE)) { 91 RTE_LOG(INFO, APP, "lcore %u was configured for both RX and WT !!!\n", 92 lcore_id); 93 return -1; 94 } 95 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); 102 } 103 104 app_rx_thread(rx_confs); 105 } 106 else if (mode == (APP_TX_MODE | APP_WT_MODE)) { 107 for (i = 0; i < wt_idx; i++) { 108 RTE_LOG(INFO, APP, 109 "flow %u lcoreid %u sched+write port %u\n", 110 i, lcore_id, wt_confs[i]->tx_port); 111 } 112 113 app_mixed_thread(wt_confs); 114 } 115 else if (mode == APP_TX_MODE) { 116 for (i = 0; i < tx_idx; i++) { 117 RTE_LOG(INFO, APP, "flow%u lcoreid%u write port%u\n", 118 i, lcore_id, tx_confs[i]->tx_port); 119 } 120 121 app_tx_thread(tx_confs); 122 } 123 else if (mode == APP_WT_MODE){ 124 for (i = 0; i < wt_idx; i++) { 125 RTE_LOG(INFO, APP, "flow %u lcoreid %u scheduling \n", i, lcore_id); 126 } 127 128 app_worker_thread(wt_confs); 129 } 130 131 return 0; 132 } 133 134 void 135 app_stat(void) 136 { 137 uint32_t i; 138 struct rte_eth_stats stats; 139 static struct rte_eth_stats rx_stats[MAX_DATA_STREAMS]; 140 static struct rte_eth_stats tx_stats[MAX_DATA_STREAMS]; 141 142 /* print statistics */ 143 for(i = 0; i < nb_pfc; i++) { 144 struct flow_conf *flow = &qos_conf[i]; 145 146 rte_eth_stats_get(flow->rx_port, &stats); 147 printf("\nRX port %"PRIu16": rx: %"PRIu64 " err: %"PRIu64 148 " no_mbuf: %"PRIu64 "\n", 149 flow->rx_port, 150 stats.ipackets - rx_stats[i].ipackets, 151 stats.ierrors - rx_stats[i].ierrors, 152 stats.rx_nombuf - rx_stats[i].rx_nombuf); 153 memcpy(&rx_stats[i], &stats, sizeof(stats)); 154 155 rte_eth_stats_get(flow->tx_port, &stats); 156 printf("TX port %"PRIu16": tx: %" PRIu64 " err: %" PRIu64 "\n", 157 flow->tx_port, 158 stats.opackets - tx_stats[i].opackets, 159 stats.oerrors - tx_stats[i].oerrors); 160 memcpy(&tx_stats[i], &stats, sizeof(stats)); 161 162 #if APP_COLLECT_STAT 163 printf("-------+------------+------------+\n"); 164 printf(" | received | dropped |\n"); 165 printf("-------+------------+------------+\n"); 166 printf(" RX | %10" PRIu64 " | %10" PRIu64 " |\n", 167 flow->rx_thread.stat.nb_rx, 168 flow->rx_thread.stat.nb_drop); 169 printf("QOS+TX | %10" PRIu64 " | %10" PRIu64 " | pps: %"PRIu64 " \n", 170 flow->wt_thread.stat.nb_rx, 171 flow->wt_thread.stat.nb_drop, 172 flow->wt_thread.stat.nb_rx - flow->wt_thread.stat.nb_drop); 173 printf("-------+------------+------------+\n"); 174 175 memset(&flow->rx_thread.stat, 0, sizeof(struct thread_stat)); 176 memset(&flow->wt_thread.stat, 0, sizeof(struct thread_stat)); 177 #endif 178 } 179 } 180 181 int 182 main(int argc, char **argv) 183 { 184 int ret; 185 186 ret = app_parse_args(argc, argv); 187 if (ret < 0) 188 return -1; 189 190 ret = app_init(); 191 if (ret < 0) 192 return -1; 193 194 /* launch per-lcore init on every lcore */ 195 rte_eal_mp_remote_launch(app_main_loop, NULL, SKIP_MAIN); 196 197 if (interactive) { 198 sleep(1); 199 prompt(); 200 } 201 else { 202 /* print statistics every second */ 203 while(1) { 204 sleep(1); 205 app_stat(); 206 } 207 } 208 209 /* clean up the EAL */ 210 rte_eal_cleanup(); 211 212 return 0; 213 } 214