From patchwork Wed Oct 5 04:09:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: datshan X-Patchwork-Id: 117360 X-Patchwork-Delegate: thomas@monjalon.net 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 D86A0A0542; Wed, 5 Oct 2022 06:10:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B769F42847; Wed, 5 Oct 2022 06:10:05 +0200 (CEST) Received: from out162-62-58-211.mail.qq.com (out162-62-58-211.mail.qq.com [162.62.58.211]) by mails.dpdk.org (Postfix) with ESMTP id 3B03E42847 for ; Wed, 5 Oct 2022 06:10:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1664943002; bh=z6PloYGYPgA27BvMg9YE4Jjc/waI/xX6qtuVqBf3C2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ISsGOqRtztritsUESaiqtTMzapOTmsLhW+VSW3i8RqO8WKFgrjCeLkPYP0lI2ZGqA O/HgYdafZfIa+E5c8F3+RlQlpe+TB7FTB1LLDg+7Cqs5wzDL4AiYofcmiG26DzY8+f 6uVRXmsWbucz0Jatz6eGansV1icPRfDxo/hW+XWw= Received: from qq.com ([120.229.93.179]) by newxmesmtplogicsvrsza31.qq.com (NewEsmtp) with SMTP id 27598E97; Wed, 05 Oct 2022 12:09:53 +0800 X-QQ-mid: xmsmtpt1664943001t7842icwi Message-ID: X-QQ-XMAILINFO: OZZSS56D9fAjnm+d5BBD3830ADL+Xbnlpj0WNFUuSea5uoSZnRqwtpiQTAsCUq xl8nw01xVIjpHM0b4TLhfNUZ/OCJZVjfwCt/T0JUseepyilUjr3lwZQRuVOZ8I9Kcnp1u2Bsx8i8 k1RM8HHqRQqp2XiQbx9bVrDPyeeDsKUowQMnyETg/xtFdFQ5OVvXNLV05ls3Wb1X00A0SkcO9wCx JIwcwEq/HSOr0/lMpZ/em1HIGGcPqp73szkwvRj2sFJbCcGxYoLFKaxKUDlqfXtkztqgpmPDHBLE RzQD3S3S8N+asVOmYNXbsyV6ZTD4l2Qvsl5WqkzB/6ev7KjQneK0++AhdNZy72tsbG8chwsKIEL2 jLe3Nh2Tl8ASAEcKLaFuMVaR/42H4QaX7R1y5fCujCTyZG2ccuVuSvEOLr60Bnatlm/HntrqMON+ iB8xZc1z0qwN72Ur3nqpLe3EpuawOKFoAiaUPxsJcdIEEeq0FARj75gjIycVhOu+TVMIobnoIh0x uYPlV2qTjh/XcmsOsf+S+A2KvoIA1r/bVudDoX3sRng6qm/peGzho4F/wvkC1ZSvG2YCQP4xwDUU DA0ehYfnNslNW4hcg0oxX+inmdaOM2jrnXOltnbODJpimZgoVMh2MdpM9qpT/xC+kRRVdgPV/ESs x+qsGLM2o0MW0B0iUsVJSJbDatE5LS6x8Ha+OexaEo9gNBVAJhgofnzRKD2gOD5ZloJFH6Ar6Ayf 9av2pCtPORwFzW1WKmXMhcJ26XIUBSh3eYGuI2XPXMA0Bt1DM3kWI74MTN3igShX8pciXgm0his7 k3KArh0R8JSNEamxrhqTm2bHHorBZ4lrmtaSSuq5PX5gE9L3LbNi3ghA8+mw6kj63SxppeFEns1/ mnzSjRB0GtTJQhRk3HeuFfdmHv8RhQIdJM5tKU/LteaNTuh12Pl7kP3W/dfNnOTC+886PDMbK18n 03+SwrdWnk3SwpX6XMxU731B7Vx/9WIbK2CjJ3OOVSgGcv5SNpl0jYo8vtNM4ZRSw/gIRGTEnJsu doUUO0Ybes+N3hXDBIVQIj/uomdy4= From: datshan To: david.marchand@redhat.com, mb@smartsharesystems.com, anatoly.burakov@intel.com, dmitry.kozliuk@gmail.com, jerinjacobk@gmail.com Cc: thomas@monjalon.net, dev@dpdk.org, Chengwen Feng Subject: [PATCH v5 05/10] memarea: support dump API Date: Wed, 5 Oct 2022 12:09:47 +0800 X-OQ-MSGID: <20221005040952.8166-6-datshan@qq.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221005040952.8166-1-datshan@qq.com> References: <20220721044648.6817-1-fengchengwen@huawei.com> <20221005040952.8166-1-datshan@qq.com> MIME-Version: 1.0 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 From: Chengwen Feng This patch supports rte_memarea_dump() API which could be used for debug. Signed-off-by: Chengwen Feng --- doc/guides/prog_guide/memarea_lib.rst | 3 + lib/memarea/rte_memarea.c | 85 +++++++++++++++++++++++++++ lib/memarea/rte_memarea.h | 21 +++++++ lib/memarea/version.map | 1 + 4 files changed, 110 insertions(+) diff --git a/doc/guides/prog_guide/memarea_lib.rst b/doc/guides/prog_guide/memarea_lib.rst index 41bc0a90cd..c77012fe44 100644 --- a/doc/guides/prog_guide/memarea_lib.rst +++ b/doc/guides/prog_guide/memarea_lib.rst @@ -43,6 +43,9 @@ The ``rte_memarea_update_refcnt()`` function is used to update the memory object's reference count, if the count reaches zero, the memory object will be freed to memarea. ++The ``rte_memarea_dump()`` function is used to dump the internal information ++of a memarea. + Reference --------- diff --git a/lib/memarea/rte_memarea.c b/lib/memarea/rte_memarea.c index a072f07f20..b70830d0bb 100644 --- a/lib/memarea/rte_memarea.c +++ b/lib/memarea/rte_memarea.c @@ -2,6 +2,7 @@ * Copyright(c) 2022 HiSilicon Limited */ +#include #include #include #include @@ -298,3 +299,87 @@ rte_memarea_update_refcnt(struct rte_memarea *ma, void *ptr, int16_t value) memarea_free_elem(ma, elem); memarea_unlock(ma); } + +static const char * +memarea_source_name(enum rte_memarea_source source) +{ + if (source == RTE_MEMAREA_SOURCE_RTE_MEMORY) + return "rte-memory"; + else if (source == RTE_MEMAREA_SOURCE_SYSTEM_API) + return "system-api"; + else if (source == RTE_MEMAREA_SOURCE_USER_ADDR) + return "user-addr"; + else if (source == RTE_MEMAREA_SOURCE_USER_MEMAREA) + return "user-memarea"; + else + return "unknown"; +} + +static const char * +memarea_alg_name(enum rte_memarea_alg alg) +{ + if (alg == RTE_MEMAREA_ALG_DEFAULT) + return "default"; + else + return "unknown"; +} + +static uint32_t +memarea_elem_list_num(struct rte_memarea *ma) +{ + struct memarea_elem *elem; + uint32_t num = 0; + + TAILQ_FOREACH(elem, &ma->elem_list, elem_node) + num++; + + return num; +} + +static uint32_t +memarea_free_list_num(struct rte_memarea *ma) +{ + struct memarea_elem *elem; + uint32_t num = 0; + + TAILQ_FOREACH(elem, &ma->free_list, free_node) + num++; + + return num; +} + +static void +memarea_dump_all(struct rte_memarea *ma, FILE *f) +{ + struct memarea_elem *elem; + + fprintf(f, " regions:\n"); + TAILQ_FOREACH(elem, &ma->elem_list, elem_node) + fprintf(f, " size: 0x%zx cookie: 0x%x refcnt: %d\n", + elem->size, elem->cookie, elem->refcnt); +} + +int +rte_memarea_dump(struct rte_memarea *ma, FILE *f, bool dump_all) +{ + if (ma == NULL || f == NULL) + return -EINVAL; + + memarea_lock(ma); + fprintf(f, "memarea name: %s\n", ma->init.name); + fprintf(f, " source: %s\n", memarea_source_name(ma->init.source)); + if (ma->init.source == RTE_MEMAREA_SOURCE_USER_MEMAREA) + fprintf(f, " source-user-memarea: %s\n", ma->init.user_memarea->init.name); + fprintf(f, " algorithm: %s\n", memarea_alg_name(ma->init.alg)); + fprintf(f, " total-size: 0x%zx\n", ma->init.total_sz); + fprintf(f, " mt-safe: %s\n", ma->init.mt_safe ? "yes" : "no"); + fprintf(f, " total-regions: %u\n", memarea_elem_list_num(ma)); + fprintf(f, " total-free-regions: %u\n", memarea_free_list_num(ma)); + fprintf(f, " alloc_fails: %" PRIu64 "\n", ma->alloc_fails); + fprintf(f, " refcnt_check_fails: %" PRIu64 "\n", ma->refcnt_check_fails); + if (dump_all) + memarea_dump_all(ma, f); + memarea_unlock(ma); + + return 0; +} diff --git a/lib/memarea/rte_memarea.h b/lib/memarea/rte_memarea.h index 10e0d6ad5a..10b8229c64 100644 --- a/lib/memarea/rte_memarea.h +++ b/lib/memarea/rte_memarea.h @@ -194,6 +194,27 @@ void rte_memarea_free(struct rte_memarea *ma, void *ptr); __rte_experimental void rte_memarea_update_refcnt(struct rte_memarea *ma, void *ptr, int16_t value); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Dump memarea. + * + * Dump one memarea. + * + * @param ma + * The pointer of memarea. + * @param f + * The file to write the output to. + * @param dump_all + * Indicate whether to dump the allocated and free memory objects information. + * + * @return + * 0 on success. Otherwise negative value is returned. + */ +__rte_experimental +int rte_memarea_dump(struct rte_memarea *ma, FILE *f, bool dump_all); + #ifdef __cplusplus } #endif diff --git a/lib/memarea/version.map b/lib/memarea/version.map index a0026fc5f9..d8ddd93c13 100644 --- a/lib/memarea/version.map +++ b/lib/memarea/version.map @@ -4,6 +4,7 @@ EXPERIMENTAL { rte_memarea_alloc; rte_memarea_create; rte_memarea_destroy; + rte_memarea_dump; rte_memarea_free; rte_memarea_update_refcnt;