From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id BE2AD45C87;
	Tue,  5 Nov 2024 11:30:11 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id ADAB1406B8;
	Tue,  5 Nov 2024 11:30:11 +0100 (CET)
Received: from NAM10-MW2-obe.outbound.protection.outlook.com
 (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78])
 by mails.dpdk.org (Postfix) with ESMTP id 9745A406B4
 for <dev@dpdk.org>; Tue,  5 Nov 2024 11:30:09 +0100 (CET)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=Dj354PYbN1ygv5IlGcowZrrrQVBbbkiG3Gs/SotJOY1oVOY4AgDPRLGJcqZjGunQgByqP1Sx5cKQl6TmkK9cKimBmznLl99HxCqtKL5PxQRihwlflRoJedrAzaDS/0VkPn81YPZCqipTzxxWbruDFwHZic1E8a5zqCI8wkd6eI7MOpVs2ZAIA1WLnbAAHzoOwZ9xslI9z2HQmkPZ7lEgaKXIG9XKuAKbsjIN4g5BhIA7TyZhHnSf2YXRWyHnwG8WBdnogMEQ2621Ap/fcz0QeJk05aoqZZEqMvB5ahK7gL1szRejOexki44L+/yMAuO3Mi3s0Fh+lWpkjp84s1FQbA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector10001;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=bPK9JeSrZb5bBrUf37jKsrYW6m1KQCWe1iBttpcMj2k=;
 b=vEPDvpWn0iyDhRd6gXMyDijhGLkw8kZ+iZpjRp1fbVY30XJckOcyY1CJGjuvTrBCXOQe5l5QikQVUoDc15PFMS2398P/z7XU8ZHzf99VbWOUSU2SO+mAvMe/wdaOUeXBWwbg7GJQcJ+6DXMypSE3z27MUYYKA14qAYiYFh1KHsROMhg7feg2tMM57VmjqbHgco+USCrXPK8baB8X3LIUYcxZQGZQLkulE7l7lk95K35X89876RZSnO+EEWEB3sa8QRWLOfnv/P862Nj/eVY2N5zktBk/S8xiiNlYauJT6/SF6G5zlgQsvoK/LFe20MEWfa7GbkQ9ebuRmBxYpfCt6A==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 165.204.84.17) smtp.rcpttodomain=dpdk.org smtp.mailfrom=amd.com; dmarc=pass
 (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com;
 dkim=none (message not signed); arc=none (0)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; 
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=bPK9JeSrZb5bBrUf37jKsrYW6m1KQCWe1iBttpcMj2k=;
 b=Qz7CnDppK4adTV1sjQZQfjxLaxzEJp7ck0pGin3mBuG9whuMQM+VIoOWV4vl49S9B7tyuuL5SlcpYdb/gkP8yUD6tJOdvNpi7Nzu5q4kzfMO0PPrkRKemCzrzVTZfyMSRyXsmgPqNCLWt00cUr1UDsWAR11albx5JthWv7jlLL4=
Received: from MW4PR04CA0271.namprd04.prod.outlook.com (2603:10b6:303:89::6)
 by PH7PR12MB8796.namprd12.prod.outlook.com (2603:10b6:510:272::22) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Tue, 5 Nov
 2024 10:30:06 +0000
Received: from SN1PEPF000252A0.namprd05.prod.outlook.com
 (2603:10b6:303:89:cafe::b1) by MW4PR04CA0271.outlook.office365.com
 (2603:10b6:303:89::6) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30 via Frontend
 Transport; Tue, 5 Nov 2024 10:30:06 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17)
 smtp.mailfrom=amd.com; dkim=none (message not signed)
 header.d=none;dmarc=pass action=none header.from=amd.com;
Received-SPF: Pass (protection.outlook.com: domain of amd.com designates
 165.204.84.17 as permitted sender) receiver=protection.outlook.com;
 client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C
Received: from SATLEXMB04.amd.com (165.204.84.17) by
 SN1PEPF000252A0.mail.protection.outlook.com (10.167.242.7) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.20.8137.17 via Frontend Transport; Tue, 5 Nov 2024 10:30:05 +0000
