linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jinyang He <hejinyang@loongson.cn>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Huacai Chen <chenhc@lemote.com>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] MIPS: Add set_memory_node()
Date: Tue, 13 Oct 2020 11:19:43 +0800	[thread overview]
Message-ID: <1602559183-12225-1-git-send-email-hejinyang@loongson.cn> (raw)

Commit e7ae8d174eec ("MIPS: replace add_memory_region with memblock")
replaced add_memory_region(, , BOOT_MEM_RAM) with memblock_add(). But
it doesn't work well on some platforms which have NUMA like Loongson64.
Because memblock_add() calls memblock_add_range() and sets memory at
MAX_NUMNODES. As mm/memblock.c says, assign the region to a NUMA node
later by using memblock_set_node(). This patch provides a NUMA port
set_memory_node() and provides Loongson64 specific function.

The one of examples as follows,
cmdline + "mem=220M@2M"

arch/mips/kernel/setup.c:
	parse_early_param();
+	__memblock_dump_all();
	if (usermem)

Without this patch:
...
[    0.000000] MEMBLOCK configuration:
[    0.000000]  memory size = 0x000000000dc00000 reserved size = 0x0000000003d74000
[    0.000000]  memory.cnt  = 0x1
[    0.000000]  memory[0x0]	[0x0000000000200000-0x000000000ddfffff], 0x000000000dc00000 bytes flags: 0x0
...
and stopped starting.

With this patch:
...
[    0.000000] MEMBLOCK configuration:
[    0.000000]  memory size = 0x000000000dc00000 reserved size = 0x0000000003d74000
[    0.000000]  memory.cnt  = 0x1
[    0.000000]  memory[0x0]	[0x0000000000200000-0x000000000ddfffff], 0x000000000dc00000 bytes on node 0 flags: 0x0
...
and started well.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/include/asm/bootinfo.h |  4 ++++
 arch/mips/kernel/setup.c         | 12 ++++++++++++
 arch/mips/loongson64/numa.c      |  8 ++++++++
 arch/mips/sgi-ip27/ip27-memory.c |  5 +++++
 4 files changed, 29 insertions(+)

diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h
index aa03b12..29e2d9c 100644
--- a/arch/mips/include/asm/bootinfo.h
+++ b/arch/mips/include/asm/bootinfo.h
@@ -92,6 +92,10 @@ extern unsigned long mips_machtype;
 
 extern void detect_memory_region(phys_addr_t start, phys_addr_t sz_min,  phys_addr_t sz_max);
 
+#ifdef CONFIG_NUMA
+extern void set_memory_node(phys_addr_t start, phys_addr_t size);
+#endif
+
 extern void prom_init(void);
 extern void prom_free_prom_memory(void);
 extern void prom_cleanup(void);
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index fb05b66..c1e282d 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -362,6 +362,9 @@ static int __init early_parse_mem(char *p)
 		start = memparse(p + 1, &p);
 
 	memblock_add(start, size);
+#ifdef CONFIG_NUMA
+	set_memory_node(start, size);
+#endif
 
 	return 0;
 }
@@ -388,12 +391,18 @@ static int __init early_parse_memmap(char *p)
 	if (*p == '@') {
 		start_at = memparse(p+1, &p);
 		memblock_add(start_at, mem_size);
+#ifdef CONFIG_NUMA
+		set_memory_node(start_at, mem_size);
+#endif
 	} else if (*p == '#') {
 		pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
 		return -EINVAL;
 	} else if (*p == '$') {
 		start_at = memparse(p+1, &p);
 		memblock_add(start_at, mem_size);
+#ifdef CONFIG_NUMA
+		set_memory_node(start_at, mem_size);
+#endif
 		memblock_reserve(start_at, mem_size);
 	} else {
 		pr_err("\"memmap\" invalid format!\n");
@@ -509,6 +518,9 @@ static void __init check_kernel_sections_mem(void)
 	if (!memblock_is_region_memory(start, size)) {
 		pr_info("Kernel sections are not in the memory maps\n");
 		memblock_add(start, size);
+#ifdef CONFIG_NUMA
+		set_memory_node(start, size);
+#endif
 	}
 }
 
diff --git a/arch/mips/loongson64/numa.c b/arch/mips/loongson64/numa.c
index cf9459f..d428058 100644
--- a/arch/mips/loongson64/numa.c
+++ b/arch/mips/loongson64/numa.c
@@ -234,6 +234,14 @@ void __init mem_init(void)
 	mem_init_print_info(NULL);
 }
 
+void __init set_memory_node(phys_addr_t start, phys_addr_t size)
+{
+	u64 node_id;
+
+	node_id = (start >> 44) & 3;
+	memblock_set_node(start, size, &memblock.memory, node_id);
+}
+
 /* All PCI device belongs to logical Node-0 */
 int pcibus_to_node(struct pci_bus *bus)
 {
diff --git a/arch/mips/sgi-ip27/ip27-memory.c b/arch/mips/sgi-ip27/ip27-memory.c
index d411e0a..f0ed2d4 100644
--- a/arch/mips/sgi-ip27/ip27-memory.c
+++ b/arch/mips/sgi-ip27/ip27-memory.c
@@ -427,3 +427,8 @@ void __init mem_init(void)
 	setup_zero_pages();	/* This comes from node 0 */
 	mem_init_print_info(NULL);
 }
+
+void __init set_memory_node(phys_addr_t start, phys_addr_t size)
+{
+
+}
-- 
2.1.0


             reply	other threads:[~2020-10-13  3:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-13  3:19 Jinyang He [this message]
2020-10-13 20:16 ` [PATCH] MIPS: Add set_memory_node() Maciej W. Rozycki
2020-10-13 21:16 ` Thomas Bogendoerfer

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=1602559183-12225-1-git-send-email-hejinyang@loongson.cn \
    --to=hejinyang@loongson.cn \
    --cc=chenhc@lemote.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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;
as well as URLs for NNTP newsgroup(s).