Skip to contentSkip to conversation

Introduce Topology NUMA grouping for lcores

PATCH In review Vipin Varghese 8 participants 35 messages Nov 5, 2024 – Oct 14 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v4 cover Introduce Topology NUMA grouping for lcores

This patch introduces improvements for NUMA topology awareness in relation to DPDK logical cores. The goal is to expose API which allows users to select optimal logical cores for any application. These logical cores can be selected from various NUMA domains like CPU and I/O.

Change Summary:
- Introduces the concept of NUMA domain partitioning based on CPU and I/O topology.
- Adds support for grouping DPDK logical cores within the same Cache and I/O domain for improved locality.
- Implements topology detection and core grouping logic that distinguishes between the following NUMA configurations:
* CPU topology & I/O topology (e.g., AMD SoC EPYC, Intel Xeon SPR)
* CPU+I/O topology (e.g., Ampere One with SLC, Intel Xeon SPR with SNC)
- Enhances performance by minimizing lcore dispersion across tiles|compute package with different L2/L3 cache or IO domains.

Reason:
- Applications using DPDK libraries relies on consistent memory access.
- Lcores being closer to same NUMA domain as IO.
- Lcores sharing same cache.

Latency is minimized by using lcores that share the same NUMA topology. Memory access is optimized by utilizing cores within the same NUMA domain or tile. Cache coherence is preserved within the same shared cache domain, reducing the remote access from tile|compute package via snooping (local hit in either L2 or L3 within same NUMA domain).

Library dependency: hwloc

Topology Flags:
---------------
- RTE_LCORE_DOMAIN_L1: to group cores sharing same L1 cache
- RTE_LCORE_DOMAIN_SMT: same as RTE_LCORE_DOMAIN_L1
- RTE_LCORE_DOMAIN_L2: group cores sharing same L2 cache
- RTE_LCORE_DOMAIN_L3: group cores sharing same L3 cache
- RTE_LCORE_DOMAIN_L4: group cores sharing same L4 cache
- RTE_LCORE_DOMAIN_IO: group cores sharing same IO

< Function: Purpose >
---------------------
- rte_get_domain_count: get domain count based on Topology Flag
- rte_lcore_count_from_domain: get valid lcores count under each domain
- rte_get_lcore_in_domain: valid lcore id based on index
- rte_lcore_cpuset_in_domain: return valid cpuset based on index
- rte_lcore_is_main_in_domain: return true|false if main lcore is present
- rte_get_next_lcore_from_domain: next valid lcore within domain
- rte_get_next_lcore_from_next_domain: next valid lcore from next domain

Note:
1. Topology is NUMA grouping.
2. Domain is various sub-groups within a specific Topology.

Topology example: L1, L2, L3, L4, IO
Domian example: IO-A, IO-B

< MACRO: Purpose >
------------------
- RTE_LCORE_FOREACH_DOMAIN: iterate lcores from all domains
- RTE_LCORE_FOREACH_WORKER_DOMAIN: iterate worker lcores from all domains
- RTE_LCORE_FORN_NEXT_DOMAIN: iterate domain select n'th lcore
- RTE_LCORE_FORN_WORKER_NEXT_DOMAIN: iterate domain for worker n'th lcore.

Future work (after merge):
--------------------------
- dma-perf per IO NUMA
- eventdev per L3 NUMA
- pipeline per SMT|L3 NUMA
- distributor per L3 for Port-Queue
- l2fwd-power per SMT
- testpmd option for IO NUMA per port

Platform tested on:
-------------------
- INTEL(R) XEON(R) PLATINUM 8562Y+ (support IO numa 1 & 2)
- AMD EPYC 8534P (supports IO numa 1 & 2)
- AMD EPYC 9554 (supports IO numa 1, 2, 4)

Logs:
-----
1. INTEL(R) XEON(R) PLATINUM 8562Y+:
- SNC=1
Domain (IO): at index (0) there are 48 core, with (0) at index 0
- SNC=2
Domain (IO): at index (0) there are 24 core, with (0) at index 0 Domain (IO): at index (1) there are 24 core, with (12) at index 0

2. AMD EPYC 8534P:
- NPS=1:
Domain (IO): at index (0) there are 128 core, with (0) at index 0
- NPS=2:
Domain (IO): at index (0) there are 64 core, with (0) at index 0 Domain (IO): at index (1) there are 64 core, with (32) at index 0

Vipin Varghese (4):
eal/lcore: add topology based functions
test/lcore: enable tests for topology
doc: add topology grouping details
examples: update with lcore topology API

 app/test/test_lcores.c                        | 528 +++++++++++++
 config/meson.build                            |  18 +
 .../prog_guide/env_abstraction_layer.rst      |  22 +
 examples/helloworld/main.c                    | 154 +++-
 examples/l2fwd/main.c                         |  56 +-
 examples/skeleton/basicfwd.c                  |  22 +
 lib/eal/common/eal_common_lcore.c             | 714 ++++++++++++++++++
 lib/eal/common/eal_private.h                  |  58 ++
 lib/eal/freebsd/eal.c                         |  10 +
 lib/eal/include/rte_lcore.h                   | 209 +++++
 lib/eal/linux/eal.c                           |  11 +
 lib/eal/meson.build                           |   4 +
 lib/eal/version.map                           |  11 +
 lib/eal/windows/eal.c                         |  12 +
 14 files changed, 1819 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/4 eal/lcore: add topology based functions

Introduce topology aware lcore mapping into lcore API. With higher core density, more and more cores are categorized into various chiplets based on IO (memory and PCIe) and Last Level Cache (mainly L3).

Using hwloc library, the dpdk available lcores can be grouped into various groups nameley L1, L2, L3, L4 and IO. This patch introduces functions and MACRO that helps to identify such groups.

Internal API:
- get_domain_lcore_count;
- get_domain_lcore_mapping
- rte_eal_topology_init;
- rte_eal_topology_release;

External Experimental API:
- rte_get_domain_count;
- rte_get_lcore_in_domain;
- rte_get_next_lcore_from_domain;
- rte_get_next_lcore_from_next_domain;
- rte_lcore_count_from_domain;
- rte_lcore_cpuset_in_domain;
- rte_lcore_is_main_in_domain;

v4 changes:
- add internal API get_domain_lcore_count
- add external API rte_lcore_cpuset_in_domain
- add external API rte_lcore_is_main_in_domain
- remove malloc casting: Stephen Hemminger
- remove NULL check before free: Stephen Hemminger
- convert l3_count & io_count to uint16_t: Stephen Hemminger
- use rte_malloc for internal core_mapping: Stephen Hemminger
- extend to L4 cache: Morten Brørup
- add comment as place holder for enable cache-id: Morten Brørup

v2 changes:
- focuses on rte_lcore api for getting topology
- use hwloc instead of sysfs exploration - Mattias Rönnblom
- L1, L2 and IO domain mapping - Ferruh, Vipin
- new API marked experimental - Stephen Hemminger

---
 config/meson.build                |  18 +
 lib/eal/common/eal_common_lcore.c | 714 ++++++++++++++++++++++++++++++
 lib/eal/common/eal_private.h      |  58 +++
 lib/eal/freebsd/eal.c             |  10 +
 lib/eal/include/rte_lcore.h       | 209 +++++++++
 lib/eal/linux/eal.c               |  11 +
 lib/eal/meson.build               |   4 +
 lib/eal/version.map               |  11 +
 lib/eal/windows/eal.c             |  12 +
 9 files changed, 1047 insertions(+)
config/meson.build +18 -0
index 5095d2fbcb..42e4d28f8d 100644
@@ -240,6 +240,24 @@ if find_libnuma
     endif
 endif
 
+has_libhwloc = false
+find_libhwloc = true
+
+if meson.is_cross_build() and not meson.get_cross_property('hwloc', true)
+    # don't look for libhwloc if explicitly disabled in cross build
+    find_libhwloc = false
+endif
+
+if find_libhwloc
+    hwloc_dep = cc.find_library('hwloc', required: false)
+    if hwloc_dep.found() and cc.has_header('hwloc.h')
+        dpdk_conf.set10('RTE_HAS_LIBHWLOC', true)
+        has_libhwloc = true
+        add_project_link_arguments('-lhwloc', language: 'c')
+        dpdk_extra_ldflags += '-lhwloc'
+    endif
+endif
+
 has_libfdt = false
 fdt_dep = cc.find_library('fdt', required: false)
 if fdt_dep.found() and cc.has_header('fdt.h')
lib/eal/common/eal_common_lcore.c +714 -0

732 lines not on this page · raw message

lib/eal/common/eal_private.h +58 -0

79 lines not on this page · raw message

lib/eal/freebsd/eal.c +10 -0
index 1229230063..301f993748 100644
@@ -73,6 +73,8 @@ struct lcore_config lcore_config[RTE_MAX_LCORE];
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
+/* holds topology information */
+struct topology_config topo_cnfg;
 
 int
 eal_clean_runtime_dir(void)
@@ -912,6 +914,12 @@ rte_eal_init(int argc, char **argv)
 			return -1;
 	}
 
+	if (rte_eal_topology_init()) {
+		rte_eal_init_alert("Cannot invoke topology!!!");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	eal_mcfg_complete();
 
 	return fctret;
@@ -932,6 +940,8 @@ rte_eal_cleanup(void)
 
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+
+	rte_eal_topology_release();
 	rte_service_finalize();
 	rte_mp_channel_cleanup();
 	eal_bus_cleanup();
lib/eal/include/rte_lcore.h +209 -0

233 lines not on this page · raw message

lib/eal/linux/eal.c +11 -0
index 54577b7718..093f208319 100644
@@ -65,6 +65,9 @@
  * duration of the program, as we hold a write lock on it in the primary proc */
 static int mem_cfg_fd = -1;
 
+/* holds topology information */
+struct topology_config topo_cnfg;
+
 static struct flock wr_lock = {
 		.l_type = F_WRLCK,
 		.l_whence = SEEK_SET,
@@ -1311,6 +1314,12 @@ rte_eal_init(int argc, char **argv)
 			return -1;
 	}
 
+	if (rte_eal_topology_init()) {
+		rte_eal_init_alert("Cannot invoke topology!!!");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	eal_mcfg_complete();
 
 	return fctret;
@@ -1352,6 +1361,8 @@ rte_eal_cleanup(void)
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
+	rte_eal_topology_release();
+
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
 			internal_conf->hugepage_file.unlink_existing)
 		rte_memseg_walk(mark_freeable, NULL);
lib/eal/meson.build +4 -0
index e1d6c4cf17..690b95d5df 100644
@@ -31,3 +31,7 @@ endif
 if is_freebsd
     annotate_locks = false
 endif
+
+if has_libhwloc
+    dpdk_conf.set10('RTE_EAL_HWLOC_TOPOLOGY_PROBE', true)
+endif
lib/eal/version.map +11 -0
index 747331af60..a2f1fc1a6c 100644
@@ -397,6 +397,15 @@ EXPERIMENTAL {
 
 	# added in 24.11
 	rte_bitset_to_str;
+
+	# added in 25.03
+	rte_get_domain_count;
+	rte_get_lcore_in_domain;
+	rte_get_next_lcore_from_domain;
+	rte_get_next_lcore_from_next_domain;
+	rte_lcore_count_from_domain;
+	rte_lcore_cpuset_in_domain;
+	rte_lcore_is_main_in_domain;
 };
 
 INTERNAL {
@@ -406,6 +415,8 @@ INTERNAL {
 	rte_bus_unregister;
 	rte_eal_get_baseaddr;
 	rte_eal_parse_coremask;
+	rte_eal_topology_init;
+	rte_eal_topology_release;
 	rte_firmware_read;
 	rte_intr_allow_others;
 	rte_intr_cap_multiple;
lib/eal/windows/eal.c +12 -0
index 28b78a95a6..2edfc4128c 100644
@@ -40,6 +40,10 @@ static int mem_cfg_fd = -1;
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+/* holds topology information */
+struct topology_config topo_cnfg;
+
+
 /* Detect if we are a primary or a secondary process */
 enum rte_proc_type_t
 eal_proc_type_detect(void)
@@ -262,6 +266,8 @@ rte_eal_cleanup(void)
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
+	rte_eal_topology_release();
+
 	eal_intr_thread_cancel();
 	eal_mem_virt2iova_cleanup();
 	eal_bus_cleanup();
@@ -505,6 +511,12 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MAIN);
 	rte_eal_mp_wait_lcore();
 
+	if (rte_eal_topology_init()) {
+		rte_eal_init_alert("Cannot invoke topology!!!");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	eal_mcfg_complete();
 
 	return fctret;
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/4 test/lcore: enable tests for topology

In reply to Vipin Varghese

add functional test cases to validate topology supported lcore API.

v4 cahnges:
- add MACRO for triggering tests if topology is enabled.
- add test cases for
* rte_lcore_is_main_in_domain
* rte_lcore_cpuset_in_domain
* MACRO RTE_LCORE_FORN_NEXT_DOMAIN
* MACRO RTE_LCORE_FORN_WORKER_NEXT_DOMAIN

v3 changes:
- fix test check for RTE_LCORE_FOREACH_DOMAIN

---
 app/test/test_lcores.c | 528 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 528 insertions(+)
app/test/test_lcores.c +528 -0
index bd5c0dd94b..15a9417e66 100644
@@ -389,6 +389,513 @@ test_ctrl_thread(void)
 	return 0;
 }
 
+#ifdef RTE_EAL_HWLOC_TOPOLOGY_PROBE
+static int
+test_topology_macro(void)
+{
+	unsigned int total_lcores = 0;
+	unsigned int total_wrkr_lcores = 0;
+
+	unsigned int total_lcore_io = 0;
+	unsigned int total_lcore_l4 = 0;
+	unsigned int total_lcore_l3 = 0;
+	unsigned int total_lcore_l2 = 0;
+	unsigned int total_lcore_l1 = 0;
+
+	unsigned int total_wrkr_lcore_io = 0;
+	unsigned int total_wrkr_lcore_l4 = 0;
+	unsigned int total_wrkr_lcore_l3 = 0;
+	unsigned int total_wrkr_lcore_l2 = 0;
+	unsigned int total_wrkr_lcore_l1 = 0;
+
+	unsigned int lcore;
+
+	/* get topology core count */
+	lcore = -1;
+	RTE_LCORE_FOREACH(lcore)
+		total_lcores += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_WORKER(lcore)
+		total_wrkr_lcores += 1;
+
+	if ((total_wrkr_lcores + 1) != total_lcores) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FOREACH\n");
+		return -2;
+	}
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_DOMAIN(lcore, RTE_LCORE_DOMAIN_IO)
+		total_lcore_io += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_DOMAIN(lcore, RTE_LCORE_DOMAIN_L4)
+		total_lcore_l4 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_DOMAIN(lcore, RTE_LCORE_DOMAIN_L3)
+		total_lcore_l3 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_DOMAIN(lcore, RTE_LCORE_DOMAIN_L2)
+		total_lcore_l2 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_DOMAIN(lcore, RTE_LCORE_DOMAIN_L1)
+		total_lcore_l1 += 1;
+
+	printf("DBG: lcore count: default (%u), io (%u), l4 (%u), l3 (%u), l2 (%u), l1 (%u).\n",
+		total_lcores, total_lcore_io,
+		total_lcore_l4, total_lcore_l3, total_lcore_l2, total_lcore_l1);
+
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_WORKER_DOMAIN(lcore, RTE_LCORE_DOMAIN_IO)
+		total_wrkr_lcore_io += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_WORKER_DOMAIN(lcore, RTE_LCORE_DOMAIN_L4)
+		total_wrkr_lcore_l4 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_WORKER_DOMAIN(lcore, RTE_LCORE_DOMAIN_L3)
+		total_wrkr_lcore_l3 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_WORKER_DOMAIN(lcore, RTE_LCORE_DOMAIN_L2)
+		total_wrkr_lcore_l2 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FOREACH_WORKER_DOMAIN(lcore, RTE_LCORE_DOMAIN_L1)
+		total_wrkr_lcore_l1 += 1;
+
+	printf("DBG: worker lcore count: default (%u), io (%u), l4 (%u), l3 (%u), l2 (%u), l1 (%u).\n",
+		total_wrkr_lcores, total_wrkr_lcore_io,
+		total_wrkr_lcore_l4, total_wrkr_lcore_l3,
+		total_wrkr_lcore_l2, total_wrkr_lcore_l1);
+
+
+	if ((total_wrkr_lcore_io) > total_lcore_io) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FOREACH_DOMAIN for IO\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l4) > total_lcore_l4) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FOREACH_DOMAIN for L4\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l3) > total_lcore_l3) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FOREACH_DOMAIN for L3\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l2) > total_lcore_l2) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FOREACH_DOMAIN for L2\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l1) > total_lcore_l1) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FOREACH_DOMAIN for L1\n");
+		return -2;
+	}
+
+	total_lcore_io = 0;
+	total_lcore_l4 = 0;
+	total_lcore_l3 = 0;
+	total_lcore_l2 = 0;
+	total_lcore_l1 = 0;
+
+	lcore = -1;
+	RTE_LCORE_FORN_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_IO, 0)
+		total_lcore_io += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L4, 0)
+		total_lcore_l4 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L3, 0)
+		total_lcore_l3 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L2, 0)
+		total_lcore_l2 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L1, 0)
+		total_lcore_l1 += 1;
+
+	printf("DBG: macro domain lcore: default (%u), io (%u), l4 (%u), l3 (%u), l2 (%u), l1 (%u).\n",
+		total_lcores, total_lcore_io,
+		total_lcore_l4, total_lcore_l3, total_lcore_l2, total_lcore_l1);
+
+	total_wrkr_lcore_io = 0;
+	total_wrkr_lcore_l4 = 0;
+	total_wrkr_lcore_l3 = 0;
+	total_wrkr_lcore_l2 = 0;
+	total_wrkr_lcore_l1 = 0;
+
+	lcore = -1;
+	RTE_LCORE_FORN_WORKER_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_IO, 0)
+		total_wrkr_lcore_io += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_WORKER_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L4, 0)
+		total_wrkr_lcore_l4 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_WORKER_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L3, 0)
+		total_wrkr_lcore_l3 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_WORKER_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L2, 0)
+		total_wrkr_lcore_l2 += 1;
+
+	lcore = -1;
+	RTE_LCORE_FORN_WORKER_NEXT_DOMAIN(lcore, RTE_LCORE_DOMAIN_L1, 0)
+		total_wrkr_lcore_l1 += 1;
+
+	printf("DBG: macro next domain worker count: default (%u), io (%u), l4 (%u), l3 (%u), l2 (%u), l1 (%u).\n",
+		total_wrkr_lcores, total_wrkr_lcore_io,
+		total_wrkr_lcore_l4, total_wrkr_lcore_l3,
+		total_wrkr_lcore_l2, total_wrkr_lcore_l1);
+
+	if ((total_wrkr_lcore_io) > total_lcore_io) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FORN_NEXT_DOMAIN for IO\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l4) > total_lcore_l4) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FORN_NEXT_DOMAIN for L4\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l3) > total_lcore_l3) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FORN_NEXT_DOMAIN for L3\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l2) > total_lcore_l2) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FORN_NEXT_DOMAIN for L2\n");
+		return -2;
+	}
+
+	if ((total_wrkr_lcore_l1) > total_lcore_l1) {
+		printf("ERR: failed in MACRO for RTE_LCORE_FORN_NEXT_DOMAIN for L1\n");
+		return -2;
+	}
+	printf("INFO: lcore DOMAIN macro: success!\n");
+	return 0;
+}
+
+static int
+test_lcore_count_from_domain(void)
+{
+	unsigned int total_lcores = 0;
+	unsigned int total_lcore_io = 0;
+	unsigned int total_lcore_l4 = 0;
+	unsigned int total_lcore_l3 = 0;
+	unsigned int total_lcore_l2 = 0;
+	unsigned int total_lcore_l1 = 0;
+
+	unsigned int domain_count;
+	unsigned int i;
+
+	/* get topology core count */
+	total_lcores = rte_lcore_count();
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_IO);
+	for (i = 0; i < domain_count; i++)
+		total_lcore_io += rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_IO, i);
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L4);
+	for (i = 0; i < domain_count; i++)
+		total_lcore_l4 += rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L4, i);
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L3);
+	for (i = 0; i < domain_count; i++)
+		total_lcore_l3 += rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L3, i);
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L2);
+	for (i = 0; i < domain_count; i++)
+		total_lcore_l2 += rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L2, i);
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L1);
+	for (i = 0; i < domain_count; i++)
+		total_lcore_l1 += rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L1, i);
+
+	printf("DBG: lcore count: default (%u), io (%u), l4 (%u), l3 (%u), l2 (%u), l1 (%u).\n",
+		total_lcores, total_lcore_io,
+		total_lcore_l4, total_lcore_l3, total_lcore_l2, total_lcore_l1);
+
+	if ((total_lcore_l1 && (total_lcores != total_lcore_l1)) ||
+		(total_lcore_l2 && (total_lcores != total_lcore_l2)) ||
+		(total_lcore_l3 && (total_lcores != total_lcore_l3)) ||
+		(total_lcore_l4 && (total_lcores != total_lcore_l4)) ||
+		(total_lcore_io && (total_lcores != total_lcore_io))) {
+		printf("ERR: failed in domain API\n");
+		return -2;
+	}
+
+	printf("INFO: lcore count domain API: success\n");
+
+	return 0;
+}
+
+#ifdef RTE_HAS_CPUSET
+static int
+test_lcore_cpuset_from_domain(void)
+{
+	unsigned int domain_count;
+	uint16_t dmn_idx;
+	rte_cpuset_t cpu_set_list;
+
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_IO);
+
+	for (; dmn_idx < domain_count; dmn_idx++) {
+		cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_IO, dmn_idx);
+
+		for (uint16_t cpu_idx = 0; cpu_idx < RTE_MAX_LCORE; cpu_idx++) {
+			if (CPU_ISSET(cpu_idx, &cpu_set_list)) {
+				if (!rte_lcore_is_enabled(cpu_idx)) {
+					printf("ERR: lcore id: %u, shared from IO (%u) domain is not enabled!\n",
+						cpu_idx, dmn_idx);
+					return -1;
+				}
+			}
+		}
+	}
+
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L4);
+
+	for (; dmn_idx < domain_count; dmn_idx++) {
+		cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L4, dmn_idx);
+
+		for (uint16_t cpu_idx = 0; cpu_idx < RTE_MAX_LCORE; cpu_idx++) {
+			if (CPU_ISSET(cpu_idx, &cpu_set_list)) {
+				if (!rte_lcore_is_enabled(cpu_idx)) {
+					printf("ERR: lcore id: %u, shared from L4 (%u) domain is not enabled!\n",
+						cpu_idx, dmn_idx);
+					return -1;
+				}
+			}
+		}
+	}
+
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L3);
+
+	for (; dmn_idx < domain_count; dmn_idx++) {
+		cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L3, dmn_idx);
+
+		for (uint16_t cpu_idx = 0; cpu_idx < RTE_MAX_LCORE; cpu_idx++) {
+			if (CPU_ISSET(cpu_idx, &cpu_set_list)) {
+				if (!rte_lcore_is_enabled(cpu_idx)) {
+					printf("ERR: lcore id: %u, shared from L3 (%u) domain is not enabled!\n",
+						cpu_idx, dmn_idx);
+					return -1;
+				}
+			}
+		}
+	}
+
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L2);
+
+	for (; dmn_idx < domain_count; dmn_idx++) {
+		cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L2, dmn_idx);
+
+		for (uint16_t cpu_idx = 0; cpu_idx < RTE_MAX_LCORE; cpu_idx++) {
+			if (CPU_ISSET(cpu_idx, &cpu_set_list)) {
+				if (!rte_lcore_is_enabled(cpu_idx)) {
+					printf("ERR: lcore id: %u, shared from L2 (%u) domain is not enabled!\n",
+						cpu_idx, dmn_idx);
+					return -1;
+				}
+			}
+		}
+	}
+
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L1);
+
+	for (; dmn_idx < domain_count; dmn_idx++) {
+		cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L1, dmn_idx);
+
+		for (uint16_t cpu_idx = 0; cpu_idx < RTE_MAX_LCORE; cpu_idx++) {
+			if (CPU_ISSET(cpu_idx, &cpu_set_list)) {
+				if (!rte_lcore_is_enabled(cpu_idx)) {
+					printf("ERR: lcore id: %u, shared from IO (%u) domain is not enabled!\n",
+						cpu_idx, dmn_idx);
+					return -1;
+				}
+			}
+		}
+	}
+
+	cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L1, RTE_MAX_LCORE);
+	if (CPU_COUNT(&cpu_set_list)) {
+		printf("ERR: RTE_MAX_LCORE (%u) in L1 domain is enabled!\n", RTE_MAX_LCORE);
+		return -2;
+	}
+
+	cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L2, RTE_MAX_LCORE);
+	if (CPU_COUNT(&cpu_set_list)) {
+		printf("ERR: RTE_MAX_LCORE (%u) in L2 domain is enabled!\n", RTE_MAX_LCORE);
+		return -2;
+	}
+
+	cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_L3, RTE_MAX_LCORE);
+	if (CPU_COUNT(&cpu_set_list)) {
+		printf("ERR: RTE_MAX_LCORE (%u) in L3 domain is enabled!\n", RTE_MAX_LCORE);
+		return -2;
+	}
+
+	cpu_set_list = rte_lcore_cpuset_in_domain(RTE_LCORE_DOMAIN_IO, RTE_MAX_LCORE);
+	if (CPU_COUNT(&cpu_set_list)) {
+		printf("ERR: RTE_MAX_LCORE (%u) in IO domain is enabled!\n", RTE_MAX_LCORE);
+		return -2;
+	}
+
+	printf("INFO: cpuset_in_domain API: success!\n");
+	return 0;
+}
+#endif
+
+static int
+test_main_lcore_in_domain(void)
+{
+	bool main_lcore_found;
+	unsigned int domain_count;
+	uint16_t dmn_idx;
+
+	main_lcore_found = false;
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_IO);
+	for (; dmn_idx < domain_count; dmn_idx++) {
+		main_lcore_found = rte_lcore_is_main_in_domain(RTE_LCORE_DOMAIN_IO, dmn_idx);
+		if (main_lcore_found) {
+			printf("DBG: main lcore found in IO domain: %u\n", dmn_idx);
+			break;
+		}
+	}
+
+	if ((domain_count) && (main_lcore_found == false)) {
+		printf("ERR: main lcore is not found in any of the IO domain!\n");
+		return -1;
+	}
+
+	main_lcore_found = false;
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L4);
+	for (; dmn_idx  < domain_count; dmn_idx++) {
+		main_lcore_found = rte_lcore_is_main_in_domain(RTE_LCORE_DOMAIN_L4, dmn_idx);
+		if (main_lcore_found) {
+			printf("DBG: main lcore found in L4 domain: %u\n", dmn_idx);
+			break;
+		}
+	}
+
+	if ((domain_count) && (main_lcore_found == false)) {
+		printf("ERR: main lcore is not found in any of the L4 domain!\n");
+		return -1;
+	}
+
+	main_lcore_found = false;
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L3);
+	for (; dmn_idx  < domain_count; dmn_idx++) {
+		main_lcore_found = rte_lcore_is_main_in_domain(RTE_LCORE_DOMAIN_L3, dmn_idx);
+		if (main_lcore_found) {
+			printf("DBG: main lcore found in L3 domain: %u\n", dmn_idx);
+			break;
+		}
+	}
+
+	if ((domain_count) && (main_lcore_found == false)) {
+		printf("ERR: main lcore is not found in any of the L3 domain!\n");
+		return -1;
+	}
+
+	main_lcore_found = false;
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L2);
+	for (; dmn_idx  < domain_count; dmn_idx++) {
+		main_lcore_found = rte_lcore_is_main_in_domain(RTE_LCORE_DOMAIN_L2, dmn_idx);
+		if (main_lcore_found) {
+			printf("DBG: main lcore is found on the L2 domain: %u\n", dmn_idx);
+			break;
+		}
+	}
+
+	if ((domain_count) && (main_lcore_found == false)) {
+		printf("ERR: main lcore is not found in any of the L2 domain!\n");
+		return -1;
+	}
+
+	main_lcore_found = false;
+	dmn_idx = 0;
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L1);
+	for (; dmn_idx  < domain_count; dmn_idx++) {
+		main_lcore_found = rte_lcore_is_main_in_domain(RTE_LCORE_DOMAIN_L1, dmn_idx);
+		if (main_lcore_found) {
+			printf("DBG: main lcore is found on the L1 domain: %u\n", dmn_idx);
+			break;
+		}
+	}
+
+	if ((domain_count) && (main_lcore_found == false)) {
+		printf("ERR: main lcore is not found in any of the L1 domain!\n");
+		return -1;
+	}
+
+	printf("INFO: is_main_lcore_in_domain API: success!\n");
+	return 0;
+}
+
+static int
+test_lcore_from_domain_negative(void)
+{
+	unsigned int domain_count;
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_IO);
+	if ((domain_count) && (rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_IO, domain_count))) {
+		printf("ERR: domain API inconsistent for IO\n");
+		return -1;
+	}
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L4);
+	if ((domain_count) && (rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L4, domain_count))) {
+		printf("ERR: domain API inconsistent for L4\n");
+		return -1;
+	}
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L3);
+	if ((domain_count) && (rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L3, domain_count))) {
+		printf("ERR: domain API inconsistent for L3\n");
+		return -1;
+	}
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L2);
+	if ((domain_count) && (rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L2, domain_count))) {
+		printf("ERR: domain API inconsistent for L2\n");
+		return -1;
+	}
+
+	domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_L1);
+	if ((domain_count) && (rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_L1, domain_count))) {
+		printf("ERR: domain API inconsistent for L1\n");
+		return -1;
+	}
+
+	printf("INFO: lcore domain API: success!\n");
+	return 0;
+}
+#endif
+
 static int
 test_lcores(void)
 {
@@ -419,6 +926,27 @@ test_lcores(void)
 	if (test_ctrl_thread() < 0)
 		return TEST_FAILED;
 
+#ifdef RTE_EAL_HWLOC_TOPOLOGY_PROBE
+	printf("\nTopology test\n");
+
+	if (test_topology_macro() < 0)
+		return TEST_FAILED;
+
+	if (test_lcore_count_from_domain() < 0)
+		return TEST_FAILED;
+
+	if (test_lcore_from_domain_negative() < 0)
+		return TEST_FAILED;
+
+#ifdef RTE_HAS_CPUSET
+	if (test_lcore_cpuset_from_domain() < 0)
+		return TEST_FAILED;
+#endif
+
+	if (test_main_lcore_in_domain() < 0)
+		return TEST_FAILED;
+#endif
+
 	return TEST_SUCCESS;
 }
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/4 doc: add topology grouping details

