arm64, numa: Add numa support for arm64 platforms
Subsystems (4)
v13 cover arm64, numa: Add numa support for arm64 platforms
From: David Daney <[email protected]>
v13:
- Added patch to unflatten the device tree earlier.
- Rewrote of_numa.c to work on unflattened the device tree.
- Cleanup of EXPORTs in arch/arm64/mm/numa.c as suggested by Will Deacon.
v12:
- Replaced 6 patches from Ard Biesheuvel with new simpler, and more correct, single patch, also from Ard.
v11:
- Dropped cleanup patches for other architectures, they will be submitted as a separate set after more testing.
- Added patch set from Ard Biesheuvel that are needed to make the whole thing actually work. Previously this was a separate set.
- Kconfig and other fixes and simplifications as suggested by Rob Herring.
- Rearranged, refactored and reordered so that we don't patch new files multiple times.
- Summary:
o 6 patches from Ard Biesheuvel to allow use of "memory" nodes with efi stub.
o 2 patches to document and add of_numa.c
o 1 patch to add arm64 NUMA support.
o 1 patch to add NUMA balancing support for arm64.
v10:
- Incorporated review comments from Rob Herring.
- Moved numa binding and implementation to devicetree core.
- Added cleanup patch to remove redundant NODE_DATA macro from asm header files
- Include numa balancing support for arm64 patch in this series.
- Fix tile build issue reported by the kbuild robot(patch 7)
v9: - Added cleanup patch to reuse and avoid redefinition of cpumask_of_pcibus
as suggested from Will Deacon and Bjorn Helgaas.
- Including patch to Make pci-host-generic driver numa aware.
- Incorporated comment from Shannon Zhao.
v8:
- Incorporated review comments of Mark Rutland and Will Deacon.
- Added pci helper function and macro for numa.
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 and without NUMA with dt
(both with and without NUMA bindings) on thunderx single socket and dual socket boards.
Ard Biesheuvel (1):
efi: ARM/arm64: ignore DT memory nodes instead of removing them
David Daney (2):
of, numa: Add NUMA of binding implementation.
arm64: Move unflatten_device_tree() call earlier.
Ganapatrao Kulkarni (3):
Documentation, dt, numa: dt bindings for NUMA. arm64, numa: Add NUMA support for arm64 platforms. arm64, mm, numa: Add NUMA balancing support for arm64.
Documentation/devicetree/bindings/numa.txt | 272 ++++++++++++++++++++ arch/arm64/Kconfig | 27 ++ arch/arm64/include/asm/mmzone.h | 12 + arch/arm64/include/asm/numa.h | 45 ++++ arch/arm64/include/asm/pgtable.h | 15 ++ arch/arm64/include/asm/topology.h | 10 + arch/arm64/kernel/pci.c | 10 + arch/arm64/kernel/setup.c | 11 +- arch/arm64/kernel/smp.c | 4 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 34 ++- arch/arm64/mm/mmu.c | 6 + arch/arm64/mm/numa.c | 396 +++++++++++++++++++++++++++++ drivers/firmware/efi/arm-init.c | 8 + drivers/firmware/efi/libstub/fdt.c | 24 +- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++ include/linux/of.h | 9 + 19 files changed, 1056 insertions(+), 32 deletions(-) create mode 100644 Documentation/devicetree/bindings/numa.txt 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 create mode 100644 drivers/of/of_numa.c
Signature · 1 line
1.8.3.1
PATCH v13 1/6 efi: ARM/arm64: ignore DT memory nodes instead of removing them
From: Ard Biesheuvel <[email protected]>
There are two problems with the UEFI stub DT memory node removal routine:
- it deletes nodes as it traverses the tree, which happens to work but is not supported, as deletion invalidates the node iterator;
- deleting memory nodes entirely may discard annotations in the form of additional properties on the nodes.
Since the discovery of DT memory nodes occurs strictly before the UEFI init sequence, we can simply clear the memblock memory table before parsing the UEFI memory map. This way, it is no longer necessary to remove the nodes, so we can remove that logic from the stub as well.
--- drivers/firmware/efi/arm-init.c | 8 ++++++++ drivers/firmware/efi/libstub/fdt.c | 24 +----------------------- 2 files changed, 9 insertions(+), 23 deletions(-)
drivers/firmware/efi/arm-init.c +8 -0
@@ -143,6 +143,14 @@ static __init void reserve_regions(void)if (efi_enabled (EFI_DBG ))pr_info ("Processing EFI memory map:\n" ); +/* +* Discard memblocks discovered so far: if there are any at this +* point, they originate from memory nodes in the DT, and UEFI +* uses its own memory map instead. +*/ +memblock_dump_all (); +memblock_remove (0 ,ULLONG_MAX ); +for_each_efi_memory_desc (&memmap, md) { paddr = md->phys_addr; npages = md->num_pages;
drivers/firmware/efi/libstub/fdt.c +1 -23
@@ -24,7 +24,7 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, unsigned long map_size, unsigned long desc_size, u32 desc_ver) { - int node, prev, num_rsv; + int node, num_rsv;int status;u32 fdt_val32;u64 fdt_val64;
@@ -54,28 +54,6 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, goto fdt_set_fail;/* -* Delete any memory nodes present. We must delete nodes which -* early_init_dt_scan_memory may try to use. -*/ - prev =0 ; -for (;;) { -const char *type; -int len; - - node =fdt_next_node (fdt, prev,NULL ); -if (node <0 ) -break ; - - type =fdt_getprop (fdt, node,"device_type" , &len); -if (type &&strncmp (type,"memory" , len) ==0 ) { -fdt_del_node (fdt, node); -continue ; - } - - prev = node; - } - -/* * Delete all memory reserve map entries. When booting via UEFI, * kernel will use the UEFI memory map to find reserved regions. */
Signature · 1 line
1.8.3.1
PATCH v13 2/6 Documentation, dt, numa: dt bindings for NUMA.
In reply to David DaneyFrom: Ganapatrao Kulkarni <[email protected]>
Add DT bindings for numa mapping of memory, CPUs and IOs.
--- Documentation/devicetree/bindings/numa.txt | 272 +++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 Documentation/devicetree/bindings/numa.txt
Documentation/devicetree/bindings/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 +============================================================================== + +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. + +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. + The distances are equal in either direction. + 2. The distance from a node to self (local distance) is represented + with value 10 and all internode distance should be represented with + a value greater than 10. + 3. distance-matrix should have entries in lexicographical ascending + order of nodes. + 4. There must be only one device node distance-map which 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 internode distance would 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>; + }; + +============================================================================== +4 - Example dts +============================================================================== + +Dual socket 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 c00000 { + device_type = "memory"; + reg = <0x0 0xc00000 0x0 0x80000000>; + /* node 0 */ + numa-node-id = <0>; + }; + + memory at 10000000000 { + device_type = "memory"; + reg = <0x100 0x0 0x0 0x80000000>; + /* node 1 */ + numa-node-id = <1>; + }; + + cpus { + #address-cells = <2>; + #size-cells = <0>; + + cpu at 0 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x0>; + enable-method = "psci"; + /* node 0 */ + numa-node-id = <0>; + }; + cpu at 1 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x1>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 2 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x2>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 3 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x3>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 4 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x4>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 5 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x5>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 6 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x6>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 7 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x7>; + enable-method = "psci"; + numa-node-id = <0>; + }; + cpu at 8 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x8>; + enable-method = "psci"; + /* node 1 */ + numa-node-id = <1>; + }; + cpu at 9 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0x9>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at a { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0xa>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at b { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0xb>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at c { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0xc>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at d { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0xd>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at e { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0xe>; + enable-method = "psci"; + numa-node-id = <1>; + }; + cpu at f { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x0 0xf>; + enable-method = "psci"; + numa-node-id = <1>; + }; + }; + + pcie0: pcie0 at 848000000000 { + 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 948000000000 { + 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.3.1
PATCH v13 3/6 of, numa: Add NUMA of binding implementation.
In reply to David DaneyFrom: David Daney <[email protected]>
Add device tree parsing for NUMA topology using device "numa-node-id" property in distance-map and cpu nodes.
This is a complete rewrite of a previous patch by:
Ganapatrao Kulkarni<[email protected]>
--- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++ 4 files changed, 213 insertions(+) create mode 100644 drivers/of/of_numa.c
drivers/of/Kconfig +3 -0
@@ -112,4 +112,7 @@ config OF_OVERLAY While this option is selected automatically when needed, you can enable it manually to improve device tree unit test coverage. +config OF_NUMA + bool + endif # OF
drivers/of/Makefile +1 -0
@@ -14,5 +14,6 @@ obj-$(CONFIG_OF_MTD) += of_mtd.o obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o +obj-$(CONFIG_OF_NUMA) += of_numa.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/
drivers/of/of_numa.c new file +200 -0
200 lines not on this page · raw message
include/linux/of.h +9 -0
@@ -685,6 +685,15 @@ static inline int of_node_to_nid(struct device_node *device) }#endif +#ifdef CONFIG_OF_NUMA +extern int of_numa_init (void ); +#else +static inline int of_numa_init (void ) +{ +return -ENOSYS ; +} +#endif +static inline struct device_node *of_find_matching_node (struct device_node *from,const struct of_device_id *matches)
Signature · 1 line
1.8.3.1
Re: [PATCH v13 3/6] of, numa: Add NUMA of binding implementation.
Quoted 56 lines · David Daney
From: David Daney <[email protected]>
Add device tree parsing for NUMA topology using device "numa-node-id" property in distance-map and cpu nodes.
This is a complete rewrite of a previous patch by:
Ganapatrao Kulkarni<[email protected]>Signed-off-by David Daney <[email protected]>--- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++ 4 files changed, 213 insertions(+) create mode 100644 drivers/of/of_numa.cdrivers/of/Kconfig +3
-0@@ -112,4 +112,7 @@ config OF_OVERLAY While this option is selected automatically when needed, you can enable it manually to improve device tree unit test coverage. +config OF_NUMA + bool + endif # OFdrivers/of/Makefile +1
-0@@ -14,5 +14,6 @@ obj-$(CONFIG_OF_MTD) += of_mtd.o obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o +obj-$(CONFIG_OF_NUMA) += of_numa.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/drivers/of/of_numa.c new file +10
-0@@ -0,0 +1,200 @@ +/* +* OF NUMA Parsing support. +* +* Copyright (C) 2015 - 2016 Cavium Inc. +* +* 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,
drivers/of/of_numa.c line 20
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+* 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/of.h> +#include <linux/of_fdt.h>
This can be dropped now.
drivers/of/of_numa.c line 32
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+#include <linux/nodemask.h> + +#include <asm/numa.h> + +/* define default numa node to 0 */ +#define DEFAULT_NODE 0 + +/* +* Even though we connect cpus to numa domains later in SMP +* init, we need to know the node ids now for all cpus. +*/ +static void __init of_find_cpu_nodes (void )
Perhaps of_parse_cpu_nodes for consistency.
Actually, if all the functions were prefixed with "of_numa_" that would be better.
drivers/of/of_numa.c line 41
Quoted 9 lines
drivers/of/of_numa.c new file +9
-0+{ +u32 nid; +int r; +struct device_node *np =NULL ; + +for (;;) { + np =of_find_node_by_type (np,"cpu" ); +if (!np) +break ;
Can't we use the child node iterator for /cpus here?
drivers/of/of_numa.c line 52
Quoted 11 lines
drivers/of/of_numa.c new file +11
-0+ + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + +pr_debug ("NUMA: CPU on %u\n" , nid); +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +node_set (nid, numa_nodes_parsed);
I'm not sure how this works, but don't you need to match this up with MPIDR of the cpu here?
Quoted 27 lines
drivers/of/of_numa.c new file +26
-0+ } +} + +static void __init of_parse_memory_nodes (void ) +{ +struct device_node *np =NULL ; +int na, ns; +const __be32 *prop; +unsigned int psize; +u32 nid; +u64 base, size; +int r; + +for (;;) { + np =of_find_node_by_type (np,"memory" ); +if (!np) +break ; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + + prop =of_get_property (np,"reg" , &psize); +if (!prop) +continue ; +
drivers/of/of_numa.c line 88
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ psize /=sizeof (__be32); + na =of_n_addr_cells (np); + ns =of_n_size_cells (np); + +if (psize < na + ns) { +pr_err ("NUMA: memory reg property too small\n" ); +continue ; + } + base =of_read_number (prop, na); + size =of_read_number (prop + na, ns);
You should be able to use of_address_to_resource for all this.
Quoted 8 lines
drivers/of/of_numa.c new file +8
-0+ +pr_debug ("NUMA: base = %llx len = %llx, node = %u\n" , + base, size, nid); + +if (numa_add_memblk (nid, base, size) <0 ) +break ; + } +
drivers/of/of_numa.c line 106
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+of_node_put (np); +} + +static int __init parse_distance_map_v1 (struct device_node *map) +{ +const __be32 *matrix; +unsigned int matrix_size; +int entry_count; +int i; +int nr_size_cells =OF_ROOT_NODE_SIZE_CELLS_DEFAULT ;
I believe the defaults are for some old DT files. As this is new, it should rely on explicit #size-cells in the DT.
OTOH, what is point of using #size-cells at all versus fixing the sizes to 1 cell. The documentation doesn't indicate that it uses #size-cells. That also means that the sizes basically follow the cell size for the memory given that this is at the top-level.
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +pr_info ("NUMA: parsing numa-distance-map-v1\n" ); + + matrix =of_get_property (map,"distance-matrix" , &matrix_size); +if (!matrix) { +pr_err ("NUMA: No distance-matrix property in distance-map\n" ); +return -EINVAL ; + } + + entry_count = matrix_size / (sizeof (__be32) *3 * nr_size_cells);
drivers/of/of_numa.c line 126
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +for (i =0 ; i < entry_count; i++) { +u32 nodea, nodeb, distance; + + nodea =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + nodeb =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + distance =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells;
Assuming you fix this to 1 cell, you can use of_property_count_u32_elems and of_property_read_u32_array.
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+ +numa_set_distance (nodea, nodeb, distance); +pr_debug ("NUMA: distance[node%d -> node%d] = %d\n" , + nodea, nodeb, distance); + +/* Set default distance of node B->A same as A->B */ +if (nodeb > nodea) +numa_set_distance (nodeb, nodea, distance); + } + +return 0 ; +}
drivers/of/of_numa.c line 148
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +static int __init of_parse_distance_map (void ) +{ +int ret = -EINVAL ; +struct device_node *np =of_find_node_by_name (NULL ,"distance-map" ); + +if (!np) +return ret; + +if (of_device_is_compatible (np,"numa-distance-map-v1" )) {
You can use of_find_compatible_node() instead of these 2 calls.
Quoted 13 lines
drivers/of/of_numa.c new file +13
-0+ ret =parse_distance_map_v1 (np); + goto out; + } + +pr_err ("NUMA: invalid distance-map device node\n" ); +out: +of_node_put (np); +return ret; +} + +int of_node_to_nid (struct device_node *device) +{ +struct device_node *np;
drivers/of/of_numa.c line 171
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+u32 nid; +int r = -ENODATA ; + + np =of_node_get (device); + +while (np) { +struct device_node *parent; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r != -EINVAL )
You want to break for other err values?
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+break ; + +/* property doesn't exist in this node, look in parent */ + parent =of_get_parent (np); +of_node_put (np); + np = parent; + } +if (np && r) +pr_warn ("NUMA: Invalid \"numa-node-id\" property in node %s\n" , + np->name); +of_node_put (np); +
drivers/of/of_numa.c line 193
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+if (!r) { +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +return nid; + } + +return NUMA_NO_NODE ; +}
Needs to be exported?
Quoted 30 lines
drivers/of/of_numa.c new file +7
-0+ +int __init of_numa_init (void ) +{ +of_find_cpu_nodes (); +of_parse_memory_nodes (); +return of_parse_distance_map (); +}include/linux/of.h +9
-1@@ -685,6 +685,15 @@ static inline int of_node_to_nid(struct device_node *device) }#endif +#ifdef CONFIG_OF_NUMA +extern int of_numa_init (void ); +#else +static inline int of_numa_init (void ) +{ +return -ENOSYS ; +} +#endif +static inline struct device_node *of_find_matching_node (struct device_node *from,const struct of_device_id *matches) --1.8.3.1
Re: [PATCH v13 3/6] of, numa: Add NUMA of binding implementation.
Quoted 177 lines · Rob Herring
Quoted 56 lines · David Daney
From: David Daney <[email protected]>
Add device tree parsing for NUMA topology using device "numa-node-id" property in distance-map and cpu nodes.
This is a complete rewrite of a previous patch by:
Ganapatrao Kulkarni<[email protected]>Signed-off-by David Daney <[email protected]>--- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++ 4 files changed, 213 insertions(+) create mode 100644 drivers/of/of_numa.cdrivers/of/Kconfig +3
-0@@ -112,4 +112,7 @@ config OF_OVERLAY While this option is selected automatically when needed, you can enable it manually to improve device tree unit test coverage. +config OF_NUMA + bool + endif # OFdrivers/of/Makefile +1
-0@@ -14,5 +14,6 @@ obj-$(CONFIG_OF_MTD) += of_mtd.o obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o +obj-$(CONFIG_OF_NUMA) += of_numa.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/drivers/of/of_numa.c new file +10
-0@@ -0,0 +1,200 @@ +/* +* OF NUMA Parsing support. +* +* Copyright (C) 2015 - 2016 Cavium Inc. +* +* 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, drivers/of/of_numa.c line 20
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+* 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/of.h> +#include <linux/of_fdt.h> This can be dropped now.
drivers/of/of_numa.c line 32
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+#include <linux/nodemask.h> + +#include <asm/numa.h> + +/* define default numa node to 0 */ +#define DEFAULT_NODE 0 + +/* +* Even though we connect cpus to numa domains later in SMP +* init, we need to know the node ids now for all cpus. +*/ +static void __init of_find_cpu_nodes (void )Perhaps
of_parse_cpu_nodesfor consistency.Actually, if all the functions were prefixed with "
of_numa_" that would be better.drivers/of/of_numa.c line 41
Quoted 9 lines
drivers/of/of_numa.c new file +9
-0+{ +u32 nid; +int r; +struct device_node *np =NULL ; + +for (;;) { + np =of_find_node_by_type (np,"cpu" ); +if (!np) +break ;Can't we use the child node iterator for /cpus here?
drivers/of/of_numa.c line 52
Quoted 11 lines
drivers/of/of_numa.c new file +11
-0+ + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + +pr_debug ("NUMA: CPU on %u\n" , nid); +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +node_set (nid, numa_nodes_parsed);I'm not sure how this works, but don't you need to match this up with MPIDR of the cpu here?
Quoted 27 lines
drivers/of/of_numa.c new file +26
-0+ } +} + +static void __init of_parse_memory_nodes (void ) +{ +struct device_node *np =NULL ; +int na, ns; +const __be32 *prop; +unsigned int psize; +u32 nid; +u64 base, size; +int r; + +for (;;) { + np =of_find_node_by_type (np,"memory" ); +if (!np) +break ; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + + prop =of_get_property (np,"reg" , &psize); +if (!prop) +continue ; +drivers/of/of_numa.c line 88
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ psize /=sizeof (__be32); + na =of_n_addr_cells (np); + ns =of_n_size_cells (np); + +if (psize < na + ns) { +pr_err ("NUMA: memory reg property too small\n" ); +continue ; + } + base =of_read_number (prop, na); + size =of_read_number (prop + na, ns);You should be able to use
of_address_to_resourcefor all this.Quoted 8 lines
drivers/of/of_numa.c new file +8
-0+ +pr_debug ("NUMA: base = %llx len = %llx, node = %u\n" , + base, size, nid); + +if (numa_add_memblk (nid, base, size) <0 ) +break ; + } +drivers/of/of_numa.c line 106
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+of_node_put (np); +} + +static int __init parse_distance_map_v1 (struct device_node *map) +{ +const __be32 *matrix; +unsigned int matrix_size; +int entry_count; +int i; +int nr_size_cells =OF_ROOT_NODE_SIZE_CELLS_DEFAULT ;I believe the defaults are for some old DT files. As this is new, it should rely on explicit #size-cells in the DT.
Quoted 4 lines
OTOH, what is point of using #size-cells at all versus fixing the sizes to 1 cell. The documentation doesn't indicate that it uses #size-cells. That also means that the sizes basically follow the cell size for the memory given that this is at the top-level.
This property needs only size-cell of 1 (32 bit is sufficient to define numa node id and their relative distance)
adding note about cell size of this property in binding will clear the doubt.
Quoted 116 lines
Quoted 11 lines
drivers/of/of_numa.c new file +10
-0+ +pr_info ("NUMA: parsing numa-distance-map-v1\n" ); + + matrix =of_get_property (map,"distance-matrix" , &matrix_size); +if (!matrix) { +pr_err ("NUMA: No distance-matrix property in distance-map\n" ); +return -EINVAL ; + } + + entry_count = matrix_size / (sizeof (__be32) *3 * nr_size_cells);drivers/of/of_numa.c line 126
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +for (i =0 ; i < entry_count; i++) { +u32 nodea, nodeb, distance; + + nodea =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + nodeb =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + distance =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells;Assuming you fix this to 1 cell, you can use
of_property_count_u32_elemsandof_property_read_u32_array.Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+ +numa_set_distance (nodea, nodeb, distance); +pr_debug ("NUMA: distance[node%d -> node%d] = %d\n" , + nodea, nodeb, distance); + +/* Set default distance of node B->A same as A->B */ +if (nodeb > nodea) +numa_set_distance (nodeb, nodea, distance); + } + +return 0 ; +}drivers/of/of_numa.c line 148
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +static int __init of_parse_distance_map (void ) +{ +int ret = -EINVAL ; +struct device_node *np =of_find_node_by_name (NULL ,"distance-map" ); + +if (!np) +return ret; + +if (of_device_is_compatible (np,"numa-distance-map-v1" )) {You can use
of_find_compatible_node()instead of these 2 calls.Quoted 13 lines
drivers/of/of_numa.c new file +13
-0+ ret =parse_distance_map_v1 (np); + goto out; + } + +pr_err ("NUMA: invalid distance-map device node\n" ); +out: +of_node_put (np); +return ret; +} + +int of_node_to_nid (struct device_node *device) +{ +struct device_node *np;drivers/of/of_numa.c line 171
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+u32 nid; +int r = -ENODATA ; + + np =of_node_get (device); + +while (np) { +struct device_node *parent; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r != -EINVAL )You want to break for other err values?
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+break ; + +/* property doesn't exist in this node, look in parent */ + parent =of_get_parent (np); +of_node_put (np); + np = parent; + } +if (np && r) +pr_warn ("NUMA: Invalid \"numa-node-id\" property in node %s\n" , + np->name); +of_node_put (np); +drivers/of/of_numa.c line 193
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+if (!r) { +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +return nid; + } + +return NUMA_NO_NODE ; +}Needs to be exported?
Quoted 15 lines
drivers/of/of_numa.c new file +7
-0+ +int __init of_numa_init (void ) +{ +of_find_cpu_nodes (); +of_parse_memory_nodes (); +return of_parse_distance_map (); +}include/linux/of.h +0
-0@@ -685,6 +685,15 @@ static inline int of_node_to_nid(struct device_node *device) }#endif
Quoted 16 lines
Quoted 13 lines
include/linux/of.h +9
-1+#ifdef CONFIG_OF_NUMA +extern int of_numa_init (void ); +#else +static inline int of_numa_init (void ) +{ +return -ENOSYS ; +} +#endif +static inline struct device_node *of_find_matching_node (struct device_node *from,const struct of_device_id *matches) --Quoted 2 lines
1.8.3.1
thanks
Ganapat
Quoted 4 lines
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v13 3/6] of, numa: Add NUMA of binding implementation.
Quoted 101 lines · Ganapatrao Kulkarni
Quoted 100 lines · Rob Herring
Quoted 56 lines · David Daney
From: David Daney <[email protected]>
Add device tree parsing for NUMA topology using device "numa-node-id" property in distance-map and cpu nodes.
This is a complete rewrite of a previous patch by:
Ganapatrao Kulkarni<[email protected]>Signed-off-by David Daney <[email protected]>--- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++ 4 files changed, 213 insertions(+) create mode 100644 drivers/of/of_numa.cdrivers/of/Kconfig +3
-0@@ -112,4 +112,7 @@ config OF_OVERLAY While this option is selected automatically when needed, you can enable it manually to improve device tree unit test coverage. +config OF_NUMA + bool + endif # OFdrivers/of/Makefile +1
-0@@ -14,5 +14,6 @@ obj-$(CONFIG_OF_MTD) += of_mtd.o obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o +obj-$(CONFIG_OF_NUMA) += of_numa.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/drivers/of/of_numa.c new file +10
-0@@ -0,0 +1,200 @@ +/* +* OF NUMA Parsing support. +* +* Copyright (C) 2015 - 2016 Cavium Inc. +* +* 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, drivers/of/of_numa.c line 20
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+* 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/of.h> +#include <linux/of_fdt.h> This can be dropped now.
drivers/of/of_numa.c line 32
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+#include <linux/nodemask.h> + +#include <asm/numa.h> + +/* define default numa node to 0 */ +#define DEFAULT_NODE 0 + +/* +* Even though we connect cpus to numa domains later in SMP +* init, we need to know the node ids now for all cpus. +*/ +static void __init of_find_cpu_nodes (void )Perhaps
of_parse_cpu_nodesfor consistency.Actually, if all the functions were prefixed with "
of_numa_" that would be better.drivers/of/of_numa.c line 41
Quoted 9 lines
drivers/of/of_numa.c new file +9
-0+{ +u32 nid; +int r; +struct device_node *np =NULL ; + +for (;;) { + np =of_find_node_by_type (np,"cpu" ); +if (!np) +break ;Can't we use the child node iterator for /cpus here?
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/of/of_numa.c new file +6
-0+ + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + +pr_debug ("NUMA: CPU on %u\n" , nid);Quoted 8 lines
drivers/of/of_numa.c line 52
Quoted 5 lines
drivers/of/of_numa.c new file +5
-0+if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +node_set (nid, numa_nodes_parsed);I'm not sure how this works, but don't you need to match this up with MPIDR of the cpu here?
we are parsing cpu node to know the number of nodes present in the system. alone memory will not convey the number of numa nodes present in the system(in some cases like node has cpu but no memory).
we do mapping of cpu logical id and numa node id in smp init when cpu logical id is numbered(of_parse_and_init_cpus).
and logical id is already mapped to hwid/MPIDR.
Quoted 63 lines
Quoted 63 lines
Quoted 28 lines
drivers/of/of_numa.c new file +26
-0+ } +} + +static void __init of_parse_memory_nodes (void ) +{ +struct device_node *np =NULL ; +int na, ns; +const __be32 *prop; +unsigned int psize; +u32 nid; +u64 base, size; +int r; + +for (;;) { + np =of_find_node_by_type (np,"memory" ); +if (!np) +break ; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + + prop =of_get_property (np,"reg" , &psize); +if (!prop) +continue ; +drivers/of/of_numa.c line 88
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ psize /=sizeof (__be32); + na =of_n_addr_cells (np); + ns =of_n_size_cells (np); + +if (psize < na + ns) { +pr_err ("NUMA: memory reg property too small\n" ); +continue ; + } + base =of_read_number (prop, na); + size =of_read_number (prop + na, ns);You should be able to use
of_address_to_resourcefor all this.Quoted 8 lines
drivers/of/of_numa.c new file +8
-0+ +pr_debug ("NUMA: base = %llx len = %llx, node = %u\n" , + base, size, nid); + +if (numa_add_memblk (nid, base, size) <0 ) +break ; + } +drivers/of/of_numa.c line 106
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+of_node_put (np); +} + +static int __init parse_distance_map_v1 (struct device_node *map) +{ +const __be32 *matrix; +unsigned int matrix_size; +int entry_count; +int i; +int nr_size_cells =OF_ROOT_NODE_SIZE_CELLS_DEFAULT ;I believe the defaults are for some old DT files. As this is new, it should rely on explicit #size-cells in the DT.
Quoted 140 lines
Quoted 4 lines
OTOH, what is point of using #size-cells at all versus fixing the sizes to 1 cell. The documentation doesn't indicate that it uses #size-cells. That also means that the sizes basically follow the cell size for the memory given that this is at the top-level.
This property needs only size-cell of 1 (32 bit is sufficient to define numa node id and their relative distance)
adding note about cell size of this property in binding will clear the doubt.Quoted 132 lines
Quoted 11 lines
drivers/of/of_numa.c new file +10
-0+ +pr_info ("NUMA: parsing numa-distance-map-v1\n" ); + + matrix =of_get_property (map,"distance-matrix" , &matrix_size); +if (!matrix) { +pr_err ("NUMA: No distance-matrix property in distance-map\n" ); +return -EINVAL ; + } + + entry_count = matrix_size / (sizeof (__be32) *3 * nr_size_cells);drivers/of/of_numa.c line 126
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +for (i =0 ; i < entry_count; i++) { +u32 nodea, nodeb, distance; + + nodea =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + nodeb =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + distance =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells;Assuming you fix this to 1 cell, you can use
of_property_count_u32_elemsandof_property_read_u32_array.Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+ +numa_set_distance (nodea, nodeb, distance); +pr_debug ("NUMA: distance[node%d -> node%d] = %d\n" , + nodea, nodeb, distance); + +/* Set default distance of node B->A same as A->B */ +if (nodeb > nodea) +numa_set_distance (nodeb, nodea, distance); + } + +return 0 ; +}drivers/of/of_numa.c line 148
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ +static int __init of_parse_distance_map (void ) +{ +int ret = -EINVAL ; +struct device_node *np =of_find_node_by_name (NULL ,"distance-map" ); + +if (!np) +return ret; + +if (of_device_is_compatible (np,"numa-distance-map-v1" )) {You can use
of_find_compatible_node()instead of these 2 calls.Quoted 13 lines
drivers/of/of_numa.c new file +13
-0+ ret =parse_distance_map_v1 (np); + goto out; + } + +pr_err ("NUMA: invalid distance-map device node\n" ); +out: +of_node_put (np); +return ret; +} + +int of_node_to_nid (struct device_node *device) +{ +struct device_node *np;drivers/of/of_numa.c line 171
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+u32 nid; +int r = -ENODATA ; + + np =of_node_get (device); + +while (np) { +struct device_node *parent; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r != -EINVAL )You want to break for other err values?
Quoted 12 lines
drivers/of/of_numa.c new file +12
-0+break ; + +/* property doesn't exist in this node, look in parent */ + parent =of_get_parent (np); +of_node_put (np); + np = parent; + } +if (np && r) +pr_warn ("NUMA: Invalid \"numa-node-id\" property in node %s\n" , + np->name); +of_node_put (np); +drivers/of/of_numa.c line 193
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+if (!r) { +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +return nid; + } + +return NUMA_NO_NODE ; +}Needs to be exported?
Quoted 30 lines
drivers/of/of_numa.c new file +7
-0+ +int __init of_numa_init (void ) +{ +of_find_cpu_nodes (); +of_parse_memory_nodes (); +return of_parse_distance_map (); +}include/linux/of.h +9
-1@@ -685,6 +685,15 @@ static inline int of_node_to_nid(struct device_node *device) }#endif +#ifdef CONFIG_OF_NUMA +extern int of_numa_init (void ); +#else +static inline int of_numa_init (void ) +{ +return -ENOSYS ; +} +#endif +static inline struct device_node *of_find_matching_node (struct device_node *from,const struct of_device_id *matches) --1.8.3.1
Ganapat
Quoted 8 lines
thanks
GanapatQuoted 4 lines
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v13 3/6] of, numa: Add NUMA of binding implementation.
In reply to Rob HerringQuoted 18 lines · Rob Herring
Quoted 17 lines · David Daney
From: David Daney <[email protected]>
Add device tree parsing for NUMA topology using device "numa-node-id" property in distance-map and cpu nodes.
This is a complete rewrite of a previous patch by:
Ganapatrao Kulkarni<[email protected]>Signed-off-by David Daney <[email protected]>--- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++ 4 files changed, 213 insertions(+)create mode 100644
drivers/of/of_numa.c
[...]
Quoted 16 lines
Quoted 16 lines
+++
b/drivers/of/of_numa.cdrivers/of/of_numa.c new file +14
-0@@ -0,0 +1,200 @@ +/* +* OF NUMA Parsing support. +* +* Copyright (C) 2015 - 2016 Cavium Inc. +* +* 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. +*
Quoted 8 lines
drivers/of/of_numa.c line 20
Quoted 6 lines
drivers/of/of_numa.c new file +6
-0+* 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/of.h> +#include <linux/of_fdt.h> This can be dropped now.
Yes.
Quoted 16 lines
drivers/of/of_numa.c line 32
Quoted 13 lines
drivers/of/of_numa.c new file +12
-0+#include <linux/nodemask.h> + +#include <asm/numa.h> + +/* define default numa node to 0 */ +#define DEFAULT_NODE 0 + +/* +* Even though we connect cpus to numa domains later in SMP +* init, we need to know the node ids now for all cpus. +*/ +static void __init of_find_cpu_nodes (void )Perhaps
of_parse_cpu_nodesfor consistency.
Quoted 3 lines
Actually, if all the functions were prefixed with "
of_numa_" that would be better.
OK, I will do that.
Quoted 11 lines
drivers/of/of_numa.c line 41
Quoted 9 lines
drivers/of/of_numa.c new file +9
-0+{ +u32 nid; +int r; +struct device_node *np =NULL ; + +for (;;) { + np =of_find_node_by_type (np,"cpu" ); +if (!np) +break ;Can't we use the child node iterator for /cpus here?
I will try to do something like that.
Quoted 15 lines
drivers/of/of_numa.c line 52
Quoted 12 lines
drivers/of/of_numa.c new file +11
-0+ + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; + +pr_debug ("NUMA: CPU on %u\n" , nid); +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid); +else +node_set (nid, numa_nodes_parsed);I'm not sure how this works, but don't you need to match this up with MPIDR of the cpu here?
As Ganapatrao said in the other e-mail, all we are doing is discovering which nodes have a CPU here. At this point we don't care about any other properties of the individual CPUs.
Quoted 24 lines
Quoted 23 lines
drivers/of/of_numa.c new file +22
-0+ } +} + +static void __init of_parse_memory_nodes (void ) +{ +struct device_node *np =NULL ; +int na, ns; +const __be32 *prop; +unsigned int psize; +u32 nid; +u64 base, size; +int r; + +for (;;) { + np =of_find_node_by_type (np,"memory" ); +if (!np) +break ; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r) +continue ; +
Quoted 17 lines
Quoted 4 lines
drivers/of/of_numa.c new file +4
-0+ prop =of_get_property (np,"reg" , &psize); +if (!prop) +continue ; +drivers/of/of_numa.c line 88
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+ psize /=sizeof (__be32); + na =of_n_addr_cells (np); + ns =of_n_size_cells (np); + +if (psize < na + ns) { +pr_err ("NUMA: memory reg property too small\n" ); +continue ; + } + base =of_read_number (prop, na); + size =of_read_number (prop + na, ns);You should be able to use
of_address_to_resourcefor all this.
I thought about doing that. It would make the code simpler. I was concerned about the address translation that is done, but since these are at the root level there should be no translation. I will change the code to do this.
Quoted 22 lines
Quoted 8 lines
drivers/of/of_numa.c new file +8
-0+ +pr_debug ("NUMA: base = %llx len = %llx, node = %u\n" , + base, size, nid); + +if (numa_add_memblk (nid, base, size) <0 ) +break ; + } +drivers/of/of_numa.c line 106
Quoted 10 lines
drivers/of/of_numa.c new file +10
-0+of_node_put (np); +} + +static int __init parse_distance_map_v1 (struct device_node *map) +{ +const __be32 *matrix; +unsigned int matrix_size; +int entry_count; +int i; +int nr_size_cells =OF_ROOT_NODE_SIZE_CELLS_DEFAULT ;I believe the defaults are for some old DT files. As this is new, it should rely on explicit #size-cells in the DT.
Quoted 4 lines
OTOH, what is point of using #size-cells at all versus fixing the sizes to 1 cell. The documentation doesn't indicate that it uses #size-cells. That also means that the sizes basically follow the cell size for the memory given that this is at the top-level.
I think we should start with specifying that all elements are a single cell. In the future if this turns out to be insufficient, the binding could easily be extended to include a #node-id-size or something similar.
I will simplify the code to assume a single cell.
Quoted 16 lines
Quoted 16 lines
drivers/of/of_numa.c new file +15
-0+ +pr_info ("NUMA: parsing numa-distance-map-v1\n" ); + + matrix =of_get_property (map,"distance-matrix" , &matrix_size); +if (!matrix) { +pr_err ("NUMA: No distance-matrix property in distance-map\n" ); +return -EINVAL ; + } + + entry_count = matrix_size / (sizeof (__be32) *3 * nr_size_cells); + +for (i =0 ; i < entry_count; i++) { +u32 nodea, nodeb, distance; + + nodea =of_read_number (matrix, nr_size_cells);
Quoted 8 lines
drivers/of/of_numa.c line 126
Quoted 5 lines
drivers/of/of_numa.c new file +5
-0+ matrix += nr_size_cells; + nodeb =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells; + distance =of_read_number (matrix, nr_size_cells); + matrix += nr_size_cells;Assuming you fix this to 1 cell, you can use
of_property_count_u32_elemsandof_property_read_u32_array.
The number of elements in the array could be large. We would have to do dynamic memory allocation to be able to use of_property_read_u32_array.
I would prefer to iterate through the array like this to avoid having
to allocate memory.
Quoted 17 lines
Quoted 17 lines
drivers/of/of_numa.c new file +16
-0+ +numa_set_distance (nodea, nodeb, distance); +pr_debug ("NUMA: distance[node%d -> node%d] = %d\n" , + nodea, nodeb, distance); + +/* Set default distance of node B->A same as A->B */ +if (nodeb > nodea) +numa_set_distance (nodeb, nodea, distance); + } + +return 0 ; +} + +static int __init of_parse_distance_map (void ) +{ +int ret = -EINVAL ;
Quoted 8 lines
drivers/of/of_numa.c line 148
Quoted 6 lines
drivers/of/of_numa.c new file +6
-0+struct device_node *np =of_find_node_by_name (NULL ,"distance-map" ); + +if (!np) +return ret; + +if (of_device_is_compatible (np,"numa-distance-map-v1" )) {You can use
of_find_compatible_node()instead of these 2 calls.
Well, we need to match exactly the name "distance-map", of_find_compatible_node() doesn't match on the name, so I think we need two checks, one for name and one for compatible.
Quoted 18 lines
Quoted 18 lines
drivers/of/of_numa.c new file +17
-0+ ret =parse_distance_map_v1 (np); + goto out; + } + +pr_err ("NUMA: invalid distance-map device node\n" ); +out: +of_node_put (np); +return ret; +} + +int of_node_to_nid (struct device_node *device) +{ +struct device_node *np; +u32 nid; +int r = -ENODATA ; + + np =of_node_get (device);
Quoted 8 lines
drivers/of/of_numa.c line 171
Quoted 6 lines
drivers/of/of_numa.c new file +6
-0+ +while (np) { +struct device_node *parent; + + r =of_property_read_u32 (np,"numa-node-id" , &nid); +if (r != -EINVAL )You want to break for other err values?
Yes, if the property doesn't exist, we need to check the parent. Otherwise, it indicates an error in the device tree, and we bail out with the warning message.
I will add a comment that explains what we are doing and the significance of -EINVAL
Quoted 17 lines
Quoted 17 lines
drivers/of/of_numa.c new file +16
-0+break ; + +/* property doesn't exist in this node, look in parent */ + parent =of_get_parent (np); +of_node_put (np); + np = parent; + } +if (np && r) +pr_warn ("NUMA: Invalid \"numa-node-id\" property in node %s\n" , + np->name); +of_node_put (np); + +if (!r) { +if (nid >=MAX_NUMNODES ) +pr_warn ("NUMA: Node id %u exceeds maximum value\n" , + nid);
Quoted 8 lines
drivers/of/of_numa.c line 193
Quoted 6 lines
drivers/of/of_numa.c new file +6
-0+else +return nid; + } + +return NUMA_NO_NODE ; +}Needs to be exported?
Good catch. I will export it.
Quoted 31 lines
Quoted 31 lines
drivers/of/of_numa.c new file +7
-0+ +int __init of_numa_init (void ) +{ +of_find_cpu_nodes (); +of_parse_memory_nodes (); +return of_parse_distance_map (); +}include/linux/of.h +9
-1@@ -685,6 +685,15 @@ static inline int of_node_to_nid(struct device_node *device) }#endif +#ifdef CONFIG_OF_NUMA +extern int of_numa_init (void ); +#else +static inline int of_numa_init (void ) +{ +return -ENOSYS ; +} +#endif +static inline struct device_node *of_find_matching_node (struct device_node *from,const struct of_device_id *matches) --1.8.3.1
Re: [PATCH v13 3/6] of, numa: Add NUMA of binding implementation.
Quoted 21 lines · David Daney
Quoted 20 lines · Rob Herring
Quoted 18 lines · David Daney
From: David Daney <[email protected]>
Add device tree parsing for NUMA topology using device "numa-node-id" property in distance-map and cpu nodes.
This is a complete rewrite of a previous patch by:
Ganapatrao Kulkarni<[email protected]>Signed-off-by David Daney <[email protected]>--- drivers/of/Kconfig | 3 + drivers/of/Makefile | 1 + drivers/of/of_numa.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++ 4 files changed, 213 insertions(+)create mode 100644
drivers/of/of_numa.c
[...]
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
drivers/of/of_numa.c new file +4
-0+static int __init of_parse_distance_map (void ) +{ +int ret = -EINVAL ; + struct device_node *np = of_find_node_by_name(NULL,"distance-map");
Quoted 8 lines
drivers/of/of_numa.c line 148
Quoted 5 lines
drivers/of/of_numa.c new file +5
-0+ +if (!np) +return ret; + +if (of_device_is_compatible (np,"numa-distance-map-v1" )) {You can use
of_find_compatible_node()instead of these 2 calls.
Quoted 3 lines
Well, we need to match exactly the name "distance-map",
of_find_compatible_node()doesn't match on the name, so I think we need two checks, one for name and one for compatible.
Node names generally aren't supposed to matter and the kernel's job is not to validate DTs, So just finding the compatible should be enough.
Not a big deal, so I've acked v14. If there's a v15, then please make the change.
Rob
PATCH v13 4/6 arm64: Move unflatten_device_tree() call earlier.
In reply to David DaneyFrom: David Daney <[email protected]>
In order to extract NUMA information from the device tree, we need to have the tree in its unflattened form.
Move the call to unflatten_device_tree() into paging_init(). This puts it before the call to bootmem_init(), which is where the NUMA information is extracted.
--- arch/arm64/kernel/setup.c | 7 +++---- arch/arm64/mm/mmu.c | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-)
arch/arm64/kernel/setup.c +3 -4
@@ -328,12 +328,11 @@ void __init setup_arch(char **cmdline_p)early_ioremap_reset (); -if (acpi_disabled) { -unflatten_device_tree (); +if (acpi_disabled)psci_dt_init (); - }else { +else psci_acpi_init (); - } +xen_early_init ();cpu_read_bootcpu_ops ();
arch/arm64/mm/mmu.c +5 -0
@@ -29,6 +29,8 @@#include <linux/io.h> #include <linux/slab.h> #include <linux/stop_machine.h> +#include <linux/acpi.h> +#include <linux/of_fdt.h> #include <asm/cputype.h> #include <asm/fixmap.h>
@@ -459,6 +461,9 @@ void __init paging_init(void)map_mem ();fixup_executable (); +if (acpi_disabled) +unflatten_device_tree (); +/* allocate the zero page. */ zero_page =early_alloc (PAGE_SIZE );
Signature · 1 line
1.8.3.1
Re: [PATCH v13 4/6] arm64: Move unflatten_device_tree() call earlier.
Quoted 8 lines · David Daney
From: David Daney <[email protected]>
In order to extract NUMA information from the device tree, we need to have the tree in its unflattened form.
Move the call to
unflatten_device_tree()intopaging_init(). This puts it before the call tobootmem_init(), which is where the NUMA information is extracted.
Can't you just move up unflatten_device_tree in setup_arch rather than hiding in paging_init?
Quoted 5 lines
Signed-off-by David Daney <[email protected]>--- arch/arm64/kernel/setup.c | 7 +++---- arch/arm64/mm/mmu.c | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-)
Re: [PATCH v13 4/6] arm64: Move unflatten_device_tree() call earlier.
Quoted 6 lines · Rob Herring
Quoted 5 lines · David Daney
From: David Daney <[email protected]>
In order to extract NUMA information from the device tree, we need to have the tree in its unflattened form.
Quoted 6 lines
Quoted 3 lines
Move the call to
unflatten_device_tree()intopaging_init(). This puts it before the call tobootmem_init(), which is where the NUMA information is extracted.Can't you just move up
unflatten_device_treeinsetup_archrather than hiding inpaging_init?
No.
It must come *after* map_mem() and *before* bootmem_init(), both of which are done within paging_init().
One option would be to split the things in paging_init() into two functions, and then do:
.
.
.
paging_init_first_part();
if (acpi_disabled)
unflatten_device_tree();
paging_init_second_part();.
.
.
Quoted 6 lines
Quoted 6 lines
Signed-off-by David Daney <[email protected]>--- arch/arm64/kernel/setup.c | 7 +++---- arch/arm64/mm/mmu.c | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-)
Re: [PATCH v13 4/6] arm64: Move unflatten_device_tree() call earlier.
Quoted 26 lines · David Daney
Quoted 8 lines · Rob Herring
Quoted 6 lines · David Daney
From: David Daney <[email protected]>
In order to extract NUMA information from the device tree, we need to have the tree in its unflattened form.
Quoted 7 lines
Quoted 3 lines
Move the call to
unflatten_device_tree()intopaging_init(). This puts it before the call tobootmem_init(), which is where the NUMA information is extracted.Can't you just move up
unflatten_device_treeinsetup_archrather than hiding inpaging_init?No.
It must come *after*
map_mem()and *before*bootmem_init(), both of which are done withinpaging_init().One option would be to split the things in
paging_init()into two functions, and then do:
Quoted 8 lines
.
.
.paging_init_first_part(); if (acpi_disabled) unflatten_device_tree(); paging_init_second_part();.
I think it makes more sense to move bootmem_init() to setup_arch() then
PATCH v13 5/6 arm64, numa: Add NUMA support for arm64 platforms.
In reply to David DaneyFrom: Ganapatrao Kulkarni <[email protected]>
Attempt to get the memory and CPU NUMA node via of_numa. If that fails, default the dummy NUMA node and map all memory and CPUs to node 0.
--- arch/arm64/Kconfig | 26 +++ arch/arm64/include/asm/mmzone.h | 12 ++ arch/arm64/include/asm/numa.h | 45 +++++ arch/arm64/include/asm/topology.h | 10 + arch/arm64/kernel/pci.c | 10 + arch/arm64/kernel/setup.c | 4 + arch/arm64/kernel/smp.c | 4 + arch/arm64/mm/Makefile | 1 + arch/arm64/mm/init.c | 34 +++- arch/arm64/mm/mmu.c | 1 + arch/arm64/mm/numa.c | 396 ++++++++++++++++++++++++++++++++++++++ 11 files changed, 538 insertions(+), 5 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 +26 -0
@@ -74,6 +74,7 @@ config ARM64 select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_IRQ_TIME_ACCOUNTING select HAVE_MEMBLOCK + select HAVE_MEMBLOCK_NODE_MAP if NUMA select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS select HAVE_PERF_REGS
@@ -96,6 +97,7 @@ config ARM64 select SYSCTL_EXCEPTION_TRACE select HAVE_CONTEXT_TRACKING select HAVE_ARM_SMCCC + select OF_NUMA if NUMA && OF help ARM 64-bit (AArch64) Linux support.
@@ -545,6 +547,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 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 +12 -0
@@ -0,0 +1,12 @@ +#ifndef __ASM_MMZONE_H +#define __ASM_MMZONE_H + +#ifdef CONFIG_NUMA + +#include <asm/numa.h> + +extern struct pglist_data *node_data[]; +#define NODE_DATA (nid) (node_data[(nid)]) + +#endif /* CONFIG_NUMA */ +#endif /* __ASM_MMZONE_H */
arch/arm64/include/asm/numa.h new file +45 -0
45 lines not on this page · raw message
arch/arm64/include/asm/topology.h +10 -0
@@ -22,6 +22,16 @@ void init_cpu_topology(void);void store_cpu_topology (unsigned int cpuid);const struct cpumask *cpu_coregroup_mask (int cpu); +#ifdef CONFIG_NUMA + +struct pci_bus ; +int pcibus_to_node (struct pci_bus *bus); +#define cpumask_of_pcibus (bus) (pcibus_to_node(bus) == -1 ? \ + cpu_all_mask : \ + cpumask_of_node(pcibus_to_node(bus))) + +#endif /* CONFIG_NUMA */ +#include <asm-generic/topology.h> #endif /* _ASM_ARM_TOPOLOGY_H */
arch/arm64/kernel/pci.c +10 -0
@@ -76,6 +76,16 @@ int raw_pci_write(unsigned int domain, unsigned int bus,return -ENXIO ; } +#ifdef CONFIG_NUMA + +int pcibus_to_node (struct pci_bus *bus) +{ +return dev_to_node (&bus->dev); +} +EXPORT_SYMBOL (pcibus_to_node); + +#endif +#ifdef CONFIG_ACPI /* Root bridge scanning */ struct pci_bus *pci_acpi_scan_root (struct acpi_pci_root *root)
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>
@@ -371,6 +372,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 +4 -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); }/*
@@ -518,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; + +early_map_cpu_to_node (cpu_count,of_node_to_nid (dn)); next: cpu_count++; }
arch/arm64/mm/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-y := dma-mapping.o extable.o fault.o init.o \ context.o proc.o pageattr.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_ARM64_PTDUMP) += dump.o +obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_KASAN) += kasan_init.o KASAN_SANITIZE_kasan_init.o := n
arch/arm64/mm/init.c +29 -5
@@ -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,21 @@ static phys_addr_t __init 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;
@@ -117,6 +133,8 @@ 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 +151,15 @@ static void __init arm64_memory_present(void)static void __init 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
@@ -181,7 +204,6 @@ void __init arm64_memblock_init(void)dma_contiguous_reserve (arm64_dma_phys_limit);memblock_allow_resize (); -memblock_dump_all (); }void __init bootmem_init (void )
@@ -193,6 +215,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 +228,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/mmu.c +1 -0
@@ -468,6 +468,7 @@ void __init paging_init(void) zero_page =early_alloc (PAGE_SIZE );bootmem_init (); +memblock_dump_all (); empty_zero_page =virt_to_page (zero_page);
arch/arm64/mm/numa.c new file +396 -0
396 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v13 6/6 arm64, mm, numa: Add NUMA balancing support for arm64.
In reply to David DaneyFrom: Ganapatrao Kulkarni <[email protected]>
Enable NUMA balancing for arm64 platforms.
Add pte, pmd protnone helpers for use by automatic NUMA balancing.
--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/pgtable.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
arch/arm64/Kconfig +1 -0
@@ -11,6 +11,7 @@ config ARM64 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_USE_CMPXCHG_LOCKREF select ARCH_SUPPORTS_ATOMIC_RMW + select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_WANT_OPTIONAL_GPIOLIB select ARCH_WANT_COMPAT_IPC_PARSE_VERSION select ARCH_WANT_FRAME_POINTERS
arch/arm64/include/asm/pgtable.h +15 -0
@@ -346,6 +346,21 @@ static inline pgprot_t mk_sect_prot(pgprot_t prot)return __pgprot (pgprot_val (prot) & ~PTE_TABLE_BIT ); } +#ifdef CONFIG_NUMA_BALANCING +/* +* See the comment in include/asm-generic/pgtable.h +*/ +static inline int pte_protnone (pte_t pte) +{ +return (pte_val (pte) & (PTE_VALID |PTE_PROT_NONE )) ==PTE_PROT_NONE ; +} + +static inline int pmd_protnone (pmd_t pmd) +{ +return pte_protnone (pmd_pte (pmd)); +} +#endif +/* * THP definitions. */
Signature · 1 line
1.8.3.1