From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-we0-f169.google.com (mail-we0-f169.google.com [74.125.82.169]) by dpdk.org (Postfix) with ESMTP id 0EE0B5946 for ; Fri, 26 Jul 2013 16:25:35 +0200 (CEST) Received: by mail-we0-f169.google.com with SMTP id n5so1199285wev.14 for ; Fri, 26 Jul 2013 07:25:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:x-gm-message-state; bh=uxPAj7OQo8i54n05Awb1L0Um8Ekgf9qlBDvX66A7G2E=; b=X9zFzemsNvAlbRHhwulB8AcLqkhXW3GVUmjt4GMsD4heXLIW/EOexQx5/s9JMetiBV vFKAbIxp3PRpBpRa3Juyid0TQp5QcfowTv6x9uEl4pbW94dmczxfgircsRbCqvs7w2QP tqFy7dwBJW4v6V+enWC6NTcQ9rcPmBY1yC6pb/Lw2VHYK/Pjv3hxp4NZ7Dz6sh44UQ6W n8pTW2bvHVZ9kjUY3uEzLAtPLrXi/wvq6Zjo0N3g1w8UBVNJxDDE2cqfXRUhEqjJfeSY GSGkQh739Xm8+K9da6jmIpxDf1exWXg15R9in+tcP7Og9TIBkAy3y40ugEfdwGObo2GD FRLg== X-Received: by 10.194.121.132 with SMTP id lk4mr35059490wjb.25.1374848758880; Fri, 26 Jul 2013 07:25:58 -0700 (PDT) Received: from 6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id nb12sm5145342wic.7.2013.07.26.07.25.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 26 Jul 2013 07:25:57 -0700 (PDT) Received: by 6wind.com (sSMTP sendmail emulation); Fri, 26 Jul 2013 16:25:55 +0200 From: Didier Pallard To: dev@dpdk.org Date: Fri, 26 Jul 2013 16:25:55 +0200 Message-Id: <1374848755-5170-1-git-send-email-didier.pallard@6wind.com> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQk6WaBD+qxeNzgH3JULw2nZ1FM1SAq9nGC3HrSYLATYXL+LhnuA5QYmyyxnSn+xzHLl1t22 Subject: [dpdk-dev] [PATCH 1/1] mem: get physical address of any rte_malloc buffer 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: Fri, 26 Jul 2013 14:25:36 -0000 Get physical address of any rte_malloc allocated buffer using function rte_malloc_virt2phy(addr). The rte_memzone pointer is now stored in each allocated memory block header to allow simple computation of physical address of a block using the memzone it comes from. Declaration of memzone in malloc_elem structure adds a dependency between rte_malloc.h and rte_memory.h; test source code are modified to include both files in correct order. Signed-off-by: Didier Pallard --- app/test/test_hash.c | 2 +- app/test/test_hash_perf.c | 2 +- app/test/test_memcpy.c | 1 + app/test/test_memcpy_perf.c | 1 + lib/librte_malloc/malloc_elem.c | 7 ++++--- lib/librte_malloc/malloc_elem.h | 2 ++ lib/librte_malloc/malloc_heap.c | 2 +- lib/librte_malloc/rte_malloc.c | 12 ++++++++++++ lib/librte_malloc/rte_malloc.h | 13 +++++++++++++ 9 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/test/test_hash.c b/app/test/test_hash.c index 5437e05..4de8cb1 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -41,10 +41,10 @@ #include #include -#include #include #include #include +#include #include #include #include diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c index 8a0feb3..311c2bd 100644 --- a/app/test/test_hash_perf.c +++ b/app/test/test_hash_perf.c @@ -42,10 +42,10 @@ #include #include -#include #include #include #include +#include #include #include #include diff --git a/app/test/test_memcpy.c b/app/test/test_memcpy.c index d7777a8..729a2ff 100644 --- a/app/test/test_memcpy.c +++ b/app/test/test_memcpy.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include diff --git a/app/test/test_memcpy_perf.c b/app/test/test_memcpy_perf.c index 236b295..1e75f53 100644 --- a/app/test/test_memcpy_perf.c +++ b/app/test/test_memcpy_perf.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include diff --git a/lib/librte_malloc/malloc_elem.c b/lib/librte_malloc/malloc_elem.c index 919d474..8da517f 100644 --- a/lib/librte_malloc/malloc_elem.c +++ b/lib/librte_malloc/malloc_elem.c @@ -57,9 +57,10 @@ */ void malloc_elem_init(struct malloc_elem *elem, - struct malloc_heap *heap, size_t size) + struct malloc_heap *heap, const struct rte_memzone *mz, size_t size) { elem->heap = heap; + elem->mz = mz; elem->prev = elem->next_free = NULL; elem->state = ELEM_FREE; elem->size = size; @@ -74,7 +75,7 @@ malloc_elem_init(struct malloc_elem *elem, void malloc_elem_mkend(struct malloc_elem *elem, struct malloc_elem *prev) { - malloc_elem_init(elem, prev->heap, 0); + malloc_elem_init(elem, prev->heap, prev->mz, 0); elem->prev = prev; elem->state = ELEM_BUSY; /* mark busy so its never merged */ } @@ -117,7 +118,7 @@ split_elem(struct malloc_elem *elem, struct malloc_elem *split_pt) const unsigned old_elem_size = (uintptr_t)split_pt - (uintptr_t)elem; const unsigned new_elem_size = elem->size - old_elem_size; - malloc_elem_init(split_pt, elem->heap, new_elem_size); + malloc_elem_init(split_pt, elem->heap, elem->mz, new_elem_size); split_pt->prev = elem; next_elem->prev = split_pt; elem->size = old_elem_size; diff --git a/lib/librte_malloc/malloc_elem.h b/lib/librte_malloc/malloc_elem.h index 8a75e0c..f1710cf 100644 --- a/lib/librte_malloc/malloc_elem.h +++ b/lib/librte_malloc/malloc_elem.h @@ -48,6 +48,7 @@ struct malloc_elem { struct malloc_heap *heap; struct malloc_elem *volatile prev; /* points to prev elem in memzone */ struct malloc_elem *volatile next_free; /* to make list of free elements */ + const struct rte_memzone *mz; volatile enum elem_state state; uint32_t pad; size_t size; @@ -134,6 +135,7 @@ malloc_elem_from_data(void *data) void malloc_elem_init(struct malloc_elem *elem, struct malloc_heap *heap, + const struct rte_memzone *mz, size_t size); /* diff --git a/lib/librte_malloc/malloc_heap.c b/lib/librte_malloc/malloc_heap.c index b6d83a4..bbf6bb8 100644 --- a/lib/librte_malloc/malloc_heap.c +++ b/lib/librte_malloc/malloc_heap.c @@ -100,7 +100,7 @@ malloc_heap_add_memzone(struct malloc_heap *heap, size_t size, unsigned align) end_elem = RTE_PTR_ALIGN_FLOOR(end_elem, CACHE_LINE_SIZE); const unsigned elem_size = (uintptr_t)end_elem - (uintptr_t)start_elem; - malloc_elem_init(start_elem, heap, elem_size); + malloc_elem_init(start_elem, heap, mz, elem_size); malloc_elem_mkend(end_elem, start_elem); start_elem->next_free = heap->free_head; diff --git a/lib/librte_malloc/rte_malloc.c b/lib/librte_malloc/rte_malloc.c index 03db51f..3c76c43 100644 --- a/lib/librte_malloc/rte_malloc.c +++ b/lib/librte_malloc/rte_malloc.c @@ -228,3 +228,15 @@ rte_malloc_set_limit(__rte_unused const char *type, { return 0; } + +/* + * Return the physical address of a virtual address obtained through rte_malloc + */ +phys_addr_t +rte_malloc_virt2phy(const void *addr) +{ + const struct malloc_elem *elem = malloc_elem_from_data(addr); + if (elem == NULL) + return 0; + return elem->mz->phys_addr + ((uintptr_t)addr - (uintptr_t)elem->mz->addr); +} diff --git a/lib/librte_malloc/rte_malloc.h b/lib/librte_malloc/rte_malloc.h index 64ffaf0..1451d9c 100644 --- a/lib/librte_malloc/rte_malloc.h +++ b/lib/librte_malloc/rte_malloc.h @@ -319,6 +319,19 @@ rte_malloc_dump_stats(const char *type); int rte_malloc_set_limit(const char *type, size_t max); +/** + * Return the physical address of a virtual address obtained through + * rte_malloc + * + * @param addr + * Adress obtained from a previous rte_malloc call + * @return + * NULL on error + * otherwise return physical address of the buffer + */ +phys_addr_t +rte_malloc_virt2phy(const void *addr); + #ifdef __cplusplus } #endif -- 1.7.10.4