From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 0E53F1B490 for ; Thu, 29 Nov 2018 14:48:38 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:48:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="113540437" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 29 Nov 2018 05:48:36 -0800 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wATDmZAQ012498; Thu, 29 Nov 2018 13:48:35 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id wATDmZda019971; Thu, 29 Nov 2018 13:48:35 GMT Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id wATDmZ7k019967; Thu, 29 Nov 2018 13:48:35 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: shahafs@mellanox.com, yskoh@mellanox.com, thomas@monjalon.net, shreyansh.jain@nxp.com Date: Thu, 29 Nov 2018 13:48:32 +0000 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/4] malloc: separate creating memseg list and malloc heap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2018 13:48:39 -0000 Currently, creating external malloc heap involves also creating a memseg list backing that malloc heap. We need to have them as separate functions, to allow creating memseg lists without creating a malloc heap. Signed-off-by: Anatoly Burakov --- lib/librte_eal/common/malloc_heap.c | 34 ++++++++++++++++++----------- lib/librte_eal/common/malloc_heap.h | 9 ++++++-- lib/librte_eal/common/rte_malloc.c | 11 ++++++++-- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index c6a6d4f6b..25693481f 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -1095,9 +1095,10 @@ destroy_seg(struct malloc_elem *elem, size_t len) return 0; } -int -malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, - rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz) +struct rte_memseg_list * +malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], + unsigned int n_pages, size_t page_sz, const char *seg_name, + unsigned int socket_id) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; char fbarray_name[RTE_FBARRAY_NAME_LEN]; @@ -1117,17 +1118,17 @@ malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, if (msl == NULL) { RTE_LOG(ERR, EAL, "Couldn't find empty memseg list\n"); rte_errno = ENOSPC; - return -1; + return NULL; } snprintf(fbarray_name, sizeof(fbarray_name) - 1, "%s_%p", - heap->name, va_addr); + seg_name, va_addr); /* create the backing fbarray */ if (rte_fbarray_init(&msl->memseg_arr, fbarray_name, n_pages, sizeof(struct rte_memseg)) < 0) { RTE_LOG(ERR, EAL, "Couldn't create fbarray backing the memseg list\n"); - return -1; + return NULL; } arr = &msl->memseg_arr; @@ -1143,32 +1144,39 @@ malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, ms->len = page_sz; ms->nchannel = rte_memory_get_nchannel(); ms->nrank = rte_memory_get_nrank(); - ms->socket_id = heap->socket_id; + ms->socket_id = socket_id; } /* set up the memseg list */ msl->base_va = va_addr; msl->page_sz = page_sz; - msl->socket_id = heap->socket_id; + msl->socket_id = socket_id; msl->len = seg_len; msl->version = 0; msl->external = 1; + return msl; +} + +int +malloc_heap_add_external_memory(struct malloc_heap *heap, + struct rte_memseg_list *msl) +{ /* erase contents of new memory */ - memset(va_addr, 0, seg_len); + memset(msl->base_va, 0, msl->len); /* now, add newly minted memory to the malloc heap */ - malloc_heap_add_memory(heap, msl, va_addr, seg_len); + malloc_heap_add_memory(heap, msl, msl->base_va, msl->len); - heap->total_size += seg_len; + heap->total_size += msl->len; /* all done! */ RTE_LOG(DEBUG, EAL, "Added segment for heap %s starting at %p\n", - heap->name, va_addr); + heap->name, msl->base_va); /* notify all subscribers that a new memory area has been added */ eal_memalloc_mem_event_notify(RTE_MEM_EVENT_ALLOC, - va_addr, seg_len); + msl->base_va, msl->len); return 0; } diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h index e48996d52..255a315b8 100644 --- a/lib/librte_eal/common/malloc_heap.h +++ b/lib/librte_eal/common/malloc_heap.h @@ -39,9 +39,14 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name); int malloc_heap_destroy(struct malloc_heap *heap); +struct rte_memseg_list * +malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], + unsigned int n_pages, size_t page_sz, const char *seg_name, + unsigned int socket_id); + int -malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, - rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz); +malloc_heap_add_external_memory(struct malloc_heap *heap, + struct rte_memseg_list *msl); int malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr, diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c index 0da5ad5e8..66bfe63c3 100644 --- a/lib/librte_eal/common/rte_malloc.c +++ b/lib/librte_eal/common/rte_malloc.c @@ -340,6 +340,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len, { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; struct malloc_heap *heap = NULL; + struct rte_memseg_list *msl; unsigned int n; int ret; @@ -373,9 +374,15 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len, goto unlock; } + msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n, page_sz, + heap_name, heap->socket_id); + if (msl == NULL) { + ret = -1; + goto unlock; + } + rte_spinlock_lock(&heap->lock); - ret = malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n, - page_sz); + ret = malloc_heap_add_external_memory(heap, msl); rte_spinlock_unlock(&heap->lock); unlock: -- 2.17.1