In reply to Vipin Varghese

Add Topology section into eal_init documentation.

---
 .../prog_guide/env_abstraction_layer.rst      | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
doc/guides/prog_guide/env_abstraction_layer.rst +22 -0
index b9fac1839d..3ff6a17501 100644
@@ -1188,3 +1188,25 @@ will not be deallocated.
 
 Any successful deallocation event will trigger a callback, for which user
 applications and other DPDK subsystems can register.
+
+Topology
+--------
+
+During `rte_eal_init`, an internal topology structure is created to group DPDK enabled
+lcores into various topology. Using HWLOC library, lcores are categorized into multiple
+domains based on topology groups such as
+
+*   L1 cache
+*   L2 cache
+*   L3 cache
+*   L4 cache
+*   IO
+
+Using `rte_lcore_` extended API, user can retrieve lcores from groups using topology flag and
+domain index. Refer to the API documentation for details.
+
+.. note::
+
+    Topology API are tested on HWLOC library version `2.7.0`.
+    In absence of HWLOC library, initialization of topology objects is skipped.
+    For cross compile, please ensure appropriate path for `pkg-config` is enabled.
Signature · 1 line
2.34.1
#4 lore raw

PATCH v4 4/4 examples: update with lcore topology API

In reply to Vipin Varghese

Enhance example code to allow topology based lcores API, while retaining default behaviour.

- helloworld: allow lcoes to send hello to lcores in selected topology.
- l2fwd: allow use of IO lcores topology.
- skeleton: choose the lcore from IO topology which has more ports.

v4 changes:
- cross compilation failure on ARM: Pavan Nikhilesh Bhagavatula
- update helloworld for L4

v3 changes:
- fix typo from SE_NO_TOPOLOGY to USE_NO_TOPOLOGY

---
 examples/helloworld/main.c   | 154 ++++++++++++++++++++++++++++++++++-
 examples/l2fwd/main.c        |  56 +++++++++++--
 examples/skeleton/basicfwd.c |  22 +++++
 3 files changed, 222 insertions(+), 10 deletions(-)
examples/helloworld/main.c +152 -2
index af509138da..f39db532d9 100644
@@ -5,8 +5,10 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <sys/queue.h>
+#include <getopt.h>
 
 #include <rte_memory.h>
 #include <rte_launch.h>
@@ -14,6 +16,14 @@
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
 #include <rte_debug.h>
+#include <rte_log.h>
+
+#define RTE_LOGTYPE_HELLOWORLD RTE_LOGTYPE_USER1
+#define USE_NO_TOPOLOGY 0xffff
+
+static uint16_t topo_sel = USE_NO_TOPOLOGY;
+/* lcore selector based on Topology */
+static const char short_options[] = "T:";
 
 /* Launch a function on lcore. 8< */
 static int
@@ -21,11 +31,119 @@ lcore_hello(__rte_unused void *arg)
 {
 	unsigned lcore_id;
 	lcore_id = rte_lcore_id();
+
 	printf("hello from core %u\n", lcore_id);
 	return 0;
 }
+
+static int
+send_lcore_hello(__rte_unused void *arg)
+{
+	unsigned int lcore_id;
+	uint16_t send_lcore_id;
+	uint16_t send_count = 0;
+
+	lcore_id = rte_lcore_id();
+
+	send_lcore_id = rte_get_next_lcore_from_domain(lcore_id, false, true, topo_sel);
+
+	while ((send_lcore_id != RTE_MAX_LCORE) && (lcore_id != send_lcore_id)) {
+		printf("hello from lcore %3u to lcore %3u\n",
+			lcore_id, send_lcore_id);
+
+		send_lcore_id = rte_get_next_lcore_from_domain(send_lcore_id,
+				false, true, topo_sel);
+		send_count += 1;
+	}
+
+	if (send_count == 0)
+		printf("for %3u lcore; there are no lcore in (%s) domain!!!\n",
+			lcore_id,
+			(topo_sel == RTE_LCORE_DOMAIN_L1) ? "L1" :
+			(topo_sel == RTE_LCORE_DOMAIN_L2) ? "L2" :
+			(topo_sel == RTE_LCORE_DOMAIN_L3) ? "L3" :
+			(topo_sel == RTE_LCORE_DOMAIN_L4) ? "L4" : "IO");
+
+	return 0;
+}
 /* >8 End of launching function on lcore. */
 
+/* display usage. 8< */
+static void
+helloworld_usage(const char *prgname)
+{
+	printf("%s [EAL options] -- [-T TOPO]\n"
+		"  -T TOPO: choose topology to send hello to cores\n"
+		"	- 0: sharing IO\n"
+		"	- 1: sharing L1\n"
+		"	- 2: sharing L2\n"
+		"	- 3: sharing L3\n"
+		"	- 4: sharing L4\n\n",
+		prgname);
+}
+
+static unsigned int
+parse_topology(const char *q_arg)
+{
+	char *end = NULL;
+	unsigned long n;
+
+	/* parse the topology option */
+	n = strtoul(q_arg, &end, 10);
+
+	if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
+		return 0;
+
+	if (n > 4)
+		return USE_NO_TOPOLOGY;
+
+	n = (n == 0) ? RTE_LCORE_DOMAIN_IO :
+		(n == 1) ? RTE_LCORE_DOMAIN_L1 :
+		(n == 2) ? RTE_LCORE_DOMAIN_L2 :
+		(n == 3) ? RTE_LCORE_DOMAIN_L3 : RTE_LCORE_DOMAIN_L4;
+
+	return n;
+}
+
+/* Parse the argument given in the command line of the application */
+static int
+helloworld_parse_args(int argc, char **argv)
+{
+	int opt, ret;
+	char **argvopt = argv;
+	int option_index;
+	char *prgname = argv[0];
+	while ((opt = getopt_long(argc, argvopt, short_options,
+				NULL, &option_index)) != EOF) {
+		switch (opt) {
+		/* Topology selection */
+		case 'T':
+			topo_sel = parse_topology(optarg);
+			if (topo_sel == USE_NO_TOPOLOGY) {
+				helloworld_usage(prgname);
+				rte_exit(EXIT_FAILURE, "Invalid Topology selection\n");
+			}
+
+			RTE_LOG(DEBUG, HELLOWORLD, "USR selects (%s) domain cores!\n",
+				(topo_sel == RTE_LCORE_DOMAIN_L1) ? "L1" :
+				(topo_sel == RTE_LCORE_DOMAIN_L2) ? "L2" :
+				(topo_sel == RTE_LCORE_DOMAIN_L3) ? "L3" :
+				(topo_sel == RTE_LCORE_DOMAIN_L4) ? "L4" : "IO");
+
+			ret = 0;
+			break;
+		default:
+			helloworld_usage(prgname);
+			return -1;
+		}
+	}
+	if (optind >= 0)
+		argv[optind-1] = prgname;
+	ret = optind-1;
+	optind = 1; /* reset getopt lib */
+	return ret;
+}
+
 /* Initialization of Environment Abstraction Layer (EAL). 8< */
 int
 main(int argc, char **argv)
@@ -38,15 +156,47 @@ main(int argc, char **argv)
 		rte_panic("Cannot init EAL\n");
 	/* >8 End of initialization of Environment Abstraction Layer */
 
+	argc -= ret;
+	argv += ret;
+
+	ret = helloworld_parse_args(argc, argv);
+	if (ret < 0)
+		rte_exit(EXIT_FAILURE, "Invalid arguments\n");
+
+	if (topo_sel != USE_NO_TOPOLOGY) {
+		uint16_t domain_count = rte_get_domain_count(topo_sel);
+
+		RTE_LOG(DEBUG, HELLOWORLD, "selected Domain (%s)\n",
+			(topo_sel == RTE_LCORE_DOMAIN_L1) ? "L1" :
+			(topo_sel == RTE_LCORE_DOMAIN_L2) ? "L2" :
+			(topo_sel == RTE_LCORE_DOMAIN_L3) ? "L3" : "IO");
+
+		for (int i = 0; i < domain_count; i++) {
+			uint16_t domain_lcore_count = rte_lcore_count_from_domain(topo_sel, i);
+			uint16_t domain_lcore = rte_get_lcore_in_domain(topo_sel, i, 0);
+
+			if (domain_lcore_count)
+				RTE_LOG(DEBUG, HELLOWORLD, "at index (%u), %u cores, lcore (%u) at index 0\n",
+					i,
+					domain_lcore_count,
+					domain_lcore);
+		}
+	}
+
 	/* Launches the function on each lcore. 8< */
 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
 		/* Simpler equivalent. 8< */
-		rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
+		rte_eal_remote_launch((topo_sel == USE_NO_TOPOLOGY) ?
+					lcore_hello : send_lcore_hello, NULL, lcore_id);
 		/* >8 End of simpler equivalent. */
 	}
 
 	/* call it on main lcore too */
-	lcore_hello(NULL);
+	if (topo_sel == USE_NO_TOPOLOGY)
+		lcore_hello(NULL);
+	else
+		send_lcore_hello(NULL);
+
 	/* >8 End of launching the function on each lcore. */
 
 	rte_eal_mp_wait_lcore();
examples/l2fwd/main.c +48 -8

97 lines not on this page · raw message

examples/skeleton/basicfwd.c +22 -0
index 133293cf15..65faf46e16 100644
@@ -176,6 +176,11 @@ main(int argc, char *argv[])
 	unsigned nb_ports;
 	uint16_t portid;
 
+	uint16_t ports_socket_domain[RTE_MAX_ETHPORTS] = {0};
+	uint16_t sel_io_socket = 0;
+	uint16_t sel_io_indx = 0;
+	uint16_t core_count_from_io = 0;
+
 	/* Initializion the Environment Abstraction Layer (EAL). 8< */
 	int ret = rte_eal_init(argc, argv);
 	if (ret < 0)
@@ -190,6 +195,20 @@ main(int argc, char *argv[])
 	if (nb_ports < 2 || (nb_ports & 1))
 		rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");
 
+	/* get the socekt of each port */
+	RTE_ETH_FOREACH_DEV(portid) {
+		ports_socket_domain[rte_eth_dev_socket_id(portid)] += 1;
+
+		if (ports_socket_domain[rte_eth_dev_socket_id(portid)] > sel_io_socket) {
+			sel_io_socket = ports_socket_domain[rte_eth_dev_socket_id(portid)];
+			sel_io_indx = rte_eth_dev_socket_id(portid);
+		}
+	}
+
+	core_count_from_io = rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_IO, sel_io_indx);
+	if (core_count_from_io == 0)
+		printf("\nWARNING: select main_lcore from IO domain (%u)\n", sel_io_indx);
+
 	/* Creates a new mempool in memory to hold the mbufs. */
 
 	/* Allocates mempool to hold the mbufs. 8< */
@@ -210,6 +229,9 @@ main(int argc, char *argv[])
 	if (rte_lcore_count() > 1)
 		printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");
 
+	if (rte_lcore_is_main_in_domain(RTE_LCORE_DOMAIN_IO, sel_io_indx) == false)
+		printf("\nWARNING: please use lcore from IO domain %u.\n", sel_io_indx);
+
 	/* Call lcore_main on the main core only. Called on single lcore. 8< */
 	lcore_main();
 	/* >8 End of called on single lcore. */
Signature · 1 line
2.34.1
#5 lore raw
In reply to Vipin Varghese

[AMD Official Use Only - AMD Internal Distribution Only]

Adding Thomas and Ajit to the loop.

Hi Ajit, we have been using the patch series for identifying the topology and getting l3 cache id for populating the steering tag for Device Specific Model & MSI-x driven af-xdp for the experimental STAG firmware on Thor.

Hence current use of topology library helps in
1. workload placement in same Cache or IO domain
2. populating id for MSIx or Device specific model for steering tags.

Thomas and Ajith can we get some help to get this mainline too?

Quoted 138 lines

-----Original Message-----
From: Vipin Varghese <[email protected]>
Sent: Tuesday, November 5, 2024 3:59 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v4 0/4] Introduce Topology NUMA grouping for lcores

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

This patch introduces improvements for NUMA topology awareness in relation to DPDK logical cores. The goal is to expose API which allows users to select optimal logical cores for any application. These logical cores can be selected from various NUMA domains like CPU and I/O.

Change Summary:
- Introduces the concept of NUMA domain partitioning based on CPU and I/O topology.
- Adds support for grouping DPDK logical cores within the same Cache and I/O domain for improved locality.
- Implements topology detection and core grouping logic that distinguishes between the following NUMA configurations:
* CPU topology & I/O topology (e.g., AMD SoC EPYC, Intel Xeon SPR)
* CPU+I/O topology (e.g., Ampere One with SLC, Intel Xeon SPR with SNC)
- Enhances performance by minimizing lcore dispersion across tiles|compute package with different L2/L3 cache or IO domains.

Reason:
- Applications using DPDK libraries relies on consistent memory access.
- Lcores being closer to same NUMA domain as IO.
- Lcores sharing same cache.

Latency is minimized by using lcores that share the same NUMA topology. Memory access is optimized by utilizing cores within the same NUMA domain or tile. Cache coherence is preserved within the same shared cache domain, reducing the remote access from tile|compute package via snooping (local hit in either L2 or L3 within same NUMA domain).

Library dependency: hwloc

Topology Flags:
---------------
- RTE_LCORE_DOMAIN_L1: to group cores sharing same L1 cache
- RTE_LCORE_DOMAIN_SMT: same as RTE_LCORE_DOMAIN_L1
- RTE_LCORE_DOMAIN_L2: group cores sharing same L2 cache
- RTE_LCORE_DOMAIN_L3: group cores sharing same L3 cache
- RTE_LCORE_DOMAIN_L4: group cores sharing same L4 cache
- RTE_LCORE_DOMAIN_IO: group cores sharing same IO

< Function: Purpose >
---------------------
- rte_get_domain_count: get domain count based on Topology Flag
- rte_lcore_count_from_domain: get valid lcores count under each domain
- rte_get_lcore_in_domain: valid lcore id based on index
- rte_lcore_cpuset_in_domain: return valid cpuset based on index
- rte_lcore_is_main_in_domain: return true|false if main lcore is present
- rte_get_next_lcore_from_domain: next valid lcore within domain
- rte_get_next_lcore_from_next_domain: next valid lcore from next domain

Note:
1. Topology is NUMA grouping.
2. Domain is various sub-groups within a specific Topology.

Topology example: L1, L2, L3, L4, IO
Domian example: IO-A, IO-B

< MACRO: Purpose >
------------------
- RTE_LCORE_FOREACH_DOMAIN: iterate lcores from all domains
- RTE_LCORE_FOREACH_WORKER_DOMAIN: iterate worker lcores from all
domains
- RTE_LCORE_FORN_NEXT_DOMAIN: iterate domain select n'th lcore
- RTE_LCORE_FORN_WORKER_NEXT_DOMAIN: iterate domain for worker n'th
lcore.

Future work (after merge):
--------------------------
- dma-perf per IO NUMA
- eventdev per L3 NUMA
- pipeline per SMT|L3 NUMA
- distributor per L3 for Port-Queue
- l2fwd-power per SMT
- testpmd option for IO NUMA per port

Platform tested on:
-------------------
- INTEL(R) XEON(R) PLATINUM 8562Y+ (support IO numa 1 & 2)
- AMD EPYC 8534P (supports IO numa 1 & 2)
- AMD EPYC 9554 (supports IO numa 1, 2, 4)

Logs:
-----
1. INTEL(R) XEON(R) PLATINUM 8562Y+:
- SNC=1
Domain (IO): at index (0) there are 48 core, with (0) at index 0
- SNC=2
Domain (IO): at index (0) there are 24 core, with (0) at index 0 Domain (IO): at index (1) there are 24 core, with (12) at index 0

2. AMD EPYC 8534P:
- NPS=1:
Domain (IO): at index (0) there are 128 core, with (0) at index 0
- NPS=2:
Domain (IO): at index (0) there are 64 core, with (0) at index 0 Domain (IO): at index (1) there are 64 core, with (32) at index 0

