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 80F634889D; Fri, 3 Oct 2025 10:17:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFC7C40DCF; Fri, 3 Oct 2025 10:15:37 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by mails.dpdk.org (Postfix) with ESMTP id 4EFA740A79 for ; Fri, 3 Oct 2025 10:15:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1759479334; x=1791015334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gGVKDFOtdRpSW0445A2QhWG1YfPjhDyWPjE7wUBIpXw=; b=SK4ZG8oLy9OcCPsUSvWqrqBoWBPFPRvWS10IdgVJvd05B+MJS1/93Emq lKO5MN+rHjI79MhZbq0j/ansy1JyX5kmvT+wojuRaoujD9gsTKAES84dl ZYitsSFMq6zjIL8gYNJUevXNKWhQVjAxOo2G6cAKslnwm/69ZKvIV9Gls h0mjqPvWgR48bNJb9i0Wh79HHteo58aM4otUwrV4+sTsFsXGsuEwSt9oH ySYtEIDwJ7ICqkTmtMCyLYcLUqKJLcQY4PGeHyDLvSQI0JqEJGBbb7Upy 4wGaGnsRBW8gNT6LPQ0zLoymF4r2/ugI/V69/nDxN/7s6KZc7A295wF3g w==; X-CSE-ConnectionGUID: fBGOcxT+QLOAC4y2uQx92g== X-CSE-MsgGUID: 6kBw4Eb0QAqIQC2a915Qrg== X-IronPort-AV: E=McAfee;i="6800,10657,11570"; a="61473607" X-IronPort-AV: E=Sophos;i="6.18,312,1751266800"; d="scan'208";a="61473607" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2025 01:15:33 -0700 X-CSE-ConnectionGUID: 6fjIbi0eSGCCp75DTXyLfA== X-CSE-MsgGUID: 3p6E9T1PSaGs3Ou8nRD9Uw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,312,1751266800"; d="scan'208";a="184525903" Received: from silpixa00401385.ir.intel.com ([10.20.224.226]) by fmviesa004.fm.intel.com with ESMTP; 03 Oct 2025 01:15:32 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: david.marchand@redhat.com, Bruce Richardson Subject: [PATCH v9 18/18] eal: allow lcore remapping with autodetected core affinity Date: Fri, 3 Oct 2025 09:15:10 +0100 Message-ID: <20251003081510.1197166-19-bruce.richardson@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251003081510.1197166-1-bruce.richardson@intel.com> References: <20250520164025.2055721-1-bruce.richardson@intel.com> <20251003081510.1197166-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 When run without an coremask or core list parameters, EAL detects the working set of cores allowed for the current process and uses that as a core list for use. Currently, this does not work for cores which are numbered >= RTE_MAX_LCORE. We can fix this by allowing the remap option to also be used with these auto-detected cores. In the process we simplify the code by taking advantage of that fact that we know up-front when processing parameters if any core parameter is passed, so we no longer need a flag and to auto-detect at the end. Instead, we take advantage of the fact that our core-arg processing routines now all work with cpusets, to have a simple tri-state option for remapping (if we don't have manual remapping done by --lcores-parameter): * parse coremask to cpuset * parse core list to cpuset * query OS for current thread's cpuset Once that is done, we have common code for processing, and optionally remapping, the resulting cpuset. Signed-off-by: Bruce Richardson --- lib/eal/common/eal_common_options.c | 110 +++++++++++----------------- 1 file changed, 43 insertions(+), 67 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index c754c19511..b1830aa9d7 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -292,8 +292,6 @@ struct device_option { static struct device_option_list devopt_list = TAILQ_HEAD_INITIALIZER(devopt_list); -static int core_parsed; - /* Returns rte_usage_hook_t */ rte_usage_hook_t eal_get_application_usage_hook(void) @@ -830,7 +828,7 @@ eal_parse_service_coremask(const char *coremask) if (count == 0) return -1; - if (core_parsed && taken_lcore_count != count) { + if (taken_lcore_count != count) { EAL_LOG(WARNING, "Not all service cores are in the coremask. " "Please ensure -c or -l includes service cores"); @@ -1051,7 +1049,7 @@ eal_parse_service_corelist(const char *corelist) if (count == 0) return -1; - if (core_parsed && taken_lcore_count != count) { + if (taken_lcore_count != count) { EAL_LOG(WARNING, "Not all service cores were in the coremask. " "Please ensure -c or -l includes service cores"); @@ -1919,32 +1917,31 @@ eal_parse_args(void) } } - /* parse the core list arguments */ - if (args.coremask != NULL) { - rte_cpuset_t cpuset; - if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) { - EAL_LOG(ERR, "invalid coremask syntax"); - return -1; - } - if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) { - char *available = available_cores(); - - EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s", - args.coremask, available); - free(available); + /* parse the core list arguments + * First handle the special case where we have explicit core mapping/remapping + */ + if (args.lcores != NULL && !remap_lcores) { + if (eal_parse_lcores(args.lcores) < 0) { + EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores); return -1; } - core_parsed = 1; - } else if (args.lcores != NULL) { - if (!remap_lcores) { - if (eal_parse_lcores(args.lcores) < 0) { - EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores); + } else { + /* otherwise get a cpuset of the cores to be used and then handle that + * taking mappings into account. Cpuset comes from either: + * 1. coremask parameter + * 2. core list parameter + * 3. autodetecting current thread affinities + */ + rte_cpuset_t cpuset; + const char *cpuset_source; + if (args.coremask != NULL) { + if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) { + EAL_LOG(ERR, "invalid coremask syntax"); return -1; } - } else { - rte_cpuset_t cpuset; - + cpuset_source = "coremask"; + } else if (args.lcores != NULL) { if (strchr(args.lcores, '@') != NULL || strchr(args.lcores, '(') != NULL) { EAL_LOG(ERR, "cannot use '@' or core groupings '()' in lcore list when remapping lcores"); return -1; @@ -1954,18 +1951,29 @@ eal_parse_args(void) EAL_LOG(ERR, "Error parsing lcore list: '%s'", args.lcores); return -1; } - - if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) { - char *available = available_cores(); - - EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s", - args.coremask, available); - free(available); + cpuset_source = "core list"; + } else { + if (rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset) != 0) { + EAL_LOG(ERR, "Error querying current process thread affinities"); return -1; } + cpuset_source = "affinity auto-detection"; + } + char *cpuset_str = eal_cpuset_to_str(&cpuset); + if (cpuset_str != NULL) { + EAL_LOG(DEBUG, "Cores selected by %s: %s", cpuset_source, cpuset_str); + free(cpuset_str); + } + if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) { + char *available = available_cores(); + + EAL_LOG(ERR, "invalid coremask or core-list parameter, please check specified cores are part of %s", + available); + free(available); + return -1; } - core_parsed = 1; } + /* service core options */ if (args.service_coremask != NULL) { if (eal_parse_service_coremask(args.service_coremask) < 0) { @@ -2208,27 +2216,6 @@ eal_parse_args(void) return 0; } -static void -eal_auto_detect_cores(struct rte_config *cfg) -{ - unsigned int lcore_id; - unsigned int removed = 0; - rte_cpuset_t affinity_set; - - if (rte_thread_get_affinity_by_id(rte_thread_self(), &affinity_set) != 0) - CPU_ZERO(&affinity_set); - - for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { - if (cfg->lcore_role[lcore_id] == ROLE_RTE && - !CPU_ISSET(lcore_id, &affinity_set)) { - cfg->lcore_role[lcore_id] = ROLE_OFF; - removed++; - } - } - - cfg->lcore_count -= removed; -} - static void compute_ctrl_threads_cpuset(struct internal_config *internal_cfg) { @@ -2276,20 +2263,9 @@ int eal_adjust_config(struct internal_config *internal_cfg) { int i; - struct rte_config *cfg = rte_eal_get_configuration(); - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - if (!core_parsed) - eal_auto_detect_cores(cfg); - - if (cfg->lcore_count == 0) { - EAL_LOG(ERR, "No detected lcore is enabled, please check the core list"); - return -1; - } - if (internal_conf->process_type == RTE_PROC_AUTO) - internal_conf->process_type = eal_proc_type_detect(); + if (internal_cfg->process_type == RTE_PROC_AUTO) + internal_cfg->process_type = eal_proc_type_detect(); compute_ctrl_threads_cpuset(internal_cfg); -- 2.48.1