Received: from BLRVIVARGHE.amd.com (10.180.168.240) by SATLEXMB04.amd.com
 (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 5 Nov
 2024 04:30:01 -0600
From: Vipin Varghese <vipin.varghese@amd.com>
To: <dev@dpdk.org>, <roretzla@linux.microsoft.com>,
 <bruce.richardson@intel.com>, <john.mcnamara@intel.com>,
 <dmitry.kozliuk@gmail.com>
CC: <pbhagavatula@marvell.com>, <jerinj@marvell.com>, <ruifeng.wang@arm.com>, 
 <mattias.ronnblom@ericsson.com>, <anatoly.burakov@intel.com>,
 <stephen@networkplumber.org>, <ferruh.yigit@amd.com>,
 <honnappa.nagarahalli@arm.com>, <wathsala.vithanage@arm.com>,
 <konstantin.ananyev@huawei.com>, <mb@smartsharesystems.com>
Subject: [PATCH v4 4/4] examples: update with lcore topology API
Date: Tue, 5 Nov 2024 15:58:49 +0530
Message-ID: <20241105102849.1947-5-vipin.varghese@amd.com>
X-Mailer: git-send-email 2.47.0.windows.1
In-Reply-To: <20241105102849.1947-1-vipin.varghese@amd.com>
References: <20241105102849.1947-1-vipin.varghese@amd.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [10.180.168.240]
X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com
 (10.181.40.145)
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: SN1PEPF000252A0:EE_|PH7PR12MB8796:EE_
X-MS-Office365-Filtering-Correlation-Id: 2cb361f1-92ab-47af-fabd-08dcfd84d0cc
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
 ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; 
X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?D45xXxTPm8pV+uU9AaS+x9W6iRYHRduDkyLt12Gq9Of6zyFwYWJ5iG2mIRkk?=
 =?us-ascii?Q?7XPNHJZV3UFLntA1mDXfJF2rzG/oqdeLe5KllfYw4vAiRA4IX7vFqvmJEqHU?=
 =?us-ascii?Q?8mTGEPIqtMHKVVXCFj+Rc9qqeg8SpAmtSlmQkeQFiYpKecv9YOiyt9KUhSgo?=
 =?us-ascii?Q?W+co2AlRYNP9+h8MugYR01ZEuKjqT3LDM2iVCrmBggedBLo9YkZsrXk4jwk/?=
 =?us-ascii?Q?QRwpgSsXRM2hrWIsTttc9asRnglK2CaCJ8QHS5AbHtRHXE9DEaB2PL5MnvN1?=
 =?us-ascii?Q?j1XVxpepkJyEGmyUccHE0Y+do05h6u7xYVSfpEAG3zgcm0SpQvf5STloJtET?=
 =?us-ascii?Q?kDZI5s2uvj9+b/Q9bdehemERNOBGA73gGhjNjFKNIxuI3Fwn0AObzUK66mRK?=
 =?us-ascii?Q?LkzWP47xZrauDg+nDevgJN9ggYUbJeCj20LKKuqAFPFfqCEx+WZcX1q0hdhi?=
 =?us-ascii?Q?V4gOD5LvsgsX/rEaBE27BzyF5cPfrpaOSzgS8B3GIjmcC7B4IVgN4GsTH8fU?=
 =?us-ascii?Q?FFdUinSb5gSDZJiiC/wRhLYqpE8YPLWv3Vvm3yzL6MDsEOmTHQaSTqsJxdLj?=
 =?us-ascii?Q?13KV9ZGDnGEVS6EPqzphHiln17RWqnQSV4OE7mLhVzdJy55KUzFA/thAL21e?=
 =?us-ascii?Q?HUolKofi/3pTPf/E3DI9CD8khsj9K/JnCI2BpulkvDAfwOGf0VE8HlAk0aYr?=
 =?us-ascii?Q?hYTCEERkKs2HEjKl8xn6e4BwvYANVa2kTDrZgCYY1O/xchhOAKezA5lmOlaL?=
 =?us-ascii?Q?srfFCCJqG9u/cRWXkMCc0IcHQ5bli2tmL9GP4Lf+kmJ3g35mKblaGtmaM2D6?=
 =?us-ascii?Q?clhnadjvaTCHjucP653lzc4EfTAEXEl8bmm1jCiKc9AeaPL5ApWg7UTTg8TF?=
 =?us-ascii?Q?pf8Gan0DwC4eWpnzWBcjDMFGcQOe7glq8XLDBx2N5bucGkO9eY9L+ItMSs4p?=
 =?us-ascii?Q?yuHuDyD+9wZ8WifbkA7uuY8FAnRT7vqG0yll6iOlyW9iBB1EbNuJktpWWPjr?=
 =?us-ascii?Q?CnsQWObdm60kO5NOtcZVKHTfudaT9aRQjvih3o33jCmy4FbkB6IjeUKxOvCr?=
 =?us-ascii?Q?ijEUEgemS9WBHOMlV0YZhSLHMz2qM9d0kFVIQsGBmLkO4uHY5NPUBbO29r5u?=
 =?us-ascii?Q?2/ZKd9/0aXrakrjrjTg3yn4XPnW1B9tJanqSHtzy/YFYz588dRcG28C5ZWBj?=
 =?us-ascii?Q?UJz3kKbGUa+dHmoj60Gn7J1QxAXESZrDtZVExLpweuMS9dA4xdX4EuAeUK67?=
 =?us-ascii?Q?kRHS5O+T0sFTpynQS4m1COKdIS043GGdq9lGTnKihIl+KPormF6k7DGpxW7z?=
 =?us-ascii?Q?MSMCS3FOT4OgOOoxdcUuDrGqLD8ZBljYRst/3RvnvjimW6bPnfnYSMm9RGAa?=
 =?us-ascii?Q?SUA60LwVmKMkHKe6OFw2gjbasQf9kJAogv0YD2DRhMzHHAMTXA=3D=3D?=
X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:;
 IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE;
 SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014); DIR:OUT;
 SFP:1101; 
