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 C4DA8A00C5; Thu, 28 Jul 2022 17:11:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3696F42BB2; Thu, 28 Jul 2022 17:11:55 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 8824D4014F for ; Thu, 28 Jul 2022 17:11:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659021111; x=1690557111; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eqJK7rM0AIyqLHe6hbcrRFn7PUbXHjOuexm3zcWcmBw=; b=PyhxFDHgDy0vgCNOztWig94AyjDk9GZ+eIQN4EICY7r+88xNvQRVVDYa rZGGeAl7gDubJbQloIZvyh8isZxpEENQnVuNd3P5vhpHdT5NuD7u4qs9F E3ve4BaTplBvRYKcTYdeV+ZPS4KoxDFY855QgpGkJugkTXDfqufBZCmn8 PKQvue9wGUpl0yIdtJoVPFxP11Z2QoKsHGTKPbOrNqJr4AyIn8N8DfYJ0 RmFrks0scxZm92eZBDJIZQFenlITvEIGy0/6N30IQoBkIzYBuClzSN7e0 M3h9GQdsfhZYrBTMY3xKbykKNWCoD+JzofjJc/cPHXEVLduU1SMY/D08Z w==; X-IronPort-AV: E=McAfee;i="6400,9594,10422"; a="288547357" X-IronPort-AV: E=Sophos;i="5.93,198,1654585200"; d="scan'208";a="288547357" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2022 08:11:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,198,1654585200"; d="scan'208";a="633727120" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga001.jf.intel.com with ESMTP; 28 Jul 2022 08:11:49 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: "Kamalakannan R ." Subject: [PATCH V6 01/17] pipeline: add pipeline name Date: Thu, 28 Jul 2022 15:11:31 +0000 Message-Id: <20220728151147.603265-2-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220728151147.603265-1-cristian.dumitrescu@intel.com> References: <20220718130713.339003-1-cristian.dumitrescu@intel.com> <20220728151147.603265-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