[PATCH v2 1/1] eal: add API to get CPU socket ID
Randy L Tice
rtice at cisco.com
Tue Sep 15 17:05:07 CEST 2026
Add experimental rte_cpu_socket_id() so applications can map an OS
logical CPU ID to its NUMA socket without requiring an EAL lcore ID.
Existing public socket APIs depend on EAL lcore configuration or the
calling thread's EAL state. They do not cover code that needs to look
up topology by OS CPU ID, such as building socket memory policy.
Reuse the existing per-OS EAL CPU socket lookup internally, while
keeping the eal_cpu_socket_id() helper private to EAL.
Signed-off-by: Randy L Tice <rtice at cisco.com>
---
.mailmap | 1 +
doc/guides/rel_notes/release_26_11.rst | 3 +++
lib/eal/common/eal_common_lcore.c | 7 +++++++
lib/eal/include/rte_lcore.h | 18 ++++++++++++++++++
4 files changed, 29 insertions(+)
diff --git a/.mailmap b/.mailmap
index fcb3d1bb3f..2a8b54ea23 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1379,6 +1379,7 @@ Rakesh Kudurumalla <rkudurumalla at marvell.com> <rkudurumalla at caviumnetworks.com>
Ralf Hoffmann <ralf.hoffmann at allegro-packets.com>
Rami Rosen <ramirose at gmail.com> <rami.rosen at intel.com>
Rami Rosen <ramirose at gmail.com> <roszenrami at gmail.com>
+Randy L Tice <rtice at cisco.com>
Randy Schacher <stuart.schacher at broadcom.com>
Rani Sharoni <ranish at nvidia.com>
Ranjit Menon <ranjit.menon at intel.com>
diff --git a/doc/guides/rel_notes/release_26_11.rst b/doc/guides/rel_notes/release_26_11.rst
index 87c7e81bde..b26e9fae88 100644
--- a/doc/guides/rel_notes/release_26_11.rst
+++ b/doc/guides/rel_notes/release_26_11.rst
@@ -95,6 +95,9 @@ API Changes
Also, make sure to start the actual text at the margin.
=======================================================
+* eal: Added experimental ``rte_cpu_socket_id()`` to map an OS logical
+ CPU ID to the NUMA socket containing that CPU.
+
ABI Changes
-----------
diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c
index b5f59a6380..b38285d642 100644
--- a/lib/eal/common/eal_common_lcore.c
+++ b/lib/eal/common/eal_common_lcore.c
@@ -130,6 +130,13 @@ rte_lcore_to_socket_id(unsigned int lcore_id)
return lcore_config[lcore_id].numa_id;
}
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_cpu_socket_id, 26.11)
+unsigned int
+rte_cpu_socket_id(unsigned int cpu_id)
+{
+ return eal_cpu_socket_id(cpu_id);
+}
+
static int
socket_id_cmp(const void *a, const void *b)
{
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 10f965b4f0..e1e15581e8 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -160,6 +160,24 @@ rte_socket_id_by_idx(unsigned int idx);
unsigned int
rte_lcore_to_socket_id(unsigned int lcore_id);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Get the ID of the NUMA node for a CPU.
+ *
+ * This function maps an OS logical CPU ID to the NUMA node containing
+ * that CPU.
+ *
+ * @param cpu_id
+ * The OS logical CPU ID.
+ * @return
+ * The ID of cpu_id's NUMA node, or 0 if unavailable.
+ */
+__rte_experimental
+unsigned int
+rte_cpu_socket_id(unsigned int cpu_id);
+
/**
* Return the id of the lcore on a socket starting from zero.
*
--
2.35.6
More information about the dev
mailing list