From nobody Thu Apr 18 07:39:44 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3B43C77B73 for ; Fri, 26 May 2023 11:49:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242602AbjEZLtA (ORCPT ); Fri, 26 May 2023 07:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236715AbjEZLs6 (ORCPT ); Fri, 26 May 2023 07:48:58 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EFCCA7 for ; Fri, 26 May 2023 04:48:57 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QSNS52ZJlzsR59; Fri, 26 May 2023 19:46:45 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Fri, 26 May 2023 19:48:54 +0800 From: Kefeng Wang To: Mike Rapoport , Andrew Morton , CC: , , , , Kefeng Wang Subject: [PATCH -next v2] memblock: unify memblock dump and debugfs show Date: Fri, 26 May 2023 20:05:05 +0800 Message-ID: <20230526120505.123693-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There are two interfaces to show the memblock information, memblock_dump_al= l() and /sys/kernel/debug/memblock/, but the content is displayed separately, let's unify them in case of more different changes over time. Signed-off-by: Kefeng Wang --- v2: - fix wrong count since we add MEMBLOCK_MAX_UNKNOWN - drop __initdata_memblock for flagname include/linux/memblock.h | 1 + mm/memblock.c | 80 ++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index f82ee3fac1cd..d68826e8c97b 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -47,6 +47,7 @@ enum memblock_flags { MEMBLOCK_MIRROR =3D 0x2, /* mirrored region */ MEMBLOCK_NOMAP =3D 0x4, /* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED =3D 0x8, /* always detected via a driver */ + MEMBLOCK_MAX_UNKNOWN =3D 0x10, /* unknow flags */ }; =20 /** diff --git a/mm/memblock.c b/mm/memblock.c index c5c80d9bcea3..04eb7c665026 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1899,16 +1899,35 @@ phys_addr_t __init_memblock memblock_get_current_li= mit(void) return memblock.current_limit; } =20 -static void __init_memblock memblock_dump(struct memblock_type *type) +#define memblock_printf(m, to_dmesg, fmt, args...) \ +({ \ + if (to_dmesg) \ + pr_info(fmt, ##args); \ + else \ + seq_printf(m, fmt, ##args); \ +}) + +static const char * const flagname[] =3D { + [ilog2(MEMBLOCK_HOTPLUG)] =3D "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] =3D "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] =3D "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] =3D "DRV_MNG", + [ilog2(MEMBLOCK_MAX_UNKNOWN)] =3D "UNKNOWN", +}; + +static void __init_memblock memblock_dump(struct memblock_type *type, + struct seq_file *m, bool to_dmesg) { + unsigned count =3D ARRAY_SIZE(flagname) - 1; phys_addr_t base, end, size; enum memblock_flags flags; - int idx; struct memblock_region *rgn; + int idx, i; =20 - pr_info(" %s.cnt =3D 0x%lx\n", type->name, type->cnt); + memblock_printf(m, to_dmesg, " %s.cnt =3D 0x%lx\n", type->name, type->cn= t); =20 for_each_memblock_type(idx, type, rgn) { + const char *fp =3D "NONE"; char nid_buf[32] =3D ""; =20 base =3D rgn->base; @@ -1920,8 +1939,19 @@ static void __init_memblock memblock_dump(struct mem= block_type *type) snprintf(nid_buf, sizeof(nid_buf), " on node %d", memblock_get_region_node(rgn)); #endif - pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n", - type->name, idx, &base, &end, &size, nid_buf, flags); + if (flags) { + fp =3D flagname[count]; + + for (i =3D 0; i < count; i++) { + if (flags & (1U << i)) { + fp =3D flagname[i]; + break; + } + } + } + + memblock_printf(m, to_dmesg, " %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %s= \n", + type->name, idx, &base, &end, &size, nid_buf, fp); } } =20 @@ -1932,10 +1962,10 @@ static void __init_memblock __memblock_dump_all(voi= d) &memblock.memory.total_size, &memblock.reserved.total_size); =20 - memblock_dump(&memblock.memory); - memblock_dump(&memblock.reserved); + memblock_dump(&memblock.memory, NULL, true); + memblock_dump(&memblock.reserved, NULL, true); #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP - memblock_dump(&physmem); + memblock_dump(&physmem, NULL, true); #endif } =20 @@ -2158,41 +2188,13 @@ void __init memblock_free_all(void) } =20 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) -static const char * const flagname[] =3D { - [ilog2(MEMBLOCK_HOTPLUG)] =3D "HOTPLUG", - [ilog2(MEMBLOCK_MIRROR)] =3D "MIRROR", - [ilog2(MEMBLOCK_NOMAP)] =3D "NOMAP", - [ilog2(MEMBLOCK_DRIVER_MANAGED)] =3D "DRV_MNG", -}; =20 static int memblock_debug_show(struct seq_file *m, void *private) { struct memblock_type *type =3D m->private; - struct memblock_region *reg; - int i, j; - unsigned int count =3D ARRAY_SIZE(flagname); - phys_addr_t end; - - for (i =3D 0; i < type->cnt; i++) { - reg =3D &type->regions[i]; - end =3D reg->base + reg->size - 1; - - seq_printf(m, "%4d: ", i); - seq_printf(m, "%pa..%pa ", ®->base, &end); - seq_printf(m, "%4d ", memblock_get_region_node(reg)); - if (reg->flags) { - for (j =3D 0; j < count; j++) { - if (reg->flags & (1U << j)) { - seq_printf(m, "%s\n", flagname[j]); - break; - } - } - if (j =3D=3D count) - seq_printf(m, "%s\n", "UNKNOWN"); - } else { - seq_printf(m, "%s\n", "NONE"); - } - } + + memblock_dump(type, m, false); + return 0; } DEFINE_SHOW_ATTRIBUTE(memblock_debug); --=20 2.35.3