Skip to contentSkip to conversation

graph enhancement for multi-core dispatch

RFC In review Zhirun Yan 3 participants 11 messages Sep 8, 2022 – Sep 30, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Zhirun Yan

author
#0 lore raw

cover graph enhancement for multi-core dispatch

Currently, the rte_graph_walk() and rte_node_enqueue* fast path API functions in graph lib implementation are designed to work on single-core.

This solution(RFC) proposes usage of cross-core dispatching mechanism to enhance the graph scaling strategy. We introduce Scheduler Workqueue then we could directly dispatch streams to another worker core which is affinity with a specific node.

This RFC:
1. Introduce core affinity API and graph clone API.
2. Introduce key functions to enqueue/dequeue for dispatching streams.
3. Enhance rte_graph_walk by cross-core dispatch.
4. Add l2fwd-graph example and stats for cross-core dispatching.

With this patch set, it could easily plan and orchestrate stream on multi-core systems.

Future work:
1. Support to affinity lcore set for one node.
2. Use l3fwd-graph instead of l2fwd-graph as example in patch 06.
3. Add new parameter, like --node(nodeid, lcoreid) to config node for core affinity.

Comments and suggestions are welcome. Thanks!

Haiyue Wang (1):
examples: add l2fwd-graph

Zhirun Yan (5):
graph: introduce core affinity API into graph
graph: introduce graph clone API for other worker core
graph: enable stream moving cross cores
graph: enhance graph walk by cross-core dispatch
graph: add stats for corss-core dispatching

 examples/l2fwd-graph/main.c      | 455 +++++++++++++++++++++++++++++++
 examples/l2fwd-graph/meson.build |  25 ++
 examples/l2fwd-graph/node.c      | 263 ++++++++++++++++++
 examples/l2fwd-graph/node.h      |  64 +++++
 examples/meson.build             |   1 +
 lib/graph/graph.c                | 121 ++++++++
 lib/graph/graph_debug.c          |   4 +
 lib/graph/graph_populate.c       |   1 +
 lib/graph/graph_private.h        |  43 +++
 lib/graph/graph_sched.c          | 194 +++++++++++++
 lib/graph/graph_stats.c          |  19 +-
 lib/graph/meson.build            |   2 +
 lib/graph/node.c                 |  25 ++
 lib/graph/rte_graph.h            |  50 ++++
 lib/graph/rte_graph_worker.h     |  59 ++++
 lib/graph/version.map            |   5 +
 16 files changed, 1327 insertions(+), 4 deletions(-)
 create mode 100644 examples/l2fwd-graph/main.c
 create mode 100644 examples/l2fwd-graph/meson.build
 create mode 100644 examples/l2fwd-graph/node.c
 create mode 100644 examples/l2fwd-graph/node.h
 create mode 100644 lib/graph/graph_sched.c
Signature · 1 line
2.25.1
author
#1 lore raw

RFC 1/6 graph: introduce core affinity API into graph

1. add lcore_id for node to hold affinity core id
2. impl rte_node_set_lcore_affinity to affinity node with one lcore
3. update version map for graph public API

---
 lib/graph/graph_private.h |  1 +
 lib/graph/node.c          | 25 +++++++++++++++++++++++++
 lib/graph/rte_graph.h     | 15 +++++++++++++++
 lib/graph/version.map     |  1 +
 4 files changed, 42 insertions(+)
lib/graph/graph_private.h +1 -0
index f9a85c8926..627090f802 100644
@@ -49,6 +49,7 @@ 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 */
 	rte_node_process_t process;   /**< Node process function. */
 	rte_node_init_t init;         /**< Node init function. */
 	rte_node_fini_t fini;	      /**< Node fini function. */
lib/graph/node.c +25 -0
index ae6eadb260..2ce031886b 100644
@@ -99,6 +99,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 */
@@ -192,6 +193,30 @@ rte_node_clone(rte_node_t id, const char *name)
 	return RTE_NODE_ID_INVALID;
 }
 
+int
+rte_node_set_lcore_affinity(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, next) {
+		if (strncmp(node->name, name, RTE_NODE_NAMESIZE) == 0) {
+			node->lcore_id = lcore_id;
+			ret = 0;
+			break;
+		}
+	}
+
+	graph_spinlock_unlock();
+
+	return ret;
+}
+
 rte_node_t
 rte_node_from_name(const char *name)
 {
lib/graph/rte_graph.h +15 -0
index b32c4bc217..9f84461dd8 100644
@@ -510,6 +510,21 @@ rte_node_t rte_node_from_name(const char *name);
 __rte_experimental
 char *rte_node_id_to_name(rte_node_t id);
 
+/**
+ * Set lcore affinity to the node.
+ *
+ * @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_node_set_lcore_affinity(const char *name, unsigned int lcore_id);
+
 /**
  * Get the number of edges(next-nodes) for a node from node id.
  *
lib/graph/version.map +1 -0
index 13b838752d..6d40a74731 100644
@@ -42,6 +42,7 @@ EXPERIMENTAL {
 	rte_node_next_stream_get;
 	rte_node_next_stream_put;
 	rte_node_next_stream_move;
+	rte_node_set_lcore_affinity;
 
 	local: *;
 };
Signature · 1 line
2.25.1
author
#2 lore raw

RFC 2/6 graph: introduce graph clone API for other worker core

In reply to Zhirun Yan

This patch adds graph API for supporting to clone the graph object for a specified worker core. The new graph will also clone all nodes.

---
 lib/graph/graph.c         | 115 ++++++++++++++++++++++++++++++++++++++
 lib/graph/graph_private.h |   4 ++
 lib/graph/rte_graph.h     |  32 +++++++++++
 lib/graph/version.map     |   1 +
 4 files changed, 152 insertions(+)
lib/graph/graph.c +115 -0
index d61288647c..b4eb18175a 100644
@@ -327,6 +327,8 @@ rte_graph_create(const char *name, struct rte_graph_param *prm)
 	graph->src_node_count = src_node_count;
 	graph->node_count = graph_nodes_count(graph);
 	graph->id = graph_id;
+	graph->parent_id = RTE_GRAPH_ID_INVALID;
+	graph->lcore_id = RTE_MAX_LCORE;
 
 	/* Allocate the Graph fast path memory and populate the data */
 	if (graph_fp_mem_create(graph))
@@ -387,6 +389,119 @@ rte_graph_destroy(rte_graph_t id)
 	return rc;
 }
 
