[v9,06/17] graph: introduce graph bind unbind API
Checks
Commit Message
Add lcore_id for graph to hold affinity core id where graph would run on.
Add bind/unbind API to set/unset graph affinity attribute. lcore_id will
be set as MAX by default, it means not enable this attribute.
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 | 58 +++++++++++++++++++++++++++++++++++++++
lib/graph/graph_private.h | 2 ++
lib/graph/rte_graph.h | 22 +++++++++++++++
lib/graph/version.map | 2 ++
4 files changed, 84 insertions(+)
Comments
On Wed, Jun 7, 2023 at 9:30 AM Zhirun Yan <zhirun.yan@intel.com> wrote:
>
> Add lcore_id for graph to hold affinity core id where graph would run on.
> Add bind/unbind API to set/unset graph affinity attribute. lcore_id will
> be set as MAX by default, it means not enable this attribute.
>
> 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>
> +int
> +rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore)
> +{
> + struct graph *graph;
> +
> + GRAPH_ID_CHECK(id);
> + if (!rte_lcore_is_enabled(lcore))
> + SET_ERR_JMP(ENOLINK, fail, "lcore %d not enabled", lcore);
> +
> + STAILQ_FOREACH(graph, &graph_list, next)
> + if (graph->id == id)
> + break;
> +
> + RTE_ASSERT(graph->graph->model == RTE_GRAPH_MODEL_MCORE_DISPATCH);
No assert in library or slowpath. Return error.
With that change
Acked-by: Jerin Jacob <jerinj@marvell.com>
@@ -260,6 +260,63 @@ graph_mem_fixup_secondary(struct rte_graph *graph)
return graph_mem_fixup_node_ctx(graph);
}
+static bool
+graph_src_node_avail(struct graph *graph)
+{
+ struct graph_node *graph_node;
+
+ STAILQ_FOREACH(graph_node, &graph->node_list, next)
+ if ((graph_node->node->flags & RTE_NODE_SOURCE_F) &&
+ (graph_node->node->lcore_id == RTE_MAX_LCORE ||
+ graph->lcore_id == graph_node->node->lcore_id))
+ return true;
+
+ return false;
+}
+
+int
+rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore)
+{
+ struct graph *graph;
+
+ GRAPH_ID_CHECK(id);
+ if (!rte_lcore_is_enabled(lcore))
+ SET_ERR_JMP(ENOLINK, fail, "lcore %d not enabled", lcore);
+
+ STAILQ_FOREACH(graph, &graph_list, next)
+ if (graph->id == id)
+ break;
+
+ RTE_ASSERT(graph->graph->model == RTE_GRAPH_MODEL_MCORE_DISPATCH);
+ graph->lcore_id = lcore;
+ graph->socket = rte_lcore_to_socket_id(lcore);
+
+ /* check the availability of source node */
+ if (!graph_src_node_avail(graph))
+ graph->graph->head = 0;
+
+ return 0;
+
+fail:
+ return -rte_errno;
+}
+
+void
+rte_graph_model_mcore_dispatch_core_unbind(rte_graph_t id)
+{
+ struct graph *graph;
+
+ GRAPH_ID_CHECK(id);
+ STAILQ_FOREACH(graph, &graph_list, next)
+ if (graph->id == id)
+ break;
+
+ graph->lcore_id = RTE_MAX_LCORE;
+
+fail:
+ return;
+}
+
struct rte_graph *
rte_graph_lookup(const char *name)
{
@@ -346,6 +403,7 @@ 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->lcore_id = RTE_MAX_LCORE;
graph->num_pkt_to_capture = prm->num_pkt_to_capture;
if (prm->pcap_filename)
rte_strscpy(graph->pcap_filename, prm->pcap_filename, RTE_GRAPH_PCAP_FILE_SZ);
@@ -100,6 +100,8 @@ struct graph {
/**< Circular buffer mask for wrap around. */
rte_graph_t id;
/**< Graph identifier. */
+ unsigned int lcore_id;
+ /**< Lcore identifier where the graph prefer to run on. Used for mcore dispatch model. */
size_t mem_sz;
/**< Memory size of the graph. */
int socket;
@@ -285,6 +285,28 @@ char *rte_graph_id_to_name(rte_graph_t id);
__rte_experimental
int rte_graph_export(const char *name, FILE *f);
+/**
+ * Bind graph with specific lcore for mcore dispatch model.
+ *
+ * @param id
+ * Graph id to get the pointer of graph object
+ * @param lcore
+ * The lcore where the graph will run on
+ * @return
+ * 0 on success, error otherwise.
+ */
+__rte_experimental
+int rte_graph_model_mcore_dispatch_core_bind(rte_graph_t id, int lcore);
+
+/**
+ * Unbind graph with lcore for mcore dispatch model
+ *
+ * @param id
+ * Graph id to get the pointer of graph object
+ */
+__rte_experimental
+void rte_graph_model_mcore_dispatch_core_unbind(rte_graph_t id);
+
/**
* Get graph object from its name.
*
@@ -18,6 +18,8 @@ EXPERIMENTAL {
rte_graph_node_get_by_name;
rte_graph_obj_dump;
rte_graph_walk;
+ rte_graph_model_mcore_dispatch_core_bind;
+ rte_graph_model_mcore_dispatch_core_unbind;
rte_graph_cluster_stats_create;
rte_graph_cluster_stats_destroy;