Skip to content

Commit

Permalink
numa: Add simple generic NUMA emulation
Browse files Browse the repository at this point in the history
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
mairacanal authored and N0m4n904 committed Sep 11, 2024
1 parent a6084c8 commit 87eab19
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/base/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ config GENERIC_ARCH_NUMA
Enable support for generic NUMA implementation. Currently, RISC-V
and ARM64 use it.

config GENERIC_ARCH_NUMA_EMULATION
bool
depends on GENERIC_ARCH_NUMA
help
Enable NUMA emulation. Note that NUMA emulation will only be used if
the machine has no NUMA node.

config FW_DEVLINK_SYNC_STATE_TIMEOUT
bool "sync_state() behavior defaults to timeout instead of strict"
help
Expand Down
1 change: 1 addition & 0 deletions drivers/base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ obj-$(CONFIG_DEV_COREDUMP) += devcoredump.o
obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
obj-$(CONFIG_GENERIC_ARCH_NUMA_EMULATION) += numa_emulation.o
obj-$(CONFIG_ACPI) += physical_location.o

obj-y += test/
Expand Down
6 changes: 6 additions & 0 deletions drivers/base/arch_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <asm/sections.h>

#include "numa_emulation.h"

struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
EXPORT_SYMBOL(node_data);
nodemask_t numa_nodes_parsed __initdata;
Expand All @@ -30,6 +32,8 @@ static __init int numa_parse_early_param(char *opt)
return -EINVAL;
if (str_has_prefix(opt, "off"))
numa_off = true;
if (str_has_prefix(opt, "fake="))
return numa_emu_cmdline(opt + 5);

return 0;
}
Expand Down Expand Up @@ -471,6 +475,8 @@ void __init arch_numa_init(void)
return;
if (acpi_disabled && !numa_init(of_numa_init))
return;
if (!numa_init(numa_emu_init))
return;
}

numa_init(dummy_numa_init);
Expand Down
67 changes: 67 additions & 0 deletions drivers/base/numa_emulation.c
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;
}
21 changes: 21 additions & 0 deletions drivers/base/numa_emulation.h
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 */

0 comments on commit 87eab19

Please sign in to comment.