Vipin Varghese (4):
eal/lcore: add topology based functions
test/lcore: enable tests for topology
doc: add topology grouping details
examples: update with lcore topology API

 app/test/test_lcores.c                        | 528 +++++++++++++
 config/meson.build                            |  18 +
 .../prog_guide/env_abstraction_layer.rst      |  22 +
 examples/helloworld/main.c                    | 154 +++-
 examples/l2fwd/main.c                         |  56 +-
 examples/skeleton/basicfwd.c                  |  22 +
 lib/eal/common/eal_common_lcore.c             | 714 ++++++++++++++++++
 lib/eal/common/eal_private.h                  |  58 ++
 lib/eal/freebsd/eal.c                         |  10 +
 lib/eal/include/rte_lcore.h                   | 209 +++++
 lib/eal/linux/eal.c                           |  11 +
 lib/eal/meson.build                           |   4 +
 lib/eal/version.map                           |  11 +
 lib/eal/windows/eal.c                         |  12 +
 14 files changed, 1819 insertions(+), 10 deletions(-)

--
2.34.1

#6 lore raw

13/02/2025 04:09, Varghese, Vipin:

Quoted 11 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Adding Thomas and Ajit to the loop.

Hi Ajit, we have been using the patch series for identifying the topology and getting l3 cache id for populating the steering tag for Device Specific Model & MSI-x driven af-xdp for the experimental STAG firmware on Thor.

Hence current use of topology library helps in
1. workload placement in same Cache or IO domain
2. populating id for MSIx or Device specific model for steering tags.

Thomas and Ajith can we get some help to get this mainline too?

Yes, sorry the review discussions did not start.
It has been forgotten.

You could rebase a v2 to make it more visible.

Minor note: the changelog should be after --- in the commit log.

#7 lore raw
Quoted 4 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, 13 February 2025 09.34

13/02/2025 04:09, Varghese, Vipin:

Quoted 8 lines
Quoted 5 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Adding Thomas and Ajit to the loop.

Hi Ajit, we have been using the patch series for identifying the

topology and getting l3 cache id for populating the steering tag for Device Specific Model & MSI-x driven af-xdp for the experimental STAG firmware on Thor.

Excellent. A real life example use case helps the review process a lot!

Quoted 9 lines
Quoted 6 lines

Hence current use of topology library helps in
1. workload placement in same Cache or IO domain
2. populating id for MSIx or Device specific model for steering tags.

Thomas and Ajith can we get some help to get this mainline too?

Yes, sorry the review discussions did not start.
It has been forgotten.

I think the topology/domain API in the EAL should be co-designed with the steering tag API in the ethdev library, so the design can be reviewed/discussed in its entirety.

To help the review discussion, please consider describing the following:
Which APIs are for slow path, and which are for fast path?
Which APIs are "must have", i.e. core to making it work at all, and which APIs are "nice to have", i.e. support APIs to ease use of the new features?

I haven't looked at the hwloc library's API; but I guess these new EAL functions are closely related. Is it a thin wrapper around the hwloc library, or is it very different?

#8 lore raw

[Public]

Hi Morten,

snipped

Quoted 8 lines
Quoted 8 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, 13 February 2025 09.34

13/02/2025 04:09, Varghese, Vipin:

Quoted 2 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Adding Thomas and Ajit to the loop.

Hi Ajit, we have been using the patch series for identifying the

topology and getting l3 cache id for populating the steering tag for Device Specific Model & MSI-x driven af-xdp for the experimental STAG firmware on Thor.

Excellent. A real life example use case helps the review process a lot!

Steering tag is one of the examples or uses, as shared in the current patch series we make use of these for other examples too. Eventdev, pkt-distributor and graph nodes are also in works to exploit L2|L3 cache local coherency too.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Hence current use of topology library helps in 1. workload placement in same Cache or IO domain 2. populating id for MSIx or Device specific model for steering tags.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thomas and Ajith can we get some help to get this mainline too?

Yes, sorry the review discussions did not start.
It has been forgotten.

I think the topology/domain API in the EAL should be co-designed with the steering tag API in the ethdev library, so the design can be reviewed/discussed in its entirety.

As shared in the discussion, we have been exploring simplified approach for steering tags, namely

1. pci-dev args (crude way)
2. flow api for RX (experimental way)

Based on the platform (in case of AMD EPYC, these are translated to L3 id + 1)

We do agree rte_ethdev library can use topology API. Current topology API are designed to be made independent from steering tags, as other examples do make use of the same.

Quoted 5 lines

To help the review discussion, please consider describing the following:
Which APIs are for slow path, and which are for fast path?
Which APIs are "must have", i.e. core to making it work at all, and which APIs are "nice to have", i.e. support APIs to ease use of the new features?

Yes, will try to do the same in updated version. For Slow and Fast path API I might need some help, as I was under the impression current behavior is same rte_lcore (invoked at setup and before remote launch). But will check again.

Quoted 3 lines

I haven't looked at the hwloc library's API; but I guess these new EAL functions are closely related. Is it a thin wrapper around the hwloc library, or is it very different?

This is very thin wrapper on top of hwloc library only. But with DPDK RTE_MAX_LCORE & RTE_NUMA boundary check and population.

#9 lore raw
Quoted 68 lines

From: Varghese, Vipin [mailto:[email protected]]
Sent: Monday, 3 March 2025 10.06

[Public]

Hi Morten,

snipped

Quoted 11 lines
Quoted 11 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, 13 February 2025 09.34

13/02/2025 04:09, Varghese, Vipin:

Quoted 5 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Adding Thomas and Ajit to the loop.

Hi Ajit, we have been using the patch series for identifying the

topology and getting l3 cache id for populating the steering tag

for

Quoted 1 line
Quoted 1 line

Device Specific Model & MSI-x driven af-xdp for the experimental

STAG

Quoted 3 lines
Quoted 1 line

firmware on Thor.

Excellent. A real life example use case helps the review process a

lot!

Steering tag is one of the examples or uses, as shared in the current patch series we make use of these for other examples too. Eventdev, pkt-distributor and graph nodes are also in works to exploit L2|L3 cache local coherency too.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hence current use of topology library helps in 1. workload

placement

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

in same Cache or IO domain 2. populating id for MSIx or Device specific model for steering tags.

Thomas and Ajith can we get some help to get this mainline too?

Yes, sorry the review discussions did not start.
It has been forgotten.

I think the topology/domain API in the EAL should be co-designed with

the steering

Quoted 1 line

tag API in the ethdev library, so the design can be

reviewed/discussed in its entirety.

As shared in the discussion, we have been exploring simplified approach for steering tags, namely

1. pci-dev args (crude way)
2. flow api for RX (experimental way)

Based on the platform (in case of AMD EPYC, these are translated to L3 id + 1)

We do agree rte_ethdev library can use topology API. Current topology API are designed to be made independent from steering tags, as other examples do make use of the same.

Quoted 2 lines

To help the review discussion, please consider describing the

following:

Quoted 2 lines

Which APIs are for slow path, and which are for fast path? Which APIs are "must have", i.e. core to making it work at all, and

Quoted 7 lines

which APIs are

Quoted 1 line

"nice to have", i.e. support APIs to ease use of the new features?

Yes, will try to do the same in updated version. For Slow and Fast path API I might need some help, as I was under the impression current behavior is same rte_lcore (invoked at setup and before remote launch). But will check again.

Probably they are all used for configuration only, and thus all slow path; but if there are any fast path APIs, they should be highlighted as such.

Quoted 8 lines
Quoted 3 lines

I haven't looked at the hwloc library's API; but I guess these new

EAL functions are

Quoted 1 line

closely related. Is it a thin wrapper around the hwloc library, or is

it very different?
This is very thin wrapper on top of hwloc library only. But with DPDK RTE_MAX_LCORE & RTE_NUMA boundary check and population.

OK. The hwloc library is portable across Linux, BSD and Windows, which is great!

Please also describe the benefits of using this DPDK library, compared to directly using the hwloc library.

#10 lore raw
Quoted 69 lines · Morten Brørup
Quoted 69 lines

From: Varghese, Vipin [mailto:[email protected]]
Sent: Monday, 3 March 2025 10.06

[Public]

Hi Morten,

snipped

Quoted 11 lines
Quoted 11 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, 13 February 2025 09.34

13/02/2025 04:09, Varghese, Vipin:

Quoted 5 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Adding Thomas and Ajit to the loop.

Hi Ajit, we have been using the patch series for identifying the

topology and getting l3 cache id for populating the steering tag

for

Quoted 1 line
Quoted 1 line

Device Specific Model & MSI-x driven af-xdp for the experimental

STAG

Quoted 3 lines
Quoted 1 line

firmware on Thor.

Excellent. A real life example use case helps the review process a

lot!

Steering tag is one of the examples or uses, as shared in the current patch series we make use of these for other examples too. Eventdev, pkt-distributor and graph nodes are also in works to exploit L2|L3 cache local coherency too.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hence current use of topology library helps in 1. workload

placement

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

in same Cache or IO domain 2. populating id for MSIx or Device specific model for steering tags.

Thomas and Ajith can we get some help to get this mainline too?

Yes, sorry the review discussions did not start.
It has been forgotten.

I think the topology/domain API in the EAL should be co-designed with

the steering

Quoted 1 line

tag API in the ethdev library, so the design can be

reviewed/discussed in its entirety.

As shared in the discussion, we have been exploring simplified approach for steering tags, namely

1. pci-dev args (crude way)
2. flow api for RX (experimental way)

Based on the platform (in case of AMD EPYC, these are translated to L3 id + 1)

We do agree rte_ethdev library can use topology API. Current topology API are designed to be made independent from steering tags, as other examples do make use of the same.

Quoted 2 lines

To help the review discussion, please consider describing the

following:

Quoted 2 lines

Which APIs are for slow path, and which are for fast path? Which APIs are "must have", i.e. core to making it work at all, and

which APIs are

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

"nice to have", i.e. support APIs to ease use of the new features?

Yes, will try to do the same in updated version. For Slow and Fast path API I might need some help, as I was under the impression current behavior is same rte_lcore (invoked at setup and before remote launch). But will check again.

Probably they are all used for configuration only, and thus all slow path; but if there are any fast path APIs, they should be highlighted as such.

Preferably, software work schedulers like DSW should be able to read topology information during run-time/steady-state operation. If topology APIs are slow or non-MT-safe, they will need to build up their own data structures for such information (which is not crazy idea, but leads to duplication).

I didn't follow the hwloc discussions, so I may lack some context for this discussion.

Quoted 13 lines
Quoted 8 lines
Quoted 3 lines

I haven't looked at the hwloc library's API; but I guess these new

EAL functions are

Quoted 1 line

closely related. Is it a thin wrapper around the hwloc library, or is

it very different?
This is very thin wrapper on top of hwloc library only. But with DPDK RTE_MAX_LCORE & RTE_NUMA boundary check and population.

OK. The hwloc library is portable across Linux, BSD and Windows, which is great!

Please also describe the benefits of using this DPDK library, compared to directly using the hwloc library.

#11 lore raw
In reply to Thomas Monjalon

[Public]

Hi Thomas

snipped

Quoted 7 lines
Quoted 2 lines

Thomas and Ajith can we get some help to get this mainline too?

Yes, sorry the review discussions did not start.
It has been forgotten.

You could rebase a v2 to make it more visible.

Sure will do this week.

Quoted 3 lines

Minor note: the changelog should be after --- in the commit log.

#12 lore raw
In reply to Vipin Varghese

Hello Vipin and others,

please, will there be any progress or update on this series?

I successfully tested those changes on our Intel and AMD machines and would like to use it in production soon.

The API is a little bit unintuitive, at least for me, but I successfully integrated into our software.

I am missing a clear relation to the NUMA socket approach used in DPDK. E.g. I would like to be able to easily walk over a list of lcores from a specific NUMA node grouped by L3 domain. Yes, there is the RTE_LCORE_DOMAIN_IO, but would it always match the appropriate socket IDs?

Also, I do not clearly understand what is the purpose of using domain selector like:

RTE_LCORE_DOMAIN_L1 | RTE_LCORE_DOMAIN_L2

or even:

RTE_LCORE_DOMAIN_L3 | RTE_LCORE_DOMAIN_L2

the documentation does not explain this. I could not spot any kind of grouping that would help me in any way. Some "best practices" examples would be nice to have to understand the intentions better.

I found a little catch when running DPDK with more lcores than there are physical or SMT CPU cores. This happens when using e.g. an option like --lcores=(0-15)@(0-1). The results from the topology API would not match the lcores because hwloc is not aware of the lcores concept. This might be mentioned somewhere.

Anyway, I really appreciate this work and would like to see it upstream. Especially for AMD machines, some framework like this is a must.

Kind regards,
Jan

Quoted 131 lines · On Tue, 5 Nov 2024 15:58:45 +0530 Vipin Varghese <[email protected]> wrote:

This patch introduces improvements for NUMA topology awareness in relation to DPDK logical cores. The goal is to expose API which allows users to select optimal logical cores for any application. These logical cores can be selected from various NUMA domains like CPU and I/O.

Change Summary:
- Introduces the concept of NUMA domain partitioning based on CPU and I/O topology.
- Adds support for grouping DPDK logical cores within the same Cache and I/O domain for improved locality.
- Implements topology detection and core grouping logic that distinguishes between the following NUMA configurations:
* CPU topology & I/O topology (e.g., AMD SoC EPYC, Intel Xeon SPR)
* CPU+I/O topology (e.g., Ampere One with SLC, Intel Xeon SPR
with SNC)
- Enhances performance by minimizing lcore dispersion across
tiles|compute package with different L2/L3 cache or IO domains.

Reason:
- Applications using DPDK libraries relies on consistent memory
access.
- Lcores being closer to same NUMA domain as IO.
- Lcores sharing same cache.

Latency is minimized by using lcores that share the same NUMA topology. Memory access is optimized by utilizing cores within the same NUMA domain or tile. Cache coherence is preserved within the same shared cache domain, reducing the remote access from tile|compute package via snooping (local hit in either L2 or L3 within same NUMA domain).

Library dependency: hwloc

Topology Flags:
---------------
- RTE_LCORE_DOMAIN_L1: to group cores sharing same L1 cache
- RTE_LCORE_DOMAIN_SMT: same as RTE_LCORE_DOMAIN_L1
- RTE_LCORE_DOMAIN_L2: group cores sharing same L2 cache
- RTE_LCORE_DOMAIN_L3: group cores sharing same L3 cache
- RTE_LCORE_DOMAIN_L4: group cores sharing same L4 cache
- RTE_LCORE_DOMAIN_IO: group cores sharing same IO

< Function: Purpose >
---------------------
- rte_get_domain_count: get domain count based on Topology Flag
- rte_lcore_count_from_domain: get valid lcores count under each
domain
- rte_get_lcore_in_domain: valid lcore id based on index
- rte_lcore_cpuset_in_domain: return valid cpuset based on index
- rte_lcore_is_main_in_domain: return true|false if main lcore is
present
- rte_get_next_lcore_from_domain: next valid lcore within domain
- rte_get_next_lcore_from_next_domain: next valid lcore from next
domain

Note:
1. Topology is NUMA grouping.
2. Domain is various sub-groups within a specific Topology.

Topology example: L1, L2, L3, L4, IO
Domian example: IO-A, IO-B

< MACRO: Purpose >
------------------
- RTE_LCORE_FOREACH_DOMAIN: iterate lcores from all domains
- RTE_LCORE_FOREACH_WORKER_DOMAIN: iterate worker lcores from all
domains
- RTE_LCORE_FORN_NEXT_DOMAIN: iterate domain select n'th lcore
- RTE_LCORE_FORN_WORKER_NEXT_DOMAIN: iterate domain for worker n'th
lcore.

Future work (after merge):
--------------------------
- dma-perf per IO NUMA
- eventdev per L3 NUMA
- pipeline per SMT|L3 NUMA
- distributor per L3 for Port-Queue
- l2fwd-power per SMT
- testpmd option for IO NUMA per port

Platform tested on:
-------------------
- INTEL(R) XEON(R) PLATINUM 8562Y+ (support IO numa 1 & 2)
- AMD EPYC 8534P (supports IO numa 1 & 2)
- AMD EPYC 9554 (supports IO numa 1, 2, 4)

Logs:
-----
1. INTEL(R) XEON(R) PLATINUM 8562Y+:
- SNC=1
Domain (IO): at index (0) there are 48 core, with (0) at
index 0
- SNC=2
Domain (IO): at index (0) there are 24 core, with (0) at
index 0 Domain (IO): at index (1) there are 24 core, with (12) at index 0

2. AMD EPYC 8534P:
- NPS=1:
Domain (IO): at index (0) there are 128 core, with (0) at
index 0
- NPS=2:
Domain (IO): at index (0) there are 64 core, with (0) at
index 0 Domain (IO): at index (1) there are 64 core, with (32) at index 0

Vipin Varghese (4):
eal/lcore: add topology based functions
test/lcore: enable tests for topology
doc: add topology grouping details
examples: update with lcore topology API

 app/test/test_lcores.c                        | 528 +++++++++++++
 config/meson.build                            |  18 +
 .../prog_guide/env_abstraction_layer.rst      |  22 +
 examples/helloworld/main.c                    | 154 +++-
 examples/l2fwd/main.c                         |  56 +-
 examples/skeleton/basicfwd.c                  |  22 +
 lib/eal/common/eal_common_lcore.c             | 714
++++++++++++++++++ lib/eal/common/eal_private.h                  |
58 ++ lib/eal/freebsd/eal.c                         |  10 +
 lib/eal/include/rte_lcore.h                   | 209 +++++
 lib/eal/linux/eal.c                           |  11 +
 lib/eal/meson.build                           |   4 +
 lib/eal/version.map                           |  11 +
 lib/eal/windows/eal.c                         |  12 +
 14 files changed, 1819 insertions(+), 10 deletions(-)
#13 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Snipped

Quoted 4 lines

Hello Vipin and others,

please, will there be any progress or update on this series?

Apologies, we did a small update in slack, and missed this out here. Let me try to address your questions below

Quoted 11 lines

I successfully tested those changes on our Intel and AMD machines and would like to use it in production soon.

The API is a little bit unintuitive, at least for me, but I successfully integrated into our software.

I am missing a clear relation to the NUMA socket approach used in DPDK. E.g. I would like to be able to easily walk over a list of lcores from a specific NUMA node grouped by L3 domain. Yes, there is the RTE_LCORE_DOMAIN_IO, but would it always match the appropriate socket IDs?

Yes, we from AMD were internally debating the same. But since there is an API in lcore API as rte_lcore_to_socket_id, adding yet another variation or argument lack it luster. Hence we internally debating when using the new API why not check if it is desired Physical Socket or Sub Socket Numa domain?

Hence, we did not add the option.

Quoted 8 lines

Also, I do not clearly understand what is the purpose of using domain selector like:

RTE_LCORE_DOMAIN_L1 | RTE_LCORE_DOMAIN_L2

or even:

RTE_LCORE_DOMAIN_L3 | RTE_LCORE_DOMAIN_L2

I believe we have mentioned in documents to choose 1, if used multiple combo based on the code flow only 1 will be picked up.

real use of these are to select physical cores, under same cache or io domain.
Example: certain SoC has 4 cores sharing L2, which makes pipeline processing more convinent (less data movement). In such cases select lcores within same L2 topologoly.

Quoted 4 lines

the documentation does not explain this. I could not spot any kind of grouping that would help me in any way. Some "best practices" examples would be nice to have to understand the intentions better.

From https://patches.dpdk.org/project/dpdk/cover/[email protected]/

```
Reason:
 - Applications using DPDK libraries relies on consistent memory access.
 - Lcores being closer to same NUMA domain as IO.
 - Lcores sharing same cache.

Latency is minimized by using lcores that share the same NUMA topology.
Memory access is optimized by utilizing cores within the same NUMA
domain or tile. Cache coherence is preserved within the same shared cache
domain, reducing the remote access from tile|compute package via snooping
(local hit in either L2 or L3 within same NUMA domain).
```
Quoted 5 lines

I found a little catch when running DPDK with more lcores than there are physical or SMT CPU cores. This happens when using e.g. an option like --lcores=(0-15)@(0-1). The results from the topology API would not match the lcores because hwloc is not aware of the lcores concept. This might be mentioned somewhere.

Yes, this is expected. As one can map any cpu cores to dpdk lcore with lcore-map. We did mentioned this in RFCv4, but when upgraded to RFCv5 we missed to mention it back.

Quoted 7 lines

Anyway, I really appreciate this work and would like to see it upstream. Especially for AMD machines, some framework like this is a must.

Kind regards,
Jan

We are planning to remove RFC tag and share the final version for upcoming release for DPDK shortly.

#14 lore raw

[Public]

Hi All,

Saring rte_topology_ API patch next version targeted for upcoming release.
Extras adding support for Cache-ID for L2 and L3 for Cache line stashing, Code Data Prioritization too.

Snipped

Quoted 91 lines
Quoted 5 lines

Hello Vipin and others,

please, will there be any progress or update on this series?

Apologies, we did a small update in slack, and missed this out here. Let me try to address your questions below

Quoted 11 lines

I successfully tested those changes on our Intel and AMD machines and would like to use it in production soon.

The API is a little bit unintuitive, at least for me, but I successfully integrated into our software.

I am missing a clear relation to the NUMA socket approach used in DPDK. E.g. I would like to be able to easily walk over a list of lcores from a specific NUMA node grouped by L3 domain. Yes, there is the RTE_LCORE_DOMAIN_IO, but would it always match the appropriate socket

IDs?

Yes, we from AMD were internally debating the same. But since there is an API in lcore API as rte_lcore_to_socket_id, adding yet another variation or argument lack it luster.
Hence we internally debating when using the new API why not check if it is desired Physical Socket or Sub Socket Numa domain?

Hence, we did not add the option.

Quoted 2 lines

Also, I do not clearly understand what is the purpose of using domain selector

like:

Quoted 6 lines

RTE_LCORE_DOMAIN_L1 | RTE_LCORE_DOMAIN_L2

or even:

RTE_LCORE_DOMAIN_L3 | RTE_LCORE_DOMAIN_L2

I believe we have mentioned in documents to choose 1, if used multiple combo based on the code flow only 1 will be picked up.

real use of these are to select physical cores, under same cache or io domain.
Example: certain SoC has 4 cores sharing L2, which makes pipeline processing more convinent (less data movement). In such cases select lcores within same L2 topologoly.

Quoted 4 lines

the documentation does not explain this. I could not spot any kind of grouping that would help me in any way. Some "best practices" examples would be nice to have to understand the intentions better.

From https://patches.dpdk.org/project/dpdk/cover/20241105102849.1947-1-
[email protected]/

```
Reason:
 - Applications using DPDK libraries relies on consistent memory access.
 - Lcores being closer to same NUMA domain as IO.
 - Lcores sharing same cache.

Latency is minimized by using lcores that share the same NUMA topology.
Memory access is optimized by utilizing cores within the same NUMA domain or
tile. Cache coherence is preserved within the same shared cache domain, reducing
the remote access from tile|compute package via snooping (local hit in either L2 or
L3 within same NUMA domain).
```
Quoted 3 lines

I found a little catch when running DPDK with more lcores than there are physical or SMT CPU cores. This happens when using e.g. an option like --

lcores=(0-15)@(0-1).

Quoted 2 lines

The results from the topology API would not match the lcores because hwloc is not aware of the lcores concept. This might be mentioned somewhere.

Yes, this is expected. As one can map any cpu cores to dpdk lcore with lcore- map.
We did mentioned this in RFCv4, but when upgraded to RFCv5 we missed to mention it back.

