From patchwork Wed Nov 22 16:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Euan Bourke X-Patchwork-Id: 134536 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F137643382; Wed, 22 Nov 2023 17:48:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7067542670; Wed, 22 Nov 2023 17:47:57 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 588DF4028C for ; Wed, 22 Nov 2023 17:45:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700671558; x=1732207558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=27rllYr0JspWUru9sD+3sf+zwNybuifUPr3djSC/NG4=; b=Qk4KTtslfNEVnkYY26gw9EU83YkvVjWcWrgRB5N0PMOqNHw6XA1NLyWh ovE4l9NxNqBlu21Hkh6qMcst9hWpfDND6Fq/+uJ9poXDoVSE+e0L49Ftp vfscPdt80QoEHXrvi3+QihG/qlWUkuuRXutURoBhc7HyPXUawKPIpBH2f YXaQR9PNFc5dWprSCS3Xph/SDgcOaNQECImpw0Xl1AGlY0X8Wd3FnNcDM ZLJEcIdxUUG6YwtD5AEkIImlNu1b5PpBYwqXB4vIu1f2eLGoL9qzmFYU/ pavAhbQVinC2vfFG18XVDXr5DPemmooCcwtKeUYbVFopb0F9pObmn9rJh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="456415986" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="456415986" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 08:45:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="884685089" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="884685089" Received: from unknown (HELO silpixa00400630.ir.intel.com) ([10.237.213.151]) by fmsmga002.fm.intel.com with ESMTP; 22 Nov 2023 08:45:57 -0800 From: Euan Bourke To: dev@dpdk.org Cc: Euan Bourke Subject: [PATCH 24.03 1/4] arg_parser: new library for command line parsing Date: Wed, 22 Nov 2023 16:45:47 +0000 Message-Id: <20231122164550.3873633-2-euan.bourke@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122164550.3873633-1-euan.bourke@intel.com> References: <20231122164550.3873633-1-euan.bourke@intel.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 22 Nov 2023 17:47:54 +0100 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 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 --- .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))); +} + +static inline void +set_core_bit(struct core_bits *mask, uint16_t idx) +{ + if (get_core_bit(mask, idx) == 0) { + 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; + errno = 0; + idx = strtol(corelist, &end, 10); + if (errno || end == NULL) + return -1; + if (idx > UINT16_MAX) + 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; + 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', From patchwork Wed Nov 22 16:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Bourke X-Patchwork-Id: 134537 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 928A943382; Wed, 22 Nov 2023 17:48:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98D84427E2; Wed, 22 Nov 2023 17:47:58 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 05A1C41143 for ; Wed, 22 Nov 2023 17:46:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700671561; x=1732207561; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7VchvCaL/vuCasWWSrsz/bp5C11rhK6oToYynqbdJqU=; b=VRFT5SaJ5N6+sBbGEkfhOmgpDLfeUnHvkvQxQZlpcF4NRc5fzGVoPcEs 2/pwv0seTA0oay3rrU2kkgbNFlA4o2UanVAvA4Bu5oHSC7GN1TbVAS9Gr Oq0lQ85KdGjulqi3oNcMIYXCX8E/5FwhhEJn1TgZjk5todsknHDPQESLW WZkp7109mLNHcd+ImriUxXsflkkSOj1OO2bC86qSQyF25XADloI6TLZOQ kgN5lyQToRTAfIrN2r7f51wZDwYtyEzBkl6an915lHLXqT8QY8lieWZvO UMUQLNfzJ2T/uT5EwK60csfdc4UaI9tjdeCZwWvX2dNK0AqHGwyp7N24j g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="456416009" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="456416009" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 08:46:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="884685111" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="884685111" Received: from unknown (HELO silpixa00400630.ir.intel.com) ([10.237.213.151]) by fmsmga002.fm.intel.com with ESMTP; 22 Nov 2023 08:46:00 -0800 From: Euan Bourke To: dev@dpdk.org Cc: Euan Bourke Subject: [PATCH 24.03 2/4] arg_parser: add new coremask parsing API Date: Wed, 22 Nov 2023 16:45:48 +0000 Message-Id: <20231122164550.3873633-3-euan.bourke@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122164550.3873633-1-euan.bourke@intel.com> References: <20231122164550.3873633-1-euan.bourke@intel.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 22 Nov 2023 17:47:54 +0100 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 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. The API also returns a 'count' which corresponds to the total number of cores in the coremask string. Signed-off-by: Euan Bourke --- 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) + 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)); + 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'))) + 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; + + 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; }; From patchwork Wed Nov 22 16:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Bourke X-Patchwork-Id: 134538 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3389843382; Wed, 22 Nov 2023 17:48:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B208A42C24; Wed, 22 Nov 2023 17:47:59 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 19145410EE for ; Wed, 22 Nov 2023 17:46:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700671564; x=1732207564; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nQZjPJbjlXMgpZEinaCyNuytZSzDGQSP0pkdzbdF3fQ=; b=KodJhTZH3ORAot3iNJ5Q1fYON9/or4Rv1BxLpfk3YHsFp5dj33b4jCCR SgzmX/ygsz6z3BnTDXZ/xBv2YReIprr+1Q00YwN5jGGwUfBq7sNfgxibw qPRXLjKTwtnOenTzSnrtzXBAyPOWFrCcgKz+9jimS2TNoGDXP777JuquR ABK6bqK1nUji00JOA+ZGwrfxQOitW6zhKeIB6OkGQzDlPap9ar1TYo7Ou 8d7yx9seeLrsEP79jcO015PoagYd9Rq2jYl2+qdJPbniihQpSJcNzgZIh WcaXS3eTNm2GMyrfETFioi4AF0Pc1/jp9YC9bVNGvWNLPB44W3Aj2VLFE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="456416031" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="456416031" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 08:46:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="884685128" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="884685128" Received: from unknown (HELO silpixa00400630.ir.intel.com) ([10.237.213.151]) by fmsmga002.fm.intel.com with ESMTP; 22 Nov 2023 08:46:02 -0800 From: Euan Bourke To: dev@dpdk.org Cc: Euan Bourke Subject: [PATCH 24.03 3/4] eal: add support for new arg parsing library Date: Wed, 22 Nov 2023 16:45:49 +0000 Message-Id: <20231122164550.3873633-4-euan.bourke@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122164550.3873633-1-euan.bourke@intel.com> References: <20231122164550.3873633-1-euan.bourke@intel.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 22 Nov 2023 17:47:54 +0100 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 Update to eal functions relating to corelist and coremask parsing to support the new arg parsing library. Functions now call the API instead of implementing their own version. Signed-off-by: Euan Bourke --- lib/eal/common/eal_common_options.c | 114 ++++------------------------ lib/eal/meson.build | 2 +- 2 files changed, 14 insertions(+), 102 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index a6d21f1cba..7c89a1e18b 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #ifndef RTE_EXEC_ENV_WINDOWS #include @@ -706,7 +707,7 @@ update_lcore_config(int *cores) } static int -check_core_list(int *lcores, unsigned int count) +check_core_list(uint16_t *lcores, unsigned int count) { char lcorestr[RTE_MAX_LCORE * 10]; bool overflow = false; @@ -746,60 +747,18 @@ check_core_list(int *lcores, unsigned int count) int rte_eal_parse_coremask(const char *coremask, int *cores) { - const char *coremask_orig = coremask; - int lcores[RTE_MAX_LCORE]; - unsigned int count = 0; - int i, j, idx; - int val; - char c; + int count; + uint16_t lcores[RTE_MAX_LCORE]; + int idx; for (idx = 0; idx < RTE_MAX_LCORE; idx++) cores[idx] = -1; - idx = 0; - /* 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'))) - coremask += 2; - i = strlen(coremask); - while ((i > 0) && isblank(coremask[i - 1])) - i--; - if (i == 0) { - RTE_LOG(ERR, EAL, "No lcores in coremask: [%s]\n", - coremask_orig); - return -1; - } + /* Call public coremask parsing API */ + count = rte_parse_coremask(coremask, lcores, RTE_MAX_LCORE); - for (i = i - 1; i >= 0; i--) { - c = coremask[i]; - if (isxdigit(c) == 0) { - /* invalid characters */ - RTE_LOG(ERR, EAL, "invalid characters in coremask: [%s]\n", - coremask_orig); - return -1; - } - val = xdigit2val(c); - for (j = 0; j < BITS_PER_HEX; j++, idx++) - { - if ((1 << j) & val) { - if (count >= RTE_MAX_LCORE) { - RTE_LOG(ERR, EAL, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)\n", - RTE_MAX_LCORE); - return -1; - } - lcores[count++] = idx; - } - } - } - if (count == 0) { - RTE_LOG(ERR, EAL, "No lcores in coremask: [%s]\n", - coremask_orig); + if (count <= 0 || count > RTE_MAX_LCORE) return -1; - } if (check_core_list(lcores, count)) return -1; @@ -898,64 +857,17 @@ eal_parse_service_corelist(const char *corelist) static int eal_parse_corelist(const char *corelist, int *cores) { - unsigned int count = 0, i; - int lcores[RTE_MAX_LCORE]; - char *end = NULL; - int min, max; + int count; + uint16_t lcores[RTE_MAX_LCORE]; int idx; for (idx = 0; idx < RTE_MAX_LCORE; idx++) cores[idx] = -1; - /* Remove all blank characters ahead */ - while (isblank(*corelist)) - corelist++; + /* Call public corelist parsing API */ + count = rte_parse_corelist(corelist, lcores, RTE_MAX_LCORE); - /* Get list of cores */ - min = -1; - do { - while (isblank(*corelist)) - corelist++; - if (*corelist == '\0') - return -1; - errno = 0; - idx = strtol(corelist, &end, 10); - if (errno || end == NULL) - return -1; - if (idx < 0) - return -1; - while (isblank(*end)) - end++; - if (*end == '-') { - min = idx; - } else if ((*end == ',') || (*end == '\0')) { - max = idx; - if (min == -1) - min = idx; - for (idx = min; idx <= max; idx++) { - bool dup = false; - - /* Check if this idx is already present */ - for (i = 0; i < count; i++) { - if (lcores[i] == idx) - dup = true; - } - if (dup) - continue; - if (count >= RTE_MAX_LCORE) { - RTE_LOG(ERR, EAL, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)\n", - RTE_MAX_LCORE); - return -1; - } - lcores[count++] = idx; - } - min = -1; - } else - return -1; - corelist = end + 1; - } while (*end != '\0'); - - if (count == 0) + if (count <= 0 || count > RTE_MAX_LCORE) return -1; if (check_core_list(lcores, count)) diff --git a/lib/eal/meson.build b/lib/eal/meson.build index e1d6c4cf17..52a22e2e66 100644 --- a/lib/eal/meson.build +++ b/lib/eal/meson.build @@ -14,7 +14,7 @@ subdir(exec_env) subdir(arch_subdir) -deps += ['log', 'kvargs'] +deps += ['log', 'kvargs', 'arg_parser'] if not is_windows deps += ['telemetry'] endif From patchwork Wed Nov 22 16:45:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Bourke X-Patchwork-Id: 134539 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CD94F43382; Wed, 22 Nov 2023 17:48:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B445442D35; Wed, 22 Nov 2023 17:48:00 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 123F941133 for ; Wed, 22 Nov 2023 17:46: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=1700671566; x=1732207566; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LYFo+tM1if1i3/yLMQL40YZVnPsIdjOrjUCpz5Kkhi8=; b=eghvW2cvO5Jfg3wXt0gEtbd0n9LQ1KeMqnmZakTSkaL9uYlikEEVkoh8 cQU5yXGjAY4B/rFkmxeQ+AGWuOWR2qh0UsJzleXlarhG9lM8deAaU2zYz qE9rCQ3W6GzrdArghBXbSm8GHIvksdhonOQ8Go3OboOw4dKhqcx+GydXd DNGl/GPycJVuepJoEUVfBosjcXIhSMYOd/LgvwW6PSoUAhffNJwlpExYQ macAClJdkAa0mDn+3VsmP1kQoLP8uiKjLpft8EeRIn1t/0Z0FM3el6UWJ jISHBbbCJ5Pn3lXaicJClW4xQSThyBQGzXDaHEJQ6KD1+wkFQM+6H78lS A==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="456416041" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="456416041" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 08:46:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="884685147" X-IronPort-AV: E=Sophos;i="6.04,219,1695711600"; d="scan'208";a="884685147" Received: from unknown (HELO silpixa00400630.ir.intel.com) ([10.237.213.151]) by fmsmga002.fm.intel.com with ESMTP; 22 Nov 2023 08:46:05 -0800 From: Euan Bourke To: dev@dpdk.org Cc: Euan Bourke Subject: [PATCH 24.03 4/4] dlb2: add new arg parsing library API support Date: Wed, 22 Nov 2023 16:45:50 +0000 Message-Id: <20231122164550.3873633-5-euan.bourke@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122164550.3873633-1-euan.bourke@intel.com> References: <20231122164550.3873633-1-euan.bourke@intel.com> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 22 Nov 2023 17:47:54 +0100 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 Switched the dlb2 driver to call the new arg parsing library instead of eal for coremask parsing, and updated the resource probe funcion to support the changed formatting of the API. Signed-off-by: Euan Bourke --- drivers/event/dlb2/dlb2_priv.h | 4 +- drivers/event/dlb2/pf/base/dlb2_resource.c | 54 +++++++++------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/drivers/event/dlb2/dlb2_priv.h b/drivers/event/dlb2/dlb2_priv.h index 31a3beeb6c..c14d83da5b 100644 --- a/drivers/event/dlb2/dlb2_priv.h +++ b/drivers/event/dlb2/dlb2_priv.h @@ -10,6 +10,7 @@ #include #include +#include #include "dlb2_user.h" #include "dlb2_log.h" #include "rte_pmd_dlb2.h" @@ -729,9 +730,6 @@ void dlb2_event_build_hcws(struct dlb2_port *qm_port, uint8_t *sched_type, uint8_t *queue_id); -/* Extern functions */ -extern int rte_eal_parse_coremask(const char *coremask, int *cores); - /* Extern globals */ extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES]; diff --git a/drivers/event/dlb2/pf/base/dlb2_resource.c b/drivers/event/dlb2/pf/base/dlb2_resource.c index 7ce3e3531c..422d075ff8 100644 --- a/drivers/event/dlb2/pf/base/dlb2_resource.c +++ b/drivers/event/dlb2/pf/base/dlb2_resource.c @@ -922,49 +922,37 @@ dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args) { const struct dlb2_devargs *args = (const struct dlb2_devargs *)probe_args; const char *mask = args ? args->producer_coremask : NULL; - int cpu = 0, cnt = 0, cores[RTE_MAX_LCORE], i; + int cpu = 0, i; + uint16_t cores[RTE_MAX_LCORE]; if (args) { mask = (const char *)args->producer_coremask; } - if (mask && rte_eal_parse_coremask(mask, cores)) { + int ret = rte_parse_coremask(mask, cores, RTE_DIM(cores)); + + if (mask && ret == -1) { DLB2_LOG_ERR(": Invalid producer coremask=%s", mask); return -1; } - hw->num_prod_cores = 0; - for (i = 0; i < RTE_MAX_LCORE; i++) { - bool is_pcore = (mask && cores[i] != -1); - - if (rte_lcore_is_enabled(i)) { - if (is_pcore) { - /* - * Populate the producer cores from parsed - * coremask - */ - hw->prod_core_list[cores[i]] = i; - hw->num_prod_cores++; - - } else if ((++cnt == DLB2_EAL_PROBE_CORE || - rte_lcore_count() < DLB2_EAL_PROBE_CORE)) { - /* - * If no producer coremask is provided, use the - * second EAL core to probe - */ - cpu = i; - break; - } - } else if (is_pcore) { - DLB2_LOG_ERR("Producer coremask(%s) must be a subset of EAL coremask", - mask); - return -1; - } + hw->num_prod_cores = ret; + /* Check for no producer cores and then get the second EAL core */ + if (hw->num_prod_cores > 0) + cpu = cores[0]; + else if (rte_lcore_count() < DLB2_EAL_PROBE_CORE) + cpu = rte_get_main_lcore(); + else + cpu = rte_get_next_lcore(-1, 1, 0); - } - /* Use the first core in producer coremask to probe */ - if (hw->num_prod_cores) - cpu = hw->prod_core_list[0]; + /* check our producer list is valid and error out if not */ + for (i = 0; i < hw->num_prod_cores; i++) { + if (!rte_lcore_is_enabled(cores[i])) { + DLB2_LOG_ERR("Producer coremask(%s) must be a subset of EAL coremask", mask); + return -1; + } + hw->prod_core_list[i] = cores[i]; +} dlb2_get_pp_allocation(hw, cpu, DLB2_LDB_PORT); dlb2_get_pp_allocation(hw, cpu, DLB2_DIR_PORT);