From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 0B6943978 for ; Wed, 9 Mar 2016 17:22:16 +0100 (CET) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id E9F1A24A4A for ; Wed, 9 Mar 2016 17:21:32 +0100 (CET) From: Olivier Matz To: dev@dpdk.org Date: Wed, 9 Mar 2016 17:19:40 +0100 Message-Id: <1457540381-20274-35-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457540381-20274-1-git-send-email-olivier.matz@6wind.com> References: <1457540381-20274-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [RFC 34/35] mempool: new flag when phys contig mem is not needed X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2016 16:22:17 -0000 Add a new flag to remove the constraint of having physically contiguous objects inside a mempool. Add this flag to the log history mempool to start, but we could add it in most cases where objects are not mbufs. Signed-off-by: Olivier Matz --- lib/librte_eal/common/eal_common_log.c | 2 +- lib/librte_mempool/rte_mempool.c | 23 ++++++++++++++++++++--- lib/librte_mempool/rte_mempool.h | 5 +++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 1ae8de7..9122b34 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -322,7 +322,7 @@ rte_eal_common_log_init(FILE *default_log) LOG_ELT_SIZE, 0, 0, NULL, NULL, NULL, NULL, - SOCKET_ID_ANY, 0); + SOCKET_ID_ANY, MEMPOOL_F_NO_PHYS_CONTIG); if ((log_history_mp == NULL) && ((log_history_mp = rte_mempool_lookup(LOG_HISTORY_MP_NAME)) == NULL)){ diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 397e6ec..209449a 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -412,7 +412,11 @@ rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr, while (off + total_elt_sz <= len && mp->populated_size < mp->size) { off += mp->header_size; - mempool_add_elem(mp, (char *)vaddr + off, paddr + off); + if (paddr == RTE_BAD_PHYS_ADDR) + mempool_add_elem(mp, (char *)vaddr + off, + RTE_BAD_PHYS_ADDR); + else + mempool_add_elem(mp, (char *)vaddr + off, paddr + off); off += mp->elt_size + mp->trailer_size; i++; } @@ -441,6 +445,10 @@ rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr, if (mp->nb_mem_chunks != 0) return -EEXIST; + if (mp->flags & MEMPOOL_F_NO_PHYS_CONTIG) + return rte_mempool_populate_phys(mp, vaddr, RTE_BAD_PHYS_ADDR, + pg_num * pg_sz, free_cb, opaque); + for (i = 0; i < pg_num && mp->populated_size < mp->size; i += n) { /* populate with the largest group of contiguous pages */ @@ -481,6 +489,10 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, if (RTE_ALIGN_CEIL(len, pg_sz) != len) return -EINVAL; + if (mp->flags & MEMPOOL_F_NO_PHYS_CONTIG) + return rte_mempool_populate_phys(mp, addr, RTE_BAD_PHYS_ADDR, + len, free_cb, opaque); + for (off = 0; off + pg_sz <= len && mp->populated_size < mp->size; off += phys_len) { @@ -530,6 +542,7 @@ rte_mempool_populate_default(struct rte_mempool *mp) char mz_name[RTE_MEMZONE_NAMESIZE]; const struct rte_memzone *mz; size_t size, total_elt_sz, align, pg_sz, pg_shift; + phys_addr_t paddr; unsigned mz_id, n; int ret; @@ -569,10 +582,14 @@ rte_mempool_populate_default(struct rte_mempool *mp) goto fail; } - /* use memzone physical address if it is valid */ + if (mp->flags & MEMPOOL_F_NO_PHYS_CONTIG) + paddr = RTE_BAD_PHYS_ADDR; + else + paddr = mz->phys_addr; + if (rte_eal_has_hugepages() && !rte_xen_dom0_supported()) ret = rte_mempool_populate_phys(mp, mz->addr, - mz->phys_addr, mz->len, + paddr, mz->len, rte_mempool_memchunk_mz_free, RTE_DECONST(void *, mz)); else diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 7a3e652..7599790 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -235,6 +235,7 @@ struct rte_mempool { #define MEMPOOL_F_SP_PUT 0x0004 /**< Default put is "single-producer".*/ #define MEMPOOL_F_SC_GET 0x0008 /**< Default get is "single-consumer".*/ #define MEMPOOL_F_RING_CREATED 0x0010 /**< Internal: ring is created */ +#define MEMPOOL_F_NO_PHYS_CONTIG 0x0020 /**< Don't need physically contiguous objs. */ /** * @internal When debug is enabled, store some statistics. @@ -416,6 +417,8 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *); * - MEMPOOL_F_SC_GET: If this flag is set, the default behavior * when using rte_mempool_get() or rte_mempool_get_bulk() is * "single-consumer". Otherwise, it is "multi-consumers". + * - MEMPOOL_F_NO_PHYS_CONTIG: If set, allocated objects won't + * necessarilly be contiguous in physical memory. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include: @@ -1221,6 +1224,8 @@ rte_mempool_empty(const struct rte_mempool *mp) * A pointer (virtual address) to the element of the pool. * @return * The physical address of the elt element. + * If the mempool was created with MEMPOOL_F_NO_PHYS_CONTIG, the + * returned value is RTE_BAD_PHYS_ADDR. */ static inline phys_addr_t rte_mempool_virt2phy(__rte_unused const struct rte_mempool *mp, const void *elt) -- 2.1.4