From patchwork Fri Jul 6 13:17:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 42505 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A8B671BF13; Fri, 6 Jul 2018 15:17:50 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 6AA681BE41 for ; Fri, 6 Jul 2018 15:17:38 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 06:17:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,316,1526367600"; d="scan'208";a="55598237" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga006.jf.intel.com with ESMTP; 06 Jul 2018 06:17:34 -0700 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 w66DHX3P027482; Fri, 6 Jul 2018 14:17:33 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w66DHXYk003783; Fri, 6 Jul 2018 14:17:33 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w66DHX6t003775; Fri, 6 Jul 2018 14:17:33 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: srinath.mannam@broadcom.com, scott.branden@broadcom.com, ajit.khaparde@broadcom.com Date: Fri, 6 Jul 2018 14:17:26 +0100 Message-Id: <9782368c814417e812260de99a5c4f83055d959d.1530881548.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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()->mem_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; + 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()->mem_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;