Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp676622pxa; Fri, 14 Aug 2020 15:01:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxRIBJuQfdD8s2ul/p0GGVqgQ1XwyKmGJI8QACRBAl22SdUUr0j7F6mVPPSZ/GE1i7o8Yi X-Received: by 2002:aa7:c6c3:: with SMTP id b3mr4340815eds.215.1597442495552; Fri, 14 Aug 2020 15:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597442495; cv=none; d=google.com; s=arc-20160816; b=IaLz5ctW7+YePfjReKaK0rQ/2Z3OPZJ3RfWAZqYRkeBN99ctvga6BAkF5H8LP0U4LJ XKel8Mwnjtd5D6uW32iuIMrykMJi6rorEnULgGs10QaH0Zs+Zx0b6NIQc8h72fr9z5Dr xpKeaH9lZomLmqhyg+uhJ2NeQSZO3cjNFQ77UOhHWy3WWG2MtfPaGb5Rz067jp5/5zkk 6hZ7hWP736fwq23u3YFZ0tPPXqVAPv6EieXi6g4cBxN++LMAubj0+d8iOkMq/sOyux5A vlxEG5oB5XuVWyBwhuhus+Bauohv3wGIEtMgttcuWhPP+b5HLt8nJ2YhJp4ayCcQU+kw monw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=SDVAl+EU2XnzUTswWT5UoI5Y6TbmiAgIQsy3y5BsitM=; b=govCbuWm/t7pMT93Ad10ssojEW0pIWQ7D/afpH2UOWi6jpokx3Isne6sUh3Lkbb8DK q7jln9sDR4foKadHi4Gg1i5oIfbcx7FV+GeNwkOq2f8doajDi2x8k1oBuI6wFkG4TZRz SiqmidfMso+HvDAuwbvAB4+Zq40cSRapX8rHYVlbVwe/+xZkA4kPOr55vW4y8nEtKNRW IPNfIySzragRhP815rgRtdpZaVwRwoemej5Um9hvW5ZlS8qF6Ri+GlwBEtulbCkOCUyv 0ntFpBoBidTW26uCWpS0E8F3o73/feD0hsr1A9R/+6SiIG78yBgnKRK0117PKsHu03Uu IbNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=O+3folRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si6138961ejb.582.2020.08.14.15.01.12; Fri, 14 Aug 2020 15:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=O+3folRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728574AbgHNVsk (ORCPT + 99 others); Fri, 14 Aug 2020 17:48:40 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25033 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728486AbgHNVse (ORCPT ); Fri, 14 Aug 2020 17:48:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1597441714; x=1628977714; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bpKvYi5cx9vYWwDbNQ8jhGTPMfOv34iHRQFrh6Rdxoo=; b=O+3folRKaX+Pg54YPTFAgjt9WFR4r12S2sGAj5gLPlLoTqjDuTzaRyyk 6zlwEDavhhNFURPxWv5xAf9wOcbgngoo1bSWo5xAuDts/SNnvh63HTp4Q uYErV+2GazFcXpXnXNAx9va8xVSPhkiUFMMeahBWZFVIPCD3py5HsK9x8 yDCz4YFbiM7ZoSRdX4kDSMUL/pdr3W+WPAryR4+ynP136tBrWF5lNMdKA uhWaQIK+ggtdr3bQJpLefE8OTrgxFN5fzvEq3DOoX+x/4t3ddcCm9uLPs EEgfIFmljtvPC745EC7hoyve5X+CFBD2yR4tKGZ7JxnDdyAjvXxp5isqv Q==; IronPort-SDR: EgQDpC1rmFSAfvRNe+888DAW9/wiggRGcUC0i8l/pA2YsdpkdqptYAWojga8qMxYLqQoV+midL Z6wVHJYG1gXLJEDr67pZYwyhdXSQTnXkbShLMkutdfWxXEDzHDcck/6pmCNYR9j0QBQR72fmit s3CW30I/mm7aecAOIGX3NOKEFIxO6dIEAhabm34megKDBnb0Kt6gS9QJ1j8+FvvmvKrEzCVeLf XlXwyCCYwBH5t3TbqBqK3s6E6j/lBNE/+wSHIAv4uuKHpQ0sgHL/SsFJOroouIXjLJQIc3p0lj ZjU= X-IronPort-AV: E=Sophos;i="5.76,313,1592841600"; d="scan'208";a="146217662" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Aug 2020 05:48:34 +0800 IronPort-SDR: W29oUUXjpXEqBO5B6gbmB5MQLTFUUdaRW/JnMFNZCuAaYJHT3E2+NO6KxB4Hpc4J77CYUksFOB gj+qcsKS2gtg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2020 14:35:38 -0700 IronPort-SDR: y4xadc0sFdmZtiUbZdLkblrbQ9WYPQZ6WosKZiphVX/7ztGGpCRL8DsBzLOgqMWU4VE2pokHET +WRi89OISuLg== WDCIronportException: Internal Received: from cnf006060.ad.shared (HELO jedi-01.hgst.com) ([10.86.59.56]) by uls-op-cesaip01.wdc.com with ESMTP; 14 Aug 2020 14:48:31 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Greentime Hu , Albert Ou , Andrew Morton , Anshuman Khandual , Anup Patel , Arnd Bergmann , Catalin Marinas , Greg Kroah-Hartman , linux-arch@vger.kernel.org, linux-riscv@lists.infradead.org, Lorenzo Pieralisi , Mike Rapoport , Nick Hu , Palmer Dabbelt , Paul Walmsley , "Rafael J. Wysocki" , Rob Herring , Steven Price , Will Deacon , Zong Li , Ganapatrao Kulkarni , linux-arm-kernel@lists.infradead.org Subject: [RFC/RFT PATCH 6/6] riscv: Add numa support for riscv64 platform Date: Fri, 14 Aug 2020 14:47:25 -0700 Message-Id: <20200814214725.28818-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200814214725.28818-1-atish.patra@wdc.com> References: <20200814214725.28818-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the generic numa implementation to add NUMA support for RISC-V. This is based on Greentime's patch[1] but modified to use generic NUMA implementation and few more fixes. [1] https://lkml.org/lkml/2020/1/10/233 Co-developed-by: Greentime Hu Signed-off-by: Greentime Hu Signed-off-by: Atish Patra --- arch/riscv/Kconfig | 31 ++++++++++++++++++++++++++++++- arch/riscv/include/asm/mmzone.h | 13 +++++++++++++ arch/riscv/include/asm/numa.h | 8 ++++++++ arch/riscv/include/asm/pci.h | 10 ++++++++++ arch/riscv/kernel/setup.c | 10 ++++++++-- arch/riscv/kernel/smpboot.c | 12 +++++++++++- arch/riscv/mm/init.c | 4 +++- 7 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 arch/riscv/include/asm/mmzone.h create mode 100644 arch/riscv/include/asm/numa.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7b5905529146..4bd67f94aaac 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -137,7 +137,7 @@ config PAGE_OFFSET default 0xffffffe000000000 if 64BIT && MAXPHYSMEM_128GB config ARCH_FLATMEM_ENABLE - def_bool y + def_bool !NUMA config ARCH_SPARSEMEM_ENABLE def_bool y @@ -295,6 +295,35 @@ config TUNE_GENERIC endchoice +# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + select GENERIC_ARCH_NUMA + select OF_NUMA + select ARCH_SUPPORTS_NUMA_BALANCING + help + Enable NUMA (Non-Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory of the CPU and add some more NUMA awareness to the kernel. + +config NODES_SHIFT + int "Maximum NUMA Nodes (as a power of 2)" + range 1 10 + default "2" + depends on NEED_MULTIPLE_NODES + help + Specify the maximum number of NUMA Nodes available on the target + system. Increases memory reserved to accommodate various tables. + +config USE_PERCPU_NUMA_NODE_ID + def_bool y + depends on NUMA + +config NEED_PER_CPU_EMBED_FIRST_CHUNK + def_bool y + depends on NUMA + config RISCV_ISA_C bool "Emit compressed instructions when building Linux" default y diff --git a/arch/riscv/include/asm/mmzone.h b/arch/riscv/include/asm/mmzone.h new file mode 100644 index 000000000000..fa17e01d9ab2 --- /dev/null +++ b/arch/riscv/include/asm/mmzone.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MMZONE_H +#define __ASM_MMZONE_H + +#ifdef CONFIG_NUMA + +#include + +extern struct pglist_data *node_data[]; +#define NODE_DATA(nid) (node_data[(nid)]) + +#endif /* CONFIG_NUMA */ +#endif /* __ASM_MMZONE_H */ diff --git a/arch/riscv/include/asm/numa.h b/arch/riscv/include/asm/numa.h new file mode 100644 index 000000000000..8c8cf4297cc3 --- /dev/null +++ b/arch/riscv/include/asm/numa.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_NUMA_H +#define __ASM_NUMA_H + +#include +#include + +#endif /* __ASM_NUMA_H */ diff --git a/arch/riscv/include/asm/pci.h b/arch/riscv/include/asm/pci.h index 1c473a1bd986..d6a0e59638c0 100644 --- a/arch/riscv/include/asm/pci.h +++ b/arch/riscv/include/asm/pci.h @@ -32,6 +32,16 @@ static inline int pci_proc_domain(struct pci_bus *bus) /* always show the domain in /proc */ return 1; } + +#ifdef CONFIG_NUMA +int pcibus_to_node(struct pci_bus *bus); +#ifndef cpumask_of_pcibus +#define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \ + cpu_all_mask : \ + cpumask_of_node(pcibus_to_node(bus))) +#endif +#endif /* CONFIG_NUMA */ + #endif /* CONFIG_PCI */ #endif /* _ASM_RISCV_PCI_H */ diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 32bb5a1bea05..1533ee5c6e56 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -104,13 +104,19 @@ void __init setup_arch(char **cmdline_p) static int __init topology_init(void) { - int i; + int i, ret; + + for_each_online_node(i) + register_one_node(i); for_each_possible_cpu(i) { struct cpu *cpu = &per_cpu(cpu_devices, i); cpu->hotpluggable = cpu_has_hotplug(i); - register_cpu(cpu, i); + ret = register_cpu(cpu, i); + if (unlikely(ret)) + pr_warn("Warning: %s: register_cpu %d failed (%d)\n", + __func__, i, ret); } return 0; diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 356825a57551..4e9bdb6230de 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -46,13 +47,18 @@ void __init smp_prepare_cpus(unsigned int max_cpus) { int cpuid; int ret; + unsigned int curr_cpuid; + + curr_cpuid = smp_processor_id(); + numa_store_cpu_info(curr_cpuid); + numa_add_cpu(curr_cpuid); /* This covers non-smp usecase mandated by "nosmp" option */ if (max_cpus == 0) return; for_each_possible_cpu(cpuid) { - if (cpuid == smp_processor_id()) + if (cpuid == curr_cpuid) continue; if (cpu_ops[cpuid]->cpu_prepare) { ret = cpu_ops[cpuid]->cpu_prepare(cpuid); @@ -60,6 +66,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) continue; } set_cpu_present(cpuid, true); + numa_store_cpu_info(cpuid); } } @@ -80,6 +87,7 @@ void __init setup_smp(void) if (hart == cpuid_to_hartid_map(0)) { BUG_ON(found_boot_cpu); found_boot_cpu = 1; + early_map_cpu_to_node(0, of_node_to_nid(dn)); continue; } if (cpuid >= NR_CPUS) { @@ -89,6 +97,7 @@ void __init setup_smp(void) } cpuid_to_hartid_map(cpuid) = hart; + early_map_cpu_to_node(cpuid, of_node_to_nid(dn)); cpuid++; } @@ -155,6 +164,7 @@ asmlinkage __visible void smp_callin(void) current->active_mm = mm; notify_cpu_starting(curr_cpuid); + numa_add_cpu(curr_cpuid); update_siblings_masks(curr_cpuid); set_cpu_online(curr_cpuid, 1); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b8905ae2bbe7..d1f4e94626aa 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "../kernel/head.h" @@ -190,7 +191,6 @@ void __init setup_bootmem(void) early_init_fdt_scan_reserved_mem(); memblock_allow_resize(); - memblock_dump_all(); for_each_memblock(memory, reg) { unsigned long start_pfn = memblock_region_memory_base_pfn(reg); @@ -575,9 +575,11 @@ void __init paging_init(void) void __init misc_mem_init(void) { + arch_numa_init(); sparse_init(); zone_sizes_init(); resource_init(); + memblock_dump_all(); } #ifdef CONFIG_SPARSEMEM_VMEMMAP -- 2.24.0