Add 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 | 7 +++++++ lib/eal/include/rte_lcore.h | 14 ++++++++++++++ 4 files changed, 25 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..6b037cdc73 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 ``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..82927ce966 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_SYMBOL(rte_cpu_socket_id) +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..f4fbe33eef 100644 --- a/lib/eal/include/rte_lcore.h +++ b/lib/eal/include/rte_lcore.h @@ -160,6 +160,20 @@ rte_socket_id_by_idx(unsigned int idx); unsigned int rte_lcore_to_socket_id(unsigned int lcore_id); +/** + * 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. + */ +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

