From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C7574A0562; Tue, 31 Mar 2020 21:29:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9EB361C13A; Tue, 31 Mar 2020 21:29:45 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 0C82D1C136 for ; Tue, 31 Mar 2020 21:29:43 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02VJTftY030667; Tue, 31 Mar 2020 12:29:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=h9ruOOxDhvMP6YxuQjKfjLexMX+CIyGcq9Pr+n1nSH4=; b=XyTeU3EgVMFhSsZhCthbhRjLMUNLENEoQ0TCDnisCVtknibLraFMKUEkH76501F26QWt GuoBaag5rp0Lw5D/iFhWg24OHAPiDtM5XRNXzQmrfOs1aGz5Qt5rMqGUJ10lzGlGt9z6 rMbfPze0ufcm4Wj3hRA3z05cIKE5zuO9ueQZG7dQ6GlwMFNujeyqA7y2oP7zIjObNGhd 16UeJLRFeHn8VSLKFKxCMfZjZ2z2DaImVeVUC4FeDF1bXNgWfWot/OFTjzI8Y2gOIv7g Ivt8Znm0nACEMCX57E5IWIkhz72B9q+4e2DjFeHseGKQWHqIPoqnAkWxT6xyNhGOzKY5 mQ== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 304855h6wy-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 31 Mar 2020 12:29:42 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 31 Mar 2020 12:29:37 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 31 Mar 2020 12:29:37 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 31 Mar 2020 12:29:36 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 66FFC3F703F; Tue, 31 Mar 2020 12:29:34 -0700 (PDT) From: To: Jerin Jacob , Kiran Kumar K CC: , , , , , , Date: Wed, 1 Apr 2020 00:59:18 +0530 Message-ID: <20200331192945.2466880-3-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200331192945.2466880-1-jerinj@marvell.com> References: <20200326165644.866053-1-jerinj@marvell.com> <20200331192945.2466880-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-03-31_07:2020-03-31, 2020-03-31 signatures=0 Subject: [dpdk-dev] [PATCH v3 02/29] graph: implement node registration X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Adding rte_node_register() API implementation includes allocating memory for node object, check for duplicate node name and add the allocated node to STAILQ node_list for future use. Signed-off-by: Jerin Jacob Signed-off-by: Kiran Kumar K Signed-off-by: Pavan Nikhilesh Signed-off-by: Nithin Dabilpuram --- lib/librte_graph/Makefile | 1 + lib/librte_graph/graph.c | 18 +++- lib/librte_graph/graph_private.h | 75 ++++++++++++++++ lib/librte_graph/meson.build | 2 +- lib/librte_graph/node.c | 115 +++++++++++++++++++++++++ lib/librte_graph/rte_graph_version.map | 4 + 6 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 lib/librte_graph/graph_private.h create mode 100644 lib/librte_graph/node.c diff --git a/lib/librte_graph/Makefile b/lib/librte_graph/Makefile index 26fe514f3..933d0ee49 100644 --- a/lib/librte_graph/Makefile +++ b/lib/librte_graph/Makefile @@ -14,6 +14,7 @@ LDLIBS += -lrte_eal EXPORT_MAP := rte_graph_version.map # all source are stored in SRCS-y +SRCS-$(CONFIG_RTE_LIBRTE_GRAPH) += node.c SRCS-$(CONFIG_RTE_LIBRTE_GRAPH) += graph.c # install header files diff --git a/lib/librte_graph/graph.c b/lib/librte_graph/graph.c index a55bf443a..a9c124896 100644 --- a/lib/librte_graph/graph.c +++ b/lib/librte_graph/graph.c @@ -2,4 +2,20 @@ * Copyright(C) 2020 Marvell International Ltd. */ -#include "rte_graph.h" +#include + +#include "graph_private.h" + +static rte_spinlock_t graph_lock = RTE_SPINLOCK_INITIALIZER; + +void +graph_spinlock_lock(void) +{ + rte_spinlock_lock(&graph_lock); +} + +void +graph_spinlock_unlock(void) +{ + rte_spinlock_unlock(&graph_lock); +} diff --git a/lib/librte_graph/graph_private.h b/lib/librte_graph/graph_private.h new file mode 100644 index 000000000..8b9ff5292 --- /dev/null +++ b/lib/librte_graph/graph_private.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#ifndef _RTE_GRAPH_PRIVATE_H_ +#define _RTE_GRAPH_PRIVATE_H_ + +#include +#include + +#include +#include + +#include "rte_graph.h" + +/** + * @internal + * + * Structure that holds node internal data. + */ +struct node { + STAILQ_ENTRY(node) next; /**< Next node in the list. */ + char name[RTE_NODE_NAMESIZE]; /**< Name of the node. */ + uint64_t flags; /**< Node configuration flag. */ + rte_node_process_t process; /**< Node process function. */ + rte_node_init_t init; /**< Node init function. */ + rte_node_fini_t fini; /**< Node fini function. */ + rte_node_t id; /**< Allocated identifier for the node. */ + rte_node_t parent_id; /**< Parent node identifier. */ + rte_edge_t nb_edges; /**< Number of edges from this node. */ + char next_nodes[][RTE_NODE_NAMESIZE]; /**< Names of next nodes. */ +}; + +/* Node functions */ +STAILQ_HEAD(node_head, node); + +/** + * @internal + * + * Get the head of the node list. + * + * @return + * Pointer to the node head. + */ +struct node_head *node_list_head_get(void); + +/** + * @internal + * + * Get node pointer from node name. + * + * @param name + * Pointer to character string containing the node name. + * + * @return + * Pointer to the node. + */ +struct node *node_from_name(const char *name); + +/* Lock functions */ +/** + * @internal + * + * Take a lock on the graph internal spin lock. + */ +void graph_spinlock_lock(void); + +/** + * @internal + * + * Release a lock on the graph internal spin lock. + */ +void graph_spinlock_unlock(void); + +#endif /* _RTE_GRAPH_PRIVATE_H_ */ diff --git a/lib/librte_graph/meson.build b/lib/librte_graph/meson.build index 455cf2ba5..5754ac23b 100644 --- a/lib/librte_graph/meson.build +++ b/lib/librte_graph/meson.build @@ -4,7 +4,7 @@ name = 'graph' -sources = files('graph.c') +sources = files('node.c', 'graph.c') headers = files('rte_graph.h') allow_experimental_apis = true diff --git a/lib/librte_graph/node.c b/lib/librte_graph/node.c new file mode 100644 index 000000000..7999ca6ed --- /dev/null +++ b/lib/librte_graph/node.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#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) + +/* Private functions */ +struct node_head * +node_list_head_get(void) +{ + return &node_list; +} + +struct node * +node_from_name(const char *name) +{ + struct node *node; + + STAILQ_FOREACH(node, &node_list, next) + if (strncmp(node->name, name, RTE_NODE_NAMESIZE) == 0) + return node; + + return NULL; +} + +static bool +node_has_duplicate_entry(const char *name) +{ + struct node *node; + + /* Is duplicate name registered */ + STAILQ_FOREACH(node, &node_list, next) { + if (strncmp(node->name, name, RTE_NODE_NAMESIZE) == 0) { + rte_errno = EEXIST; + return 1; + } + } + return 0; +} + +/* Public functions */ +rte_node_t +__rte_node_register(const struct rte_node_register *reg) +{ + struct node *node; + rte_edge_t i; + size_t sz; + + graph_spinlock_lock(); + + /* Check sanity */ + if (reg == NULL || reg->process == NULL) { + rte_errno = EINVAL; + goto fail; + } + + /* Check for duplicate name */ + if (node_has_duplicate_entry(reg->name)) + goto fail; + + sz = sizeof(struct node) + (reg->nb_edges * RTE_NODE_NAMESIZE); + node = calloc(1, sz); + if (node == NULL) { + rte_errno = ENOMEM; + goto fail; + } + + /* Initialize the node */ + if (rte_strscpy(node->name, reg->name, RTE_NODE_NAMESIZE) < 0) { + rte_errno = E2BIG; + goto free; + } + node->flags = reg->flags; + node->process = reg->process; + node->init = reg->init; + node->fini = reg->fini; + node->nb_edges = reg->nb_edges; + node->parent_id = reg->parent_id; + for (i = 0; i < reg->nb_edges; i++) { + if (rte_strscpy(node->next_nodes[i], reg->next_nodes[i], + RTE_NODE_NAMESIZE) < 0) { + rte_errno = E2BIG; + goto free; + } + } + + node->id = node_id++; + + /* Add the node at tail */ + STAILQ_INSERT_TAIL(&node_list, node, next); + graph_spinlock_unlock(); + + return node->id; +free: + free(node); +fail: + graph_spinlock_unlock(); + return RTE_NODE_ID_INVALID; +} + diff --git a/lib/librte_graph/rte_graph_version.map b/lib/librte_graph/rte_graph_version.map index 55ef35df5..0884c09f1 100644 --- a/lib/librte_graph/rte_graph_version.map +++ b/lib/librte_graph/rte_graph_version.map @@ -1,3 +1,7 @@ EXPERIMENTAL { + global: + __rte_node_register; + + local: *; }; -- 2.25.1