Quoted 7 lines

Anyway, I really appreciate this work and would like to see it upstream. Especially for AMD machines, some framework like this is a must.

Kind regards,
Jan

We are planning to remove RFC tag and share the final version for upcoming release for DPDK shortly.

#15 lore raw
In reply to Jan Viktorin
Quoted 35 lines · On Mon, 17 Mar 2025 14:46:07 +0100 Jan Viktorin <[email protected]> wrote:

Hello Vipin and others,

please, will there be any progress or update on this series?

I successfully tested those changes on our Intel and AMD machines and would like to use it in production soon.

The API is a little bit unintuitive, at least for me, but I successfully integrated into our software.

I am missing a clear relation to the NUMA socket approach used in DPDK. E.g. I would like to be able to easily walk over a list of lcores from a specific NUMA node grouped by L3 domain. Yes, there is the RTE_LCORE_DOMAIN_IO, but would it always match the appropriate socket IDs?

Also, I do not clearly understand what is the purpose of using domain selector like:

RTE_LCORE_DOMAIN_L1 | RTE_LCORE_DOMAIN_L2

or even:

RTE_LCORE_DOMAIN_L3 | RTE_LCORE_DOMAIN_L2

the documentation does not explain this. I could not spot any kind of grouping that would help me in any way. Some "best practices" examples would be nice to have to understand the intentions better.

I found a little catch when running DPDK with more lcores than there are physical or SMT CPU cores. This happens when using e.g. an option like --lcores=(0-15)@(0-1). The results from the topology API would not match the lcores because hwloc is not aware of the lcores concept. This might be mentioned somewhere.

Quoted 140 lines

Anyway, I really appreciate this work and would like to see it upstream. Especially for AMD machines, some framework like this is a must.

Kind regards,
Jan

Quoted 131 lines · On Tue, 5 Nov 2024 15:58:45 +0530 Vipin Varghese <[email protected]> wrote:

This patch introduces improvements for NUMA topology awareness in relation to DPDK logical cores. The goal is to expose API which allows users to select optimal logical cores for any application. These logical cores can be selected from various NUMA domains like CPU and I/O.

Change Summary:
- Introduces the concept of NUMA domain partitioning based on CPU and I/O topology.
- Adds support for grouping DPDK logical cores within the same Cache and I/O domain for improved locality.
- Implements topology detection and core grouping logic that distinguishes between the following NUMA configurations:
* CPU topology & I/O topology (e.g., AMD SoC EPYC, Intel Xeon SPR)
* CPU+I/O topology (e.g., Ampere One with SLC, Intel Xeon SPR
with SNC)
- Enhances performance by minimizing lcore dispersion across
tiles|compute package with different L2/L3 cache or IO domains.

Reason:
- Applications using DPDK libraries relies on consistent memory
access.
- Lcores being closer to same NUMA domain as IO.
- Lcores sharing same cache.

Latency is minimized by using lcores that share the same NUMA topology. Memory access is optimized by utilizing cores within the same NUMA domain or tile. Cache coherence is preserved within the same shared cache domain, reducing the remote access from tile|compute package via snooping (local hit in either L2 or L3 within same NUMA domain).

Library dependency: hwloc

Topology Flags:
---------------
- RTE_LCORE_DOMAIN_L1: to group cores sharing same L1 cache
- RTE_LCORE_DOMAIN_SMT: same as RTE_LCORE_DOMAIN_L1
- RTE_LCORE_DOMAIN_L2: group cores sharing same L2 cache
- RTE_LCORE_DOMAIN_L3: group cores sharing same L3 cache
- RTE_LCORE_DOMAIN_L4: group cores sharing same L4 cache
- RTE_LCORE_DOMAIN_IO: group cores sharing same IO

< Function: Purpose >
---------------------
- rte_get_domain_count: get domain count based on Topology Flag
- rte_lcore_count_from_domain: get valid lcores count under each
domain
- rte_get_lcore_in_domain: valid lcore id based on index
- rte_lcore_cpuset_in_domain: return valid cpuset based on index
- rte_lcore_is_main_in_domain: return true|false if main lcore is
present
- rte_get_next_lcore_from_domain: next valid lcore within domain
- rte_get_next_lcore_from_next_domain: next valid lcore from next
domain

Note:
1. Topology is NUMA grouping.
2. Domain is various sub-groups within a specific Topology.

Topology example: L1, L2, L3, L4, IO
Domian example: IO-A, IO-B

< MACRO: Purpose >
------------------
- RTE_LCORE_FOREACH_DOMAIN: iterate lcores from all domains
- RTE_LCORE_FOREACH_WORKER_DOMAIN: iterate worker lcores from all
domains
- RTE_LCORE_FORN_NEXT_DOMAIN: iterate domain select n'th lcore
- RTE_LCORE_FORN_WORKER_NEXT_DOMAIN: iterate domain for worker n'th
lcore.

Future work (after merge):
--------------------------
- dma-perf per IO NUMA
- eventdev per L3 NUMA
- pipeline per SMT|L3 NUMA
- distributor per L3 for Port-Queue
- l2fwd-power per SMT
- testpmd option for IO NUMA per port

Platform tested on:
-------------------
- INTEL(R) XEON(R) PLATINUM 8562Y+ (support IO numa 1 & 2)
- AMD EPYC 8534P (supports IO numa 1 & 2)
- AMD EPYC 9554 (supports IO numa 1, 2, 4)

Logs:
-----
1. INTEL(R) XEON(R) PLATINUM 8562Y+:
- SNC=1
Domain (IO): at index (0) there are 48 core, with (0) at
index 0
- SNC=2
Domain (IO): at index (0) there are 24 core, with (0) at
index 0 Domain (IO): at index (1) there are 24 core, with (12) at index 0

2. AMD EPYC 8534P:
- NPS=1:
Domain (IO): at index (0) there are 128 core, with (0) at
index 0
- NPS=2:
Domain (IO): at index (0) there are 64 core, with (0) at
index 0 Domain (IO): at index (1) there are 64 core, with (32) at index 0

Vipin Varghese (4):
eal/lcore: add topology based functions
test/lcore: enable tests for topology
doc: add topology grouping details
examples: update with lcore topology API

 app/test/test_lcores.c                        | 528 +++++++++++++
 config/meson.build                            |  18 +
 .../prog_guide/env_abstraction_layer.rst      |  22 +
 examples/helloworld/main.c                    | 154 +++-
 examples/l2fwd/main.c                         |  56 +-
 examples/skeleton/basicfwd.c                  |  22 +
 lib/eal/common/eal_common_lcore.c             | 714
++++++++++++++++++ lib/eal/common/eal_private.h                  |
58 ++ lib/eal/freebsd/eal.c                         |  10 +
 lib/eal/include/rte_lcore.h                   | 209 +++++
 lib/eal/linux/eal.c                           |  11 +
 lib/eal/meson.build                           |   4 +
 lib/eal/version.map                           |  11 +
 lib/eal/windows/eal.c                         |  12 +
 14 files changed, 1819 insertions(+), 10 deletions(-)

This patch series does not apply cleanly to current DPDK main branch. Please rebase and resubmit.

AI patch review had the following insights:

# DPDK Patch Series Review: Topology-based Lcore Functions (v4)

**Series**: [PATCH v4 1-4/4] eal/lcore: add topology based functions **Date**: November 5, 2024
**Author**: Vipin Varghese <[email protected]>

---

## Executive Summary

This 4-patch series adds topology-aware lcore mapping to DPDK's lcore API, allowing cores to be grouped by chiplet locality (L1-L4 cache, IO). The series includes API additions, tests, documentation, and example updates.

**Overall Assessment**: The patches have several issues that need to be addressed before acceptance.

---

## Patch 1/4: eal/lcore: add topology based functions

### Commit Message Review

#### ✅ PASS: Subject Line Format
- Length: 45 characters (within 60 char limit)
- Format: eal/lcore: add topology based functions
- Proper prefix, lowercase, imperative mood, no trailing period

#### ⚠️ WARNING: Commit Body Issues

**Line Length Violations** (must be ≤75 characters):
- Line 147: "Using hwloc library, the dpdk available lcores can be grouped" - appears OK
- Line 148: "into various groups nameley L1, L2, L3, L4 and IO. This patch" - OK
- However, several lines approach the limit

**Typo**: "nameley" should be "namely" (line 147)

**Body Structure**: The commit message starts appropriately but could be more detailed about the problem being solved and why this change is needed.

#### ❌ ERROR: Missing Required Tags

The patch is missing:
- Signed-off-by: tag - This is **MANDATORY** per AGENTS.md line 116

The version history (v4 changes) is good and appropriately placed but should be separated from the main commit message by a --- line before the diff.

### Code Review

#### License Headers

Need to check if new files have proper SPDX headers. From the visible diff, additions to existing files should maintain their existing headers.

#### Naming Conventions

**✅ PASS**: External API functions properly prefixed with rte_:
- rte_get_domain_count
- rte_get_lcore_in_domain
- rte_get_next_lcore_from_domain
- rte_get_next_lcore_from_next_domain
- rte_lcore_count_from_domain
- rte_lcore_cpuset_in_domain
- rte_lcore_is_main_in_domain

**⚠️ INFO**: Internal functions lack rte_ prefix, which is appropriate for internal APIs:
- get_domain_lcore_count
- get_domain_lcore_mapping
- rte_eal_topology_init
- rte_eal_topology_release

However, the last two (rte_eal_topology_*) have rte_ prefix despite being listed as internal - verify if these should be marked as __rte_internal.

#### Code Style Issues

From the visible diffs:

**Line Length**: Need to verify all code lines are ≤100 characters

**Type Usage**:
- Good: Conversion of l3_count & io_count to uint16_t (mentioned in v4 changes)

**Memory Management**:
- Good: Removed unnecessary NULL checks before free (mentioned in v4 changes)
- Good: Removed unnecessary malloc casting (mentioned in v4 changes)

**Comments**: Would need to see full code to verify comment formatting

#### API Design Issues

**⚠️ WARNING: Experimental APIs**
All new external APIs should be marked with __rte_experimental per AGENTS.md line 766. The commit message mentions "External Experimental API" but need to verify in the actual header file that each function has the __rte_experimental attribute on its own line.

**⚠️ WARNING: Missing Doxygen**
New public APIs must have Doxygen comments (AGENTS.md line 756). Need to verify full header file.

#### Testing Requirements

**⚠️ WARNING**: Per AGENTS.md line 698-699:
- New APIs must be used in /app test directory
- New device APIs require at least one driver implementation

The series includes patch 2/4 for tests, which is good. Need to verify the tests use the TEST_ASSERT macros and unit_test_suite_runner infrastructure (AGENTS.md lines 703-743).

### Documentation Requirements

**⚠️ WARNING**: Per AGENTS.md line 758-762:
- Release notes must be updated in doc/guides/rel_notes/ for important changes
- Code and documentation must be updated atomically

The series includes patch 3/4 for documentation, which is good. However, need to verify:
- Documentation matches code behavior
- Only the **current release** notes file is updated
- Doxygen comments are present for all public APIs

---

## Patch 2/4: test/lcore: enable tests for topology

### Commit Message Review

#### Subject Line
- Format: test/lcore: enable tests for topology
- Length: 37 characters ✅
- Proper prefix, lowercase, imperative ✅

#### Missing Elements
- ❌ **ERROR**: Missing Signed-off-by: tag

### Test Code Requirements

**Need to verify**:
- Tests use TEST_ASSERT macros (AGENTS.md line 745-752)
- Tests use unit_test_suite_runner infrastructure (AGENTS.md line 703-743)
- Tests are properly registered with REGISTER_FAST_TEST or similar

---

## Patch 3/4: doc: add topology grouping details

### Commit Message Review

#### Subject Line
- Format: doc: add topology grouping details
- Length: 35 characters ✅
- Proper prefix, lowercase, imperative ✅

#### Missing Elements
- ❌ **ERROR**: Missing Signed-off-by: tag

### Documentation Requirements

**Need to verify**:
- Documentation matches actual code behavior
- Release notes updated for current release only
- Proper RST formatting
- No passive voice (per DPDK documentation standards)

---

## Patch 4/4: examples: update with lcore topology API

### Commit Message Review

#### Subject Line
- Format: examples: update with lcore topology API
- Length: 39 characters ✅
- Proper prefix ✅

**⚠️ WARNING: Component Prefix**
Per AGENTS.md line 89, example: should be examples/foo: with specific example name. Should be something like: examples/helloworld: add topology support

#### Missing Elements
- ❌ **ERROR**: Missing Signed-off-by: tag

### Code Review for Examples

From the visible diff in helloworld:

**Line 2608-2609**: Ternary operator formatting

```c
rte_eal_remote_launch((topo_sel == USE_NO_TOPOLOGY) ?
    lcore_hello : send_lcore_hello, NULL, lcore_id);
```
This is acceptable but could be more readable. Consider:
```c
lcore_func = (topo_sel == USE_NO_TOPOLOGY) ? lcore_hello : send_lcore_hello;
rte_eal_remote_launch(lcore_func, NULL, lcore_id);
```

**Line 2631-2632**: Comment formatting

```c
+/* select lcores based on ports numa (RTE_LCORE_DOMAIN_IO). */
+static bool select_port_from_io_domain;
```

✅ Good comment style

**L2fwd example changes** (lines 2624-2729):

**Line 2641**: Missing space in comment

```c
+	       "  -t : Enable IO domain lcores mapping to Ports\n"
```

Should probably be: "IO-domain lcore mapping" or "IO domain lcore mapping"

**Line 2670**: Variable type change

```c
-	unsigned lcore_id, rx_lcore_id;
+	uint16_t lcore_id, rx_lcore_id;
```

✅ Good: Using explicit types instead of unsigned

**Line 2681-2686**: Array initialization

```c
+	uint16_t coreindx_io_domain[RTE_MAX_ETHPORTS] = {0};
+	uint16_t lcore_io_domain[RTE_MAX_ETHPORTS] = {RTE_MAX_LCORE};
```
**⚠️ WARNING**: The second initialization is problematic. It only sets the first element to `RTE_MAX_LCORE`, not all elements. Should use a loop or memset for initialization:
```c
for (int i = 0; i < RTE_MAX_ETHPORTS; i++)
    lcore_io_domain[i] = RTE_MAX_LCORE;
```

**Line 2683**: Variable naming issue

```c
+	uint16_t l3_domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_IO);
```

**❌ ERROR**: Variable is named l3_domain_count but gets IO domain count. Should be io_domain_count.

**Line 2705-2710**: Parentheses in while condition

```c
while ((rte_lcore_is_enabled(rx_lcore_id) == 0) ||
       (lcore_queue_conf[rx_lcore_id].n_rx_port ==
	l2fwd_rx_queue_per_lcore)) {
```

Excessive parentheses - the outer ones around each condition aren't needed.

**Skeleton example changes** (lines 2731-2777):

**Line 2750**: Typo in comment

```c
+	/* get the socekt of each port */
```

Should be "socket", not "socekt"

**Line 2760**: Function usage looks good

```c
+	core_count_from_io = rte_lcore_count_from_domain(RTE_LCORE_DOMAIN_IO, sel_io_indx);
```

---

## Summary of Critical Issues

### Errors (Must Fix):

1. **All 4 patches missing Signed-off-by: tags** - This is mandatory per DPDK contribution guidelines
2. **Patch 4**: Variable naming bug - l3_domain_count should be io_domain_count
3. **Patch 4**: Array initialization bug - lcore_io_domain array not fully initialized

### Warnings (Should Fix):

4. **Patch 1**: Typo in commit message - "nameley" → "namely"
5. **Patch 4**: Wrong component prefix - should be examples/helloworld: and examples/l2fwd: and examples/skeleton:
6. **Patch 4**: Typo in comment - "socekt" → "socket"
7. **Patch 4**: Unnecessary parentheses in while condition
8. All patches should verify:
- API functions have __rte_experimental markers
- Doxygen comments present for all public APIs
- Tests use proper TEST_ASSERT infrastructure
- Release notes updated

### Info (Consider):

9. **Patch 1**: Version history (v4 changes) should be after --- separator, not in commit body
10. **Patch 4**: Ternary operator could be more readable with intermediate variable
11. Verify all code lines are ≤100 characters
12. Verify commit body lines are ≤75 characters

---

## Recommended Actions

1. **Immediate**: Add Signed-off-by: tags to all patches with author's real name and email
2. **Immediate**: Fix variable naming bug (l3_domain_count → io_domain_count)
3. **Immediate**: Fix array initialization bug for lcore_io_domain
4. Fix typos: "nameley" → "namely", "socekt" → "socket"
5. Update patch 4 subject lines to use specific example names
6. Verify all new APIs are marked __rte_experimental
7. Verify all new APIs have Doxygen documentation
8. Move v4 changelog to post---- section
9. Run DPDK validation tools:
- devtools/check-git-log.sh
- devtools/checkpatches.sh
- devtools/test-meson-builds.sh

---

## Validation Commands

Before resubmitting, run:

```bash
# Check commit messages
devtools/check-git-log.sh

# Check patch formatting
devtools/checkpatches.sh *.patch

# Verify compilation
devtools/test-meson-builds.sh

# Check maintainers
devtools/get-maintainer.sh *.patch
```

---

## Positive Aspects

✅ Good responsiveness to v4 feedback (removed malloc casting, NULL checks, fixed types) ✅ Comprehensive series with tests, documentation, and examples
✅ Clear API naming with proper rte_ prefixes
✅ Good use of explicit types (uint16_t) instead of unsigned
✅ Appropriate subject line formatting and component prefixes (mostly)

The core concept and implementation approach appear sound, but the patches need the above corrections before merging.

#16 lore raw

RE: [PATCH v4 0/4] Introduce Topology NUMA grouping for cores

[Public]

Hi @Stephen Hemminger,

Thank you for the tool and report generation, we are working internally to release v5 soon.

Snipped

Quoted 13 lines

---

## Positive Aspects

✅ Good responsiveness to v4 feedback (removed malloc casting, NULL checks, fixed types) ✅ Comprehensive series with tests, documentation, and examples ✅ Clear API naming with proper rte_ prefixes ✅ Good use of explicit types (uint16_t) instead of unsigned ✅ Appropriate subject line formatting and component prefixes (mostly)

The core concept and implementation approach appear sound, but the patches need the above corrections before merging.

#17 lore raw

v5 cover eal/topology: introduce topology-aware lcore grouping

In reply to Vipin Varghese

This series introduces a topology library that groups DPDK lcores based on CPU cache hierarchy and NUMA topology. The goal is to provide a stable and explicit API that allows applications to select lcores with better locality and cache sharing characteristics.

The series includes:
- EAL support for topology discovery using hwloc and domain-based lcore

    grouping (L1/L2/L3/L4/NUMA)

- Topology-aware test cases validating API behavior and edge conditions
- Programmer’s guide describing the topology library and APIs

The API is marked experimental and does not change existing lcore behavior unless explicitly used by the application.

Changes in v5:
- Addressed review comments from v4
- Fixed ARM cross-compilation issues
- Cleaned up domain iteration and error handling
- Updated tests to cover domain edge cases
- Documentation refinements and API usage clarification

Changes in v4:
- Corrected domain selection semantics
- Updated example usage
- Fixed naming and typo issues

Changes in v3:
- Fixed macro naming (USE_NO_TOPOLOGY)
- Minor cleanups based on early feedback

Tested on:
- AMD EPYC (Milan, Genoa, Siena, Turin, Turin-Dense, Sorano)
- Intel Xeon (SPR-SP, GNR-SP)
- ARM Ampere
- NVIDIA Grace Superchip

Dependencies:
- hwloc-dev (tested with 2.10.0)

Patch breakdown:
1/3 eal/topology: add topology grouping for lcores 2/3 app: add topology-aware test cases
3/3 doc: add topology library documentation

Future Work:
- integrate into examples
-- hellowrld: ready
-- pkt-distributor: in-progress
-- l2fwd: ready
-- l3fwd: to start
-- eventdevpipeline: PoC ready
- integrate topology test
-- crypto: yet to start
-- compression: yet to start
-- dma: PoC ready
- add new features for
-- PQoS: yet to start
-- Data Injection: PoC with BRDCM Thor-2 ready

Tested OS: Linux only, need help with BSD and Windows

Tested with and without hwloc-dev library for
- Ampere, aarch64, Neoverse-N1, NUMA-2, 256 CPU threads
- Grace superchip, aarch64, Neoverse-V2, NUMA-2, 144 CPU threads
- Intel GNR-SP, 6767P, NUMA-2, 256 Threads
- AMD EPYC Siena, 8534P, NUMA-1, 128 Threads
- AMD EPYC Sorano, 8635P, NUMA-1, 168 Threads

``

Vipin Varghese (3):
eal/topology: add Topology grouping for lcores
app: add topology aware test case
doc: add new section topology

 app/test/meson.build                   |   1 +
 app/test/test_ring_perf.c              | 416 +++++++++++++-
 app/test/test_stack_perf.c             | 409 ++++++++++++++
 app/test/test_topology.c               | 676 ++++++++++++++++++++++
 config/meson.build                     |  18 +
 doc/api/doxy-api-index.md              |   1 +
 doc/guides/prog_guide/index.rst        |   3 +-
 doc/guides/prog_guide/topology_lib.rst | 155 +++++
 lib/eal/common/eal_private.h           |  74 +++
 lib/eal/common/eal_topology.c          | 747 +++++++++++++++++++++++++
 lib/eal/common/meson.build             |   1 +
 lib/eal/freebsd/eal.c                  |  10 +-
 lib/eal/include/meson.build            |   1 +
 lib/eal/include/rte_topology.h         | 255 +++++++++
 lib/eal/linux/eal.c                    |   7 +
 lib/eal/meson.build                    |   4 +
 16 files changed, 2773 insertions(+), 5 deletions(-)
 create mode 100644 app/test/test_topology.c
 create mode 100644 doc/guides/prog_guide/topology_lib.rst
 create mode 100644 lib/eal/common/eal_topology.c
 create mode 100644 lib/eal/include/rte_topology.h
Signature · 1 line
2.43.0
#18 lore raw

PATCH v5 1/3 eal/topology: add Topology grouping for lcores

This patch introduces NUMA topology awareness in relation to DPDK logical cores. The goal is to expose API which allows users to select optimal logical cores for any application. These logical cores can be selected from various NUMA domains like CPU and I/O.

Change Summary:
- Add concept of domain partitioning based on CPU and I/O topology.
- Group DPDK logical cores iinto groups of L1|L2|L3|L4|IO.
- Add supportor helper MACRO as iterator.

v4 changes:
- cross compilation failure on ARM: Pavan Nikhilesh Bhagavatula
- update helloworld for L4

v3 changes:
- fix typo from SE_NO_TOPOLOGY to USE_NO_TOPOLOGY

Reason:
- Applications can performs better using lcores within the same domain.
- In pipeline and graph application; sharing cache reduces memory access.
- Use L2|L3 cache-id to configure Data injection & PQoS.
- Integrate hwloc-dev library, which allows
-- grouping into DPDK favourable domain
-- reverse lookup from lcore to domain-id.
-- ensure no ABI breakage with versions of hwloc-dev
-- consistent mapping even with DPDK lcore option R.

Library dependency: hwloc-dev

RTE_TOPO API:
+++++++++++++

Domain Enumeration
- rte_topo_get_domain_count(domain_sel)

