[v10,04/16] graph: add get/set graph worker model APIs

Message ID 20230608095759.1800617-5-zhirun.yan@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series graph enhancement for multi-core dispatch |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Yan, Zhirun June 8, 2023, 9:57 a.m. UTC
  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        | 39 ++++++++++++++++
 lib/graph/rte_graph_worker_common.h | 69 +++++++++++++++++++++++++++++
 lib/graph/version.map               |  5 +++
 4 files changed, 114 insertions(+)
 create mode 100644 lib/graph/rte_graph_worker.c
  

Comments

Jerin Jacob June 8, 2023, 10:38 a.m. UTC | #1
On Thu, Jun 8, 2023 at 3:35 PM Zhirun Yan <zhirun.yan@intel.com> wrote:
>
> 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>
>
> +/** Graph worker models */
> +/* If adding new entry, then update graph_model_is_valid API. */

graph_model_is_valid-> rte_graph_model_is_valid.

Comments suggestion:
When adding a new graph model entry, update rte_graph_model_is_valid()
implementation.

With above change,
Acked-by: Jerin Jacob <jerinj@marvell.com>
  

Patch

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..7e2a918fae
--- /dev/null
+++ b/lib/graph/rte_graph_worker.c
@@ -0,0 +1,39 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Intel Corporation
+ */
+
+#include "rte_graph_worker_common.h"
+#include "graph_private.h"
+
+bool
+rte_graph_model_is_valid(uint8_t model)
+{
+	if (model > RTE_GRAPH_MODEL_MCORE_DISPATCH)
+		return false;
+
+	return true;
+}
+
+int
+rte_graph_worker_model_set(uint8_t model)
+{
+	struct graph_head *graph_head = graph_list_head_get();
+	struct graph *graph;
+
+	if (!rte_graph_model_is_valid(model))
+		return -EINVAL;
+
+	STAILQ_FOREACH(graph, graph_head, next)
+			graph->graph->model = model;
+
+	return 0;
+}
+
+uint8_t
+rte_graph_worker_model_get(struct rte_graph *graph)
+{
+	if (!rte_graph_model_is_valid(graph->model))
+		return -EINVAL;
+
+	return graph->model;
+}
diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h
index 41428974db..71fd620035 100644
--- a/lib/graph/rte_graph_worker_common.h
+++ b/lib/graph/rte_graph_worker_common.h
@@ -29,6 +29,13 @@ 
 extern "C" {
 #endif
 
+/** Graph worker models */
+/* If adding new entry, then update graph_model_is_valid API. */
+#define RTE_GRAPH_MODEL_RTC 0 /**< Run-To-Completion model. It is the default model. */
+#define RTE_GRAPH_MODEL_MCORE_DISPATCH 1
+/**< Dispatch model to support cross-core dispatching within core affinity. */
+#define RTE_GRAPH_MODEL_DEFAULT RTE_GRAPH_MODEL_RTC /**< Default graph model. */
+
 /**
  * @internal
  *
@@ -41,6 +48,9 @@  struct rte_graph {
 	rte_node_t nb_nodes;	     /**< Number of nodes in the graph. */
 	rte_graph_off_t *cir_start;  /**< Pointer to circular buffer. */
 	rte_graph_off_t nodes_start; /**< Offset at which node memory starts. */
+	uint8_t model;		     /**< graph model */
+	uint8_t reserved1;	     /**< Reserved for future use. */
+	uint16_t reserved2;	     /**< Reserved for future use. */
 	rte_graph_t id;	/**< Graph identifier. */
 	int socket;	/**< Socket ID where memory is allocated. */
 	char name[RTE_GRAPH_NAMESIZE];	/**< Name of the graph. */
@@ -490,6 +500,65 @@  rte_node_next_stream_move(struct rte_graph *graph, struct rte_node *src,
 	}
 }
 
+/**
+ * Test the validity of model.
+ *
+ * @param model
+ *   Model to check.
+ *
+ * @return
+ *   True if graph model is valid, false otherwise.
+ */
+bool
+rte_graph_model_is_valid(uint8_t model);
+
+/**
+ * @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 model
+ *   Name of the graph worker model.
+ *
+ * @return
+ *   0 on success, -1 otherwise.
+ */
+__rte_experimental
+int rte_graph_worker_model_set(uint8_t model);
+
+/**
+ * Get the graph worker model
+ *
+ * @note All graph will use the same model and this function will get model from the first one.
+ *    Used for slow path.
+ *
+ * @param graph
+ *   Graph pointer.
+ *
+ * @return
+ *   Graph worker model on success.
+ */
+__rte_experimental
+uint8_t rte_graph_worker_model_get(struct rte_graph *graph);
+
+/**
+ * Get the graph worker model without check
+ *
+ * @note All graph will use the same model and this function will get model from the first one.
+ *    Used for fast path.
+ *
+ * @param graph
+ *   Graph pointer.
+ *
+ * @return
+ *   Graph worker model on success.
+ */
+__rte_experimental
+static __rte_always_inline
+uint8_t rte_graph_worker_model_no_check_get(struct rte_graph *graph)
+{
+	return graph->model;
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/graph/version.map b/lib/graph/version.map
index 13b838752d..d8b66640bd 100644
--- a/lib/graph/version.map
+++ b/lib/graph/version.map
@@ -43,5 +43,10 @@  EXPERIMENTAL {
 	rte_node_next_stream_put;
 	rte_node_next_stream_move;
 
+	graph_model_is_valid;
+	rte_graph_worker_model_set;
+	rte_graph_worker_model_get;
+	rte_graph_worker_model_no_check_get;
+
 	local: *;
 };