From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by dpdk.org (Postfix) with ESMTP id EDE8827D for ; Fri, 13 Jul 2018 18:25:36 +0200 (CEST) Received: by mail-ed1-f67.google.com with SMTP id t2-v6so10412774edr.5 for ; Fri, 13 Jul 2018 09:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NmKXEJ7Wo9VKJMEn9NMT/7XyExGYH3mIOEK3GgXjd9c=; b=Dz1OY32lSul7+mTsK+BYa/wowrEL+4Xy5XnRmXTH8X86m2L9PTlbPjMQzP/n93rgC0 CWJj9RfReJU4EsOLa+eSza28JBvdAUOPZVkQxhZ7OWQxDtXrNvvkEm+0OFDPjmKWTUxY 8eRMu1MZbmM69Z6vtT07e539bI9R6YLTR8XLg/1Dj8kjcajp1KJ3gydrxqXBaKpQnXtV gWkRXQq/n3PJqaTtxXOsHCLmPBdjUumqb4l+iXpQj2HJmCZzrb2ZT/ncquUNToQNf4aI zrBBn3ScheC2Jk6XuZmrZS37iuLu4z6SL8l8K1UwEYNkmv3bN+oOgSGd+T1VDnlddlfj u38Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NmKXEJ7Wo9VKJMEn9NMT/7XyExGYH3mIOEK3GgXjd9c=; b=fpoKzeDlY8CVSPg59K2LGhWl8RpH0jP/aEoUlu9ofydDSXQaK4WTozjweGirz0dg0N PbSnlWdMv0l1lyXdEDDa1cQnHWmxw89DfjKc+lDx741e4grPD9+zDMSEdvWfyMngShAe hi3lMkhGJ48KeWDUTPvhpUBplgghKiPtLeX79tw7+MaTKo0718gEFfkRub2pCE7zxwVL 15JYsMRtOr5cRf8J0Gzad+AoZmV6Bu4jTtpnTF/B+IS1c8UyXPxzPqP2tnfV+8kOqxBz 8ZaRwjkcOK75zSuB9xmH+auQKDB/ZuKra10AovCdVoyDgxXsKeQkpN3Q7Kebt5ULMP4B OD8g== X-Gm-Message-State: AOUpUlFVPJsMxpPKuZRiCOKEYMXyRNc/gJups1qXUP4UH4lHf7aRl1AL YallsPtNmoKeo/4LhsF2KbzzH3Mt2d4z1KZbZESsrQ== X-Google-Smtp-Source: AAOMgpdzdlNOgEH+JwvZcKtP28BlBJWWCx+1gxTzrIxONTxDrGoI8wh4Cb5+RJECorvBwd1stMZ5bWIn2Q0umsqTz1c= X-Received: by 2002:a50:f098:: with SMTP id v24-v6mr7941479edl.90.1531499136762; Fri, 13 Jul 2018 09:25:36 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:b194:0:0:0:0:0 with HTTP; Fri, 13 Jul 2018 09:25:36 -0700 (PDT) In-Reply-To: <9782368c814417e812260de99a5c4f83055d959d.1530881548.git.anatoly.burakov@intel.com> References: <9782368c814417e812260de99a5c4f83055d959d.1530881548.git.anatoly.burakov@intel.com> From: Alejandro Lucero Date: Fri, 13 Jul 2018 17:25:36 +0100 Message-ID: To: Anatoly Burakov Cc: dev , srinath.mannam@broadcom.com, scott.branden@broadcom.com, Ajit Khaparde Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [RFC 05/11] malloc: enable retrieving statistics from named heaps 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: Fri, 13 Jul 2018 16:25:37 -0000 On Fri, Jul 6, 2018 at 2:17 PM, Anatoly Burakov wrote: > Add internal functions to look up heap by name, and enable > dumping statistics for a specified named heap. > > Signed-off-by: Anatoly Burakov > --- > lib/librte_eal/common/include/rte_malloc.h | 19 +++++++++++-- > lib/librte_eal/common/malloc_heap.c | 31 ++++++++++++++++++++++ > lib/librte_eal/common/malloc_heap.h | 6 +++++ > lib/librte_eal/common/rte_malloc.c | 17 ++++++++++++ > lib/librte_eal/rte_eal_version.map | 1 + > 5 files changed, 72 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_eal/common/include/rte_malloc.h > b/lib/librte_eal/common/include/rte_malloc.h > index a9fb7e452..7cbcd3184 100644 > --- a/lib/librte_eal/common/include/rte_malloc.h > +++ b/lib/librte_eal/common/include/rte_malloc.h > @@ -256,13 +256,28 @@ rte_malloc_validate(const void *ptr, size_t *size); > * @param socket_stats > * A structure which provides memory to store statistics > * @return > - * Null on error > - * Pointer to structure storing statistics on success > + * 0 on success > + * -1 on error > */ > int > rte_malloc_get_socket_stats(int socket, > struct rte_malloc_socket_stats *socket_stats); > > +/** > + * Get heap statistics for the specified heap. > + * > + * @param socket > + * An unsigned integer specifying the socket to get heap statistics for > + * @param socket_stats > + * A structure which provides memory to store statistics > + * @return > + * 0 on success > + * -1 on error > + */ > +int __rte_experimental > +rte_malloc_get_stats_from_heap(const char *heap_name, > + struct rte_malloc_socket_stats *socket_stats); > + > /** > * Dump statistics. > * > diff --git a/lib/librte_eal/common/malloc_heap.c > b/lib/librte_eal/common/malloc_heap.c > index 8f22c062b..8437d33b3 100644 > --- a/lib/librte_eal/common/malloc_heap.c > +++ b/lib/librte_eal/common/malloc_heap.c > @@ -614,6 +614,37 @@ malloc_heap_free_pages(void *aligned_start, size_t > aligned_len) > return 0; > } > > +int > +malloc_heap_find_named_heap_idx(const char *heap_name) > +{ > + struct rte_mem_config *mcfg = rte_eal_get_configuration()->m > em_config; > + int heap_idx; > + > + if (heap_name == NULL) > + return -1; > + if (strnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) == > RTE_HEAP_NAME_MAX_LEN) > + return -1; > + for (heap_idx = rte_socket_count(); heap_idx < RTE_MAX_HEAPS; > Why not to allow to use a default DPDK heap here? They got names as well and I think it is good for consistency. > + heap_idx++) { > + struct malloc_heap *heap = &mcfg->malloc_heaps[heap_idx]; > + if (strncmp(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN) > == 0) > + return heap_idx; > + } > + return -1; > +} > + > +struct malloc_heap * > +malloc_heap_find_named_heap(const char *heap_name) > +{ > + struct rte_mem_config *mcfg = rte_eal_get_configuration()->m > em_config; > + int heap_idx; > + > + heap_idx = malloc_heap_find_named_heap_idx(heap_name); > + if (heap_idx < 0) > + return NULL; > + return &mcfg->malloc_heaps[heap_idx]; > +} > + > int > malloc_heap_free(struct malloc_elem *elem) > { > diff --git a/lib/librte_eal/common/malloc_heap.h > b/lib/librte_eal/common/malloc_heap.h > index 03b801415..4f3137260 100644 > --- a/lib/librte_eal/common/malloc_heap.h > +++ b/lib/librte_eal/common/malloc_heap.h > @@ -29,6 +29,12 @@ void * > malloc_heap_alloc(const char *type, size_t size, int socket, unsigned int > flags, > size_t align, size_t bound, bool contig); > > +int > +malloc_heap_find_named_heap_idx(const char *name); > + > +struct malloc_heap * > +malloc_heap_find_named_heap(const char *name); > + > int > malloc_heap_free(struct malloc_elem *elem); > > diff --git a/lib/librte_eal/common/rte_malloc.c > b/lib/librte_eal/common/rte_malloc.c > index 75d6e0b4d..2508abdb1 100644 > --- a/lib/librte_eal/common/rte_malloc.c > +++ b/lib/librte_eal/common/rte_malloc.c > @@ -165,6 +165,23 @@ rte_malloc_get_socket_stats(int socket, > socket_stats); > } > > +/* > + * Function to retrieve data for heap on given socket > + */ > +int __rte_experimental > +rte_malloc_get_stats_from_heap(const char *heap_name, > + struct rte_malloc_socket_stats *socket_stats) > +{ > + struct malloc_heap *heap; > + > + heap = malloc_heap_find_named_heap(heap_name); > + > + if (heap == NULL) > + return -1; > + > + return malloc_heap_get_stats(heap, socket_stats); > +} > + > /* > * Function to dump contents of all heaps > */ > diff --git a/lib/librte_eal/rte_eal_version.map > b/lib/librte_eal/rte_eal_version.map > index e7fb37b2a..786df1e39 100644 > --- a/lib/librte_eal/rte_eal_version.map > +++ b/lib/librte_eal/rte_eal_version.map > @@ -278,6 +278,7 @@ EXPERIMENTAL { > rte_fbarray_set_used; > rte_log_register_type_and_pick_level; > rte_malloc_dump_heaps; > + rte_malloc_get_stats_from_heap; > rte_mem_alloc_validator_register; > rte_mem_alloc_validator_unregister; > rte_mem_event_callback_register; > -- > 2.17.1 >