Lcore Enumeration
- rte_topo_get_lcore_count_from_domain(domain_sel, domain_idx)
- rte_topo_get_nth_lcore_in_domain(domain_sel, domain_idx, lcore_pos)
- rte_topo_get_next_lcore(lcore, skip_main, wrap, flag)
- rte_topo_get_nth_lcore_from_domain(domain_idx, lcore_pos, wrap, flag)

Domain Lookup
- rte_topo_get_domain_index_from_lcore(domain_sel, lcore)
- rte_topo_is_main_lcore_in_domain(domain_sel, domain_idx)

Cpuset
- rte_topo_get_lcore_cpuset_in_domain(domain_sel, domain_idx)

Debug
- rte_topo_dump(FILE *f)

Platform tested on:
-------------------
- AMD EPYC MILAN
- AMD EPYC GENOA
- AMD EPYC SIENA
- AMD EPYC TURIN
- AMD EPYC TURIN-DENSE
- AMD EPYC SORANO
- ARM AMPERE
- INTEL XEON GNR-SP
- INTEL XEON SPR-SP
- NVIDIA GRACE SUPERCHIP

---
 config/meson.build             |  18 +
 lib/eal/common/eal_private.h   |  74 ++++
 lib/eal/common/eal_topology.c  | 746 +++++++++++++++++++++++++++++++++
 lib/eal/common/meson.build     |   1 +
 lib/eal/freebsd/eal.c          |  10 +-
 lib/eal/include/meson.build    |   1 +
 lib/eal/include/rte_topology.h | 255 +++++++++++
 lib/eal/linux/eal.c            |   7 +
 lib/eal/meson.build            |   4 +
 9 files changed, 1115 insertions(+), 1 deletion(-)
 create mode 100644 lib/eal/common/eal_topology.c
 create mode 100644 lib/eal/include/rte_topology.h
config/meson.build +18 -0
index 9ba7b9a338..db2faccdbc 100644
@@ -245,6 +245,24 @@ if find_libnuma
     endif
 endif
 
+has_libhwloc = false
+find_libhwloc = true
+
+if meson.is_cross_build() and not meson.get_external_property('hwloc', true)
+    # don't look for libhwloc if explicitly disabled in cross build
+    find_libhwloc = false
+endif
+
+if find_libhwloc
+    hwloc_dep = cc.find_library('hwloc', required: false)
+    if hwloc_dep.found() and cc.has_header('hwloc.h')
+        dpdk_conf.set10('RTE_LIBHWLOC_PROBE', true)
+        has_libhwloc = true
+        #add_project_link_arguments('-lhwloc', language: 'c')
+        #dpdk_extra_ldflags += '-lhwloc'
+    endif
+endif
+
 has_libfdt = false
 fdt_dep = cc.find_library('fdt', required: false)
 if fdt_dep.found() and cc.has_header('fdt.h') and cc.links(min_c_code, dependencies: fdt_dep)
lib/eal/common/eal_private.h +74 -0

98 lines not on this page · raw message

lib/eal/common/eal_topology.c new file +746 -0

746 lines not on this page · raw message

lib/eal/common/meson.build +1 -0
index e273745e93..834ed2130b 100644
@@ -50,6 +50,7 @@ if not is_windows
             'eal_common_trace.c',
             'eal_common_trace_ctf.c',
             'eal_common_trace_utils.c',
+            'eal_topology.c',
             'hotplug_mp.c',
             'malloc_mp.c',
             'rte_keepalive.c',
lib/eal/freebsd/eal.c +9 -1
index 60f5e676a8..0d016a379f 100644
@@ -42,6 +42,8 @@
 #include <rte_devargs.h>
 #include <rte_version.h>
 #include <rte_vfio.h>
+#include <rte_topology.h>
+
 #include <malloc_heap.h>
 #include <telemetry_internal.h>
 
@@ -77,7 +79,6 @@ struct lcore_config lcore_config[RTE_MAX_LCORE];
 RTE_EXPORT_SYMBOL(rte_cycles_vmware_tsc_map)
 int rte_cycles_vmware_tsc_map;
 
-
 int
 eal_clean_runtime_dir(void)
 {
@@ -754,6 +755,12 @@ rte_eal_init(int argc, char **argv)
 			goto err_out;
 	}
 
+	ret = rte_eal_topology_init();
+	if (ret) {
+		rte_eal_init_alert("Cannot invoke topology, skipping topology!!!");
+		rte_errno = ENOTSUP;
+	}
+
 	eal_mcfg_complete();
 
 	return fctret;
@@ -781,6 +788,7 @@ rte_eal_cleanup(void)
 		eal_get_internal_configuration();
 	rte_service_finalize();
 	eal_bus_cleanup();
+	rte_eal_topology_release();
 	rte_mp_channel_cleanup();
 	rte_eal_alarm_cleanup();
 	rte_trace_save();
lib/eal/include/meson.build +1 -0
index aef5824e5f..16857f76bf 100644
@@ -50,6 +50,7 @@ headers += files(
         'rte_thread.h',
         'rte_ticketlock.h',
         'rte_time.h',
+        'rte_topology.h',
         'rte_trace.h',
         'rte_trace_point.h',
         'rte_trace_point_register.h',
lib/eal/include/rte_topology.h new file +255 -0

255 lines not on this page · raw message

lib/eal/linux/eal.c +7 -0
index d848de03d8..f6a49badf2 100644
@@ -42,6 +42,7 @@
 #include <rte_version.h>
 #include <malloc_heap.h>
 #include <rte_vfio.h>
+#include <rte_topology.h>
 
 #include <telemetry_internal.h>
 #include <eal_export.h>
@@ -927,6 +928,11 @@ rte_eal_init(int argc, char **argv)
 			goto err_out;
 	}
 
+	if (rte_eal_topology_init()) {
+		rte_eal_init_alert("Cannot invoke topology, skipping topologly!!!");
+		rte_errno = ENOTSUP;
+	}
+
 	eal_mcfg_complete();
 
 	return fctret;
@@ -981,6 +987,7 @@ rte_eal_cleanup(void)
 	rte_service_finalize();
 	eal_bus_cleanup();
 	vfio_mp_sync_cleanup();
+	rte_eal_topology_release();
 	rte_mp_channel_cleanup();
 	rte_eal_alarm_cleanup();
 	rte_trace_save();
lib/eal/meson.build +4 -0
index f9fcee24ee..f6cd81ed8e 100644
@@ -31,3 +31,7 @@ endif
 if is_freebsd
     annotate_locks = false
 endif
+
+if dpdk_conf.has('RTE_LIBHWLOC_PROBE')
+    ext_deps += hwloc_dep
+endif
Signature · 1 line
2.43.0
#19 lore raw

RE: [PATCH v5 v5 1/3] eal/topology: add Topology grouping for lcores

lib/eal/common/eal_private.h struct lcore_config { · line 52

Quoted 10 lines
lib/eal/common/eal_private.h +2 -0
@@ -40,6 +45,63 @@ struct lcore_config {
 
 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
 
+struct core_domain_mapping {
+	rte_cpuset_t core_set;	/**< cpu_set representing lcores within

domain */

lib/eal/common/eal_private.h +3 -0
+	uint16_t core_count;	/**< dpdk enabled lcores within domain */
+	uint16_t *cores;	/**< list of cores */
+};

In Linux, rte_cpu_set_t is the same as cpu_set_t, which is limited to CPU_SETSIZE (1024) cores.

We should stop using that (fixed size) type, and use dynamically sized CPU sets instead.
Ref: https://man7.org/linux/man-pages/man3/CPU_SET.3.html

IMHO, both the fd_set type, limited to FDSET_SIZE (1024) file descriptors, and the cpu_set_t type, limited to CPU_SETSIZE (1024) cores, should be considered obsolete, and not used in new DPDK code.

It's hard to change old DPDK APIs relying on the fixed size rte_cpu_set_t type, but let's avoid adding new APIs using that (obsolete) type.

Also refer to: https://bugs.dpdk.org/show_bug.cgi?id=1704

PS: I guess a larger CPU_SETSIZE is available for systems built entirely from scratch, including libc and all libraries and applications. Not a generic solution.

-Morten

#20 lore raw

RE: [PATCH v5 v5 1/3] eal/topology: add Topology grouping for lcores

[AMD Official Use Only - AMD Internal Distribution Only]

Thank you @Morten Brørup

<snipped>

Quoted 22 lines

lib/eal/common/eal_private.h struct lcore_config { · line 52

Quoted 7 lines
(quoted diff) +2 -0
+struct core_domain_mapping {
+     rte_cpuset_t core_set;  /**< cpu_set representing lcores within

domain */

lib/eal/common/eal_private.h +3 -0
+     uint16_t core_count;    /**< dpdk enabled lcores within domain */
+     uint16_t *cores;        /**< list of cores */
+};

In Linux, rte_cpu_set_t is the same as cpu_set_t, which is limited to CPU_SETSIZE (1024) cores.

We should stop using that (fixed size) type, and use dynamically sized CPU sets instead.
Ref: https://man7.org/linux/man-pages/man3/CPU_SET.3.html

IMHO, both the fd_set type, limited to FDSET_SIZE (1024) file descriptors, and the cpu_set_t type, limited to CPU_SETSIZE (1024) cores, should be considered obsolete, and not used in new DPDK code.

It's hard to change old DPDK APIs relying on the fixed size rte_cpu_set_t type, but let's avoid adding new APIs using that (obsolete) type.

Quoted 6 lines

Also refer to: https://bugs.dpdk.org/show_bug.cgi?id=1704

PS: I guess a larger CPU_SETSIZE is available for systems built entirely from scratch, including libc and all libraries and applications. Not a generic solution.

-Morten

Thanks for the pointer, If I understand this correctly for given DPDK processing for rte_lcore_count is valid representation While hwloc_init can show upto 1024 or more. Hence step-1 identify the number of cores (or execution engines) per domain. Alloc for cpuset and use set for valid lcores.

I will make this change in v6 and omit rte_cpuset_t

#21 lore raw

PATCH v5 2/3 app: add topology aware test case

In reply to Vipin Varghese

changes:
- rework stack and ring with domain lcores
- add new test cases for topology API

ring_test inspired from [email protected]

---
 app/test/meson.build       |   1 +
 app/test/test_ring_perf.c  | 416 ++++++++++++++++++++++-
 app/test/test_stack_perf.c | 409 ++++++++++++++++++++++
 app/test/test_topology.c   | 676 +++++++++++++++++++++++++++++++++++++
 4 files changed, 1499 insertions(+), 3 deletions(-)
 create mode 100644 app/test/test_topology.c
app/test/meson.build +1 -0
index 7d458f9c07..f584ea66c1 100644
@@ -207,6 +207,7 @@ source_file_deps = {
     'test_timer_perf.c': ['timer'],
     'test_timer_racecond.c': ['timer'],
     'test_timer_secondary.c': ['timer'],
+    'test_topology.c': [],
     'test_trace.c': [],
     'test_trace_perf.c': [],
     'test_trace_register.c': [],
app/test/test_ring_perf.c +413 -3

452 lines not on this page · raw message

app/test/test_stack_perf.c +409 -0

427 lines not on this page · raw message

app/test/test_topology.c new file +676 -0

676 lines not on this page · raw message

Signature · 1 line
2.43.0
#22 lore raw

Re: [PATCH v5 v5 2/3] app: add topology aware test case

Hi Vipin,

This is my first ever patch review with DPDK. Apologies if I am not following the right procedure. I welcome any feedback or help in correcting the procedure.

However, I had the following review related to the above patch.

I see that changes to app/test/test_ring_perf.c introduced the following functions:

get_same_numa_domains(struct lcore_pair *lcp)
get_same_l4_domains(struct lcore_pair *lcp)
get_same_l3_domains(struct lcore_pair *lcp)
get_same_l2_domains(struct lcore_pair *lcp)
get_same_l1_domains(struct lcore_pair *lcp)
get_two_numa_domains(struct lcore_pair *lcp)
get_two_l4_domains(struct lcore_pair *lcp)
get_two_l3_domains(struct lcore_pair *lcp)
get_two_l2_domains(struct lcore_pair *lcp)
get_two_l1_domains(struct lcore_pair *lcp)

In the implementation of these, most of the code is pretty much identical, except for the topology domain type.

Curious to know if it is better to implement a 'common function' - get_topo_domains(struct lcore_pair *, topology_domain) - as arguments and call get_topo_domains() from all of the above functions.

For example:
get_same_numa_domains() calls get_topo_domains(lp, RTE_TOPO_DOMAIN_NUMA)

This will make it more cleaner and will help changes isolated to one place if there are 'common' issues.

Appreciate if you can let me know if my thinking aligns with the correct implementation.

Thanks and best regards,

Sudheendra G Sampath

#23 lore raw

RE: [PATCH v5 v5 2/3] app: add topology aware test case

In reply to Vipin Varghese

[AMD Official Use Only - AMD Internal Distribution Only]

Snipped

Quoted 935 lines

#include "test.h"

app/test/test_ring_perf.c +18 -3
@@ -74,7 +77,7 @@ test_ring_print_test_string(unsigned int api_type, int esize,
 static int
 get_two_hyperthreads(struct lcore_pair *lcp)
 {
-       unsigned id1, id2;
+       unsigned int id1, id2;
        unsigned c1, c2, s1, s2;
        RTE_LCORE_FOREACH(id1) {
                /* inner loop just re-reads all id's. We could skip the first few
@@ -101,7 +104,7 @@ get_two_hyperthreads(struct lcore_pair *lcp)
 static int
 get_two_cores(struct lcore_pair *lcp)
 {
-       unsigned id1, id2;
+       unsigned int id1, id2;
        unsigned c1, c2, s1, s2;
        RTE_LCORE_FOREACH(id1) {
                RTE_LCORE_FOREACH(id2) {
@@ -125,7 +128,7 @@ get_two_cores(struct lcore_pair *lcp)
 static int
 get_two_sockets(struct lcore_pair *lcp)
 {
-       unsigned id1, id2;
+       unsigned int id1, id2;
        unsigned s1, s2;
        RTE_LCORE_FOREACH(id1) {
                RTE_LCORE_FOREACH(id2) {
@@ -143,6 +146,359 @@ get_two_sockets(struct lcore_pair *lcp)
        return 1;
 }
 
+#ifdef RTE_LIBHWLOC_PROBE
+static int
+get_same_numa_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_NUMA) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_NUMA) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if

(rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_NUMA, domain) <
2)

app/test/test_ring_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_NUMA);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_NUMA);

app/test/test_ring_perf.c +28 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_same_l4_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L4) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L4) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L4,

domain) < 2)

app/test/test_ring_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L4);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_L4);

app/test/test_ring_perf.c +26 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+       return 0;
+}
+
+static int
+get_same_l3_domains(struct lcore_pair *lcp)
+{      if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L3) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L3) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L3,

domain) < 2)

app/test/test_ring_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L3);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_L3);

app/test/test_ring_perf.c +28 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+
+}
+
+static int
+get_same_l2_domains(struct lcore_pair *lcp)
+{      if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L2) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L2) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L2,

domain) < 2)

app/test/test_ring_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L2);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_L2);

app/test/test_ring_perf.c +29 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+
+}
+
+static int
+get_same_l1_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L1) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L1) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L1,

domain) < 2)

app/test/test_ring_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L1);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,
RTE_TOPO_DOMAIN_L1);

app/test/test_ring_perf.c +28 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+
+}
+static int
+get_two_numa_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_NUMA) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_NUMA) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if

(rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_NUMA, domain) == 0)

app/test/test_ring_perf.c +40 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, RTE_TOPO_DOMAIN_NUMA);
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, RTE_TOPO_DOMAIN_NUMA);
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_l4_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L4) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L4) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L4,

domain) == 0)

app/test/test_ring_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L4);

app/test/test_ring_perf.c +4 -0
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L4);

app/test/test_ring_perf.c +28 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+       return 0;
+}
+
+static int
+get_two_l3_domains(struct lcore_pair *lcp)
+{      if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L3) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L3) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L3,

domain) == 0)

app/test/test_ring_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L3);

app/test/test_ring_perf.c +4 -0
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L3);

app/test/test_ring_perf.c +30 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+
+}
+
+static int
+get_two_l2_domains(struct lcore_pair *lcp)
+{      if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L2) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L2) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L2,

domain) == 0)

app/test/test_ring_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L2);

app/test/test_ring_perf.c +4 -0
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L2);

app/test/test_ring_perf.c +31 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+
+}
+
+static int
+get_two_l1_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L1) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L1) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L1,

domain) == 0)

app/test/test_ring_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L1);

app/test/test_ring_perf.c +4 -0
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L1);

app/test/test_ring_perf.c +72 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+
+}
+#endif
+
 /* Get cycle counts for dequeuing from an empty ring. Should be 2 or 3 cycles */
 static void
 test_empty_dequeue(struct rte_ring *r, const int esize,
@@ -488,6 +844,60 @@ test_ring_perf_esize_run_on_two_cores(
                if (run_on_core_pair(&cores, param1, param2) < 0)
                        return -1;
        }
+#ifdef RTE_LIBHWLOC_PROBE
+       if (rte_lcore_count() > 2) {
+               if (get_same_numa_domains(&cores) == 0) {
+                       printf("\n### Testing using same numa domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_same_l4_domains(&cores) == 0) {
+                       printf("\n### Testing using same l4 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_same_l3_domains(&cores) == 0) {
+                       printf("\n### Testing using same l3 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_same_l2_domains(&cores) == 0) {
+                       printf("\n### Testing using same l2 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_same_l1_domains(&cores) == 0) {
+                       printf("\n### Testing using same l1 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_two_numa_domains(&cores) == 0) {
+                       printf("\n### Testing using two numa domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_two_l4_domains(&cores) == 0) {
+                       printf("\n### Testing using two l4 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_two_l3_domains(&cores) == 0) {
+                       printf("\n### Testing using two l3 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_two_l2_domains(&cores) == 0) {
+                       printf("\n### Testing using two l2 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+               if (get_two_l1_domains(&cores) == 0) {
+                       printf("\n### Testing using two l1 domain nodes ###\n");
+                       if (run_on_core_pair(&cores, param1, param2) < 0)
+                               return -1;
+               }
+       }
+#endif
        return 0;
 }
 
app/test/test_stack_perf.c +18 -0
index 3f17a2606c..e5b038a3e8 100644
@@ -10,6 +10,9 @@
 #include <rte_launch.h>
 #include <rte_pause.h>
 #include <rte_stack.h>
+#ifdef RTE_LIBHWLOC_PROBE
+#include <rte_topology.h>
+#endif
 
 #include "test.h"
 
@@ -105,6 +108,367 @@ get_two_sockets(struct lcore_pair *lcp)
        return 1;
 }
 
+#ifdef RTE_LIBHWLOC_PROBE
+static int
+get_same_numa_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_NUMA) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_NUMA) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if

(rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_NUMA, domain) <
2)

app/test/test_stack_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_NUMA);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_NUMA);

app/test/test_stack_perf.c +28 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_same_l4_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L4) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L4) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L4,

domain) < 2)

app/test/test_stack_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L4);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_L4);

app/test/test_stack_perf.c +28 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_same_l3_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L3) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L3) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L3,

domain) < 2)

app/test/test_stack_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L3);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_L3);

app/test/test_stack_perf.c +28 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_same_l2_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L2) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L2) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L2,

domain) < 2)

app/test/test_stack_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L2);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0,
RTE_TOPO_DOMAIN_L2);

app/test/test_stack_perf.c +25 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_same_l1_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L1) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L1) {
+               if (rte_topo_is_main_lcore_in_domain(domain,

RTE_TOPO_DOMAIN_L1))

app/test/test_stack_perf.c +6 -0
+                       continue;
+
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L1,

domain) < 2)

app/test/test_stack_perf.c +3 -0
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L1);
+ id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,
RTE_TOPO_DOMAIN_L1);

app/test/test_stack_perf.c +27 -0
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+static int
+get_two_numa_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_NUMA) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_NUMA) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if

(rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_NUMA, domain) == 0)

app/test/test_stack_perf.c +41 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, RTE_TOPO_DOMAIN_NUMA);
+                       continue;
+               }
+
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, RTE_TOPO_DOMAIN_NUMA);
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_l4_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L4) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L4) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L4,

domain) == 0)

app/test/test_stack_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L4);

app/test/test_stack_perf.c +4 -0
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L4);

app/test/test_stack_perf.c +30 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_l3_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L3) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L3) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L3,

domain) == 0)

app/test/test_stack_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L3);

app/test/test_stack_perf.c +5 -0
+                       continue;
+               }
+
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L3);

app/test/test_stack_perf.c +30 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_l2_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L2) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L2) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L2,

domain) == 0)

app/test/test_stack_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L2);

app/test/test_stack_perf.c +5 -0
+                       continue;
+               }
+
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L2);

app/test/test_stack_perf.c +30 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_l1_domains(struct lcore_pair *lcp)
+{
+       if (rte_topo_get_domain_count(RTE_TOPO_DOMAIN_L1) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, RTE_TOPO_DOMAIN_L1) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(RTE_TOPO_DOMAIN_L1,

domain) == 0)

app/test/test_stack_perf.c +4 -0
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L1);

app/test/test_stack_perf.c +5 -0
+                       continue;
+               }
+
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,

RTE_TOPO_DOMAIN_L1);

app/test/test_stack_perf.c +56 -0
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+#endif
+
+
 /* Measure the cycle cost of popping an empty stack. */
 static void
 test_empty_pop(struct rte_stack *s)
@@ -331,6 +695,51 @@ __test_stack_perf(uint32_t flags)
                run_on_core_pair(&cores, s, bulk_push_pop);
        }
 
