From nobody Thu Dec 18 20:23:53 2025 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CCBB15A87A for ; Tue, 25 Jun 2024 12:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719320306; cv=none; b=j4QUYWRgdB+pHiad+aY5DmvgaoJldU2ilel1JabyUq4QZBYCOhuacLyH2m0kI85/w71kezzHVrChobsqB6kQPmNFzA6zTQdxaS5vgTBDdM1t+ShAqX+RxESRBM6nD2hL8D9Vw034T9xYeE5YCka87WkFZGMW1dMtFNE3lOC7LDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719320306; c=relaxed/simple; bh=yysy+0k4viJZlCgs1FiqKD47K2a53OZQmVhcvIJQp0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LGssrdcH7wm3rcLfZTeJYx9z4gOAXzatcdg9AHXeDNe2MRpcqLZS/4b828Hsc4A2rrFFc8AcGQMPrY5GhHvxr8GSfBo2obFbTY5acsL8LAecTDs52V61PWeS7FIywg85gRK/CDgFsJijwHnqhufjEfmAwfrp/gcKIEf5Ixz5H80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=l0pphxkQ; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="l0pphxkQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1zOlxzHp0smE9UfbcodciZvu33TYDM4Qa9pbUNbyMBc=; b=l0pphxkQFC4KW/uenGEhMUEkcm XpB0tL6qB6mak5eVAObHEjmdhoVGolx3KmJ5NuunL4j/OPvIRQa9GAochTiwJoPWs0Eiivm1v8GEx jyqhCu+pxtxlGlo2aGOL/MIloUgtCIqudY7kU3e+0tiO+xnkpwlG8fP8XP86BJIZBO/qVb+Fw/ljA uqM6+nuemrjoF7NfBvDylTSDRHYOgsc7T9nbaeSHR1Vt4vld5xDInfglha2FB28v+O9kjB/+3HMbk N7b6IlnFkWW9Smx6eZr40I2ZKmyukkFoLXyu6Gfc+0jRUyWrjaKSTMCuu5XcHyzv1IsMXmmtbcDNv /Afy8rDA==; Received: from [84.69.19.168] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sM5kV-007J4Y-Kc; Tue, 25 Jun 2024 14:58:15 +0200 From: Tvrtko Ursulin To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?UTF-8?q?Ma=C3=ADra=20Canal?= , Tvrtko Ursulin , Catalin Marinas , Will Deacon , Greg Kroah-Hartman Subject: [PATCH 1/2] numa: Add simple generic NUMA emulation Date: Tue, 25 Jun 2024 13:58:02 +0100 Message-ID: <20240625125803.38038-2-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240625125803.38038-1-tursulin@igalia.com> References: <20240625125803.38038-1-tursulin@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Ma=C3=ADra Canal 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=3Dfake=3D kernel argument to enable it. Memory is always split into equally sized chunks. Signed-off-by: Ma=C3=ADra Canal Signed-off-by: Tvrtko Ursulin Co-developed-by: Tvrtko Ursulin Cc: Catalin Marinas Cc: Will Deacon Cc: Greg Kroah-Hartman Cc: =E2=80=9CRafael J. Wysocki" --- drivers/base/Kconfig | 7 ++++ drivers/base/Makefile | 1 + drivers/base/arch_numa.c | 6 ++++ drivers/base/numa_emulation.c | 67 +++++++++++++++++++++++++++++++++++ drivers/base/numa_emulation.h | 21 +++++++++++ 5 files changed, 102 insertions(+) create mode 100644 drivers/base/numa_emulation.c create mode 100644 drivers/base/numa_emulation.h diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index 2b8fd6bb7da0..1f60cd4dd057 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -230,6 +230,13 @@ config GENERIC_ARCH_NUMA Enable support for generic NUMA implementation. Currently, RISC-V and ARM64 use it. =20 +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 diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 3079bfe53d04..34fcf5bd7370 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_DEV_COREDUMP) +=3D devcoredump.o obj-$(CONFIG_GENERIC_MSI_IRQ) +=3D platform-msi.o obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) +=3D arch_topology.o obj-$(CONFIG_GENERIC_ARCH_NUMA) +=3D arch_numa.o +obj-$(CONFIG_GENERIC_ARCH_NUMA_EMULATION) +=3D numa_emulation.o obj-$(CONFIG_ACPI) +=3D physical_location.o =20 obj-y +=3D test/ diff --git a/drivers/base/arch_numa.c b/drivers/base/arch_numa.c index 5b59d133b6af..6ad08f681b3c 100644 --- a/drivers/base/arch_numa.c +++ b/drivers/base/arch_numa.c @@ -15,6 +15,8 @@ =20 #include =20 +#include "numa_emulation.h" + struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; EXPORT_SYMBOL(node_data); nodemask_t numa_nodes_parsed __initdata; @@ -30,6 +32,8 @@ static __init int numa_parse_early_param(char *opt) return -EINVAL; if (str_has_prefix(opt, "off")) numa_off =3D true; + if (str_has_prefix(opt, "fake=3D")) + return numa_emu_cmdline(opt + 5); =20 return 0; } @@ -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; } =20 numa_init(dummy_numa_init); diff --git a/drivers/base/numa_emulation.c b/drivers/base/numa_emulation.c new file mode 100644 index 000000000000..df652fa8351b --- /dev/null +++ b/drivers/base/numa_emulation.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Simple NUMA emulation. + * + * Copyright =C2=A9 2024 Raspberry Pi Ltd + * + * Author: Ma=C3=ADra Canal + * Author: Tvrtko Ursulin + */ +#include + +#include "numa_emulation.h" + +static unsigned int emu_nodes; + +int __init numa_emu_cmdline(char *str) +{ + int ret; + + ret =3D kstrtouint(str, 10, &emu_nodes); + if (ret) + return ret; + + if (emu_nodes > MAX_NUMNODES) { + pr_notice("numa=3Dfake=3D%u too large, reducing to %u\n", + emu_nodes, MAX_NUMNODES); + emu_nodes =3D 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 =3D memblock_start_of_DRAM(); + end =3D memblock_end_of_DRAM() - 1; + + size =3D DIV_ROUND_DOWN_ULL(end - start + 1, emu_nodes); + size =3D PAGE_ALIGN_DOWN(size); + + for (i =3D 0; i < emu_nodes; i++) { + u64 s, e; + + s =3D start + i * size; + e =3D s + size - 1; + + if (i =3D=3D (emu_nodes - 1) && e !=3D end) + e =3D end; + + pr_info("Faking a node at [mem %pap-%pap]\n", &s, &e); + ret =3D numa_add_memblk(i, s, e + 1); + if (ret) { + pr_err("Failed to add fake NUMA node %d!\n", i); + break; + } + } + + return ret; +} diff --git a/drivers/base/numa_emulation.h b/drivers/base/numa_emulation.h new file mode 100644 index 000000000000..62b38215a2f0 --- /dev/null +++ b/drivers/base/numa_emulation.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * NUMA emulation header + * + * Copyright =C2=A9 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 */ --=20 2.44.0 From nobody Thu Dec 18 20:23:53 2025 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CC6F157A6C for ; Tue, 25 Jun 2024 12:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719320306; cv=none; b=cdqkDLimySPSI2vmpc4oR2QMhOFD/ymm8wbm1FiHy7VGQQraHq7RYmcKrX7QB9bJvJNGciVeLY4N2HkhOFx9ktmI6o4+aITECra7MmQ4zLIEh/UwIryvtROTlQyYHaX4ztlQ72eckAkh4zcsND0ccbw4/lBDyWB60vNzS7bE4Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719320306; c=relaxed/simple; bh=R+0v3SjYynSFu6kDngop0Uopo9Xqhn/mNhXd+Yeuzas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n5tGE3lV6ooiimKSJKLA7/CjL2S4yVkGbJ3GQg1uNNDF1HgZX9qeJoDwqNZ8pG0ld9ClFL+AmPNO644CMlQ0JmgscqBAWK2K9n9RNV5LOw32e5VZPwqdKxuw7R9CmiIe1PJEn9quVI9WTOHQBnIL/XrOjeRIvPLV9u1pTinZm2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=cd0A3Mqx; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="cd0A3Mqx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=u73BM2k0P5V0AYjELtkiQ2BhOsIZOrApdWBJKOtljdU=; b=cd0A3Mqxf8WtqGzNNBqSZzdhFe 51ANiA2VcZdEPlHP5VTbnLoyccrXwEHOYk97oHIgGPYcz8Vsj/w14T5ZQVYO2mko5ixw5gTzjtTnV LRMVlcgu735PH73u4Mj71RUymizaVWyvpq6LQOJtiK89pXNmzfcv0hKxNR/yhoAoDvibeRtEwduo1 sz1omZjEiVSrHQn6HWWqpRe60/abE3kM/RdeCHHB75ALRjPl9SnhO52UYu/4/w5fBT7j/0+pI9E4A mwwZcZCJsXNLj0Qvde6ghN9IhKW3qbmuoHj2r3ZAmUyQmNZdQ7oYz6ZSonONvXPSiCbLfQKgCqRVd roJzfXaA==; Received: from [84.69.19.168] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sM5kW-007J4a-AU; Tue, 25 Jun 2024 14:58:16 +0200 From: Tvrtko Ursulin To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?UTF-8?q?Ma=C3=ADra=20Canal?= , Tvrtko Ursulin , Catalin Marinas , Will Deacon , Greg Kroah-Hartman Subject: [PATCH 2/2] arm64/numa: Add NUMA emulation for ARM64 Date: Tue, 25 Jun 2024 13:58:03 +0100 Message-ID: <20240625125803.38038-3-tursulin@igalia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240625125803.38038-1-tursulin@igalia.com> References: <20240625125803.38038-1-tursulin@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Ma=C3=ADra Canal Allow selecting NUMA emulation on arm64. Signed-off-by: Ma=C3=ADra Canal Signed-off-by: Tvrtko Ursulin Cc: Catalin Marinas Cc: Will Deacon Cc: Greg Kroah-Hartman Cc: =E2=80=9CRafael J. Wysocki" --- arch/arm64/Kconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 8e80df015bdd..49c1cdc545d3 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1507,6 +1507,16 @@ config NODES_SHIFT Specify the maximum number of NUMA Nodes available on the target system. Increases memory reserved to accommodate various tables. =20 +config NUMA_EMULATION + bool "NUMA emulation" + depends on NUMA + select GENERIC_ARCH_NUMA_EMULATION + help + Enable NUMA emulation support. A flat machine will be split into + virtual nodes when booted with "numa=3Dfake=3DN", where N is the number + of nodes, the system RAM will be split into N equal chunks, and + assigned to each node. + source "kernel/Kconfig.hz" =20 config ARCH_SPARSEMEM_ENABLE --=20 2.44.0