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 987AAA00C4; Thu, 28 Jul 2022 00:36:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 370E640DF7; Thu, 28 Jul 2022 00:36:43 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id DB08240141 for ; Thu, 28 Jul 2022 00:36:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658961402; x=1690497402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eqJK7rM0AIyqLHe6hbcrRFn7PUbXHjOuexm3zcWcmBw=; b=NXa7DAYjzC7mKz3S/XX7H0vxpP3gBR0tjsymyDCFTQMoC4sjRcLyL9Rm 5ZGxcbU1WITwWJ3AJ3jpQslcVUmTxTrVUS+VU5AlGMXoK0Mwc89vzboPi 5wNvWzPvjFLizUAwyS7MTpvAtm5Shy0iLJeKZr8cMVujF7g0mxJCgE/yf 4ChY4w/96cVL3thjkxn8QToxg0X6z4rjBweoRdrZSrxctn1yzad0/SDsY hKv4+SGLwOs2THXIPaaD/dfqpE5xlxGJXHMZrUza0jdPrN39e4x1+GG1U WfLUZEKrgDPFLzVv+sKMmm+WBUK/ginjzcqckqLYu1ZnsxgQstlTGMkco w==; X-IronPort-AV: E=McAfee;i="6400,9594,10421"; a="350068816" X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="350068816" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2022 15:36:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="628567594" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga008.jf.intel.com with ESMTP; 27 Jul 2022 15:36:39 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: "Kamalakannan R ." Subject: [PATCH V3 01/17] pipeline: add pipeline name Date: Wed, 27 Jul 2022 22:36:23 +0000 Message-Id: <20220727223639.598932-1-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220718132603.339314-1-cristian.dumitrescu@intel.com> References: <20220718132603.339314-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Add an unique name to every pipeline. This enables the library to maintain a list of the existing pipeline objects, which can be queried by the application. Signed-off-by: Cristian Dumitrescu Signed-off-by: Kamalakannan R. --- examples/pipeline/obj.c | 2 +- lib/pipeline/rte_swx_ctl.c | 99 +++++++++++++++++++++ lib/pipeline/rte_swx_ctl.h | 15 ++++ lib/pipeline/rte_swx_pipeline.c | 107 ++++++++++++++++++++++- lib/pipeline/rte_swx_pipeline.h | 18 +++- lib/pipeline/rte_swx_pipeline_internal.h | 2 + lib/pipeline/version.map | 4 + 7 files changed, 244 insertions(+), 3 deletions(-) diff --git a/examples/pipeline/obj.c b/examples/pipeline/obj.c index b79f044ac7..967342c580 100644 --- a/examples/pipeline/obj.c +++ b/examples/pipeline/obj.c @@ -533,7 +533,7 @@ pipeline_create(struct obj *obj, const char *name, int numa_node) return NULL; /* Resource create */ - status = rte_swx_pipeline_config(&p, numa_node); + status = rte_swx_pipeline_config(&p, name, numa_node); if (status) goto error; diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c index 710e89a46a..1b776fc543 100644 --- a/lib/pipeline/rte_swx_ctl.c +++ b/lib/pipeline/rte_swx_ctl.c @@ -9,6 +9,8 @@ #include #include +#include +#include #include @@ -1157,12 +1159,103 @@ table_state_create(struct rte_swx_ctl_pipeline *ctl) return status; } +/* Global list of pipeline instances. */ +TAILQ_HEAD(rte_swx_ctl_pipeline_list, rte_tailq_entry); + +static struct rte_tailq_elem rte_swx_ctl_pipeline_tailq = { + .name = "RTE_SWX_CTL_PIPELINE", +}; + +EAL_REGISTER_TAILQ(rte_swx_ctl_pipeline_tailq) + +struct rte_swx_ctl_pipeline * +rte_swx_ctl_pipeline_find(const char *name) +{ + struct rte_swx_ctl_pipeline_list *ctl_list; + struct rte_tailq_entry *te = NULL; + + if (!name || !name[0] || (strnlen(name, RTE_SWX_CTL_NAME_SIZE) >= RTE_SWX_CTL_NAME_SIZE)) + return NULL; + + ctl_list = RTE_TAILQ_CAST(rte_swx_ctl_pipeline_tailq.head, rte_swx_ctl_pipeline_list); + + rte_mcfg_tailq_read_lock(); + + TAILQ_FOREACH(te, ctl_list, next) { + struct rte_swx_ctl_pipeline *ctl = (struct rte_swx_ctl_pipeline *)te->data; + + if (!strncmp(name, ctl->info.name, sizeof(ctl->info.name))) { + rte_mcfg_tailq_read_unlock(); + return ctl; + } + } + + rte_mcfg_tailq_read_unlock(); + return NULL; +} + +static int +ctl_register(struct rte_swx_ctl_pipeline *ctl) +{ + struct rte_swx_ctl_pipeline_list *ctl_list; + struct rte_tailq_entry *te = NULL; + + ctl_list = RTE_TAILQ_CAST(rte_swx_ctl_pipeline_tailq.head, rte_swx_ctl_pipeline_list); + + rte_mcfg_tailq_write_lock(); + + TAILQ_FOREACH(te, ctl_list, next) { + struct rte_swx_ctl_pipeline *ctl_crt = (struct rte_swx_ctl_pipeline *)te->data; + + if (!strncmp(ctl->info.name, ctl_crt->info.name, sizeof(ctl->info.name))) { + rte_mcfg_tailq_write_unlock(); + return -EEXIST; + } + } + + te = calloc(1, sizeof(struct rte_tailq_entry)); + if (!te) { + rte_mcfg_tailq_write_unlock(); + return -ENOMEM; + } + + te->data = (void *)ctl; + TAILQ_INSERT_TAIL(ctl_list, te, next); + rte_mcfg_tailq_write_unlock(); + return 0; +} + +static void +ctl_unregister(struct rte_swx_ctl_pipeline *ctl) +{ + struct rte_swx_ctl_pipeline_list *ctl_list; + struct rte_tailq_entry *te = NULL; + + ctl_list = RTE_TAILQ_CAST(rte_swx_ctl_pipeline_tailq.head, rte_swx_ctl_pipeline_list); + + rte_mcfg_tailq_write_lock(); + + TAILQ_FOREACH(te, ctl_list, next) { + if (te->data == (void *)ctl) { + TAILQ_REMOVE(ctl_list, te, next); + rte_mcfg_tailq_write_unlock(); + free(te); + return; + } + } + + rte_mcfg_tailq_write_unlock(); +} + void rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl) { if (!ctl) return; + if (ctl->info.name[0]) + ctl_unregister(ctl); + action_free(ctl); table_state_free(ctl); @@ -1441,6 +1534,12 @@ rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p) if (status) goto error; + if (ctl->info.name[0]) { + status = ctl_register(ctl); + if (status) + goto error; + } + return ctl; error: diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h index d771389d26..63ee479e47 100644 --- a/lib/pipeline/rte_swx_ctl.h +++ b/lib/pipeline/rte_swx_ctl.h @@ -35,6 +35,9 @@ struct rte_swx_pipeline; /** Pipeline info. */ struct rte_swx_ctl_pipeline_info { + /** Pipeline name. */ + char name[RTE_SWX_CTL_NAME_SIZE]; + /** Number of input ports. */ uint32_t n_ports_in; @@ -812,6 +815,18 @@ rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p, /** Pipeline control opaque data structure. */ struct rte_swx_ctl_pipeline; +/** + * Pipeline control find + * + * @param[in] name + * Pipeline name. + * @return + * Valid pipeline control handle if found or NULL otherwise. + */ +__rte_experimental +struct rte_swx_ctl_pipeline * +rte_swx_ctl_pipeline_find(const char *name); + /** * Pipeline control create * diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index 3e1c6e9edb..c8ccded4f8 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include @@ -9578,6 +9580,95 @@ metarray_free(struct rte_swx_pipeline *p) /* * Pipeline. */ + +/* Global list of pipeline instances. */ +TAILQ_HEAD(rte_swx_pipeline_list, rte_tailq_entry); + +static struct rte_tailq_elem rte_swx_pipeline_tailq = { + .name = "RTE_SWX_PIPELINE", +}; + +EAL_REGISTER_TAILQ(rte_swx_pipeline_tailq) + +struct rte_swx_pipeline * +rte_swx_pipeline_find(const char *name) +{ + struct rte_swx_pipeline_list *pipeline_list; + struct rte_tailq_entry *te = NULL; + + if (!name || !name[0] || (strnlen(name, RTE_SWX_NAME_SIZE) >= RTE_SWX_NAME_SIZE)) + return NULL; + + pipeline_list = RTE_TAILQ_CAST(rte_swx_pipeline_tailq.head, rte_swx_pipeline_list); + + rte_mcfg_tailq_read_lock(); + + TAILQ_FOREACH(te, pipeline_list, next) { + struct rte_swx_pipeline *p = (struct rte_swx_pipeline *)te->data; + + if (!strncmp(name, p->name, sizeof(p->name))) { + rte_mcfg_tailq_read_unlock(); + return p; + } + } + + rte_mcfg_tailq_read_unlock(); + return NULL; +} + +static int +pipeline_register(struct rte_swx_pipeline *p) +{ + struct rte_swx_pipeline_list *pipeline_list; + struct rte_tailq_entry *te = NULL; + + pipeline_list = RTE_TAILQ_CAST(rte_swx_pipeline_tailq.head, rte_swx_pipeline_list); + + rte_mcfg_tailq_write_lock(); + + TAILQ_FOREACH(te, pipeline_list, next) { + struct rte_swx_pipeline *pipeline = (struct rte_swx_pipeline *)te->data; + + if (!strncmp(p->name, pipeline->name, sizeof(p->name))) { + rte_mcfg_tailq_write_unlock(); + return -EEXIST; + } + } + + te = calloc(1, sizeof(struct rte_tailq_entry)); + if (!te) { + rte_mcfg_tailq_write_unlock(); + return -ENOMEM; + } + + te->data = (void *)p; + TAILQ_INSERT_TAIL(pipeline_list, te, next); + rte_mcfg_tailq_write_unlock(); + return 0; +} + +static void +pipeline_unregister(struct rte_swx_pipeline *p) +{ + struct rte_swx_pipeline_list *pipeline_list; + struct rte_tailq_entry *te = NULL; + + pipeline_list = RTE_TAILQ_CAST(rte_swx_pipeline_tailq.head, rte_swx_pipeline_list); + + rte_mcfg_tailq_write_lock(); + + TAILQ_FOREACH(te, pipeline_list, next) { + if (te->data == (void *)p) { + TAILQ_REMOVE(pipeline_list, te, next); + rte_mcfg_tailq_write_unlock(); + free(te); + return; + } + } + + rte_mcfg_tailq_write_unlock(); +} + void rte_swx_pipeline_free(struct rte_swx_pipeline *p) { @@ -9586,6 +9677,9 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p) if (!p) return; + if (p->name[0]) + pipeline_unregister(p); + lib = p->lib; free(p->instruction_data); @@ -9720,13 +9814,14 @@ hash_funcs_register(struct rte_swx_pipeline *p) } int -rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node) +rte_swx_pipeline_config(struct rte_swx_pipeline **p, const char *name, int numa_node) { struct rte_swx_pipeline *pipeline = NULL; int status = 0; /* Check input parameters. */ CHECK(p, EINVAL); + CHECK(!name || (strnlen(name, RTE_SWX_NAME_SIZE) < RTE_SWX_NAME_SIZE), EINVAL); /* Memory allocation. */ pipeline = calloc(1, sizeof(struct rte_swx_pipeline)); @@ -9736,6 +9831,9 @@ rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node) } /* Initialization. */ + if (name) + strcpy(pipeline->name, name); + TAILQ_INIT(&pipeline->struct_types); TAILQ_INIT(&pipeline->port_in_types); TAILQ_INIT(&pipeline->ports_in); @@ -9776,6 +9874,12 @@ rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node) if (status) goto error; + if (pipeline->name[0]) { + status = pipeline_register(pipeline); + if (status) + goto error; + } + *p = pipeline; return 0; @@ -9966,6 +10070,7 @@ rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p, TAILQ_FOREACH(table, &p->tables, node) n_tables++; + strcpy(pipeline->name, p->name); pipeline->n_ports_in = p->n_ports_in; pipeline->n_ports_out = p->n_ports_out; pipeline->n_mirroring_slots = p->n_mirroring_slots; diff --git a/lib/pipeline/rte_swx_pipeline.h b/lib/pipeline/rte_swx_pipeline.h index c41ca5cb15..ef50a0fa70 100644 --- a/lib/pipeline/rte_swx_pipeline.h +++ b/lib/pipeline/rte_swx_pipeline.h @@ -44,22 +44,38 @@ extern "C" { /** Pipeline opaque data structure. */ struct rte_swx_pipeline; +/** + * Pipeline find + * + * @param[in] name + * Pipeline name. + * @return + * Valid pipeline handle if found or NULL otherwise. + */ +__rte_experimental +struct rte_swx_pipeline * +rte_swx_pipeline_find(const char *name); + /** * Pipeline configure * * @param[out] p * Pipeline handle. Must point to valid memory. Contains valid pipeline handle * when the function returns successfully. + * @param[in] name + * Pipeline unique name. * @param[in] numa_node * Non-Uniform Memory Access (NUMA) node. * @return * 0 on success or the following error codes otherwise: * -EINVAL: Invalid argument; - * -ENOMEM: Not enough space/cannot allocate memory. + * -ENOMEM: Not enough space/cannot allocate memory; + * -EEXIST: Pipeline with this name already exists. */ __rte_experimental int rte_swx_pipeline_config(struct rte_swx_pipeline **p, + const char *name, int numa_node); /* diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h index a35635efb7..588cad62b5 100644 --- a/lib/pipeline/rte_swx_pipeline_internal.h +++ b/lib/pipeline/rte_swx_pipeline_internal.h @@ -1459,6 +1459,8 @@ instr_operand_nbo(struct thread *t, const struct instr_operand *x) #endif struct rte_swx_pipeline { + char name[RTE_SWX_NAME_SIZE]; + struct struct_type_tailq struct_types; struct port_in_type_tailq port_in_types; struct port_in_tailq ports_in; diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map index 8312307a7a..50029aadcf 100644 --- a/lib/pipeline/version.map +++ b/lib/pipeline/version.map @@ -145,4 +145,8 @@ EXPERIMENTAL { rte_swx_ctl_pipeline_learner_timeout_get; rte_swx_ctl_pipeline_learner_timeout_set; rte_swx_pipeline_hash_func_register; + + #added in 22.11 + rte_swx_ctl_pipeline_find; + rte_swx_pipeline_find; }; -- 2.34.1