+#ifdef RTE_LIBHWLOC_PROBE
+       if (rte_lcore_count() > 2) {
+               if (get_same_numa_domains(&cores) == 0) {
+                       printf("\n### Testing using same numa domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_same_l4_domains(&cores) == 0) {
+                       printf("\n### Testing using same l4 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_same_l3_domains(&cores) == 0) {
+                       printf("\n### Testing using same l3 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_same_l2_domains(&cores) == 0) {
+                       printf("\n### Testing using same l2 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_same_l1_domains(&cores) == 0) {
+                       printf("\n### Testing using same l1 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_two_numa_domains(&cores) == 0) {
+                       printf("\n### Testing using two numa domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_two_l4_domains(&cores) == 0) {
+                       printf("\n### Testing using two l4 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_two_l3_domains(&cores) == 0) {
+                       printf("\n### Testing using two l3 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+               if (get_two_l2_domains(&cores) == 0) {
+                       printf("\n### Testing using two l2 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }

app/test/test_stack_perf.c __test_stack_perf(uint32_t flags) · line 745

Quoted 10 lines
app/test/test_stack_perf.c +7 -0
+               if (get_two_l1_domains(&cores) == 0) {
+                       printf("\n### Testing using two l1 domain nodes ###\n");
+                       run_on_core_pair(&cores, s, bulk_push_pop);
+               }
+       }
+#endif
+
        printf("\n### Testing on all %u lcores ###\n", rte_lcore_count());
        run_on_n_cores(s, bulk_push_pop, rte_lcore_count());
 

<snipped>

Unable to find Sudheendra Sampath in dpdk mailing list and Slack. Can you please connect with me email address or slack.

#24 lore raw

RE: [PATCH v5 v5 2/3] app: add topology aware test case

[Public]

<snipped>

Quoted 3 lines

Unable to find Sudheendra Sampath in dpdk mailing list and Slack. Can you please connect with me email address or slack.

Hi Sudheendra,

Thank you for the suggestion and welcome to dpdk review too.

My initial code design were

```
#ifdef RTE_LIBHWLOC_PROBE
+static int
+get_same_domains(struct lcore_pair *lcp, uint32_t domain_sel)
+{
+       if (rte_topo_get_domain_count(domain_sel) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, domain_sel) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(domain_sel, domain) < 2)
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, domain_sel);
+               id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0, domain_sel);
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_domains(struct lcore_pair *lcp, uint32_t domain_sel)
+{
+       if (rte_topo_get_domain_count(domain_sel) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, domain_sel) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(domain_sel, domain) == 0)
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, domain_sel);
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, domain_sel);
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+#endif
+
 /* Get cycle counts for dequeuing from an empty ring. Should be 2 or 3 cycles */
 static void
 test_empty_dequeue(struct rte_ring *r, const int esize,
@@ -488,6 +574,33 @@ test_ring_perf_esize_run_on_two_cores(
                if (run_on_core_pair(&cores, param1, param2) < 0)
                        return -1;
        }
+#ifdef RTE_LIBHWLOC_PROBE
+       if (rte_lcore_count() > 2) {
+               for (uint32_t d = 0; d < RTE_DIM(domain_types); d++) {
+                       if (get_same_domains(&cores, domain_types[d]) == 0) {
+                               printf("\n### Testing using same %s domain nodes ###\n",
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_NUMA) ? "NUMA" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L4) ? "L4" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L3) ? "L3" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L2) ? "L2" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L1) ? "L1" : NULL);
+                               if (run_on_core_pair(&cores, param1, param2) < 0)
+                                       return -1;
+                       }
+
+                       if (get_two_domains(&cores, domain_types[d]) == 0) {
+                               printf("\n### Testing using two %s domain nodes ###\n",
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_NUMA) ? "NUMA" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L4) ? "L4" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L3) ? "L3" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L2) ? "L2" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L1) ? "L1" : NULL);
+                               if (run_on_core_pair(&cores, param1, param2) < 0)
+                                       return -1;
+                       }
+               }
+       }
+#endif
        return 0;
 }

```

Since it breaks the current function test format, I went ahead with current approach. I will re-introduce the domain iterator design in v6 for you. Please try it out and let me know.

Regards
Vipin Varghese

#25 lore raw

RE: [PATCH v5 v5 2/3] app: add topology aware test case

[Public]

Sudhhendra and myself were able to connect over Slack. Adding his email address to the loop of reply .

Sudhendra please check the reply posted below

Quoted 146 lines

-----Original Message-----
From: Varghese, Vipin <[email protected]>
Sent: Thursday, April 16, 2026 6:50 PM
To: [email protected]; Tummala, Sivaprasad <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v5 v5 2/3] app: add topology aware test case

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

[Public]

<snipped>

Quoted 3 lines

Unable to find Sudheendra Sampath in dpdk mailing list and Slack. Can you please connect with me email address or slack.

Hi Sudheendra,

Thank you for the suggestion and welcome to dpdk review too.

My initial code design were

```
#ifdef RTE_LIBHWLOC_PROBE

app/test/test_ring_perf.c +71 -0
+static int
+get_same_domains(struct lcore_pair *lcp, uint32_t domain_sel) {
+       if (rte_topo_get_domain_count(domain_sel) == 0)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, domain_sel) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(domain_sel, domain) < 2)
+                       continue;
+
+               id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, domain_sel);
+               id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0, domain_sel);
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+
+static int
+get_two_domains(struct lcore_pair *lcp, uint32_t domain_sel) {
+       if (rte_topo_get_domain_count(domain_sel) < 2)
+               return 1;
+
+       unsigned int id1 = RTE_MAX_LCORE, id2 = RTE_MAX_LCORE;
+       unsigned int domain = 0;
+
+       RTE_TOPO_FOREACH_DOMAIN(domain, domain_sel) {
+               if ((id1 != RTE_MAX_LCORE) && (id2 != RTE_MAX_LCORE))
+                       break;
+
+               if (rte_topo_get_lcore_count_from_domain(domain_sel, domain) == 0)
+                       continue;
+
+               if (id1 == RTE_MAX_LCORE) {
+                       id1 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, domain_sel);
+                       continue;
+               }
+               if (id2 == RTE_MAX_LCORE) {
+                       id2 = rte_topo_get_nth_lcore_from_domain(domain,
+                               0, 0, domain_sel);
+                       continue;
+               }
+       }
+
+       if ((id1 == RTE_MAX_LCORE) || (id2 == RTE_MAX_LCORE))
+               return 2;
+
+       if (id1 == id2)
+               return 3;
+
+       lcp->c1 = id1;
+       lcp->c2 = id2;
+
+       return 0;
+}
+#endif
+
 /* Get cycle counts for dequeuing from an empty ring. Should be 2 or 3 cycles */

static void test_empty_dequeue(struct rte_ring *r, const int esize, @@ -488,6 +574,33 @@ test_ring_perf_esize_run_on_two_cores(

                if (run_on_core_pair(&cores, param1, param2) < 0)
                        return -1;
        }
(quoted diff) +6 -0
+#ifdef RTE_LIBHWLOC_PROBE
+       if (rte_lcore_count() > 2) {
+               for (uint32_t d = 0; d < RTE_DIM(domain_types); d++) {
+                       if (get_same_domains(&cores, domain_types[d]) == 0) {
+                               printf("\n### Testing using same %s domain nodes ###\n",
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_NUMA) ?

"NUMA" :

app/test/test_topology.c new file +4 -0
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L4) ? "L4" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L3) ? "L3" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L2) ? "L2" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L1) ? "L1" :

NULL);

(quoted diff) +7 -0
+                               if (run_on_core_pair(&cores, param1, param2) < 0)
+                                       return -1;
+                       }
+
+                       if (get_two_domains(&cores, domain_types[d]) == 0) {
+                               printf("\n### Testing using two %s domain nodes ###\n",
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_NUMA) ?

"NUMA" :

app/test/test_topology.c new file +4 -0
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L4) ? "L4" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L3) ? "L3" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L2) ? "L2" :
+                                       (domain_types[d] == RTE_TOPO_DOMAIN_L1) ? "L1" :

NULL);

app/test/test_ring_perf.c +6 -0
+                               if (run_on_core_pair(&cores, param1, param2) < 0)
+                                       return -1;
+                       }
+               }
+       }
+#endif
        return 0;
 }

```

Since it breaks the current function test format, I went ahead with current approach. I will re-introduce the domain iterator design in v6 for you. Please try it out and let me know.

Regards
Vipin Varghese

#26 lore raw

Re: [PATCH v5 v5 2/3] app: add topology aware test case

Hi Vipin,

Pardon my ignorance. I am not sure I understand what you mean by "current function test format".

Can you let me know where I can read about the current function test format ?

Thanks

Sudheendra Sampath

#27 lore raw

RE: [PATCH v5 v5 2/3] app: add topology aware test case

[AMD Official Use Only - AMD Internal Distribution Only]

<snipped>

Quoted 8 lines

Hi Vipin,

Pardon my ignorance. I am not sure I understand what you mean by "current function test format".

Can you let me know where I can read about the current function test format ?

I read the test code and understand each test call is individual test function from the main function. There do not have iterator or helper function supporting it.

But I shared already my initial design, and reason why I did not submit it.

I mentioned in my email, I can submit the same design for you in v6.

Let me know if you have any questions for the same?

Quoted 4 lines

Thanks

Sudheendra Sampath

#28 lore raw

PATCH v5 3/3 doc: add new section topology

In reply to Vipin Varghese

changes:
- add new section under utility
- include rte_topo API and usuage

---
 doc/api/doxy-api-index.md              |   1 +
 doc/guides/prog_guide/index.rst        |   3 +-
 doc/guides/prog_guide/topology_lib.rst | 155 +++++++++++++++++++++++++
 3 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 doc/guides/prog_guide/topology_lib.rst
doc/api/doxy-api-index.md +1 -0
index 9296042119..e8655fb956 100644
@@ -102,6 +102,7 @@ The public API headers are grouped by topics:
   [interrupts](@ref rte_interrupts.h),
   [launch](@ref rte_launch.h),
   [lcore](@ref rte_lcore.h),
+  [topology](@ref rte_topology.h),
   [service cores](@ref rte_service.h),
   [keepalive](@ref rte_keepalive.h),
   [power/freq](@ref rte_power_cpufreq.h),
doc/guides/prog_guide/index.rst +2 -1
index e6f24945b0..8e1153acef 100644
@@ -133,9 +133,10 @@ Utility Libraries
     pcapng_lib
     bpf_lib
     trace_lib
+    topology_lib
 
 
-Howto Guides
+How to Guides
 -------------
 
 .. toctree::
doc/guides/prog_guide/topology_lib.rst new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
2.43.0
#29 lore raw

Re: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

In reply to Vipin Varghese
Quoted 89 lines · On Wed, 15 Apr 2026 01:08:18 +0530 Vipin Varghese <[email protected]>…

This series introduces a topology library that groups DPDK lcores based on CPU cache hierarchy and NUMA topology. The goal is to provide a stable and explicit API that allows applications to select lcores with better locality and cache sharing characteristics.

The series includes:
- EAL support for topology discovery using hwloc and domain-based lcore

    grouping (L1/L2/L3/L4/NUMA)

- Topology-aware test cases validating API behavior and edge conditions
- Programmer’s guide describing the topology library and APIs

The API is marked experimental and does not change existing lcore behavior unless explicitly used by the application.

Changes in v5:
- Addressed review comments from v4
- Fixed ARM cross-compilation issues
- Cleaned up domain iteration and error handling
- Updated tests to cover domain edge cases
- Documentation refinements and API usage clarification

Changes in v4:
- Corrected domain selection semantics
- Updated example usage
- Fixed naming and typo issues

Changes in v3:
- Fixed macro naming (USE_NO_TOPOLOGY)
- Minor cleanups based on early feedback

Tested on:
- AMD EPYC (Milan, Genoa, Siena, Turin, Turin-Dense, Sorano)
- Intel Xeon (SPR-SP, GNR-SP)
- ARM Ampere
- NVIDIA Grace Superchip

Dependencies:
- hwloc-dev (tested with 2.10.0)

Patch breakdown:
1/3 eal/topology: add topology grouping for lcores 2/3 app: add topology-aware test cases
3/3 doc: add topology library documentation

Future Work:
- integrate into examples
-- hellowrld: ready
-- pkt-distributor: in-progress
-- l2fwd: ready
-- l3fwd: to start
-- eventdevpipeline: PoC ready
- integrate topology test
-- crypto: yet to start
-- compression: yet to start
-- dma: PoC ready
- add new features for
-- PQoS: yet to start
-- Data Injection: PoC with BRDCM Thor-2 ready

Tested OS: Linux only, need help with BSD and Windows

Tested with and without hwloc-dev library for
- Ampere, aarch64, Neoverse-N1, NUMA-2, 256 CPU threads
- Grace superchip, aarch64, Neoverse-V2, NUMA-2, 144 CPU threads
- Intel GNR-SP, 6767P, NUMA-2, 256 Threads
- AMD EPYC Siena, 8534P, NUMA-1, 128 Threads
- AMD EPYC Sorano, 8635P, NUMA-1, 168 Threads

``

Vipin Varghese (3):
eal/topology: add Topology grouping for lcores
app: add topology aware test case
doc: add new section topology

 app/test/meson.build                   |   1 +
 app/test/test_ring_perf.c              | 416 +++++++++++++-
 app/test/test_stack_perf.c             | 409 ++++++++++++++
 app/test/test_topology.c               | 676 ++++++++++++++++++++++
 config/meson.build                     |  18 +
 doc/api/doxy-api-index.md              |   1 +
 doc/guides/prog_guide/index.rst        |   3 +-
 doc/guides/prog_guide/topology_lib.rst | 155 +++++
 lib/eal/common/eal_private.h           |  74 +++
 lib/eal/common/eal_topology.c          | 747 +++++++++++++++++++++++++
 lib/eal/common/meson.build             |   1 +
 lib/eal/freebsd/eal.c                  |  10 +-
 lib/eal/include/meson.build            |   1 +
Quoted 9 lines
 lib/eal/include/rte_topology.h         | 255 +++++++++
 lib/eal/linux/eal.c                    |   7 +
 lib/eal/meson.build                    |   4 +
 16 files changed, 2773 insertions(+), 5 deletions(-)
 create mode 100644 app/test/test_topology.c
 create mode 100644 doc/guides/prog_guide/topology_lib.rst
 create mode 100644 lib/eal/common/eal_topology.c
 create mode 100644 lib/eal/include/rte_topology.h

AI review reported lots of possible correctness problems:

# DPDK Patch Review - bundle-1843-topology-v5.mbox

## Overview

This patch series introduces topology awareness to DPDK, allowing applications to select logical cores based on CPU cache and I/O topology. The series adds a new rte_topology library with APIs to query and enumerate logical cores within topology domains (L1/L2/L3/L4/NUMA).

---

## Correctness Bugs (HIGHEST PRIORITY - report at >=50% confidence)

### Patch 1/3: lib/eal/common/eal_topology.c

#### **Error: Resource leak on eal_topology_map_layer() failure**

In rte_eal_topology_init(), if any call to eal_topology_map_layer() fails (returns < 0), the code calls rte_eal_topology_release() which frees previously allocated layers. However, the hwloc_topology_t handle topo_cnfg.topology is **NOT** destroyed before returning. This leaks the hwloc topology handle.

**Location:** lib/eal/common/eal_topology.c:685-712

```c
for (int i = 0; i < 5; i++) {
    *layers[i].count = hwloc_get_nbobjs_by_depth(topo_cnfg.topology, layers[i].depth);
    if (eal_topology_map_layer(topo_cnfg.topology, layers[i].depth, layers[i].count,
        layers[i].ptr, layers[i].total_cores, layers[i].name) < 0) {
        rte_eal_topology_release();  /* frees layer memory */
        return -1;  /* BUG: topo_cnfg.topology NOT destroyed here */
    }
}

hwloc_topology_destroy(topo_cnfg.topology);  /* only reached on success */
topo_cnfg.topology = NULL;
```

**Fix:** Destroy the topology before returning on error:

```c
if (eal_topology_map_layer(...) < 0) {
    hwloc_topology_destroy(topo_cnfg.topology);
    topo_cnfg.topology = NULL;
    rte_eal_topology_release();
    return -1;
}
```

---

#### **Error: Potential use-after-free in eal_topology_map_layer() on partial allocation failure**

In eal_topology_map_layer(), the code allocates dm->cores for each domain. If a later allocation in the same loop iteration fails (e.g., for domain j+1), the function returns -1 immediately **without freeing dm->cores already allocated for earlier domains**. The caller (rte_eal_topology_init()) then calls rte_eal_topology_release(), which expects layer_ptr[j] to be non-NULL but layer_ptr[j]->cores may be uninitialized or garbage if the allocation failed before that point. This can cause a use-after-free or double-free when rte_eal_topology_release() calls rte_free(d->map[i]->cores).

**Location:** lib/eal/common/eal_topology.c:537-557

```c
for (uint16_t j = 0; j < *layer_cnt; j++) {
    hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, j);
    int cpu_count = hwloc_bitmap_weight(obj->cpuset);
    if (cpu_count == -1)
        continue;

    struct core_domain_mapping *dm =
        rte_zmalloc(NULL, sizeof(struct core_domain_mapping), 0);
    if (!dm)
        return -1;  /* BUG: leaks layer_ptr array allocated by caller */

    (*layer_ptr)[j] = dm;
    CPU_ZERO(&dm->core_set);
    dm->core_count = 0;

    dm->cores = rte_malloc(NULL, sizeof(uint16_t) * cpu_count, 0);
    if (!dm->cores)
        return -1;  /* BUG: leaks dm (just allocated) and previous entries */
}
```

**Fix:** On allocation failure, free all previously allocated entries before returning:

```c
if (!dm) {
    /* Free all previously allocated entries */
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}

/* Same cleanup for dm->cores allocation failure */
if (!dm->cores) {
    rte_free(dm);
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}
```

---

#### **Error: NULL pointer dereference in eal_topology_map_layer() when hwloc_get_obj_by_depth() returns NULL**

In the second loop of eal_topology_map_layer() (lines 560-620), the code calls hwloc_get_obj_by_depth(topology, depth, j) and checks if (!obj || hwloc_bitmap_iszero(obj->cpuset)) to skip NULL objects. However, in the **inner loop** (lines 579-618), the code calls hwloc_get_obj_by_depth(topology, depth, k) and assigns it to obj_core but does **NOT** check if obj_core is NULL before calling hwloc_bitmap_weight(obj_core->cpuset) on line 581. If hwloc_get_obj_by_depth() returns NULL for domain k, this will dereference a NULL pointer.

**Location:** lib/eal/common/eal_topology.c:579-582

```c
for (uint16_t k = 0; k < *layer_cnt; k++) {
    hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k);
    int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);  /* NULL deref if obj_core == NULL */
    if (cpu_count_core == -1)
        continue;
```

**Fix:** Check obj_core before dereferencing:

```c
hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k);
if (!obj_core)
    continue;
int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);
if (cpu_count_core == -1)
    continue;
```

---

#### **Error: Incorrect second argument to rte_topo_get_nth_lcore_from_domain() in get_same_l1_domains() (test_ring_perf.c and test_stack_perf.c)**

In both app/test/test_ring_perf.c:290 and app/test/test_stack_perf.c:258, the function get_same_l1_domains() calls:

```c
id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, RTE_TOPO_DOMAIN_L1);
```

The second argument (lcore_pos) is 0, which is the same as for id1. This will assign **the same lcore** to both id1 and id2, causing the subsequent check if (id1 == id2) return 3; to always trigger. This is a logic error: the intent is clearly to get two **different** lcores from the same domain.

**Location:** app/test/test_ring_perf.c:287-290 and app/test/test_stack_perf.c:255-258

**Fix:** Use position 1 for the second lcore:

```c
id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, RTE_TOPO_DOMAIN_L1);
id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0, RTE_TOPO_DOMAIN_L1);
```

---

#### **Error: Iteration condition in test_main_lcore_in_domain() uses wrong domain type for lookup**

In app/test/test_topology.c:211, the loop iterates over domain_count for domain_types[d], but the call to rte_topo_is_main_lcore_in_domain() uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]. This means the test only checks the NUMA domain regardless of which domain type d selects (L1/L2/L3/L4).

**Location:** app/test/test_topology.c:206-216

```c
for (unsigned int d = 0; d < RTE_DIM(domain_types); d++) {
    bool main_lcore_found = false;
    unsigned int domain_count = rte_topo_get_domain_count(domain_types[d]);
    for (unsigned int dmn_idx = 0; dmn_idx < domain_count; dmn_idx++) {
        main_lcore_found = rte_topo_is_main_lcore_in_domain(RTE_TOPO_DOMAIN_NUMA,  /* BUG: should be domain_types[d] */
            dmn_idx);
        if (main_lcore_found)
            break;
    }
```

**Fix:**

```c
main_lcore_found = rte_topo_is_main_lcore_in_domain(domain_types[d], dmn_idx);
```

---

#### **Error: Infinite loop risk in rte_topo_get_nth_lcore_from_domain() when ptr->core_count is 0**

In lib/eal/common/eal_topology.c:296-318, the function enters a while (1) loop that increments new_lcore_pos. If ptr->core_count is 0 (which the code checks earlier but does not return immediately), the loop will wrap new_lcore_pos back to 0 indefinitely, never breaking. While the function returns RTE_MAX_LCORE if ptr->core_count == 0 before the loop, the logic flow is unclear and the loop body does not have a clear termination condition if the core count is 0.

**Location:** lib/eal/common/eal_topology.c:283-318

**Fix:** Add a sanity check inside the loop to prevent infinite iteration:

```c
unsigned int iterations = 0;
while (1) {
    if (iterations++ > ptr->core_count * 2)  /* safety limit */
        return RTE_MAX_LCORE;
    /* ... rest of loop ... */
}
```

However, the real issue is that the code already returns RTE_MAX_LCORE if ptr->core_count == 0 on line 287, so this is more of a defensive-programming note. The function should be refactored for clarity.

---

#### **Error: Missing NULL check after get_domain_lcore_mapping() in rte_topo_get_next_lcore()**

In rte_topo_get_next_lcore(), the code calls get_domain_lcore_mapping(flag, lcore_domain) and checks if ptr is NULL on line 350. However, if ptr is NULL, the function returns RTE_MAX_LCORE. This is correct, but the subsequent logic on line 381 calls rte_topo_is_main_lcore_in_domain(flag, lcore_domain), which internally may call get_domain_lcore_mapping() again. If that call also returns NULL (which it will if the domain is invalid), the function rte_topo_is_main_lcore_in_domain() will return false, which is safe. However, the logic is fragile and should explicitly handle the NULL case to avoid relying on transitive safety.

**Location:** lib/eal/common/eal_topology.c:381

**Recommendation:** The code is technically safe but could be clearer. No change required, but consider restructuring for maintainability.

---

### Patch 2/3: app/test Topology Tests

#### **Error: Macro RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN declares variable in macro expansion (shadowing risk)**

In lib/eal/include/rte_topology.h:243-248, the macro RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN declares a local variable main_lcore inside the macro expansion:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore, domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, flag);  \
    uint16_t main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag))
```

This can cause a compiler error or shadowing if the caller already has a variable named main_lcore in scope. Additionally, the macro uses domain (line 244) but the parameter is domain_indx, which is a typo and will cause a compilation error.

**Location:** lib/eal/include/rte_topology.h:243-248

**Fix:** Wrap in a do { } while (0) and use a uniquely-named variable, or document that the macro must not be used if main_lcore is already declared. Also fix the typo:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore, domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain_indx, 0, 0, flag);  \
    uint16_t __topo_main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != __topo_main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag))
```

---

### Summary of Correctness Bugs

1. **hwloc topology leak** on eal_topology_map_layer() failure
2. **Resource leak** in eal_topology_map_layer() on partial allocation failure
3. **NULL pointer dereference** in eal_topology_map_layer() inner loop
4. **Logic error** in get_same_l1_domains() (same lcore assigned to id1 and id2)
5. **Wrong domain type** in test_main_lcore_in_domain() (uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d])
6. **Macro typo** in RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN (uses domain instead of domain_indx)
7. **Potential infinite loop** in rte_topo_get_nth_lcore_from_domain() if ptr->core_count == 0 (mitigated by early

#30 lore raw

RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

AMD General

Sharing v6 with fixes and cache-id fetch shortly.

Quoted 431 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, April 15, 2026 1:52 AM
To: Varghese, Vipin <[email protected]>
Cc: [email protected]; Tummala, Sivaprasad <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 95 lines · On Wed, 15 Apr 2026 01:08:18 +0530 Vipin Varghese <[email protected]>…

This series introduces a topology library that groups DPDK lcores based on CPU cache hierarchy and NUMA topology. The goal is to provide a stable and explicit API that allows applications to select lcores with better locality and cache sharing characteristics.

The series includes:
- EAL support for topology discovery using hwloc and domain-based lcore

    grouping (L1/L2/L3/L4/NUMA)

- Topology-aware test cases validating API behavior and edge conditions
- Programmer’s guide describing the topology library and APIs

The API is marked experimental and does not change existing lcore behavior unless explicitly used by the application.

Changes in v5:
- Addressed review comments from v4
- Fixed ARM cross-compilation issues
- Cleaned up domain iteration and error handling
- Updated tests to cover domain edge cases
- Documentation refinements and API usage clarification

Changes in v4:
- Corrected domain selection semantics
- Updated example usage
- Fixed naming and typo issues

Changes in v3:
- Fixed macro naming (USE_NO_TOPOLOGY)
- Minor cleanups based on early feedback

Tested on:
- AMD EPYC (Milan, Genoa, Siena, Turin, Turin-Dense, Sorano)
- Intel Xeon (SPR-SP, GNR-SP)
- ARM Ampere
- NVIDIA Grace Superchip

Dependencies:
- hwloc-dev (tested with 2.10.0)

Patch breakdown:
1/3 eal/topology: add topology grouping for lcores 2/3 app: add topology-aware test cases
3/3 doc: add topology library documentation

Future Work:
- integrate into examples
-- hellowrld: ready
-- pkt-distributor: in-progress
-- l2fwd: ready
-- l3fwd: to start
-- eventdevpipeline: PoC ready
- integrate topology test
-- crypto: yet to start
-- compression: yet to start
-- dma: PoC ready
- add new features for
-- PQoS: yet to start
-- Data Injection: PoC with BRDCM Thor-2 ready

Tested OS: Linux only, need help with BSD and Windows

Tested with and without hwloc-dev library for
- Ampere, aarch64, Neoverse-N1, NUMA-2, 256 CPU threads
- Grace superchip, aarch64, Neoverse-V2, NUMA-2, 144 CPU threads
- Intel GNR-SP, 6767P, NUMA-2, 256 Threads
- AMD EPYC Siena, 8534P, NUMA-1, 128 Threads
- AMD EPYC Sorano, 8635P, NUMA-1, 168 Threads

Vipin Varghese (3):
eal/topology: add Topology grouping for lcores
app: add topology aware test case
doc: add new section topology

 app/test/meson.build                   |   1 +
 app/test/test_ring_perf.c              | 416 +++++++++++++-
 app/test/test_stack_perf.c             | 409 ++++++++++++++
 app/test/test_topology.c               | 676 ++++++++++++++++++++++
 config/meson.build                     |  18 +
 doc/api/doxy-api-index.md              |   1 +
 doc/guides/prog_guide/index.rst        |   3 +-
 doc/guides/prog_guide/topology_lib.rst | 155 +++++
 lib/eal/common/eal_private.h           |  74 +++
 lib/eal/common/eal_topology.c          | 747 +++++++++++++++++++++++++
 lib/eal/common/meson.build             |   1 +
 lib/eal/freebsd/eal.c                  |  10 +-
 lib/eal/include/meson.build            |   1 +
 lib/eal/include/rte_topology.h         | 255 +++++++++
 lib/eal/linux/eal.c                    |   7 +
 lib/eal/meson.build                    |   4 +
 16 files changed, 2773 insertions(+), 5 deletions(-)  create mode
100644 app/test/test_topology.c  create mode 100644
doc/guides/prog_guide/topology_lib.rst
 create mode 100644 lib/eal/common/eal_topology.c  create mode 100644
Quoted 2 lines

lib/eal/include/rte_topology.h

AI review reported lots of possible correctness problems:

# DPDK Patch Review - bundle-1843-topology-v5.mbox

## Overview

This patch series introduces topology awareness to DPDK, allowing applications to select logical cores based on CPU cache and I/O topology. The series adds a new rte_topology library with APIs to query and enumerate logical cores within topology domains (L1/L2/L3/L4/NUMA).

---

## Correctness Bugs (HIGHEST PRIORITY - report at >=50% confidence)

### Patch 1/3: lib/eal/common/eal_topology.c

#### **Error: Resource leak on eal_topology_map_layer() failure**

In rte_eal_topology_init(), if any call to eal_topology_map_layer() fails (returns < 0), the code calls rte_eal_topology_release() which frees previously allocated layers. However, the hwloc_topology_t handle topo_cnfg.topology is **NOT** destroyed before returning. This leaks the hwloc topology handle.

**Location:** lib/eal/common/eal_topology.c:685-712

```c
for (int i = 0; i < 5; i++) {
    *layers[i].count = hwloc_get_nbobjs_by_depth(topo_cnfg.topology,
layers[i].depth);
    if (eal_topology_map_layer(topo_cnfg.topology, layers[i].depth, layers[i].count,
        layers[i].ptr, layers[i].total_cores, layers[i].name) < 0) {
        rte_eal_topology_release();  /* frees layer memory */
        return -1;  /* BUG: topo_cnfg.topology NOT destroyed here */
    }
}

hwloc_topology_destroy(topo_cnfg.topology);  /* only reached on success */
topo_cnfg.topology = NULL; ```

**Fix:** Destroy the topology before returning on error:

```c
if (eal_topology_map_layer(...) < 0) {
    hwloc_topology_destroy(topo_cnfg.topology);
    topo_cnfg.topology = NULL;
    rte_eal_topology_release();
    return -1;
}
```

---

#### **Error: Potential use-after-free in `eal_topology_map_layer()` on partial
allocation failure**

In `eal_topology_map_layer()`, the code allocates `dm->cores` for each domain. If a
later allocation in the same loop iteration fails (e.g., for domain `j+1`), the function
returns -1 immediately **without freeing `dm->cores` already allocated for earlier
domains**. The caller (`rte_eal_topology_init()`) then calls
`rte_eal_topology_release()`, which expects `layer_ptr[j]` to be non-NULL but
`layer_ptr[j]->cores` may be uninitialized or garbage if the allocation failed before
that point. This can cause a use-after-free or double-free when
`rte_eal_topology_release()` calls `rte_free(d->map[i]->cores)`.

**Location:** `lib/eal/common/eal_topology.c:537-557`

```c
for (uint16_t j = 0; j < *layer_cnt; j++) {
    hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, j);
    int cpu_count = hwloc_bitmap_weight(obj->cpuset);
    if (cpu_count == -1)
        continue;

    struct core_domain_mapping *dm =
        rte_zmalloc(NULL, sizeof(struct core_domain_mapping), 0);
    if (!dm)
        return -1;  /* BUG: leaks layer_ptr array allocated by caller */

    (*layer_ptr)[j] = dm;
    CPU_ZERO(&dm->core_set);
    dm->core_count = 0;

    dm->cores = rte_malloc(NULL, sizeof(uint16_t) * cpu_count, 0);
    if (!dm->cores)
        return -1;  /* BUG: leaks dm (just allocated) and previous entries */ } ```

**Fix:** On allocation failure, free all previously allocated entries before returning:

```c
if (!dm) {
    /* Free all previously allocated entries */
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}

/* Same cleanup for dm->cores allocation failure */ if (!dm->cores) {
    rte_free(dm);
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}
```

---

#### **Error: NULL pointer dereference in eal_topology_map_layer() when hwloc_get_obj_by_depth() returns NULL**

In the second loop of eal_topology_map_layer() (lines 560-620), the code calls hwloc_get_obj_by_depth(topology, depth, j) and checks if (!obj || hwloc_bitmap_iszero(obj->cpuset)) to skip NULL objects. However, in the **inner loop** (lines 579-618), the code calls hwloc_get_obj_by_depth(topology, depth, k) and assigns it to obj_core but does **NOT** check if obj_core is NULL before calling hwloc_bitmap_weight(obj_core->cpuset) on line 581. If hwloc_get_obj_by_depth() returns NULL for domain k, this will dereference a NULL pointer.

**Location:** lib/eal/common/eal_topology.c:579-582

```c
for (uint16_t k = 0; k < *layer_cnt; k++) {
    hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k);
    int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);  /* NULL deref if
obj_core == NULL */
    if (cpu_count_core == -1)
        continue;
```

**Fix:** Check obj_core before dereferencing:

```c
hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k); if (!obj_core)
    continue;
int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);
if (cpu_count_core == -1)
    continue;
```

---

#### **Error: Incorrect second argument to rte_topo_get_nth_lcore_from_domain() in get_same_l1_domains() (test_ring_perf.c and test_stack_perf.c)**

In both app/test/test_ring_perf.c:290 and app/test/test_stack_perf.c:258, the function get_same_l1_domains() calls:

```c
id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,
RTE_TOPO_DOMAIN_L1); ```

The second argument (`lcore_pos`) is `0`, which is the same as for `id1`. This will
assign **the same lcore** to both `id1` and `id2`, causing the subsequent check `if
(id1 == id2) return 3;` to always trigger. This is a logic error: the intent is clearly to
get two **different** lcores from the same domain.

**Location:** `app/test/test_ring_perf.c:287-290` and
`app/test/test_stack_perf.c:255-258`

**Fix:** Use position `1` for the second lcore:

```c

id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, RTE_TOPO_DOMAIN_L1);
id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0, RTE_TOPO_DOMAIN_L1); ```

---

#### **Error: Iteration condition in test_main_lcore_in_domain() uses wrong domain type for lookup**

In app/test/test_topology.c:211, the loop iterates over domain_count for domain_types[d], but the call to rte_topo_is_main_lcore_in_domain() uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]. This means the test only checks the NUMA domain regardless of which domain type d selects (L1/L2/L3/L4).

**Location:** app/test/test_topology.c:206-216

```c
for (unsigned int d = 0; d < RTE_DIM(domain_types); d++) {
    bool main_lcore_found = false;
    unsigned int domain_count = rte_topo_get_domain_count(domain_types[d]);
    for (unsigned int dmn_idx = 0; dmn_idx < domain_count; dmn_idx++) {
        main_lcore_found =
rte_topo_is_main_lcore_in_domain(RTE_TOPO_DOMAIN_NUMA,  /* BUG: should
be domain_types[d] */
            dmn_idx);
        if (main_lcore_found)
            break;
    }
```

**Fix:**

```c
main_lcore_found = rte_topo_is_main_lcore_in_domain(domain_types[d], dmn_idx);
```

---

#### **Error: Infinite loop risk in rte_topo_get_nth_lcore_from_domain() when `ptr-

Quoted 1 line

core_count` is 0**

In lib/eal/common/eal_topology.c:296-318, the function enters a while (1) loop that increments new_lcore_pos. If ptr->core_count is 0 (which the code checks earlier but does not return immediately), the loop will wrap new_lcore_pos back to 0 indefinitely, never breaking. While the function returns RTE_MAX_LCORE if `ptr-

Quoted 1 line

core_count == 0` before the loop, the logic flow is unclear and the loop body does

not have a clear termination condition if the core count is 0.

**Location:** lib/eal/common/eal_topology.c:283-318

**Fix:** Add a sanity check inside the loop to prevent infinite iteration:

```c
unsigned int iterations = 0;
while (1) {
    if (iterations++ > ptr->core_count * 2)  /* safety limit */
        return RTE_MAX_LCORE;
    /* ... rest of loop ... */
}
```

However, the real issue is that the code already returns RTE_MAX_LCORE if ptr->core_count == 0 on line 287, so this is more of a defensive-programming note. The function should be refactored for clarity.

---

#### **Error: Missing NULL check after get_domain_lcore_mapping() in rte_topo_get_next_lcore()**

In rte_topo_get_next_lcore(), the code calls get_domain_lcore_mapping(flag, lcore_domain) and checks if ptr is NULL on line 350. However, if ptr is NULL, the function returns RTE_MAX_LCORE. This is correct, but the subsequent logic on line 381 calls rte_topo_is_main_lcore_in_domain(flag, lcore_domain), which internally may call get_domain_lcore_mapping() again. If that call also returns NULL (which it will if the domain is invalid), the function rte_topo_is_main_lcore_in_domain() will return false, which is safe. However, the logic is fragile and should explicitly handle the NULL case to avoid relying on transitive safety.

**Location:** lib/eal/common/eal_topology.c:381

**Recommendation:** The code is technically safe but could be clearer. No change required, but consider restructuring for maintainability.

---

### Patch 2/3: app/test Topology Tests

#### **Error: Macro RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN declares variable in macro expansion (shadowing risk)**

In lib/eal/include/rte_topology.h:243-248, the macro RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN declares a local variable main_lcore inside the macro expansion:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore,
domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, flag);  \
    uint16_t main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag)) ```

This can cause a compiler error or shadowing if the caller already has a variable
named `main_lcore` in scope. Additionally, the macro uses `domain` (line 244) but
the parameter is `domain_indx`, which is a typo and will cause a compilation error.

**Location:** `lib/eal/include/rte_topology.h:243-248`

**Fix:** Wrap in a `do { } while (0)` and use a uniquely-named variable, or document
that the macro must not be used if `main_lcore` is already declared. Also fix the
typo:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore,
domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain_indx, 0, 0, flag);  \
    uint16_t __topo_main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != __topo_main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag)) ```

---

### Summary of Correctness Bugs

1. **hwloc topology leak** on eal_topology_map_layer() failure 2. **Resource leak** in eal_topology_map_layer() on partial allocation failure 3. **NULL pointer dereference** in eal_topology_map_layer() inner loop 4. **Logic error** in get_same_l1_domains() (same lcore assigned to id1 and id2) 5. **Wrong domain type** in test_main_lcore_in_domain() (uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]) 6. **Macro typo** in RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN (uses domain
instead of domain_indx) 7. **Potential infinite loop** in rte_topo_get_nth_lcore_from_domain() if ptr->core_count == 0 (mitigated by early

#31 lore raw

RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

AMD General

Hi All,

Quick update, implementing CPU_ALLOC instead of rte_cpu_set is turing out to eat a lot of memory.

I am working on logic to use CPU_ALLOC when CPU_SIZE > rte_cpu_Set capacity or find smarter ways not to pre-alloc extra.

Note: for accommodating CPU alloc we need to do it for all valid l1, l2, l3 and l4. On 384 single socket machine it exhausts memory (heap) like anything.

Quoted 470 lines

-----Original Message-----
From: Varghese, Vipin <[email protected]>
Sent: Thursday, May 28, 2026 12:48 PM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; Tummala, Sivaprasad <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

AMD General

Sharing v6 with fixes and cache-id fetch shortly.

Quoted 132 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, April 15, 2026 1:52 AM
To: Varghese, Vipin <[email protected]>
Cc: [email protected]; Tummala, Sivaprasad <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 95 lines · On Wed, 15 Apr 2026 01:08:18 +0530 Vipin Varghese <[email protected]>…

This series introduces a topology library that groups DPDK lcores based on CPU cache hierarchy and NUMA topology. The goal is to provide a stable and explicit API that allows applications to select lcores with better locality and cache sharing characteristics.

The series includes:
- EAL support for topology discovery using hwloc and domain-based lcore

    grouping (L1/L2/L3/L4/NUMA)

- Topology-aware test cases validating API behavior and edge conditions
- Programmer’s guide describing the topology library and APIs

The API is marked experimental and does not change existing lcore behavior unless explicitly used by the application.

Changes in v5:
- Addressed review comments from v4
- Fixed ARM cross-compilation issues
- Cleaned up domain iteration and error handling
- Updated tests to cover domain edge cases
- Documentation refinements and API usage clarification

Changes in v4:
- Corrected domain selection semantics
- Updated example usage
- Fixed naming and typo issues

Changes in v3:
- Fixed macro naming (USE_NO_TOPOLOGY)
- Minor cleanups based on early feedback

Tested on:
- AMD EPYC (Milan, Genoa, Siena, Turin, Turin-Dense, Sorano)
- Intel Xeon (SPR-SP, GNR-SP)
- ARM Ampere
- NVIDIA Grace Superchip

Dependencies:
- hwloc-dev (tested with 2.10.0)

Patch breakdown:
1/3 eal/topology: add topology grouping for lcores 2/3 app: add topology-aware test cases
3/3 doc: add topology library documentation

Future Work:
- integrate into examples
-- hellowrld: ready
-- pkt-distributor: in-progress
-- l2fwd: ready
-- l3fwd: to start
-- eventdevpipeline: PoC ready
- integrate topology test
-- crypto: yet to start
-- compression: yet to start
-- dma: PoC ready
- add new features for
-- PQoS: yet to start
-- Data Injection: PoC with BRDCM Thor-2 ready

Tested OS: Linux only, need help with BSD and Windows

Tested with and without hwloc-dev library for
- Ampere, aarch64, Neoverse-N1, NUMA-2, 256 CPU threads
- Grace superchip, aarch64, Neoverse-V2, NUMA-2, 144 CPU threads
- Intel GNR-SP, 6767P, NUMA-2, 256 Threads
- AMD EPYC Siena, 8534P, NUMA-1, 128 Threads
- AMD EPYC Sorano, 8635P, NUMA-1, 168 Threads

Vipin Varghese (3):
eal/topology: add Topology grouping for lcores
app: add topology aware test case
doc: add new section topology

 app/test/meson.build                   |   1 +
 app/test/test_ring_perf.c              | 416 +++++++++++++-
 app/test/test_stack_perf.c             | 409 ++++++++++++++
 app/test/test_topology.c               | 676 ++++++++++++++++++++++
 config/meson.build                     |  18 +
 doc/api/doxy-api-index.md              |   1 +
 doc/guides/prog_guide/index.rst        |   3 +-
 doc/guides/prog_guide/topology_lib.rst | 155 +++++
 lib/eal/common/eal_private.h           |  74 +++
 lib/eal/common/eal_topology.c          | 747 +++++++++++++++++++++++++
 lib/eal/common/meson.build             |   1 +
 lib/eal/freebsd/eal.c                  |  10 +-
 lib/eal/include/meson.build            |   1 +
 lib/eal/include/rte_topology.h         | 255 +++++++++
 lib/eal/linux/eal.c                    |   7 +
 lib/eal/meson.build                    |   4 +
 16 files changed, 2773 insertions(+), 5 deletions(-)  create mode
100644 app/test/test_topology.c  create mode 100644
doc/guides/prog_guide/topology_lib.rst
 create mode 100644 lib/eal/common/eal_topology.c  create mode
Quoted 2 lines

100644 lib/eal/include/rte_topology.h

AI review reported lots of possible correctness problems:

# DPDK Patch Review - bundle-1843-topology-v5.mbox

## Overview

This patch series introduces topology awareness to DPDK, allowing applications to select logical cores based on CPU cache and I/O topology. The series adds a new rte_topology library with APIs to query and enumerate logical cores within topology domains (L1/L2/L3/L4/NUMA).

---

## Correctness Bugs (HIGHEST PRIORITY - report at >=50% confidence)

Quoted 8 lines

### Patch 1/3: lib/eal/common/eal_topology.c

#### **Error: Resource leak on eal_topology_map_layer() failure**

In rte_eal_topology_init(), if any call to eal_topology_map_layer() fails (returns < 0), the code calls rte_eal_topology_release() which frees previously allocated layers. However, the hwloc_topology_t handle topo_cnfg.topology is **NOT**

destroyed before returning. This leaks the hwloc topology handle.

Quoted 33 lines

**Location:** lib/eal/common/eal_topology.c:685-712

```c
for (int i = 0; i < 5; i++) {
    *layers[i].count = hwloc_get_nbobjs_by_depth(topo_cnfg.topology,
layers[i].depth);
    if (eal_topology_map_layer(topo_cnfg.topology, layers[i].depth, layers[i].count,
        layers[i].ptr, layers[i].total_cores, layers[i].name) < 0) {
        rte_eal_topology_release();  /* frees layer memory */
        return -1;  /* BUG: topo_cnfg.topology NOT destroyed here */
    }
}

hwloc_topology_destroy(topo_cnfg.topology);  /* only reached on
success */ topo_cnfg.topology = NULL; ```

**Fix:** Destroy the topology before returning on error:

```c
if (eal_topology_map_layer(...) < 0) {
    hwloc_topology_destroy(topo_cnfg.topology);
    topo_cnfg.topology = NULL;
    rte_eal_topology_release();
    return -1;
}

```

---

#### **Error: Potential use-after-free in eal_topology_map_layer() on partial allocation failure**

Quoted 8 lines

In eal_topology_map_layer(), the code allocates dm->cores for each domain. If a later allocation in the same loop iteration fails (e.g., for domain j+1), the function returns -1 immediately **without freeing dm->cores already allocated for earlier domains**. The caller (rte_eal_topology_init()) then calls rte_eal_topology_release(), which expects layer_ptr[j] to be non-NULL but layer_ptr[j]->cores may be uninitialized or garbage if the allocation failed before that point. This can cause a use-after-free or double-

free when rte_eal_topology_release() calls rte_free(d->map[i]->cores).

Quoted 58 lines

**Location:** lib/eal/common/eal_topology.c:537-557

```c
for (uint16_t j = 0; j < *layer_cnt; j++) {
    hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, j);
    int cpu_count = hwloc_bitmap_weight(obj->cpuset);
    if (cpu_count == -1)
        continue;

    struct core_domain_mapping *dm =
        rte_zmalloc(NULL, sizeof(struct core_domain_mapping), 0);
    if (!dm)
        return -1;  /* BUG: leaks layer_ptr array allocated by caller
*/

    (*layer_ptr)[j] = dm;
    CPU_ZERO(&dm->core_set);
    dm->core_count = 0;

    dm->cores = rte_malloc(NULL, sizeof(uint16_t) * cpu_count, 0);
    if (!dm->cores)
        return -1;  /* BUG: leaks dm (just allocated) and previous
entries */ } ```

**Fix:** On allocation failure, free all previously allocated entries before returning:

```c
if (!dm) {
    /* Free all previously allocated entries */
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}
/* Same cleanup for dm->cores allocation failure */ if (!dm->cores) {
    rte_free(dm);
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}

