Skip to contentSkip to conversation

eal: add CPU socket lookup API

PATCH Superseded Randy L Tice 3 participants 9 messages Sep 14 – Sep 18

lore
Share & tools
lore
#0 lore raw

cover eal: add CPU socket lookup API

Some applications need to derive socket-specific EAL configuration from OS CPU IDs before EAL lcore IDs are useful. One example is building socket memory policy from the CPUs available to the process.

Existing public socket APIs do not cover this directly. rte_socket_id() reports the calling thread socket, while rte_lcore_to_socket_id() requires an EAL lcore ID and uses EAL lcore configuration.

Add rte_cpu_socket_id() as a public API for mapping an OS logical CPU ID to the NUMA socket containing that CPU. The implementation reuses the existing per-OS EAL lookup internally, while keeping the eal_cpu_socket_id() helper private to EAL.

Randy L Tice (1):
eal: add API to get CPU socket ID

 .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(+)
Signature · 1 line
2.35.6
#1 lore raw

PATCH 1/1 eal: add API to get CPU socket ID

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.

---
 .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(+)
.mailmap +1 -0
index fcb3d1bb3f..2a8b54ea23 100644
@@ -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]>
doc/guides/rel_notes/release_26_11.rst +3 -0
index 87c7e81bde..6b037cdc73 100644
@@ -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
 -----------
lib/eal/common/eal_common_lcore.c +7 -0
index b5f59a6380..82927ce966 100644
@@ -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)
 {
lib/eal/include/rte_lcore.h +14 -0
index 10f965b4f0..f4fbe33eef 100644
@@ -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.
  *
Signature · 1 line
2.35.6
#2 lore raw

Re: [PATCH 1/1] eal: add API to get CPU socket ID

Quoted 7 lines · On Mon, 14 Sep 2026 15:28:14 -0400 Randy L Tice <[email protected]> wrote:

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.

Quoted 5 lines

Reuse the existing per-OS EAL CPU socket lookup internally, while keeping the eal_cpu_socket_id() helper private to EAL.

---

New API's should be marked as experimental, so there is no ABI contract. The return value of eal_cpu_socket_id() has no way with that signature to return error. If given a bogus cpu, that code returns 0.

New functions in DPDK need to have a matching test. Somewhere in the existing dpdk-test would be good.

There was a bigger patch series to give a full topology API to deal with more complex chip arch; but it seems to have stalled.

#3 lore raw

v2 cover eal: add CPU socket lookup API

In reply to Randy L Tice

Some applications need to derive socket-specific EAL configuration from OS CPU IDs before EAL lcore IDs are useful. One example is building socket memory policy from the CPUs available to the process.

Existing public socket APIs do not cover this directly. rte_socket_id() reports the calling thread socket, while rte_lcore_to_socket_id() requires an EAL lcore ID and uses EAL lcore configuration.

Add experimental rte_cpu_socket_id() as a public API for mapping an OS logical CPU ID to the NUMA socket containing that CPU. The implementation reuses the existing per-OS EAL lookup internally, while keeping the eal_cpu_socket_id() helper private to EAL.

v2:
- Mark rte_cpu_socket_id() experimental in the declaration, export macro, release note and commit message.

Randy L Tice (1):
eal: add API to get CPU socket ID

 .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(+)
Signature · 1 line
2.35.6
#4 lore raw

PATCH v2 1/1 eal: add API to get CPU socket ID

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.

---
 .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(+)
.mailmap +1 -0
index fcb3d1bb3f..2a8b54ea23 100644
@@ -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]>
doc/guides/rel_notes/release_26_11.rst +3 -0
index 87c7e81bde..b26e9fae88 100644
@@ -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
 -----------
lib/eal/common/eal_common_lcore.c +7 -0
index b5f59a6380..b38285d642 100644
@@ -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)
 {
lib/eal/include/rte_lcore.h +18 -0
index 10f965b4f0..e1e15581e8 100644
@@ -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.
  *
Signature · 1 line
2.35.6
#5 lore raw
In reply to Randy L Tice
Quoted 17 lines · Randy L Tice

Some applications need to derive socket-specific EAL configuration from OS CPU IDs before EAL lcore IDs are useful. One example is building socket memory policy from the CPUs available to the process.

Existing public socket APIs do not cover this directly. rte_socket_id() reports the calling thread socket, while rte_lcore_to_socket_id() requires an EAL lcore ID and uses EAL lcore configuration.

Add experimental rte_cpu_socket_id() as a public API for mapping an OS logical CPU ID to the NUMA socket containing that CPU. The implementation reuses the existing per-OS EAL lookup internally, while keeping the eal_cpu_socket_id() helper private to EAL.

v2:
- Mark rte_cpu_socket_id() experimental in the declaration, export macro, release note and commit message.

Quoted 9 lines

Randy L Tice (1):
eal: add API to get CPU socket ID

 .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(+)

I think this support is a good idea.

JFYI, something similar should be possible (or else easily added, I hope) if patchset [1] ever makes it into DPDK. One of the goals of that patchset is to have hardware information querying possible before initialization of EAL. This ties in with the overall goal of alternative init paths for DPDK, as having hardware querying available allows sanity checking of args as they are added, rather than just as EAL init time.

/Bruce

[1] https://patches.dpdk.org/project/dpdk/list/?series=39005

#6 lore raw

v3 cover eal: add CPU socket lookup API

In reply to Randy L Tice

Applications may need to build socket-specific EAL policy before they have an EAL lcore ID for each relevant CPU. Existing public APIs expose the current thread socket, socket IDs by EAL socket index, or sockets for EAL lcore IDs, but do not directly map an OS logical CPU ID to its NUMA socket.

Add experimental rte_cpu_socket_id() for that lookup while keeping the existing eal_cpu_socket_id() helper private to EAL.

v3:
- Return SOCKET_ID_ANY for invalid CPU IDs and document that behavior.

v2:
- Mark rte_cpu_socket_id() experimental in the declaration, export macro, release note and commit message.

Randy L Tice (1):
eal: add API to get CPU socket ID

 .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(+)
Signature · 1 line
2.35.6
#7 lore raw

PATCH v3 1/1 eal: add API to get CPU socket ID

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.

---
 .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(+)
.mailmap +1 -0
index fcb3d1bb3f..2a8b54ea23 100644
@@ -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]>
doc/guides/rel_notes/release_26_11.rst +3 -0
index 87c7e81bde..b26e9fae88 100644
@@ -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
 -----------
lib/eal/common/eal_common_lcore.c +11 -0
index b5f59a6380..1b6d77d8bc 100644
@@ -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)
 {
lib/eal/include/rte_lcore.h +19 -0
index 10f965b4f0..696ae9ec95 100644
@@ -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.
  *
Signature · 1 line
2.35.6
#8 lore raw

Re: [PATCH v3 1/1] eal: add API to get CPU socket ID

Quoted 7 lines · On Wed, 16 Sep 2026 10:55:16 -0400 Randy L Tice <[email protected]> wrote:

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.

Quoted 5 lines

Reuse the existing per-OS EAL CPU socket lookup internally, while keeping the eal_cpu_socket_id() helper private to EAL.

---

Applied to next-net. Put the release note in the New Features section