From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id D1EE71C122 for ; Wed, 27 Jun 2018 18:31:31 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jun 2018 09:31:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,279,1526367600"; d="scan'208";a="240789585" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by fmsmga005.fm.intel.com with ESMTP; 27 Jun 2018 09:31:29 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, bernard.iremonger@intel.com Date: Wed, 27 Jun 2018 17:31:04 +0100 Message-Id: <20180627163123.135686-5-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180627163123.135686-1-jasvinder.singh@intel.com> References: <20180615165224.25004-2-jasvinder.singh@intel.com> <20180627163123.135686-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 04/23] net/softnic: add mempool 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: Wed, 27 Jun 2018 16:31:32 -0000 Add mempool object implementation to the softnic. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- drivers/net/softnic/Makefile | 1 + drivers/net/softnic/rte_eth_softnic.c | 2 + drivers/net/softnic/rte_eth_softnic_internals.h | 38 +++++++++ drivers/net/softnic/rte_eth_softnic_mempool.c | 103 ++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 drivers/net/softnic/rte_eth_softnic_mempool.c diff --git a/drivers/net/softnic/Makefile b/drivers/net/softnic/Makefile index 3a7a10f..b211559 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_mempool.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_swq.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_link.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tm.c diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index e1c6a25..5d5dd8e 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -222,6 +222,7 @@ pmd_init(struct pmd_params *params) memcpy(&p->params, params, sizeof(p->params)); /* Resources */ + mempool_init(p); swq_init(p); link_init(p); @@ -236,6 +237,7 @@ pmd_free(struct pmd_internals *p) link_free(p); swq_free(p); + mempool_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 2163979..35fb140 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,24 @@ struct pmd_params { }; /** + * MEMPOOL + */ +struct mempool_params { + uint32_t buffer_size; + uint32_t pool_size; + uint32_t cache_size; +}; + +struct mempool { + TAILQ_ENTRY(mempool) node; + char name[NAME_SIZE]; + struct rte_mempool *m; + uint32_t buffer_size; +}; + +TAILQ_HEAD(mempool_list, mempool); + +/** * SWQ */ struct swq_params { @@ -193,11 +212,30 @@ struct pmd_internals { struct tm_internals tm; /**< Traffic Management */ } soft; + struct mempool_list mempool_list; struct swq_list swq_list; struct link_list link_list; }; /** + * MEMPOOL + */ +int +mempool_init(struct pmd_internals *p); + +void +mempool_free(struct pmd_internals *p); + +struct mempool * +mempool_find(struct pmd_internals *p, + const char *name); + +struct mempool * +mempool_create(struct pmd_internals *p, + const char *name, + struct mempool_params *params); + +/** * SWQ */ int diff --git a/drivers/net/softnic/rte_eth_softnic_mempool.c b/drivers/net/softnic/rte_eth_softnic_mempool.c new file mode 100644 index 0000000..ff2de67 --- /dev/null +++ b/drivers/net/softnic/rte_eth_softnic_mempool.c @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include +#include + +#include +#include + +#include "rte_eth_softnic_internals.h" + +#define BUFFER_SIZE_MIN (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM) + +int +mempool_init(struct pmd_internals *p) +{ + TAILQ_INIT(&p->mempool_list); + + return 0; +} + +void +mempool_free(struct pmd_internals *p) +{ + for ( ; ; ) { + struct mempool *mempool; + + mempool = TAILQ_FIRST(&p->mempool_list); + if (mempool == NULL) + break; + + TAILQ_REMOVE(&p->mempool_list, mempool, node); + rte_mempool_free(mempool->m); + free(mempool); + } +} + +struct mempool * +mempool_find(struct pmd_internals *p, + const char *name) +{ + struct mempool *mempool; + + if (name == NULL) + return NULL; + + TAILQ_FOREACH(mempool, &p->mempool_list, node) + if (strcmp(mempool->name, name) == 0) + return mempool; + + return NULL; +} + +struct mempool * +mempool_create(struct pmd_internals *p, + const char *name, + struct mempool_params *params) +{ + char mempool_name[NAME_SIZE]; + struct mempool *mempool; + struct rte_mempool *m; + + /* Check input params */ + if (name == NULL || + mempool_find(p, name) || + params == NULL || + params->buffer_size < BUFFER_SIZE_MIN || + params->pool_size == 0) + return NULL; + + /* Resource create */ + snprintf(mempool_name, sizeof(mempool_name), "%s_%s", + p->params.name, + name); + + m = rte_pktmbuf_pool_create(mempool_name, + params->pool_size, + params->cache_size, + 0, + params->buffer_size - sizeof(struct rte_mbuf), + p->params.cpu_id); + + if (m == NULL) + return NULL; + + /* Node allocation */ + mempool = calloc(1, sizeof(struct mempool)); + if (mempool == NULL) { + rte_mempool_free(m); + return NULL; + } + + /* Node fill in */ + strlcpy(mempool->name, name, sizeof(mempool->name)); + mempool->m = m; + mempool->buffer_size = params->buffer_size; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&p->mempool_list, mempool, node); + + return mempool; +} -- 2.9.3