arm64, numa: Add numa support for arm64 platforms
Subsystems (2)
v7 cover arm64, numa: Add numa support for arm64 platforms
v7:
- managing numa memory mapping using memblock.
- Incorporated review comments of Mark Rutland.
v6:
- defined and implemented the numa dt binding using node property proximity and device node distance-map.
- renamed dt_numa to of_numa
v5:
- created base verion of numa.c which creates dummy numa without using dt on single socket platforms. Then added patches for dt support.
- Incorporated review comments from Hanjun Guo.
v4:
done changes as per Arnd review comments.
v3:
Added changes to support numa on arm64 based platforms. Tested these patches on cavium's multinode(2 node topology) platform. In this patchset, defined and implemented dt bindings for numa mapping for core and memory using device node property arm,associativity.
v2:
Defined and implemented numa map for memory, cores to node and proximity distance matrix of nodes.
v1:
Initial patchset to support numa on arm64 platforms.
Note:
1. This patchset is tested for numa with dt on
thunderx single socket and dual socket boards.
2. Numa DT booting needs the dt memory nodes, which are deleted in current efi-stub, hence to try numa with dt, you need to rebase with ard's patchset.
http://git.linaro.org/people/ard.biesheuvel/linux-arm.git/shortlog/refs/heads/arm64-uefi-early-fdt-handling
Ganapatrao Kulkarni (4):
arm64, numa: adding numa support for arm64 platforms. Documentation, dt, arm64/arm: dt bindings for numa. arm64/arm, numa, dt: adding numa dt binding implementation for arm64
platforms.
arm64, dt, thunderx: Add initial dts for Cavium Thunderx in 2 node
topology.
Documentation/devicetree/bindings/arm/numa.txt | 272 ++++++++ arch/arm64/Kconfig | 35 + arch/arm64/boot/dts/cavium/Makefile | 2 +- arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts | 83 +++ arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi | 806 ++++++++++++++++++++++++ arch/arm64/include/asm/mmzone.h | 17 + arch/arm64/include/asm/numa.h | 56 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/of_numa.c | 265 ++++++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 4 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +- arch/arm64/mm/numa.c | 392 ++++++++++++ 14 files changed, 1963 insertions(+), 5 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/numa.txt create mode 100644 arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts create mode 100644 arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/kernel/of_numa.c create mode 100644 arch/arm64/mm/numa.c
Signature · 1 line
1.8.1.4
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.
--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.c
arch/arm64/Kconfig +25 -0
@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS
@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu. +# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller 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 + source kernel/Kconfig.preempt source kernel/Kconfig.hz
arch/arm64/include/asm/mmzone.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_ + +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)]) + +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */
arch/arm64/include/asm/numa.h new file +47 -0
47 lines not on this page · raw message
arch/arm64/kernel/setup.c +4 -0
@@ -53,6 +53,7 @@#include <asm/cpufeature.h> #include <asm/cpu_ops.h> #include <asm/kasan.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/smp_plat.h>
@@ -372,6 +373,9 @@ static int __init topology_init(void) {int i; +for_each_online_node (i) +register_one_node (i); +for_each_possible_cpu (i) {struct cpu *cpu = &per_cpu (cpu_data.cpu, i); cpu->hotpluggable =1 ;
arch/arm64/kernel/smp.c +2 -0
@@ -45,6 +45,7 @@#include <asm/cputype.h> #include <asm/cpu_ops.h> #include <asm/mmu_context.h> +#include <asm/numa.h> #include <asm/pgtable.h> #include <asm/pgalloc.h> #include <asm/processor.h>
@@ -125,6 +126,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)static void smp_store_cpu_info (unsigned int cpuid) {store_cpu_topology (cpuid); +numa_store_cpu_info (cpuid); }/*
arch/arm64/mm/Makefile +1 -0
@@ -6,4 +6,5 @@ obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_ARM64_PTDUMP) += dump.o obj-$(CONFIG_KASAN) += kasan_init.o +obj-$(CONFIG_NUMA) += numa.o KASAN_SANITIZE_kasan_init.o := n
arch/arm64/mm/init.c +26 -4
@@ -37,6 +37,7 @@#include <asm/fixmap.h> #include <asm/memory.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h>
@@ -77,6 +78,19 @@ static phys_addr_t max_zone_dma_phys(void)return min (offset + (1ULL <<32 ),memblock_end_of_DRAM ()); } +#ifdef CONFIG_NUMA +static void __init zone_sizes_init (unsigned long min,unsigned long max) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; + +if (IS_ENABLED (CONFIG_ZONE_DMA )) + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); + max_zone_pfns[ZONE_NORMAL ] = max; + +free_area_init_nodes (max_zone_pfns); +} + +#else static void __init zone_sizes_init (unsigned long min,unsigned long max) {struct memblock_region *reg;
@@ -116,6 +130,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) free_area_init_node(0, zone_size, min, zhole_size); } +#endif /* CONFIG_NUMA */ #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid (unsigned long pfn)
@@ -133,10 +148,15 @@ static void arm64_memory_present(void)static void arm64_memory_present (void ) {struct memblock_region *reg; +int nid =0 ; -for_each_memblock (memory, reg) -memory_present (0 ,memblock_region_memory_base_pfn (reg), -memblock_region_memory_end_pfn (reg)); +for_each_memblock (memory, reg) { +#ifdef CONFIG_NUMA + nid = reg->nid; +#endif +memory_present (nid,memblock_region_memory_base_pfn (reg), +memblock_region_memory_end_pfn (reg)); + } }#endif
@@ -193,6 +213,9 @@ void __init bootmem_init(void)early_memtest (min <<PAGE_SHIFT , max <<PAGE_SHIFT ); + max_pfn = max_low_pfn = max; + +arm64_numa_init ();/* * Sparsemem tries to allocate bootmem in memory_present(), so must be * done after the fixed reservations.
@@ -203,7 +226,6 @@ void __init bootmem_init(void)zone_sizes_init (min, max); high_memory =__va ((max <<PAGE_SHIFT ) -1 ) +1 ; - max_pfn = max_low_pfn = max; }#ifndef CONFIG_SPARSEMEM_VMEMMAP
arch/arm64/mm/numa.c new file +384 -0
384 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Quoted 7 lines · Ganapatrao Kulkarni
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>
I've tested this patch on QEMU VM.
Quoted 653 lines
--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +25
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu. +# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller 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 + source kernel/Kconfig.preempt source kernel/Kconfig.hzarch/arm64/include/asm/mmzone.h new file +17
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_ + +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)]) + +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +47
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_H + +#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) +#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT)) + +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0 + +extern int cpu_to_node_map[NR_CPUS ]; +extern nodemask_t numa_nodes_parsed__initdata ; + +/* Mappings between node number and cpus on that node. */ +extern cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +extern void numa_clear_node (unsigned int cpu); +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +extern const struct cpumask *cpumask_of_node (int node); +#else +/* Returns a pointer to the cpumask of CPUs on Node 'node'. */ +static inline const struct cpumask *cpumask_of_node (int node) +{ +return node_to_cpumask_map[node]; +} +#endif + +void __init arm64_numa_init (void ); +int __init numa_add_memblk (int nodeid,u64 start,u64 end); +void __init numa_set_distance (int from,int to,int distance); +void __init numa_reset_distance (void ); +void numa_store_cpu_info (unsigned int cpu); +#else /* CONFIG_NUMA */ +static inline void numa_store_cpu_info (unsigned int cpu) { } +static inline void arm64_numa_init (void ) { } +#endif /* CONFIG_NUMA */ +#endif /* _ASM_NUMA_H */ arch/arm64/kernel/setup.c +4
-0@@ -53,6 +53,7 @@#include <asm/cpufeature.h> #include <asm/cpu_ops.h> #include <asm/kasan.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/smp_plat.h> @@ -372,6 +373,9 @@ static int __init topology_init(void) {int i; +for_each_online_node (i) +register_one_node (i); +for_each_possible_cpu (i) {struct cpu *cpu = &per_cpu (cpu_data.cpu, i); cpu->hotpluggable =1 ;arch/arm64/kernel/smp.c +2
-0@@ -45,6 +45,7 @@#include <asm/cputype.h> #include <asm/cpu_ops.h> #include <asm/mmu_context.h> +#include <asm/numa.h> #include <asm/pgtable.h> #include <asm/pgalloc.h> #include <asm/processor.h> @@ -125,6 +126,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)static void smp_store_cpu_info (unsigned int cpuid) {store_cpu_topology (cpuid); +numa_store_cpu_info (cpuid); }/* arch/arm64/mm/Makefile +1
-0@@ -6,4 +6,5 @@ obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_ARM64_PTDUMP) += dump.o obj-$(CONFIG_KASAN) += kasan_init.o +obj-$(CONFIG_NUMA) += numa.o KASAN_SANITIZE_kasan_init.o := narch/arm64/mm/init.c +26
-4@@ -37,6 +37,7 @@#include <asm/fixmap.h> #include <asm/memory.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> @@ -77,6 +78,19 @@ static phys_addr_t max_zone_dma_phys(void)return min (offset + (1ULL <<32 ),memblock_end_of_DRAM ()); } +#ifdef CONFIG_NUMA +static void __init zone_sizes_init (unsigned long min,unsigned long max) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; + +if (IS_ENABLED (CONFIG_ZONE_DMA )) + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); + max_zone_pfns[ZONE_NORMAL ] = max; + +free_area_init_nodes (max_zone_pfns); +} + +#else static void __init zone_sizes_init (unsigned long min,unsigned long max) {struct memblock_region *reg;@@ -116,6 +130,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) free_area_init_node(0, zone_size, min, zhole_size); } +#endif /* CONFIG_NUMA */ #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid (unsigned long pfn)@@ -133,10 +148,15 @@ static void arm64_memory_present(void)static void arm64_memory_present (void ) {struct memblock_region *reg; +int nid =0 ; -for_each_memblock (memory, reg) -memory_present (0 ,memblock_region_memory_base_pfn (reg), -memblock_region_memory_end_pfn (reg)); +for_each_memblock (memory, reg) { +#ifdef CONFIG_NUMA + nid = reg->nid; +#endif +memory_present (nid,memblock_region_memory_base_pfn (reg), +memblock_region_memory_end_pfn (reg)); + } }#endif @@ -193,6 +213,9 @@ void __init bootmem_init(void)early_memtest (min <<PAGE_SHIFT , max <<PAGE_SHIFT ); + max_pfn = max_low_pfn = max; + +arm64_numa_init ();/* * Sparsemem tries to allocate bootmem in memory_present(), so must be * done after the fixed reservations. @@ -203,7 +226,6 @@ void __init bootmem_init(void)zone_sizes_init (min, max); high_memory =__va ((max <<PAGE_SHIFT ) -1 ) +1 ; - max_pfn = max_low_pfn = max; }#ifndef CONFIG_SPARSEMEM_VMEMMAP arch/arm64/mm/numa.c new file +384
-0@@ -0,0 +1,384 @@ +/* +* NUMA support, based on the x86 implementation. +* +* Copyright (C) 2015 Cavium Inc. +* Author: Ganapatrao Kulkarni <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/bootmem.h> +#include <linux/ctype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/module.h> +#include <linux/mmzone.h> +#include <linux/nodemask.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/topology.h> + +#include <asm/smp_plat.h> + +struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; +EXPORT_SYMBOL (node_data); +nodemask_t numa_nodes_parsed__initdata ; +int cpu_to_node_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE }; + +static int numa_off; +static int numa_distance_cnt; +static u8 *numa_distance; + +static __init int numa_parse_early_param (char *opt) +{ +if (!opt) +return -EINVAL ; +if (!strncmp (opt,"off" ,3 )) { +pr_info ("%s\n" ,"NUMA turned off" ); + numa_off =1 ; + } +return 0 ; +} +early_param ("numa" , numa_parse_early_param); + +cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_to_cpumask_map); + +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance; +} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{ +if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance); + +static int __init numa_register_nodes (void ) +{ +int nid; +struct memblock_region *mblk; + +/* Check that valid nid is set to memblks */ +for_each_memblock (memory, mblk) +if (mblk->nid ==NUMA_NO_NODE || mblk->nid >=MAX_NUMNODES ) +return -EINVAL ; + +/* Finally register nodes. */ +for_each_node_mask (nid, numa_nodes_parsed) { +unsigned long start_pfn, end_pfn; + +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); +setup_node_data (nid, start_pfn, end_pfn); +node_set_online (nid); + } + +/* Setup online nodes to actual nodes*/ + node_possible_map = numa_nodes_parsed; + +/* Dump memblock with node info and return. */ +memblock_dump_all (); +return 0 ; +} + +static int __init numa_init (int (*init_func)(void )) +{ +int ret; + +nodes_clear (numa_nodes_parsed); +nodes_clear (node_possible_map); +nodes_clear (node_online_map); +numa_reset_distance (); + + ret =init_func (); +if (ret <0 ) +return ret; + +if (nodes_empty (numa_nodes_parsed)) +return -EINVAL ; + + ret =numa_register_nodes (); +if (ret <0 ) +return ret; + + ret =numa_alloc_distance (); +if (ret <0 ) +return ret; + +setup_node_to_cpumask_map (); + +/* init boot processor */ + cpu_to_node_map[0 ] =0 ; +map_cpu_to_node (0 ,0 ); + +return 0 ; +} + +/** +* dummy_numa_init - Fallback dummy NUMA init +* +* Used if there's no underlying NUMA architecture, NUMA initialization +* fails, or NUMA is disabled on the command line. +* +* Must online at least one node and add memory blocks that cover all +* allowed memory. This function must not fail. +*/ +static int __init dummy_numa_init (void ) +{ +struct memblock_region *mblk; + +pr_info ("%s\n" ,"No NUMA configuration found" ); +pr_info ("Faking a node at [mem %#018Lx-%#018Lx]\n" , +0LLU ,PFN_PHYS (max_pfn) -1 ); +for_each_memblock (memory, mblk) +numa_add_memblk (0 , mblk->base, mblk->size); + numa_off =1 ; + +return 0 ; +} + +/** +* arm64_numa_init - Initialize NUMA +* +* Try each configured NUMA initialization method until one succeeds. The +* last fallback is dummy single node config encomapssing whole memory and +* never fails. +*/ +void __init arm64_numa_init (void ) +{ +numa_init (dummy_numa_init); +}
Signature · 1 line
Shannon
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Quoted 8 lines · Shannon Zhao
Quoted 5 lines · Ganapatrao Kulkarni
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.
Quoted 6 lines
Quoted 2 lines
Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>I've tested this patch on QEMU VM.
Tested-by Shannon Zhao <[email protected]>
thanks a lot!
Quoted 657 lines
Quoted 643 lines
--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +25
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu. +# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller 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 + source kernel/Kconfig.preempt source kernel/Kconfig.hzarch/arm64/include/asm/mmzone.h new file +17
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_ + +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)]) + +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +47
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_H + +#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) +#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT)) + +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0 + +extern int cpu_to_node_map[NR_CPUS ]; +extern nodemask_t numa_nodes_parsed__initdata ; + +/* Mappings between node number and cpus on that node. */ +extern cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +extern void numa_clear_node (unsigned int cpu); +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +extern const struct cpumask *cpumask_of_node (int node); +#else +/* Returns a pointer to the cpumask of CPUs on Node 'node'. */ +static inline const struct cpumask *cpumask_of_node (int node) +{ +return node_to_cpumask_map[node]; +} +#endif + +void __init arm64_numa_init (void ); +int __init numa_add_memblk (int nodeid,u64 start,u64 end); +void __init numa_set_distance (int from,int to,int distance); +void __init numa_reset_distance (void ); +void numa_store_cpu_info (unsigned int cpu); +#else /* CONFIG_NUMA */ +static inline void numa_store_cpu_info (unsigned int cpu) { } +static inline void arm64_numa_init (void ) { } +#endif /* CONFIG_NUMA */ +#endif /* _ASM_NUMA_H */ arch/arm64/kernel/setup.c +4
-0@@ -53,6 +53,7 @@#include <asm/cpufeature.h> #include <asm/cpu_ops.h> #include <asm/kasan.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/smp_plat.h> @@ -372,6 +373,9 @@ static int __init topology_init(void) {int i; +for_each_online_node (i) +register_one_node (i); +for_each_possible_cpu (i) {struct cpu *cpu = &per_cpu (cpu_data.cpu, i); cpu->hotpluggable =1 ;arch/arm64/kernel/smp.c +2
-0@@ -45,6 +45,7 @@#include <asm/cputype.h> #include <asm/cpu_ops.h> #include <asm/mmu_context.h> +#include <asm/numa.h> #include <asm/pgtable.h> #include <asm/pgalloc.h> #include <asm/processor.h> @@ -125,6 +126,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)static void smp_store_cpu_info (unsigned int cpuid) {store_cpu_topology (cpuid); +numa_store_cpu_info (cpuid); }/* arch/arm64/mm/Makefile +1
-0@@ -6,4 +6,5 @@ obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_ARM64_PTDUMP) += dump.o obj-$(CONFIG_KASAN) += kasan_init.o +obj-$(CONFIG_NUMA) += numa.o KASAN_SANITIZE_kasan_init.o := narch/arm64/mm/init.c +26
-4@@ -37,6 +37,7 @@#include <asm/fixmap.h> #include <asm/memory.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> @@ -77,6 +78,19 @@ static phys_addr_t max_zone_dma_phys(void)return min (offset + (1ULL <<32 ),memblock_end_of_DRAM ()); } +#ifdef CONFIG_NUMA +static void __init zone_sizes_init (unsigned long min,unsigned long max) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; + +if (IS_ENABLED (CONFIG_ZONE_DMA )) + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); + max_zone_pfns[ZONE_NORMAL ] = max; + +free_area_init_nodes (max_zone_pfns); +} + +#else static void __init zone_sizes_init (unsigned long min,unsigned long max) {struct memblock_region *reg;@@ -116,6 +130,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) free_area_init_node(0, zone_size, min, zhole_size); } +#endif /* CONFIG_NUMA */ #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid (unsigned long pfn)@@ -133,10 +148,15 @@ static void arm64_memory_present(void)static void arm64_memory_present (void ) {struct memblock_region *reg; +int nid =0 ; -for_each_memblock (memory, reg) -memory_present (0 ,memblock_region_memory_base_pfn (reg), -memblock_region_memory_end_pfn (reg)); +for_each_memblock (memory, reg) { +#ifdef CONFIG_NUMA + nid = reg->nid; +#endif +memory_present (nid,memblock_region_memory_base_pfn (reg), +memblock_region_memory_end_pfn (reg)); + } }#endif @@ -193,6 +213,9 @@ void __init bootmem_init(void)early_memtest (min <<PAGE_SHIFT , max <<PAGE_SHIFT ); + max_pfn = max_low_pfn = max; + +arm64_numa_init ();/* * Sparsemem tries to allocate bootmem in memory_present(), so must be * done after the fixed reservations. @@ -203,7 +226,6 @@ void __init bootmem_init(void)zone_sizes_init (min, max); high_memory =__va ((max <<PAGE_SHIFT ) -1 ) +1 ; - max_pfn = max_low_pfn = max; }#ifndef CONFIG_SPARSEMEM_VMEMMAP arch/arm64/mm/numa.c new file +374
-0@@ -0,0 +1,384 @@ +/* +* NUMA support, based on the x86 implementation. +* +* Copyright (C) 2015 Cavium Inc. +* Author: Ganapatrao Kulkarni <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/bootmem.h> +#include <linux/ctype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/module.h> +#include <linux/mmzone.h> +#include <linux/nodemask.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/topology.h> + +#include <asm/smp_plat.h> + +struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; +EXPORT_SYMBOL (node_data); +nodemask_t numa_nodes_parsed__initdata ; +int cpu_to_node_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE }; + +static int numa_off; +static int numa_distance_cnt; +static u8 *numa_distance; + +static __init int numa_parse_early_param (char *opt) +{ +if (!opt) +return -EINVAL ; +if (!strncmp (opt,"off" ,3 )) { +pr_info ("%s\n" ,"NUMA turned off" ); + numa_off =1 ; + } +return 0 ; +} +early_param ("numa" , numa_parse_early_param); + +cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_to_cpumask_map); + +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance; +} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{ +if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance); + +static int __init numa_register_nodes (void ) +{ +int nid; +struct memblock_region *mblk; + +/* Check that valid nid is set to memblks */ +for_each_memblock (memory, mblk) +if (mblk->nid ==NUMA_NO_NODE || mblk->nid >=MAX_NUMNODES ) +return -EINVAL ; + +/* Finally register nodes. */ +for_each_node_mask (nid, numa_nodes_parsed) { +unsigned long start_pfn, end_pfn; + +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); +setup_node_data (nid, start_pfn, end_pfn); +node_set_online (nid); + } + +/* Setup online nodes to actual nodes*/ + node_possible_map = numa_nodes_parsed; + +/* Dump memblock with node info and return. */ +memblock_dump_all (); +return 0 ; +} + +static int __init numa_init (int (*init_func)(void )) +{ +int ret; + +nodes_clear (numa_nodes_parsed); +nodes_clear (node_possible_map); +nodes_clear (node_online_map); +numa_reset_distance (); + + ret =init_func (); +if (ret <0 ) +return ret; + +if (nodes_empty (numa_nodes_parsed)) +return -EINVAL ; + + ret =numa_register_nodes (); +if (ret <0 ) +return ret; + + ret =numa_alloc_distance (); +if (ret <0 ) +return ret; + +setup_node_to_cpumask_map (); + +/* init boot processor */ + cpu_to_node_map[0 ] =0 ; +map_cpu_to_node (0 ,0 ); + +return 0 ; +} + +/** +* dummy_numa_init - Fallback dummy NUMA init +* +* Used if there's no underlying NUMA architecture, NUMA initialization +* fails, or NUMA is disabled on the command line. +* +* Must online at least one node and add memory blocks that cover all +* allowed memory. This function must not fail. +*/ +static int __init dummy_numa_init (void ) +{ +struct memblock_region *mblk; + +pr_info ("%s\n" ,"No NUMA configuration found" ); +pr_info ("Faking a node at [mem %#018Lx-%#018Lx]\n" , +0LLU ,PFN_PHYS (max_pfn) -1 ); +for_each_memblock (memory, mblk) +numa_add_memblk (0 , mblk->base, mblk->size); + numa_off =1 ; + +return 0 ; +} + +/** arch/arm64/mm/numa.c line 384
Quoted 10 lines
arch/arm64/mm/numa.c new file +10
-0+* arm64_numa_init - Initialize NUMA +* +* Try each configured NUMA initialization method until one succeeds. The +* last fallback is dummy single node config encomapssing whole memory and +* never fails. +*/ +void __init arm64_numa_init (void ) +{ +numa_init (dummy_numa_init); +}--
Shannon
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
In reply to Ganapatrao KulkarniHello,
This all looks pretty reasonable, but I'd like to see an Ack from a devicetree maintainer on the binding before I merge anything (and I see that there are outstanding comments from Rutland on that).
Quoted 37 lines · Ganapatrao Kulkarni
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +1
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu.
arch/arm64/Kconfig config HOTPLUG_CPU · line 495
Quoted 10 lines
arch/arm64/Kconfig +10
-0+# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller of the CPU and add some more + NUMA awareness to the kernel.
I appreciate that this is copied from x86, but what exactly do you mean by "memory controller" here?
arch/arm64/include/asm/mmzone.h line 2
Quoted 8 lines
arch/arm64/include/asm/mmzone.h new file +2
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_
Please try to follow the standard naming for header guards under arm64 (yes, it's not perfect, but we've made some effort for consistency).
arch/arm64/include/asm/mmzone.h line 14
Quoted 12 lines
arch/arm64/include/asm/mmzone.h new file +12
-0+ +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)])
This is the same as m32r, metag, parisc, powerpc, s390, sh, sparc, tile and x86. Can we make this the default in the core code instead and then replace this header file with asm-generic or something?
arch/arm64/include/asm/numa.h line 2
Quoted 11 lines
arch/arm64/include/asm/mmzone.h new file +3
-0+ +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +2
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_H
Same comment on the guards.
arch/arm64/include/asm/numa.h line 9
Quoted 6 lines
arch/arm64/include/asm/numa.h new file +6
-0+#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)
This is only used by the ACPI code afaict, so maybe include it when you add that?
arch/arm64/include/asm/numa.h line 10
Quoted 1 line
arch/arm64/include/asm/numa.h new file +1
-0+#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT))
Where is this used?
arch/arm64/include/asm/numa.h line 20
Quoted 10 lines
arch/arm64/include/asm/numa.h new file +10
-0+ +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0
There's a bunch of these dummy definitions already available in asm-generic/topology.h. Can we use those instead of rolling our own please?
Quoted 17 lines
arch/arm64/mm/init.c +2
-0@@ -37,6 +37,7 @@#include <asm/fixmap.h> #include <asm/memory.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> @@ -77,6 +78,19 @@ static phys_addr_t max_zone_dma_phys(void)return min (offset + (1ULL <<32 ),memblock_end_of_DRAM ()); } +#ifdef CONFIG_NUMA
arch/arm64/mm/init.c static phys_addr_t max_zone_dma_phys(void) · line 91
Quoted 10 lines
arch/arm64/mm/init.c +10
-0+static void __init zone_sizes_init (unsigned long min,unsigned long max) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; + +if (IS_ENABLED (CONFIG_ZONE_DMA )) + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); + max_zone_pfns[ZONE_NORMAL ] = max; + +free_area_init_nodes (max_zone_pfns); +}
This is certainly more readable then the non-numa zone_sizes_init. Is there a reason we can't always select HAVE_MEMBLOCK_NODE_MAP and avoid having to handle the zone holds explicitly?
Also, I couldn't find any calls to memblock_add_node, which seem to be expected. What am I missing?
Quoted 46 lines
arch/arm64/mm/numa.c new file +40
-0@@ -0,0 +1,384 @@ +/* +* NUMA support, based on the x86 implementation. +* +* Copyright (C) 2015 Cavium Inc. +* Author: Ganapatrao Kulkarni <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/bootmem.h> +#include <linux/ctype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/module.h> +#include <linux/mmzone.h> +#include <linux/nodemask.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/topology.h> + +#include <asm/smp_plat.h> + +struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; +EXPORT_SYMBOL (node_data); +nodemask_t numa_nodes_parsed__initdata ; +int cpu_to_node_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE }; + +static int numa_off;
arch/arm64/mm/numa.c line 50
Quoted 10 lines
arch/arm64/mm/numa.c new file +10
-0+static int numa_distance_cnt; +static u8 *numa_distance; + +static __init int numa_parse_early_param (char *opt) +{ +if (!opt) +return -EINVAL ; +if (!strncmp (opt,"off" ,3 )) { +pr_info ("%s\n" ,"NUMA turned off" ); + numa_off =1 ;
There's a patch kicking around to add this to strtobool:
https://lkml.org/lkml/2015/12/9/802
but I can't see it in next :(
Quoted 229 lines
arch/arm64/mm/numa.c new file +229
-0+ } +return 0 ; +} +early_param ("numa" , numa_parse_early_param); + +cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_to_cpumask_map); + +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance;
arch/arm64/mm/numa.c line 289
Quoted 10 lines
arch/arm64/mm/numa.c new file +10
-0+} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{ +if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance);
Much of this is simply a direct copy/paste from x86. Why can't it be moved to common code? I don't see anything arch-specific here.
Quoted 14 lines
arch/arm64/mm/numa.c new file +14
-0+static int __init numa_register_nodes (void ) +{ +int nid; +struct memblock_region *mblk; + +/* Check that valid nid is set to memblks */ +for_each_memblock (memory, mblk) +if (mblk->nid ==NUMA_NO_NODE || mblk->nid >=MAX_NUMNODES ) +return -EINVAL ; + +/* Finally register nodes. */ +for_each_node_mask (nid, numa_nodes_parsed) { +unsigned long start_pfn, end_pfn; +
arch/arm64/mm/numa.c line 314
Quoted 10 lines
arch/arm64/mm/numa.c new file +10
-0+get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); +setup_node_data (nid, start_pfn, end_pfn); +node_set_online (nid); + } + +/* Setup online nodes to actual nodes*/ + node_possible_map = numa_nodes_parsed; + +/* Dump memblock with node info and return. */ +memblock_dump_all ();
We already call this from arm64_memblock_init. If that's now too early to be of any use, we should move it to after bootmem_init, but we should probably avoid calling it twice.
Quoted 34 lines
arch/arm64/mm/numa.c new file +34
-0+return 0 ; +} + +static int __init numa_init (int (*init_func)(void )) +{ +int ret; + +nodes_clear (numa_nodes_parsed); +nodes_clear (node_possible_map); +nodes_clear (node_online_map); +numa_reset_distance (); + + ret =init_func (); +if (ret <0 ) +return ret; + +if (nodes_empty (numa_nodes_parsed)) +return -EINVAL ; + + ret =numa_register_nodes (); +if (ret <0 ) +return ret; + + ret =numa_alloc_distance (); +if (ret <0 ) +return ret; + +setup_node_to_cpumask_map (); + +/* init boot processor */ + cpu_to_node_map[0 ] =0 ; +map_cpu_to_node (0 ,0 ); + +return 0 ;
arch/arm64/mm/numa.c line 358
Quoted 10 lines
arch/arm64/mm/numa.c new file +10
-0+} + +/** +* dummy_numa_init - Fallback dummy NUMA init +* +* Used if there's no underlying NUMA architecture, NUMA initialization +* fails, or NUMA is disabled on the command line. +* +* Must online at least one node and add memory blocks that cover all +* allowed memory. This function must not fail.
Why can't it fail? It looks like the return value is ignored by numa_init.
Will
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Thanks Will for the review.
Quoted 5 lines · Will Deacon
Hello,
This all looks pretty reasonable, but I'd like to see an Ack from a devicetree maintainer on the binding before I merge anything (and I see that there are outstanding comments from Rutland on that).
IIUC, there are no open comments for the binding. Mark Rutland: please let me know, if there any open comments. otherwise, can you please Ack the binding.
Quoted 39 lines · Ganapatrao Kulkarni
Quoted 37 lines
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +1
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu.
Quoted 13 lines
arch/arm64/Kconfig config HOTPLUG_CPU · line 495
Quoted 10 lines
arch/arm64/Kconfig +10
-0+# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller of the CPU and add some more + NUMA awareness to the kernel.I appreciate that this is copied from x86, but what exactly do you mean by "memory controller" here?
ok, it is fair enough to say local memory.
Quoted 12 lines
arch/arm64/include/asm/mmzone.h line 2
Quoted 9 lines
arch/arm64/include/asm/mmzone.h new file +2
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_Please try to follow the standard naming for header guards under arm64 (yes, it's not perfect, but we've made some effort for consistency).
sure, will follow as in other code.
Quoted 17 lines
arch/arm64/include/asm/mmzone.h line 14
Quoted 13 lines
arch/arm64/include/asm/mmzone.h new file +12
-0+ +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)])This is the same as m32r, metag, parisc, powerpc, s390, sh, sparc, tile and x86. Can we make this the default in the core code instead and then replace this header file with asm-generic or something?
IIUC, it is same in most but not in all arch.
Quoted 14 lines
arch/arm64/include/asm/numa.h line 2
Quoted 12 lines
arch/arm64/include/asm/mmzone.h new file +3
-0+ +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +2
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_HSame comment on the guards.
ok
Quoted 10 lines
arch/arm64/include/asm/numa.h line 9
Quoted 7 lines
arch/arm64/include/asm/numa.h new file +6
-0+#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)This is only used by the ACPI code afaict, so maybe include it when you add that?
ok
Quoted 4 lines
arch/arm64/include/asm/numa.h line 10
Quoted 2 lines
arch/arm64/include/asm/numa.h new file +1
-0+#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT))Where is this used?
sorry, was used in v6, missed to delete.
Quoted 32 lines
arch/arm64/include/asm/numa.h line 20
Quoted 11 lines
arch/arm64/include/asm/numa.h new file +10
-0+ +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0There's a bunch of these dummy definitions already available in
asm-generic/topology.h. Can we use those instead of rolling our own please?Quoted 16 lines
arch/arm64/mm/init.c +1
-0@@ -37,6 +37,7 @@#include <asm/fixmap.h> #include <asm/memory.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> @@ -77,6 +78,19 @@ static phys_addr_t max_zone_dma_phys(void)return min (offset + (1ULL <<32 ),memblock_end_of_DRAM ()); }
Quoted 15 lines
arch/arm64/mm/init.c static phys_addr_t max_zone_dma_phys(void) · line 91
Quoted 11 lines
arch/arm64/mm/init.c +11
-0+#ifdef CONFIG_NUMA +static void __init zone_sizes_init (unsigned long min,unsigned long max) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; + +if (IS_ENABLED (CONFIG_ZONE_DMA )) + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); + max_zone_pfns[ZONE_NORMAL ] = max; + +free_area_init_nodes (max_zone_pfns); +}This is certainly more readable then the non-numa
zone_sizes_init. Is there a reason we can't always selectHAVE_MEMBLOCK_NODE_MAPand avoid having to handle the zone holds explicitly?
yes, i can think off to have select HAVE_MEMBLOCK_NODE_MAP always instead of for only numa.
i can experiment to have the zone_sizes_init of numa to non-numa case also and delete the current zone_sizes_init.
Quoted 3 lines
Also, I couldn't find any calls to
memblock_add_node, which seem to be expected. What am I missing?
memblks are added much before numa in dt or acpi parsing. memblock_set_node is used to set the node.
Quoted 51 lines
Quoted 51 lines
arch/arm64/mm/numa.c new file +44
-0@@ -0,0 +1,384 @@ +/* +* NUMA support, based on the x86 implementation. +* +* Copyright (C) 2015 Cavium Inc. +* Author: Ganapatrao Kulkarni <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/bootmem.h> +#include <linux/ctype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/module.h> +#include <linux/mmzone.h> +#include <linux/nodemask.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/topology.h> + +#include <asm/smp_plat.h> + +struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; +EXPORT_SYMBOL (node_data); +nodemask_t numa_nodes_parsed__initdata ; +int cpu_to_node_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE }; + +static int numa_off; +static int numa_distance_cnt; +static u8 *numa_distance; + +static __init int numa_parse_early_param (char *opt)
Quoted 8 lines
arch/arm64/mm/numa.c line 50
Quoted 6 lines
arch/arm64/mm/numa.c new file +6
-0+{ +if (!opt) +return -EINVAL ; +if (!strncmp (opt,"off" ,3 )) { +pr_info ("%s\n" ,"NUMA turned off" ); + numa_off =1 ;There's a patch kicking around to add this to strtobool:
will change once it is in upstream. dont want to have dependency for this.
Quoted 239 lines
https://lkml.org/lkml/2015/12/9/802
but I can't see it in next :(
Quoted 234 lines
arch/arm64/mm/numa.c new file +234
-0+ } +return 0 ; +} +early_param ("numa" , numa_parse_early_param); + +cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_to_cpumask_map); + +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance; +} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{
Quoted 8 lines
arch/arm64/mm/numa.c line 289
Quoted 5 lines
arch/arm64/mm/numa.c new file +5
-0+if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance);Much of this is simply a direct copy/paste from x86. Why can't it be moved to common code? I don't see anything arch-specific here.
not same for all arch.
Quoted 21 lines
Quoted 21 lines
arch/arm64/mm/numa.c new file +20
-0+static int __init numa_register_nodes (void ) +{ +int nid; +struct memblock_region *mblk; + +/* Check that valid nid is set to memblks */ +for_each_memblock (memory, mblk) +if (mblk->nid ==NUMA_NO_NODE || mblk->nid >=MAX_NUMNODES ) +return -EINVAL ; + +/* Finally register nodes. */ +for_each_node_mask (nid, numa_nodes_parsed) { +unsigned long start_pfn, end_pfn; + +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); +setup_node_data (nid, start_pfn, end_pfn); +node_set_online (nid); + } + +/* Setup online nodes to actual nodes*/
Quoted 8 lines
arch/arm64/mm/numa.c line 314
Quoted 4 lines
arch/arm64/mm/numa.c new file +4
-0+ node_possible_map = numa_nodes_parsed; + +/* Dump memblock with node info and return. */ +memblock_dump_all ();We already call this from
arm64_memblock_init. If that's now too early to be of any use, we should move it to afterbootmem_init, but we should probably avoid calling it twice.
sure, will do changes to have called once.
Quoted 39 lines
Quoted 39 lines
arch/arm64/mm/numa.c new file +38
-0+return 0 ; +} + +static int __init numa_init (int (*init_func)(void )) +{ +int ret; + +nodes_clear (numa_nodes_parsed); +nodes_clear (node_possible_map); +nodes_clear (node_online_map); +numa_reset_distance (); + + ret =init_func (); +if (ret <0 ) +return ret; + +if (nodes_empty (numa_nodes_parsed)) +return -EINVAL ; + + ret =numa_register_nodes (); +if (ret <0 ) +return ret; + + ret =numa_alloc_distance (); +if (ret <0 ) +return ret; + +setup_node_to_cpumask_map (); + +/* init boot processor */ + cpu_to_node_map[0 ] =0 ; +map_cpu_to_node (0 ,0 ); + +return 0 ; +} + +/** +* dummy_numa_init - Fallback dummy NUMA init
Quoted 8 lines
arch/arm64/mm/numa.c line 358
Quoted 6 lines
arch/arm64/mm/numa.c new file +6
-0+* +* Used if there's no underlying NUMA architecture, NUMA initialization +* fails, or NUMA is disabled on the command line. +* +* Must online at least one node and add memory blocks that cover all +* allowed memory. This function must not fail. Why can't it fail? It looks like the return value is ignored by
numa_init.
this function adds all memblocks to node 0. which is unlikely that it will fail.
Quoted 2 lines
Will
thanks
Ganapat
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Hi Will,
Quoted 120 lines · Ganapatrao Kulkarni
Thanks Will for the review.
Quoted 5 lines · Will Deacon
Hello,
This all looks pretty reasonable, but I'd like to see an Ack from a devicetree maintainer on the binding before I merge anything (and I see that there are outstanding comments from Rutland on that).
IIUC, there are no open comments for the binding. Mark Rutland: please let me know, if there any open comments. otherwise, can you please Ack the binding.
Quoted 39 lines · Ganapatrao Kulkarni
Quoted 37 lines
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +1
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu.Quoted 13 lines
arch/arm64/Kconfig config HOTPLUG_CPU · line 495
Quoted 10 lines
arch/arm64/Kconfig +10
-0+# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller of the CPU and add some more + NUMA awareness to the kernel.I appreciate that this is copied from x86, but what exactly do you mean by "memory controller" here?
ok, it is fair enough to say local memory.
Quoted 12 lines
arch/arm64/include/asm/mmzone.h line 2
Quoted 9 lines
arch/arm64/include/asm/mmzone.h new file +2
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_Please try to follow the standard naming for header guards under arm64 (yes, it's not perfect, but we've made some effort for consistency).
sure, will follow as in other code.
Quoted 17 lines
arch/arm64/include/asm/mmzone.h line 14
Quoted 13 lines
arch/arm64/include/asm/mmzone.h new file +12
-0+ +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)])This is the same as m32r, metag, parisc, powerpc, s390, sh, sparc, tile and x86. Can we make this the default in the core code instead and then replace this header file with asm-generic or something?
IIUC, it is same in most but not in all arch.
Quoted 14 lines
arch/arm64/include/asm/numa.h line 2
Quoted 12 lines
arch/arm64/include/asm/mmzone.h new file +3
-0+ +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +2
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_HSame comment on the guards.
ok
Quoted 10 lines
arch/arm64/include/asm/numa.h line 9
Quoted 7 lines
arch/arm64/include/asm/numa.h new file +6
-0+#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)This is only used by the ACPI code afaict, so maybe include it when you add that?
Quoted 21 lines
ok
Quoted 4 lines
arch/arm64/include/asm/numa.h line 10
Quoted 2 lines
arch/arm64/include/asm/numa.h new file +1
-0+#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT))Where is this used?
sorry, was used in v6, missed to delete.
Quoted 15 lines
arch/arm64/include/asm/numa.h line 20
Quoted 11 lines
arch/arm64/include/asm/numa.h new file +10
-0+ +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0There's a bunch of these dummy definitions already available in
asm-generic/topology.h. Can we use those instead of rolling our own please?
these are dummy in this patch, and i will post separate patch for numa-pci.
Quoted 32 lines
Quoted 17 lines
Quoted 17 lines
arch/arm64/mm/init.c +1
-0@@ -37,6 +37,7 @@#include <asm/fixmap.h> #include <asm/memory.h> +#include <asm/numa.h> #include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> @@ -77,6 +78,19 @@ static phys_addr_t max_zone_dma_phys(void)return min (offset + (1ULL <<32 ),memblock_end_of_DRAM ()); }Quoted 15 lines
arch/arm64/mm/init.c static phys_addr_t max_zone_dma_phys(void) · line 91
Quoted 11 lines
arch/arm64/mm/init.c +11
-0+#ifdef CONFIG_NUMA +static void __init zone_sizes_init (unsigned long min,unsigned long max) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; + +if (IS_ENABLED (CONFIG_ZONE_DMA )) + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); + max_zone_pfns[ZONE_NORMAL ] = max; + +free_area_init_nodes (max_zone_pfns); +}This is certainly more readable then the non-numa
zone_sizes_init. Is there a reason we can't always selectHAVE_MEMBLOCK_NODE_MAPand avoid having to handle the zone holds explicitly?
Quoted 4 lines
yes, i can think off to have select
HAVE_MEMBLOCK_NODE_MAPalways instead of for only numa.
i can experiment to have thezone_sizes_initof numa to non-numa case also and delete the currentzone_sizes_init.
if i enable HAVE_MEMBLOCK_NODE_MAP for non-numa case, i see issues in sparse_init and could be some dependency due to explicit call of memory_present(note sure) in non-numa.
IMO, this needs to be worked out as a separate patch.
Quoted 391 lines
Quoted 4 lines
Also, I couldn't find any calls to
memblock_add_node, which seem to be expected. What am I missing?memblks are added much before numa in dt or acpi parsing.
memblock_set_nodeis used to set the node.Quoted 51 lines
Quoted 51 lines
arch/arm64/mm/numa.c new file +44
-0@@ -0,0 +1,384 @@ +/* +* NUMA support, based on the x86 implementation. +* +* Copyright (C) 2015 Cavium Inc. +* Author: Ganapatrao Kulkarni <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/bootmem.h> +#include <linux/ctype.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/module.h> +#include <linux/mmzone.h> +#include <linux/nodemask.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/topology.h> + +#include <asm/smp_plat.h> + +struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; +EXPORT_SYMBOL (node_data); +nodemask_t numa_nodes_parsed__initdata ; +int cpu_to_node_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE }; + +static int numa_off; +static int numa_distance_cnt; +static u8 *numa_distance; + +static __init int numa_parse_early_param (char *opt)Quoted 8 lines
arch/arm64/mm/numa.c line 50
Quoted 6 lines
arch/arm64/mm/numa.c new file +6
-0+{ +if (!opt) +return -EINVAL ; +if (!strncmp (opt,"off" ,3 )) { +pr_info ("%s\n" ,"NUMA turned off" ); + numa_off =1 ;There's a patch kicking around to add this to strtobool:
will change once it is in upstream. dont want to have dependency for this.
Quoted 239 lines
https://lkml.org/lkml/2015/12/9/802
but I can't see it in next :(
Quoted 234 lines
arch/arm64/mm/numa.c new file +234
-0+ } +return 0 ; +} +early_param ("numa" , numa_parse_early_param); + +cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_to_cpumask_map); + +#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance; +} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{Quoted 8 lines
arch/arm64/mm/numa.c line 289
Quoted 5 lines
arch/arm64/mm/numa.c new file +5
-0+if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance);Much of this is simply a direct copy/paste from x86. Why can't it be moved to common code? I don't see anything arch-specific here.
not same for all arch.
Quoted 21 lines
Quoted 21 lines
arch/arm64/mm/numa.c new file +20
-0+static int __init numa_register_nodes (void ) +{ +int nid; +struct memblock_region *mblk; + +/* Check that valid nid is set to memblks */ +for_each_memblock (memory, mblk) +if (mblk->nid ==NUMA_NO_NODE || mblk->nid >=MAX_NUMNODES ) +return -EINVAL ; + +/* Finally register nodes. */ +for_each_node_mask (nid, numa_nodes_parsed) { +unsigned long start_pfn, end_pfn; + +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); +setup_node_data (nid, start_pfn, end_pfn); +node_set_online (nid); + } + +/* Setup online nodes to actual nodes*/ Quoted 8 lines
arch/arm64/mm/numa.c line 314
Quoted 4 lines
arch/arm64/mm/numa.c new file +4
-0+ node_possible_map = numa_nodes_parsed; + +/* Dump memblock with node info and return. */ +memblock_dump_all ();We already call this from
arm64_memblock_init. If that's now too early to be of any use, we should move it to afterbootmem_init, but we should probably avoid calling it twice.sure, will do changes to have called once.
Quoted 39 lines
Quoted 39 lines
arch/arm64/mm/numa.c new file +38
-0+return 0 ; +} + +static int __init numa_init (int (*init_func)(void )) +{ +int ret; + +nodes_clear (numa_nodes_parsed); +nodes_clear (node_possible_map); +nodes_clear (node_online_map); +numa_reset_distance (); + + ret =init_func (); +if (ret <0 ) +return ret; + +if (nodes_empty (numa_nodes_parsed)) +return -EINVAL ; + + ret =numa_register_nodes (); +if (ret <0 ) +return ret; + + ret =numa_alloc_distance (); +if (ret <0 ) +return ret; + +setup_node_to_cpumask_map (); + +/* init boot processor */ + cpu_to_node_map[0 ] =0 ; +map_cpu_to_node (0 ,0 ); + +return 0 ; +} + +/** +* dummy_numa_init - Fallback dummy NUMA init Quoted 8 lines
arch/arm64/mm/numa.c line 358
Quoted 6 lines
arch/arm64/mm/numa.c new file +6
-0+* +* Used if there's no underlying NUMA architecture, NUMA initialization +* fails, or NUMA is disabled on the command line. +* +* Must online at least one node and add memory blocks that cover all +* allowed memory. This function must not fail. Why can't it fail? It looks like the return value is ignored by
numa_init.
Quoted 7 lines
this function adds all memblocks to node 0. which is unlikely that it will fail.
Quoted 2 lines
Will
thanks
Ganapat
thanks
Ganapat
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Quoted 92 lines · Ganapatrao Kulkarni
Quoted 90 lines · Ganapatrao Kulkarni
Quoted 3 lines · Will Deacon
This all looks pretty reasonable, but I'd like to see an Ack from a devicetree maintainer on the binding before I merge anything (and I see that there are outstanding comments from Rutland on that).
IIUC, there are no open comments for the binding. Mark Rutland: please let me know, if there any open comments. otherwise, can you please Ack the binding.
Quoted 39 lines · Ganapatrao Kulkarni
Quoted 37 lines
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +1
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu.Quoted 13 lines
arch/arm64/Kconfig config HOTPLUG_CPU · line 495
Quoted 10 lines
arch/arm64/Kconfig +10
-0+# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller of the CPU and add some more + NUMA awareness to the kernel.I appreciate that this is copied from x86, but what exactly do you mean by "memory controller" here?
ok, it is fair enough to say local memory.
Quoted 12 lines
arch/arm64/include/asm/mmzone.h line 2
Quoted 9 lines
arch/arm64/include/asm/mmzone.h new file +2
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_Please try to follow the standard naming for header guards under arm64 (yes, it's not perfect, but we've made some effort for consistency).
sure, will follow as in other code.
Quoted 17 lines
arch/arm64/include/asm/mmzone.h line 14
Quoted 13 lines
arch/arm64/include/asm/mmzone.h new file +12
-0+ +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)])This is the same as m32r, metag, parisc, powerpc, s390, sh, sparc, tile and x86. Can we make this the default in the core code instead and then replace this header file with asm-generic or something?
Quoted 1 line
Quoted 1 line
IIUC, it is same in most but not in all arch.
Yes, so we should make the core code take on the behaviour that most architectures want, and then allow the few remaining architectures that need to do something differently override those macros. We do this all over the place in the kernel.
Quoted 46 lines
Quoted 25 lines
Quoted 14 lines
arch/arm64/include/asm/numa.h line 2
Quoted 12 lines
arch/arm64/include/asm/mmzone.h new file +3
-0+ +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +2
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_HSame comment on the guards.
ok
Quoted 10 lines
arch/arm64/include/asm/numa.h line 9
Quoted 7 lines
arch/arm64/include/asm/numa.h new file +6
-0+#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)This is only used by the ACPI code afaict, so maybe include it when you add that?
Quoted 21 lines
ok
Quoted 4 lines
arch/arm64/include/asm/numa.h line 10
Quoted 2 lines
arch/arm64/include/asm/numa.h new file +1
-0+#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT))Where is this used?
sorry, was used in v6, missed to delete.
Quoted 15 lines
arch/arm64/include/asm/numa.h line 20
Quoted 11 lines
arch/arm64/include/asm/numa.h new file +10
-0+ +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0There's a bunch of these dummy definitions already available in
asm-generic/topology.h. Can we use those instead of rolling our own please?
Quoted 1 line
these are dummy in this patch, and i will post separate patch for numa-pci.
So you're doing to use the generic definitions?
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
This is certainly more readable then the non-numa
zone_sizes_init. Is there a reason we can't always selectHAVE_MEMBLOCK_NODE_MAPand avoid having to handle the zone holds explicitly?yes, i can think off to have select
HAVE_MEMBLOCK_NODE_MAPalways instead of for only numa.
i can experiment to have thezone_sizes_initof numa to non-numa case also and delete the currentzone_sizes_init.if i enable
HAVE_MEMBLOCK_NODE_MAPfor non-numa case, i see issues insparse_initand could be some dependency due to explicit call ofmemory_present(note sure)in non-numa.
IMO, this needs to be worked out as a separate patch.
Ok, please can you investigate and send a separate patch then?
Quoted 234 lines
Quoted 234 lines
Quoted 234 lines
Quoted 221 lines
arch/arm64/include/asm/numa.h new file +221
-0+#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance;arch/arm64/include/asm/numa.h
Quoted 10 lines
arch/arm64/include/asm/numa.h new file +10
-0+} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{ +if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance);Much of this is simply a direct copy/paste from x86. Why can't it be moved to common code? I don't see anything arch-specific here.
Quoted 1 line
Quoted 1 line
not same for all arch.
See my earlier comment. Not having identical code for all architectures doesn't mean it's not worth having a common portion of that in core code. It makes it easier to maintain, easier to use and easier to extend.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
+/**
+ *dummy_numa_init- Fallback dummy NUMA init
+ *
+ * Used if there's no underlying NUMA architecture, NUMA initialization
+ * fails, or NUMA is disabled on the command line.
+ *
+ * Must online at least one node and add memory blocks that cover all
+ * allowed memory. This function must not fail.Why can't it fail? It looks like the return value is ignored by
numa_init.this function adds all memblocks to node 0. which is unlikely that it will fail.
Good thing it returns an int, then.
Will
PATCH v7 1/4 arm64, numa: adding numa support for arm64 platforms.
Quoted 93 lines · Will Deacon
Quoted 92 lines · Ganapatrao Kulkarni
Quoted 90 lines · Ganapatrao Kulkarni
Quoted 3 lines · Will Deacon
This all looks pretty reasonable, but I'd like to see an Ack from a devicetree maintainer on the binding before I merge anything (and I see that there are outstanding comments from Rutland on that).
IIUC, there are no open comments for the binding. Mark Rutland: please let me know, if there any open comments. otherwise, can you please Ack the binding.
Quoted 39 lines · Ganapatrao Kulkarni
Quoted 37 lines
Adding numa support for arm64 based platforms.
This patch adds by default the dummy numa node and
maps all memory and cpus to node 0.
using this patch, numa can be simulated on single node arm64 platforms.Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>--- arch/arm64/Kconfig | 25 +++ arch/arm64/include/asm/mmzone.h | 17 ++ arch/arm64/include/asm/numa.h | 47 +++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +++- arch/arm64/mm/numa.c | 384 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 506 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/mm/numa.carch/arm64/Kconfig +1
-0@@ -71,6 +71,7 @@ config ARM64 select HAVE_GENERIC_DMA_COHERENT select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS@@ -482,6 +483,30 @@ config HOTPLUG_CPU Say Y here to experiment with turning CPUs off and on. CPUs can be controlled through /sys/devices/system/cpu.Quoted 13 lines
arch/arm64/Kconfig config HOTPLUG_CPU · line 495
Quoted 10 lines
arch/arm64/Kconfig +10
-0+# Common NUMA Features +config NUMA + bool "Numa Memory Allocation and Scheduler Support" + depends on SMP + help + Enable NUMA (Non Uniform Memory Access) support. + + The kernel will try to allocate memory used by a CPU on the + local memory controller of the CPU and add some more + NUMA awareness to the kernel.I appreciate that this is copied from x86, but what exactly do you mean by "memory controller" here?
ok, it is fair enough to say local memory.
Quoted 12 lines
arch/arm64/include/asm/mmzone.h line 2
Quoted 9 lines
arch/arm64/include/asm/mmzone.h new file +2
-0@@ -0,0 +1,17 @@ +#ifndef __ASM_ARM64_MMZONE_H_ +#define __ASM_ARM64_MMZONE_H_Please try to follow the standard naming for header guards under arm64 (yes, it's not perfect, but we've made some effort for consistency).
sure, will follow as in other code.
Quoted 17 lines
arch/arm64/include/asm/mmzone.h line 14
Quoted 13 lines
arch/arm64/include/asm/mmzone.h new file +12
-0+ +#ifdef CONFIG_NUMA + +#include <linux/mmdebug.h> +#include <linux/types.h> + +#include <asm/smp.h> +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[(nid)])This is the same as m32r, metag, parisc, powerpc, s390, sh, sparc, tile and x86. Can we make this the default in the core code instead and then replace this header file with asm-generic or something?
Quoted 6 lines
Quoted 1 line
Quoted 1 line
IIUC, it is same in most but not in all arch.
Yes, so we should make the core code take on the behaviour that most architectures want, and then allow the few remaining architectures that need to do something differently override those macros. We do this all over the place in the kernel.
i totally agree with you.
we will do these in subsequent clean up patches, once this series is upstreamed. please let us not mix in this series.
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 15 lines
arch/arm64/include/asm/numa.h line 2
Quoted 13 lines
arch/arm64/include/asm/mmzone.h new file +3
-0+ +#endif /* CONFIG_NUMA */ +#endif /* __ASM_ARM64_MMZONE_H_ */ arch/arm64/include/asm/numa.h new file +2
-0@@ -0,0 +1,47 @@ +#ifndef _ASM_NUMA_H +#define _ASM_NUMA_HSame comment on the guards.
ok
Quoted 10 lines
arch/arm64/include/asm/numa.h line 9
Quoted 7 lines
arch/arm64/include/asm/numa.h new file +6
-0+#include <linux/nodemask.h> +#include <asm/topology.h> + +#ifdef CONFIG_NUMA + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)This is only used by the ACPI code afaict, so maybe include it when you add that?
ok
Quoted 4 lines
arch/arm64/include/asm/numa.h line 10
Quoted 2 lines
arch/arm64/include/asm/numa.h new file +1
-0+#define ZONE_ALIGN (1UL << (MAX_ORDER + PAGE_SHIFT))Where is this used?
sorry, was used in v6, missed to delete.
Quoted 15 lines
arch/arm64/include/asm/numa.h line 20
Quoted 11 lines
arch/arm64/include/asm/numa.h new file +10
-0+ +/* currently, arm64 implements flat NUMA topology */ +#define parent_node (node) (node) + +extern int __node_distance (int from,int to); +#define node_distance (a, b) __node_distance(a, b) + +/* dummy definitions for pci functions */ +#define pcibus_to_node (node) 0 +#define cpumask_of_pcibus (bus) 0There's a bunch of these dummy definitions already available in
asm-generic/topology.h. Can we use those instead of rolling our own please?
Quoted 3 lines
Quoted 1 line
these are dummy in this patch, and i will post separate patch for numa-pci.
So you're doing to use the generic definitions?
generic are different than what we need.
for pci, i have sent a patch.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
This is certainly more readable then the non-numa
zone_sizes_init. Is there a reason we can't always selectHAVE_MEMBLOCK_NODE_MAPand avoid having to handle the zone holds explicitly?yes, i can think off to have select
HAVE_MEMBLOCK_NODE_MAPalways instead of for only numa.
i can experiment to have thezone_sizes_initof numa to non-numa case also and delete the currentzone_sizes_init.
Quoted 6 lines
Quoted 4 lines
if i enable
HAVE_MEMBLOCK_NODE_MAPfor non-numa case, i see issues insparse_initand could be some dependency due to explicit call ofmemory_present(note sure)in non-numa.
IMO, this needs to be worked out as a separate patch.Ok, please can you investigate and send a separate patch then?
sure, not in this series please.
Quoted 235 lines
Quoted 235 lines
Quoted 235 lines
Quoted 235 lines
Quoted 222 lines
arch/arm64/include/asm/numa.h new file +221
-0+#ifdef CONFIG_DEBUG_PER_CPU_MAPS +/* +* Returns a pointer to the bitmask of CPUs on Node 'node'. +*/ +const struct cpumask *cpumask_of_node (int node) +{ + +if (WARN_ON (node >= nr_node_ids)) +return cpu_none_mask; + +if (WARN_ON (node_to_cpumask_map[node] ==NULL )) +return cpu_online_mask; + +return node_to_cpumask_map[node]; +} +EXPORT_SYMBOL (cpumask_of_node); +#endif + +static void map_cpu_to_node (unsigned int cpu,int nid) +{ +set_cpu_numa_node (cpu, nid); +if (nid >=0 ) +cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); +} + +static void unmap_cpu_to_node (unsigned int cpu) +{ +int nid =cpu_to_node (cpu); + +if (nid >=0 ) +cpumask_clear_cpu (cpu, node_to_cpumask_map[nid]); +set_cpu_numa_node (cpu,NUMA_NO_NODE ); +} + +void numa_clear_node (unsigned int cpu) +{ +unmap_cpu_to_node (cpu); +} + +/* +* Allocate node_to_cpumask_map based on number of available nodes +* Requires node_possible_map to be valid. +* +* Note: cpumask_of_node() is not valid until after this is done. +* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) +*/ +static void __init setup_node_to_cpumask_map (void ) +{ +unsigned int cpu; +int node; + +/* setup nr_node_ids if not done yet */ +if (nr_node_ids ==MAX_NUMNODES ) +setup_nr_node_ids (); + +/* allocate and clear the mapping */ +for (node =0 ; node < nr_node_ids; node++) { +alloc_bootmem_cpumask_var (&node_to_cpumask_map[node]); +cpumask_clear (node_to_cpumask_map[node]); + } + +for_each_possible_cpu (cpu) +set_cpu_numa_node (cpu,NUMA_NO_NODE ); + +/* cpumask_of_node() will now work */ +pr_debug ("Node to cpumask map for %d nodes\n" , nr_node_ids); +} + +/* +* Set the cpu to node and mem mapping +*/ +void numa_store_cpu_info (unsigned int cpu) +{ +map_cpu_to_node (cpu, numa_off ?0 : cpu_to_node_map[cpu]); +} + +/** +* numa_add_memblk - Set node id to memblk +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @size: Size of the new memblk +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_add_memblk (int nid,u64 start,u64 size) +{ +int ret; + + ret =memblock_set_node (start, size, &memblock.memory, nid); +if (ret <0 ) { +pr_err ("NUMA: memblock [0x%llx - 0x%llx] failed to add on node %d\n" , + start, (start + size -1 ), nid); +return ret; + } + +node_set (nid, numa_nodes_parsed); +pr_info ("NUMA: Adding memblock [0x%llx - 0x%llx] on node %d\n" , + start, (start + size -1 ), nid); +return ret; +} +EXPORT_SYMBOL (numa_add_memblk); + +/* Initialize NODE_DATA for a node on the local memory */ +static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); +u64 nd_pa; +void *nd; +int tnid; + +pr_info ("Initmem setup node %d [mem %#010Lx-%#010Lx]\n" , + nid, start_pfn <<PAGE_SHIFT , + (end_pfn <<PAGE_SHIFT ) -1 ); + + nd_pa =memblock_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +NODE_DATA (nid)->node_id = nid; +NODE_DATA (nid)->node_start_pfn = start_pfn; +NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; +} + +/** +* numa_reset_distance - Reset NUMA distance table +* +* The current table is freed. +* The next numa_set_distance() call will create a new one. +*/ +void __init numa_reset_distance (void ) +{ +size_t size; + +if (!numa_distance) +return ; + + size = numa_distance_cnt * numa_distance_cnt * +sizeof (numa_distance[0 ]); + +memblock_free (__pa (numa_distance), size); + numa_distance_cnt =0 ; + numa_distance =NULL ; +} + +static int __init numa_alloc_distance (void ) +{ +size_t size; +u64 phys; +int i, j; + + size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); + phys =memblock_find_in_range (0 ,PFN_PHYS (max_pfn), + size,PAGE_SIZE ); +if (WARN_ON (!phys)) +return -ENOMEM ; + +memblock_reserve (phys, size); + + numa_distance =__va (phys); + numa_distance_cnt = nr_node_ids; + +/* fill with the default distances */ +for (i =0 ; i < numa_distance_cnt; i++) +for (j =0 ; j < numa_distance_cnt; j++) + numa_distance[i * numa_distance_cnt + j] = i == j ? +LOCAL_DISTANCE :REMOTE_DISTANCE ; + +pr_debug ("NUMA: Initialized distance table, cnt=%d\n" , + numa_distance_cnt); + +return 0 ; +} + +/** +* numa_set_distance - Set NUMA distance from one NUMA to another +* @from: the 'from' node to set distance +* @to: the 'to' node to set distance +* @distance: NUMA distance +* +* Set the distance from node @from to @to to @distance. If distance table +* doesn't exist, one which is large enough to accommodate all the currently +* known nodes will be created. +* +* If such table cannot be allocated, a warning is printed and further +* calls are ignored until the distance table is reset with +* numa_reset_distance(). +* +* If @from or @to is higher than the highest known node or lower than zero +* at the time of table creation or @distance doesn't make sense, the call +* is ignored. +* This is to allow simplification of specific NUMA config implementations. +*/ +void __init numa_set_distance (int from,int to,int distance) +{ +if (!numa_distance) +return ; + +if (from >= numa_distance_cnt || to >= numa_distance_cnt || + from <0 || to <0 ) { +pr_warn_once ("NUMA: Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + +if ((u8 )distance != distance || + (from == to && distance !=LOCAL_DISTANCE )) { +pr_warn_once ("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , + from, to, distance); +return ; + } + + numa_distance[from * numa_distance_cnt + to] = distance;arch/arm64/include/asm/numa.h
Quoted 10 lines
arch/arm64/include/asm/numa.h new file +10
-0+} +EXPORT_SYMBOL (numa_set_distance); + +int __node_distance (int from,int to) +{ +if (from >= numa_distance_cnt || to >= numa_distance_cnt) +return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; +return numa_distance[from * numa_distance_cnt + to]; +} +EXPORT_SYMBOL (__node_distance);Much of this is simply a direct copy/paste from x86. Why can't it be moved to common code? I don't see anything arch-specific here.
Quoted 16 lines
Quoted 1 line
Quoted 1 line
not same for all arch.
See my earlier comment. Not having identical code for all architectures doesn't mean it's not worth having a common portion of that in core code. It makes it easier to maintain, easier to use and easier to extend.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
+/**
+ *dummy_numa_init- Fallback dummy NUMA init
+ *
+ * Used if there's no underlying NUMA architecture, NUMA initialization
+ * fails, or NUMA is disabled on the command line.
+ *
+ * Must online at least one node and add memory blocks that cover all
+ * allowed memory. This function must not fail.Why can't it fail? It looks like the return value is ignored by
numa_init.
no, numa_init is not ignoring return value.
ret = init_func();
if (ret < 0)
return ret;Quoted 5 lines
Quoted 1 line
Quoted 1 line
this function adds all memblocks to node 0. which is unlikely that it will fail.
Good thing it returns an int, then.
Will
thanks
Ganapat
PATCH v7 2/4 Documentation, dt, arm64/arm: dt bindings for numa.
In reply to Ganapatrao KulkarniDT bindings for numa mapping of memory, cores and IOs.
--- Documentation/devicetree/bindings/arm/numa.txt | 272 +++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/numa.txt
Documentation/devicetree/bindings/arm/numa.txt new file +272 -0
@@ -0,0 +1,272 @@ +============================================================================== +NUMA binding description. +============================================================================== + +============================================================================== +1 - Introduction +============================================================================== + +Systems employing a Non Uniform Memory Access (NUMA) architecture contain +collections of hardware resources including processors, memory, and I/O buses, +that comprise what is commonly known as a NUMA node. +Processor accesses to memory within the local NUMA node is generally faster +than processor accesses to memory outside of the local NUMA node. +DT defines interfaces that allow the platform to convey NUMA node +topology information to OS. + +============================================================================== +2 - numa-node-id +============================================================================== +The device node property numa-node-id describes numa domains within a +machine. This property can be used in device nodes like cpu, memory, bus and +devices to map to respective numa nodes. + +numa-node-id property is a 32-bit integer which defines numa node id to which +this device node has numa domain association. + +Example: + /* numa node 0 */ + numa-node-id = <0>; + + /* numa node 1 */ + numa-node-id = <1>; + +============================================================================== +3 - distance-map +============================================================================== + +The device tree node distance-map describes the relative +distance (memory latency) between all numa nodes. + +- compatible : Should at least contain "numa,distance-map-v1". + +- distance-matrix + This property defines a matrix to describe the relative distances + between all numa nodes. + It is represented as a list of node pairs and their relative distance. + + Note: + 1. Each entry represents distance from first node to second node. + 2. If both directions between 2 nodes have the same distance, only + one entry is required. + 2. distance-matrix shold have entries in lexicographical ascending order of nodes. + 3. There must be only one Device node distance-map and must reside in the root node. + +Example: + 4 nodes connected in mesh/ring topology as below, + + 0_______20______1 + | | + | | + 20| |20 + | | + | | + |_______________| + 3 20 2 + + if relative distance for each hop is 20, + then inter node distance would be for this topology will be, + 0 -> 1 = 20 + 1 -> 2 = 20 + 2 -> 3 = 20 + 3 -> 0 = 20 + 0 -> 2 = 40 + 1 -> 3 = 40 + + and dt presentation for this distance matrix is, + + distance-map { + compatible = "numa,distance-map-v1"; + distance-matrix = <0 0 10>, + <0 1 20>, + <0 2 40>, + <0 3 20>, + <1 0 20>, + <1 1 10>, + <1 2 20>, + <1 3 40>, + <2 0 40>, + <2 1 20>, + <2 2 10>, + <2 3 20>, + <3 0 20>, + <3 1 40>, + <3 2 20>, + <3 3 10>; + }; + +Note: + 1. The entries like <1 0> can be optional if <0 1> and <1 0> + are of same distance. + +============================================================================== +4 - Example dts +============================================================================== + +2 sockets system consists of 2 boards connected through ccn bus and +each board having one socket/soc of 8 cpus, memory and pci bus. + + memory at 00c00000 { + device_type = "memory"; + reg = <0x0 0x00c00000 0x0 0x80000000>; + /* node 0 */ + numa-node-id = <0>; + }; + + memory at 10000000000 { + device_type = "memory"; + reg = <0x100 0x00000000 0x0 0x80000000>; + /* node 1 */ + numa-node-id = <1>; + }; + + cpus { + #address-cells = <2>; + #size-cells = <0>; + + cpu at 000 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x000>; + enable-method = "psci"; + /* node 0 */ + numa-node-id = <0>; + }; + cpu at 001 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x001>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 002 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x002>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 003 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x003>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 004 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x004>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 005 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x005>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 006 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x006>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 007 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x007>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 008 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x008>; + enable-method = "psci"; + /* node 1 */ + numa-node-id = <1>; + }; + cpu at 009 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x009>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at 00a { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x00a>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at 00b { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x00b>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at 00c { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x00c>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at 00d { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x00d>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at 00e { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x00e>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at 00f { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x00f>; + enable-method = "psci"; + numa-node-id = <1>; + }; + }; + + pcie0: pcie0 at 0x8480,00000000 { + compatible = "arm,armv8"; + device_type = "pci"; + bus-range = <0 255>; + #size-cells = <2>; + #address-cells = <3>; + reg = <0x8480 0x00000000 0 0x10000000>; /* Configuration space */ + ranges = <0x03000000 0x8010 0x00000000 0x8010 0x00000000 0x70 0x00000000>; + /* node 0 */ + numa-node-id = <0>; + }; + + pcie1: pcie1 at 0x9480,00000000 { + compatible = "arm,armv8"; + device_type = "pci"; + bus-range = <0 255>; + #size-cells = <2>; + #address-cells = <3>; + reg = <0x9480 0x00000000 0 0x10000000>; /* Configuration space */ + ranges = <0x03000000 0x9010 0x00000000 0x9010 0x00000000 0x70 0x00000000>; + /* node 1 */ + numa-node-id = <1>; + }; + + distance-map { + compatible = "numa,distance-map-v1"; + distance-matrix = <0 0 10>, + <0 1 20>, + <1 1 10>; + };
Signature · 1 line
1.8.1.4
Mark Rutland
reviewerPATCH v7 2/4 Documentation, dt, arm64/arm: dt bindings for numa.
Hi,
Quoted 4 lines · Ganapatrao Kulkarni
DT bindings for numa mapping of memory, cores and IOs.
Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>
Overall this looks good to me. However, I have a couple of concerns.
Quoted 26 lines
--- Documentation/devicetree/bindings/arm/numa.txt | 272 +++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/numa.txtDocumentation/devicetree/bindings/arm/numa.txt new file +15
-0@@ -0,0 +1,272 @@ +============================================================================== +NUMA binding description. +============================================================================== + +============================================================================== +1 - Introduction +============================================================================== + +Systems employing a Non Uniform Memory Access (NUMA) architecture contain +collections of hardware resources including processors, memory, and I/O buses, +that comprise what is commonly known as a NUMA node. +Processor accesses to memory within the local NUMA node is generally faster +than processor accesses to memory outside of the local NUMA node. +DT defines interfaces that allow the platform to convey NUMA node +topology information to OS.
Documentation/devicetree/bindings/arm/numa.txt line 25
Quoted 10 lines
Documentation/devicetree/bindings/arm/numa.txt new file +10
-0+ +============================================================================== +2 - numa-node-id +============================================================================== +The device node property numa-node-id describes numa domains within a +machine. This property can be used in device nodes like cpu, memory, bus and +devices to map to respective numa nodes. + +numa-node-id property is a 32-bit integer which defines numa node id to which +this device node has numa domain association.
I'd prefer if the above two paragraphs were replaced with:
For the purpose of identification, each NUMA node is associated with a unique token known as a node id. For the purpose of this binding a node id is a 32-bit integer.
A device node is associated with a NUMA node by the presence of a numa-node-id property which contains the node id of the device.
Quoted 4 lines
Documentation/devicetree/bindings/arm/numa.txt new file +4
-0+ +Example: + /* numa node 0 */ + numa-node-id = <0>;
Documentation/devicetree/bindings/arm/numa.txt line 39
Quoted 10 lines
Documentation/devicetree/bindings/arm/numa.txt new file +10
-0+ + /* numa node 1 */ + numa-node-id = <1>; + +============================================================================== +3 - distance-map +============================================================================== + +The device tree node distance-map describes the relative +distance (memory latency) between all numa nodes.
Is this not a combined approximation for latency and bandwidth?
Documentation/devicetree/bindings/arm/numa.txt line 41
Quoted 1 line
Documentation/devicetree/bindings/arm/numa.txt new file +1
-0+- compatible : Should at least contain "numa,distance-map-v1".
Please use "numa-distance-map-v1", as "numa" is not a vendor.
Documentation/devicetree/bindings/arm/numa.txt line 51
Quoted 9 lines
Documentation/devicetree/bindings/arm/numa.txt new file +9
-0+- distance-matrix + This property defines a matrix to describe the relative distances + between all numa nodes. + It is represented as a list of node pairs and their relative distance. + + Note: + 1. Each entry represents distance from first node to second node. + 2. If both directions between 2 nodes have the same distance, only + one entry is required.
I still don't understand what direction means in this context. Are there systems (of any architecture) which don't have symmetric distances? Which accesses does this apply differently to?
Given that, I think that it might be best to explicitly call out distances as being equal, and leave any directionality for a later revision of the binding when we have some semantics for directionality.
Quoted 13 lines
Documentation/devicetree/bindings/arm/numa.txt new file +13
-0+ 2. distance-matrix shold have entries in lexicographical ascending order of nodes. + 3. There must be only one Device node distance-map and must reside in the root node. + +Example: + 4 nodes connected in mesh/ring topology as below, + + 0_______20______1 + | | + | | + 20| |20 + | | + | | + |_______________|
Documentation/devicetree/bindings/arm/numa.txt line 74
Quoted 10 lines
Documentation/devicetree/bindings/arm/numa.txt new file +10
-0+ 3 20 2 + + if relative distance for each hop is 20, + then inter node distance would be for this topology will be, + 0 -> 1 = 20 + 1 -> 2 = 20 + 2 -> 3 = 20 + 3 -> 0 = 20 + 0 -> 2 = 40 + 1 -> 3 = 40
How is this scaled relative to a local access?
Do we assume that a local access has value 1, e.g. each hop takes 20x a local access in this example?
Do we need a finer-grained scale (e.g. to allow us to represent a distance of 2.5)? The ACPI SLIT spec seems to give local accesses a value 10 implicitly to this end.
Other than those points, I'm happy with this binding.
Thanks,
Mark.
PATCH v7 2/4 Documentation, dt, arm64/arm: dt bindings for numa.
Quoted 9 lines · Mark Rutland
Hi,
Quoted 4 lines · Ganapatrao Kulkarni
DT bindings for numa mapping of memory, cores and IOs.
Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>Overall this looks good to me. However, I have a couple of concerns.
thanks.
Quoted 40 lines
Quoted 27 lines
--- Documentation/devicetree/bindings/arm/numa.txt | 272 +++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/numa.txtDocumentation/devicetree/bindings/arm/numa.txt new file +15
-0@@ -0,0 +1,272 @@ +============================================================================== +NUMA binding description. +============================================================================== + +============================================================================== +1 - Introduction +============================================================================== + +Systems employing a Non Uniform Memory Access (NUMA) architecture contain +collections of hardware resources including processors, memory, and I/O buses, +that comprise what is commonly known as a NUMA node. +Processor accesses to memory within the local NUMA node is generally faster +than processor accesses to memory outside of the local NUMA node. +DT defines interfaces that allow the platform to convey NUMA node +topology information to OS.Documentation/devicetree/bindings/arm/numa.txt line 25
Quoted 10 lines
Documentation/devicetree/bindings/arm/numa.txt new file +10
-0+ +============================================================================== +2 - numa-node-id +============================================================================== +The device node property numa-node-id describes numa domains within a +machine. This property can be used in device nodes like cpu, memory, bus and +devices to map to respective numa nodes. + +numa-node-id property is a 32-bit integer which defines numa node id to which +this device node has numa domain association.I'd prefer if the above two paragraphs were replaced with:
Quoted 7 lines
For the purpose of identification, each NUMA node is associated with a unique token known as a node id. For the purpose of this binding a node id is a 32-bit integer.
A device node is associated with a NUMA node by the presence of a numa-node-id property which contains the node id of the device.
ok, will do.
Quoted 17 lines
Quoted 5 lines
Documentation/devicetree/bindings/arm/numa.txt new file +4
-0+ +Example: + /* numa node 0 */ + numa-node-id = <0>;Documentation/devicetree/bindings/arm/numa.txt line 39
Quoted 10 lines
Documentation/devicetree/bindings/arm/numa.txt new file +10
-0+ + /* numa node 1 */ + numa-node-id = <1>; + +============================================================================== +3 - distance-map +============================================================================== + +The device tree node distance-map describes the relative +distance (memory latency) between all numa nodes.Is this not a combined approximation for latency and bandwidth?
AFAIK, it is to represent inter-node memory access latency.
Quoted 4 lines
Documentation/devicetree/bindings/arm/numa.txt line 41
Quoted 2 lines
Documentation/devicetree/bindings/arm/numa.txt new file +1
-0+- compatible : Should at least contain "numa,distance-map-v1".Please use "numa-distance-map-v1", as "numa" is not a vendor.
ok
Quoted 11 lines
Documentation/devicetree/bindings/arm/numa.txt line 51
Quoted 10 lines
Documentation/devicetree/bindings/arm/numa.txt new file +9
-0+- distance-matrix + This property defines a matrix to describe the relative distances + between all numa nodes. + It is represented as a list of node pairs and their relative distance. + + Note: + 1. Each entry represents distance from first node to second node. + 2. If both directions between 2 nodes have the same distance, only + one entry is required.
Quoted 7 lines
I still don't understand what direction means in this context. Are there systems (of any architecture) which don't have symmetric distances? Which accesses does this apply differently to?
Given that, I think that it might be best to explicitly call out distances as being equal, and leave any directionality for a later revision of the binding when we have some semantics for directionality.
agreed, given that there is no know system to substantiate dual direction, let us not explicit about direction.
Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/arm/numa.txt new file +17
-0+ 2. distance-matrix shold have entries in lexicographical ascending order of nodes. + 3. There must be only one Device node distance-map and must reside in the root node. + +Example: + 4 nodes connected in mesh/ring topology as below, + + 0_______20______1 + | | + | | + 20| |20 + | | + | | + |_______________| + 3 20 2 + + if relative distance for each hop is 20, + then inter node distance would be for this topology will be,
Quoted 8 lines
Documentation/devicetree/bindings/arm/numa.txt line 74
Quoted 6 lines
Documentation/devicetree/bindings/arm/numa.txt new file +6
-0+ 0 -> 1 = 20 + 1 -> 2 = 20 + 2 -> 3 = 20 + 3 -> 0 = 20 + 0 -> 2 = 40 + 1 -> 3 = 40How is this scaled relative to a local access?
this is based on representing local distance with 10 and all inter-node latency being represented as multiple of 10.
Quoted 3 lines
Do we assume that a local access has value 1, e.g. each hop takes 20x a local access in this example?
The local distance is represented as 10, this is fixed and same as in ACPI. Inter-node distance can be any number greater than 10.
this information can be added here to make it clear.
Quoted 4 lines
Do we need a finer-grained scale (e.g. to allow us to represent a distance of 2.5)? The ACPI SLIT spec seems to give local accesses a value 10 implicitly to this end.
yes, same as ACPI, local node is 10.
Quoted 6 lines
Other than those points, I'm happy with this binding.
Thanks,
Mark.
thanks
Ganapat
Mark Rutland
reviewerPATCH v7 2/4 Documentation, dt, arm64/arm: dt bindings for numa.
Hi,
Quoted 11 lines · Ganapatrao Kulkarni
Quoted 9 lines · Mark Rutland
Hi,
Quoted 4 lines · Ganapatrao Kulkarni
DT bindings for numa mapping of memory, cores and IOs.
Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>Overall this looks good to me. However, I have a couple of concerns.
thanks.
[...]
Quoted 20 lines
Quoted 12 lines
Documentation/devicetree/bindings/arm/numa.txt line 25
Quoted 9 lines
+==============================================================================
+2 - numa-node-id
+==============================================================================Documentation/devicetree/bindings/arm/numa.txt new file +6
-0+The device node property numa-node-id describes numa domains within a +machine. This property can be used in device nodes like cpu, memory, bus and +devices to map to respective numa nodes. + +numa-node-id property is a 32-bit integer which defines numa node id to which +this device node has numa domain association.I'd prefer if the above two paragraphs were replaced with:
Quoted 7 lines
For the purpose of identification, each NUMA node is associated with a unique token known as a node id. For the purpose of this binding a node id is a 32-bit integer.
A device node is associated with a NUMA node by the presence of a numa-node-id property which contains the node id of the device.
ok, will do.
[...]
Quoted 29 lines
Quoted 8 lines
Documentation/devicetree/bindings/arm/numa.txt line 39
Quoted 6 lines
+==============================================================================
+3 - distance-map
+==============================================================================Documentation/devicetree/bindings/arm/numa.txt new file +3
-0+ +The device tree node distance-map describes the relative +distance (memory latency) between all numa nodes.Is this not a combined approximation for latency and bandwidth?
AFAIK, it is to represent inter-node memory access latency.
Quoted 4 lines
Quoted 2 lines
+- compatible : Should at least contain "numa,distance-map-v1".
Please use "numa-distance-map-v1", as "numa" is not a vendor.
ok
Quoted 15 lines
Documentation/devicetree/bindings/arm/numa.txt line 51
Quoted 10 lines
+- distance-matrix
Documentation/devicetree/bindings/arm/numa.txt new file +8
-0+ This property defines a matrix to describe the relative distances + between all numa nodes. + It is represented as a list of node pairs and their relative distance. + + Note: + 1. Each entry represents distance from first node to second node. + 2. If both directions between 2 nodes have the same distance, only + one entry is required.I still don't understand what direction means in this context. Are there systems (of any architecture) which don't have symmetric distances? Which accesses does this apply differently to?
Quoted 5 lines
Quoted 3 lines
Given that, I think that it might be best to explicitly call out distances as being equal, and leave any directionality for a later revision of the binding when we have some semantics for directionality.
agreed, given that there is no know system to substantiate dual direction, let us not explicit about direction.
Regarding your comment in [1], I was expecting a respin of this series with the above comments addressed. I will not provide an ack until I've seen that.
Additional concerns below also apply.
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/arm/numa.txt new file +17
-0+ 2. distance-matrix shold have entries in lexicographical ascending order of nodes. + 3. There must be only one Device node distance-map and must reside in the root node. + +Example: + 4 nodes connected in mesh/ring topology as below, + + 0_______20______1 + | | + | | + 20| |20 + | | + | | + |_______________| + 3 20 2 + + if relative distance for each hop is 20, + then inter node distance would be for this topology will be,Quoted 8 lines
Documentation/devicetree/bindings/arm/numa.txt line 74
Quoted 6 lines
Documentation/devicetree/bindings/arm/numa.txt new file +6
-0+ 0 -> 1 = 20 + 1 -> 2 = 20 + 2 -> 3 = 20 + 3 -> 0 = 20 + 0 -> 2 = 40 + 1 -> 3 = 40How is this scaled relative to a local access?
this is based on representing local distance with 10 and all inter-node latency being represented as multiple of 10.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
Do we assume that a local access has value 1, e.g. each hop takes 20x a local access in this example?
The local distance is represented as 10, this is fixed and same as in ACPI. Inter-node distance can be any number greater than 10.
this information can be added here to make it clear.
This seems rather arbitrary.
Why can we not define the local distance in the DT? I appreciate that the value is hard-coded for ACPI, but we don't have to copy that limitation.
I'm not sure if asymmetric local distances matter.
Thanks,
Mark.
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/394634.html
PATCH v7 2/4 Documentation, dt, arm64/arm: dt bindings for numa.
Quoted 72 lines · Mark Rutland
Hi,
Quoted 11 lines · Ganapatrao Kulkarni
Quoted 9 lines · Mark Rutland
Hi,
Quoted 4 lines · Ganapatrao Kulkarni
DT bindings for numa mapping of memory, cores and IOs.
Reviewed-by Robert Richter <[email protected]>Signed-off-by Ganapatrao Kulkarni <[email protected]>Overall this looks good to me. However, I have a couple of concerns.
thanks.
[...]
Quoted 20 lines
Quoted 12 lines
Documentation/devicetree/bindings/arm/numa.txt line 25
Quoted 9 lines
+==============================================================================
+2 - numa-node-id
+==============================================================================Documentation/devicetree/bindings/arm/numa.txt new file +6
-0+The device node property numa-node-id describes numa domains within a +machine. This property can be used in device nodes like cpu, memory, bus and +devices to map to respective numa nodes. + +numa-node-id property is a 32-bit integer which defines numa node id to which +this device node has numa domain association.I'd prefer if the above two paragraphs were replaced with:
Quoted 7 lines
For the purpose of identification, each NUMA node is associated with a unique token known as a node id. For the purpose of this binding a node id is a 32-bit integer.
A device node is associated with a NUMA node by the presence of a numa-node-id property which contains the node id of the device.
ok, will do.
[...]
Quoted 32 lines
Quoted 8 lines
Documentation/devicetree/bindings/arm/numa.txt line 39
Quoted 6 lines
+==============================================================================
+3 - distance-map
+==============================================================================Documentation/devicetree/bindings/arm/numa.txt new file +3
-0+ +The device tree node distance-map describes the relative +distance (memory latency) between all numa nodes.Is this not a combined approximation for latency and bandwidth?
AFAIK, it is to represent inter-node memory access latency.
Quoted 4 lines
Quoted 2 lines
+- compatible : Should at least contain "numa,distance-map-v1".
Please use "numa-distance-map-v1", as "numa" is not a vendor.
ok
Quoted 18 lines
Documentation/devicetree/bindings/arm/numa.txt line 51
Quoted 10 lines
+- distance-matrix
Documentation/devicetree/bindings/arm/numa.txt new file +8
-0+ This property defines a matrix to describe the relative distances + between all numa nodes. + It is represented as a list of node pairs and their relative distance. + + Note: + 1. Each entry represents distance from first node to second node. + 2. If both directions between 2 nodes have the same distance, only + one entry is required.I still don't understand what direction means in this context. Are there systems (of any architecture) which don't have symmetric distances? Which accesses does this apply differently to?
Given that, I think that it might be best to explicitly call out distances as being equal, and leave any directionality for a later revision of the binding when we have some semantics for directionality.
Quoted 6 lines
Quoted 2 lines
agreed, given that there is no know system to substantiate dual direction, let us not explicit about direction.
Regarding your comment in [1], I was expecting a respin of this series with the above comments addressed. I will not provide an ack until I've seen that.
sure, i will respin with the comments addressed.
Quoted 38 lines
Additional concerns below also apply.
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/arm/numa.txt new file +17
-0+ 2. distance-matrix shold have entries in lexicographical ascending order of nodes. + 3. There must be only one Device node distance-map and must reside in the root node. + +Example: + 4 nodes connected in mesh/ring topology as below, + + 0_______20______1 + | | + | | + 20| |20 + | | + | | + |_______________| + 3 20 2 + + if relative distance for each hop is 20, + then inter node distance would be for this topology will be,Quoted 8 lines
Documentation/devicetree/bindings/arm/numa.txt line 74
Quoted 6 lines
Documentation/devicetree/bindings/arm/numa.txt new file +6
-0+ 0 -> 1 = 20 + 1 -> 2 = 20 + 2 -> 3 = 20 + 3 -> 0 = 20 + 0 -> 2 = 40 + 1 -> 3 = 40How is this scaled relative to a local access?
this is based on representing local distance with 10 and all inter-node latency being represented as multiple of 10.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
Do we assume that a local access has value 1, e.g. each hop takes 20x a local access in this example?
The local distance is represented as 10, this is fixed and same as in ACPI. Inter-node distance can be any number greater than 10.
this information can be added here to make it clear.
Quoted 5 lines
This seems rather arbitrary.
Why can we not define the local distance in the DT? I appreciate that the value is hard-coded for ACPI, but we don't have to copy that limitation.
yes, we can mention local distance.
Quoted 7 lines
I'm not sure if asymmetric local distances matter.
Thanks,
Mark.[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/394634.html
thanks
Ganapat
PATCH v7 3/4 arm64/arm, numa, dt: adding numa dt binding implementation for arm64 platforms.
In reply to Ganapatrao KulkarniAdding numa dt binding support for arm64 based platforms. dt node parsing for numa topology is done using device property proximity and device node distance-map.
--- arch/arm64/Kconfig | 10 ++ arch/arm64/include/asm/numa.h | 9 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/of_numa.c | 265 ++++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/smp.c | 2 + arch/arm64/mm/numa.c | 10 +- 6 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/of_numa.c
arch/arm64/Kconfig +10 -0
@@ -494,6 +494,16 @@ config NUMA local memory controller of the CPU and add some more NUMA awareness to the kernel. +config OF_NUMA + bool "Device Tree NUMA support" + depends on NUMA + depends on OF + default y + help + Enable Device Tree NUMA support. + This enables the numa mapping of cpu, memory, io and + inter node distances using dt bindings. + config NODES_SHIFT int "Maximum NUMA Nodes (as a power of 2)" range 1 10
arch/arm64/include/asm/numa.h +9 -0
@@ -44,4 +44,13 @@ void numa_store_cpu_info(unsigned int cpu);static inline void numa_store_cpu_info (unsigned int cpu) { }static inline void arm64_numa_init (void ) { }#endif /* CONFIG_NUMA */ + +struct device_node ; +#ifdef CONFIG_OF_NUMA +int __init arm64_of_numa_init (void ); +void __init of_numa_set_node_info (unsigned int cpu,struct device_node *dn); +#else +static inline void of_numa_set_node_info (unsigned int cpu, +struct device_node *dn) { } +#endif #endif /* _ASM_NUMA_H */
arch/arm64/kernel/Makefile +1 -0
@@ -41,6 +41,7 @@ arm64-obj-$(CONFIG_EFI) += efi.o efi-entry.stub.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o arm64-obj-$(CONFIG_ACPI) += acpi.o +arm64-obj-$(CONFIG_OF_NUMA) += of_numa.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m)
arch/arm64/kernel/of_numa.c new file +265 -0
265 lines not on this page · raw message
arch/arm64/kernel/smp.c +2 -0
@@ -520,6 +520,8 @@ static void __init of_parse_and_init_cpus(void)pr_debug ("cpu logical map 0x%llx\n" , hwid);cpu_logical_map (cpu_count) = hwid; +/* map logical cpu to node */ +of_numa_set_node_info (cpu_count, dn); next: cpu_count++; }
arch/arm64/mm/numa.c +9 -1
@@ -380,5 +380,13 @@ static int __init dummy_numa_init(void)*/ void __init arm64_numa_init (void ) { -numa_init (dummy_numa_init); +int ret = -ENODEV ; + +#ifdef CONFIG_OF_NUMA +if (!numa_off) + ret =numa_init (arm64_of_numa_init); +#endif + +if (ret) +numa_init (dummy_numa_init); }
Signature · 1 line
1.8.1.4
PATCH v7 3/4 arm64/arm, numa, dt: adding numa dt binding implementation for arm64 platforms.
Quoted 30 lines · Ganapatrao Kulkarni
arch/arm64/kernel/of_numa.c new file +30
-0+static int __init early_init_parse_memory_node (unsigned long node) +{ +const __be32 *reg, *endp; +int length; +int nid; + +const char *type =of_get_flat_dt_prop (node,"device_type" ,NULL ); + +/* We are scanning "memory" nodes only */ +if (type ==NULL ) +return 0 ; +else if (strcmp (type,"memory" ) !=0 ) +return 0 ; + + nid =early_init_of_get_numa_nid (node); + +if (nid ==NUMA_NO_NODE ) +return -EINVAL ; + + reg =of_get_flat_dt_prop (node,"reg" , &length); + endp = reg + (length /sizeof (__be32)); + +while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { +u64 base, size; +struct memblock_region *mblk; + + base =dt_mem_next_cell (dt_root_addr_cells, ®); + size =dt_mem_next_cell (dt_root_size_cells, ®); +pr_debug ("NUMA-DT: base = %llx , node = %u\n" , + base, nid);
arch/arm64/kernel/of_numa.c line 180
Quoted 10 lines
arch/arm64/kernel/of_numa.c new file +10
-0+ +for_each_memblock (memory, mblk) { +if (mblk->base == base) { +if (numa_add_memblk (nid, + mblk->base, + mblk->size) <0 ) +return -EINVAL ; +break ; + } + }
Maybe this is not right. If the memory spaces of NUMA nodes are continuous like below:
memory at 60000000 {
numa-node-id = <0x1>;
reg = <0x0 0x60000000 0x0 0x20000000>;
device_type = "memory";
};
memory at 40000000 {
numa-node-id = <0x0>;
reg = <0x0 0x40000000 0x0 0x20000000>;
device_type = "memory";
};There is only one memory region [0x00000040000000-0x0000007fffffff] and the mblk->base is 40000000, so it will not add the memory node 1.
I think this should do the same thing like ACPI_NUMA but add some codes to check if the [base, base + size] is located in some memory region. Or don't check because numa_add_memblk will fail if the [base, base + size] is not located in some memory region.
Thanks,
Signature · 1 line
Shannon
PATCH v7 3/4 arm64/arm, numa, dt: adding numa dt binding implementation for arm64 platforms.
Quoted 59 lines · Shannon Zhao
Quoted 30 lines · Ganapatrao Kulkarni
arch/arm64/kernel/of_numa.c new file +30
-0+static int __init early_init_parse_memory_node (unsigned long node) +{ +const __be32 *reg, *endp; +int length; +int nid; + +const char *type =of_get_flat_dt_prop (node,"device_type" ,NULL ); + +/* We are scanning "memory" nodes only */ +if (type ==NULL ) +return 0 ; +else if (strcmp (type,"memory" ) !=0 ) +return 0 ; + + nid =early_init_of_get_numa_nid (node); + +if (nid ==NUMA_NO_NODE ) +return -EINVAL ; + + reg =of_get_flat_dt_prop (node,"reg" , &length); + endp = reg + (length /sizeof (__be32)); + +while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { +u64 base, size; +struct memblock_region *mblk; + + base =dt_mem_next_cell (dt_root_addr_cells, ®); + size =dt_mem_next_cell (dt_root_size_cells, ®); +pr_debug ("NUMA-DT: base = %llx , node = %u\n" , + base, nid);arch/arm64/kernel/of_numa.c line 180
Quoted 10 lines
arch/arm64/kernel/of_numa.c new file +10
-0+ +for_each_memblock (memory, mblk) { +if (mblk->base == base) { +if (numa_add_memblk (nid, + mblk->base, + mblk->size) <0 ) +return -EINVAL ; +break ; + } + }Maybe this is not right. If the memory spaces of NUMA nodes are continuous like below:
memory at 60000000 { numa-node-id = <0x1>; reg = <0x0 0x60000000 0x0 0x20000000>; device_type = "memory"; }; memory at 40000000 { numa-node-id = <0x0>; reg = <0x0 0x40000000 0x0 0x20000000>; device_type = "memory"; };
Quoted 7 lines
There is only one memory region [0x00000040000000-0x0000007fffffff] and the
mblk->baseis 40000000, so it will not add the memory node 1.I think this should do the same thing like
ACPI_NUMAbut add some codes to check if the [base, base + size] is located in some memory region. Or don't check becausenuma_add_memblkwill fail if the [base, base + size] is not located in some memory region.
i am not sure, this kind of mapping we can have, since memblock can only map contiguous region to only one numa node. however i can add a check as you suggested.
Thanks for the review!.
Quoted 5 lines
Thanks,
--
Shannon
thanks
Ganapat
PATCH v7 4/4 arm64, dt, thunderx: Add initial dts for Cavium Thunderx in 2 node topology.
In reply to Ganapatrao KulkarniAdding dt file for Cavium's Thunderx dual socket platform.
--- arch/arm64/boot/dts/cavium/Makefile | 2 +- arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts | 83 +++ arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi | 806 ++++++++++++++++++++++++ 3 files changed, 890 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts create mode 100644 arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi
arch/arm64/boot/dts/cavium/Makefile +1 -1
@@ -1,4 +1,4 @@ -dtb-$(CONFIG_ARCH_THUNDER) += thunder-88xx.dtb +dtb-$(CONFIG_ARCH_THUNDER) += thunder-88xx.dtb thunder-88xx-2n.dtb always := $(dtb-y) subdir-y := $(dts-dirs)
arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts new file +83 -0
83 lines not on this page · raw message
arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi new file +806 -0
806 lines not on this page · raw message
Signature · 1 line
1.8.1.4
v7 cover arm64, numa: Add numa support for arm64 platforms
In reply to Ganapatrao KulkarniHi All, Mark R,
please review!!
thanks,
Ganapat
Quoted 71 lines · Ganapatrao Kulkarni
v7:
- managing numa memory mapping using memblock.
- Incorporated review comments of Mark Rutland.v6:
- defined and implemented the numa dt binding using node property proximity and device node distance-map.
- renameddt_numatoof_numav5:
- created base verion ofnuma.cwhich creates dummy numa without using dt on single socket platforms. Then added patches for dt support.
- Incorporated review comments from Hanjun Guo.v4:
done changes as per Arnd review comments.v3:
Added changes to support numa on arm64 based platforms. Tested these patches on cavium's multinode(2 node topology) platform. In this patchset, defined and implemented dt bindings for numa mapping for core and memory using device node property arm,associativity.v2:
Defined and implemented numa map for memory, cores to node and proximity distance matrix of nodes.v1:
Initial patchset to support numa on arm64 platforms.Note:
1. This patchset is tested for numa with dt on
thunderx single socket and dual socket boards.
2. Numa DT booting needs the dt memory nodes, which are deleted in current efi-stub, hence to try numa with dt, you need to rebase with ard's patchset.
http://git.linaro.org/people/ard.biesheuvel/linux-arm.git/shortlog/refs/heads/arm64-uefi-early-fdt-handlingGanapatrao Kulkarni (4):
arm64, numa: adding numa support for arm64 platforms. Documentation, dt, arm64/arm: dt bindings for numa. arm64/arm, numa, dt: adding numa dt binding implementation for arm64
platforms.
arm64, dt, thunderx: Add initial dts for Cavium Thunderx in 2 node
topology.Documentation/devicetree/bindings/arm/numa.txt | 272 ++++++++ arch/arm64/Kconfig | 35 + arch/arm64/boot/dts/cavium/Makefile | 2 +- arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts | 83 +++ arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi | 806 ++++++++++++++++++++++++ arch/arm64/include/asm/mmzone.h | 17 + arch/arm64/include/asm/numa.h | 56 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/of_numa.c | 265 ++++++++ arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 4 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 30 +- arch/arm64/mm/numa.c | 392 ++++++++++++ 14 files changed, 1963 insertions(+), 5 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/numa.txt create mode 100644 arch/arm64/boot/dts/cavium/thunder-88xx-2n.dts create mode 100644 arch/arm64/boot/dts/cavium/thunder-88xx-2n.dtsi create mode 100644 arch/arm64/include/asm/mmzone.h create mode 100644 arch/arm64/include/asm/numa.h create mode 100644 arch/arm64/kernel/of_numa.c create mode 100644 arch/arm64/mm/numa.c--
1.8.1.4