From patchwork Thu May 19 13:03:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forrest Shi X-Patchwork-Id: 68109 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3049004qge; Thu, 19 May 2016 00:37:40 -0700 (PDT) X-Received: by 10.55.140.69 with SMTP id o66mr12938690qkd.188.1463643460605; Thu, 19 May 2016 00:37:40 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u5si10159562qkl.180.2016.05.19.00.37.40; Thu, 19 May 2016 00:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4E83261776; Thu, 19 May 2016 07:37:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DATE_IN_FUTURE_03_06, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 794E8617E8; Thu, 19 May 2016 07:35:17 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5900561694; Thu, 19 May 2016 07:35:07 +0000 (UTC) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0094.outbound.protection.outlook.com [65.55.169.94]) by lists.linaro.org (Postfix) with ESMTPS id C493B61579 for ; Thu, 19 May 2016 07:33:43 +0000 (UTC) Received: from BY2PR03CA012.namprd03.prod.outlook.com (10.255.93.29) by BN1PR0301MB0596.namprd03.prod.outlook.com (10.160.170.23) with Microsoft SMTP Server (TLS) id 15.1.497.12; Thu, 19 May 2016 07:33:43 +0000 Received: from BN1AFFO11FD040.protection.gbl (10.255.93.4) by BY2PR03CA012.outlook.office365.com (10.255.93.29) with Microsoft SMTP Server (TLS) id 15.1.492.11 via Frontend Transport; Thu, 19 May 2016 07:33:42 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning linaro.org discourages use of 192.88.168.50 as permitted sender) Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD040.mail.protection.outlook.com (10.58.52.251) with Microsoft SMTP Server (TLS) id 15.1.497.8 via Frontend Transport; Thu, 19 May 2016 07:33:42 +0000 Received: from netperf2.ap.freescale.net ([10.232.133.164]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u4J7Xdph015981; Thu, 19 May 2016 00:33:40 -0700 From: To: Date: Thu, 19 May 2016 18:33:25 +0530 Message-ID: <1463663005-1392-1-git-send-email-forrest.shi@linaro.org> X-Mailer: git-send-email 2.8.2 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131081168223840060; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(199003)(189002)(9170700003)(104016004)(2906002)(2876002)(1220700001)(50986999)(50226002)(92566002)(77096005)(8936002)(5008740100001)(11100500001)(19580405001)(586003)(6806005)(48376002)(86362001)(86152002)(19580395003)(4326007)(110136002)(189998001)(87936001)(50466002)(105596002)(36756003)(2351001)(229853001)(81166006)(5003940100001)(33646002)(8676002)(106466001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0596; H:tx30smr01.am.freescale.net; FPR:; SPF:SoftFail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD040; 1:zt5XPWIdjYzobz4ORIX3ayXKaBMtSCMaTfs175UxY6mucUAIjQov8rOBA2OAQcy2ZlLnzv9BqybdtLppt89/DS3E1NcnJLw4wjo1MaSkiQS4M9Al/FmoItcUwQNQ95vZpmxypZZ1vUBirdabtbqDbA78IIRTVB3KXvUT6JFXieV57SPxAS8vWPHuyiTmId7Nqd+EtXKX84Bdt4DwLTnWrrHVYXaLnoDggnIq0GVmC2bFnaaFeJIWJ71M18tUge/nQvtT7BaS//PL9sE+Cl15HqE2NG43Yl/rzL1qIgMsokG8ZFkDykLYaksOkenoRUL4HqPlIcvDtIZ3qmoV2CgJbB754P60UTzaRZnHRriYYp/7IGGzeJT9tmStR7Krt4EidAbHKLZmbPZ2jnbiu49cLRPYKPTdPa6yL3pOTR2P1eOtt72y2Pgr2rgstljTlUFMmuW9aDG16HwgcWdV6NXoNWFIdg6ktnU3I5MzmF2XPufqiiVCCn1kK/t9+HlN/j9pcCwNtRyQU+1Dc99GKvDSgWwypgqjZhHM3aHm8BBDoAWNg/xZ/q75QU/PJx4OiwWJhpWyV6ibVQP3ct+GN9ZoRQ== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 28829218-0da0-4a5c-9c34-08d37fb7e71d X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0596; 2:gEykUvQeb5ZDHNyNSe7BDHbBWhSUrQ1NAqf8822X7T1G9wTajQ7a5tiFgnO3CWx9qqUoa0Z7HMl0M2Nyf+VFyFFAS2m58Bz10Z8j2VYZ5K0Bok5ddujJF5BZ5QM+2smc3unoYQVGwH2dfosWba57UZCJXohRuHA+1g8+7Mi5b1mtxyAVbAOO9sK1avSzXU9i; 3:ZRSMM+u4lhR6BQr4cIbH6xj79c69JxsE7yruupgbF1UHaJxb5Ozm/IOLf6I6gfujp3JxCDq2JZT6iHoSiod6/kOHs7i23mxY5AL/CpMHKjZikdYKBfq2S8QFsLTNjpJIfCjnSTDlAlBLmKMv9MmZyIihYtxxGq+/y4dAItGRC/RB9WsLyt9d06N0ic7PwQiJZPArGwb1dTgaXLkJ0yjar6R1cinq+9bpTVYIX+V855Y= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0596; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0596; 25:StADnN2eXuCbAII2tVYoxoQmbDubsCEfqotiYn4UdoGJjNiLlxMfMpcmZ6+Ub0BmpDyvHoHK0+/RMwD0DC9OYdgh8DxY9yt0qUPZ8XcaFSxkgEuOz9gmt5cKJ2hHSnQ1fL8Qm48+FMzTTlBtCmxvpXw8mgnsYtMLsrsI82okbTBzDfWcO0DOK128RdWVMiUoCZOFaC8z6F1jn/31fwkgEhv+KoRvUo9JG1hmbeZroUhEik+o145bNdeq8iVEwQjPGQ+FqXMVR1hBSJIELFIS7GOvqxLu0mj4KunQF0itemrRyp4R1r+25OFzB2Wzd00KU7LXpN69FkstYOsJbtm+I7kufhvqvzIa7KEuTXohNZzb5elyN/RIgybQj0Ux8DjVMG190pwaKgnFAqLHD5Lmcr1I/j+zM8BPaxdLpog0/Ok5hbljuvxRCh3zALFrdqZ7ylRZBAKC1LWPvpxEpFBdCWKsT3/+fLWjG1OKPpVKlhwgk8msr98PVCjNQcgHjAiThwN3l5w9/E1bFYd2TiJmPfxvJTToFEVIZe+HFq4AYK8qzj7JSPoBc7QoRtcbQEeJ0eZzWrhiHrMwQsnTlJ8ThvKvkun5wf0uGfOIIvsyurSoY3g6NnDa3DvMgReScncSJWCLWunxtOwMx159vrn95Wo235D6iTRPnlJmR/OsDlVYoS4iPcEPaQNjn0pIe391sVXojni/gea6JD7qhhuUbw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13024025)(13023025)(13018025)(13017025)(13015025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:BN1PR0301MB0596; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0596; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0596; 4:077T0qzORefNI1cvGVWas+APYl32H43ldAqrR82NTlEZ3Vhcx2fhQe57clJpAucNDjIGeaPHSdpZQwPEAmr6n8+uJCZFdqy+8Oe3Ue3siiO7AiiXCSPJs0ZMEVibH42mzedO7cf4PPXhZsc2hF3XK05X4rAzKB0ekSgHYiXAX0OK9FT9BlxyQCucfzrrGZqPYvMCXcBL0esHdcX+rVawpDR4gGoW3RVNsvYWrz9Dfv8vkkwsFobnPsy8DjB4SdDu3ZrMzrb/W5wSX27xnRYv81cvKOioqswD4SWogS04zNo6/s+G+Uz0dYokFcLDRf088yOkn3Harja5RLEc3YkEgefC2g4P2Q1uQRFOPCSx4fd9IB/zXQfp4RYPFYccJPHgx9M2H59JmGrNvgH7Lwsxzp+rlf0MbD7oBuX2TkczSSDD35cVr7uJ5bm4CPyJVT3EjvyThSKaEEaMYpkowBIONvAODNmK5yVRbvnKVOVly14= X-Forefront-PRVS: 094700CA91 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0596; 23:9ACQKCZG8Rt2Kw+V1TgTmgBLdW0eqFesbVkdeLj?= =?us-ascii?Q?IhuqYxMNtMb1xj2yJbWI9F6VND/Gd8xYg1ATw9yhvICVtvQiVe8BhjsmBPDY?= =?us-ascii?Q?nrM8LhHWPDmVz4WSL8pQwNYCZ0acYg0eH95IeA8qiYcRImvM1bvZTNgaKLzF?= =?us-ascii?Q?lGek1/WwzOrY3tP9jRPHXuuykfgQ6olnDwifRkhxIkkYFiMdbnwYbh28nIMu?= =?us-ascii?Q?jdRGTqlh/RgX8GNdkg4n/aFtqmCl+QxUe2tcGd2sDKUwdYKzu1Ko86MoLwYj?= =?us-ascii?Q?11r9EMRmXskDt6ONkao3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PnUYYH5DOFWCtxOU=; 24:8MHSYHUW1ExPoie50Rndgjhu6O7bMi2OltjVFGrkpwWufTag/IZi1ncBSa0Vjb1pwjhEIihF3dVCEszkBDERzgB2/Rkb4l+icjCVPR8j3eo=; 7:4WR1Y/axHIiliRPQsWbdXgCwbYxYob2QysHGYERYpbYaI+9RutR/ys0syI76a4Sgr+EtQi1fc+g9+z64lTLDAF6xnvPCfUCOFel+4M3RM5hCPr/mqk38YfaBhIFjXNzH50S++cz4On9d2LbgFmQS1sekrM7X+XtWNYcE6zoI2FJWMwVxyTZIQXCYrfh52u8R SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2016 07:33:42.0876 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0596 X-Topics: patch Subject: [lng-odp] [PATCH 5/5] example:l3fwd: add option -t in command line X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Xuelin Shi specify the number of threads to do forwarding. support at most cpu-1 forwarding threads, one thread for each port. Signed-off-by: Xuelin Shi --- example/l3fwd/odp_l3fwd.c | 66 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/example/l3fwd/odp_l3fwd.c b/example/l3fwd/odp_l3fwd.c index 5598a5a..61e90b9 100644 --- a/example/l3fwd/odp_l3fwd.c +++ b/example/l3fwd/odp_l3fwd.c @@ -33,8 +33,9 @@ typedef struct { char *if_names[MAX_NB_PKTIO]; - uint32_t if_count; + int if_count; char *route_str[MAX_NB_ROUTE]; + int worker_count; } app_args_t; struct l3fwd_pktio_s { @@ -256,8 +257,16 @@ int main(int argc, char **argv) printf("create pktio %s, mac %s\n", args->if_names[i], buf); } - /* one thread for each port */ - global.nb_worker = args->if_count; + /* at most cpu_count-1 threads, only 1 thread on 1 port. + * TODO: assign more threads for each port + */ + if (args->worker_count == 0) + args->worker_count = args->if_count; + if (args->worker_count >= odp_cpu_count()) + args->worker_count = odp_cpu_count() - 1; + + global.nb_worker = args->worker_count; + memset(&thr_params, 0, sizeof(thr_params)); thr_params.start = run_worker; thr_params.thr_type = ODP_THREAD_WORKER; @@ -298,8 +307,10 @@ static void print_usage(char *progname) " -r, --route SubNet:Intf[:NextHopMAC]\n" " NextHopMAC can be optional, in this case, zeroed mac\n" "\n" - "Optional OPTIONS\n" - " -h, --help Display help and exit.\n\n" + "Optional OPTIONS:\n" + " -t, --thread number of threads to do forwarding\n" + " optional, default as cpu count\n" + " -h, --help Display help and exit.\n\n" "\n", NO_PATH(progname), NO_PATH(progname) ); } @@ -315,18 +326,30 @@ static void parse_cmdline_args(int argc, char *argv[], app_args_t *args) static struct option longopts[] = { {"interface", required_argument, NULL, 'i'}, /* return 'i' */ {"route", required_argument, NULL, 'r'}, /* return 'r' */ + {"thread", optional_argument, NULL, 't'}, /* return 't'*/ {"help", no_argument, NULL, 'h'}, /* return 'h' */ {NULL, 0, NULL, 0} }; while (1) { - opt = getopt_long(argc, argv, "+i:r:h", + opt = getopt_long(argc, argv, "+t:i:r:h", longopts, &long_index); if (opt == -1) break; /* No more options */ switch (opt) { + /* parse number of worker threads to be run*/ + case 't': + i = odp_cpu_count(); + args->worker_count = atoi(optarg); + if (args->worker_count > i) { + printf("Too many threads," + "truncate to cpu count: %d\n", i); + args->worker_count = i; + } + + break; /* parse packet-io interface names */ case 'i': len = strlen(optarg); @@ -352,8 +375,14 @@ static void parse_cmdline_args(int argc, char *argv[], app_args_t *args) if (i == 0) { print_usage(argv[0]); exit(EXIT_FAILURE); + } else if ((i & 1) != 0) { + printf("even number of ports expected, " + "got %u.\n", i); + exit(EXIT_FAILURE); + } else if (i > MAX_NB_PKTIO) { + printf("too many ports specified, " + "truncated to max %d", MAX_NB_PKTIO); } - args->if_count = i; /* store the if names (reset names string) */ @@ -390,17 +419,32 @@ static void parse_cmdline_args(int argc, char *argv[], app_args_t *args) } } - if (args->if_count == 0 || mem_failure == 1) { - print_usage(argv[0]); - exit(EXIT_FAILURE); + /* checking arguments */ + if (args->if_count == 0) { + printf("\nNo option -i specified.\n"); + goto out; + } + + if (args->route_str[0]== NULL) { + printf("\nNo option -r specified.\n"); + goto out; } + if (mem_failure == 1) { + printf("\nAllocate memory failure.\n"); + goto out; + } optind = 1; /* reset 'extern optind' from the getopt lib */ + return; + +out: + print_usage(argv[0]); + exit(EXIT_FAILURE); } static void print_info(char *progname, app_args_t *args) { - uint32_t i; + int i; printf("\n" "ODP system info\n"