All of lore.kernel.org
 help / color / mirror / Atom feed
From: <kirankumark@marvell.com>
To: Jerin Jacob <jerinj@marvell.com>,
	Kiran Kumar K <kirankumark@marvell.com>,
	 Nithin Dabilpuram <ndabilpuram@marvell.com>,
	Zhirun Yan <yanzhirun_163@163.com>
Cc: <dev@dpdk.org>
Subject: [PATCH v6 2/3] graph: add support for node free API
Date: Mon, 5 May 2025 11:50:54 +0530	[thread overview]
Message-ID: <20250505062056.570488-2-kirankumark@marvell.com> (raw)
In-Reply-To: <20250505062056.570488-1-kirankumark@marvell.com>

From: Kiran Kumar K <kirankumark@marvell.com>

Add support for rte_node_free API to free the node and its
memory, if node is not part of any of the created graphs.

Signed-off-by: Kiran Kumar K <kirankumark@marvell.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
---
 lib/graph/graph.c         | 16 ++++++++++++++++
 lib/graph/graph_private.h | 13 +++++++++++++
 lib/graph/node.c          | 26 ++++++++++++++++++++++++++
 lib/graph/rte_graph.h     | 15 +++++++++++++++
 4 files changed, 70 insertions(+)

diff --git a/lib/graph/graph.c b/lib/graph/graph.c
index fe12bd3753..0975bd8d49 100644
--- a/lib/graph/graph.c
+++ b/lib/graph/graph.c
@@ -21,6 +21,22 @@
 static struct graph_head graph_list = STAILQ_HEAD_INITIALIZER(graph_list);
 static rte_spinlock_t graph_lock = RTE_SPINLOCK_INITIALIZER;
 
+bool
+graph_is_node_active_in_graph(struct node *node)
+{
+	struct graph *graph;
+
+	STAILQ_FOREACH(graph, &graph_list, next) {
+		struct graph_node *graph_node;
+
+		STAILQ_FOREACH(graph_node, &graph->node_list, next)
+			if (graph_node->node == node)
+				return 1;
+	}
+
+	return 0;
+}
+
 /* Private functions */
 static struct graph *
 graph_from_id(rte_graph_t id)
diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index 3529640abf..eee5be6a34 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -440,4 +440,17 @@ int graph_sched_wq_create(struct graph *_graph, struct graph *_parent_graph,
  */
 void graph_sched_wq_destroy(struct graph *_graph);
 
+/**
+ * @internal
+ *
+ * Check if given node present in any of the created graphs.
+ *
+ * @param node
+ *   The node object
+ *
+ * @return
+ *   0 if not present in any graph, else return 1.
+ */
+bool graph_is_node_active_in_graph(struct node *_node);
+
 #endif /* _RTE_GRAPH_PRIVATE_H_ */
diff --git a/lib/graph/node.c b/lib/graph/node.c
index 53a3f3f2d4..c1b5878592 100644
--- a/lib/graph/node.c
+++ b/lib/graph/node.c
@@ -493,3 +493,29 @@ rte_node_max_count(void)
 	}
 	return node_id;
 }
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_node_free, 25.7)
+int
+rte_node_free(rte_node_t id)
+{
+	struct node *node;
+	int rc = -1;
+
+	if (node_from_id(id) == NULL)
+		goto fail;
+
+	graph_spinlock_lock();
+	STAILQ_FOREACH(node, &node_list, next) {
+		if (id == node->id) {
+			if (!graph_is_node_active_in_graph(node)) {
+				STAILQ_REMOVE(&node_list, node, node, next);
+				free(node);
+				rc = 0;
+			}
+			break;
+		}
+	}
+	graph_spinlock_unlock();
+fail:
+	return rc;
+}
diff --git a/lib/graph/rte_graph.h b/lib/graph/rte_graph.h
index f5e575dbed..097d0dc9d5 100644
--- a/lib/graph/rte_graph.h
+++ b/lib/graph/rte_graph.h
@@ -22,6 +22,7 @@
 #include <stdio.h>
 
 #include <rte_common.h>
+#include <rte_compat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -661,6 +662,20 @@ rte_node_is_invalid(rte_node_t id)
 	return (id == RTE_NODE_ID_INVALID);
 }
 
+/**
+ * Release the memory allocated for a node created using RTE_NODE_REGISTER or rte_node_clone,
+ * if it is not linked to any graphs.
+ *
+ * @param id
+ *   Node id to check.
+ *
+ * @return
+ *   - 0: Success.
+ *   -<0: Failure.
+ */
+__rte_experimental
+int rte_node_free(rte_node_t id);
+
 /**
  * Test the validity of edge id.
  *
-- 
2.48.1


  reply	other threads:[~2025-05-05  6:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14  7:04 [PATCH v3 1/3] graph: avoid global node ID counter kirankumark
2024-11-14  7:04 ` [PATCH v3 2/3] graph: add support for node free API kirankumark
2024-11-14  7:04 ` [PATCH v3 3/3] test/graph: fix graph autotest second run test failure kirankumark
2024-11-14  9:08 ` [PATCH v4 1/3] graph: avoid global node ID counter kirankumark
2024-11-14  9:08   ` [PATCH v4 2/3] graph: add support for node free API kirankumark
2024-11-14 17:07     ` Stephen Hemminger
2024-11-14  9:08   ` [PATCH v4 3/3] test/graph: fix graph autotest second run test failure kirankumark
2024-11-14 17:09     ` Stephen Hemminger
2024-11-26  4:44 ` [PATCH v5 1/3] graph: avoid global node ID counter kirankumark
2024-11-26  4:44   ` [PATCH v5 2/3] graph: add support for node free API kirankumark
2025-02-10 16:49     ` Jerin Jacob
2024-11-26  4:44   ` [PATCH v5 3/3] test/graph: fix graph autotest second run test failure kirankumark
2025-02-10 16:47     ` Jerin Jacob
2025-05-05  6:20   ` [PATCH v6 1/3] graph: avoid global node ID counter kirankumark
2025-05-05  6:20     ` kirankumark [this message]
2025-05-05  6:20     ` [PATCH v6 3/3] test/graph: fix graph autotest second run test failure kirankumark
2025-05-05  6:24   ` [PATCH v7 1/3] graph: avoid global node ID counter kirankumark
2025-05-05  6:24     ` [PATCH v7 2/3] graph: add support for node free API kirankumark
2025-05-05  6:24     ` [PATCH v7 3/3] test/graph: fix graph autotest second run test failure kirankumark
2025-05-30 11:07     ` [PATCH v7 1/3] graph: avoid global node ID counter Kiran Kumar Kokkilagadda
2025-06-11  7:15     ` Thomas Monjalon

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=20250505062056.570488-2-kirankumark@marvell.com \
    --to=kirankumark@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=ndabilpuram@marvell.com \
    --cc=yanzhirun_163@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.