From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2392D433AC; Thu, 23 Nov 2023 16:50:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1513142F21; Thu, 23 Nov 2023 16:50:46 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id D0EED42F1B for ; Thu, 23 Nov 2023 16:50:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700754644; x=1732290644; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=x2IE30BXtgyJNc8nH5aJ4ADPROsH9RsEDA2YE6W5MKA=; b=mAJ1CSGsJhYAKSV5yu6nGY5zyU4o8MfQCxrR8bcpVbHIIettSzwilJ2t Oy14GH1AeZCLCUlIc1kQFIxoe861y02P1pLz1SWAsmOQYHBK+oUtR45FU eM7jdQsMJTbq+P+2YczoCn7T4RxviUIGNe/rooXXlb261gJVyXcMSFLTs C88urNWR9aG0LaXcYLg6gIvtqh/PGR/mVnWo1x/8TJSVy7IdgJie6gwgM ElXY/KBjtvM0oBuKviVisMkslPmujZi6rc4ogEJK5TF1zJdYpHUupezPG 5SryNyQi60fBX1YgkFfaZhII68LCmfxmSDZqjOMHHtQAEY0TBvylgMHLz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="5435096" X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="5435096" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 07:50:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="8880559" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa002.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 23 Nov 2023 07:50:42 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 23 Nov 2023 07:50:42 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 23 Nov 2023 07:50:42 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Thu, 23 Nov 2023 07:50:42 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.169) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Thu, 23 Nov 2023 07:50:41 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QPoUGnHqiSD+o6GB5xQB9vBmDdZ7gY9gJzQMC8cqv80HGfchZIGiA/HfVn6xHSk1nWcmFWmx3iDcWBmWZkkoByBNYAz2436yDRIZUz3fh2ZfkAcRVCFlGiZRXNL5HbnrdRNdh3XJZK2ofMWD8mI4/VoisNbD25CL5zculb74UQBBHSQ21mkFATN0xGYnRzeeYmXBCr+iShpPB4H/lg4UxK3sNUsz8wGVF/ymDSOFLA0cTjUwM/vSk/LyrfZ0ufaJm9SZGrDzTsHnG5FhG58pYDWqNKi1OZwo4ozyFVScuOTmmigzwhf+UIAnT6YZETpWguGFjBvSvmAhoFUdkdR7rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gJ9rOqT5EUZoOZiAZV7vNfyM0nhODl56iLfMv+J39cc=; b=IyzB5VBtoJQJNiVasCVcIO1A7v33EmLaYXYaHAPUiMKjseH0FBGBFYo2bATdBJ5dPtGaW6fYq5jzpK3eUFBGMrBCnrYZUQRSdM1O/XasV0xjhwstxATwbZ+arVlOGOLqFRpabqxHztWv74O2rcJRywYhN/9fL4iZ+OxcZoZut8hhd1Ffa7flK3ZGrnPGdf2nK0ZSaOMdJHmiSTyuUtemf1h5eSRY//0DZLUPP2PbDcqsOod0PiB4X/2gPC4n18cZQZ69+7DdWrk6t0tHviQm35uELhh16Bil9npKESPiyy9MZMahy8U9l7WkVOPuWP2Qxg+DHuntUqxVVe+M8R8rbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by SA3PR11MB7464.namprd11.prod.outlook.com (2603:10b6:806:31b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28; Thu, 23 Nov 2023 15:50:39 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::4782:d54a:209d:cb49]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::4782:d54a:209d:cb49%7]) with mapi id 15.20.7025.020; Thu, 23 Nov 2023 15:50:39 +0000 Date: Thu, 23 Nov 2023 15:50:34 +0000 From: Bruce Richardson To: Euan Bourke CC: Subject: Re: [PATCH 24.03 1/4] arg_parser: new library for command line parsing Message-ID: References: <20231122164550.3873633-1-euan.bourke@intel.com> <20231122164550.3873633-2-euan.bourke@intel.com> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231122164550.3873633-2-euan.bourke@intel.com> X-ClientProxiedBy: DB9PR05CA0004.eurprd05.prod.outlook.com (2603:10a6:10:1da::9) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|SA3PR11MB7464:EE_ X-MS-Office365-Filtering-Correlation-Id: da38672b-a002-4c9f-3b4f-08dbec3bf0c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 70ghT5lqbf1A+nsx5WWzmihrS4+mG+HgXpeJYGSHikcjF/dajluSG2QRxdNz733U41iT+iFBu7VmUjNWHlNSxjmNbQOlYDsoc+5ZiLywdMBYZHI2QHzKdGv4btqdciXJai62Xd9L7Gu1nOcVPUXEjFyhrIpnPidV2sKFdEnYhr5idNsyfmaaxNTgTKUCFkXOuDXh/6ZgHlmkXt2IxE7EGQHTH2XnUTOcMVTB5TgHR4eprlmTRe4X6NT0CUFtbA7ECGvXpYS567+uDGcArADj+BsOjgNTRFFUraq4FNLsINc7j2dqIS+Vg9ANYS23CDIc+HM5vrLTxCNa7FPWEZAKOQ9Uz7PP0dKKxXoMFiMXN0onwouPlFhtTOqwBH012/KVdCBDBYNMNhttAOHaHd0Torunf7AP7rOz1OAB6YWy2+nin1FeBxoIfVg+cKE9LNlvsN2WPvuEF7v7ET+gr7CMz+ZcQ0hpDycMHxgaeJ+wpzJ6xxFty72KQXHFEE5Fl5TLvfO4PGBRht7Wtn4hnx8b3SyC0/JrI6bqeAlG7QuproqRKwMhypcZxrGA0UB5yGJL X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(136003)(376002)(366004)(39860400002)(396003)(230922051799003)(64100799003)(451199024)(186009)(1800799012)(86362001)(5660300002)(8936002)(2906002)(8676002)(44832011)(4326008)(66946007)(6636002)(66556008)(66476007)(316002)(6862004)(41300700001)(66574015)(82960400001)(26005)(83380400001)(6506007)(6512007)(6666004)(38100700002)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?sOj0wORMdbYkoNDWI7ui9ZZ3RwrQPwNplRBLBIXS2aUm2o3v1HPPt1h36g?= =?iso-8859-1?Q?SfDra4BxfK/6yLNWh7BqN68Bq1q+66w7c06anq8VOG1esVT2UzrJBLKp6B?= =?iso-8859-1?Q?2atkfQmJ5deXdh6RGmR8QdCDdD1LzteMplejDYYxNWGqpsCWfJ44clZxdy?= =?iso-8859-1?Q?GXU7EQBN1pQhSwEzcZ3POna3c+ecwVTKWlrhiMD/A6dNipNlNe+Zq+hUv3?= =?iso-8859-1?Q?/71YDG5tg/shudRjs93uGeZcYj6I7zAwaF/9cQsOXKsXQLusS7eEd6xAYH?= =?iso-8859-1?Q?90bXe3AvVZ+s5nIiyf76EZ4YYjXFsMaMIXhDO7Dm8BCjmVqlXL14eqz2RU?= =?iso-8859-1?Q?aY7NBE3rlcGDlD6luGDIsO8khiOHI6i1jzoxk7M4Q3Zo0c6zTgiLfX7gM4?= =?iso-8859-1?Q?vx9Xt4fbwSaHteuLAnE99k6ntiK3A9gRP4lMl0Kod19M8CSoMMv/vHYiW8?= =?iso-8859-1?Q?1Dej027X2k+KZGCO5WBLD8ZA7ycj0vb4keit5xMAIJRmFKmW8UVUVyTEiF?= =?iso-8859-1?Q?L/hAD7ocCEWkNrNF/WYJM9Q3b40Y23kYxSQToVEHA6eyh8zpUH93KbSycW?= =?iso-8859-1?Q?DuOnuNesD3D67UJwig02TmVXeWMkjrt2NOJbnGOiCP5MN+DjxUyWWjhpJ2?= =?iso-8859-1?Q?hdOgUx9+MD9A7l2d0brFbOWuaY5mxIZu3tdFAw7QSQ639qkVl2w6W0/84F?= =?iso-8859-1?Q?66cMAcZRfXgC1suwhHr7Rs7HzzbPnUf34uS0dgjR8dCiYBs+4yPj/fwLQC?= =?iso-8859-1?Q?W2GQftd5+R85phOh0Z1kCS76av12dJL20OOgWRwyLN1ZGPyTl3kYJfQGQV?= =?iso-8859-1?Q?8AWt7pnK7nzQIC1/jCAz0HX/Xufg6Xn7qbOCAQQd4wSjLbhE0BQatnDYZR?= =?iso-8859-1?Q?5ykuDSqi8Sgnc7Zbj/aJwUMQ8xRz5n/2vABsmiN/P6+McQNwmE1XbkKZSl?= =?iso-8859-1?Q?NgYHdg6wp55k8FPJD5/93/p15wNs5V7nxsge3G2YuUC9KqLDUneIePZuAN?= =?iso-8859-1?Q?UHnLhxU+KiDEOR+w22SMJ9RvZfTkGWcKkozs62qdf3FTGuFJqgGRYArdf0?= =?iso-8859-1?Q?99lsWWhmAYfZGUWqC38T90Gi7JSoMQppyl58iTgx4m8QpBKuml5Eec2wy8?= =?iso-8859-1?Q?ACWCjVp6EDwvDQ+rpN9bn6G3joYYAywi/ijaJryNyA81FqwQO2fhWokmbP?= =?iso-8859-1?Q?L2G9/Zp2d58JPp3yNxPEFIRnA+CxZX6OOloQrf0Wvmdj1B9FyAOkpn/vFl?= =?iso-8859-1?Q?VKFyZisJo1zXyLe4KoKHiAUPjsJUEI6BdSKxgmtYQwcO7zDkefDr86yE0D?= =?iso-8859-1?Q?CrebBea64TeFi8aHw/8tjHH/6S3jBauDZKaJ53lM3gt1pZuc65l1cW4KWR?= =?iso-8859-1?Q?yugAyhJaUMAZgc281RqXzFwjbwBd1ASN81vG6LIjpssfVZdftZaasMPA+v?= =?iso-8859-1?Q?knDOJp7RTpt0CIm8mbRqKekuQFm8v0vVJOYebQc2xN3+O2vaVa/43PoMu0?= =?iso-8859-1?Q?TfAB9hXn+CxPX5F3uvC0ZNZ3Qxn+REecJTJDujQttexGCrgUXXlTZJrfIu?= =?iso-8859-1?Q?7HDoVNddrLFUbFS6Ran2l1bJffH6ehRUsB2DS3OLeWYG8O7Duv1Ac9ssQz?= =?iso-8859-1?Q?mPkPxLx4kHMgRznFAP8D0Xc5LaZlDkBIr+HabgxNAhPlSqfu2iluQzxA?= =?iso-8859-1?Q?=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: da38672b-a002-4c9f-3b4f-08dbec3bf0c7 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2023 15:50:39.2476 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ap5KCCA7SgOAD9jg6II9NWrWubUYg/2nIeatwAvwBOFe6BieaTyhrUgC8c//IJeDMJAG/QAfkc+NN60iVob9eyut2aDZBLd8KL2LI37T2V0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR11MB7464 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Nov 22, 2023 at 04:45:47PM +0000, Euan Bourke wrote: > Add a new library to make it easier for eal and other libraries to parse > command line arguments. > > The first function in this library is one to parse a corelist string into an > array of individual core ids. The function will then return the total number > of cores described in the corelist > > Signed-off-by: Euan Bourke Thanks for the patchset. Some comments inline below. /Bruce > --- > .mailmap | 1 + > MAINTAINERS | 5 ++ > doc/api/doxy-api-index.md | 3 +- > doc/api/doxy-api.conf.in | 1 + > lib/arg_parser/arg_parser.c | 113 ++++++++++++++++++++++++++++++++ > lib/arg_parser/meson.build | 7 ++ > lib/arg_parser/rte_arg_parser.h | 66 +++++++++++++++++++ > lib/arg_parser/version.map | 10 +++ > lib/meson.build | 1 + > 9 files changed, 206 insertions(+), 1 deletion(-) > create mode 100644 lib/arg_parser/arg_parser.c > create mode 100644 lib/arg_parser/meson.build > create mode 100644 lib/arg_parser/rte_arg_parser.h > create mode 100644 lib/arg_parser/version.map > > diff --git a/.mailmap b/.mailmap > index 72b216df9c..c1a4bf85f6 100644 > --- a/.mailmap > +++ b/.mailmap > @@ -379,6 +379,7 @@ Eric Zhang > Erik Gabriel Carrillo > Erik Ziegenbalg > Erlu Chen > +Euan Bourke > Eugenio Pérez > Eugeny Parshutin > Evan Swanson > diff --git a/MAINTAINERS b/MAINTAINERS > index cf2af0d3a4..ce81877ce0 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -1753,6 +1753,11 @@ M: Nithin Dabilpuram > M: Pavan Nikhilesh > F: lib/node/ > > +Argument parsing > +M: Bruce Richardson > +M: Euan Bourke > +F: lib/arg_parser/ > + > > Test Applications > ----------------- > diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md > index a6a768bd7c..f711010140 100644 > --- a/doc/api/doxy-api-index.md > +++ b/doc/api/doxy-api-index.md > @@ -221,7 +221,8 @@ The public API headers are grouped by topics: > [config file](@ref rte_cfgfile.h), > [key/value args](@ref rte_kvargs.h), > [string](@ref rte_string_fns.h), > - [thread](@ref rte_thread.h) > + [thread](@ref rte_thread.h), > + [argument parsing](@ref rte_arg_parser.h) > > - **debug**: > [jobstats](@ref rte_jobstats.h), > diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in > index e94c9e4e46..05718ba6ed 100644 > --- a/doc/api/doxy-api.conf.in > +++ b/doc/api/doxy-api.conf.in > @@ -28,6 +28,7 @@ INPUT = @TOPDIR@/doc/api/doxy-api-index.md \ > @TOPDIR@/lib/eal/include \ > @TOPDIR@/lib/eal/include/generic \ > @TOPDIR@/lib/acl \ > + @TOPDIR@/lib/arg_parser \ > @TOPDIR@/lib/bbdev \ > @TOPDIR@/lib/bitratestats \ > @TOPDIR@/lib/bpf \ > diff --git a/lib/arg_parser/arg_parser.c b/lib/arg_parser/arg_parser.c > new file mode 100644 > index 0000000000..45acaf5631 > --- /dev/null > +++ b/lib/arg_parser/arg_parser.c > @@ -0,0 +1,113 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Intel Corporation > + */ > + > +#include "errno.h" > +#include "stdlib.h" > +#include "ctype.h" > +#include "string.h" > +#include "stdbool.h" > + > +#include > +#include > + > + > +struct core_bits { > + uint8_t bits[(UINT16_MAX + 1)/CHAR_BIT]; > + uint16_t max_bit_set; > + uint16_t min_bit_set; > + uint32_t total_bits_set; > +}; > + > +static inline bool > +get_core_bit(struct core_bits *mask, uint16_t idx) > +{ > + return !!(mask->bits[idx/8] & (1 << (idx % 8))); Very minor nit, whitespace around the "/" in idx/8. > +} > + > +static inline void > +set_core_bit(struct core_bits *mask, uint16_t idx) > +{ > + if (get_core_bit(mask, idx) == 0) { The function would be simpler flipping the comparison, since we do nothing if the bit is already set. if (get_core_bit(mask, idx)) return; Thereafter you can unconditionally set the bit, and increment total_bits_set, before branching for total_bits_set == 1, and the min/max comparison in the else leg of that. > + mask->total_bits_set++; > + > + /* If its the first bit, assign min and max that value */ > + if (mask->total_bits_set == 1) { > + mask->min_bit_set = idx; > + mask->max_bit_set = idx; > + } > + } > + > + mask->bits[idx/8] |= 1 << (idx % 8); > + > + if (idx > mask->max_bit_set) > + mask->max_bit_set = idx; > + > + if (idx < mask->min_bit_set) > + mask->min_bit_set = idx; > +} > + > +static inline void > +corebits_to_array(struct core_bits *mask, uint16_t *cores, size_t max_cores) > +{ > + uint32_t count = 0; > + for (uint32_t i = mask->min_bit_set; i <= mask->max_bit_set && count < max_cores; i++) { > + if (get_core_bit(mask, i)) > + cores[count++] = i; > + } > +} > + > + > +int > +rte_parse_corelist(const char *corelist, uint16_t *cores, uint32_t cores_len) > +{ > + int32_t min = -1; > + char *end = NULL; > + > + struct core_bits *mask = malloc(sizeof(struct core_bits)); > + memset(mask, 0, sizeof(struct core_bits)); > + > + min = -1; > + do { > + uint32_t idx; > + int32_t max; > + > + while (isblank(*corelist)) > + corelist++; > + if (!isdigit(*corelist)) > + return -1; a blank line here wouldn't hurt to break up the block. > + errno = 0; > + idx = strtol(corelist, &end, 10); > + if (errno || end == NULL) > + return -1; > + if (idx > UINT16_MAX) > + return -1; Can shorten code by merging these two conditions since both just return -1. > + while (isblank(*end)) > + end++; > + if (*end == '-') > + min = idx; > + > + else if (*end == ',' || *end == '\0') { > + max = idx; > + if (min == -1) > + min = idx; > + > + /* Swap min and max if min is larger than max */ > + if (min > max) > + RTE_SWAP(min, max); > + > + for (; min <= max; min++) > + set_core_bit(mask, min); > + > + min = -1; > + } else > + return -1; > + corelist = end + 1; > + } while (*end != '\0'); > + > + corebits_to_array(mask, cores, cores_len); > + uint32_t total_count = mask->total_bits_set; corebits_to_array() should return total_bits_set, save accessing the structure directly. > + free(mask); > + > + return total_count; > +} > diff --git a/lib/arg_parser/meson.build b/lib/arg_parser/meson.build > new file mode 100644 > index 0000000000..6ee228bd69 > --- /dev/null > +++ b/lib/arg_parser/meson.build > @@ -0,0 +1,7 @@ > +# SPDX-License-Identifier: BSD-3-Clause > +# Copyright(c) 2023 Intel Corporation > + > +sources = files('arg_parser.c') > +headers = files('rte_arg_parser.h') > + > +includes += global_inc > diff --git a/lib/arg_parser/rte_arg_parser.h b/lib/arg_parser/rte_arg_parser.h > new file mode 100644 > index 0000000000..1b12bf451f > --- /dev/null > +++ b/lib/arg_parser/rte_arg_parser.h > @@ -0,0 +1,66 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Intel Corporation > + */ > + > +#ifndef _RTE_ARG_PARSER_H_ > +#define _RTE_ARG_PARSER_H_ > + > +/** > + * @file > + * > + * RTE Argument Parsing API > + * > + * The argument parsing API is a collection of functions to help parse > + * command line arguments. The API takes a string input and will return > + * it to the user in a more usable format. > + * > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > + > +#include > + > + > +/** > + * Convert a string describing a list of core ids into an array of core ids. > + * > + * On success, the passed array is filled with the core ids present in the > + * list up to the "cores_len", and the length of the array is returned. > + * For example, passing a 1-3,6 "corelist" results in an array of [1, 2, 3, 6] > + * and would return 4. > + * > + * Like the snprintf function for strings, if the length of the input array is > + * insufficient to hold the number of cores in the "corelist", the input array is > + * filled to capacity and the return value is the number of elements which would > + * be returned if the array had been big enough. > + * Function can also be called with a NULL array and 0 "cores_len" to find out > + * the "cores_len" required. > + * > + * @param corelist > + * Input string describing a list of core ids. > + * @param cores > + * An array where to store the core ids. > + * Array can be NULL if "cores_len" is 0. > + * @param cores_len > + * The length of the "cores" array. > + * If the size is smaller than that needed to hold all cores from "corelist", > + * only "cores_len" elements will be written to the array. > + * @return > + * n: the number of unique cores present in "corelist". > + * -1 if the string was invalid. > + * NOTE: if n > "cores_len", then only "cores_len" elements in the "cores" array are valid. > + */ > +__rte_experimental > +int > +rte_parse_corelist(const char *corelist, uint16_t *cores, uint32_t cores_len); > + > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* _RTE_ARG_PARSER_H_ */ > diff --git a/lib/arg_parser/version.map b/lib/arg_parser/version.map > new file mode 100644 > index 0000000000..f11699a306 > --- /dev/null > +++ b/lib/arg_parser/version.map > @@ -0,0 +1,10 @@ > +DPDK_24 { > + local: *; > +}; > + > +EXPERIMENTAL { > + global: > + > + # added in 24.03 > + rte_parse_corelist; > +}; > diff --git a/lib/meson.build b/lib/meson.build > index 6c143ce5a6..1b068fc61f 100644 > --- a/lib/meson.build > +++ b/lib/meson.build > @@ -11,6 +11,7 @@ > libraries = [ > 'log', > 'kvargs', # eal depends on kvargs > + 'arg_parser', > 'telemetry', # basic info querying > 'eal', # everything depends on eal > 'ring', The new lib needs to be added to the list for windows builds too. > -- > 2.34.1 >