```

---

#### **Error: NULL pointer dereference in eal_topology_map_layer() when hwloc_get_obj_by_depth() returns NULL**

Quoted 9 lines

In the second loop of eal_topology_map_layer() (lines 560-620), the code calls hwloc_get_obj_by_depth(topology, depth, j) and checks if (!obj || hwloc_bitmap_iszero(obj->cpuset)) to skip NULL objects. However, in the **inner
loop** (lines 579-618), the code calls hwloc_get_obj_by_depth(topology, depth, k) and assigns it to obj_core but does **NOT** check if obj_core is NULL before calling hwloc_bitmap_weight(obj_core->cpuset) on line 581. If hwloc_get_obj_by_depth() returns NULL for domain k, this will dereference a

NULL pointer.

Quoted 65 lines

**Location:** lib/eal/common/eal_topology.c:579-582

```c
for (uint16_t k = 0; k < *layer_cnt; k++) {
    hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k);
    int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);  /*
NULL deref if obj_core == NULL */
    if (cpu_count_core == -1)
        continue;
```

**Fix:** Check obj_core before dereferencing:

```c
hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k); if (!obj_core)
    continue;
int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);
if (cpu_count_core == -1)
    continue;
```

---

#### **Error: Incorrect second argument to rte_topo_get_nth_lcore_from_domain() in get_same_l1_domains() (test_ring_perf.c and test_stack_perf.c)**

In both app/test/test_ring_perf.c:290 and app/test/test_stack_perf.c:258, the function get_same_l1_domains() calls:

```c
id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0,
RTE_TOPO_DOMAIN_L1); ```

The second argument (`lcore_pos`) is `0`, which is the same as for
`id1`. This will assign **the same lcore** to both `id1` and `id2`,
causing the subsequent check `if
(id1 == id2) return 3;` to always trigger. This is a logic error: the
intent is clearly to get two **different** lcores from the same domain.

**Location:** `app/test/test_ring_perf.c:287-290` and
`app/test/test_stack_perf.c:255-258`

**Fix:** Use position `1` for the second lcore:

```c

