1474572d2SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2474572d2SBruce Richardson * Copyright(c) 2010-2016 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> 13*f6897b23SFeifei Wang #include <signal.h> 14474572d2SBruce Richardson #include <errno.h> 15474572d2SBruce Richardson #include <getopt.h> 16474572d2SBruce Richardson #include <unistd.h> 17474572d2SBruce Richardson 18474572d2SBruce Richardson #include <rte_common.h> 19474572d2SBruce Richardson #include <rte_byteorder.h> 20474572d2SBruce Richardson #include <rte_log.h> 21474572d2SBruce Richardson #include <rte_memory.h> 22474572d2SBruce Richardson #include <rte_memcpy.h> 23474572d2SBruce Richardson #include <rte_eal.h> 24474572d2SBruce Richardson #include <rte_per_lcore.h> 25474572d2SBruce Richardson #include <rte_launch.h> 26474572d2SBruce Richardson #include <rte_cycles.h> 27474572d2SBruce Richardson #include <rte_prefetch.h> 28474572d2SBruce Richardson #include <rte_lcore.h> 29474572d2SBruce Richardson #include <rte_branch_prediction.h> 30474572d2SBruce Richardson #include <rte_interrupts.h> 31474572d2SBruce Richardson #include <rte_pci.h> 32474572d2SBruce Richardson #include <rte_random.h> 33474572d2SBruce Richardson #include <rte_debug.h> 34474572d2SBruce Richardson #include <rte_ether.h> 35474572d2SBruce Richardson #include <rte_ethdev.h> 36474572d2SBruce Richardson #include <rte_mempool.h> 37474572d2SBruce Richardson #include <rte_mbuf.h> 38474572d2SBruce Richardson #include <rte_ip.h> 39474572d2SBruce Richardson #include <rte_tcp.h> 40474572d2SBruce Richardson #include <rte_lpm.h> 41474572d2SBruce Richardson #include <rte_lpm6.h> 42474572d2SBruce Richardson 43474572d2SBruce Richardson #include "main.h" 44474572d2SBruce Richardson 45*f6897b23SFeifei Wang bool force_quit; 46*f6897b23SFeifei Wang 47*f6897b23SFeifei Wang static void 48*f6897b23SFeifei Wang signal_handler(int signum) 49*f6897b23SFeifei Wang { 50*f6897b23SFeifei Wang if (signum == SIGINT || signum == SIGTERM) 51*f6897b23SFeifei Wang force_quit = true; 52*f6897b23SFeifei Wang } 53*f6897b23SFeifei Wang 54474572d2SBruce Richardson int 55474572d2SBruce Richardson main(int argc, char **argv) 56474572d2SBruce Richardson { 57474572d2SBruce Richardson uint32_t lcore; 58474572d2SBruce Richardson int ret; 59474572d2SBruce Richardson 60474572d2SBruce Richardson /* Init EAL */ 61474572d2SBruce Richardson ret = rte_eal_init(argc, argv); 62474572d2SBruce Richardson if (ret < 0) 63474572d2SBruce Richardson return -1; 64474572d2SBruce Richardson argc -= ret; 65474572d2SBruce Richardson argv += ret; 66474572d2SBruce Richardson 67*f6897b23SFeifei Wang force_quit = false; 68*f6897b23SFeifei Wang signal(SIGINT, signal_handler); 69*f6897b23SFeifei Wang signal(SIGTERM, signal_handler); 70*f6897b23SFeifei Wang 71474572d2SBruce Richardson /* Parse application arguments (after the EAL ones) */ 72474572d2SBruce Richardson ret = app_parse_args(argc, argv); 73474572d2SBruce Richardson if (ret < 0) { 74474572d2SBruce Richardson app_print_usage(); 75474572d2SBruce Richardson return -1; 76474572d2SBruce Richardson } 77474572d2SBruce Richardson 78474572d2SBruce Richardson /* Init */ 79474572d2SBruce Richardson app_init(); 80474572d2SBruce Richardson 81474572d2SBruce Richardson /* Launch per-lcore init on every lcore */ 82cb056611SStephen Hemminger rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MAIN); 83cb056611SStephen Hemminger RTE_LCORE_FOREACH_WORKER(lcore) { 84474572d2SBruce Richardson if (rte_eal_wait_lcore(lcore) < 0) 85474572d2SBruce Richardson return -1; 86474572d2SBruce Richardson } 87474572d2SBruce Richardson 88474572d2SBruce Richardson return 0; 89474572d2SBruce Richardson } 90474572d2SBruce Richardson 91474572d2SBruce Richardson int 92f2fc83b4SThomas Monjalon app_lcore_main_loop(__rte_unused void *arg) 93474572d2SBruce Richardson { 94474572d2SBruce Richardson unsigned lcore; 95474572d2SBruce Richardson 96474572d2SBruce Richardson lcore = rte_lcore_id(); 97474572d2SBruce Richardson 98474572d2SBruce Richardson if (lcore == app.core_rx) { 99474572d2SBruce Richardson switch (app.pipeline_type) { 100474572d2SBruce Richardson case e_APP_PIPELINE_ACL: 101474572d2SBruce Richardson app_main_loop_rx(); 102474572d2SBruce Richardson return 0; 103474572d2SBruce Richardson 104474572d2SBruce Richardson default: 105474572d2SBruce Richardson app_main_loop_rx_metadata(); 106474572d2SBruce Richardson return 0; 107474572d2SBruce Richardson } 108474572d2SBruce Richardson } 109474572d2SBruce Richardson 110474572d2SBruce Richardson if (lcore == app.core_worker) { 111474572d2SBruce Richardson switch (app.pipeline_type) { 112474572d2SBruce Richardson case e_APP_PIPELINE_STUB: 113474572d2SBruce Richardson app_main_loop_worker_pipeline_stub(); 114474572d2SBruce Richardson return 0; 115474572d2SBruce Richardson 116474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY8_EXT: 117474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY8_LRU: 118474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY16_EXT: 119474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY16_LRU: 120474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY32_EXT: 121474572d2SBruce Richardson case e_APP_PIPELINE_HASH_KEY32_LRU: 122474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT: 123474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU: 124474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT: 125474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU: 126474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT: 127474572d2SBruce Richardson case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU: 128474572d2SBruce Richardson /* cases for cuckoo hash table types */ 129474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY8: 130474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY16: 131474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY32: 132474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY48: 133474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY64: 134474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY80: 135474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY96: 136474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY112: 137474572d2SBruce Richardson case e_APP_PIPELINE_HASH_CUCKOO_KEY128: 138474572d2SBruce Richardson app_main_loop_worker_pipeline_hash(); 139474572d2SBruce Richardson return 0; 140474572d2SBruce Richardson 141474572d2SBruce Richardson case e_APP_PIPELINE_ACL: 142a8d0d473SBruce Richardson #ifndef RTE_LIB_ACL 143474572d2SBruce Richardson rte_exit(EXIT_FAILURE, "ACL not present in build\n"); 144474572d2SBruce Richardson #else 145474572d2SBruce Richardson app_main_loop_worker_pipeline_acl(); 146474572d2SBruce Richardson return 0; 147474572d2SBruce Richardson #endif 148474572d2SBruce Richardson 149474572d2SBruce Richardson case e_APP_PIPELINE_LPM: 150474572d2SBruce Richardson app_main_loop_worker_pipeline_lpm(); 151474572d2SBruce Richardson return 0; 152474572d2SBruce Richardson 153474572d2SBruce Richardson case e_APP_PIPELINE_LPM_IPV6: 154474572d2SBruce Richardson app_main_loop_worker_pipeline_lpm_ipv6(); 155474572d2SBruce Richardson return 0; 156474572d2SBruce Richardson 157474572d2SBruce Richardson case e_APP_PIPELINE_NONE: 158474572d2SBruce Richardson default: 159474572d2SBruce Richardson app_main_loop_worker(); 160474572d2SBruce Richardson return 0; 161474572d2SBruce Richardson } 162474572d2SBruce Richardson } 163474572d2SBruce Richardson 164474572d2SBruce Richardson if (lcore == app.core_tx) { 165474572d2SBruce Richardson app_main_loop_tx(); 166474572d2SBruce Richardson return 0; 167474572d2SBruce Richardson } 168474572d2SBruce Richardson 169474572d2SBruce Richardson return 0; 170474572d2SBruce Richardson } 171