+static int
+clone_name(struct graph *graph, struct graph *parent_graph, const char *name)
+{
+	ssize_t sz, rc;
+
+#define SZ RTE_GRAPH_NAMESIZE
+	rc = rte_strscpy(graph->name, parent_graph->name, SZ);
+	if (rc < 0)
+		goto fail;
+	sz = rc;
+	rc = rte_strscpy(graph->name + sz, "-", RTE_MAX((int16_t)(SZ - sz), 0));
+	if (rc < 0)
+		goto fail;
+	sz += rc;
+	sz = rte_strscpy(graph->name + sz, name, RTE_MAX((int16_t)(SZ - sz), 0));
+	if (sz < 0)
+		goto fail;
+
+	return 0;
+fail:
+	rte_errno = E2BIG;
+	return -rte_errno;
+}
+
+static rte_graph_t
+graph_clone(struct graph *parent_graph, const char *name,
+	    struct rte_graph_clone_param *prm)
+{
+	struct graph_node *graph_node;
+	struct graph *graph;
+
+	graph_spinlock_lock();
+
+	if (prm->lcore_id >= RTE_MAX_LCORE)
+		SET_ERR_JMP(EINVAL, fail, "Invalid lcore ID");
+
+	/* Don't allow to clone a node from a cloned graph */
+	if (parent_graph->parent_id != RTE_GRAPH_ID_INVALID)
+		SET_ERR_JMP(EEXIST, fail, "A cloned graph is not allowed to be cloned");
+
+	/* Create graph object */
+	graph = calloc(1, sizeof(*graph));
+	if (graph == NULL)
+		SET_ERR_JMP(ENOMEM, fail, "Failed to calloc cloned graph object");
+
+	/* Naming ceremony of the new graph. name is node->name + "-" + name */
+	if (clone_name(graph, parent_graph, name))
+		goto free;
+
+	/* Check for existence of duplicate graph */
+	if (rte_graph_from_name(graph->name) != RTE_GRAPH_ID_INVALID)
+		SET_ERR_JMP(EEXIST, free, "Found duplicate graph %s",
+			    graph->name);
+
+	/* Clone nodes from parent graph firstly */
+	STAILQ_INIT(&graph->node_list);
+	STAILQ_FOREACH(graph_node, &parent_graph->node_list, next) {
+		if (graph_node_add(graph, graph_node->node))
+			goto graph_cleanup;
+	}
+
+	/* Just update adjacency list of all nodes in the graph */
+	if (graph_adjacency_list_update(graph))
+		goto graph_cleanup;
+
+	/* Initialize the graph object */
+	graph->src_node_count = parent_graph->src_node_count;
+	graph->node_count = parent_graph->node_count;
+	graph->parent_id = parent_graph->id;
+	graph->lcore_id = prm->lcore_id;
+	graph->socket = rte_lcore_to_socket_id(prm->lcore_id);
+	graph->id = graph_id;
+
+	/* Allocate the Graph fast path memory and populate the data */
+	if (graph_fp_mem_create(graph))
+		goto graph_cleanup;
+
+	/* Call init() of the all the nodes in the graph */
+	if (graph_node_init(graph))
+		goto graph_mem_destroy;
+
+	/* All good, Lets add the graph to the list */
+	graph_id++;
+	STAILQ_INSERT_TAIL(&graph_list, graph, next);
+
+	graph_spinlock_unlock();
+	return graph->id;
+
+graph_mem_destroy:
+	graph_fp_mem_destroy(graph);
+graph_cleanup:
+	graph_cleanup(graph);
+free:
+	free(graph);
+fail:
+	graph_spinlock_unlock();
+	return RTE_GRAPH_ID_INVALID;
+}
+
+rte_graph_t
+rte_graph_clone(rte_graph_t id, const char *name, struct rte_graph_clone_param *prm)
+{
+	struct graph *graph;
+
+	GRAPH_ID_CHECK(id);
+	STAILQ_FOREACH(graph, &graph_list, next)
+		if (graph->id == id)
+			return graph_clone(graph, name, prm);
+
+fail:
+	return RTE_GRAPH_ID_INVALID;
+}
+
 rte_graph_t
 rte_graph_from_name(const char *name)
 {
lib/graph/graph_private.h +4 -0
index 627090f802..d53ef289d4 100644
@@ -97,8 +97,12 @@ struct graph {
 	/**< Circular buffer mask for wrap around. */
 	rte_graph_t id;
 	/**< Graph identifier. */
+	rte_graph_t parent_id;
+	/**< Parent graph identifier. */
 	size_t mem_sz;
 	/**< Memory size of the graph. */
+	unsigned int lcore_id;
+	/**< Lcore identifier where the grap runs on. */
 	int socket;
 	/**< Socket identifier where memory is allocated. */
 	STAILQ_HEAD(gnode_list, graph_node) node_list;
lib/graph/rte_graph.h +32 -0
index 9f84461dd8..27fd1e6cd0 100644
@@ -166,6 +166,15 @@ struct rte_graph_param {
 	/**< Array of node patterns based on shell pattern. */
 };
 
+/**
+ * Structure to hold configuration parameters for cloning the graph.
+ *
+ * @see rte_graph_clone()
+ */
+struct rte_graph_clone_param {
+	unsigned int lcore_id; /**< Lcore id where the new graph is cloned to run. */
+};
+
 /**
  * Structure to hold configuration parameters for graph cluster stats create.
  *
@@ -242,6 +251,29 @@ rte_graph_t rte_graph_create(const char *name, struct rte_graph_param *prm);
 __rte_experimental
 int rte_graph_destroy(rte_graph_t id);
 
+/**
+ * Clone Graph.
+ *
+ * Clone a graph from static graph (graph created from rte_graph_create). And
+ * all cloned graphs attached to the parent graph MUST be destroied together
+ * for fast schedule design limitation (stop ALL graph walk firstly).
+ *
+ * @param id
+ *   Static graph id to clone from.
+ * @param name
+ *   Name of the new graph. The library prepends the parent graph name to the
+ * user-specified name. The final graph name will be,
+ * "parent graph name" + "-" + name.
+ * @param prm
+ *   Graph clone parameter, includes lcore ID.
+ *
+ * @return
+ *   Valid graph id on success, RTE_GRAPH_ID_INVALID otherwise.
+ */
+__rte_experimental
+rte_graph_t rte_graph_clone(rte_graph_t id, const char *name,
+			    struct rte_graph_clone_param *prm);
+
 /**
  * Get graph id from graph name.
  *
lib/graph/version.map +1 -0
index 6d40a74731..6fc43e4411 100644
@@ -5,6 +5,7 @@ EXPERIMENTAL {
 	__rte_node_stream_alloc;
 	__rte_node_stream_alloc_size;
 
+	rte_graph_clone;
 	rte_graph_create;
 	rte_graph_destroy;
 	rte_graph_dump;
Signature · 1 line
2.25.1
author
#3 lore raw

RFC 3/6 graph: enable stream moving cross cores

In reply to Zhirun Yan

This patch allows a worker thread to enable enqueue and move streams of objects to the next nodes over different cores.

1. add graph_sched_wq_node to hold graph scheduling workqueue node stream
2. add workqueue help functions to create/destroy/enqueue/dequeue

---
 lib/graph/graph_populate.c   |   1 +
 lib/graph/graph_private.h    |  38 +++++++
 lib/graph/graph_sched.c      | 194 +++++++++++++++++++++++++++++++++++
 lib/graph/meson.build        |   2 +
 lib/graph/rte_graph_worker.h |  45 ++++++++
 lib/graph/version.map        |   3 +
 6 files changed, 283 insertions(+)
 create mode 100644 lib/graph/graph_sched.c
lib/graph/graph_populate.c +1 -0
index 102fd6c29b..26f9670406 100644
@@ -84,6 +84,7 @@ graph_nodes_populate(struct graph *_graph)
 		}
 		node->id = graph_node->node->id;
 		node->parent_id = pid;
+		node->lcore_id = graph_node->node->lcore_id;
 		nb_edges = graph_node->node->nb_edges;
 		node->nb_edges = nb_edges;
 		off += sizeof(struct rte_node);
lib/graph/graph_private.h +38 -0
index d53ef289d4..e50a207764 100644
@@ -59,6 +59,17 @@ struct node {
 	char next_nodes[][RTE_NODE_NAMESIZE]; /**< Names of next nodes. */
 };
 
+/**
+ * @internal
+ *
+ * Structure that holds the graph scheduling workqueue node stream.
+ */
+struct graph_sched_wq_node {
+	rte_graph_off_t node_off;
+	uint16_t nb_objs;
+	void *objs[RTE_GRAPH_BURST_SIZE];
+} __rte_cache_aligned;
+
 /**
  * @internal
  *
@@ -349,4 +360,31 @@ void graph_dump(FILE *f, struct graph *g);
  */
 void node_dump(FILE *f, struct node *n);
 
+/**
+ * @internal
+ *
+ * Create the graph schedule work queue. And all cloned graphs attached to the
+ * parent graph MUST be destroied together for fast schedule design limitation.
+ *
+ * @param _graph
+ *   The graph object
+ * @param _parent_graph
+ *   The parent graph object which holds the run-queue head.
+ *
+ * @return
+ *   - 0: Success.
+ *   - <0: Graph schedule work queue related error.
+ */
+int graph_sched_wq_create(struct graph *_graph, struct graph *_parent_graph);
+
+/**
+ * @internal
+ *
+ * Destroy the graph schedule work queue.
+ *
+ * @param _graph
+ *   The graph object
+ */
+void graph_sched_wq_destroy(struct graph *_graph);
+
 #endif /* _RTE_GRAPH_PRIVATE_H_ */
lib/graph/graph_sched.c new file +194 -0

194 lines not on this page · raw message

lib/graph/meson.build +2 -0
index c7327549e8..440063b24e 100644
@@ -13,8 +13,10 @@ sources = files(
         'graph_ops.c',
         'graph_debug.c',
         'graph_stats.c',
+        'graph_sched.c',
         'graph_populate.c',
 )
 headers = files('rte_graph.h', 'rte_graph_worker.h')
 
 deps += ['eal']
+deps += ['mempool', 'ring']
lib/graph/rte_graph_worker.h +45 -0

69 lines not on this page · raw message

lib/graph/version.map +3 -0
index 6fc43e4411..99f82eb21a 100644
@@ -1,6 +1,9 @@
 EXPERIMENTAL {
 	global:
 
+	__rte_graph_sched_node_enqueue;
+	__rte_graph_sched_wq_process;
+
 	__rte_node_register;
 	__rte_node_stream_alloc;
 	__rte_node_stream_alloc_size;
Signature · 1 line
2.25.1
author
#4 lore raw

RFC 4/6 graph: enhance graph walk by cross-core dispatch

In reply to Zhirun Yan

This patch enhance the task scheduler mechanism to enable dispatching tasks to another worker cores. Currently, there is only a local work queue for one graph to walk. We introduce a scheduler worker queue in each worker core for dispatching tasks. It will perform the walk on scheduler work queue first, then handle the local work queue.

---
 lib/graph/graph.c            |  6 ++++++
 lib/graph/rte_graph_worker.h | 11 +++++++++++
 2 files changed, 17 insertions(+)
lib/graph/graph.c +6 -0
index b4eb18175a..49ea2b3fbb 100644
@@ -368,6 +368,8 @@ rte_graph_destroy(rte_graph_t id)
 	while (graph != NULL) {
 		tmp = STAILQ_NEXT(graph, next);
 		if (graph->id == id) {
+			/* Destroy the schedule work queue if has */
+			graph_sched_wq_destroy(graph);
 			/* Call fini() of the all the nodes in the graph */
 			graph_node_fini(graph);
 			/* Destroy graph fast path memory */
@@ -470,6 +472,10 @@ graph_clone(struct graph *parent_graph, const char *name,
 	if (graph_node_init(graph))
 		goto graph_mem_destroy;
 
+	/* Create the graph schedule work queue */
+	if (graph_sched_wq_create(graph, parent_graph))
+		goto graph_mem_destroy;
+
 	/* All good, Lets add the graph to the list */
 	graph_id++;
 	STAILQ_INSERT_TAIL(&graph_list, graph, next);
lib/graph/rte_graph_worker.h +11 -0
index faf3f31ddc..e98697d880 100644
@@ -177,6 +177,7 @@ static inline void
 rte_graph_walk(struct rte_graph *graph)
 {
 	const rte_graph_off_t *cir_start = graph->cir_start;
+	const unsigned int lcore_id = graph->lcore_id;
 	const rte_node_t mask = graph->cir_mask;
 	uint32_t head = graph->head;
 	struct rte_node *node;
@@ -184,6 +185,9 @@ rte_graph_walk(struct rte_graph *graph)
 	uint16_t rc;
 	void **objs;
 
+	if (graph->wq != NULL)
+		__rte_graph_sched_wq_process(graph);
+
 	/*
 	 * Walk on the source node(s) ((cir_start - head) -> cir_start) and then
 	 * on the pending streams (cir_start -> (cir_start + mask) -> cir_start)
@@ -205,6 +209,12 @@ rte_graph_walk(struct rte_graph *graph)
 		objs = node->objs;
 		rte_prefetch0(objs);
 
+		/* Schedule the node until all task/objs are done */
+		if (node->lcore_id != RTE_MAX_LCORE && (int32_t)head > 0 &&
+		    lcore_id != node->lcore_id && graph->rq != NULL &&
+		    __rte_graph_sched_node_enqueue(node, graph->rq))
+			goto next;
+
 		if (rte_graph_has_stats_feature()) {
 			start = rte_rdtsc();
 			rc = node->process(graph, node, objs, node->idx);
@@ -215,6 +225,7 @@ rte_graph_walk(struct rte_graph *graph)
 			node->process(graph, node, objs, node->idx);
 		}
 		node->idx = 0;
+	next:
 		head = likely((int32_t)head > 0) ? head & mask : head;
 	}
 	graph->tail = 0;
Signature · 1 line
2.25.1
#5 lore raw

RE: [EXT] [RFC, v1 4/6] graph: enhance graph walk by cross-core dispatch

Quoted 52 lines

This patch enhance the task scheduler mechanism to enable dispatching tasks to another worker cores. Currently, there is only a local work queue for one graph to walk. We introduce a scheduler worker queue in each worker core for dispatching tasks. It will perform the walk on scheduler work queue first, then handle the local work queue.

---
 lib/graph/graph.c            |  6 ++++++
 lib/graph/rte_graph_worker.h | 11 +++++++++++
 2 files changed, 17 insertions(+)
lib/graph/graph.c +6 -0
index b4eb18175a..49ea2b3fbb 100644
@@ -368,6 +368,8 @@ rte_graph_destroy(rte_graph_t id)
 	while (graph != NULL) {
 		tmp = STAILQ_NEXT(graph, next);
 		if (graph->id == id) {
+			/* Destroy the schedule work queue if has */
+			graph_sched_wq_destroy(graph);
 			/* Call fini() of the all the nodes in the graph */
 			graph_node_fini(graph);
 			/* Destroy graph fast path memory */
@@ -470,6 +472,10 @@ graph_clone(struct graph *parent_graph, const char
 *name,
 	if (graph_node_init(graph))
 		goto graph_mem_destroy;
 
+	/* Create the graph schedule work queue */
+	if (graph_sched_wq_create(graph, parent_graph))
+		goto graph_mem_destroy;
+
 	/* All good, Lets add the graph to the list */
 	graph_id++;
lib/graph/graph.c +0 -0
 	STAILQ_INSERT_TAIL(&graph_list, graph, next);
lib/graph/rte_graph_worker.h +1 -0
index faf3f31ddc..e98697d880 100644
@@ -177,6 +177,7 @@ static inline void
 rte_graph_walk(struct rte_graph *graph)
 {
 	const rte_graph_off_t *cir_start = graph->cir_start;
+	const unsigned int lcore_id = graph->lcore_id;
 	const rte_node_t mask = graph->cir_mask;
 	uint32_t head = graph->head;
 	struct rte_node *node;

lib/graph/rte_graph_worker.h rte_graph_walk(struct rte_graph *graph) · line 190

Quoted 6 lines
lib/graph/rte_graph_worker.h +3 -0
@@ -184,6 +185,9 @@ rte_graph_walk(struct rte_graph *graph)
 	uint16_t rc;
 	void **objs;
 
+	if (graph->wq != NULL)
+		__rte_graph_sched_wq_process(graph);
+

We should introduce a flags field in rte_graph_param which can be used by the application to define whether a graph should support multi-core dispatch.

Then we can make __rte_graph_sched_wq_process as node 0 during graph creation so that it will be always called at the start of graph processing followed by calling rest of the nodes.
This will remove unnecessary branches in fastpath.

Quoted 28 lines
lib/graph/rte_graph_worker.h +0 -0
 	/*
 	 * Walk on the source node(s) ((cir_start - head) -> cir_start) and

then

lib/graph/rte_graph_worker.h +2 -0
 	 * on the pending streams (cir_start -> (cir_start + mask) -> cir_start)
@@ -205,6 +209,12 @@ rte_graph_walk(struct rte_graph *graph)
 		objs = node->objs;
 		rte_prefetch0(objs);
 
+		/* Schedule the node until all task/objs are done */
+		if (node->lcore_id != RTE_MAX_LCORE && (int32_t)head > 0

&&

lib/graph/rte_graph_worker.h +5 -1
+		    lcore_id != node->lcore_id && graph->rq != NULL &&
+		    __rte_graph_sched_node_enqueue(node, graph->rq))
+			goto next;
+
 		if (rte_graph_has_stats_feature()) {
 			start = rte_rdtsc();
 			rc = node->process(graph, node, objs, node->idx);
@@ -215,6 +225,7 @@ rte_graph_walk(struct rte_graph *graph)
 			node->process(graph, node, objs, node->idx);
 		}
 		node->idx = 0;
+	next:
 		head = likely((int32_t)head > 0) ? head & mask : head;
 	}
 	graph->tail = 0;
--

2.25.1

#6 lore raw

RE: [EXT] [RFC, v1 4/6] graph: enhance graph walk by cross-core dispatch

Quoted 67 lines

-----Original Message-----
From: Pavan Nikhilesh Bhagavatula <[email protected]>
Sent: Thursday, September 8, 2022 1:27 PM
To: Yan, Zhirun <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>
Cc: Liang, Cunming <[email protected]>; Wang, Haiyue <[email protected]>
Subject: RE: [EXT] [RFC, v1 4/6] graph: enhance graph walk by cross-core dispatch

Quoted 19 lines

This patch enhance the task scheduler mechanism to enable dispatching tasks to another worker cores. Currently, there is only a local work queue for one graph to walk. We introduce a scheduler worker queue in each worker core for dispatching tasks. It will perform the walk on scheduler work queue first, then handle the local work queue.

---
 lib/graph/graph.c            |  6 ++++++
 lib/graph/rte_graph_worker.h | 11 +++++++++++
 2 files changed, 17 insertions(+)
lib/graph/graph.c index renamed from lib/graph/graph.c +0 -0

b4eb18175a..49ea2b3fbb 100644

lib/graph/graph.c rte_graph_destroy(rte_graph_t id) · line 375

Quoted 8 lines
lib/graph/graph.c +2 -0
@@ -368,6 +368,8 @@ rte_graph_destroy(rte_graph_t id)
 	while (graph != NULL) {
 		tmp = STAILQ_NEXT(graph, next);
 		if (graph->id == id) {
+			/* Destroy the schedule work queue if has */
+			graph_sched_wq_destroy(graph);
 			/* Call fini() of the all the nodes in the graph */
 			graph_node_fini(graph);
 			/* Destroy graph fast path memory */ @@ -470,6 +472,10

@@

Quoted 26 lines

graph_clone(struct graph *parent_graph, const char *name,

lib/graph/graph.c +4 -0
 	if (graph_node_init(graph))
 		goto graph_mem_destroy;
 
+	/* Create the graph schedule work queue */
+	if (graph_sched_wq_create(graph, parent_graph))
+		goto graph_mem_destroy;
+
 	/* All good, Lets add the graph to the list */
 	graph_id++;
 	STAILQ_INSERT_TAIL(&graph_list, graph, next); diff --git

a/lib/graph/rte_graph_worker.h b/lib/graph/rte_graph_worker.h index faf3f31ddc..e98697d880 100644

lib/graph/rte_graph_worker.h +1 -0
@@ -177,6 +177,7 @@ static inline void  rte_graph_walk(struct
 rte_graph *graph)  {
 	const rte_graph_off_t *cir_start = graph->cir_start;
+	const unsigned int lcore_id = graph->lcore_id;
 	const rte_node_t mask = graph->cir_mask;
 	uint32_t head = graph->head;
 	struct rte_node *node;
@@ -184,6 +185,9 @@ rte_graph_walk(struct rte_graph *graph)
 	uint16_t rc;
 	void **objs;
 
Quoted 9 lines

lib/graph/rte_graph_worker.h rte_graph_walk(struct rte_graph *graph) · line 190

Quoted 3 lines
lib/graph/rte_graph_worker.h +3 -0
+	if (graph->wq != NULL)
+		__rte_graph_sched_wq_process(graph);
+

We should introduce a flags field in rte_graph_param which can be used by the application to define whether a graph should support multi-core dispatch.

Yes, I will add a flags field in next version.

Quoted 5 lines

Then we can make __rte_graph_sched_wq_process as node 0 during graph creation so that it will be always called at the start of graph processing followed by calling rest of the nodes.
This will remove unnecessary branches in fastpath.

Thanks for your comments and sorry for my late reply.
Yes, we can make __rte_graph_sched_wq_process as node 0 with dispatch flags. But I am not sure whether we need to register a new node here. It means we should change the graph topo, and it will be an isolated node with no links.

Quoted 30 lines
Quoted 5 lines
lib/graph/rte_graph_worker.h +0 -0
 	/*
 	 * Walk on the source node(s) ((cir_start - head) -> cir_start) and

then
* on the pending streams (cir_start -> (cir_start + mask) ->
cir_start) @@ -205,6 +209,12 @@ rte_graph_walk(struct rte_graph

*graph)

lib/graph/rte_graph_worker.h rte_graph_walk(struct rte_graph *graph)

Quoted 13 lines
lib/graph/rte_graph_worker.h +2 -0
 		objs = node->objs;
 		rte_prefetch0(objs);
 
+		/* Schedule the node until all task/objs are done */
+		if (node->lcore_id != RTE_MAX_LCORE && (int32_t)head > 0

&&

lib/graph/rte_graph_worker.h +4 -0
+		    lcore_id != node->lcore_id && graph->rq != NULL &&
+		    __rte_graph_sched_node_enqueue(node, graph->rq))
+			goto next;
+
 		if (rte_graph_has_stats_feature()) {
 			start = rte_rdtsc();
 			rc = node->process(graph, node, objs, node->idx); @@ -215,6

+225,7

Quoted 10 lines

@@ rte_graph_walk(struct rte_graph *graph)

lib/graph/rte_graph_worker.h +1 -1
 			node->process(graph, node, objs, node->idx);
 		}
 		node->idx = 0;
+	next:
 		head = likely((int32_t)head > 0) ? head & mask : head;
 	}
 	graph->tail = 0;
--

2.25.1

author
#7 lore raw

RFC 5/6 graph: add stats for corss-core dispatching

In reply to Zhirun Yan

Add stats for cross-core dispatching scheduler if stats collection is enabled.

---
 lib/graph/graph_debug.c      |  4 ++++
 lib/graph/graph_stats.c      | 19 +++++++++++++++----
 lib/graph/rte_graph.h        |  3 +++
 lib/graph/rte_graph_worker.h |  3 +++
 4 files changed, 25 insertions(+), 4 deletions(-)
lib/graph/graph_debug.c +4 -0
index b84412f5dd..168299259b 100644
@@ -74,6 +74,10 @@ rte_graph_obj_dump(FILE *f, struct rte_graph *g, bool all)
 		fprintf(f, "       size=%d\n", n->size);
 		fprintf(f, "       idx=%d\n", n->idx);
 		fprintf(f, "       total_objs=%" PRId64 "\n", n->total_objs);
+		fprintf(f, "       total_sched_objs=%" PRId64 "\n",
+			n->total_sched_objs);
+		fprintf(f, "       total_sched_fail=%" PRId64 "\n",
+			n->total_sched_fail);
 		fprintf(f, "       total_calls=%" PRId64 "\n", n->total_calls);
 		for (i = 0; i < n->nb_edges; i++)
 			fprintf(f, "          edge[%d] <%s>\n", i,
lib/graph/graph_stats.c +15 -4
index 65e12d46a3..c123ac4087 100644
@@ -41,15 +41,18 @@ struct rte_graph_cluster_stats {
 
 #define boarder()                                                              \
 	fprintf(f, "+-------------------------------+---------------+--------" \
-		   "-------+---------------+---------------+---------------+-" \
+		   "-------+---------------+---------------+---------------+"\
+		   "---------------+---------------+-" \
 		   "----------+\n")
 
 static inline void
 print_banner(FILE *f)
 {
 	boarder();
-	fprintf(f, "%-32s%-16s%-16s%-16s%-16s%-16s%-16s\n", "|Node", "|calls",
-		"|objs", "|realloc_count", "|objs/call", "|objs/sec(10E6)",
+	fprintf(f, "%-32s%-16s%-16s%-16s%-16s%-16s%-16s%-16s%-16s\n",
+		"|Node", "|calls",
+		"|objs", "|sched objs", "|sched fail",
+		"|realloc_count", "|objs/call", "|objs/sec(10E6)",
 		"|cycles/call|");
 	boarder();
 }
@@ -77,8 +80,10 @@ print_node(FILE *f, const struct rte_graph_cluster_node_stats *stat)
 
 	fprintf(f,
 		"|%-31s|%-15" PRIu64 "|%-15" PRIu64 "|%-15" PRIu64
+		"|%-15" PRIu64 "|%-15" PRIu64
 		"|%-15.3f|%-15.6f|%-11.4f|\n",
-		stat->name, calls, objs, stat->realloc_count, objs_per_call,
+		stat->name, calls, objs, stat->sched_objs,
+		stat->sched_fail, stat->realloc_count, objs_per_call,
 		objs_per_sec, cycles_per_call);
 }
 
@@ -331,6 +336,7 @@ static inline void
 cluster_node_arregate_stats(struct cluster_node *cluster)
 {
 	uint64_t calls = 0, cycles = 0, objs = 0, realloc_count = 0;
+	uint64_t sched_objs = 0, sched_fail = 0;
 	struct rte_graph_cluster_node_stats *stat = &cluster->stat;
 	struct rte_node *node;
 	rte_node_t count;
@@ -338,6 +344,9 @@ cluster_node_arregate_stats(struct cluster_node *cluster)
 	for (count = 0; count < cluster->nb_nodes; count++) {
 		node = cluster->nodes[count];
 
+		sched_objs += node->total_sched_objs;
+		sched_fail += node->total_sched_fail;
+
 		calls += node->total_calls;
 		objs += node->total_objs;
 		cycles += node->total_cycles;
@@ -347,6 +356,8 @@ cluster_node_arregate_stats(struct cluster_node *cluster)
 	stat->calls = calls;
 	stat->objs = objs;
 	stat->cycles = cycles;
+	stat->sched_objs = sched_objs;
+	stat->sched_fail = sched_fail;
 	stat->ts = rte_get_timer_cycles();
 	stat->realloc_count = realloc_count;
 }
lib/graph/rte_graph.h +3 -0
index 27fd1e6cd0..1c929d741a 100644
@@ -208,6 +208,9 @@ struct rte_graph_cluster_node_stats {
 	uint64_t objs;      /**< Current number of objs processed. */
 	uint64_t cycles;    /**< Current number of cycles. */
 
+	uint64_t sched_objs;
+	uint64_t sched_fail;
+
 	uint64_t prev_ts;	/**< Previous call timestamp. */
 	uint64_t prev_calls;	/**< Previous number of calls. */
 	uint64_t prev_objs;	/**< Previous number of processed objs. */
lib/graph/rte_graph_worker.h +3 -0
index e98697d880..51f174c5c1 100644
@@ -80,6 +80,9 @@ struct rte_node {
 
 	/* Fast schedule area */
 	unsigned int lcore_id __rte_cache_aligned;  /**< Node running Lcore. */
+	uint64_t total_sched_objs; /**< Number of objects scheduled. */
+	uint64_t total_sched_fail; /**< Number of scheduled failure. */
+
 	/* Fast path area  */
 #define RTE_NODE_CTX_SZ 16
 	uint8_t ctx[RTE_NODE_CTX_SZ] __rte_cache_aligned; /**< Node Context. */
Signature · 1 line
2.25.1
author
#8 lore raw

RFC 6/6 examples: add l2fwd-graph

In reply to Zhirun Yan

From: Haiyue Wang <[email protected]>

l2fwd with graph function.
Adding 3 nodes for quick test, and the node will affinity to worker core successively.

./dpdk-l2fwd-graph -l 7,8,9,10 -n 4 -a 0000:4b:00.0 -- -P

---
 examples/l2fwd-graph/main.c      | 455 +++++++++++++++++++++++++++++++
 examples/l2fwd-graph/meson.build |  25 ++
 examples/l2fwd-graph/node.c      | 263 ++++++++++++++++++
 examples/l2fwd-graph/node.h      |  64 +++++
 examples/meson.build             |   1 +
 5 files changed, 808 insertions(+)
 create mode 100644 examples/l2fwd-graph/main.c
 create mode 100644 examples/l2fwd-graph/meson.build
 create mode 100644 examples/l2fwd-graph/node.c
 create mode 100644 examples/l2fwd-graph/node.h
examples/l2fwd-graph/main.c new file +455 -0
new file mode 100644
index 0000000000..88ffd84340
@@ -0,0 +1,455 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <netinet/in.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <getopt.h>
+#include <signal.h>
+#include <stdbool.h>
+
+#include <rte_common.h>
+#include <rte_log.h>
+#include <rte_malloc.h>
+#include <rte_memory.h>
+#include <rte_memcpy.h>
+#include <rte_eal.h>
+#include <rte_launch.h>
+#include <rte_atomic.h>
+#include <rte_cycles.h>
+#include <rte_prefetch.h>
+#include <rte_lcore.h>
+#include <rte_per_lcore.h>
+#include <rte_branch_prediction.h>
+#include <rte_interrupts.h>
+#include <rte_random.h>
+#include <rte_debug.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_string_fns.h>
+#include <rte_graph_worker.h>
+
+#include "node.h"
+
+#define MAX_PKT_BURST 32
+#define MEMPOOL_CACHE_SIZE 256
+#define RTE_TEST_RX_DESC_DEFAULT 1024
+#define RTE_TEST_TX_DESC_DEFAULT 1024
+
+/* ethernet addresses of ports */
+struct rte_ether_addr l2fwd_ports_eth_addr[RTE_MAX_ETHPORTS];
+
+static struct rte_eth_conf default_port_conf = {
+	.rxmode = {
+		.mq_mode = RTE_ETH_MQ_RX_RSS,
+		.split_hdr_size = 0,
+	},
+	.rx_adv_conf = {
+		.rss_conf = {
+			.rss_key = NULL,
+			.rss_hf = RTE_ETH_RSS_IP,
+		},
+	},
+	.txmode = {
+		.mq_mode = RTE_ETH_MQ_TX_NONE,
+	},
+};
+
+static struct rte_mempool *l2fwd_pktmbuf_pool;
+
+static volatile bool force_quit;
+static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
+static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
+static uint16_t nb_rxq = 1;
+
+/* Lcore conf */
+struct lcore_conf {
+	int enable;
+	uint16_t port_id;
+
+	struct rte_graph *graph;
+	char name[RTE_GRAPH_NAMESIZE];
+	rte_graph_t graph_id;
+} __rte_cache_aligned;
+
+static struct lcore_conf l2fwd_lcore_conf[RTE_MAX_LCORE];
+
+#define L2FWD_GRAPH_NAME_PREFIX "l2fwd_graph_"
+
+static int
+l2fwd_graph_loop(void *conf)
+{
+	struct lcore_conf *lconf;
+	struct rte_graph *graph;
+	uint32_t lcore_id;
+
+	RTE_SET_USED(conf);
+
+	lcore_id = rte_lcore_id();
+	lconf = &l2fwd_lcore_conf[lcore_id];
+	graph = lconf->graph;
+
+	if (!graph) {
+		RTE_LOG(INFO, L2FWD_GRAPH, "Lcore %u has nothing to do\n",
+			lcore_id);
+		return 0;
+	}
+
+	RTE_LOG(INFO, L2FWD_GRAPH,
+		"Entering graph loop on lcore %u, graph %s\n",
+		lcore_id, graph->name);
+
+	while (likely(!force_quit))
+		rte_graph_walk(graph);
+
+	RTE_LOG(INFO, L2FWD_GRAPH,
+		"Leaving graph loop on lcore %u, graph %s\n",
+		lcore_id, graph->name);
+
+	return 0;
+}
+
+static void
+print_stats(void)
+{
+	const char topLeft[] = {27, '[', '1', ';', '1', 'H', '\0'};
+	const char clr[] = {27, '[', '2', 'J', '\0'};
+	struct rte_graph_cluster_stats_param s_param;
+	struct rte_graph_cluster_stats *stats;
+	const char *pattern = L2FWD_GRAPH_NAME_PREFIX "*";
+
+	/* Prepare stats object */
+	memset(&s_param, 0, sizeof(s_param));
+	s_param.f = stdout;
+	s_param.socket_id = SOCKET_ID_ANY;
+	s_param.graph_patterns = &pattern;
+	s_param.nb_graph_patterns = 1;
+
+	stats = rte_graph_cluster_stats_create(&s_param);
+	if (stats == NULL)
+		rte_exit(EXIT_FAILURE, "Unable to create stats object\n");
+
+	while (!force_quit) {
+		/* Clear screen and move to top left */
+		printf("%s%s", clr, topLeft);
+		rte_graph_cluster_stats_get(stats, 0);
+		rte_delay_ms(1E3);
+	}
+
+	rte_graph_cluster_stats_destroy(stats);
+}
+
+static void
+signal_handler(int signum)
+{
+	if (signum == SIGINT || signum == SIGTERM) {
+		printf("\n\nSignal %d received, preparing to exit...\n",
+				signum);
+		force_quit = true;
+	}
+}
+
+enum {
+	/* Long options mapped to a short option */
+
+	/* First long only option value must be >= 256, so that we won't
+	 * conflict with short options
+	 */
+	CMD_LINE_OPT_MIN_NUM = 256,
+	CMD_LINE_OPT_RXQ_NUM,
+};
+
+int
+main(int argc, char **argv)
+{
+	static const char *default_patterns[] = {
+		"l2fwd_pkt_rx-0-0",
+		"l2fwd_pkt_fwd",
+		"l2fwd_pkt_tx",
+		"l2fwd_pkt_drop"
+	};
+	struct rte_graph_param graph_conf;
+	union l2fwd_node_ctx node_ctx;
+	struct lcore_conf *lconf;
+	uint16_t nb_ports_available = 0;
+	uint16_t nb_ports;
+	uint16_t portid;
+	uint16_t fwd_portid = 0;
+	unsigned int nb_lcores = 0;
+	unsigned int lcore_id;
+	unsigned int nb_mbufs;
+	rte_graph_t main_graph_id = RTE_GRAPH_ID_INVALID;
+	rte_graph_t graph_id;
+	uint16_t n;
+	int ret;
+
+	/* init EAL */
+	ret = rte_eal_init(argc, argv);
+	if (ret < 0)
+		rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+	argc -= ret;
+	argv += ret;
+
+	force_quit = false;
+	signal(SIGINT, signal_handler);
+	signal(SIGTERM, signal_handler);
+
+	nb_ports = rte_eth_dev_count_avail();
+	if (nb_ports == 0)
+		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
+
+	nb_lcores = 2;
+	nb_mbufs = RTE_MAX(nb_ports * ((nb_rxd * nb_rxq) + nb_txd + MAX_PKT_BURST +
+			   nb_lcores * MEMPOOL_CACHE_SIZE), 8192U);
+
+	/* create the mbuf pool */
+	l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
+						     MEMPOOL_CACHE_SIZE, 0,
+						     RTE_MBUF_DEFAULT_BUF_SIZE,
+						     rte_socket_id());
+	if (l2fwd_pktmbuf_pool == NULL)
+		rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
+
+	/* Initialise each port */
+	RTE_ETH_FOREACH_DEV(portid) {
+		struct rte_eth_conf local_port_conf = default_port_conf;
+		struct rte_eth_dev_info dev_info;
+		struct rte_eth_rxconf rxq_conf;
+		struct rte_eth_txconf txq_conf;
+
+		nb_ports_available++;
+
+		/* init port */
+		printf("Initializing port %u... ", portid);
+		fflush(stdout);
+
+		ret = rte_eth_dev_info_get(portid, &dev_info);
+		if (ret != 0)
+			rte_exit(EXIT_FAILURE,
+				"Error during getting device (port %u) info: %s\n",
+				portid, strerror(-ret));
+
+		if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
+			local_port_conf.txmode.offloads |=
+				RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
+
+		local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
+			dev_info.flow_type_rss_offloads;
+		if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
+		    default_port_conf.rx_adv_conf.rss_conf.rss_hf) {
+			printf("Port %u modified RSS hash function based on "
+			       "hardware support,"
+			       "requested:%#" PRIx64 " configured:%#" PRIx64
+			       "\n",
+			       portid, default_port_conf.rx_adv_conf.rss_conf.rss_hf,
+			       local_port_conf.rx_adv_conf.rss_conf.rss_hf);
+		}
+
+		ret = rte_eth_dev_configure(portid, nb_rxq, 1, &local_port_conf);
+		if (ret < 0)
+			rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
+				  ret, portid);
+
+		ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd);
+		if (ret < 0)
+			rte_exit(EXIT_FAILURE,
+				 "Cannot adjust number of descriptors: err=%d, port=%u\n",
+				 ret, portid);
+
+		ret = rte_eth_macaddr_get(portid,
+					  &l2fwd_ports_eth_addr[portid]);
+		if (ret < 0)
+			rte_exit(EXIT_FAILURE,
+				 "Cannot get MAC address: err=%d, port=%u\n",
+				 ret, portid);
+
+		/* init RX queues */
+		fflush(stdout);
+		for (n = 0;  n < nb_rxq; n++) {
+			rxq_conf = dev_info.default_rxconf;
+			rxq_conf.offloads = local_port_conf.rxmode.offloads;
+			ret = rte_eth_rx_queue_setup(portid, n, nb_rxd,
+						     rte_eth_dev_socket_id(portid),
+						     &rxq_conf,
+						     l2fwd_pktmbuf_pool);
+			if (ret < 0)
+				rte_exit(EXIT_FAILURE,
+					 "rte_eth_rx_queue_setup:err=%d, port=%u, queue=%u\n",
+					 ret, portid, n);
+		}
+
+		/* init one TX queue on each port */
+		fflush(stdout);
+		txq_conf = dev_info.default_txconf;
+		txq_conf.offloads = local_port_conf.txmode.offloads;
+		ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
+					     rte_eth_dev_socket_id(portid),
+					     &txq_conf);
+		if (ret < 0)
+			rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n",
+				 ret, portid);
+
+		/* Start device */
+		ret = rte_eth_dev_start(portid);
+		if (ret < 0)
+			rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n",
+				 ret, portid);
+
+		ret = rte_eth_promiscuous_enable(portid);
+		if (ret < 0)
+			printf("Failed to set port %u promiscuous mode!\n", portid);
+
+		printf("done:\n");
+
+		printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
+		       portid,
+		       l2fwd_ports_eth_addr[portid].addr_bytes[0],
+		       l2fwd_ports_eth_addr[portid].addr_bytes[1],
+		       l2fwd_ports_eth_addr[portid].addr_bytes[2],
+		       l2fwd_ports_eth_addr[portid].addr_bytes[3],
+		       l2fwd_ports_eth_addr[portid].addr_bytes[4],
+		       l2fwd_ports_eth_addr[portid].addr_bytes[5]);
+
+		fwd_portid = portid;
+	}
+
+	if (!nb_ports_available) {
+		rte_exit(EXIT_FAILURE,
+			"All available ports are disabled. Please set portmask.\n");
+	}
+
+	l2fwd_rx_node_init(0, nb_rxq);
+
+	memset(&node_ctx, 0, sizeof(node_ctx));
+	node_ctx.fwd_ctx.dest_port = fwd_portid;
+	l2fwd_node_ctx_add(l2fwd_get_pkt_fwd_node_id(), &node_ctx);
+
+	memset(&node_ctx, 0, sizeof(node_ctx));
+	node_ctx.rxtx_ctx.port = fwd_portid;
+	node_ctx.rxtx_ctx.queue = 0;
+	l2fwd_node_ctx_add(l2fwd_get_pkt_tx_node_id(), &node_ctx);
+
+	/* Need to set the node Lcore affinity before creating graph */
+	for (n = 0, lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
+		if (rte_lcore_is_enabled(lcore_id) == 0 ||
+		    rte_get_main_lcore() == lcore_id)
+			continue;
+
+		if (n < RTE_DIM(default_patterns)) {
+			ret = rte_node_set_lcore_affinity(default_patterns[n], lcore_id);
+			if (ret == 0)
+				printf("Set node %s affinity to Lcore %u\n",
+				       default_patterns[n], lcore_id);
+		}
+
+		n++;
+	}
+
+	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
+		lconf = &l2fwd_lcore_conf[lcore_id];
+
+		if (rte_lcore_is_enabled(lcore_id) == 0 ||
+		    rte_get_main_lcore() == lcore_id) {
+			lconf->graph_id = RTE_GRAPH_ID_INVALID;
+			continue;
+		}
+
+		if (main_graph_id != RTE_GRAPH_ID_INVALID) {
+			struct rte_graph_clone_param clone_prm;
+
+			snprintf(lconf->name, sizeof(lconf->name), "cloned-%u", lcore_id);
+			memset(&clone_prm, 0, sizeof(clone_prm));
+			clone_prm.lcore_id = lcore_id;
+			graph_id = rte_graph_clone(main_graph_id, lconf->name, &clone_prm);
+			if (graph_id == RTE_GRAPH_ID_INVALID)
+				rte_exit(EXIT_FAILURE,
+					 "Failed to clone graph for lcore %u\n",
+					 lcore_id);
+
+			/* full cloned graph name */
+			snprintf(lconf->name, sizeof(lconf->name), "%s",
+				 rte_graph_id_to_name(graph_id));
+			lconf->graph_id = graph_id;
+			lconf->graph = rte_graph_lookup(lconf->name);
+			if (!lconf->graph)
+				rte_exit(EXIT_FAILURE,
+					 "Failed to lookup graph %s\n",
+					 lconf->name);
+			//rte_graph_obj_dump(stdout, lconf->graph, true);
+			continue;
+		}
+
+		memset(&graph_conf, 0, sizeof(graph_conf));
+		graph_conf.socket_id = rte_lcore_to_socket_id(lcore_id);
+		graph_conf.nb_node_patterns = RTE_DIM(default_patterns);
+		graph_conf.node_patterns = default_patterns;
+
+		snprintf(lconf->name, sizeof(lconf->name), L2FWD_GRAPH_NAME_PREFIX "%u",
+			 lcore_id);
+
+		graph_id = rte_graph_create(lconf->name, &graph_conf);
+		if (graph_id == RTE_GRAPH_ID_INVALID)
+			rte_exit(EXIT_FAILURE,
+				 "Failed to create graph for lcore %u\n",
+				 lcore_id);
+
+		lconf->graph_id = graph_id;
+		lconf->graph = rte_graph_lookup(lconf->name);
+		if (!lconf->graph)
+			rte_exit(EXIT_FAILURE,
+				 "Failed to lookup graph %s\n",
+				 lconf->name);
+		//rte_graph_obj_dump(stdout, lconf->graph, true);
+		main_graph_id = graph_id;
+	}
+
+	rte_eal_mp_remote_launch(l2fwd_graph_loop, NULL, SKIP_MAIN);
+
+	if (rte_graph_has_stats_feature())
+		print_stats();
+
+	ret = 0;
+
+	printf("Waiting all graphs to quit ...\n");
+	RTE_LCORE_FOREACH_WORKER(lcore_id) {
+		if (rte_eal_wait_lcore(lcore_id) < 0) {
+			ret = -1;
+			break;
+		}
+
+		lconf = &l2fwd_lcore_conf[lcore_id];
+		printf("Lcore %u with graph %s quit!\n", lcore_id,
+		       lconf->graph != NULL ? lconf->name : "Empty");
+	}
+
+	RTE_LCORE_FOREACH_WORKER(lcore_id) {
+		graph_id = l2fwd_lcore_conf[lcore_id].graph_id;
+		if (graph_id != RTE_GRAPH_ID_INVALID)
+			rte_graph_destroy(graph_id);
+	}
+
+	RTE_ETH_FOREACH_DEV(portid) {
+		printf("Closing port %d...", portid);
+		ret = rte_eth_dev_stop(portid);
+		if (ret != 0)
+			printf("rte_eth_dev_stop: err=%d, port=%d\n",
+			       ret, portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+	}
+	printf("Bye...\n");
+
+	return ret;
+}
examples/l2fwd-graph/meson.build new file +25 -0
new file mode 100644
index 0000000000..ce417c7ffe
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(C) 2020 Marvell International Ltd.
+
+# meson file, for building this example as part of a main DPDK build.
+#
+# To build this example as a standalone application with an already-installed
+# DPDK instance, use 'make'
+
+allow_experimental_apis = true
+
+deps += ['graph', 'eal', 'lpm', 'ethdev']
+
+if dpdk_conf.has('RTE_MEMPOOL_RING')
+	deps += 'mempool_ring'
+endif
+
+if dpdk_conf.has('RTE_NET_ICE')
+	deps += 'net_ice'
+endif
+
+sources = files(
+	'node.c',
+	'main.c'
+)
+
examples/l2fwd-graph/node.c new file +263 -0

263 lines not on this page · raw message

examples/l2fwd-graph/node.h new file +64 -0

64 lines not on this page · raw message

examples/meson.build +1 -0
index 81e93799f2..7c38e63ebf 100644
@@ -29,6 +29,7 @@ all_examples = [
         'l2fwd-cat',
         'l2fwd-crypto',
         'l2fwd-event',
+        'l2fwd-graph',
         'l2fwd-jobstats',
         'l2fwd-keepalive',
         'l3fwd',
Signature · 1 line
2.25.1
#9 lore raw
In reply to Zhirun Yan
Quoted 18 lines · Zhirun Yan

Currently, the rte_graph_walk() and rte_node_enqueue* fast path API functions in graph lib implementation are designed to work on single-core.

This solution(RFC) proposes usage of cross-core dispatching mechanism to enhance the graph scaling strategy. We introduce Scheduler Workqueue then we could directly dispatch streams to another worker core which is affinity with a specific node.

This RFC:
1. Introduce core affinity API and graph clone API.
2. Introduce key functions to enqueue/dequeue for dispatching streams.
3. Enhance rte_graph_walk by cross-core dispatch.
4. Add l2fwd-graph example and stats for cross-core dispatching.

With this patch set, it could easily plan and orchestrate stream on multi-core systems.

Quoted 7 lines

Future work:
1. Support to affinity lcore set for one node.
2. Use l3fwd-graph instead of l2fwd-graph as example in patch 06.
3. Add new parameter, like --node(nodeid, lcoreid) to config node for core affinity.

Comments and suggestions are welcome. Thanks!

Some top level comments.

1)Yes it makes sense to not create the l2fwd-graph, Please enhance the l3fwd-graph and compare the performance with multi core scenarios.

2) It is good to have multiple graph walk schemes like the one you have introduced now.
Though I am not sure about performance aspects, specifically, it is used with multiple producers and multi consumers with node.

If you have a use case for the new worker scheme, then we can add it. I think, it would call for

a) We need to have separate rte_graph_worker.h for each implementation to avoid the performance impact for each other.
That may boils down to
i) Create lib/graph/rte_graph_worker_common.h
ii) Treat existing rte_graph_worker.h as default scheme and include rte_graph_worker_common.h
iii) Add new rte_graph_worker_xxx.h for the new scheme(diff between default worker) with leveraging te_graph_worker_common.h

Application can select the worker by

#define RTE_GRAPH_WORKER_MODEL_XXX
//#define RTE_GRAPH_WORKER_MODEL_YYY
#include <rte_graph_worker.h>

b) Introduce a new enum rte_graph_model or so to express this new model and other models in feature

c) Each core has its own node instance so we don't need explicit critical section management when dealing with node instances. In this new scheme, Can we leverage the existing node implementation? If not, we need to have separate node
implementation for different graph models. It will be a maintenance issue. But if we really need to take this path,
Probably on each node's capability, the node needs to declare the models supported(Use enum rte_graph_model).
This can be used for sanity checking when we clone the graph etc and check the compatibility for creating the graph etc.
I think this is the biggest issue with adding a new model. Where nodes need to be written based on the model. I think this could be the reason for VPP not adding other models.

d) All new slowpath APIs like rte_node_set_lcore_affinity, rte_graph_clone, We need to fix the namespace by rte_graph_model_<model_name>_<operation> or so to make sure application writer understand this APIs
are only for this model.(Also we can use "enum rte_graph_model" for sanity check etc)

