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 2541642BCF;
	Mon,  5 Jun 2023 13:26:46 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id DF59642D32;
	Mon,  5 Jun 2023 13:26:32 +0200 (CEST)
Received: from mga07.intel.com (mga07.intel.com [134.134.136.100])
 by mails.dpdk.org (Postfix) with ESMTP id ED34142D32
 for <dev@dpdk.org>; Mon,  5 Jun 2023 13:26:30 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1685964391; x=1717500391;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=y9s1CLNC+zNbO3SFFpWuD2WjR076h95on33E9NgMTHQ=;
 b=LmUjgIO7JeD1TUgP9E/QtCiePVcuo3wBfDezJh3KxMlkQcMh6JKPMl/j
 5hTfHaMJeYMDJYfod6ds8NEQuCFI3If0yQ71rhPuaMc5d6Wx20uXq0/4Y
 KLUd/bmdiWRnjz1+19GbH/eOVvnCWphsXu0ssRUsi6qB/pGE26h+OuDJi
 5bL9omtR02s1h+xxWmn2Y1D33xuiVaVTp7SZrEUplQroaEospU6okpOEj
 XAn0bUZUIxvnVEbHpPNaoU7QLGKxZfth7DFQHmKiu97LciR4Ji9rPAY9i
 QC4D7d+wCUajeHzms77yspPMLQSw8hogaQpX2H3xjxrUO5D7zijxX4xOw g==;
X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="422168498"
X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="422168498"
Received: from orsmga004.jf.intel.com ([10.7.209.38])
 by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 05 Jun 2023 04:26:30 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6600,9927,10731"; a="832778895"
X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="832778895"
Received: from dpdk-zhirun-lmm.sh.intel.com ([10.67.119.94])
 by orsmga004.jf.intel.com with ESMTP; 05 Jun 2023 04:26:27 -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
Cc: cunming.liang@intel.com, haiyue.wang@intel.com,
 mattias.ronnblom@ericsson.com, Zhirun Yan <zhirun.yan@intel.com>
Subject: [PATCH v7 04/17] graph: add get/set graph worker model APIs
Date: Mon,  5 Jun 2023 20:19:10 +0900
Message-Id: <20230605111923.3772260-5-zhirun.yan@intel.com>
X-Mailer: git-send-email 2.37.2
In-Reply-To: <20230605111923.3772260-1-zhirun.yan@intel.com>
References: <20230509060347.1237884-1-zhirun.yan@intel.com>
 <20230605111923.3772260-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 new get/set APIs to configure graph worker model which is used to
determine which model will be chosen.

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>
---
 lib/graph/meson.build               |  1 +
 lib/graph/rte_graph_worker.c        | 70 +++++++++++++++++++++++++++++
 lib/graph/rte_graph_worker_common.h | 19 ++++++++
 lib/graph/version.map               |  3 ++
 4 files changed, 93 insertions(+)
 create mode 100644 lib/graph/rte_graph_worker.c

diff --git a/lib/graph/meson.build b/lib/graph/meson.build
index 3526d1b5d4..9fab8243da 100644
--- a/lib/graph/meson.build
+++ b/lib/graph/meson.build
@@ -15,6 +15,7 @@ sources = files(
         'graph_stats.c',
         'graph_populate.c',
         'graph_pcap.c',
+        'rte_graph_worker.c',
 )
 headers = files('rte_graph.h', 'rte_graph_worker.h')
 
diff --git a/lib/graph/rte_graph_worker.c b/lib/graph/rte_graph_worker.c
new file mode 100644
index 0000000000..fc188e7cfa
--- /dev/null
+++ b/lib/graph/rte_graph_worker.c
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Intel Corporation
+ */
+
+/**
+ * @file graph_worker.c
+ *
+ * @warning
+ * @b EXPERIMENTAL:
+ * All functions in this file may be changed or removed without prior notice.
+ *
+ * These API enable to set/get graph walking model.
+ *
+ */
+
+#include "rte_graph_worker_common.h"
+#include "graph_private.h"
+
+/**
+ * @note This function does not perform any locking, and is only safe to call
+ *    before graph running. It will set all graphs the same model.
+ *
+ * @param name
+ *   Name of the graph worker model.
+ *
+ * @return
+ *   0 on success, -1 otherwise.
+ */
+int
+rte_graph_worker_model_set(enum rte_graph_worker_model model)
+{
+	struct graph_head *graph_head = graph_list_head_get();
+	struct graph *graph;
+	int ret = 0;
+
+	if (model == RTE_GRAPH_MODEL_DEFAULT || model == RTE_GRAPH_MODEL_RTC ||
+	    model == RTE_GRAPH_MODEL_MCORE_DISPATCH)
+		STAILQ_FOREACH(graph, graph_head, next)
+			graph->graph->model = model;
+	else {
+		STAILQ_FOREACH(graph, graph_head, next)
+			graph->graph->model = RTE_GRAPH_MODEL_DEFAULT;
+		ret = -1;
+		}
+
+	return ret;
+}
+
+/**
+ * Get the graph worker model
+ *
+ * @note All graph will use the same model and this function will get model from the first one
+ *
+ * @param name
+ *   Name of the graph worker model.
+ *
+ * @return
+ *   Graph worker model on success.
+ */
+inline
+enum rte_graph_worker_model
+rte_graph_worker_model_get(void)
+{
+	struct graph_head *graph_head = graph_list_head_get();
+	struct graph *graph;
+
+	graph = STAILQ_FIRST(graph_head);
+
+	return graph->graph->model;
+}
diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h
index 41428974db..72d132bae4 100644
--- a/lib/graph/rte_graph_worker_common.h
+++ b/lib/graph/rte_graph_worker_common.h
@@ -29,6 +29,16 @@
 extern "C" {
 #endif
 
+/** Graph worker models */
+enum rte_graph_worker_model {
+	RTE_GRAPH_MODEL_DEFAULT,
+	/**< Default graph model*/
+	RTE_GRAPH_MODEL_RTC = RTE_GRAPH_MODEL_DEFAULT,
+	/**< Run-To-Completion model. It is the default model. */
+	RTE_GRAPH_MODEL_MCORE_DISPATCH
+	/**< Dispatch model to support cross-core dispatching within core affinity. */
+};
+
 /**
  * @internal
  *
@@ -50,6 +60,7 @@ struct rte_graph {
 	/** Number of packets to capture per core. */
 	uint64_t nb_pkt_to_capture;
 	char pcap_filename[RTE_GRAPH_PCAP_FILE_SZ];  /**< Pcap filename. */
+	enum rte_graph_worker_model model; /**< graph model */
 	uint64_t fence;			/**< Fence. */
 } __rte_cache_aligned;
 
@@ -490,6 +501,14 @@ rte_node_next_stream_move(struct rte_graph *graph, struct rte_node *src,
 	}
 }
 
+__rte_experimental
+enum rte_graph_worker_model
+rte_graph_worker_model_get(void);
+
+__rte_experimental
+int
+rte_graph_worker_model_set(enum rte_graph_worker_model model);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/graph/version.map b/lib/graph/version.map
index 13b838752d..eea73ec9ca 100644
--- a/lib/graph/version.map
+++ b/lib/graph/version.map
@@ -43,5 +43,8 @@ EXPERIMENTAL {
 	rte_node_next_stream_put;
 	rte_node_next_stream_move;
 
+	rte_graph_worker_model_set;
+	rte_graph_worker_model_get;
+
 	local: *;
 };
-- 
2.37.2