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 73A61A00C3; Tue, 20 Sep 2022 05:53:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A262242B70; Tue, 20 Sep 2022 05:53:06 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id F220140DFB for ; Tue, 20 Sep 2022 05:53:00 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MWncg4w1pzpSyR; Tue, 20 Sep 2022 11:50:11 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 11:52:58 +0800 From: Chengwen Feng To: CC: , , , Subject: [PATCH 5/8] memarea: support dump API Date: Tue, 20 Sep 2022 03:46:40 +0000 Message-ID: <20220920034643.55476-6-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220920034643.55476-1-fengchengwen@huawei.com> References: <20220721044648.6817-1-fengchengwen@huawei.com> <20220920034643.55476-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected 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 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 | 83 +++++++++++++++++++++++++++ lib/memarea/rte_memarea.h | 21 +++++++ lib/memarea/version.map | 1 + 4 files changed, 108 insertions(+) diff --git a/doc/guides/prog_guide/memarea_lib.rst b/doc/guides/prog_guide/memarea_lib.rst index 967129d560..7686625c90 100644 --- a/doc/guides/prog_guide/memarea_lib.rst +++ b/doc/guides/prog_guide/memarea_lib.rst @@ -45,6 +45,9 @@ The ``rte_memarea_update_refcnt()`` function is used to update the memory region's reference count, if the count reaches zero, the memory region will be freed to memarea object. +The ``rte_memarea_dump()`` function is used to dump the internal information +of a memarea object. + Reference --------- diff --git a/lib/memarea/rte_memarea.c b/lib/memarea/rte_memarea.c index fe4a820173..e40715d16a 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 @@ -278,3 +279,85 @@ rte_memarea_update_refcnt(struct rte_memarea *ma, void *ptr, int16_t value) memarea_free_elem(priv, elem); memarea_unlock(priv); } + +static const char * +memarea_source_name(enum rte_memarea_source source) +{ + 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_name(struct rte_memarea *ma) +{ + struct memarea_private *priv = ma->private_data; + return priv->init.name; +} + +static uint32_t +memarea_elem_list_num(struct memarea_private *priv) +{ + struct memarea_elem *elem; + uint32_t num = 0; + + TAILQ_FOREACH(elem, &priv->elem_list, elem_node) + num++; + + return num; +} + +static uint32_t +memarea_free_list_num(struct memarea_private *priv) +{ + struct memarea_elem *elem; + uint32_t num = 0; + + TAILQ_FOREACH(elem, &priv->free_list, free_node) + num++; + + return num; +} + +static void +memarea_dump_all(struct memarea_private *priv, FILE *f) +{ + struct memarea_elem *elem; + + fprintf(f, " regions:\n"); + TAILQ_FOREACH(elem, &priv->elem_list, elem_node) + fprintf(f, " size: 0x%lx cookie: %u refcnt: %d\n", + elem->size, elem->cookie, elem->refcnt); +} + +int +rte_memarea_dump(struct rte_memarea *ma, FILE *f, bool dump_all) +{ + struct memarea_private *priv; + + if (ma == NULL || f == NULL) + return -EINVAL; + + priv = ma->private_data; + memarea_lock(priv); + fprintf(f, "memarea name: %s\n", priv->init.name); + fprintf(f, " source: %s\n", memarea_source_name(priv->init.source)); + if (priv->init.source == RTE_MEMAREA_SOURCE_USER_MEMAREA) + fprintf(f, " source-user-memarea: %s\n", memarea_name(priv->init.user_memarea)); + fprintf(f, " total-size: 0x%lx\n", priv->init.total_sz); + fprintf(f, " mt-safe: %s\n", priv->init.mt_safe ? "yes" : "no"); + fprintf(f, " total-regions: %u\n", memarea_elem_list_num(priv)); + fprintf(f, " total-free-regions: %u\n", memarea_free_list_num(priv)); + fprintf(f, " alloc_fails: %" PRIu64 "\n", priv->alloc_fails); + fprintf(f, " refcnt_check_fails: %" PRIu64 "\n", priv->refcnt_check_fails); + if (dump_all) + memarea_dump_all(priv, f); + memarea_unlock(priv); + + return 0; +} diff --git a/lib/memarea/rte_memarea.h b/lib/memarea/rte_memarea.h index cded2904e3..d1383f18c3 100644 --- a/lib/memarea/rte_memarea.h +++ b/lib/memarea/rte_memarea.h @@ -180,6 +180,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 region 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; -- 2.17.1