From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B8B57A058B; Wed, 25 Mar 2020 22:18:42 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 109571C0D0; Wed, 25 Mar 2020 22:16:58 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 8CD3A1C10A for ; Wed, 25 Mar 2020 22:16:56 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02PLGGPG008345; Wed, 25 Mar 2020 14:16:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=CqYPnb6DYjhJhzDjNGQn8WW03RppzYT9Zm4INVh9ELs=; b=oS0UfcQamoyBm6WAp/adjoGflJaYuTOUYIaBBM9b3/FhC2eZ2cYeyhlnYjRjMipxaWE/ Pk8FckUj+zaf6wNUVBSnUYxoRSc0fuHlhP6jME4Fosa3+Re9rwuZ2c68xwk+we9mcb3s CRVp9p7mkzVj/nz1UeAnxmURoApsYDK9pKPbqBzzLDtyHSxkIqnhPic+JVeYvxsTi09h stOr+Tq/oI9g4kE7jYA9Acm/mZFw3ckOiGH8/kfmenU8NgsZlzko9EuM2Ay1U5f7cXCJ EcT7FbXIfODcjuj01RfWffMJnm3eVnlknSA/+dnLyhW3lSZIoYt6qI7jz+rNuFkEzeWS dw== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 2ywg9ntf1j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 Mar 2020 14:16:55 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 Mar 2020 14:16:54 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 Mar 2020 14:16:53 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 25 Mar 2020 14:16:53 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id F0D2F3F703F; Wed, 25 Mar 2020 14:16:50 -0700 (PDT) From: To: Anatoly Burakov CC: , , , , , , Jerin Jacob Date: Thu, 26 Mar 2020 02:45:48 +0530 Message-ID: <20200325211603.240288-19-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200325211603.240288-1-jerinj@marvell.com> References: <20200318190241.3150971-1-jerinj@marvell.com> <20200325211603.240288-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-25_11:2020-03-24, 2020-03-25 signatures=0 Subject: [dpdk-dev] [PATCH v2 18/32] eal/trace: add memory tracepoints 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" From: Jerin Jacob Add the following memory-related tracepoints. rte_trace_lib_eal_mem_zmalloc; rte_trace_lib_eal_mem_malloc; rte_trace_lib_eal_mem_realloc; rte_trace_lib_eal_mem_free; rte_malloc() and rte_free() has been used in the trace implementation, in order to avoid tracing implementation specific events, added an internal no trace version rte_malloc() and rte_free(). Signed-off-by: Jerin Jacob --- lib/librte_eal/common/eal_common_trace.c | 4 +- .../common/eal_common_trace_points.c | 14 +++++ lib/librte_eal/common/eal_private.h | 5 ++ lib/librte_eal/common/include/rte_trace_eal.h | 33 ++++++++++ lib/librte_eal/common/rte_malloc.c | 60 ++++++++++++++++--- lib/librte_eal/rte_eal_version.map | 4 ++ 6 files changed, 109 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index 6b1600758..840cab5a1 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -428,7 +428,7 @@ __rte_trace_mem_per_thread_alloc(void) } /* First attempt from huge page */ - header = rte_malloc(NULL, trace_mem_sz(trace->buff_len), 8); + header = eal_malloc_no_trace(NULL, trace_mem_sz(trace->buff_len), 8); if (header) { trace->lcore_meta[count].area = TRACE_AREA_HUGEPAGE; goto found; @@ -480,7 +480,7 @@ trace_mem_per_thread_free(void) for (count = 0; count < trace->nb_trace_mem_list; count++) { mem = trace->lcore_meta[count].mem; if (trace->lcore_meta[count].area == TRACE_AREA_HUGEPAGE) - rte_free(mem); + eal_free_no_trace(mem); else if (trace->lcore_meta[count].area == TRACE_AREA_HEAP) free(mem); } diff --git a/lib/librte_eal/common/eal_common_trace_points.c b/lib/librte_eal/common/eal_common_trace_points.c index 16261b1d6..dcae51bac 100644 --- a/lib/librte_eal/common/eal_common_trace_points.c +++ b/lib/librte_eal/common/eal_common_trace_points.c @@ -26,6 +26,11 @@ RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_generic_func); RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_alarm_set); RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_alarm_cancel); +RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_mem_zmalloc); +RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_mem_malloc); +RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_mem_realloc); +RTE_TRACE_POINT_DEFINE(rte_trace_lib_eal_mem_free); + RTE_INIT(eal_trace_init) { RTE_TRACE_POINT_REGISTER(rte_trace_lib_eal_generic_void, @@ -66,4 +71,13 @@ RTE_INIT(eal_trace_init) RTE_TRACE_POINT_REGISTER(rte_trace_lib_eal_alarm_cancel, lib.eal.alarm.cancel, INFO); + RTE_TRACE_POINT_REGISTER(rte_trace_lib_eal_mem_zmalloc, + lib.eal.mem.zmalloc, INFO); + RTE_TRACE_POINT_REGISTER(rte_trace_lib_eal_mem_malloc, + lib.eal.mem.malloc, INFO); + RTE_TRACE_POINT_REGISTER(rte_trace_lib_eal_mem_realloc, + lib.eal.mem.realloc, INFO); + RTE_TRACE_POINT_REGISTER(rte_trace_lib_eal_mem_free, + lib.eal.mem.free, INFO); + } diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 81694616b..f61f52eff 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -446,4 +446,9 @@ eal_get_baseaddr(void); const char * eal_loglevel_to_string(uint32_t level); +void * +eal_malloc_no_trace(const char *type, size_t size, unsigned int align); + +void eal_free_no_trace(void *addr); + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/common/include/rte_trace_eal.h b/lib/librte_eal/common/include/rte_trace_eal.h index df1b3854b..597cf9ca3 100644 --- a/lib/librte_eal/common/include/rte_trace_eal.h +++ b/lib/librte_eal/common/include/rte_trace_eal.h @@ -133,6 +133,39 @@ RTE_TRACE_POINT( rte_trace_ctf_int(count); ) +/* Memory */ +RTE_TRACE_POINT( + rte_trace_lib_eal_mem_zmalloc, + RTE_TRACE_POINT_ARGS(const char *type, size_t size, unsigned int align, + int socket, void *ptr), + rte_trace_ctf_string(type); rte_trace_ctf_long(size); + rte_trace_ctf_u32(align); rte_trace_ctf_int(socket); + rte_trace_ctf_ptr(ptr); +) + +RTE_TRACE_POINT( + rte_trace_lib_eal_mem_malloc, + RTE_TRACE_POINT_ARGS(const char *type, size_t size, unsigned int align, + int socket, void *ptr), + rte_trace_ctf_string(type); rte_trace_ctf_long(size); + rte_trace_ctf_u32(align); rte_trace_ctf_int(socket); + rte_trace_ctf_ptr(ptr); +) + +RTE_TRACE_POINT( + rte_trace_lib_eal_mem_realloc, + RTE_TRACE_POINT_ARGS(size_t size, unsigned int align, + int socket, void *ptr), + rte_trace_ctf_long(size); rte_trace_ctf_u32(align); + rte_trace_ctf_int(socket); rte_trace_ctf_ptr(ptr); +) + +RTE_TRACE_POINT( + rte_trace_lib_eal_mem_free, + RTE_TRACE_POINT_ARGS(void *ptr), + rte_trace_ctf_ptr(ptr); +) + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c index d6026a2b1..9ad032aed 100644 --- a/lib/librte_eal/common/rte_malloc.c +++ b/lib/librte_eal/common/rte_malloc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "malloc_elem.h" @@ -30,20 +31,35 @@ /* Free the memory space back to heap */ -void rte_free(void *addr) +static void +mem_free(void *addr, const bool trace_ena) { + if (trace_ena == true) + rte_trace_lib_eal_mem_free(addr); + if (addr == NULL) return; if (malloc_heap_free(malloc_elem_from_data(addr)) < 0) RTE_LOG(ERR, EAL, "Error: Invalid memory\n"); } -/* - * Allocate memory on specified heap. - */ -void * -rte_malloc_socket(const char *type, size_t size, unsigned int align, - int socket_arg) +void +rte_free(void *addr) { + return mem_free(addr, true); +} + +void +eal_free_no_trace(void *addr) +{ + return mem_free(addr, false); +} + +static void * +malloc_socket(const char *type, size_t size, unsigned int align, + int socket_arg, const bool trace_ena) +{ + void *ptr; + /* return NULL if size is 0 or alignment is not power-of-2 */ if (size == 0 || (align && !rte_is_power_of_2(align))) return NULL; @@ -57,8 +73,29 @@ rte_malloc_socket(const char *type, size_t size, unsigned int align, !rte_eal_has_hugepages()) socket_arg = SOCKET_ID_ANY; - return malloc_heap_alloc(type, size, socket_arg, 0, + ptr = malloc_heap_alloc(type, size, socket_arg, 0, align == 0 ? 1 : align, 0, false); + + if (trace_ena == true) + rte_trace_lib_eal_mem_malloc(type, size, align, + socket_arg, ptr); + return ptr; +} + +/* + * Allocate memory on specified heap. + */ +void * +rte_malloc_socket(const char *type, size_t size, unsigned int align, + int socket_arg) +{ + return malloc_socket(type, size, align, socket_arg, true); +} + +void * +eal_malloc_no_trace(const char *type, size_t size, unsigned int align) +{ + return malloc_socket(type, size, align, SOCKET_ID_ANY, false); } /* @@ -87,6 +124,8 @@ rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket) if (ptr != NULL) memset(ptr, 0, size); #endif + + rte_trace_lib_eal_mem_zmalloc(type, size, align, socket, ptr); return ptr; } @@ -140,8 +179,10 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) if ((socket == SOCKET_ID_ANY || (unsigned int)socket == elem->heap->socket_id) && RTE_PTR_ALIGN(ptr, align) == ptr && - malloc_heap_resize(elem, size) == 0) + malloc_heap_resize(elem, size) == 0) { + rte_trace_lib_eal_mem_realloc(size, align, socket, ptr); return ptr; + } /* either requested socket id doesn't match, alignment is off * or we have no room to expand, @@ -155,6 +196,7 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) rte_memcpy(new_ptr, ptr, old_size < size ? old_size : size); rte_free(ptr); + rte_trace_lib_eal_mem_realloc(size, align, socket, new_ptr); return new_ptr; } diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index d1c4c10de..8f354cb81 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -383,4 +383,8 @@ EXPERIMENTAL { __rte_trace_lib_eal_generic_func; __rte_trace_lib_eal_alarm_set; __rte_trace_lib_eal_alarm_cancel; + __rte_trace_lib_eal_mem_zmalloc; + __rte_trace_lib_eal_mem_malloc; + __rte_trace_lib_eal_mem_realloc; + __rte_trace_lib_eal_mem_free; }; -- 2.25.1