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 DCD9A45CE4; Mon, 11 Nov 2024 08:34:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 74AD240E0C; Mon, 11 Nov 2024 08:34:57 +0100 (CET) Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id A9CAE40B98 for ; Mon, 11 Nov 2024 08:34:55 +0100 (CET) Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AANSB3N017051; Sun, 10 Nov 2024 23:34:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pfpt0220; bh=tLj8BtQ5dEknWhWXlRcYlmp F2ofIDnMGUIXihJhkCz4=; b=kX0CX6OvmVwGZESPD/hfw+3zYb7W1SwMYPjGrvl Nr/E9wN9N0RcbICcgJ4rgsSv1BZ+SFB6cXDeLI0o3n3Y5LhtKNFxup+EZCpYo6D5 ZML+/P9sjC2kdVz06Ycq/cdB9SHs0x6vuk0tBUBrPIhxeSWf59Eu1WD4vn6/YzhI L1ju7/bFehYjfLfWIOk3LGM2I+b09lxRwVQAx8qlcFQ2xrb7cNx3qONO5NhSHnoL qHmYVdj1rT1E5RKtg2IjQlU7+Uv5dLHO0WsW1yzUJK0S3Tu4prg8fRBkN7/W3Zfm fObn2njFEnkAySuB1fjHQ6E8ysWzKaGz4sE4/7gi78nZHKQ== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 42tvvc17ux-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 10 Nov 2024 23:34:51 -0800 (PST) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 10 Nov 2024 23:34:50 -0800 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 10 Nov 2024 23:34:50 -0800 Received: from cavium-System-Product-Name.. (unknown [10.28.37.22]) by maili.marvell.com (Postfix) with ESMTP id 2B4305B692C; Sun, 10 Nov 2024 23:34:47 -0800 (PST) From: To: Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan CC: , , Subject: [PATCH v2 1/3] graph: avoid global node ID counter Date: Mon, 11 Nov 2024 13:04:34 +0530 Message-ID: <20241111073437.1796101-1-kirankumark@marvell.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: Z1TzudgEQa0JVMXzvctDql5y-dTmgrq4 X-Proofpoint-GUID: Z1TzudgEQa0JVMXzvctDql5y-dTmgrq4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_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_private.h | 8 ---- lib/graph/node.c | 81 +++++++++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 20 deletions(-) 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..0f382d744c 100644 --- a/lib/graph/node.c +++ b/lib/graph/node.c @@ -15,9 +15,51 @@ #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; + + STAILQ_FOREACH(node, &node_list, next) { + if (node->id == id) + return node; + } + rte_errno = EINVAL; + return NULL; +} + +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 +158,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 +236,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 +264,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 +279,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 +349,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 +377,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 +412,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 +437,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 +467,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