Quoted 1 line
#10 lore raw
Quoted 35 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Tuesday, September 20, 2022 5:33 PM
To: Yan, Zhirun <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Liang, Cunming <[email protected]>; Wang, Haiyue <[email protected]>
Subject: Re: [RFC, v1 0/6] graph enhancement for multi-core dispatch

Quoted 15 lines · Zhirun Yan

Currently, the rte_graph_walk() and rte_node_enqueue* fast path API functions in graph lib implementation are designed to work on single-core.

This solution(RFC) proposes usage of cross-core dispatching mechanism to enhance the graph scaling strategy. We introduce Scheduler Workqueue then we could directly dispatch streams to another worker core which is affinity with a specific node.

This RFC:
1. Introduce core affinity API and graph clone API.
2. Introduce key functions to enqueue/dequeue for dispatching streams.
3. Enhance rte_graph_walk by cross-core dispatch.
4. Add l2fwd-graph example and stats for cross-core dispatching.

Quoted 7 lines

With this patch set, it could easily plan and orchestrate stream on multi-core systems.

Future work:
1. Support to affinity lcore set for one node.
2. Use l3fwd-graph instead of l2fwd-graph as example in patch 06.
3. Add new parameter, like --node(nodeid, lcoreid) to config node for

core

Quoted 9 lines
Quoted 3 lines

