From: Zhirun Yan <zhirun.yan@intel.com>
To: dev@dpdk.org, jerinj@marvell.com, kirankumark@marvell.com
Cc: cunming.liang@intel.com, haiyue.wang@intel.com,
Zhirun Yan <zhirun.yan@intel.com>
Subject: [RFC, v1 2/6] graph: introduce graph clone API for other worker core
Date: Thu, 8 Sep 2022 10:09:55 +0800 [thread overview]
Message-ID: <20220908020959.1675953-3-zhirun.yan@intel.com> (raw)
In-Reply-To: <20220908020959.1675953-1-zhirun.yan@intel.com>
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.
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/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(+)
diff --git a/lib/graph/graph.c b/lib/graph/graph.c
index d61288647c..b4eb18175a 100644
--- a/lib/graph/graph.c
+++ b/lib/graph/graph.c
@@ -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)
{
diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index 627090f802..d53ef289d4 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -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;
diff --git a/lib/graph/rte_graph.h b/lib/graph/rte_graph.h
index 9f84461dd8..27fd1e6cd0 100644
--- a/lib/graph/rte_graph.h
+++ b/lib/graph/rte_graph.h
@@ -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.
*
diff --git a/lib/graph/version.map b/lib/graph/version.map
index 6d40a74731..6fc43e4411 100644
--- a/lib/graph/version.map
+++ b/lib/graph/version.map
@@ -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;
--
2.25.1
next prev parent reply other threads:[~2022-09-08 2:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 2:09 [RFC, v1 0/6] graph enhancement for multi-core dispatch Zhirun Yan
2022-09-08 2:09 ` [RFC, v1 1/6] graph: introduce core affinity API into graph Zhirun Yan
2022-09-08 2:09 ` Zhirun Yan [this message]
2022-09-08 2:09 ` [RFC, v1 3/6] graph: enable stream moving cross cores Zhirun Yan
2022-09-08 2:09 ` [RFC, v1 4/6] graph: enhance graph walk by cross-core dispatch Zhirun Yan
2022-09-08 5:27 ` [EXT] " Pavan Nikhilesh Bhagavatula
2022-09-15 1:52 ` Yan, Zhirun
2022-09-08 2:09 ` [RFC, v1 5/6] graph: add stats for corss-core dispatching Zhirun Yan
2022-09-08 2:09 ` [RFC, v1 6/6] examples: add l2fwd-graph Zhirun Yan
2022-09-20 9:33 ` [RFC, v1 0/6] graph enhancement for multi-core dispatch Jerin Jacob
2022-09-30 6:41 ` Yan, Zhirun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220908020959.1675953-3-zhirun.yan@intel.com \
--to=zhirun.yan@intel.com \
--cc=cunming.liang@intel.com \
--cc=dev@dpdk.org \
--cc=haiyue.wang@intel.com \
--cc=jerinj@marvell.com \
--cc=kirankumark@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).