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 8ED2E4591D; Fri, 6 Sep 2024 13:48:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 204F042F01; Fri, 6 Sep 2024 13:47:47 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by mails.dpdk.org (Postfix) with ESMTP id 0787742EE8 for ; Fri, 6 Sep 2024 13:47:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725623265; x=1757159265; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=jQ4qYpqTVb88Ldwf87/bCttLBBkwEyASLgTGGZela64=; b=E9y5f5NI5g9ZolrUl7PRIIAn4Vy16QkR99yxxmKz8DeZ3wq6fMpLRZ6E uMNqMa2bFb2DcW6HJjZNtQcO0hY094N2JZ+Em6S1vfQOfZCDSllUqo8YO skH1mCutIYLVFxISTgO5riVsGkO/ZqFwJuQFpywlYuUH2EJzV6iDeYulc FQ92Lkb/h+FvMiGRKRl71cd5J6g7R0SfYNSNTvI1SqIbbJ5sQ+HJvnxK2 Xrp5jviFOYFAzeYJ+iZ74CLBbRcPXDjaTNMtCBj94rI+VRmSrltTMTk9c ljrzykhOkpj7GvTRpOBF0Jyxygi0w6oTxnx5bO3It4jF0H+jETndZuvLp g==; X-CSE-ConnectionGUID: pm4T9UnERjCX95sRrOzDaw== X-CSE-MsgGUID: /eGNfjuHTIGwVMoLk6fldg== X-IronPort-AV: E=McAfee;i="6700,10204,11187"; a="13408808" X-IronPort-AV: E=Sophos;i="6.10,207,1719903600"; d="scan'208";a="13408808" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2024 04:47:45 -0700 X-CSE-ConnectionGUID: jKUqx5TUQEqhw+g45k42cw== X-CSE-MsgGUID: VqypwyUYSZKP1Zoiwx2iOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,207,1719903600"; d="scan'208";a="66162998" Received: from silpixa00401119.ir.intel.com ([10.55.129.167]) by fmviesa010.fm.intel.com with ESMTP; 06 Sep 2024 04:47:44 -0700 From: Anatoly Burakov To: dev@dpdk.org, Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [RFC PATCH v1 5/5] lcore: store physical package ID internally Date: Fri, 6 Sep 2024 12:47:31 +0100 Message-ID: X-Mailer: git-send-email 2.43.5 In-Reply-To: References: 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 This patch introduces a new field in the lcore structure that stores the physical package ID of the core. This field is populated during EAL init. It is not exposed through any external API's for now. Signed-off-by: Anatoly Burakov --- lib/eal/common/eal_common_lcore.c | 18 ++++++++++++++++++ lib/eal/common/eal_private.h | 3 +++ lib/eal/common/eal_thread.h | 11 +++++++++++ lib/eal/freebsd/eal_lcore.c | 6 ++++++ lib/eal/linux/eal_lcore.c | 28 ++++++++++++++++++++++++++++ lib/eal/windows/eal_lcore.c | 7 +++++++ 6 files changed, 73 insertions(+) diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c index ba8fce6607..9e937c2d6a 100644 --- a/lib/eal/common/eal_common_lcore.c +++ b/lib/eal/common/eal_common_lcore.c @@ -144,7 +144,9 @@ rte_eal_cpu_init(void) unsigned lcore_id; unsigned count = 0; unsigned int socket_id, prev_socket_id; + unsigned int package_id, prev_package_id; int lcore_to_socket_id[RTE_MAX_LCORE]; + int lcore_to_package_id[RTE_MAX_LCORE]; /* * Parse the maximum set of logical cores, detect the subset of running @@ -160,6 +162,10 @@ rte_eal_cpu_init(void) socket_id = eal_cpu_socket_id(lcore_id); lcore_to_socket_id[lcore_id] = socket_id; + /* find physical package ID */ + package_id = eal_cpu_package_id(lcore_id); + lcore_to_package_id[lcore_id] = package_id; + if (eal_cpu_detected(lcore_id) == 0) { config->lcore_role[lcore_id] = ROLE_OFF; lcore_config[lcore_id].core_index = -1; @@ -174,6 +180,7 @@ rte_eal_cpu_init(void) lcore_config[lcore_id].core_role = ROLE_RTE; lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id); lcore_config[lcore_id].numa_id = socket_id; + lcore_config[lcore_id].package_id = package_id; EAL_LOG(DEBUG, "Detected lcore %u as " "core %u on NUMA node %u", lcore_id, lcore_config[lcore_id].core_id, @@ -199,14 +206,25 @@ rte_eal_cpu_init(void) qsort(lcore_to_socket_id, RTE_DIM(lcore_to_socket_id), sizeof(lcore_to_socket_id[0]), socket_id_cmp); + /* sort all package id's in ascending order */ + qsort(lcore_to_package_id, RTE_DIM(lcore_to_package_id), + sizeof(lcore_to_package_id[0]), socket_id_cmp); + prev_socket_id = -1; + prev_package_id = -1; config->numa_node_count = 0; + config->package_count = 0; for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { socket_id = lcore_to_socket_id[lcore_id]; + package_id = lcore_to_package_id[lcore_id]; if (socket_id != prev_socket_id) config->numa_nodes[config->numa_node_count++] = socket_id; + if (package_id != prev_package_id) + config->packages[config->package_count++] = + package_id; prev_socket_id = socket_id; + prev_package_id = package_id; } EAL_LOG(INFO, "Detected NUMA nodes: %u", config->numa_node_count); diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 196dadc8a2..611c0de640 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -31,6 +31,7 @@ struct lcore_config { volatile RTE_ATOMIC(enum rte_lcore_state_t) state; /**< lcore state */ unsigned int numa_id; /**< NUMA node ID for this lcore */ + unsigned int package_id; /**< Physical package ID for this lcore */ unsigned int core_id; /**< core number on socket for this lcore */ int core_index; /**< relative index, starting from 0 */ uint8_t core_role; /**< role of core eg: OFF, RTE, SERVICE */ @@ -48,6 +49,8 @@ struct rte_config { uint32_t lcore_count; /**< Number of available logical cores. */ uint32_t numa_node_count; /**< Number of detected NUMA nodes. */ uint32_t numa_nodes[RTE_MAX_NUMA_NODES]; /**< List of detected NUMA nodes. */ + uint32_t package_count; /**< Number of detected physical packages. */ + uint32_t packages[RTE_MAX_NUMA_NODES]; /**< List of detected physical packages. */ uint32_t service_lcore_count;/**< Number of available service cores. */ enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */ diff --git a/lib/eal/common/eal_thread.h b/lib/eal/common/eal_thread.h index 1c3c3442d3..32ba36589e 100644 --- a/lib/eal/common/eal_thread.h +++ b/lib/eal/common/eal_thread.h @@ -27,6 +27,17 @@ __rte_noreturn uint32_t eal_thread_loop(void *arg); */ unsigned eal_cpu_socket_id(unsigned cpu_id); +/** + * Get the package id from cpu id. + * This function is private to EAL. + * + * @param cpu_id + * The logical process id. + * @return + * socket_id or SOCKET_ID_ANY + */ +unsigned eal_cpu_package_id(unsigned cpu_id); + /** * Default buffer size to use with eal_thread_dump_affinity() */ diff --git a/lib/eal/freebsd/eal_lcore.c b/lib/eal/freebsd/eal_lcore.c index 1d3d1b67b9..26284bf7e3 100644 --- a/lib/eal/freebsd/eal_lcore.c +++ b/lib/eal/freebsd/eal_lcore.c @@ -41,6 +41,12 @@ eal_cpu_socket_id(__rte_unused unsigned cpu_id) return 0; } +unsigned +eal_cpu_package_id(__rte_unused unsigned cpu_id) +{ + return 0; +} + /* Check if a cpu is present by the presence of the * cpu information for it. */ diff --git a/lib/eal/linux/eal_lcore.c b/lib/eal/linux/eal_lcore.c index 29b36dd610..c436686e1b 100644 --- a/lib/eal/linux/eal_lcore.c +++ b/lib/eal/linux/eal_lcore.c @@ -13,6 +13,7 @@ #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u" #define CORE_ID_FILE "topology/core_id" +#define PACKAGE_ID_FILE "topology/physical_package_id" #define NUMA_NODE_PATH "/sys/devices/system/node" /* Check if a cpu is present by the presence of the cpu information for it */ @@ -53,6 +54,33 @@ eal_cpu_socket_id(unsigned lcore_id) return 0; } +/* + * Get CPU package ID for a logical core. + * + * This searches each nodeX directories in /sys for the symlink for the given + * lcore_id and returns the numa node where the lcore is found. If lcore is not + * found on any numa node, returns zero. + */ +unsigned +eal_cpu_package_id(unsigned lcore_id) +{ + char path[PATH_MAX]; + unsigned long id; + + int len = snprintf(path, sizeof(path), + SYS_CPU_DIR "/%s", lcore_id, PACKAGE_ID_FILE); + if (len <= 0 || (unsigned)len >= sizeof(path)) + goto err; + if (eal_parse_sysfs_value(path, &id) != 0) + goto err; + return (unsigned)id; + +err: + EAL_LOG(ERR, "Error reading package id value from %s " + "for lcore %u - assuming package 0", SYS_CPU_DIR, lcore_id); + return 0; +} + /* Get the cpu core id value from the /sys/.../cpuX core_id value */ unsigned eal_cpu_core_id(unsigned lcore_id) diff --git a/lib/eal/windows/eal_lcore.c b/lib/eal/windows/eal_lcore.c index a498044620..cca954b689 100644 --- a/lib/eal/windows/eal_lcore.c +++ b/lib/eal/windows/eal_lcore.c @@ -233,6 +233,13 @@ eal_cpu_socket_id(unsigned int lcore_id) return cpu_map.lcores[lcore_id].socket_id; } +unsigned +eal_cpu_package_id(unsigned int lcore_id) +{ + /* FIXME: Windows does support reporting Package ID */ + return cpu_map.lcores[lcore_id].socket_id; +} + unsigned eal_cpu_core_id(unsigned int lcore_id) { -- 2.43.5