From 0efefe115a1ef0baf411e0cecb6f426ba600d12a Mon Sep 17 00:00:00 2001 From: Jasvinder Singh Date: Fri, 6 Jul 2018 18:20:57 +0100 Subject: [PATCH] net/softnic: add mempool object 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/meson.build | 1 + drivers/net/softnic/rte_eth_softnic.c | 2 + .../net/softnic/rte_eth_softnic_internals.h | 38 +++++++ drivers/net/softnic/rte_eth_softnic_mempool.c | 103 ++++++++++++++++++ 5 files changed, 145 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 3a7a10ffef..b211559ff5 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/meson.build b/drivers/net/softnic/meson.build index 814d614fd5..f20fca48be 100644 --- a/drivers/net/softnic/meson.build +++ b/drivers/net/softnic/meson.build @@ -4,6 +4,7 @@ install_headers('rte_eth_softnic.h') sources = files('rte_eth_softnic_tm.c', 'rte_eth_softnic.c', + 'rte_eth_softnic_mempool.c', 'rte_eth_softnic_swq.c', 'rte_eth_softnic_link.c') deps += 'sched' diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index 18bc41489f..cc22d0adc8 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -216,6 +216,7 @@ pmd_init(struct pmd_params *params) memcpy(&p->params, params, sizeof(p->params)); /* Resources */ + softnic_mempool_init(p); softnic_swq_init(p); softnic_link_init(p); @@ -230,6 +231,7 @@ pmd_free(struct pmd_internals *p) softnic_link_free(p); softnic_swq_free(p); + softnic_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 36dc24723b..be56c4f52f 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 @@ -36,6 +37,24 @@ struct pmd_params { } tm; }; +/** + * MEMPOOL + */ +struct softnic_mempool_params { + uint32_t buffer_size; + uint32_t pool_size; + uint32_t cache_size; +}; + +struct softnic_mempool { + TAILQ_ENTRY(softnic_mempool) node; + char name[NAME_SIZE]; + struct rte_mempool *m; + uint32_t buffer_size; +}; + +TAILQ_HEAD(softnic_mempool_list, softnic_mempool); + /** * SWQ */ @@ -193,10 +212,29 @@ struct pmd_internals { struct tm_internals tm; /**< Traffic Management */ } soft; + struct softnic_mempool_list mempool_list; struct softnic_swq_list swq_list; struct softnic_link_list link_list; }; +/** + * MEMPOOL + */ +int +softnic_mempool_init(struct pmd_internals *p); + +void +softnic_mempool_free(struct pmd_internals *p); + +struct softnic_mempool * +softnic_mempool_find(struct pmd_internals *p, + const char *name); + +struct softnic_mempool * +softnic_mempool_create(struct pmd_internals *p, + const char *name, + struct softnic_mempool_params *params); + /** * SWQ */ 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 0000000000..d5c569f94e --- /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 +softnic_mempool_init(struct pmd_internals *p) +{ + TAILQ_INIT(&p->mempool_list); + + return 0; +} + +void +softnic_mempool_free(struct pmd_internals *p) +{ + for ( ; ; ) { + struct softnic_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 softnic_mempool * +softnic_mempool_find(struct pmd_internals *p, + const char *name) +{ + struct softnic_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 softnic_mempool * +softnic_mempool_create(struct pmd_internals *p, + const char *name, + struct softnic_mempool_params *params) +{ + char mempool_name[NAME_SIZE]; + struct softnic_mempool *mempool; + struct rte_mempool *m; + + /* Check input params */ + if (name == NULL || + softnic_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 softnic_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.20.1