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 <[email protected]>
---
 .mailmap                               |  1 +
 doc/guides/rel_notes/release_26_11.rst |  3 +++
 lib/eal/common/eal_common_lcore.c      | 11 +++++++++++
 lib/eal/include/rte_lcore.h            | 19 +++++++++++++++++++
 4 files changed, 34 insertions(+)

diff --git a/.mailmap b/.mailmap
index fcb3d1bb3f..2a8b54ea23 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1379,6 +1379,7 @@ Rakesh Kudurumalla <[email protected]> 
<[email protected]>
 Ralf Hoffmann <[email protected]>
 Rami Rosen <[email protected]> <[email protected]>
 Rami Rosen <[email protected]> <[email protected]>
+Randy L Tice <[email protected]>
 Randy Schacher <[email protected]>
 Rani Sharoni <[email protected]>
 Ranjit Menon <[email protected]>
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..1b6d77d8bc 100644
--- a/lib/eal/common/eal_common_lcore.c
+++ b/lib/eal/common/eal_common_lcore.c
@@ -12,6 +12,7 @@
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <rte_log.h>
+#include <rte_memory.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <rte_telemetry.h>
 #endif
@@ -130,6 +131,16 @@ 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)
+{
+       if (eal_cpu_detected(cpu_id) == 0)
+               return (unsigned int)SOCKET_ID_ANY;
+
+       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..696ae9ec95 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -160,6 +160,25 @@ 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. If cpu_id does not identify a detected CPU, the
+ *   function returns SOCKET_ID_ANY.
+ * @return
+ *   The ID of cpu_id's NUMA node, or SOCKET_ID_ANY if cpu_id is not valid.
+ */
+__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

Reply via email to