affinity.

Comments and suggestions are welcome. Thanks!

Some top level comments.

1)Yes it makes sense to not create the l2fwd-graph, Please enhance the l3fwd-graph and compare the performance with multi core scenarios.

Thanks for your comments.
Yes, I will use l3fwd-graph and compare the performance in next version.

Quoted 17 lines

2) It is good to have multiple graph walk schemes like the one you have introduced now.
Though I am not sure about performance aspects, specifically, it is used with multiple producers and multi consumers with node.

If you have a use case for the new worker scheme, then we can add it. I think, it would call for

a) We need to have separate rte_graph_worker.h for each implementation to avoid the performance impact for each other.
That may boils down to
i) Create lib/graph/rte_graph_worker_common.h
ii) Treat existing rte_graph_worker.h as default scheme and include rte_graph_worker_common.h
iii) Add new rte_graph_worker_xxx.h for the new scheme(diff between default worker) with leveraging te_graph_worker_common.h

Quoted 6 lines

Application can select the worker by

#define RTE_GRAPH_WORKER_MODEL_XXX
//#define RTE_GRAPH_WORKER_MODEL_YYY
#include <rte_graph_worker.h>

Yes, I will break it down in next version.

Quoted 17 lines

b) Introduce a new enum rte_graph_model or so to express this new model and other models in feature

