From patchwork Wed Sep 15 09:53:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harman Kalra X-Patchwork-Id: 98894 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 865CFA0C41; Wed, 15 Sep 2021 11:54:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 17F7B4013F; Wed, 15 Sep 2021 11:54:00 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id A881B4003F for ; Wed, 15 Sep 2021 11:53:57 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18F9dhLs022327; Wed, 15 Sep 2021 02:53:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=pfpt0220; bh=zvqQbEnX1Qvr5pGXo8Z3dDQ04ZbKW9v6nlI3OrEntVA=; b=DvzvIUzyu3OhbYox4PsoVtQIBp2TQZLLThjWgt3KzXfxijg9o97MZOIHX+A96z3l9mTb oMinC2KkZlX5VxL+RZwZwBTbhAlZcAgObt6G2ruEi9ZyLY3EtJqyLxE3uupY8rpS7i8M rxFtN7Ham5TlWnBeET4SMszsRegULJwIsBCsQFXq74sX2OKCF/cFamiYmVMz/6QMwJ9z Hw95yW6ZSZVImE4f4jAHYzPBTqB2K0NKBH7kdut5ykG3fxoVhQVcHe8CgBGnEO7aFFgB ytFgU/p5dh0HLN8jzey/aMF0tvjzTaCnNyNkBj0JjlYEujhWusaXU/QhXMA+EFAJCMaD Xw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3b3ed002hj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 15 Sep 2021 02:53:56 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 15 Sep 2021 02:53:55 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 15 Sep 2021 02:53:55 -0700 Received: from localhost.localdomain (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id A06EC3F7063; Wed, 15 Sep 2021 02:53:53 -0700 (PDT) From: Harman Kalra To: , , , Anatoly Burakov CC: Harman Kalra Date: Wed, 15 Sep 2021 15:23:36 +0530 Message-ID: <20210915095336.105635-1-hkalra@marvell.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-Proofpoint-GUID: FMOZRyKP7G60AxalCNGkZPV3a6LBpxE7 X-Proofpoint-ORIG-GUID: FMOZRyKP7G60AxalCNGkZPV3a6LBpxE7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-15_02,2021-09-14_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH] eal: add telemetry callbacks for memory info X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Registering new telemetry callbacks to dump named (memzones) and unnamed (malloc) memory information to a file provided as an argument. Example: Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2 {"version": "DPDK 21.08.0", "pid": 34075, "max_output_len": 16384} Connected to application: "dpdk-testpmd" --> /eal/malloc_dump,/tmp/malloc_dump {"/eal/malloc_dump": {"Malloc elements file: ": "/tmp/malloc_dump"}} --> --> /eal/malloc_info,/tmp/info {"/eal/malloc_info": {"Malloc stats file: ": "/tmp/info"}} --> --> --> /eal/memzone_dump,/tmp/memzone_info {"/eal/memzone_dump": {"Memzones count: ": 11, \ "Memzones info file: ": "/tmp/memzone_info"}} Signed-off-by: Harman Kalra --- lib/eal/common/eal_common_memory.c | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c index f83b75092e..592b3453b6 100644 --- a/lib/eal/common/eal_common_memory.c +++ b/lib/eal/common/eal_common_memory.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "eal_memalloc.h" #include "eal_private.h" @@ -38,6 +40,7 @@ #define MEMSEG_LIST_FMT "memseg-%" PRIu64 "k-%i-%i" +static int count; static void *next_baseaddr; static uint64_t system_page_sz; @@ -1102,3 +1105,78 @@ rte_eal_memory_init(void) rte_mcfg_mem_read_unlock(); return -1; } + +#define EAL_MEMZONE_DUMP_REQ "/eal/memzone_dump" +#define EAL_MALLOC_INFO_REQ "/eal/malloc_info" +#define EAL_MALLOC_DUMP_REQ "/eal/malloc_dump" + +static void +memzone_walk_clb(const struct rte_memzone *mz __rte_unused, + void *arg __rte_unused) +{ + count++; +} + +/* Callback handler for telemetry library to dump named and unnamed memory + * information. + */ +static int +handle_eal_mem_info_request(const char *cmd, const char *params, + struct rte_tel_data *d) +{ + char filename[PATH_MAX]; + FILE *fp; + + if (params == NULL || strlen(params) == 0) + return -1; + + rte_strscpy(filename, params, PATH_MAX); + + fp = fopen(filename, "w+"); + if (fp == NULL) { + RTE_LOG(ERR, EAL, "cannot open %s", filename); + return -1; + } + + rte_tel_data_start_dict(d); + /* Dumping memzone info. */ + if (strcmp(cmd, EAL_MEMZONE_DUMP_REQ) == 0) { + count = 0; + /* Callback to count memzones */ + rte_memzone_walk(memzone_walk_clb, NULL); + rte_tel_data_add_dict_int(d, "Memzones count: ", count); + rte_tel_data_add_dict_string(d, "Memzones info file: ", + filename); + rte_memzone_dump(fp); + } + + /* Dumping malloc statistics */ + if (strcmp(cmd, EAL_MALLOC_INFO_REQ) == 0) { + rte_tel_data_add_dict_string(d, "Malloc stats file: ", + filename); + rte_malloc_dump_stats(fp, NULL); + } + + /* Dumping malloc elements info */ + if (strcmp(cmd, EAL_MALLOC_DUMP_REQ) == 0) { + rte_tel_data_add_dict_string(d, "Malloc elements file: ", + filename); + rte_malloc_dump_heaps(fp); + } + + fclose(fp); + return 0; +} + +RTE_INIT(memory_telemetry) +{ + rte_telemetry_register_cmd( + EAL_MEMZONE_DUMP_REQ, handle_eal_mem_info_request, + "Dumps memzones info to file. Parameters: file name"); + rte_telemetry_register_cmd( + EAL_MALLOC_INFO_REQ, handle_eal_mem_info_request, + "Dumps malloc info to file. Parameters: file name"); + rte_telemetry_register_cmd( + EAL_MALLOC_DUMP_REQ, handle_eal_mem_info_request, + "Dumps malloc elems to file. Parameters: file name"); +}