X-OriginatorOrg: amd.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 10:30:05.9435 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 2cb361f1-92ab-47af-fabd-08dcfd84d0cc
X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17];
 Helo=[SATLEXMB04.amd.com]
X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000252A0.namprd05.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8796
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

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

Signed-off-by: Vipin Varghese <vipin.varghese@amd.com>
---
 examples/helloworld/main.c   | 154 ++++++++++++++++++++++++++++++++++-
 examples/l2fwd/main.c        |  56 +++++++++++--
 examples/skeleton/basicfwd.c |  22 +++++
 3 files changed, 222 insertions(+), 10 deletions(-)

diff --git a/examples/helloworld/main.c b/examples/helloworld/main.c
index af509138da..f39db532d9 100644
--- a/examples/helloworld/main.c
+++ b/examples/helloworld/main.c
@@ -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();
diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index c6fafdd019..398dd15502 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -46,6 +46,9 @@ static int mac_updating = 1;
 /* Ports set in promiscuous mode off by default. */
 static int promiscuous_on;
 
+/* select lcores based on ports numa (RTE_LCORE_DOMAIN_IO). */
+static bool select_port_from_io_domain;
+
 #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
 
 #define MAX_PKT_BURST 32
@@ -314,6 +317,7 @@ l2fwd_usage(const char *prgname)
 	       "  -P : Enable promiscuous mode\n"
 	       "  -q NQ: number of queue (=ports) per lcore (default is 1)\n"
 	       "  -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n"
+	       "  -t : Enable IO domain lcores mapping to Ports\n"
 	       "  --no-mac-updating: Disable MAC addresses updating (enabled by default)\n"
 	       "      When enabled:\n"
 	       "       - The source MAC address is replaced by the TX port MAC address\n"
@@ -431,6 +435,7 @@ static const char short_options[] =
 	"P"   /* promiscuous */
 	"q:"  /* number of queues */
 	"T:"  /* timer period */
+	"t"  /* lcore from port io numa */
 	;
 
 #define CMD_LINE_OPT_NO_MAC_UPDATING "no-mac-updating"
