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 5D42142CAB;
	Tue, 13 Jun 2023 16:12:37 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 1676842D36;
	Tue, 13 Jun 2023 16:12:16 +0200 (CEST)
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by mails.dpdk.org (Postfix) with ESMTP id 0BA7942D35
 for <dev@dpdk.org>; Tue, 13 Jun 2023 16:12:13 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1686665534; x=1718201534;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=ertvvigeaxkq5v6BYVWYs3n7afGZQ/jGZqYWjQbZnag=;
 b=TnTbU+fhoN0grdHnG5L4v7hGvv5RFYHW+ZPjTUTM2N/xxD53cEjlQ6Ps
 5hUm5u23bNlm5nAcYZdH7AiVPXqncUGfeQ7zb0DENkaS5tikqML/QLPAZ
 ZPiDb3ZaIaxVeU7HE41nInFSXi1/i6G/Yg1tNkvrhwROBXDMUbGChsVOX
 iboUpob8XTwOq+wNwuP4seXRSCFCd3RMFuGC662DiCHKmBiSyG5QlQnNH
 /tN48XDFGzaoHdmbf5BywdVtxgEbC/yXa8VkduPkBU+W1YeOx5vw+suw/
 1/ftILGzNR7YIoxUyfY1qyVrrFsJC3v3Xl4z0Oa5/wdKzoG5Q1Nua1Guq Q==;
X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="355839723"
X-IronPort-AV: E=Sophos;i="6.00,239,1681196400"; d="scan'208";a="355839723"
Received: from orsmga008.jf.intel.com ([10.7.209.65])
 by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 13 Jun 2023 07:12:12 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6600,9927,10740"; a="741439329"
X-IronPort-AV: E=Sophos;i="6.00,239,1681196400"; d="scan'208";a="741439329"
Received: from dpdk-zhirun-lmm.sh.intel.com ([10.67.119.94])
 by orsmga008.jf.intel.com with ESMTP; 13 Jun 2023 07:12:09 -0700
From: Zhirun Yan <zhirun.yan@intel.com>
To: dev@dpdk.org, jerinj@marvell.com, kirankumark@marvell.com,
 ndabilpuram@marvell.com, stephen@networkplumber.org,
 pbhagavatula@marvell.com, jerinjacobk@gmail.com, david.marchand@redhat.com
Cc: cunming.liang@intel.com, haiyue.wang@intel.com,
 mattias.ronnblom@ericsson.com, Zhirun Yan <zhirun.yan@intel.com>
Subject: [PATCH v14 05/16] graph: introduce graph node core affinity API
Date: Tue, 13 Jun 2023 22:04:34 +0800
Message-Id: <20230613140445.2155542-6-zhirun.yan@intel.com>
X-Mailer: git-send-email 2.37.2
In-Reply-To: <20230613140445.2155542-1-zhirun.yan@intel.com>
References: <20230613101404.1787790-1-zhirun.yan@intel.com>
 <20230613140445.2155542-1-zhirun.yan@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
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

Add lcore_id for node to hold affinity core id and impl
rte_graph_model_mcore_dispatch_lcore_affinity_set to set node affinity
with specific lcore.

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
Signed-off-by: Cunming Liang <cunming.liang@intel.com>
Signed-off-by: Zhirun Yan <zhirun.yan@intel.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
---
 lib/graph/graph_private.h                  |  2 +
 lib/graph/meson.build                      |  2 +
 lib/graph/node.c                           |  1 +
 lib/graph/rte_graph_model_mcore_dispatch.c | 30 +++++++++++++++
 lib/graph/rte_graph_model_mcore_dispatch.h | 45 ++++++++++++++++++++++
 lib/graph/version.map                      |  1 +
 6 files changed, 81 insertions(+)
 create mode 100644 lib/graph/rte_graph_model_mcore_dispatch.c
 create mode 100644 lib/graph/rte_graph_model_mcore_dispatch.h

diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index eacdef45f0..ea4409448d 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -51,6 +51,8 @@ struct node {
 	STAILQ_ENTRY(node) next;      /**< Next node in the list. */
 	char name[RTE_NODE_NAMESIZE]; /**< Name of the node. */
 	uint64_t flags;		      /**< Node configuration flag. */
+	unsigned int lcore_id;
+	/**< Node runs on the Lcore ID used for mcore dispatch model. */
 	rte_node_process_t process;   /**< Node process function. */
 	rte_node_init_t init;         /**< Node init function. */
 	rte_node_fini_t fini;	      /**< Node fini function. */
diff --git a/lib/graph/meson.build b/lib/graph/meson.build
index 5661dd855b..8aef451f7b 100644
--- a/lib/graph/meson.build
+++ b/lib/graph/meson.build
@@ -16,9 +16,11 @@ sources = files(
         'graph_populate.c',
         'graph_pcap.c',
         'rte_graph_worker.c',
+        'rte_graph_model_mcore_dispatch.c',
 )
 headers = files('rte_graph.h', 'rte_graph_worker.h')
 indirect_headers += files(
+        'rte_graph_model_mcore_dispatch.h',
         'rte_graph_model_rtc.h',
         'rte_graph_worker_common.h',
         )
diff --git a/lib/graph/node.c b/lib/graph/node.c
index 149414dcd9..339b4a0da5 100644
--- a/lib/graph/node.c
+++ b/lib/graph/node.c
@@ -100,6 +100,7 @@ __rte_node_register(const struct rte_node_register *reg)
 			goto free;
 	}
 
+	node->lcore_id = RTE_MAX_LCORE;
 	node->id = node_id++;
 
 	/* Add the node at tail */
diff --git a/lib/graph/rte_graph_model_mcore_dispatch.c b/lib/graph/rte_graph_model_mcore_dispatch.c
new file mode 100644
index 0000000000..9df2479a10
--- /dev/null
+++ b/lib/graph/rte_graph_model_mcore_dispatch.c
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Intel Corporation
+ */
+
+#include "graph_private.h"
+#include "rte_graph_model_mcore_dispatch.h"
+
+int
+rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name, unsigned int lcore_id)
+{
+	struct node *node;
+	int ret = -EINVAL;
+
+	if (lcore_id >= RTE_MAX_LCORE)
+		return ret;
+
+	graph_spinlock_lock();
+
+	STAILQ_FOREACH(node, node_list_head_get(), next) {
+		if (strncmp(node->name, name, RTE_NODE_NAMESIZE) == 0) {
+			node->lcore_id = lcore_id;
+			ret = 0;
+			break;
+		}
+	}
+
+	graph_spinlock_unlock();
+
+	return ret;
+}
diff --git a/lib/graph/rte_graph_model_mcore_dispatch.h b/lib/graph/rte_graph_model_mcore_dispatch.h
new file mode 100644
index 0000000000..7da0483d13
--- /dev/null
+++ b/lib/graph/rte_graph_model_mcore_dispatch.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Intel Corporation
+ */
+
+#ifndef _RTE_GRAPH_MODEL_MCORE_DISPATCH_H_
+#define _RTE_GRAPH_MODEL_MCORE_DISPATCH_H_
+
+/**
+ * @file rte_graph_model_mcore_dispatch.h
+ *
+ * @warning
+ * @b EXPERIMENTAL:
+ * All functions in this file may be changed or removed without prior notice.
+ *
+ * These APIs allow to set core affinity with the node and only used for mcore
+ * dispatch model.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "rte_graph_worker_common.h"
+
+/**
+ * Set lcore affinity with the node used for mcore dispatch model.
+ *
+ * @param name
+ *   Valid node name. In the case of the cloned node, the name will be
+ * "parent node name" + "-" + name.
+ * @param lcore_id
+ *   The lcore ID value.
+ *
+ * @return
+ *   0 on success, error otherwise.
+ */
+__rte_experimental
+int rte_graph_model_mcore_dispatch_node_lcore_affinity_set(const char *name,
+							   unsigned int lcore_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_GRAPH_MODEL_MCORE_DISPATCH_H_ */
diff --git a/lib/graph/version.map b/lib/graph/version.map
index e9a680a45e..6ae19b0d6e 100644
--- a/lib/graph/version.map
+++ b/lib/graph/version.map
@@ -15,6 +15,7 @@ EXPERIMENTAL {
 	rte_graph_list_dump;
 	rte_graph_max_count;
 	rte_graph_model_is_valid;
+	rte_graph_model_mcore_dispatch_node_lcore_affinity_set;
 	rte_graph_node_get;
 	rte_graph_node_get_by_name;
 	rte_graph_obj_dump;
-- 
2.37.2