From patchwork Thu Dec 7 16:18:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Euan Bourke X-Patchwork-Id: 134932 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 B5BCF4369D; Thu, 7 Dec 2023 17:19:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B499642F45; Thu, 7 Dec 2023 17:18:43 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 71B0242F37 for ; Thu, 7 Dec 2023 17:18:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701965921; x=1733501921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LVghYsSuh7gYwi/527BOt+d4xJ7IPnG1RmWH9spLqnc=; b=SnpQVg4RYfj2ZArFWA+/UXOpZuARu7RdmIAfwdQCOMlTaji5Kq86L9WN OncAGmA4i0IHkAeFYSC1yjiW4xYUjTqdnahNRpzl3WIoqY4lE7Dg+l9ee MUd5uvDSTvH0DbzXsFi81vhaBoGVUM375wUZ8kTiJOHQnENNkgHd+DiNf VHK7E2qekrmIbscgJYeNhfWXFBTpvFr9/FkuWQRqlBN+E4+6FkGRhNzUT p1WhFkvZnUT2ZhLUuvTld8H+wG1c4RxhN8ZxXSB21tqmbtH6KLgfzEGMN z98q/ClPGBdjr6bEe/wEQmPREezY9hpx+2hz3yVpF5KFUCjG1pdsyBGpq A==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="397048617" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="397048617" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 08:18:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="765153974" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="765153974" Received: from unknown (HELO silpixa00400630.ir.intel.com) ([10.237.213.151]) by orsmga007.jf.intel.com with ESMTP; 07 Dec 2023 08:18:39 -0800 From: Euan Bourke To: dev@dpdk.org Cc: Euan Bourke Subject: [PATCH v3 4/8] eal: update to service core related parsers Date: Thu, 7 Dec 2023 16:18:14 +0000 Message-Id: <20231207161818.2590661-5-euan.bourke@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207161818.2590661-1-euan.bourke@intel.com> References: <20231207161818.2590661-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 Updates to the parse service cores functions in EAL to call the arg parser API instead of implementing its own versions. Signed-off-by: Euan Bourke --- lib/eal/common/eal_common_options.c | 171 +++++++--------------------- 1 file changed, 41 insertions(+), 130 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 60ba12a368..d44654f621 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -573,97 +573,49 @@ eal_plugins_init(void) * the global configuration (core role and core count) with the parsed * value. */ -static int xdigit2val(unsigned char c) -{ - int val; - - if (isdigit(c)) - val = c - '0'; - else if (isupper(c)) - val = c - 'A' + 10; - else - val = c - 'a' + 10; - return val; -} - static int eal_parse_service_coremask(const char *coremask) { struct rte_config *cfg = rte_eal_get_configuration(); - int i, j, idx = 0; - unsigned int count = 0; - char c; - int val; + uint16_t cores[RTE_MAX_LCORE]; + int64_t count; uint32_t taken_lcore_count = 0; - if (coremask == NULL) - return -1; - /* 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) + count = rte_arg_parse_coremask(coremask, cores, RTE_DIM(cores)); + + if (count == 0 || count == -1) return -1; - for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) { - c = coremask[i]; - if (isxdigit(c) == 0) { - /* invalid characters */ + for (int i = 0; i < count; i++) { + uint32_t lcore = cores[i]; + if (main_lcore_parsed && + cfg->main_lcore == lcore) { + RTE_LOG(ERR, EAL, + "lcore %u is main lcore, cannot use as service core\n", + cores[i]); return -1; } - val = xdigit2val(c); - for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; - j++, idx++) { - if ((1 << j) & val) { - /* handle main lcore already parsed */ - uint32_t lcore = idx; - if (main_lcore_parsed && - cfg->main_lcore == lcore) { - RTE_LOG(ERR, EAL, - "lcore %u is main lcore, cannot use as service core\n", - idx); - return -1; - } - if (eal_cpu_detected(idx) == 0) { - RTE_LOG(ERR, EAL, - "lcore %u unavailable\n", idx); - return -1; - } - - if (cfg->lcore_role[idx] == ROLE_RTE) - taken_lcore_count++; - - lcore_config[idx].core_role = ROLE_SERVICE; - count++; - } - } - } - - for (; i >= 0; i--) - if (coremask[i] != '0') + if (eal_cpu_detected(cores[i]) == 0) { + RTE_LOG(ERR, EAL, + "lcore %u unavailable\n", cores[i]); return -1; + } - for (; idx < RTE_MAX_LCORE; idx++) - lcore_config[idx].core_index = -1; - - if (count == 0) - return -1; + if (cfg->lcore_role[cores[i]] == ROLE_RTE) + taken_lcore_count++; + lcore_config[cores[i]].core_role = ROLE_SERVICE; + } if (core_parsed && taken_lcore_count != count) { RTE_LOG(WARNING, EAL, - "Not all service cores are in the coremask. " + "Not all service cores were in the coremask. " "Please ensure -c or -l includes service cores\n"); } + for (uint16_t j = count*4; j < RTE_MAX_LCORE; j++) + lcore_config[j].core_index = -1; + cfg->service_lcore_count = count; return 0; } @@ -780,70 +732,29 @@ static int eal_parse_service_corelist(const char *corelist) { struct rte_config *cfg = rte_eal_get_configuration(); - int i; - unsigned count = 0; - char *end = NULL; - uint32_t min, max, idx; + int64_t i, count; + uint16_t cores[RTE_MAX_LCORE]; uint32_t taken_lcore_count = 0; - if (corelist == NULL) - return -1; + count = rte_arg_parse_corelist(corelist, cores, RTE_DIM(cores)); - /* Remove all blank characters ahead and after */ - while (isblank(*corelist)) - corelist++; - i = strlen(corelist); - while ((i > 0) && isblank(corelist[i - 1])) - i--; + if (count == 0 || count == -1) + return -1; - /* Get list of cores */ - min = RTE_MAX_LCORE; - do { - while (isblank(*corelist)) - corelist++; - if (*corelist == '\0') - return -1; - errno = 0; - idx = strtoul(corelist, &end, 10); - if (errno || end == NULL) - return -1; - if (idx >= RTE_MAX_LCORE) - return -1; - while (isblank(*end)) - end++; - if (*end == '-') { - min = idx; - } else if ((*end == ',') || (*end == '\0')) { - max = idx; - if (min == RTE_MAX_LCORE) - min = idx; - for (idx = min; idx <= max; idx++) { - if (cfg->lcore_role[idx] != ROLE_SERVICE) { - /* handle main lcore already parsed */ - uint32_t lcore = idx; - if (cfg->main_lcore == lcore && - main_lcore_parsed) { - RTE_LOG(ERR, EAL, - "Error: lcore %u is main lcore, cannot use as service core\n", - idx); - return -1; - } - if (cfg->lcore_role[idx] == ROLE_RTE) - taken_lcore_count++; - - lcore_config[idx].core_role = - ROLE_SERVICE; - count++; - } - } - min = RTE_MAX_LCORE; - } else + for (i = 0; i < count; i++) { + uint32_t lcore = cores[i]; + if (cfg->main_lcore == lcore && + main_lcore_parsed) { + RTE_LOG(ERR, EAL, + "Error: lcore %u is main lcore, cannot use as service core\n", + cores[i]); return -1; - corelist = end + 1; - } while (*end != '\0'); + } + if (cfg->lcore_role[cores[i]] == ROLE_RTE) + taken_lcore_count++; - if (count == 0) - return -1; + lcore_config[cores[i]].core_role = ROLE_SERVICE; + } if (core_parsed && taken_lcore_count != count) { RTE_LOG(WARNING, EAL,