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 03A1137B8 for ; Wed, 9 Mar 2016 17:22:15 +0100 (CET) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id F143424A4A for ; Wed, 9 Mar 2016 17:21:31 +0100 (CET) From: Olivier Matz To: dev@dpdk.org Date: Wed, 9 Mar 2016 17:19:20 +0100 Message-Id: <1457540381-20274-15-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 14/35] mempool: store physaddr in mempool objects 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:15 -0000 Store the physical address of the object in its header. It simplifies rte_mempool_virt2phy() and prepares the removing of the paddr[] table in the mempool header. Signed-off-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 17 +++++++++++------ lib/librte_mempool/rte_mempool.h | 10 ++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index d533484..7aedc89 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -132,19 +132,22 @@ static unsigned optimize_object_size(unsigned obj_size) typedef void (*rte_mempool_obj_iter_t)(void * /*obj_iter_arg*/, void * /*obj_start*/, void * /*obj_end*/, - uint32_t /*obj_index */); + uint32_t /*obj_index */, + phys_addr_t /*physaddr*/); static void -mempool_add_elem(struct rte_mempool *mp, void *obj) +mempool_add_elem(struct rte_mempool *mp, void *obj, phys_addr_t physaddr) { struct rte_mempool_objhdr *hdr; struct rte_mempool_objtlr *tlr __rte_unused; obj = (char *)obj + mp->header_size; + physaddr += mp->header_size; /* set mempool ptr in header */ hdr = RTE_PTR_SUB(obj, sizeof(*hdr)); hdr->mp = mp; + hdr->physaddr = physaddr; STAILQ_INSERT_TAIL(&mp->elt_list, hdr, next); #ifdef RTE_LIBRTE_MEMPOOL_DEBUG @@ -173,6 +176,7 @@ rte_mempool_obj_mem_iter(void *vaddr, uint32_t elt_num, size_t total_elt_sz, uint32_t pgn, pgf; uintptr_t end, start, va; uintptr_t pg_sz; + phys_addr_t physaddr; pg_sz = (uintptr_t)1 << pg_shift; va = (uintptr_t)vaddr; @@ -208,9 +212,10 @@ rte_mempool_obj_mem_iter(void *vaddr, uint32_t elt_num, size_t total_elt_sz, * otherwise, just skip that chunk unused. */ if (k == pgn) { + physaddr = paddr[k] + (start & (pg_sz - 1)); if (obj_iter != NULL) obj_iter(obj_iter_arg, (void *)start, - (void *)end, i); + (void *)end, i, physaddr); va = end; j += pgf; i++; @@ -247,11 +252,11 @@ rte_mempool_obj_iter(struct rte_mempool *mp, static void mempool_obj_populate(void *arg, void *start, void *end, - __rte_unused uint32_t idx) + __rte_unused uint32_t idx, phys_addr_t physaddr) { struct rte_mempool *mp = arg; - mempool_add_elem(mp, start); + mempool_add_elem(mp, start, physaddr); mp->elt_va_end = (uintptr_t)end; } @@ -355,7 +360,7 @@ rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift) * argument to the end of the object. */ static void mempool_lelem_iter(void *arg, __rte_unused void *start, void *end, - __rte_unused uint32_t idx) + __rte_unused uint32_t idx, __rte_unused phys_addr_t physaddr) { *(uintptr_t *)arg = (uintptr_t)end; } diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 5b760f0..f32d705 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -158,6 +158,7 @@ struct rte_mempool_objsz { struct rte_mempool_objhdr { STAILQ_ENTRY(rte_mempool_objhdr) next; /**< Next in list. */ struct rte_mempool *mp; /**< The mempool owning the object. */ + phys_addr_t physaddr; /**< Physical address of the object. */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG uint64_t cookie; /**< Debug cookie. */ #endif @@ -1125,13 +1126,14 @@ rte_mempool_empty(const struct rte_mempool *mp) * The physical address of the elt element. */ static inline phys_addr_t -rte_mempool_virt2phy(const struct rte_mempool *mp, const void *elt) +rte_mempool_virt2phy(__rte_unused const struct rte_mempool *mp, const void *elt) { if (rte_eal_has_hugepages()) { - uintptr_t off; + const struct rte_mempool_objhdr *hdr; - off = (const char *)elt - (const char *)mp->elt_va_start; - return mp->elt_pa[off >> mp->pg_shift] + (off & mp->pg_mask); + hdr = (const struct rte_mempool_objhdr *) + ((const char *)elt - sizeof(*hdr)); + return hdr->physaddr; } else { /* * If huge pages are disabled, we cannot assume the -- 2.1.4