From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6F9CFA034F; Fri, 8 Oct 2021 14:44:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 35B17410E2; Fri, 8 Oct 2021 14:44:21 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 62114410F6 for ; Fri, 8 Oct 2021 14:44:19 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19897uDn029337; Fri, 8 Oct 2021 05:44:18 -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-type; s=pfpt0220; bh=s2S+fd4RtaLYkEUbOF9zgZ11538C7JZuFd2w0zN7fPM=; b=HVUWI5BhBveiuhHbASaklLZxyaykZUlmvnP9HeRbf4eLyXHpWZgRDmL+i7VkO655owDH nEdVhPINozmjq7vRUMqi3KHVjG9V9ACgSpci/ZAPV819LrLdX8PoUYbJPcEoqNoS04y3 MZ8v/dMsqbsh5/8QfHEyIswKUz5R+IAVs+9lJ6CHlfKDaEtaQyxC473FOwmulDHKZTgP hAd3IypQcAYq/WGMQEvl9EcAsQwxYxONiEJXajWBnm6tyauHjGdKhgETtJnMCeTuCPZf RzeiIDoXmN49+XGhYpCFedI1Mk5lzWOrALUcv5zKiXmOaUK8NYcH6MVn3D2FGz1ZSv76 +w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3bja9f2pbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 08 Oct 2021 05:44:18 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 8 Oct 2021 05:44:16 -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; Fri, 8 Oct 2021 05:44:15 -0700 Received: from localhost.localdomain (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id 742065B692B; Fri, 8 Oct 2021 05:44:14 -0700 (PDT) From: Harman Kalra To: , , , Anatoly Burakov CC: Harman Kalra Date: Fri, 8 Oct 2021 18:14:07 +0530 Message-ID: <20211008124407.24738-1-hkalra@marvell.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210915095336.105635-1-hkalra@marvell.com> References: <20210915095336.105635-1-hkalra@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: iYYzq0_wF-O-OD6C2KheosOaP_Ezdhww X-Proofpoint-GUID: iYYzq0_wF-O-OD6C2KheosOaP_Ezdhww 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-10-08_03,2021-10-07_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2] 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 list named (memzones) and unnamed (malloc) memory reserved and return information based on arguments provided by user. Example: Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2 {"version": "DPDK 21.11.0-rc0", "pid": 59754, "max_output_len": 16384} Connected to application: "dpdk-testpmd" --> --> /eal/memzone_list {"/eal/memzone_list": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]} --> --> --> /eal/memzone_info,0 {"/eal/memzone_info": {"Zone": 0, "Name": "rte_eth_dev_data", \ "Length": 225408, "Address": "0x13ffc0280", "Socket": 0, "Flags": 0, \ "Hugepage_size": 536870912, "Hugepage_base": "0x120000000", \ "Hugepage_used": 1}} --> --> --> /eal/memzone_info,6 {"/eal/memzone_info": {"Zone": 6, "Name": "MP_mb_pool_0_0", \ "Length": 669918336, "Address": "0x15811db80", "Socket": 0, \ "Flags": 0, "Hugepage_size": 536870912, "Hugepage_base": "0x140000000", \ "Hugepage_used": 2}} --> --> --> /eal/memzone_info,14 {"/eal/memzone_info": null} --> --> --> /eal/heap_list {"/eal/heap_list": [0]} --> --> --> /eal/heap_info,0 {"/eal/heap_info": {"Head id": 0, "Name": "socket_0", \ "Heap_size": 1610612736, "Free_size": 927645952, \ "Alloc_size": 682966784, "Greatest_free_size": 529153152, \ "Alloc_count": 482, "Free_count": 2}} Signed-off-by: Harman Kalra --- v2: - Reimplemented the patch which is aligned with the telemetry ideology i.e. perform read operations to fetch the info with no changes to filesystem. - Fixed windows build failure. --- lib/eal/common/eal_common_memory.c | 173 +++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c index f83b75092e..616db5ce31 100644 --- a/lib/eal/common/eal_common_memory.c +++ b/lib/eal/common/eal_common_memory.c @@ -20,6 +20,9 @@ #include #include #include +#ifndef RTE_EXEC_ENV_WINDOWS +#include +#endif #include "eal_memalloc.h" #include "eal_private.h" @@ -1102,3 +1105,173 @@ rte_eal_memory_init(void) rte_mcfg_mem_read_unlock(); return -1; } + +#ifndef RTE_EXEC_ENV_WINDOWS +#define EAL_MEMZONE_LIST_REQ "/eal/memzone_list" +#define EAL_MEMZONE_INFO_REQ "/eal/memzone_info" +#define EAL_HEAP_LIST_REQ "/eal/heap_list" +#define EAL_HEAP_INFO_REQ "/eal/heap_info" +#define ADDR_STR 15 + +/* Telemetry callback handler to return heap stats for requested heap id. */ +static int +handle_eal_heap_info_request(const char *cmd __rte_unused, const char *params, + struct rte_tel_data *d) +{ + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + struct rte_malloc_socket_stats sock_stats; + struct malloc_heap *heap; + unsigned int heap_id; + + if (params == NULL || strlen(params) == 0) + return -1; + + heap_id = (unsigned int)strtoul(params, NULL, 10); + + /* Get the heap stats of user provided heap id */ + heap = &mcfg->malloc_heaps[heap_id]; + malloc_heap_get_stats(heap, &sock_stats); + + rte_tel_data_start_dict(d); + rte_tel_data_add_dict_int(d, "Head id", heap_id); + rte_tel_data_add_dict_string(d, "Name", heap->name); + rte_tel_data_add_dict_u64(d, "Heap_size", + sock_stats.heap_totalsz_bytes); + rte_tel_data_add_dict_u64(d, "Free_size", sock_stats.heap_freesz_bytes); + rte_tel_data_add_dict_u64(d, "Alloc_size", + sock_stats.heap_allocsz_bytes); + rte_tel_data_add_dict_u64(d, "Greatest_free_size", + sock_stats.greatest_free_size); + rte_tel_data_add_dict_u64(d, "Alloc_count", sock_stats.alloc_count); + rte_tel_data_add_dict_u64(d, "Free_count", sock_stats.free_count); + + return 0; +} + +/* Telemetry callback handler to list the heap ids setup. */ +static int +handle_eal_heap_list_request(const char *cmd __rte_unused, + const char *params __rte_unused, + struct rte_tel_data *d) +{ + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + struct rte_malloc_socket_stats sock_stats; + unsigned int heap_id; + + rte_tel_data_start_array(d, RTE_TEL_INT_VAL); + /* Iterate through all initialised heaps */ + for (heap_id = 0; heap_id < RTE_MAX_HEAPS; heap_id++) { + struct malloc_heap *heap = &mcfg->malloc_heaps[heap_id]; + + malloc_heap_get_stats(heap, &sock_stats); + if (sock_stats.heap_totalsz_bytes != 0) + rte_tel_data_add_array_int(d, heap_id); + } + + return 0; +} + +/* Telemetry callback handler to return memzone info for requested index. */ +static int +handle_eal_memzone_info_request(const char *cmd __rte_unused, + const char *params, struct rte_tel_data *d) +{ + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + struct rte_memseg_list *msl = NULL; + int ms_idx, ms_count = 0; + void *cur_addr, *mz_end; + struct rte_memzone *mz; + struct rte_memseg *ms; + char addr[ADDR_STR]; + unsigned int mz_idx; + size_t page_sz; + + if (params == NULL || strlen(params) == 0) + return -1; + + mz_idx = strtoul(params, NULL, 10); + + /* Get the memzone handle using index */ + mz = rte_fbarray_get(&mcfg->memzones, mz_idx); + + rte_tel_data_start_dict(d); + rte_tel_data_add_dict_int(d, "Zone", mz_idx); + rte_tel_data_add_dict_string(d, "Name", mz->name); + rte_tel_data_add_dict_int(d, "Length", mz->len); + snprintf(addr, ADDR_STR, "%p", mz->addr); + rte_tel_data_add_dict_string(d, "Address", addr); + rte_tel_data_add_dict_int(d, "Socket", mz->socket_id); + rte_tel_data_add_dict_int(d, "Flags", mz->flags); + + /* go through each page occupied by this memzone */ + msl = rte_mem_virt2memseg_list(mz->addr); + if (!msl) { + RTE_LOG(DEBUG, EAL, "Skipping bad memzone\n"); + return -1; + } + page_sz = (size_t)mz->hugepage_sz; + cur_addr = RTE_PTR_ALIGN_FLOOR(mz->addr, page_sz); + mz_end = RTE_PTR_ADD(cur_addr, mz->len); + + ms_idx = RTE_PTR_DIFF(mz->addr, msl->base_va) / page_sz; + ms = rte_fbarray_get(&msl->memseg_arr, ms_idx); + + rte_tel_data_add_dict_int(d, "Hugepage_size", page_sz); + snprintf(addr, ADDR_STR, "%p", ms->addr); + rte_tel_data_add_dict_string(d, "Hugepage_base", addr); + + do { + /* advance VA to next page */ + cur_addr = RTE_PTR_ADD(cur_addr, page_sz); + + /* memzones occupy contiguous segments */ + ++ms; + ms_count++; + } while (cur_addr < mz_end); + + rte_tel_data_add_dict_int(d, "Hugepage_used", ms_count); + + return 0; +} + +static void +memzone_list_cb(const struct rte_memzone *mz __rte_unused, + void *arg __rte_unused) +{ + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + struct rte_tel_data *d = arg; + int mz_idx; + + mz_idx = rte_fbarray_find_idx(&mcfg->memzones, mz); + rte_tel_data_add_array_int(d, mz_idx); +} + + +/* Telemetry callback handler to list the memzones reserved. */ +static int +handle_eal_memzone_list_request(const char *cmd __rte_unused, + const char *params __rte_unused, + struct rte_tel_data *d) +{ + rte_tel_data_start_array(d, RTE_TEL_INT_VAL); + rte_memzone_walk(memzone_list_cb, d); + + return 0; +} + +RTE_INIT(memory_telemetry) +{ + rte_telemetry_register_cmd( + EAL_MEMZONE_LIST_REQ, handle_eal_memzone_list_request, + "List of memzone index reserved. Takes no parameters"); + rte_telemetry_register_cmd( + EAL_MEMZONE_INFO_REQ, handle_eal_memzone_info_request, + "Returns memzone info. Parameters: int mz_id"); + rte_telemetry_register_cmd( + EAL_HEAP_LIST_REQ, handle_eal_heap_list_request, + "List of heap index setup. Takes no parameters"); + rte_telemetry_register_cmd( + EAL_HEAP_INFO_REQ, handle_eal_heap_info_request, + "Returns malloc heap stats. Parameters: int heap_id"); +} +#endif -- 2.18.0