From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5431E45DA7; Tue, 26 Nov 2024 05:44:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F343640E17; Tue, 26 Nov 2024 05:44:21 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 4EC09400EF for ; Tue, 26 Nov 2024 05:44:19 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AQ1550X009463; Mon, 25 Nov 2024 20:44:12 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=L blZMhtMEovw4at1/0hK+efgRuomwYSM5xOdiLhZoz8=; b=OVrvoXMJKA/PL9ofW H6wss8swxN9INXTXDqkBazHlaHDowsn2wed9IDGXtEcKAG3iNUnVtb07WbRqTxoy 7JNxVW7D5LuvtB5CRDaU2eXmNZYERtKxS6Q9AxFyy5YgtroqInwwhmLbIP/nZFlQ dy6wVdmy6dUAgKSFBN3/ifM6FusYYGyNtXTEGV1XZkYYafpGOsO9C4aPOMIe51Kx HElT9oBGmuXDFOwuPZYFSERA2rmSWF2qq78eQInokoYCGHq6sZw56ltmXc3r/C8x hMx6cAMOVMLgVbyFyVy8pu9G0OA49OGbDJM6nXp3+F+Xr0Gs1LYKG2m5fjP2LlUJ lT4Uw== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4354bt0bhn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Nov 2024 20:44:11 -0800 (PST) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 25 Nov 2024 20:44:11 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 25 Nov 2024 20:44:11 -0800 Received: from cavium-System-Product-Name.. (unknown [10.28.37.22]) by maili.marvell.com (Postfix) with ESMTP id E47493F7093; Mon, 25 Nov 2024 20:44:08 -0800 (PST) From: To: Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan CC: , , Subject: [PATCH v5 1/3] graph: avoid global node ID counter Date: Tue, 26 Nov 2024 10:14:00 +0530 Message-ID: <20241126044402.1209998-1-kirankumark@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241114070432.3152188-1-kirankumark@marvell.com> References: <20241114070432.3152188-1-kirankumark@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: 0ccGP51bVr2aBKETrMQfQjlTXr6kRKBl X-Proofpoint-GUID: 0ccGP51bVr2aBKETrMQfQjlTXr6kRKBl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Kiran Kumar K The node id is determined based on a global variable that is incremented every time a node is created. Adding changes to remove the global counter. Make sure that the node list is always ordered by increasing node ids. When creating a new node, pick a free id which is not allocated. Signed-off-by: Kiran Kumar K --- lib/graph/graph_populate.c | 11 +++-- lib/graph/graph_private.h | 8 ---- lib/graph/node.c | 86 ++++++++++++++++++++++++++++++++------ 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/lib/graph/graph_populate.c b/lib/graph/graph_populate.c index 1e6b08319e..026daecb21 100644 --- a/lib/graph/graph_populate.c +++ b/lib/graph/graph_populate.c @@ -78,7 +78,6 @@ graph_nodes_populate(struct graph *_graph) struct rte_graph *graph = _graph->graph; struct graph_node *graph_node; rte_edge_t count, nb_edges; - const char *parent; rte_node_t pid; STAILQ_FOREACH(graph_node, &_graph->node_list, next) { @@ -94,8 +93,14 @@ graph_nodes_populate(struct graph *_graph) memcpy(node->name, graph_node->node->name, RTE_GRAPH_NAMESIZE); pid = graph_node->node->parent_id; if (pid != RTE_NODE_ID_INVALID) { /* Cloned node */ - parent = rte_node_id_to_name(pid); - memcpy(node->parent, parent, RTE_GRAPH_NAMESIZE); + struct node *pnode; + + STAILQ_FOREACH(pnode, node_list_head_get(), next) { + if (pnode->id == pid) { + memcpy(node->parent, pnode->name, RTE_GRAPH_NAMESIZE); + break; + } + } } node->id = graph_node->node->id; node->parent_id = pid; diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h index da48d73587..fdaf5649b8 100644 --- a/lib/graph/graph_private.h +++ b/lib/graph/graph_private.h @@ -29,14 +29,6 @@ extern int rte_graph_logtype; #define graph_info(...) GRAPH_LOG(INFO, __VA_ARGS__) #define graph_dbg(...) GRAPH_LOG(DEBUG, __VA_ARGS__) -#define ID_CHECK(id, id_max) \ - do { \ - if ((id) >= (id_max)) { \ - rte_errno = EINVAL; \ - goto fail; \ - } \ - } while (0) - #define SET_ERR_JMP(err, where, fmt, ...) \ do { \ graph_err(fmt, ##__VA_ARGS__); \ diff --git a/lib/graph/node.c b/lib/graph/node.c index 63db629da8..5ff8dfcd55 100644 --- a/lib/graph/node.c +++ b/lib/graph/node.c @@ -15,9 +15,56 @@ #include "graph_private.h" static struct node_head node_list = STAILQ_HEAD_INITIALIZER(node_list); -static rte_node_t node_id; -#define NODE_ID_CHECK(id) ID_CHECK(id, node_id) +static struct node * +node_from_id(rte_node_t id) +{ + struct node *node = NULL; + + graph_spinlock_lock(); + rte_errno = EINVAL; + STAILQ_FOREACH(node, &node_list, next) { + if (node->id == id) { + rte_errno = 0; + goto exit; + } + } +exit: + graph_spinlock_unlock(); + return node; +} + +static rte_node_t +next_next_free_id(void) +{ + struct node *node; + rte_node_t id = 0; + + STAILQ_FOREACH(node, &node_list, next) { + if (id < node->id) + break; + id = node->id + 1; + } + return id; +} + +static void +node_insert_ordered(struct node *node) +{ + struct node *after, *g; + + after = NULL; + STAILQ_FOREACH(g, &node_list, next) { + if (g->id < node->id) + after = g; + else if (g->id > node->id) + break; + } + if (after == NULL) + STAILQ_INSERT_HEAD(&node_list, node, next); + else + STAILQ_INSERT_AFTER(&node_list, after, node, next); +} /* Private functions */ struct node_head * @@ -116,10 +163,10 @@ __rte_node_register(const struct rte_node_register *reg) } node->lcore_id = RTE_MAX_LCORE; - node->id = node_id++; + node->id = next_next_free_id(); - /* Add the node at tail */ - STAILQ_INSERT_TAIL(&node_list, node, next); + /* Add the node in ordered list */ + node_insert_ordered(node); graph_spinlock_unlock(); return node->id; @@ -194,7 +241,9 @@ rte_node_clone(rte_node_t id, const char *name) { struct node *node; - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; + STAILQ_FOREACH(node, &node_list, next) if (node->id == id) return node_clone(node, name); @@ -220,7 +269,8 @@ rte_node_id_to_name(rte_node_t id) { struct node *node; - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; STAILQ_FOREACH(node, &node_list, next) if (node->id == id) return node->name; @@ -234,7 +284,8 @@ rte_node_edge_count(rte_node_t id) { struct node *node; - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; STAILQ_FOREACH(node, &node_list, next) if (node->id == id) return node->nb_edges; @@ -303,7 +354,8 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size) rte_edge_t rc = RTE_EDGE_ID_INVALID; struct node *node; - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; graph_spinlock_lock(); STAILQ_FOREACH(node, &node_list, next) { @@ -330,7 +382,8 @@ rte_node_edge_update(rte_node_t id, rte_edge_t from, const char **next_nodes, rte_edge_t rc = RTE_EDGE_ID_INVALID; struct node *n, *prev; - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; graph_spinlock_lock(); prev = NULL; @@ -364,7 +417,8 @@ rte_node_edge_get(rte_node_t id, char *next_nodes[]) rte_node_t rc = RTE_NODE_ID_INVALID; struct node *node; - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; graph_spinlock_lock(); STAILQ_FOREACH(node, &node_list, next) { @@ -388,7 +442,8 @@ node_scan_dump(FILE *f, rte_node_t id, bool all) struct node *node; RTE_ASSERT(f != NULL); - NODE_ID_CHECK(id); + if (node_from_id(id) == NULL) + goto fail; STAILQ_FOREACH(node, &node_list, next) { if (all == true) { @@ -417,5 +472,12 @@ rte_node_list_dump(FILE *f) rte_node_t rte_node_max_count(void) { + rte_node_t node_id = 0; + struct node *node; + + STAILQ_FOREACH(node, &node_list, next) { + if (node_id < node->id) + node_id = node->id; + } return node_id; } -- 2.43.0