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 65A434369D; Thu, 7 Dec 2023 17:44:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 039B642F04; Thu, 7 Dec 2023 17:44:15 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mails.dpdk.org (Postfix) with ESMTP id 05A0C42ECC for ; Thu, 7 Dec 2023 17:44:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701967454; x=1733503454; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=4ujafcsB1LpzcBSytLUHouWS72FRdaSnMrJiGu/yGIA=; b=MzbQ/TF240ueVzGvdJ59qvNXZlvHMxG/bKXTT9UbjbhsjXndcwQZu1ns ZgV7M70y/WiDmiVRYUeh/vY+jgJxceGqrSrfzDhljBkPiNh3lc4LqrmIX dS6SaNDAEF6O0V8LIE7NWZ15hzpceDpI9bG/vqYInqHk+CSTeHk2Rt+iC y7duqlCRssS5ndM4P/m/5CHfdiWT4tIuwLyr7LCzg/7U6HRJZCC1uQCEJ 8NqHdbCocgv3eemWXUjx1dMrUSA0GkIt4J6I+AxxOzRJ0hZxlIYxvqB6Z Z6rJgVrtve4EiGbSNu3fPPcTSOlQgG/9xY7Gbue/JZLCrykA7DodQ/+GZ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="1369438" X-IronPort-AV: E=Sophos;i="6.04,258,1695711600"; d="scan'208";a="1369438" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 08:44:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="945089733" X-IronPort-AV: E=Sophos;i="6.04,258,1695711600"; d="scan'208";a="945089733" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga005.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 07 Dec 2023 08:44:11 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Dec 2023 08:44:10 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Dec 2023 08:44:10 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Thu, 7 Dec 2023 08:44:10 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.100) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 7 Dec 2023 08:44:10 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gi6ZZQHs09v8kt7yB7qaibNY/RO02XMCoLeO1AKSRJEILKjCqOVADtEULkR9dENy/LhftFetr3rdVC1ZYHzgZWe1jCH72cINturMjPuDgtVKb7JDN7lHUKJD7jaG50TMMZ/SIvA9y4TtvULBXVCxb35WFoPqFZwwZOo1N/D5IdvUOywy3M71jWlQ/sNxrrNW48lna2hwvM0vdbGZpooRmntZv0uZ3dUq6YkLRXLKcoNLYF2gzWLGZYmoEGMutGSU34QpUT3Kcmgch5954TEOySms9j5Wpbs/MnEz2o8t6VbtCgLGR1+3lp+1qbS+uaUCnVVorhbiywf1RfwKNnyRNg== 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=Vj4WrAdn65NCZNPfhduzbzyKFQ9iUOaCH9jve/tfXac=; b=kkxClUGbJpUZLZ16FQhM1xK/EdV0LUwnUIvUSqHFAMLjhb0jM70o/Clodl/6kS9aESPmQR+KL24PecMpSR8Zlc0ouzdMCI4NkzGFu1xXmgxCDQeTSTUxZQyaG1WDo7+UawRZG50S7QuH8N8a3FoKpQGiwp9OnGxqvRsYQru5oEKK5IO4kxm7iwK4MLLGOAysksroa0xu1viinG/xj2q6tLriKHYxas6YzUV7Jy+82V+MKoa8uNVF0h506o6D8m8+BeSiZ+3cpOHRfUJJo+aRpv/O7jdMU6pfRgImZVt4ipyzsgN3caeNPL9Nz2mNcjUrlwJBTGzX7kLh0MmqVKFRaA== 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 IA1PR11MB6146.namprd11.prod.outlook.com (2603:10b6:208:3ee::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.27; Thu, 7 Dec 2023 16:44:07 +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.7068.027; Thu, 7 Dec 2023 16:44:07 +0000 Date: Thu, 7 Dec 2023 16:44:01 +0000 From: Bruce Richardson To: Euan Bourke CC: , Thomas Monjalon Subject: Re: [PATCH v3 1/8] arg_parser: new library for command line parsing Message-ID: References: <20231207161818.2590661-1-euan.bourke@intel.com> <20231207161818.2590661-2-euan.bourke@intel.com> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231207161818.2590661-2-euan.bourke@intel.com> X-ClientProxiedBy: DU2PR04CA0338.eurprd04.prod.outlook.com (2603:10a6:10:2b4::8) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|IA1PR11MB6146:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d7f59d4-6ca1-4724-3d3d-08dbf743bacb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 55pz+IKH1xEuhlrOzABQFzTSHuXiVjONUaO0hpQroqsxR49HxrwSayOmNcq3yJJFwTm50pxY0Ke2dd8UsyQWckEs2jaryIH5Er4slBa75wU/9JEyHr/bgjU68t0SOhEd7cEbTHc1CithUL+uIYpdpSzmWQ025HtmtsHYHF0Zs/qv6Yq+M+bOeqSDvQm/g8dySG3jAwFs9NYlTokmhuXqkk0ydSi4Q7QBLd5Isk2at00fwTrorIcNsnbsIa0lscEwz80edWlN36RfRw2kV8KGF8IYQMCWDmPV0wlh9/ohl/HHJTMFqWaZPxyk25aRmqi8qGgOZUypuvnAOjhRiC1S68B4dCmTEgtf2NZk5ni0k4Fvc5TOEMIMi+gJ1KsnhS8CnwbHKZ8mYKxNM2vr64N7qiEbhw56IOnigniSCDnnZcnw0UEwcYI6myDnP92vlOUnPFyXhfEd/SnlLI8EVZOmZQ5UvX+wNOM5hlYt5cKQMHp24G7waY6cfJz5ob7ZqcufcNCNk70EefXHDzoP2+UumCVdwh7KACHszCoBN0Z7Sy0= 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)(396003)(136003)(346002)(376002)(366004)(39860400002)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(83380400001)(6666004)(6486002)(966005)(478600001)(4326008)(8676002)(6862004)(8936002)(316002)(6636002)(66556008)(66946007)(66476007)(6506007)(82960400001)(6512007)(38100700002)(26005)(66574015)(30864003)(2906002)(5660300002)(41300700001)(44832011)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?gempR5WeucJeWBxk/0OUYQ36J3+8KBH7IanQzEWOlLBh8zcoKJXVhYji4D?= =?iso-8859-1?Q?G/44pFAyE5/9ThY1SRtVLuExb9jJu33canu0bGEgmlzhxRktk4cIHAeMJQ?= =?iso-8859-1?Q?EeopvsXtVxshVa1K7ajyPyzCM33WXoAYXLUaj3jG6YPwlgR2JuZfEtNGfZ?= =?iso-8859-1?Q?quXKTLDnh+c9pZwJfjkHNEw7VxHGKykmfWOKjKFA18BPXUQ8rVnMnaK/Oh?= =?iso-8859-1?Q?F9NU/V0k5yUZsr/ZYpBlJv7Q6daTcuWRyHIT4eLx3anh3OKUN1w4nWen8V?= =?iso-8859-1?Q?uu7LdmVe1MGMm9zo4s8SauRmpQSP0z/n4Am/wyPGCXsEMOQnV1yeZ+S3bX?= =?iso-8859-1?Q?2NtlQNEbZuUvmdI5eDNVff03qwOcpNlaMX5TMPfgYrWcMDTHnmHfj6cdBw?= =?iso-8859-1?Q?qcz7Sq7kdZIGIndng9qLOW2SEP0H01FpRJCdepS2Dfktr8T6bbkilFiG31?= =?iso-8859-1?Q?xfNbCFdk+OxgeajySPNlxIPCWNgw1LEZusWDV7XGdDfOBENdJJBar7Rhj3?= =?iso-8859-1?Q?heZtxGX/b0TyHbpikbFqjjzwfWDyyNx7DE9siYPCWh2NS4lRmLGqslPMaL?= =?iso-8859-1?Q?cp7j0UZ63s5rSzOXZp0O+odru3sEjlW92pTL1vDB3pW1zmhuL5x0fEyxnE?= =?iso-8859-1?Q?8OW+xpnrDiyTsrnrbySlIQMHiTH7+4KRNEYGjO7d+jUoqZxkAgCOLvNyoB?= =?iso-8859-1?Q?TWa70fXr0aU/QqLycPCUD9cs65wwxRT4gc3GzHyg2LhiDs6/RnsxsOhs9J?= =?iso-8859-1?Q?5A7St9bOWhhbjuL/xjJAY/06izEgfUmjukqOADnLLE+LO9/90LMpPPz5yy?= =?iso-8859-1?Q?785/F8EHBQjNc7MdmfW0/KyVXSlw6vc13WeYR17EGIHcTpvwb5rea+r3zV?= =?iso-8859-1?Q?IsUqlfDhMsGDR7IfXvFReDygkEm5PWFPJIU+kMBvctOWmIdXAPF7zoW6/t?= =?iso-8859-1?Q?J46BneBV3jNKRUh0WHOOQKB+RAKfaB8JlH/9rPa7NkNRy1dfdZRdyhuUJB?= =?iso-8859-1?Q?jVmITVO+5lmnSA+dh49cbd6v+t2MsA4xBb/j6IAcXhiXwz/PCQdIfcg/aj?= =?iso-8859-1?Q?ENNbqO00Pvlhk8JltplEXh1Zj6dpxWNBh4USOR2Pl0kBxviwa6SxGgB/5+?= =?iso-8859-1?Q?sfOwjYeKWWPn6vZXNHjaurB7hWc+vgsWv4Gkb92xfejLHiFRdKZCQJfujw?= =?iso-8859-1?Q?L9s5mHCcaRtZes6Z0OqOPVm7VWzHRda5cGo3g2QtOE5Fd40hUi6pvcv8on?= =?iso-8859-1?Q?ocieH9pDd1IPt4El0i+fGA98TeyUQqO0FDW1I3oiAcXb8yRjj3R/VkrNGZ?= =?iso-8859-1?Q?fZr+J1id/DyXQ+YGGGcHwAcJKu7WX+7065fmJAV3VeF4Zie/kADdIxBfJv?= =?iso-8859-1?Q?s34SmjnPjWYwxqV/HPjBw8KPY/sa95hB8Ne9IHZRo8MfOG9L1JblyTJwhh?= =?iso-8859-1?Q?3IX0Pp+h3iC+vEtdLmYRjLOSYqnIlgLLN0enDXIGBfDiNlsDPgFXTfJpyM?= =?iso-8859-1?Q?FMWft6UKOH2QUM+vOs+nnGiMzINcGH+6JTIv9O+3CQVvNmfWn+6Lfeyg4M?= =?iso-8859-1?Q?X6XhfxWma69ywDrTkyp/YnBPaDe8Wsxw2gycidC5kD9w8Dz6AxrU9BA2JC?= =?iso-8859-1?Q?NOO2pq9RnTmYUuYQc0K/fSo6YqQrUpl/8ymWZNOms0YYQC0MlNEKLimg?= =?iso-8859-1?Q?=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5d7f59d4-6ca1-4724-3d3d-08dbf743bacb X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2023 16:44:07.3839 (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: vUxpSCpV4j15UjzBLLwtiyaPJcy2N7Zb3/wSLzduelapPKPmDq+zzYphGGb5FgSvdDBXPRmZmYbI+rNJgzwu3cohpBZsL6nwq1CqEI/X93w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR11MB6146 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 Thu, Dec 07, 2023 at 04:18:11PM +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 There are other patches outstanding on the list for argument parsing too [1], and we need to reconcile what goes into what libraries with what names! Probably they can all be merged into one, but we need to check. [1] http://patches.dpdk.org/project/dpdk/list/?series=30439 Some minor comments inline below for any v4. > --- > .mailmap | 1 + > MAINTAINERS | 4 ++ > doc/api/doxy-api-index.md | 3 +- > doc/api/doxy-api.conf.in | 1 + > lib/arg_parser/arg_parser.c | 108 ++++++++++++++++++++++++++++++++ > lib/arg_parser/meson.build | 7 +++ > lib/arg_parser/rte_arg_parser.h | 66 +++++++++++++++++++ > lib/arg_parser/version.map | 10 +++ > lib/meson.build | 2 + > 9 files changed, 201 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 ab0742a382..528bc68a30 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 0d1c8126e3..68ef5ba14b 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -1756,6 +1756,10 @@ M: Nithin Dabilpuram > M: Pavan Nikhilesh > F: lib/node/ > > +Argument parsing > +M: Bruce Richardson > +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) Not sure what order, if any, these elements are in, but I think argument parsing could well be further up the list. It also reduces the diff by one line, since you don't need to append the comma on the end of rte_thread line. > > - **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..240f63d8e1 > --- /dev/null > +++ b/lib/arg_parser/arg_parser.c > @@ -0,0 +1,108 @@ > +/* 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 / CHAR_BIT] & (1 << (idx % CHAR_BIT))); > +} > + > +static inline void > +set_core_bit(struct core_bits *mask, uint16_t idx) > +{ > + if (get_core_bit(mask, idx)) > + return; > + > + mask->bits[idx / CHAR_BIT] |= 1 << (idx % CHAR_BIT); > + /* Update min and max bit if its first time setting a bit */ > + if (++(mask->total_bits_set) == 1) { > + mask->min_bit_set = idx; > + mask->max_bit_set = idx; > + return; > + } > + > + if (idx > mask->max_bit_set) > + mask->max_bit_set = idx; > + > + if (idx < mask->min_bit_set) > + mask->min_bit_set = idx; > +} > + > +static inline uint32_t > +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; > + } > + return mask->total_bits_set; > +} > + > + > +int > +rte_arg_parse_corelist(const char *corelist, uint16_t *cores, uint32_t cores_len) > +{ > + struct core_bits mask = {0}; > + int32_t min = -1; > + char *end = NULL; > + > + min = -1; > + do { > + int64_t idx; > + int32_t max; > + > + while (isblank(*corelist)) > + corelist++; > + if (!isdigit(*corelist)) > + return -1; > + > + errno = 0; > + idx = strtol(corelist, &end, 10); > + if (errno || end == NULL || idx > UINT16_MAX) > + return -1; > + while (isblank(*end)) > + end++; > + if (*end == '-') > + min = idx; > + > + else if (*end == ',' || *end == '\0') { > + if (min == -1) > + min = max = idx; > + else if (min > idx) { > + max = min; > + min = idx; > + } else > + max = idx; > + This set of if-else branches could do with a few comments. The first case, min == -1, is for when we get a bare number without a range, right? The second is when the range is reversed, e.g. 6-3, rather than 3-6, and the last is for normal ranges. A one-line comment in each leg of the condition would make this clearer for anyone editing it in future. > + for (; min <= max; min++) > + set_core_bit(&mask, min); > + > + min = -1; > + } else > + return -1; > + corelist = end + 1; > + } while (*end != '\0'); > + > + uint32_t total_count = corebits_to_array(&mask, cores, cores_len); > + > + return total_count; Since you no longer have the bitmask on the heap, total_count is unnecessary since there is no "free" call. You can just do "return corebits_to_array(...)" > +} > 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..80579f8cf3 > --- /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 number of unique cores present in the "corelist" > + * is returned. > + * For example, passing a 1-3,6 "corelist" results in an array of [1, 2, 3, 6] > + * and would return 4. > + * > + * NOTE: if the length of the input array is insufficient to hold the number of core ids > + * in "corelist" the input array is filled to capacity but the return value is the > + * number of elements which would have been written to the array, had enough space been > + * available. [This is similar to the behaviour of the snprintf function]. Because of > + * this, the number of core values in the "corelist" may be determined by calling the > + * function with a NULL array pointer and array length given as 0. > + * > + * @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_arg_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..b0caaac569 > --- /dev/null > +++ b/lib/arg_parser/version.map > @@ -0,0 +1,10 @@ > +DPDK_24 { > + local: *; > +}; > + > +EXPERIMENTAL { > + global: > + > + # added in 24.03 > + rte_arg_parse_corelist; > +}; > diff --git a/lib/meson.build b/lib/meson.build > index 6c143ce5a6..db9e769033 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', > @@ -72,6 +73,7 @@ if is_ms_compiler > 'log', > 'kvargs', > 'telemetry', > + 'arg_parser', > ] > endif > > -- > 2.34.1 >