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 BCAC645C7A; Mon, 11 Nov 2024 08:09:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 46B6340B98; Mon, 11 Nov 2024 08:09:41 +0100 (CET) Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 5152E4067A for ; Mon, 11 Nov 2024 08:09:40 +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 4AAM2QBw020174; Sun, 10 Nov 2024 23:09:33 -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=AQRAT3NzcUhqEd9yOA13YnY99dH609eQegnlnCc jIHOTzlfE4pCV0TyzPUOJYo9vdOEjaDXFQExgpdbk+15vZUjSWks98es3O/I6pP5 Y0/k82OBSsOP7aVEW22lZkJ5tMATOTtNQckgHbwxAEglh8/vA7QYg6fW4+e/f9Q4 Ov2pAqcNmxyFNjI/E/HumksccvupKWwuiCWez3fyTIftIrlR6bzQ4sFjqKjQpkZU HkvPtBJKVYOQDLBr6Dnn7QRgPbD3uEhcnkhjdxcBO0guYM/Q9yE6WXE8ewZhYlOo ZoeKhc4Zp7f/1QpPwQs5J5r8/h6cQ2fe+1ktgbGeiHRo0jA== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 42tvvc16hq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 10 Nov 2024 23:09:33 -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; Sun, 10 Nov 2024 23:09:32 -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; Sun, 10 Nov 2024 23:09:32 -0800 Received: from cavium-System-Product-Name.. (unknown [10.28.37.22]) by maili.marvell.com (Postfix) with ESMTP id A0A7C5B692C; Sun, 10 Nov 2024 23:09:30 -0800 (PST) From: To: Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Zhirun Yan CC: Subject: [PATCH 1/3] graph: avoid global node ID counter Date: Mon, 11 Nov 2024 12:39:23 +0530 Message-ID: <20241111070925.1702461-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: -I1-sSxXLmUu8CZmEheHRkImq60QMghF X-Proofpoint-GUID: -I1-sSxXLmUu8CZmEheHRkImq60QMghF 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