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 7009245CE8; Mon, 11 Nov 2024 12:49:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3BE3941101; Mon, 11 Nov 2024 12:49:08 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 5349040E0C for ; Mon, 11 Nov 2024 12:49:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731325745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CTkMS0U6nWQxBZfcd5P/uZ5dwhN/+KqVQdOn4kwq7gM=; b=RSrt1xGJ6NDFsTeOmiXxdJQ2YXOlknwFJQT9yd41X8UFChWJlVQ+FBRpmOlUM9+YjIpdLR hVb7REqXm9sirfrcDrkNzk8t25eNxMoyzaFyAgBDaiTRatYYqy37chSoPRM4Sbc7hSfivL KvuSsI+Q1uYvimP+SVKtTT+FbHlOXYA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-STpuPVtyMkKjBlqCAYUWuw-1; Mon, 11 Nov 2024 06:49:03 -0500 X-MC-Unique: STpuPVtyMkKjBlqCAYUWuw-1 X-Mimecast-MFC-AGG-ID: STpuPVtyMkKjBlqCAYUWuw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-431ad45828aso34014515e9.3 for ; Mon, 11 Nov 2024 03:49:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731325742; x=1731930542; h=in-reply-to:references:user-agent:from:cc:subject:to:message-id :date:content-transfer-encoding:mime-version:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QyOfI1eZRs00ePbN/h15PT3WKCco3LnnhzKRpP2oO/8=; b=vTc5WvTIoe4RfEc7x5p6uHRTWE1ExnDPvy51gCuvG1u7eJMghEkFNlm5FQkfGb7xTW gLVpViBIsPmhmRYQONj5Hiv+lt7hIfhCY/GmAGUtsbVE68byuTU5lmbFM6jIIQsYNyo1 MF0JCfBjOOvOVXnSPfTJ4E/q2OXUvUTMmc5GH/trUtOCf4Ciimc3DenIjYQJB42+5fDh 04B8Y7TnzeLlLWgCG3ymwUEp4r+qeAy9jYK+5KaLmLpRnJRqN0wNvx0XwbACijo1X6fU FFSZCh7DTyjj5EZDJVALsb1KEKH0qtTeG4ln1POoeDDXeMfjCa3EaZ53LxZL4ogsZOrq iAvA== X-Gm-Message-State: AOJu0YyV565pJypagp0LPVQ7he9G27HfvctfRp529OgOy+LF/0wUnsc9 14RduLgMcCIZV2w+pe0KQpdmXdVqeeXi6HNwRU7HrbhpYh4USYcOCxQ9/ImzM3u4ugW6QQFoC7e bcdTxAbNK+iWUVhpl25t710yjUS1FCd53GQmMxugi X-Received: by 2002:a05:600c:35cc:b0:430:5356:ac8e with SMTP id 5b1f17b1804b1-432b74fcb49mr99922025e9.5.1731325741750; Mon, 11 Nov 2024 03:49:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkxMIYIUDZ8VCb3jTyXLgjdlOsoXCLGXaMeTpG+h9LUEPGSx61vBCjUSs1zn/HzZK0QidARw== X-Received: by 2002:a05:600c:35cc:b0:430:5356:ac8e with SMTP id 5b1f17b1804b1-432b74fcb49mr99921805e9.5.1731325741388; Mon, 11 Nov 2024 03:49:01 -0800 (PST) Received: from localhost (2a01cb00025433001b9f807167cdbf20.ipv6.abo.wanadoo.fr. [2a01:cb00:254:3300:1b9f:8071:67cd:bf20]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432aa6b2d13sm203653135e9.12.2024.11.11.03.49.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Nov 2024 03:49:00 -0800 (PST) Mime-Version: 1.0 Date: Mon, 11 Nov 2024 12:48:59 +0100 Message-Id: To: , "Jerin Jacob" , "Nithin Dabilpuram" , "Zhirun Yan" Subject: Re: [PATCH v2 1/3] graph: avoid global node ID counter Cc: , From: "Robin Jarry" User-Agent: aerc/0.18.2-101-g95b6f544c5c4 References: <20241111073437.1796101-1-kirankumark@marvell.com> In-Reply-To: <20241111073437.1796101-1-kirankumark@marvell.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: WEs_SoZzlupBilDFI8OcrePnf4zUZl4MmMwHtJ4iR68_1731325742 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8; format=Flowed 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 , Nov 11, 2024 at 08:34: > 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 Hi Kiran, Thanks for the fix. I think most of the accesses to the node_list is racy. Maybe we need to=20 add a lock to protect that linked list from concurrent access? > --- > 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__) > =20 > -#define ID_CHECK(id, id_max) = \ > -=09do { = \ > -=09=09if ((id) >=3D (id_max)) { \ > -=09=09=09rte_errno =3D EINVAL; \ > -=09=09=09goto fail; \ > -=09=09} \ > -=09} while (0) > - > #define SET_ERR_JMP(err, where, fmt, ...) = \ > =09do { = \ > =09=09graph_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" > =20 > static struct node_head node_list =3D STAILQ_HEAD_INITIALIZER(node_list)= ; > -static rte_node_t node_id; > =20 > -#define NODE_ID_CHECK(id) ID_CHECK(id, node_id) > +static struct node * > +node_from_id(rte_node_t id) > +{ > +=09struct node *node; > + > +=09STAILQ_FOREACH(node, &node_list, next) { > +=09=09if (node->id =3D=3D id) > +=09=09=09return node; > +=09} > +=09rte_errno =3D EINVAL; > +=09return NULL; > +} > + > +static rte_node_t > +next_next_free_id(void) > +{ > +=09struct node *node; > +=09rte_node_t id =3D 0; > + > +=09STAILQ_FOREACH(node, &node_list, next) { > +=09=09if (id < node->id) > +=09=09=09break; > +=09=09id =3D node->id + 1; > +=09} > +=09return id; > +} > + > +static void > +node_insert_ordered(struct node *node) > +{ > +=09struct node *after, *g; > + > +=09after =3D NULL; > +=09STAILQ_FOREACH(g, &node_list, next) { > +=09=09if (g->id < node->id) > +=09=09=09after =3D g; > +=09=09else if (g->id > node->id) > +=09=09=09break; > +=09} > +=09if (after =3D=3D NULL) > +=09=09STAILQ_INSERT_HEAD(&node_list, node, next); > +=09else > +=09=09STAILQ_INSERT_AFTER(&node_list, after, node, next); > +} > =20 > /* Private functions */ > struct node_head * > @@ -116,10 +158,10 @@ __rte_node_register(const struct rte_node_register = *reg) > =09} > =20 > =09node->lcore_id =3D RTE_MAX_LCORE; > -=09node->id =3D node_id++; > +=09node->id =3D next_next_free_id(); > =20 > -=09/* Add the node at tail */ > -=09STAILQ_INSERT_TAIL(&node_list, node, next); > +=09/* Add the node in ordered list */ > +=09node_insert_ordered(node); > =09graph_spinlock_unlock(); > =20 > =09return node->id; > @@ -194,7 +236,9 @@ rte_node_clone(rte_node_t id, const char *name) > { > =09struct node *node; > =20 > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > + > =09STAILQ_FOREACH(node, &node_list, next) > =09=09if (node->id =3D=3D id) > =09=09=09return node_clone(node, name); > @@ -220,7 +264,8 @@ rte_node_id_to_name(rte_node_t id) > { > =09struct node *node; > =20 > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > =09STAILQ_FOREACH(node, &node_list, next) > =09=09if (node->id =3D=3D id) > =09=09=09return node->name; > @@ -234,7 +279,8 @@ rte_node_edge_count(rte_node_t id) > { > =09struct node *node; > =20 > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > =09STAILQ_FOREACH(node, &node_list, next) > =09=09if (node->id =3D=3D id) > =09=09=09return node->nb_edges; > @@ -303,7 +349,8 @@ rte_node_edge_shrink(rte_node_t id, rte_edge_t size) > =09rte_edge_t rc =3D RTE_EDGE_ID_INVALID; > =09struct node *node; > =20 > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > =09graph_spinlock_lock(); > =20 > =09STAILQ_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, > =09rte_edge_t rc =3D RTE_EDGE_ID_INVALID; > =09struct node *n, *prev; > =20 > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > =09graph_spinlock_lock(); > =20 > =09prev =3D NULL; > @@ -364,7 +412,8 @@ rte_node_edge_get(rte_node_t id, char *next_nodes[]) > =09rte_node_t rc =3D RTE_NODE_ID_INVALID; > =09struct node *node; > =20 > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > =09graph_spinlock_lock(); > =20 > =09STAILQ_FOREACH(node, &node_list, next) { > @@ -388,7 +437,8 @@ node_scan_dump(FILE *f, rte_node_t id, bool all) > =09struct node *node; > =20 > =09RTE_ASSERT(f !=3D NULL); > -=09NODE_ID_CHECK(id); > +=09if (node_from_id(id) =3D=3D NULL) > +=09=09goto fail; > =20 > =09STAILQ_FOREACH(node, &node_list, next) { > =09=09if (all =3D=3D true) { > @@ -417,5 +467,12 @@ rte_node_list_dump(FILE *f) > rte_node_t > rte_node_max_count(void) > { > +=09rte_node_t node_id =3D 0; > +=09struct node *node; > + > +=09STAILQ_FOREACH(node, &node_list, next) { > +=09=09if (node_id < node->id) > +=09=09=09node_id =3D node->id; > +=09}