All of lore.kernel.org
 help / color / mirror / Atom feed
From: Randy L Tice <rtice@cisco.com>
To: dev@dpdk.org
Cc: Thomas Monjalon <thomas@monjalon.net>, Randy L Tice <rtice@cisco.com>
Subject: [PATCH v3 1/1] eal: add API to get CPU socket ID
Date: Wed, 16 Sep 2026 10:55:16 -0400	[thread overview]
Message-ID: <20260916145516.3-2-rtice@cisco.com> (raw)
In-Reply-To: <20260916145516.3-1-rtice@cisco.com>

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@cisco.com>
---
 .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 <rkudurumalla@marvell.com> <rkudurumalla@caviumnetworks.com>
 Ralf Hoffmann <ralf.hoffmann@allegro-packets.com>
 Rami Rosen <ramirose@gmail.com> <rami.rosen@intel.com>
 Rami Rosen <ramirose@gmail.com> <roszenrami@gmail.com>
+Randy L Tice <rtice@cisco.com>
 Randy Schacher <stuart.schacher@broadcom.com>
 Rani Sharoni <ranish@nvidia.com>
 Ranjit Menon <ranjit.menon@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..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	other threads:[~2026-09-16 14:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 19:28 [PATCH 0/1] eal: add CPU socket lookup API Randy L Tice
2026-09-14 19:28 ` [PATCH 1/1] eal: add API to get CPU socket ID Randy L Tice
2026-09-14 21:19   ` Stephen Hemminger
2026-09-15 15:05   ` [PATCH v2 0/1] eal: add CPU socket lookup API Randy L Tice
2026-09-15 15:05     ` [PATCH v2 1/1] eal: add API to get CPU socket ID Randy L Tice
2026-09-15 15:09     ` [PATCH v2 0/1] eal: add CPU socket lookup API Bruce Richardson
2026-09-16 14:55     ` [PATCH v3 " Randy L Tice
2026-09-16 14:55       ` Randy L Tice [this message]
2026-09-18 16:19         ` [PATCH v3 1/1] eal: add API to get CPU socket ID Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916145516.3-2-rtice@cisco.com \
    --to=rtice@cisco.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.