[dpdk-dev,14/36] mempool: store physaddr in mempool objects

Message ID 1460629199-32489-15-git-send-email-olivier.matz@6wind.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Olivier Matz April 14, 2016, 10:19 a.m. UTC
  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 <olivier.matz@6wind.com>
---
 lib/librte_mempool/rte_mempool.c | 17 +++++++++++------
 lib/librte_mempool/rte_mempool.h | 11 ++++++-----
 2 files changed, 17 insertions(+), 11 deletions(-)
  

Comments

Wiles, Keith April 14, 2016, 3:40 p.m. UTC | #1
>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 <olivier.matz@6wind.com>

>---

> lib/librte_mempool/rte_mempool.c | 17 +++++++++++------

> lib/librte_mempool/rte_mempool.h | 11 ++++++-----

> 2 files changed, 17 insertions(+), 11 deletions(-)

>

>diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c

>index 839b828..b8e46fc 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*/);


What is the reason to comment out the variable names, if no reason I would suggest we remove the comment marks and leave the var names.
>


Regards,
Keith
  
Olivier Matz April 15, 2016, 7:34 a.m. UTC | #2
On 04/14/2016 05:40 PM, Wiles, Keith wrote:
>> 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 <olivier.matz@6wind.com>
>> ---
>> lib/librte_mempool/rte_mempool.c | 17 +++++++++++------
>> lib/librte_mempool/rte_mempool.h | 11 ++++++-----
>> 2 files changed, 17 insertions(+), 11 deletions(-)
>>
>> diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
>> index 839b828..b8e46fc 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*/);
> 
> What is the reason to comment out the variable names, if no reason I would suggest we remove the comment marks and leave the var names.

I just kept the initial style here.
Anyway this code is removed later in the series. See "mempool: simplify
xmem_usage".


Olivier
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index 839b828..b8e46fc 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 0153e62..00ca087 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,13 @@  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;
-
-		off = (const char *)elt - (const char *)mp->elt_va_start;
-		return mp->elt_pa[off >> mp->pg_shift] + (off & mp->pg_mask);
+		const struct rte_mempool_objhdr *hdr;
+		hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
+			sizeof(*hdr));
+		return hdr->physaddr;
 	} else {
 		/*
 		 * If huge pages are disabled, we cannot assume the