[RFC,v1,5/5] lcore: store physical package ID internally

Message ID f68d303116b86fd1df004c43941c72444a697c9d.1725622420.git.anatoly.burakov@intel.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series Adjust wording for NUMA vs. socket ID in DPDK |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues
ci/iol-unit-arm64-testing fail Testing issues
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Functional fail Functional Testing issues
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Burakov, Anatoly Sept. 6, 2024, 11:47 a.m. UTC
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 <anatoly.burakov@intel.com>
---
 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(+)
  

Comments

fengchengwen Sept. 9, 2024, 7:49 a.m. UTC | #1
It seemed there is no usage scenario of the new field, suggest add it when we indeed need it.

On 2024/9/6 19:47, Anatoly Burakov wrote:
> 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 <anatoly.burakov@intel.com>
> ---

...
  

Patch

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)
 {