c) Each core has its own node instance so we don't need explicit critical section management when dealing with node instances.
In this new scheme, Can we leverage the existing node implementation? If not, we need to have separate node
implementation for different graph models. It will be a maintenance issue. But if we really need to take this path, Probably on each node's capability, the node needs to declare the models supported(Use enum rte_graph_model).
This can be used for sanity checking when we clone the graph etc and check the compatibility for creating the graph etc.
I think this is the biggest issue with adding a new model. Where nodes need to be written based on the model. I think this could be the reason for VPP not adding other models.

I am agree with you. We should leverage the existing node implementation. Also, I think the node should be agnostic of graph model.

There’re different kinds of data (tables, state, etc.) being referred in the node.
Some of them are private data of node, which has no constraint to any graph model.
For other shared data within graph, it does have thread-safe prerequisite of data access.
Instead of declaring graph model, actually it makes more sense for the node to declare the visibility of data. It can still be transparent to the node. When running on a ‘single-core’ model, it can simplify fallback to a zero cost data access.

Quoted 6 lines

d) All new slowpath APIs like rte_node_set_lcore_affinity, rte_graph_clone, We need to fix the namespace by rte_graph_model_<model_name>_<operation> or so to make sure application writer understand this APIs are only for this model.(Also we can use "enum rte_graph_model" for sanity check etc)

Yes, If the operation is binding with one model, we need add the namespace.

But for rte_node_set_lcore_affinity(), it could be treated as a common API for all models.

For current single-core model, one graph is binding with one lcore. And it actually makes an implicit call to set all nodes to current lcore. So I think rte_node_set_lcore_affinity() could be a common API.

Quoted 3 lines
Quoted 3 lines