From: Martin Liu <liumartin@google.com>
To: robh+dt@kernel.org, frowand.list@gmail.com
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
surenb@google.com, minchan@kernel.org, tkjos@google.com,
liumartin@google.com
Subject: [PATCH] of: reserved-mem: expose reserved-mem details via debugfs
Date: Mon, 6 Feb 2023 22:27:14 +0800 [thread overview]
Message-ID: <20230206142714.4151047-1-liumartin@google.com> (raw)
It's important to know reserved-mem information in mobile world
since reserved memory via device tree keeps increased in platform
(e.g., 45% in our platform). Therefore, it's crucial to know the
reserved memory sizes breakdown for the memory accounting.
This patch shows the reserved memory breakdown under debugfs to
make them visible.
Below is an example output:
cat $debugfs/reserved_mem/show
0x00000009fc400000..0x00000009ffffffff ( 61440 KB ) map reusable test1
0x00000009f9000000..0x00000009fc3fffff ( 53248 KB ) map reusable test2
0x00000000ffdf0000..0x00000000ffffffff ( 2112 KB ) map non-reusable test3
0x00000009f6000000..0x00000009f8ffffff ( 49152 KB ) map reusable test4
...
0x00000000fd902000..0x00000000fd909fff ( 32 KB ) nomap non-reusable test38
0x00000000fd90a000..0x00000000fd90bfff ( 8 KB ) nomap non-reusable test39
Total 39 regions, 1446140 KB
Signed-off-by: Martin Liu <liumartin@google.com>
---
drivers/of/of_reserved_mem.c | 39 ++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 65f3b02a0e4e..a73228e07c8c 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -23,6 +23,7 @@
#include <linux/memblock.h>
#include <linux/kmemleak.h>
#include <linux/cma.h>
+#include <linux/debugfs.h>
#include "of_private.h"
@@ -446,3 +447,41 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
return NULL;
}
EXPORT_SYMBOL_GPL(of_reserved_mem_lookup);
+
+#if defined(CONFIG_DEBUG_FS)
+static int of_reserved_mem_debug_show(struct seq_file *m, void *private)
+{
+ unsigned int i;
+ size_t sum = 0;
+
+ for (i = 0; i < reserved_mem_count; i++) {
+ const struct reserved_mem *rmem = &reserved_mem[i];
+ unsigned long node = rmem->fdt_node;
+ phys_addr_t end = rmem->base + rmem->size - 1;
+ bool nomap = (of_get_flat_dt_prop(node, "no-map", NULL)) != NULL;
+ bool reusable = (of_get_flat_dt_prop(node, "reusable", NULL)) != NULL;
+
+ sum += rmem->size;
+ seq_printf(m, "%pa..%pa ( %7lu KB ) %5s %12s %s\n", &rmem->base,
+ &end, rmem->size / 1024,
+ nomap ? "nomap" : "map",
+ reusable ? "reusable" : "non-reusable",
+ rmem->name ? rmem->name : "unknown");
+ }
+ seq_printf(m, "Total %d regions, %zu KB\n",
+ reserved_mem_count,
+ sum / 1024);
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(of_reserved_mem_debug);
+
+static int __init of_reserved_mem_init_debugfs(void)
+{
+ struct dentry *root = debugfs_create_dir("reserved_mem", NULL);
+
+ debugfs_create_file("show", 0444, root,
+ NULL, &of_reserved_mem_debug_fops);
+ return 0;
+}
+device_initcall(of_reserved_mem_init_debugfs);
+#endif
--
2.39.1.519.gcb327c4b5f-goog
next reply other threads:[~2023-02-06 14:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 14:27 Martin Liu [this message]
2023-02-06 15:12 ` Rob Herring
2023-02-07 17:05 ` Martin Liu
2023-02-07 21:04 ` Rob Herring
2023-02-08 8:59 ` Martin Liu
2023-02-06 17:24 ` kernel test robot
2023-02-06 19:57 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230206142714.4151047-1-liumartin@google.com \
--to=liumartin@google.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=robh+dt@kernel.org \
--cc=surenb@google.com \
--cc=tkjos@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®