id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, RTE_TOPO_DOMAIN_L1);
id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0, RTE_TOPO_DOMAIN_L1); ```

---

#### **Error: Iteration condition in test_main_lcore_in_domain() uses wrong domain type for lookup**

In app/test/test_topology.c:211, the loop iterates over domain_count for domain_types[d], but the call to rte_topo_is_main_lcore_in_domain() uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]. This means the test only checks the NUMA domain regardless of which domain type d selects (L1/L2/L3/L4).

**Location:** app/test/test_topology.c:206-216

Quoted 7 lines

```c

for (unsigned int d = 0; d < RTE_DIM(domain_types); d++) {
    bool main_lcore_found = false;
    unsigned int domain_count = rte_topo_get_domain_count(domain_types[d]);
    for (unsigned int dmn_idx = 0; dmn_idx < domain_count; dmn_idx++) {
        main_lcore_found =

rte_topo_is_main_lcore_in_domain(RTE_TOPO_DOMAIN_NUMA, /* BUG:

should

Quoted 51 lines

be domain_types[d] */

            dmn_idx);
        if (main_lcore_found)
            break;
    }
```

**Fix:**

```c

main_lcore_found = rte_topo_is_main_lcore_in_domain(domain_types[d], dmn_idx); ```

---

#### **Error: Infinite loop risk in
rte_topo_get_nth_lcore_from_domain() when `ptr-

Quoted 1 line

core_count` is 0**

In lib/eal/common/eal_topology.c:296-318, the function enters a while (1) loop that increments new_lcore_pos. If ptr->core_count is 0 (which the code checks earlier but does not return immediately), the loop will wrap new_lcore_pos back to
0 indefinitely, never breaking. While the function returns RTE_MAX_LCORE if `ptr-

Quoted 2 lines

core_count == 0` before the loop, the logic flow is unclear and the loop body does

not have a clear termination condition if the core count is 0.

**Location:** lib/eal/common/eal_topology.c:283-318

**Fix:** Add a sanity check inside the loop to prevent infinite iteration:

```c
unsigned int iterations = 0;
while (1) {
    if (iterations++ > ptr->core_count * 2)  /* safety limit */
        return RTE_MAX_LCORE;
    /* ... rest of loop ... */
}
```

However, the real issue is that the code already returns RTE_MAX_LCORE if ptr->core_count == 0 on line 287, so this is more of a defensive-programming note. The function should be refactored for clarity.

---

#### **Error: Missing NULL check after get_domain_lcore_mapping() in rte_topo_get_next_lcore()**

Quoted 9 lines

In rte_topo_get_next_lcore(), the code calls get_domain_lcore_mapping(flag, lcore_domain) and checks if ptr is NULL on line 350. However, if ptr is NULL, the function returns RTE_MAX_LCORE. This is correct, but the subsequent logic on line 381 calls rte_topo_is_main_lcore_in_domain(flag, lcore_domain), which internally may call get_domain_lcore_mapping() again. If that call also returns NULL (which it will if the domain is invalid), the function rte_topo_is_main_lcore_in_domain() will return false, which is safe. However, the logic is fragile and should explicitly handle the NULL

case to avoid relying on transitive safety.

Quoted 11 lines

**Location:** lib/eal/common/eal_topology.c:381

**Recommendation:** The code is technically safe but could be clearer. No change required, but consider restructuring for maintainability.

---

### Patch 2/3: app/test Topology Tests

#### **Error: Macro

RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN

Quoted 4 lines

declares variable in macro expansion (shadowing risk)**

In lib/eal/include/rte_topology.h:243-248, the macro RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN declares a local

variable

Quoted 12 lines

main_lcore inside the macro expansion:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore,

domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, flag);  \
    uint16_t main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag)) ```
Quoted 3 lines

This can cause a compiler error or shadowing if the caller already has a variable named main_lcore in scope. Additionally, the macro uses domain (line 244) but the parameter is domain_indx, which is a typo and will

cause a compilation error.

Quoted 22 lines

**Location:** lib/eal/include/rte_topology.h:243-248

**Fix:** Wrap in a do { } while (0) and use a uniquely-named variable, or document that the macro must not be used if main_lcore is already declared. Also fix the
typo:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore,

domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain_indx, 0, 0, flag);  \
    uint16_t __topo_main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != __topo_main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag)) ```

---

### Summary of Correctness Bugs

Quoted 9 lines

1. **hwloc topology leak** on eal_topology_map_layer() failure 2. **Resource
leak** in eal_topology_map_layer() on partial allocation failure 3. **NULL pointer
dereference** in eal_topology_map_layer() inner loop 4. **Logic error** in get_same_l1_domains() (same lcore assigned to id1 and id2) 5. **Wrong domain type** in test_main_lcore_in_domain() (uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]) 6. **Macro typo** in RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN (uses domain

instead of

Quoted 3 lines

domain_indx) 7. **Potential infinite loop** in rte_topo_get_nth_lcore_from_domain() if ptr->core_count == 0 (mitigated by early

#32 lore raw

RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

AMD General

Hi All,

Sending out the patch for same with fixes, I tried my best to fix LLC probe in ARM on both Ampere and Nvidia Vera it fails. As LLC is not identified via sysfs tool.

Current patch is limited to x86 Linux only.

Can someone help me with Riscv and powerpc?

@Ajit Khaparde @Wathsala Wathawana Vithanage or @Honnappa Nagarahalli can you please help me with ARM Cache Probing alternative to SYSFS?

Regards
Vipin Varghese

Quoted 508 lines

-----Original Message-----
From: Varghese, Vipin <[email protected]>
Sent: Monday, June 15, 2026 8:04 PM
To: Varghese, Vipin <[email protected]>; Stephen Hemminger <[email protected]>
Cc: [email protected]; Tummala, Sivaprasad <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

AMD General

Hi All,

Quick update, implementing CPU_ALLOC instead of rte_cpu_set is turing out to eat a lot of memory.

I am working on logic to use CPU_ALLOC when CPU_SIZE > rte_cpu_Set capacity or find smarter ways not to pre-alloc extra.

Note: for accommodating CPU alloc we need to do it for all valid l1, l2, l3 and l4. On 384 single socket machine it exhausts memory (heap) like anything.

Quoted 11 lines

-----Original Message-----
From: Varghese, Vipin <[email protected]>
Sent: Thursday, May 28, 2026 12:48 PM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; Tummala, Sivaprasad <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Quoted 135 lines

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

AMD General

Sharing v6 with fixes and cache-id fetch shortly.

Quoted 127 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, April 15, 2026 1:52 AM
To: Varghese, Vipin <[email protected]>
Cc: [email protected]; Tummala, Sivaprasad <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 95 lines · On Wed, 15 Apr 2026 01:08:18 +0530 Vipin Varghese <[email protected]>…

This series introduces a topology library that groups DPDK lcores based on CPU cache hierarchy and NUMA topology. The goal is to provide a stable and explicit API that allows applications to select lcores with better locality and cache sharing characteristics.

The series includes:
- EAL support for topology discovery using hwloc and domain-based lcore

    grouping (L1/L2/L3/L4/NUMA)

- Topology-aware test cases validating API behavior and edge conditions
- Programmer’s guide describing the topology library and APIs

The API is marked experimental and does not change existing lcore behavior unless explicitly used by the application.

Changes in v5:
- Addressed review comments from v4
- Fixed ARM cross-compilation issues
- Cleaned up domain iteration and error handling
- Updated tests to cover domain edge cases
- Documentation refinements and API usage clarification

Changes in v4:
- Corrected domain selection semantics
- Updated example usage
- Fixed naming and typo issues

Changes in v3:
- Fixed macro naming (USE_NO_TOPOLOGY)
- Minor cleanups based on early feedback

Tested on:
- AMD EPYC (Milan, Genoa, Siena, Turin, Turin-Dense, Sorano)
- Intel Xeon (SPR-SP, GNR-SP)
- ARM Ampere
- NVIDIA Grace Superchip

Dependencies:
- hwloc-dev (tested with 2.10.0)

Patch breakdown:
1/3 eal/topology: add topology grouping for lcores 2/3 app: add topology-aware test cases
3/3 doc: add topology library documentation

Future Work:
- integrate into examples
-- hellowrld: ready
-- pkt-distributor: in-progress
-- l2fwd: ready
-- l3fwd: to start
-- eventdevpipeline: PoC ready
- integrate topology test
-- crypto: yet to start
-- compression: yet to start
-- dma: PoC ready
- add new features for
-- PQoS: yet to start
-- Data Injection: PoC with BRDCM Thor-2 ready

Tested OS: Linux only, need help with BSD and Windows

Tested with and without hwloc-dev library for
- Ampere, aarch64, Neoverse-N1, NUMA-2, 256 CPU threads
- Grace superchip, aarch64, Neoverse-V2, NUMA-2, 144 CPU threads
- Intel GNR-SP, 6767P, NUMA-2, 256 Threads
- AMD EPYC Siena, 8534P, NUMA-1, 128 Threads
- AMD EPYC Sorano, 8635P, NUMA-1, 168 Threads

Vipin Varghese (3):
eal/topology: add Topology grouping for lcores
app: add topology aware test case
doc: add new section topology

 app/test/meson.build                   |   1 +
 app/test/test_ring_perf.c              | 416 +++++++++++++-
 app/test/test_stack_perf.c             | 409 ++++++++++++++
 app/test/test_topology.c               | 676 ++++++++++++++++++++++
 config/meson.build                     |  18 +
 doc/api/doxy-api-index.md              |   1 +
 doc/guides/prog_guide/index.rst        |   3 +-
 doc/guides/prog_guide/topology_lib.rst | 155 +++++
 lib/eal/common/eal_private.h           |  74 +++
 lib/eal/common/eal_topology.c          | 747 +++++++++++++++++++++++++
 lib/eal/common/meson.build             |   1 +
 lib/eal/freebsd/eal.c                  |  10 +-
 lib/eal/include/meson.build            |   1 +
 lib/eal/include/rte_topology.h         | 255 +++++++++
 lib/eal/linux/eal.c                    |   7 +
 lib/eal/meson.build                    |   4 +
 16 files changed, 2773 insertions(+), 5 deletions(-)  create mode
100644 app/test/test_topology.c  create mode 100644
doc/guides/prog_guide/topology_lib.rst
 create mode 100644 lib/eal/common/eal_topology.c  create mode
Quoted 2 lines

100644 lib/eal/include/rte_topology.h

AI review reported lots of possible correctness problems:

# DPDK Patch Review - bundle-1843-topology-v5.mbox

## Overview

This patch series introduces topology awareness to DPDK, allowing applications to select logical cores based on CPU cache and I/O topology. The series adds a new rte_topology library with APIs to query and enumerate logical cores within topology domains

(L1/L2/L3/L4/NUMA).

Quoted 7 lines
Quoted 7 lines

---

## Correctness Bugs (HIGHEST PRIORITY - report at >=50% confidence)

### Patch 1/3: lib/eal/common/eal_topology.c

Quoted 16 lines
Quoted 7 lines

#### **Error: Resource leak on eal_topology_map_layer() failure**

In rte_eal_topology_init(), if any call to eal_topology_map_layer() fails (returns < 0), the code calls rte_eal_topology_release() which frees previously allocated layers. However, the hwloc_topology_t handle topo_cnfg.topology is **NOT**

destroyed before returning. This leaks the hwloc topology handle.

Quoted 8 lines

**Location:** lib/eal/common/eal_topology.c:685-712

```c
for (int i = 0; i < 5; i++) {
*layers[i].count = hwloc_get_nbobjs_by_depth(topo_cnfg.topology,
layers[i].depth);
if (eal_topology_map_layer(topo_cnfg.topology, layers[i].depth,

layers[i].count,

Quoted 34 lines
Quoted 25 lines
        layers[i].ptr, layers[i].total_cores, layers[i].name) < 0) {
        rte_eal_topology_release();  /* frees layer memory */
        return -1;  /* BUG: topo_cnfg.topology NOT destroyed here */
    }
}

hwloc_topology_destroy(topo_cnfg.topology); /* only reached on success */ topo_cnfg.topology = NULL; ```

**Fix:** Destroy the topology before returning on error:

```c
if (eal_topology_map_layer(...) < 0) {
    hwloc_topology_destroy(topo_cnfg.topology);
    topo_cnfg.topology = NULL;
    rte_eal_topology_release();
    return -1;
}
```

---

#### **Error: Potential use-after-free in eal_topology_map_layer() on partial allocation failure**

Quoted 9 lines

In eal_topology_map_layer(), the code allocates dm->cores for each domain. If a later allocation in the same loop iteration fails (e.g., for domain j+1), the function returns -1 immediately **without freeing dm->cores already allocated for earlier domains**. The caller (rte_eal_topology_init()) then calls rte_eal_topology_release(), which expects layer_ptr[j] to be non-NULL but layer_ptr[j]->cores may be uninitialized or garbage if the allocation failed before that point. This can cause a use-after-free or double-

Quoted 27 lines

free when rte_eal_topology_release() calls rte_free(d->map[i]->cores).

Quoted 26 lines

**Location:** lib/eal/common/eal_topology.c:537-557

```c

for (uint16_t j = 0; j < *layer_cnt; j++) {
    hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, j);
    int cpu_count = hwloc_bitmap_weight(obj->cpuset);
    if (cpu_count == -1)
        continue;

    struct core_domain_mapping *dm =
        rte_zmalloc(NULL, sizeof(struct core_domain_mapping), 0);
    if (!dm)
        return -1;  /* BUG: leaks layer_ptr array allocated by

caller */

    (*layer_ptr)[j] = dm;
    CPU_ZERO(&dm->core_set);
    dm->core_count = 0;

    dm->cores = rte_malloc(NULL, sizeof(uint16_t) * cpu_count, 0);
    if (!dm->cores)
        return -1;  /* BUG: leaks dm (just allocated) and previous

entries */ } ```

**Fix:** On allocation failure, free all previously allocated entries before

returning:

Quoted 42 lines
Quoted 32 lines
```c
if (!dm) {
    /* Free all previously allocated entries */
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}

/* Same cleanup for dm->cores allocation failure */ if (!dm->cores) {
    rte_free(dm);
    for (uint16_t k = 0; k < j; k++) {
        if ((*layer_ptr)[k]) {
            rte_free((*layer_ptr)[k]->cores);
            rte_free((*layer_ptr)[k]);
        }
    }
    rte_free(*layer_ptr);
    return -1;
}
```

---

#### **Error: NULL pointer dereference in eal_topology_map_layer() when hwloc_get_obj_by_depth() returns NULL**

Quoted 10 lines

In the second loop of eal_topology_map_layer() (lines 560-620), the code calls hwloc_get_obj_by_depth(topology, depth, j) and checks if (!obj || hwloc_bitmap_iszero(obj->cpuset)) to skip NULL objects. However, in the **inner
loop** (lines 579-618), the code calls hwloc_get_obj_by_depth(topology, depth, k) and assigns it to obj_core but does **NOT** check if obj_core is NULL before calling hwloc_bitmap_weight(obj_core->cpuset) on line 581. If hwloc_get_obj_by_depth() returns NULL for domain k, this will dereference a

Quoted 17 lines

NULL pointer.

Quoted 16 lines

**Location:** lib/eal/common/eal_topology.c:579-582

```c
for (uint16_t k = 0; k < *layer_cnt; k++) {
    hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k);
    int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);  /*
NULL deref if obj_core == NULL */
    if (cpu_count_core == -1)
        continue;
```

**Fix:** Check obj_core before dereferencing:

```c
hwloc_obj_t obj_core = hwloc_get_obj_by_depth(topology, depth, k); if

(!obj_core)

Quoted 49 lines
Quoted 49 lines
    continue;
int cpu_count_core = hwloc_bitmap_weight(obj_core->cpuset);
if (cpu_count_core == -1)
    continue;
```

---

#### **Error: Incorrect second argument to
`rte_topo_get_nth_lcore_from_domain()` in `get_same_l1_domains()`
(test_ring_perf.c and test_stack_perf.c)**

In both `app/test/test_ring_perf.c:290` and
`app/test/test_stack_perf.c:258`, the function `get_same_l1_domains()` calls:

```c

id2 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, RTE_TOPO_DOMAIN_L1); ```

The second argument (lcore_pos) is 0, which is the same as for id1. This will assign **the same lcore** to both id1 and id2, causing the subsequent check `if
(id1 == id2) return 3;` to always trigger. This is a logic error:
the intent is clearly to get two **different** lcores from the same domain.

**Location:** app/test/test_ring_perf.c:287-290 and app/test/test_stack_perf.c:255-258

**Fix:** Use position 1 for the second lcore:

```c
id1 = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, RTE_TOPO_DOMAIN_L1);
id2 = rte_topo_get_nth_lcore_from_domain(domain, 1, 0, RTE_TOPO_DOMAIN_L1); ```

---

#### **Error: Iteration condition in test_main_lcore_in_domain() uses wrong domain type for lookup**

In app/test/test_topology.c:211, the loop iterates over domain_count for domain_types[d], but the call to rte_topo_is_main_lcore_in_domain() uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]. This means the test only checks the NUMA domain regardless of which domain type d selects (L1/L2/L3/L4).

**Location:** app/test/test_topology.c:206-216

Quoted 53 lines
Quoted 7 lines

```c

for (unsigned int d = 0; d < RTE_DIM(domain_types); d++) {
    bool main_lcore_found = false;
    unsigned int domain_count = rte_topo_get_domain_count(domain_types[d]);
    for (unsigned int dmn_idx = 0; dmn_idx < domain_count; dmn_idx++) {
        main_lcore_found =

rte_topo_is_main_lcore_in_domain(RTE_TOPO_DOMAIN_NUMA, /* BUG:

should

Quoted 45 lines

be domain_types[d] */

            dmn_idx);
        if (main_lcore_found)
            break;
    }
```

**Fix:**

```c

main_lcore_found = rte_topo_is_main_lcore_in_domain(domain_types[d], dmn_idx); ```

---

#### **Error: Infinite loop risk in
rte_topo_get_nth_lcore_from_domain() when `ptr-

Quoted 1 line

core_count` is 0**

In lib/eal/common/eal_topology.c:296-318, the function enters a while (1) loop that increments new_lcore_pos. If ptr->core_count is 0 (which the code checks earlier but does not return immediately), the loop will wrap new_lcore_pos back to 0 indefinitely, never breaking. While the function returns RTE_MAX_LCORE if `ptr-

Quoted 2 lines

core_count == 0` before the loop, the logic flow is unclear and the loop body does

not have a clear termination condition if the core count is 0.

**Location:** lib/eal/common/eal_topology.c:283-318

**Fix:** Add a sanity check inside the loop to prevent infinite iteration:

```c
unsigned int iterations = 0;
while (1) {
    if (iterations++ > ptr->core_count * 2)  /* safety limit */
        return RTE_MAX_LCORE;
    /* ... rest of loop ... */
}
```

However, the real issue is that the code already returns RTE_MAX_LCORE if ptr->core_count == 0 on line 287, so this is more of a defensive-programming note. The function should be refactored for

clarity.

Quoted 47 lines
Quoted 7 lines

---

#### **Error: Missing NULL check after get_domain_lcore_mapping() in
rte_topo_get_next_lcore()**

Quoted 10 lines

In rte_topo_get_next_lcore(), the code calls get_domain_lcore_mapping(flag, lcore_domain) and checks if ptr is NULL on line 350. However, if ptr is NULL, the function returns RTE_MAX_LCORE. This is correct, but the subsequent logic on line 381 calls rte_topo_is_main_lcore_in_domain(flag, lcore_domain), which internally may call get_domain_lcore_mapping() again. If that call also returns NULL (which it will if the domain is invalid), the function rte_topo_is_main_lcore_in_domain() will return false, which is safe. However, the logic is fragile and should explicitly handle the NULL

case to avoid relying on transitive safety.

Quoted 11 lines

**Location:** lib/eal/common/eal_topology.c:381

**Recommendation:** The code is technically safe but could be clearer. No change required, but consider restructuring for maintainability.

---

### Patch 2/3: app/test Topology Tests

#### **Error: Macro

RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN

Quoted 4 lines

declares variable in macro expansion (shadowing risk)**

In lib/eal/include/rte_topology.h:243-248, the macro RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN declares a local

variable

Quoted 12 lines

main_lcore inside the macro expansion:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore,

domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain, 0, 0, flag);  \
    uint16_t main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag)) ```
Quoted 36 lines
Quoted 4 lines

This can cause a compiler error or shadowing if the caller already has a variable named main_lcore in scope. Additionally, the macro uses domain (line 244) but the parameter is domain_indx, which is a typo and will

cause a compilation error.

Quoted 31 lines

**Location:** lib/eal/include/rte_topology.h:243-248

**Fix:** Wrap in a do { } while (0) and use a uniquely-named variable, or document that the macro must not be used if main_lcore is already declared. Also fix the
typo:

```c
#define RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN(lcore,

domain_indx, flag)  \
    lcore = rte_topo_get_nth_lcore_from_domain(domain_indx, 0, 0, flag);  \
    uint16_t __topo_main_lcore = rte_get_main_lcore();  \
    for (lcore = (lcore != __topo_main_lcore) ? \
        lcore : rte_topo_get_next_lcore(lcore, 1, 0, flag);  \
        lcore < RTE_MAX_LCORE;  \
        lcore = rte_topo_get_next_lcore(lcore, 1, 0, flag)) ```

---

### Summary of Correctness Bugs

1. **hwloc topology leak** on eal_topology_map_layer() failure 2. **Resource
leak** in eal_topology_map_layer() on partial allocation failure 3. **NULL pointer
dereference** in eal_topology_map_layer() inner loop 4. **Logic error** in get_same_l1_domains() (same lcore assigned to id1 and id2) 5. **Wrong domain type** in test_main_lcore_in_domain() (uses RTE_TOPO_DOMAIN_NUMA instead of domain_types[d]) 6. **Macro typo** in RTE_TOPO_FOREACH_WORKER_LCORE_IN_DOMAIN

(uses

Quoted 5 lines
Quoted 1 line

domain

instead of

Quoted 3 lines

domain_indx) 7. **Potential infinite loop** in rte_topo_get_nth_lcore_from_domain() if ptr->core_count == 0 (mitigated by early

Tested-by
#33 lore raw

Re: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Hi Vipin,

Tested v5 on two RISC-V machines, no RISC-V specific code needed. topology_autotest passes on both. L3 is detected where the firmware describes it (SG2044), and empty where it doesn't, same as on ARM.

#34 lore raw

RE: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

AMD General

Thank you very much! Then I will use tag x86 and RISCV

Quoted 26 lines

-----Original Message-----
From: Sun Yuechi <[email protected]>
Sent: Tuesday, October 13, 2026 6:40 PM
To: Varghese, Vipin <[email protected]>
Cc: [email protected]; Stephen Hemminger <[email protected]>; Wathsala Vithanage <[email protected]>; Ajit Khaparde <[email protected]>; Honnappa Nagarahalli <[email protected]>; Tummala, Sivaprasad <[email protected]>; Konstantin Ananyev <[email protected]>; Bruce Richardson <[email protected]>; Jan Viktorin <[email protected]>; Morten Brørup <[email protected]>; Thomas Monjalon <[email protected]>; David Marchand <[email protected]>
Subject: Re: [PATCH v5 0/3] eal/topology: introduce topology-aware lcore grouping

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Hi Vipin,

Tested v5 on two RISC-V machines, no RISC-V specific code needed. topology_autotest passes on both. L3 is detected where the firmware describes it (SG2044), and empty where it doesn't, same as on ARM.