Linux-MIPS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] MIPS: Add set_memory_node()
@ 2020-10-13  3:19 Jinyang He
  2020-10-13 20:16 ` Maciej W. Rozycki
  2020-10-13 21:16 ` Thomas Bogendoerfer
  0 siblings, 2 replies; 3+ messages in thread
From: Jinyang He @ 2020-10-13  3:19 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Huacai Chen, Jiaxun Yang; +Cc: linux-mips, linux-kernel

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: Add set_memory_node()
  2020-10-13  3:19 [PATCH] MIPS: Add set_memory_node() Jinyang He
@ 2020-10-13 20:16 ` Maciej W. Rozycki
  2020-10-13 21:16 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2020-10-13 20:16 UTC (permalink / raw)
  To: Jinyang He
  Cc: Thomas Bogendoerfer, Huacai Chen, Jiaxun Yang, linux-mips, linux-kernel

On Tue, 13 Oct 2020, Jinyang He wrote:

> 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.

 Please note this is not a full review, I haven't investigated the fitness 
for purpose of this change and instead just addressed one aspect of coding 
style.

> 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
> +

 If anything this needs to be:

#ifdef CONFIG_NUMA
extern void set_memory_node(phys_addr_t start, phys_addr_t size);
#else
static inline void set_memory_node(phys_addr_t start, phys_addr_t size) {}
#endif

so as to avoid #ifdef clutter across call places.

  Maciej

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: Add set_memory_node()
  2020-10-13  3:19 [PATCH] MIPS: Add set_memory_node() Jinyang He
  2020-10-13 20:16 ` Maciej W. Rozycki
@ 2020-10-13 21:16 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Bogendoerfer @ 2020-10-13 21:16 UTC (permalink / raw)
  To: Jinyang He; +Cc: Huacai Chen, Jiaxun Yang, linux-mips, linux-kernel

On Tue, Oct 13, 2020 at 11:19:43AM +0800, Jinyang He wrote:
> Commit e7ae8d174eec ("MIPS: replace add_memory_region with memblock")

this commit just changed code and doesn't change the problem you want to
solve.

> 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

so it says later, which doesn't have to be right after the memblock_add.
I don't know why you need the whole mem=/memmap= game, but please do a

for_each_memblock(...) 
	memblock_set_node(...);

somewhere in arch/mips/loongson64 to fix up the memory blocks as needed.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13  3:19 [PATCH] MIPS: Add set_memory_node() Jinyang He
2020-10-13 20:16 ` Maciej W. Rozycki
2020-10-13 21:16 ` Thomas Bogendoerfer

Linux-MIPS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mips/0 linux-mips/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mips linux-mips/ https://lore.kernel.org/linux-mips \
		linux-mips@vger.kernel.org
	public-inbox-index linux-mips

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mips


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git