From patchwork Fri Dec 15 17:26:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Bourke X-Patchwork-Id: 135235 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 A02FE43700; Fri, 15 Dec 2023 18:27:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F1DA74339E; Fri, 15 Dec 2023 18:26:54 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mails.dpdk.org (Postfix) with ESMTP id C55B24339A for ; Fri, 15 Dec 2023 18:26:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702661213; x=1734197213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JeGTeJZFctZd+znjoV2swqZS09T6IyEHBTmac4LtOtQ=; b=OxmYwTT4OD8Bc9iqCf6ttwPa/zTmWGT72RExERbkU2XWxKATInNLJHPd rsSopKED7qxM6lJl7vUJQwyCWLOqXL2IU9hBGnOm53raM3aMAnAXuJ53x azc909BWm8t3eM72rcqugp57n1e9No6W2Lse7PWab2cMAgcvR5/9/0TFU zvrdR+KRT8RsdsYlrL0NYW9VisH7Ggc6Qum7rty7cUfNEUq23GJXo7H44 +aY4TrrzWrrAj9j0Fukcd+iI+T1Nl1Ii8jqEeTFrs8f5X2f2/KATBEz25 zZaImjfMEEQUm/XeFIx26JTXIzEU9pv5No1usChzERCRphadm63OsY9e9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10925"; a="2474246" X-IronPort-AV: E=Sophos;i="6.04,279,1695711600"; d="scan'208";a="2474246" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 09:26:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,279,1695711600"; d="scan'208";a="22914251" Received: from unknown (HELO silpixa00400630.ir.intel.com) ([10.237.213.151]) by orviesa001.jf.intel.com with ESMTP; 15 Dec 2023 09:26:52 -0800 From: Euan Bourke To: dev@dpdk.org Cc: Euan Bourke Subject: [PATCH v4 3/8] eal: add support for new arg parsing library Date: Fri, 15 Dec 2023 17:26:27 +0000 Message-Id: <20231215172632.3102502-4-euan.bourke@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231215172632.3102502-1-euan.bourke@intel.com> References: <20231215172632.3102502-1-euan.bourke@intel.com> MIME-Version: 1.0 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..60ba12a368 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_arg_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_arg_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