From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 42FD21BEBF for ; Fri, 6 Jul 2018 19:21:31 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 10:21:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,317,1526367600"; d="scan'208";a="64955266" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga003.jf.intel.com with ESMTP; 06 Jul 2018 10:21:19 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 6 Jul 2018 18:20:55 +0100 Message-Id: <20180706172116.50951-3-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180706172116.50951-1-jasvinder.singh@intel.com> References: <20180705154754.147420-2-jasvinder.singh@intel.com> <20180706172116.50951-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v5 02/23] net/softnic: add software queue object 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: , X-List-Received-Date: Fri, 06 Jul 2018 17:21:31 -0000 Add swq object implementation to the softnic. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- drivers/net/softnic/Makefile | 1 + drivers/net/softnic/meson.build | 3 +- drivers/net/softnic/rte_eth_softnic.c | 7 ++ drivers/net/softnic/rte_eth_softnic_internals.h | 39 ++++++++++ drivers/net/softnic/rte_eth_softnic_swq.c | 97 +++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 drivers/net/softnic/rte_eth_softnic_swq.c diff --git a/drivers/net/softnic/Makefile b/drivers/net/softnic/Makefile index 97ac884..5da7842 100644 --- a/drivers/net/softnic/Makefile +++ b/drivers/net/softnic/Makefile @@ -22,6 +22,7 @@ LIBABIVER := 1 # all source are stored in SRCS-y # SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_swq.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tm.c # diff --git a/drivers/net/softnic/meson.build b/drivers/net/softnic/meson.build index 41059da..355749d 100644 --- a/drivers/net/softnic/meson.build +++ b/drivers/net/softnic/meson.build @@ -3,5 +3,6 @@ install_headers('rte_eth_softnic.h') sources = files('rte_eth_softnic_tm.c', - 'rte_eth_softnic.c') + 'rte_eth_softnic.c', + 'rte_eth_softnic_swq.c') deps += 'sched' diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index ccf3bd4..be4b086 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -218,14 +218,21 @@ pmd_init(struct pmd_params *params) if (p == NULL) return NULL; + /* Params */ memcpy(&p->params, params, sizeof(p->params)); + /* Resources */ + softnic_swq_init(p); return p; } static void pmd_free(struct pmd_internals *p) { + if (p == NULL) + return; + + softnic_swq_free(p); rte_free(p); } diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 6ae5954..002b25f 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -7,8 +7,10 @@ #include #include +#include #include +#include #include #include #include @@ -16,6 +18,8 @@ #include "rte_eth_softnic.h" +#define NAME_SIZE 64 + /** * PMD Parameters */ @@ -33,6 +37,21 @@ struct pmd_params { }; /** + * SWQ + */ +struct softnic_swq_params { + uint32_t size; +}; + +struct softnic_swq { + TAILQ_ENTRY(softnic_swq) node; + char name[NAME_SIZE]; + struct rte_ring *r; +}; + +TAILQ_HEAD(softnic_swq_list, softnic_swq); + +/** * Traffic Management (TM) Internals */ @@ -155,9 +174,29 @@ struct pmd_internals { struct { struct tm_internals tm; /**< Traffic Management */ } soft; + + struct softnic_swq_list swq_list; }; /** + * SWQ + */ +int +softnic_swq_init(struct pmd_internals *p); + +void +softnic_swq_free(struct pmd_internals *p); + +struct softnic_swq * +softnic_swq_find(struct pmd_internals *p, + const char *name); + +struct softnic_swq * +softnic_swq_create(struct pmd_internals *p, + const char *name, + struct softnic_swq_params *params); + +/** * Traffic Management (TM) Operation */ extern const struct rte_tm_ops pmd_tm_ops; diff --git a/drivers/net/softnic/rte_eth_softnic_swq.c b/drivers/net/softnic/rte_eth_softnic_swq.c new file mode 100644 index 0000000..c46cad9 --- /dev/null +++ b/drivers/net/softnic/rte_eth_softnic_swq.c @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include +#include + +#include + +#include "rte_eth_softnic_internals.h" + +int +softnic_swq_init(struct pmd_internals *p) +{ + TAILQ_INIT(&p->swq_list); + + return 0; +} + +void +softnic_swq_free(struct pmd_internals *p) +{ + for ( ; ; ) { + struct softnic_swq *swq; + + swq = TAILQ_FIRST(&p->swq_list); + if (swq == NULL) + break; + + TAILQ_REMOVE(&p->swq_list, swq, node); + rte_ring_free(swq->r); + free(swq); + } +} + +struct softnic_swq * +softnic_swq_find(struct pmd_internals *p, + const char *name) +{ + struct softnic_swq *swq; + + if (name == NULL) + return NULL; + + TAILQ_FOREACH(swq, &p->swq_list, node) + if (strcmp(swq->name, name) == 0) + return swq; + + return NULL; +} + +struct softnic_swq * +softnic_swq_create(struct pmd_internals *p, + const char *name, + struct softnic_swq_params *params) +{ + char ring_name[NAME_SIZE]; + struct softnic_swq *swq; + struct rte_ring *r; + unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ; + + /* Check input params */ + if (name == NULL || + softnic_swq_find(p, name) || + params == NULL || + params->size == 0) + return NULL; + + /* Resource create */ + snprintf(ring_name, sizeof(ring_name), "%s_%s", + p->params.name, + name); + + r = rte_ring_create(ring_name, + params->size, + p->params.cpu_id, + flags); + + if (r == NULL) + return NULL; + + /* Node allocation */ + swq = calloc(1, sizeof(struct softnic_swq)); + if (swq == NULL) { + rte_ring_free(r); + return NULL; + } + + /* Node fill in */ + strlcpy(swq->name, name, sizeof(swq->name)); + swq->r = r; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&p->swq_list, swq, node); + + return swq; +} -- 2.9.3