x86-64, NUMA: Prepare numa_emulation() for moving NUMA emulation into a separate file
PATCH 1/3 x86-64, NUMA: Prepare numa_emulation() for moving NUMA emulation into a separate file
Update numa_emulation() such that, it
- takes @numa_meminfo and @numa_dist_cnt instead of directly referencing the global variables.
- copies the distance table by iterating each distance with node_distance() instead of memcpy'ing the distance table.
- tests emu_cmdline to determine whether emulation is requested and fills emu_nid_to_phys[] with identity mapping if emulation is not used. This allows the caller to call numa_emulation() unconditionally and makes return value unncessary.
- defines dummy version if CONFIG_NUMA_EMU is disabled.
This patch doesn't introduce any behavior change.
---
These three patches move NUMA emulation into a separate file. Once reviewed, I'll push them through misc#x86-numa branch.
Thanks.
arch/x86/mm/numa_64.c | 56 +++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-)
arch/x86/mm/numa_64.c +33 -23
@@ -797,17 +797,20 @@ static int __init split_nodes_size_inter* Sets up the system RAM area from start_pfn to last_pfn according to the * numa=fake command-line option. */ -static bool __init numa_emulation (void ) +static void __init numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt) {static struct numa_meminfo ei__initdata ;static struct numa_meminfo pi__initdata ;const u64 max_addr = max_pfn <<PAGE_SHIFT ; -int phys_dist_cnt = numa_distance_cnt;u8 *phys_dist =NULL ;int i, j, ret; +if (!emu_cmdline) + goto no_emu; +memset (&ei,0 ,sizeof (ei)); - pi = numa_meminfo; + pi = *numa_meminfo;for (i =0 ; i <MAX_NUMNODES ; i++) emu_nid_to_phys[i] =NUMA_NO_NODE ;
@@ -830,19 +833,19 @@ static bool __init numa_emulation(void) }if (ret <0 ) -return false; + goto no_emu;if (numa_cleanup_meminfo (&ei) <0 ) {pr_warning ("NUMA: Warning: constructed meminfo invalid, disabling emulation\n" ); -return false; + goto no_emu; }/* * Copy the original distance table. It's temporary so no need to * reserve it. */ -if (phys_dist_cnt) { -size_t size = phys_dist_cnt *sizeof (numa_distance[0 ]); +if (numa_dist_cnt) { +size_t size = numa_dist_cnt *sizeof (phys_dist[0 ]);u64 phys; phys = memblock_find_in_range(0,
@@ -850,14 +853,18 @@ static bool __init numa_emulation(void) size, PAGE_SIZE);if (phys ==MEMBLOCK_ERROR ) {pr_warning ("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n" ); -return false; + goto no_emu; } phys_dist =__va (phys); -memcpy (phys_dist, numa_distance, size); + +for (i =0 ; i < numa_dist_cnt; i++) +for (j =0 ; j < numa_dist_cnt; j++) + phys_dist[i * numa_dist_cnt + j] = +node_distance (i, j); }/* commit */ - numa_meminfo = ei; + *numa_meminfo = ei;/* * Transform __apicid_to_node table to use emulated nids by
@@ -886,18 +893,27 @@ static bool __init numa_emulation(void)int physj = emu_nid_to_phys[j];int dist; -if (physi >= phys_dist_cnt || physj >= phys_dist_cnt) +if (physi >= numa_dist_cnt || physj >= numa_dist_cnt) dist = physi == physj ?LOCAL_DISTANCE :REMOTE_DISTANCE ;else - dist = phys_dist[physi * phys_dist_cnt + physj]; + dist = phys_dist[physi * numa_dist_cnt + physj]; numa_set_distance(i, j, dist); } } -return true; +return ; + +no_emu: +/* No emulation. Build identity emu_nid_to_phys[] for numa_add_cpu() */ +for (i =0 ; i <ARRAY_SIZE (emu_nid_to_phys); i++) + emu_nid_to_phys[i] = i; } -#endif /* CONFIG_NUMA_EMU */ +#else /* CONFIG_NUMA_EMU */ +static inline void numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt) +{ } +#endif /* CONFIG_NUMA_EMU */ static int __init dummy_numa_init (void ) {
@@ -945,15 +961,9 @@ void __init initmem_init(void)if (numa_cleanup_meminfo (&numa_meminfo) <0 )continue ; -#ifdef CONFIG_NUMA_EMU -/* -* If requested, try emulation. If emulation is not used, -* build identity emu_nid_to_phys[] for numa_add_cpu() -*/ -if (!emu_cmdline || !numa_emulation ()) -for (j =0 ; j <ARRAY_SIZE (emu_nid_to_phys); j++) - emu_nid_to_phys[j] = j; -#endif + +numa_emulation (&numa_meminfo, numa_distance_cnt); +if (numa_register_memblks (&numa_meminfo) <0 )continue ;
PATCH 2/3 x86-64, NUMA: Move NUMA emulation into numa_emulation.c
Create numa_emulation.c and move all NUMA emulation code there. The definitions of struct numa_memblk and numa_meminfo are moved to numa_64.h. Also, numa_remove_memblk_from(), numa_cleanup_meminfo(), numa_reset_distance() along with numa_emulation() are made global.
--- arch/x86/include/asm/numa_64.h | 29 ++ arch/x86/mm/Makefile | 1 arch/x86/mm/numa_64.c | 479 ----------------------------------------- arch/x86/mm/numa_emulation.c | 451 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 482 insertions(+), 478 deletions(-)
arch/x86/include/asm/numa_64.h +27 -2
@@ -18,6 +18,21 @@ extern void setup_node_bootmem(int nodei#ifdef CONFIG_NUMA /* +* Data structures to describe memory configuration during NUMA +* initialization. Use only in NUMA init and emulation paths. +*/ +struct numa_memblk { +u64 start; +u64 end; +int nid; +}; + +struct numa_meminfo { +int nr_blks; +struct numa_memblk blk[NR_NODE_MEMBLKS ]; +}; + +/* * Too small node sizes may confuse the VM badly. Usually they * result from BIOS bugs. So dont recognize nodes as standalone * NUMA entities that have less than this amount of RAM listed:
@@ -28,15 +43,25 @@ extern nodemask_t numa_nodes_parsed __inextern int __cpuinit numa_cpu_node (int cpu);extern int __init numa_add_memblk (int nodeid,u64 start,u64 end); +extern void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi); +extern int __init numa_cleanup_meminfo (struct numa_meminfo *mi); +extern void __init numa_reset_distance (void );extern void __init numa_set_distance (int from,int to,int distance);#ifdef CONFIG_NUMA_EMU #define FAKE_NODE_MIN_SIZE ((u64)32 << 20)#define FAKE_NODE_MIN_HASH_MASK (~(FAKE_NODE_MIN_SIZE - 1UL))void numa_emu_cmdline (char *); +void __init numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt); +#else /* CONFIG_NUMA_EMU */ +static inline void numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt) +{ }#endif /* CONFIG_NUMA_EMU */ -#else + +#else /* CONFIG_NUMA */ static inline int numa_cpu_node (int cpu) {return NUMA_NO_NODE ; } -#endif +#endif /* CONFIG_NUMA */ #endif /* _ASM_X86_NUMA_64_H */
arch/x86/mm/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_MMIOTRACE_TEST) += testmmio obj-$(CONFIG_NUMA) += numa.o numa_$(BITS).o obj-$(CONFIG_AMD_NUMA) += amdtopology_64.o obj-$(CONFIG_ACPI_NUMA) += srat_$(BITS).o +obj-$(CONFIG_NUMA_EMU) += numa_emulation.o obj-$(CONFIG_HAVE_MEMBLOCK) += memblock.o
arch/x86/mm/numa_64.c +3 -476
512 lines not on this page · raw message
arch/x86/mm/numa_emulation.c new file +451 -0
451 lines not on this page · raw message
Re: [PATCH 2/3 tip:x86/mm] x86-64, NUMA: Move NUMA emulation into numa_emulation.c
Quoted 20 lines · Tejun Heo
Create
numa_emulation.cand move all NUMA emulation code there. The definitions of structnuma_memblkandnuma_meminfoare moved tonuma_64.h. Also,numa_remove_memblk_from(),numa_cleanup_meminfo(),numa_reset_distance()along withnuma_emulation()are made global.Signed-off-by Tejun Heo <[email protected]>Cc Yinghai Lu <[email protected]>Cc Ingo Molnar <[email protected]>--- arch/x86/include/asm/numa_64.h | 29 ++ arch/x86/mm/Makefile | 1 arch/x86/mm/numa_64.c | 479 ----------------------------------------- arch/x86/mm/numa_emulation.c | 451 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 482 insertions(+), 478 deletions(-)Index:
work/arch/x86/include/asm/numa_64.h
===================================================================
arch/x86/include/asm/numa_64.h extern void setup_node_bootmem(int nodei · line 23
Quoted 6 lines
arch/x86/include/asm/numa_64.h +3
-0@@ -18,6 +18,21 @@ extern void setup_node_bootmem(int nodei#ifdef CONFIG_NUMA /* +* Data structures to describe memory configuration during NUMA +* initialization. Use only in NUMA init and emulation paths. +*/
those internal struct and functions declaring could be in arch/x86/mm/numa_internal.h ?
David, can you please check tip/x86/mm ?
Thanks
Yinghai
Quoted 43 lines
arch/x86/include/asm/numa_64.h +24
-2+struct numa_memblk { +u64 start; +u64 end; +int nid; +}; + +struct numa_meminfo { +int nr_blks; +struct numa_memblk blk[NR_NODE_MEMBLKS ]; +}; + +/* * Too small node sizes may confuse the VM badly. Usually they * result from BIOS bugs. So dont recognize nodes as standalone * NUMA entities that have less than this amount of RAM listed: @@ -28,15 +43,25 @@ extern nodemask_t numa_nodes_parsed __inextern int __cpuinit numa_cpu_node (int cpu);extern int __init numa_add_memblk (int nodeid,u64 start,u64 end); +extern void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi); +extern int __init numa_cleanup_meminfo (struct numa_meminfo *mi); +extern void __init numa_reset_distance (void );extern void __init numa_set_distance (int from,int to,int distance);#ifdef CONFIG_NUMA_EMU #define FAKE_NODE_MIN_SIZE ((u64)32 << 20)#define FAKE_NODE_MIN_HASH_MASK (~(FAKE_NODE_MIN_SIZE - 1UL))void numa_emu_cmdline (char *); +void __init numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt); +#else /* CONFIG_NUMA_EMU */ +static inline void numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt) +{ }#endif /* CONFIG_NUMA_EMU */ -#else + +#else /* CONFIG_NUMA */ static inline int numa_cpu_node (int cpu) {return NUMA_NO_NODE ; } -#endif +#endif /* CONFIG_NUMA */ #endif /* _ASM_X86_NUMA_64_H */
Re: [PATCH 2/3 tip:x86/mm] x86-64, NUMA: Move NUMA emulation into numa_emulation.c
Quoted 2 lines · Yinghai Lu
David, can you please check tip/x86/mm ?
Yeah, I'm in the process of doing so without this set yet. I'm getting boot failures for numa=fake=128M right now, so I'll need to investigate and diagnose that issue before adding more patches.
Re: [PATCH 2/3 tip:x86/mm] x86-64, NUMA: Move NUMA emulation into numa_emulation.c
Quoted 8 lines · David Rientjes
Quoted 2 lines · Yinghai Lu
David, can you please check tip/x86/mm ?
Yeah, I'm in the process of doing so without this set yet. I'm getting boot failures for numa=fake=128M right now, so I'll need to investigate and diagnose that issue before adding more patches.
any info about the boot failures?
Thanks
Yinghai
PATCH 2/3 x86-64, NUMA: Move NUMA emulation into numa_emulation.c
In reply to Tejun HeoCreate numa_emulation.c and move all NUMA emulation code there. The definitions of struct numa_memblk and numa_meminfo are moved to numa_64.h. Also, numa_remove_memblk_from(), numa_cleanup_meminfo(), numa_reset_distance() along with numa_emulation() are made global.
- v2: Internal declarations moved to numa_internal.h as suggested by Yinghai.
---
Yinghai, does it look okay to you?
Thanks.
arch/x86/mm/Makefile | 1 arch/x86/mm/numa_64.c | 480 ------------------------------------------- arch/x86/mm/numa_emulation.c | 452 ++++++++++++++++++++++++++++++++++++++++ arch/x86/mm/numa_internal.h | 31 ++ 4 files changed, 488 insertions(+), 476 deletions(-)
arch/x86/mm/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_MMIOTRACE_TEST) += testmmio obj-$(CONFIG_NUMA) += numa.o numa_$(BITS).o obj-$(CONFIG_AMD_NUMA) += amdtopology_64.o obj-$(CONFIG_ACPI_NUMA) += srat_$(BITS).o +obj-$(CONFIG_NUMA_EMU) += numa_emulation.o obj-$(CONFIG_HAVE_MEMBLOCK) += memblock.o
arch/x86/mm/numa_64.c +4 -476
516 lines not on this page · raw message
arch/x86/mm/numa_emulation.c new file +452 -0
452 lines not on this page · raw message
arch/x86/mm/numa_internal.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef __X86_MM_NUMA_INTERNAL_H +#define __X86_MM_NUMA_INTERNAL_H + +#include <linux/types.h> +#include <asm/numa.h> + +struct numa_memblk { +u64 start; +u64 end; +int nid; +}; + +struct numa_meminfo { +int nr_blks; +struct numa_memblk blk[NR_NODE_MEMBLKS ]; +}; + +void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi); +int __init numa_cleanup_meminfo (struct numa_meminfo *mi); +void __init numa_reset_distance (void ); + +#ifdef CONFIG_NUMA_EMU +void __init numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt); +#else +static inline void numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt) +{ } +#endif + +#endif /* __X86_MM_NUMA_INTERNAL_H */
Re: [PATCH UPDATED 2/3 tip:x86/mm] x86-64, NUMA: Move NUMA emulation into numa_emulation.c
Quoted 5 lines · Tejun Heo
Create
numa_emulation.cand move all NUMA emulation code there. The definitions of structnuma_memblkandnuma_meminfoare moved tonuma_64.h. Also,numa_remove_memblk_from(),numa_cleanup_meminfo(),numa_reset_distance()along withnuma_emulation()are made global.
Quoted 9 lines
- v2: Internal declarations moved to
numa_internal.has suggested by Yinghai.Signed-off-by Tejun Heo <[email protected]>Cc Yinghai Lu <[email protected]>Cc Ingo Molnar <[email protected]>---
Yinghai, does it look okay to you?
Yes.
Re: [PATCH UPDATED 2/3 tip:x86/mm] x86-64, NUMA: Move NUMA emulation into numa_emulation.c
Quoted 1 line · Yinghai Lu
Acked-by Yinghai Lu <[email protected]>
Thanks. Patches 1-3 applied to x86-numa.
Signature · 1 line
tejun
PATCH 3/3 x86-64, NUMA: Add proper function comments to global functions
In reply to Tejun Heo--- arch/x86/mm/numa_64.c | 50 ++++++++++++++++++++++++++++++++++++------- arch/x86/mm/numa_emulation.c | 29 ++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 10 deletions(-)
arch/x86/mm/numa_64.c +43 -7
@@ -204,6 +204,14 @@ static int __init numa_add_memblk_to(intreturn 0 ; } +/** +* numa_remove_memblk_from - Remove one numa_memblk from a numa_meminfo +* @idx: Index of memblk to remove +* @mi: numa_meminfo to remove memblk from +* +* Remove @idx'th numa_memblk from @mi by shifting @mi->blk[] and +* decrementing @mi->nr_blks. +*/ void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi) { mi->nr_blks--;
@@ -211,6 +219,17 @@ void __init numa_remove_memblk_from(int (mi->nr_blks - idx) * sizeof(mi->blk[0])); } +/** +* numa_add_memblk - Add one numa_memblk to numa_meminfo +* @nid: NUMA node ID of the new memblk +* @start: Start address of the new memblk +* @end: End address of the new memblk +* +* Add a new memblk to the default numa_meminfo. +* +* RETURNS: +* 0 on success, -errno on failure. +*/ int __init numa_add_memblk (int nid,u64 start,u64 end) {return numa_add_memblk_to (nid, start, end, &numa_meminfo);
@@ -262,6 +281,16 @@ setup_node_bootmem(int nodeid, unsignednode_set_online (nodeid); } +/** +* numa_cleanup_meminfo - Cleanup a numa_meminfo +* @mi: numa_meminfo to clean up +* +* Sanitize @mi by merging and removing unncessary memblks. Also check for +* conflicts and clear unused memblks. +* +* RETURNS: +* 0 on success, -errno on failure. +*/ int __init numa_cleanup_meminfo (struct numa_meminfo *mi) {const u64 low =0 ;
@@ -352,9 +381,11 @@ static void __init numa_nodemask_from_menode_set (mi->blk[i].nid, *nodemask); } -/* -* Reset distance table. The current table is freed. The next -* numa_set_distance() call will create a new one. +/** +* 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 ) {
@@ -369,10 +400,15 @@ void __init numa_reset_distance(void) numa_distance =NULL ; } -/* -* Set the distance between node @from to @to to @distance. If distance -* table doesn't exist, one which is large enough to accomodate all the -* currently known nodes will be created. +/** +* 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 accomodate all the currently +* known nodes will be created. */ void __init numa_set_distance (int from,int to,int distance) {
arch/x86/mm/numa_emulation.c +26 -3
@@ -266,9 +266,32 @@ static int __init split_nodes_size_interreturn 0 ; } -/* -* Sets up the system RAM area from start_pfn to last_pfn according to the -* numa=fake command-line option. +/** +* numa_emulation - Emulate NUMA nodes +* @numa_meminfo: NUMA configuration to massage +* @numa_dist_cnt: The size of the physical NUMA distance table +* +* Emulate NUMA nodes according to the numa=fake kernel parameter. +* @numa_meminfo contains the physical memory configuration and is modified +* to reflect the emulated configuration on success. @numa_dist_cnt is +* used to determine the size of the physical distance table. +* +* On success, the following modifications are made. +* +* - @numa_meminfo is updated to reflect the emulated nodes. +* +* - __apicid_to_node[] is updated such that APIC IDs are mapped to the +* emulated nodes. +* +* - NUMA distance table is rebuilt to represent distances between emulated +* nodes. The distances are determined considering how emulated nodes +* are mapped to physical nodes and match the actual distances. +* +* - emu_nid_to_phys[] reflects how emulated nodes are mapped to physical +* nodes. This is used by numa_add_cpu() and numa_remove_cpu(). +* +* If emulation is not enabled or fails, emu_nid_to_phys[] is filled with +* identity mapping and no other modification is made. */ void __init numa_emulation (struct numa_meminfo *numa_meminfo,int numa_dist_cnt) {