forked from raspberrypi/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
numa: Add simple generic NUMA emulation
Add some common code for splitting the memory into N emulated NUMA memory nodes. Individual architecture can then enable selecting this option and use the existing numa=fake=<N> kernel argument to enable it. Memory is always split into equally sized chunks. Signed-off-by: Maíra Canal <mcanal@igalia.com> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Co-developed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: “Rafael J. Wysocki" <rafael@kernel.org>
- Loading branch information
1 parent
a6084c8
commit 87eab19
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Simple NUMA emulation. | ||
* | ||
* Copyright © 2024 Raspberry Pi Ltd | ||
* | ||
* Author: Maíra Canal <mcanal@igalia.com> | ||
* Author: Tvrtko Ursulin <tursulin@igalia.com> | ||
*/ | ||
#include <linux/memblock.h> | ||
|
||
#include "numa_emulation.h" | ||
|
||
static unsigned int emu_nodes; | ||
|
||
int __init numa_emu_cmdline(char *str) | ||
{ | ||
int ret; | ||
|
||
ret = kstrtouint(str, 10, &emu_nodes); | ||
if (ret) | ||
return ret; | ||
|
||
if (emu_nodes > MAX_NUMNODES) { | ||
pr_notice("numa=fake=%u too large, reducing to %u\n", | ||
emu_nodes, MAX_NUMNODES); | ||
emu_nodes = MAX_NUMNODES; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int __init numa_emu_init(void) | ||
{ | ||
phys_addr_t start, end; | ||
unsigned long size; | ||
unsigned int i; | ||
int ret; | ||
|
||
if (!emu_nodes) | ||
return -EINVAL; | ||
|
||
start = memblock_start_of_DRAM(); | ||
end = memblock_end_of_DRAM() - 1; | ||
|
||
size = DIV_ROUND_DOWN_ULL(end - start + 1, emu_nodes); | ||
size = PAGE_ALIGN_DOWN(size); | ||
|
||
for (i = 0; i < emu_nodes; i++) { | ||
u64 s, e; | ||
|
||
s = start + i * size; | ||
e = s + size - 1; | ||
|
||
if (i == (emu_nodes - 1) && e != end) | ||
e = end; | ||
|
||
pr_info("Faking a node at [mem %pap-%pap]\n", &s, &e); | ||
ret = numa_add_memblk(i, s, e + 1); | ||
if (ret) { | ||
pr_err("Failed to add fake NUMA node %d!\n", i); | ||
break; | ||
} | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* NUMA emulation header | ||
* | ||
* Copyright © 2024 Raspberry Pi Ltd | ||
*/ | ||
|
||
#ifdef CONFIG_GENERIC_ARCH_NUMA_EMULATION | ||
int numa_emu_cmdline(char *str); | ||
int __init numa_emu_init(void); | ||
#else | ||
static inline int numa_emu_cmdline(char *str) | ||
{ | ||
return -EINVAL; | ||
} | ||
|
||
static int __init numa_emu_init(void) | ||
{ | ||
return -EOPNOTSUPP; | ||
} | ||
#endif /* CONFIG_NUMA_EMU */ |