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 C4A884369D; Thu, 7 Dec 2023 17:58:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6B8A242F04; Thu, 7 Dec 2023 17:58:23 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 18A9F42ECC for ; Thu, 7 Dec 2023 17:58:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701968302; x=1733504302; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=C4tC5H/Te1XRmF1TiCdARpQkK8uYw/bB8Y3UbkfpI9k=; b=ZEzLovMVeUGEgrBT+PgEv88j+JuuWaxnOjw6vV55lRtq+cEzlerVrr86 ETQQbF/Ms1hd+VqNpDi/uNRbVuoW076FNh55HJowzBcMqtkXFCMbjt+5R CBQLmEASf2IPYjuPRmTpKAB6CVYNV5xIvvkpleynjt6mZLfCNHhgpxWTj B2uc7oVEhtcKy/NipNaP8w8dcVefNRjcUM+p0sth9mzN8WgzTtfFP6JNe LJmrgaUQz5dyT/JmQnFg2uY7D6U6n3kn03sf9hNuv0/FojwGHQyd28PiD OkDso4EUSy4U4t5xZu8uW3v7YMRnGjVZuE3S6tM0p4tuk42cac4ka3Gnp g==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="391436331" X-IronPort-AV: E=Sophos;i="6.04,258,1695711600"; d="scan'208";a="391436331" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 08:58:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="800788477" X-IronPort-AV: E=Sophos;i="6.04,258,1695711600"; d="scan'208";a="800788477" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga008.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 07 Dec 2023 08:58:20 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) 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:58:20 -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:58:19 -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:58:19 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) 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:58:19 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S+j+TO6IEIq6WGSfzGIVAEX1mjkDhOcWzS4YBN4IZgeia7vAYcO0G9WmFBfBgbNv8rMerOY2cA/ylUPiyUY17wVTQJWB9ge0YDAzU1bBuKbB9Ni5F/TWMK0UH44ta0fS6kV0T1AsiYBBK+UQqeGXJyg/W3ymYNCVBDCC14a3olJv1qoxA+zY38WmyuA4Ijp/exs5qIuLgdyXBZbdDbCJfxqJUVztsSmXpZSDJi8mPKKCgh1tCVbkeWX8/yguaz0IN+dOX0Cp+efjMRAeF0UcwfnkpodLHL7yPlorv4X57+c1BgWS7nbzM4KS7Iiv9W8lemtYgLF/ThmUa5BicxviPQ== 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=OihKD7mXHSfhidN25qj/raVV7HWDuY8AO/l/xQndosc=; b=O8RVL9zvAi0L6qvrfxPnEXT1PDfzp3mhnK0sdVyNZczpnSfDkyO+MiM2LFzx3FQ966qzYDh+82cirPfOgt2Mc4gohSYWFMn5/yqwn+UNHr7Fr/TbMNh6UnuDUZl+8a+pi9zgPvRW9yu48jVcuWQJhoS/I4qIGCGwonzyqZlVnehQls/V/2lQrlhtK9SiYcpb8R2KQff46gVw/WK6KFnkrOpscUBpd46Ugp2crtZHwxBIaMhMY+iE+qyZs8a22fpW5p3TpgEUsi/zcL5ABm6uDqJd4FDEPbkyBDzBXxyQvn9EaTg24BHbstNaNmtIWn5opcaIiMhm5/Yi5TS+qNgn0A== 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 LV8PR11MB8679.namprd11.prod.outlook.com (2603:10b6:408:1f9::5) 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:58:17 +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:58:17 +0000 Date: Thu, 7 Dec 2023 16:58:12 +0000 From: Bruce Richardson To: Euan Bourke CC: Subject: Re: [PATCH v3 6/8] arg_parser: added common core string and heuristic parsers Message-ID: References: <20231207161818.2590661-1-euan.bourke@intel.com> <20231207161818.2590661-7-euan.bourke@intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20231207161818.2590661-7-euan.bourke@intel.com> X-ClientProxiedBy: DU6P191CA0026.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:53f::17) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|LV8PR11MB8679:EE_ X-MS-Office365-Filtering-Correlation-Id: 035f2fd6-722f-4643-c694-08dbf745b55f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZjiQgABH6Co4aNbAm0ih8dMDfrWaSk86je4CPT+LqY5eZVksY6vTMVGFjAdNsNG/zJz5vKjr/OR1Ngh7UXSEFNq6arS0TNLmdCpc7MK+e3k3t6TkBpC/AoehatYpxbGM9NocQQr/qlIYKOTWgzI0tOnVppn2tsIl3Y1vNUbiee4jaiO4RBFfBt6o2QZIx9t1uWbLWZMN9iN1wd6E0qnWgRI6I9TOMNMtFn4GfUMjTUuDlHlBWMD3jRCuOyQcutVSfwpUyl/SOQ+1nI1nmMy/EcqkM2LtBCgG20dp8f2Dmg2pHNAl13IGWez0SAIQDaPYE4BuuZjTqOnjtqjJA9DP7oTCsCmcfmnEgWRM4TLcL2LjaLiGzxzBGJBP1isTCAgiH+eRWxH+fIcPOLMN9ojLiQUqwQDcqIG/dqCHl0xwPR+ZOhZYeInr8u29YothkymHIgw4Lh3/kSUSML5d5DkQytb+R5iHmED70Ugx4vdxIBpvUS9HuLKxnvv+DBm0QqUKB9xik/xaDMXw5OjPnBDN8ijJUI5mAPBjZnNgBQ+gv9LqptiaABLYku935sgLnpTF 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)(376002)(136003)(366004)(39860400002)(396003)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(2906002)(44832011)(8936002)(8676002)(4326008)(6862004)(5660300002)(316002)(66556008)(66476007)(66946007)(6486002)(6512007)(6636002)(6506007)(26005)(41300700001)(6666004)(478600001)(38100700002)(82960400001)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?7Fle6XRTaq7vaLKgo46FbANfecX4cUBGRir236oFr1AElRZ4lNn8akLRDRHn?= =?us-ascii?Q?43HkO6ZyMuqXWI4t0Z+0yLv6KJJGO6iM2fwCyB78NmW/gGyYuL0I3zNQXLs4?= =?us-ascii?Q?XKgBSjG2DAgC9/5LUR6qsPzKwqaqdEr4cJboRZW06Ib4B1W2RcerhRrdue8S?= =?us-ascii?Q?M1ejvOI16wSUtXN/DOjIRhUBbkv/tELXnLK84FkElDMq1+A96v5uBBrDMIvz?= =?us-ascii?Q?ugdpihME3bu0RAWDJ1vB1ZbpqS+3WEeo+qXIhxvoflUNzK+jKW9YYfsRQ/cW?= =?us-ascii?Q?uD6QufG/233gj6Dv0zWZfZdTmi/qRFNq/TRXKADiN4uFZxbNmf+R3HENpaeb?= =?us-ascii?Q?QYOpfd9vMonB6OpelQlvo1Hchc/djK9ZTe1qNTLX7jkgiwz5vf3/gafJbcUx?= =?us-ascii?Q?xhr1JZVv1Hku3LKrxmFau6Ge2Q2v9cACAIl4kgNRfSAtSYHK0dG8Oat7+Bv6?= =?us-ascii?Q?CtgpXiAohFdQ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+s8UCbCAnTaafqBc7?= =?us-ascii?Q?cS+I0S6EpHkA/+MuW1LiURAkRD3SB0Mz3TJo7yjjM9s3NdyY6BHC9B6W1fXS?= =?us-ascii?Q?7QJ5cyJkuIWhCdF+DFrKGiaip+RWH5u7sGsvsART1+4siCeOrvnDroB18Vu/?= =?us-ascii?Q?HrY2Qowlz2iFVn4OVb0XIWlkDdpM1SCXaqDM0dZaMhLuRwJ+/19wJK8wh84t?= =?us-ascii?Q?uMnkh+9t7HnuH+qWK3Z81BpIz204Z2eluo31G2G92TUJ3JYp6IDO+frAnV0Y?= =?us-ascii?Q?6Q=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 035f2fd6-722f-4643-c694-08dbf745b55f 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:58:17.6125 (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: loEskuAyqb4mktp0YfDRuahvt/qg8ItC46DH/iF5ilnodSAfz1obhb6DM2jmYF1vXd/1ZkJYiK7SHVIZM3jpsxsIanJkbTzwCFB+UznNw24= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR11MB8679 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:16PM +0000, Euan Bourke wrote: > Two new functions, the first is a 'heuristic parser' which examines a > string describing a set of cores and determines based off heuristics > whether its a coremask or a corelist. > > Second is a 'combined parser' which calls the first function and then > based off the returned value will call the relevant core string parser. > This function also takes a 'default_type' int which corresponds to > which parser should be used in the case of an ambiguous string. > > Signed-off-by: Euan Bourke > --- > lib/arg_parser/arg_parser.c | 68 +++++++++++++++++++++++++++++++++ > lib/arg_parser/rte_arg_parser.h | 60 +++++++++++++++++++++++++++++ > lib/arg_parser/version.map | 2 + > 3 files changed, 130 insertions(+) > > diff --git a/lib/arg_parser/arg_parser.c b/lib/arg_parser/arg_parser.c > index cebab9e2f8..95cbc50c13 100644 > --- a/lib/arg_parser/arg_parser.c > +++ b/lib/arg_parser/arg_parser.c > @@ -7,10 +7,15 @@ > #include "ctype.h" > #include "string.h" > #include "stdbool.h" > +#include "stdio.h" > > #include > #include > > +#define RTE_ARG_PARSE_TYPE_COREMASK 0 > +#define RTE_ARG_PARSE_TYPE_CORELIST 1 > +#define RTE_ARG_PARSE_TYPE_UNKNOWN 2 > + As these are used as return values, they need to be defined in the header file so that applications can use them. > #define BITS_PER_HEX 4 > #define MAX_COREMASK_SIZE ((UINT16_MAX + 1) / BITS_PER_HEX) > > @@ -22,6 +27,7 @@ struct core_bits { > uint32_t total_bits_set; > }; > > + Stray newline added to patch. > static inline bool > get_core_bit(struct core_bits *mask, uint16_t idx) > { > @@ -159,3 +165,65 @@ rte_arg_parse_coremask(const char *coremask, uint16_t *cores, uint32_t cores_len > > return total_count; > } > + > +int > +rte_arg_parse_arg_type(const char *core_string) > +{ > + /* Remove leading whitespace */ > + while (isblank(*core_string)) > + core_string++; > + > + /* Check for 0x prefix */ > + if (core_string[0] == '0' && tolower(core_string[1]) == 'x') { > + if (core_string[2] != '\0') > + return RTE_ARG_PARSE_TYPE_COREMASK; > + return -1; > + } > + > + int i = 0, idx = 0; > + /* Check for ',' and '-' and check for A-F */ > + do { > + while (isblank(core_string[idx])) > + idx++; > + > + if (core_string[idx] == ',' || core_string[idx] == '-') > + return RTE_ARG_PARSE_TYPE_CORELIST; > + > + if (isalpha(core_string[idx])) { > + if (isxdigit(core_string[idx])) > + return RTE_ARG_PARSE_TYPE_COREMASK; > + return -1; > + } > + idx++; > + i++; > + } while (core_string[idx] != '\0'); > + > + /* Check length of core_string if ambiguous as max length of a uint16_t is 5 digits > + * implying its a coremask. > + */ > + if (i > 5) > + return RTE_ARG_PARSE_TYPE_COREMASK; > + > + return -1; Rather than returning -1, I think in most/all cases above, the function should return -EINVAL as error code, since it's invalid input passed. > +} > + > +int > +rte_arg_parse_core_string(const char *core_string, uint16_t *cores, uint32_t cores_len, > + int default_type) > +{ > + if (default_type != RTE_ARG_PARSE_TYPE_COREMASK && > + default_type != RTE_ARG_PARSE_TYPE_CORELIST) { > + return -1; > + } > + switch (rte_arg_parse_arg_type(core_string)) { > + case RTE_ARG_PARSE_TYPE_COREMASK: > + return rte_arg_parse_coremask(core_string, cores, cores_len); > + case RTE_ARG_PARSE_TYPE_CORELIST: > + return rte_arg_parse_corelist(core_string, cores, cores_len); > + default: > + return default_type == RTE_ARG_PARSE_TYPE_COREMASK ? > + rte_arg_parse_coremask(core_string, cores, cores_len) : > + rte_arg_parse_corelist(core_string, cores, cores_len); > + return -1; > + } > +} > diff --git a/lib/arg_parser/rte_arg_parser.h b/lib/arg_parser/rte_arg_parser.h > index 359d40e305..125ca9524c 100644 > --- a/lib/arg_parser/rte_arg_parser.h > +++ b/lib/arg_parser/rte_arg_parser.h > @@ -92,6 +92,66 @@ __rte_experimental > int > rte_arg_parse_coremask(const char *coremask, uint16_t *cores, uint32_t cores_len); > > +/** > + * Use heuristics to determine if a string contains a coremask or a corelist. > + * > + * This function will check a series of conditions and return an int representing which > + * core type (mask or list) the string represents or UNKNOWN if the string is ambiguous. "or report the type as unknown if it is ambiguous" > + * > + * @param core_string > + * A string describing the intended cores to be parsed > + * @return > + * int representing the core type > + * -1: error. Suggest "negative error code on error". We should also list out the error codes at the end, though I think right now -EINVAL is the only one we need. > + * 0: coremask. > + * 1: corelist. > + * 2: unknown (ambiguous). Move the #defines from the C file to the header, and use them here rather than magic numbers. > + */ > +__rte_experimental > +int > +rte_arg_parse_arg_type(const char *core_string); > + > +/** > + * Convert a string describing either a corelist or coremask into an array of core ids. > + * > + * This function will fill the "cores" array up to "cores_len" with the core ids described > + * in the "core_string". The string can either describe a corelist or a coremask, and > + * will be parsed accordingly. The number of unique core ids in the string is then returned. > + * For example: > + * "1-4" is treated as a corelist and results in an array of [1,2,3,4] with 4 being returned > + * "0xA1" is treated as a coremask and results in an array of [0,5,7] with 3 being returned > + * > + * In the case of an ambiguous string, the function will use the default_type parameter to > + * decide. > + * > + * NOTE: if the length of the input array is insufficient to hold the number of core ids > + * in "core_string" 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 "core_string" may be determined by calling the > + * function with a NULL array pointer and array length given as 0. > + * > + * @param core_string > + * A string describing the intended cores to be parsed. > + * @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 "core_string" > + * @param default_type > + * How to treat ambiguous cases (e.g. '4' could be mask or list). > + * 0: mask. > + * 1: list. Again, use the defines. > + * @return > + * n: the number of unique cores present in "core_string". > + * -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_core_string(const char *core_string, uint16_t *cores, uint32_t cores_len, > + int default_type); > > #ifdef __cplusplus > } > diff --git a/lib/arg_parser/version.map b/lib/arg_parser/version.map > index b44d4b02b7..383b6bd0e9 100644 > --- a/lib/arg_parser/version.map > +++ b/lib/arg_parser/version.map > @@ -8,4 +8,6 @@ EXPERIMENTAL { > # added in 24.03 > rte_arg_parse_corelist; > rte_arg_parse_coremask; > + rte_arg_parse_arg_type; > + rte_arg_parse_core_string; The version.map lists are kept alphabetical, so the new entries need to be moved up. > }; > -- > 2.34.1 >