From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anatoly Burakov Subject: [RFC 05/23] eal/malloc: protect malloc heap stats with a lock Date: Tue, 19 Dec 2017 11:04:24 +0000 Message-ID: References: Cc: andras.kovacs@ericsson.com, laszlo.vadkeri@ericsson.com, keith.wiles@intel.com, benjamin.walker@intel.com, bruce.richardson@intel.com, thomas@monjalon.net To: dev@dpdk.org Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 8C7FB7D19 for ; Tue, 19 Dec 2017 12:05:02 +0100 (CET) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This does not change the public API, as this API is not meant to be called directly. Signed-off-by: Anatoly Burakov --- lib/librte_eal/common/malloc_heap.c | 7 ++++++- lib/librte_eal/common/malloc_heap.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index 099e448..b3a1043 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -214,12 +214,14 @@ malloc_heap_resize(struct malloc_elem *elem, size_t size) { * Function to retrieve data for heap on given socket */ int -malloc_heap_get_stats(const struct malloc_heap *heap, +malloc_heap_get_stats(struct malloc_heap *heap, struct rte_malloc_socket_stats *socket_stats) { size_t idx; struct malloc_elem *elem; + rte_spinlock_lock(&(heap->lock)); + /* Initialise variables for heap */ socket_stats->free_count = 0; socket_stats->heap_freesz_bytes = 0; @@ -241,6 +243,9 @@ malloc_heap_get_stats(const struct malloc_heap *heap, socket_stats->heap_allocsz_bytes = (socket_stats->heap_totalsz_bytes - socket_stats->heap_freesz_bytes); socket_stats->alloc_count = heap->alloc_count; + + rte_spinlock_unlock(&(heap->lock)); + return 0; } diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h index 3767ef3..df04dd8 100644 --- a/lib/librte_eal/common/malloc_heap.h +++ b/lib/librte_eal/common/malloc_heap.h @@ -63,7 +63,7 @@ int malloc_heap_resize(struct malloc_elem *elem, size_t size); int -malloc_heap_get_stats(const struct malloc_heap *heap, +malloc_heap_get_stats(struct malloc_heap *heap, struct rte_malloc_socket_stats *socket_stats); int -- 2.7.4