@@ -502,6 +507,11 @@ l2fwd_parse_args(int argc, char **argv)
 			timer_period = timer_secs;
 			break;
 
+		/* lcores from port io numa */
+		case 't':
+			select_port_from_io_domain = true;
+			break;
+
 		/* long options */
 		case CMD_LINE_OPT_PORTMAP_NUM:
 			ret = l2fwd_parse_port_pair_config(optarg);
@@ -654,7 +664,7 @@ main(int argc, char **argv)
 	uint16_t nb_ports;
 	uint16_t nb_ports_available = 0;
 	uint16_t portid, last_port;
-	unsigned lcore_id, rx_lcore_id;
+	uint16_t lcore_id, rx_lcore_id;
 	unsigned nb_ports_in_mask = 0;
 	unsigned int nb_lcores = 0;
 	unsigned int nb_mbufs;
@@ -738,18 +748,48 @@ main(int argc, char **argv)
 	qconf = NULL;
 
 	/* Initialize the port/queue configuration of each logical core */
+	if (rte_get_domain_count(RTE_LCORE_DOMAIN_IO) == 0)
+		rte_exit(EXIT_FAILURE, "we do not have enough cores in IO numa!\n");
+
+	uint16_t coreindx_io_domain[RTE_MAX_ETHPORTS] = {0};
+	uint16_t lcore_io_domain[RTE_MAX_ETHPORTS] = {RTE_MAX_LCORE};
+	uint16_t l3_domain_count = rte_get_domain_count(RTE_LCORE_DOMAIN_IO);
+
+	for (int i = 0; i < l3_domain_count; i++)
+		lcore_io_domain[i] = rte_get_lcore_in_domain(RTE_LCORE_DOMAIN_IO, i, 0);
+
 	RTE_ETH_FOREACH_DEV(portid) {
 		/* skip ports that are not enabled */
 		if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
 			continue;
 
-		/* get the lcore_id for this port */
-		while (rte_lcore_is_enabled(rx_lcore_id) == 0 ||
-		       lcore_queue_conf[rx_lcore_id].n_rx_port ==
-		       l2fwd_rx_queue_per_lcore) {
-			rx_lcore_id++;
-			if (rx_lcore_id >= RTE_MAX_LCORE)
-				rte_exit(EXIT_FAILURE, "Not enough cores\n");
+		/* get IO NUMA for the port */
+		int port_socket = rte_eth_dev_socket_id(portid);
+
+		if (select_port_from_io_domain == false) {
+			/* get the lcore_id for this port */
+			while ((rte_lcore_is_enabled(rx_lcore_id) == 0) ||
+			       (lcore_queue_conf[rx_lcore_id].n_rx_port ==
+				l2fwd_rx_queue_per_lcore)) {
+				rx_lcore_id++;
+				if (rx_lcore_id >= RTE_MAX_LCORE)
+					rte_exit(EXIT_FAILURE, "Not enough cores\n");
+			}
+		} else {
+			/* get lcore from IO numa for this port */
+			rx_lcore_id = lcore_io_domain[port_socket];
+
+			if (lcore_queue_conf[rx_lcore_id].n_rx_port == l2fwd_rx_queue_per_lcore) {
+				coreindx_io_domain[port_socket] += 1;
+				rx_lcore_id = rte_get_lcore_in_domain(RTE_LCORE_DOMAIN_IO,
+						port_socket, coreindx_io_domain[port_socket]);
+			}
+
+			if (rx_lcore_id == RTE_MAX_LCORE)
+				rte_exit(EXIT_FAILURE, "unable find IO (%u) numa lcore for port (%u)\n",
+					 port_socket, portid);
+
+			lcore_io_domain[port_socket] = rx_lcore_id;
 		}
 
 		if (qconf != &lcore_queue_conf[rx_lcore_id]) {
diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c
index 133293cf15..65faf46e16 100644
--- a/examples/skeleton/basicfwd.c
+++ b/examples/skeleton/basicfwd.c
@@ -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. */
-- 
2.34.1