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 15E53433AC; Thu, 23 Nov 2023 16:56:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E936A42FAD; Thu, 23 Nov 2023 16:56:08 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id BB8E942DDD for ; Thu, 23 Nov 2023 16:56:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700754967; x=1732290967; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=uQvxLxi8ig7YFGR5NHKVuj4/NjDAPHwKiZy9GduBtTk=; b=XzUs3YpIJDPTdstSduuQzJyMOry6mdd+rGPTzpLRJMKYjMFgFWSJSNdB WL4WGY4x6jVhHZZb+2WxT0fJAMB63mPYpiPNvuk8owQz/gNDOgIF7niNU jnRYgO5qmfCA9LK4oahRqFNc3aaUlZxebNVuCp5HMWygN8Q4Met0cDHwE 8qv5ZH0B53CuO0KhIgtHiOxTRTBMjJoEc9JEetsv9ucNZ+sh/Mkc902AZ 29o630rY0gPpxm3zxwbxGhEUZVBBcK1exvEfeBpfuPwf8jID9/tuFRaqE d5cqgjKRSveR9BQPa/n6zbjd1qSinC4AodtbxIbbARmoSBBX+x5s5wyal Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="372445918" X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="372445918" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 07:56:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="760698870" X-IronPort-AV: E=Sophos;i="6.04,222,1695711600"; d="scan'208";a="760698870" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 23 Nov 2023 07:56:00 -0800 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) 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.34; Thu, 23 Nov 2023 07:56:00 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) 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.34 via Frontend Transport; Thu, 23 Nov 2023 07:56:00 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (134.134.137.100) 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:55:59 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dHR6vdfwJu33CrUcY1Pm125kaGeRcPZLfIfinkq2m7BYqYylQq/2c0s8MUliqulc4XDZt8fAuIbT9aQXKjZ7ekj6RYknvMjM+lTbdrk6I3nsGe1qQhsuWhHI1UfaFyGZbTzDiIqNpX/OPg31prJLZXLUm4NZUAzQxHyR4xfMcS6CabzGurdXOdGsi8T5vfIZW24lCsyypFmESW0GjsY92jFTzMVLoFEhneXfXJ8YAx8Y2nhXLF40LFXF+1nfncoka952xV8N6RYmf/fNHLFmWPxRU88xqlr+TbuhTh/3+enTCxWGPcZuIsRubBo0Fn40yOaTLQPHr34gO7y67RH6ag== 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=yFoyl/JtAA1eRqCq5ySRcTjtRJnSwFxZckWeS2pdvd4=; b=Bq1z24o4MSywAkNG/wtFUTO1M2gTZ9mBX7y39skJ6nTduhNKHX+TqSCOCECdUfwgvjHf9HpW2Z3r1u9v5sShP5vpfpvVIsKsS0H8gb3mQ2O1lbxAQTUCxX2jP2xgcQUZD+KGhN2SvTApRg9o502+gobFMoJAUzqTFgKqOx6uKYGKHTXwVE7CGnjjgyW4VWasolsTngiTMhUa8rE1c3emAiC+1cYhdmnsG3eNLHwwePDTwgnaYLxmUHpeWWO2gW2wAKVBVDLDTqpxoSRccemty5bdMV226NKqKRQzWD2zgnI0O445snO6CpY2I8kWlKqFM/OQITPJ+Z7exvhG8d6o0Q== 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 MN6PR11MB8220.namprd11.prod.outlook.com (2603:10b6:208:478::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.20; Thu, 23 Nov 2023 15:55:58 +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:55:58 +0000 Date: Thu, 23 Nov 2023 15:55:53 +0000 From: Bruce Richardson To: Euan Bourke CC: Subject: Re: [PATCH 24.03 2/4] arg_parser: add new coremask parsing API Message-ID: References: <20231122164550.3873633-1-euan.bourke@intel.com> <20231122164550.3873633-3-euan.bourke@intel.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20231122164550.3873633-3-euan.bourke@intel.com> X-ClientProxiedBy: DUZPR01CA0124.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bc::7) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|MN6PR11MB8220:EE_ X-MS-Office365-Filtering-Correlation-Id: a4edcfff-735d-4e5f-d80c-08dbec3caec3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hz81VPXPBfh06+W90xgmRa6CIqUcxx2vuj6I79PDMDErfP94UqxfDAnj09FTNY8m+C/R4BkQEyTlscZkg7Gz8fo0yG7Vmfa6OWPjngEgkzdhLpDW1s7+0zrRtcafdvUR9/0nqzIzHWRZihcBuAcNM4Hgqqf2dZH6c5yoUmcBCyNy8Mw7oizLUfCaWx06iTgc4667YxkikBLpm/qOyDPqIquiDRiDTL7K0GymYsL0Wic1Ga+/yWYvJt5KS8tJ0xyfKL8q1c+pRRoWqkyW8bkFJq7dXjz1aGtU3w5m3uLg1MX63C1KN/lLpFimugTXFbXkE/YpYaVaV+cKfwzy9VNCGwgCIWoO5gavAqx6Xdg65esiGhj0OEGstOSaYG4bKa2HhaufJTv3S+GxEUUUoxSfIWrOJuHC8vyh4GIrKbxK1fLcGcAoiUESciN1eCk9+IvzV/pkFdjum3HVkcKBsx6ItOKFhVlyXVc+HAdErCvHa7disDE2BAIus0wsQh/4icC+St3cZpCSk8YMZT+kX5oOXM/q54RNp6rlaKZzmW/DsUXuZmag3pAEdRtgtwVt4a+E 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)(366004)(346002)(39860400002)(396003)(136003)(376002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(86362001)(83380400001)(38100700002)(82960400001)(316002)(66946007)(66476007)(66556008)(4326008)(8676002)(8936002)(6486002)(2906002)(41300700001)(5660300002)(44832011)(6862004)(6512007)(6636002)(26005)(6666004)(478600001)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4Bna6liCfquzmv+OS+nV/Sb7m35fvM/LpQrASp/1+GRLA3Pu52KEvWO2JoRi?= =?us-ascii?Q?nIw9mDy+mb0UnvPj5nFA17CAX5H9uAa5f0XKJtpF8t47pAZhXzJR7Ity5WV6?= =?us-ascii?Q?oHiYYUSgoROitjEd88SAVBqy9YcOqUzbIScGIFnOhOaZBVkqFIac5zHuDZ+3?= =?us-ascii?Q?VUfkDi8U58/TGcWHoHkq1lcv0/QhK4dpbIVTa/IPUMav2wDCaWadvALeLgWI?= =?us-ascii?Q?LL2rdqdDROtmidDlezk1I1/V81PGPukbTilfPCjSzFo4Ht7qTh2f51SN/vEs?= =?us-ascii?Q?RKi5y+xhXLq4ok+0YjbvmpmKwwD3bk7cBxqudh7k42R2dt4/7SL1c25zH3lR?= =?us-ascii?Q?wLOoGm2vTGP2FXuCkwWSg/lo2P2vyfPzCBcMZ3nZjyp/8CxHvCqGNtxlWYe1?= =?us-ascii?Q?PJ4jXYpvJD8Z3ckVZswormQ5NJauv02oq+QZvNzE6wTZb+idPXLu+fYmHd9t?= =?us-ascii?Q?NVIs9ay1qrMujCVsCZcNs/NJLdcAs2dEgqFCi/Ac5LFFhmOC3Z82PXu6C5q4?= =?us-ascii?Q?sB0TjCLbybIefjBVfAWRgWKxroZaAXN3lX5OWidAKSiSqPvpPqTKQ6EmP6Ua?= =?us-ascii?Q?dUqsItttwL8jMChNrMUaqO/2Svb+iizegw8Kd8Odi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RBu7gVkyJ2edQRP6aILdL0PRaSEjFRWi/47wZyJVd5Q?= =?us-ascii?Q?3Atg3xm7e6knd8Lqgv3z6TJMlCSbUrs/1PMgBRId1Ed2LG0somJiCSDL5NG0?= =?us-ascii?Q?ag=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: a4edcfff-735d-4e5f-d80c-08dbec3caec3 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:55:57.9514 (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: lvejSih2FEhIJgwp+t0eKJKI4QqwB54EkuA/dh+yyJAHtCF8tZvF8iONkwvEWocMsW7Cj6u5EExlS7wqmo5a1Hy/B1QwYtYw20W4yJjsvHw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR11MB8220 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:48PM +0000, Euan Bourke wrote: > Add new coremask parsing API. This API behaves similarly to the corelist parsing > API, parsing the coremask string, filling its values into the cores array. > General tip - commit log messages are generally wrapped at 72 characters. > The API also returns a 'count' which corresponds to the total number of cores > in the coremask string. > > Signed-off-by: Euan Bourke Again, some review comments inline below. /Bruce > --- > lib/arg_parser/arg_parser.c | 58 +++++++++++++++++++++++++++++++++ > lib/arg_parser/rte_arg_parser.h | 33 +++++++++++++++++++ > lib/arg_parser/version.map | 1 + > 3 files changed, 92 insertions(+) > > diff --git a/lib/arg_parser/arg_parser.c b/lib/arg_parser/arg_parser.c > index 45acaf5631..58be94b67d 100644 > --- a/lib/arg_parser/arg_parser.c > +++ b/lib/arg_parser/arg_parser.c > @@ -11,6 +11,9 @@ > #include > #include > > +#define BITS_PER_HEX 4 > +#define MAX_COREMASK_SIZE ((UINT16_MAX+1)/BITS_PER_HEX) > + Whitespace around "/" operator here, and below in bits definition (which I missed on review of first patch). > > struct core_bits { > uint8_t bits[(UINT16_MAX + 1)/CHAR_BIT]; > @@ -57,6 +60,15 @@ corebits_to_array(struct core_bits *mask, uint16_t *cores, size_t max_cores) > } > } > > +static int xdigit2val(unsigned char c) > +{ > + if (isdigit(c)) > + return c - '0'; > + else if (isupper(c)) > + return c - 'A' + 10; > + else > + return c - 'a' + 10; > +} > > int > rte_parse_corelist(const char *corelist, uint16_t *cores, uint32_t cores_len) > @@ -111,3 +123,49 @@ rte_parse_corelist(const char *corelist, uint16_t *cores, uint32_t cores_len) > > return total_count; > } > + > +int > +rte_parse_coremask(const char *coremask, uint16_t *cores, uint32_t cores_len) > +{ > + struct core_bits *mask = malloc(sizeof(struct core_bits)); Check return value from malloc. Need to do so in patch 1 also. > + memset(mask, 0, sizeof(struct core_bits)); > + > + /* Remove all blank characters ahead and after . > + * Remove 0x/0X if exists. > + */ > + while (isblank(*coremask)) > + coremask++; > + if (coremask[0] == '0' && ((coremask[1] == 'x') > + || (coremask[1] == 'X'))) Nit: this can all fit on one line, as it's <100 chars long. > + coremask += 2; > + > + int32_t i = strlen(coremask); > + while ((i > 0) && isblank(coremask[i - 1])) > + i--; > + if (i == 0 || i > MAX_COREMASK_SIZE) > + return -1; > + > + uint32_t idx = 0; > + uint8_t j; > + int val; > + You can define "val" inside the for loop as it's not needed outside it. Since we use C11 standard, you can also avoid declaring j here too, and just do "for (uint8_t j = 0; ....)". > + for (i = i - 1; i >= 0; i--) { > + char c = coremask[i]; > + > + if (isxdigit(c) == 0) > + return -1; > + > + val = xdigit2val(c); > + > + for (j = 0; j < BITS_PER_HEX; j++, idx++) { > + if ((1 << j) & val) > + set_core_bit(mask, idx); > + } > + } > + > + corebits_to_array(mask, cores, cores_len); > + uint32_t total_count = mask->total_bits_set; > + free(mask); > + > + return total_count; > +} > diff --git a/lib/arg_parser/rte_arg_parser.h b/lib/arg_parser/rte_arg_parser.h > index 1b12bf451f..b149b37755 100644 > --- a/lib/arg_parser/rte_arg_parser.h > +++ b/lib/arg_parser/rte_arg_parser.h > @@ -58,6 +58,39 @@ __rte_experimental > int > rte_parse_corelist(const char *corelist, uint16_t *cores, uint32_t cores_len); > > +/** > + * Convert a string describing a bitmask of core ids into an array of core ids. > + * > + * On success, the passed array is filled with the core ids present in the > + * bitmask up to the "cores_len", and the number of elements added into the array is returned. > + * For example, passing a 0xA "coremask" results in an array of [1, 3] > + * and would return 2. > + * > + * Like the snprintf function for strings, if the length of the input array is > + * insufficient to hold the number of cores in the "coresmask", 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 coremask > + * A string containing a bitmask 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 "coremask", > + * only "cores_len" elements will be written to the array. > + * @return > + * n: the number of unique cores present in "coremask". > + * -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_coremask(const char* coremask, uint16_t *cores, uint32_t cores_len); > + > > #ifdef __cplusplus > } > diff --git a/lib/arg_parser/version.map b/lib/arg_parser/version.map > index f11699a306..f334f1aaed 100644 > --- a/lib/arg_parser/version.map > +++ b/lib/arg_parser/version.map > @@ -7,4 +7,5 @@ EXPERIMENTAL { > > # added in 24.03 > rte_parse_corelist; > + rte_parse_coremask; > }; > -- > 2.34.1 >