pv guest numa [RE: Host Numa informtion in dom0]
Subsystems (4)
RFC 1/1 pv guest numa [RE: Host Numa informtion in dom0]
I am attaching (RFC) patches for NUMA-aware pv guests.
* The patch adds hypervisor interfaces to export minimal numa-related information about the memory of pv domain, which can then be used to setup the node ranges, virtual cpu<->node maps, and virtual slit tables in the pv domain.
* The guest-domain also maintains a mapping between its vnodes and mnodes(actual machine nodes). These mappings can be used in the memory operations, such as those in ballooning.
* In the patch, dom0 is made numa-aware using these interfaces. Other domains should be simpler. I am in the process of adding python interfaces for this. And, this would work with any node selection policy.
* The patch is tested only for 64-on-64 (on x86_64)
* Along with the following other patches, this could provide a good solution for numa-aware guests -
- numa-aware ballooning (previously posted by me on xen-devel)
- Andre's patch for HVM domains (posted by Andre recently)
I am in the process of making other places of dynamic memory mgmt/operations numa-aware - tmem, memory exchange operations, etc.
Please let know your comments.
-dulloor
Quoted 14 lines · Ian Pratt
Quoted 11 lines
Quoted 7 lines
If guest NUMA is disabled, we just use a single node mask which is the union of the per-VCPU node masks.
Where allowed node masks span more than one physical node, we should allocate memory to the guest's virtual node by pseudo randomly striping memory allocations (in 2MB chunks) from across the specified physical nodes. [pseudo random is probably better than round robin]
Do we really want to support this? I don't think the allowed node masks should span more than one physical NUMA node. We also need to look at I/O devices as well.
Given that we definitely need this striping code in the case where the guest is non NUMA, I'd be inclined to still allow it to be used even if the guest has multiple NUMA nodes. It could come in handy where there is a hierarchy between physical NUMA nodes, enabling for example striping to be used between a pair of 'close' nodes, while exposing the higher-level topology of sets of the paired nodes to be exposed to the guest.
Quoted 9 lines
Ian
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
arch/x86/kernel/setup.c +2 -1
@@ -940,7 +940,8 @@ void __init setup_arch(char **cmdline_p)/* * Parse SRAT to discover nodes. */ -acpi_numa_init (); +if (acpi_numa >0 ) +acpi_numa_init ();#endif initmem_init (0 , max_pfn);
arch/x86/mm/numa_64.c +149 -1
185 lines not on this page · raw message
arch/x86/xen/enlighten.c +9 -0
@@ -83,6 +83,8 @@ void *xen_initial_gdt;*/ struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info; +struct xen_domain_numa_layout *HYPERVISOR_domain_numa_layout; +/* * Flag to determine whether vcpu info placement is available on all * VCPUs. We assume it is to start with, and then set it to zero on
@@ -1089,6 +1091,7 @@ static void __init xen_setup_stackprotector(void) pv_cpu_ops.load_gdt = xen_load_gdt; } +extern struct xen_domain_numa_layout pv_numa_layout;/* First C function to be called on Xen boot */ asmlinkage void __init xen_start_kernel(void) {
@@ -1230,6 +1233,12 @@ asmlinkage void __init xen_start_kernel(void) xen_start_info->console.domU.evtchn =0 ; } + { +struct xen_domain_numa_layout *layout = + (void *)((char *)xen_start_info + + xen_start_info->numa_layout_info.info_off); +memcpy (&pv_numa_layout, layout,sizeof (*layout)); + }xen_raw_console_write ("about to get started...\n" );/* Start the world */
arch/x86/xen/setup.c +3 -0
@@ -281,6 +281,9 @@ void __init xen_arch_setup(void)printk (KERN_INFO "ACPI in unprivileged domain disabled\n" ); disable_acpi(); } + + acpi_numa =-1 ; + numa_off =1 ;#endif /*
include/xen/interface/xen.h +54 -0
66 lines not on this page · raw message
tools/include/xen-foreign/reference.size +1 -1
@@ -1,7 +1,7 @@ structs | x86_32 x86_64 ia64 -start_info | 1112 1168 1168 +start_info | 1120 1176 1176 trap_info | 8 16 - pt_fpreg | - - 16 cpu_user_regs | 68 200 -
xen/arch/x86/domain_build.c +155 -28
330 lines not on this page · raw message
xen/arch/x86/e820.c +47 -0
50 lines not on this page · raw message
xen/arch/x86/numa.c +9 -2
@@ -28,8 +28,10 @@struct node_data node_data[MAX_NUMNODES ]; -int memnode_shift; -u8 memnodemap[NODEMAPSIZE ]; +struct memnode memnode = {.mapsize =NODEMAPSIZE }; +#define memnode_shift memnode.shift +#define memnodemap memnode.map +#define memnodemapsize memnode.mapsizeunsigned char cpu_to_node[NR_CPUS ]__read_mostly = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE
@@ -278,6 +280,9 @@EXPORT_SYMBOL (memnodemap);EXPORT_SYMBOL (node_data); +extern struct xen_domain_numa_layout dom0_numa_layout; +extern void dump_numa_layout (struct xen_domain_numa_layout *layout); +static void dump_numa (unsigned char key) {s_time_t now =NOW ();
@@ -289,6 +294,8 @@printk ("'%c' pressed -> dumping numa info (now-0x%X:%08X)\n" , key, (u32)(now>>32 ), (u32 )now); +dump_numa_layout (&dom0_numa_layout); +for_each_online_node (i) {paddr_t pa = (paddr_t)(NODE_DATA (i)->node_start_pfn +1 )<<PAGE_SHIFT ; printk("idx%d -> NODE%d start->%lu size->%lu\n",
xen/common/compat/xlat.c +2 -0
@@ -8,6 +8,7 @@#include <compat/event_channel.h> #include <compat/vcpu.h> +#if 0 /* In-place translation functons: */ void xlat_start_info (struct start_info *native,enum XLAT_start_info_console console)
@@ -17,6 +18,7 @@BUILD_BUG_ON (sizeof (*native) <sizeof (*compat)); XLAT_start_info(compat, native); } +#endif void xlat_vcpu_runstate_info (struct vcpu_runstate_info *native) {
xen/common/domain.c +3 -0
@@ -241,7 +241,10 @@if ( domid ==0 ) { +/* should be opt_dom0_numa */ d->is_pinned = opt_dom0_vcpus_pin; + d->is_numa =1 ; + d->is_pinned =1 ; d->disable_migrate =1 ; }
xen/common/page_alloc.c +16 -4
@@ -287,11 +287,17 @@unsigned int i, j, zone =0 ;unsigned int num_nodes =num_online_nodes ();unsigned long request =1UL << order; +unsigned int exact_node_request;cpumask_t extra_cpus_mask, mask;struct page_info *pg; -if ( node ==NUMA_NO_NODE ) +if ( node ==NUMA_NO_NODE ) { node =cpu_to_node (smp_processor_id ()); + exact_node_request =0 ; + }else { + exact_node_request = (memflags & MEMF_exact_node); + } +ASSERT (node >=0 );ASSERT (zone_lo <= zone_hi);
@@ -321,6 +327,8 @@ goto found; }while ( zone-- > zone_lo );/* careful: unsigned zone may wrap */ +if (exact_node_request) + goto not_found;/* Pick next node, wrapping around if needed. */ node =next_node (node, node_online_map);if (node ==MAX_NUMNODES )
@@ -335,6 +343,7 @@return pg; } +not_found:/* No suitable memory blocks. Fail the request. */ spin_unlock (&heap_lock);return NULL ;
@@ -834,6 +843,11 @@return free_pages; } +unsigned long avail_node_heap_pages (unsigned int node) +{ +return avail_heap_pages (MEMZONE_XEN ,NR_ZONES -1 , node); +} +void __init end_boot_allocator (void ) {unsigned int i;
@@ -1188,9 +1202,7 @@unsigned long avail_domheap_pages (void ) { -return avail_heap_pages (MEMZONE_XEN +1 , -NR_ZONES -1 , --1 ); +return avail_heap_pages (MEMZONE_XEN +1 ,NR_ZONES -1 ,-1 ); }static void pagealloc_info (unsigned char key)
xen/common/schedule.c +8 -2
@@ -33,6 +33,7 @@#include <xen/multicall.h> #include <public/sched.h> #include <xsm/xsm.h> +#include <asm/numa.h> /* opt_sched: scheduler - default to credit */ static char __initdata opt_sched[10 ] ="credit" ;
@@ -150,7 +151,7 @@return state.time[RUNSTATE_running]; } -int sched_init_vcpu (struct vcpu *v,unsigned int processor) +int sched_init_vcpu (struct vcpu *v,unsigned int processor) {struct domain *d = v->domain;
@@ -160,7 +161,12 @@*/ v->processor = processor;if (is_idle_domain (d) || d->is_pinned ) - v->cpu_affinity =cpumask_of_cpu (processor); + { +if (d->is_numa) + v->cpu_affinity =node_to_cpumask (cpu_to_node (processor)); +else + v->cpu_affinity =cpumask_of_cpu (processor); + }else cpus_setall (v->cpu_affinity);
xen/include/asm-x86/e820.h +5 -0
@@ -29,6 +29,11 @@ struct e820map *e820, uint64_t s, uint64_t e, uint32_t orig_type, uint32_t new_type);extern unsigned long init_e820 (const char *,struct e820entry *,int *); +extern int e820_find_active_region (const struct e820entry *ei, +unsigned long start_pfn,unsigned long last_pfn, +unsigned long *ei_startpfn,unsigned long *ei_endpfn); +extern unsigned long e820_hole_size (unsigned long start_pfn, +unsigned long end_pfn);extern struct e820map e820;/* These symbols live in the boot trampoline. */
xen/include/asm-x86/numa.h +14 -3
@@ -12,7 +12,7 @@#define cpu_to_node (cpu) (cpu_to_node[cpu])#define parent_node (node) (node) -#define node_to_first_cpu (node) (__ffs(node_to_cpumask[node])) +#define node_to_first_cpu (node) (ffs(node_to_cpumask[node]))#define node_to_cpumask (node) (node_to_cpumask[node])struct node {
@@ -49,8 +49,15 @@ }/* Simple perfect hash to map physical addresses to node numbers */ -extern int memnode_shift; -extern u8 memnodemap[NODEMAPSIZE ]; +struct memnode { +int shift; +unsigned int mapsize; +u8 map[NODEMAPSIZE ]; +}; +extern struct memnode memnode; +#define memnode_shift memnode.shift +#define memnodemap memnode.map +#define memnodemapsize memnode.mapsizestruct node_data {unsigned long node_start_pfn;
@@ -69,11 +76,15 @@ return nid; } +int __node_distance (int a,int b); +#define NODE_DATA (nid) (&(node_data[nid]))#define node_start_pfn (nid) (NODE_DATA(nid)->node_start_pfn) +#define node_spanned_pages (nid) (NODE_DATA(nid)->node_spanned_pages)#define node_end_pfn (nid) (NODE_DATA(nid)->node_start_pfn + \ NODE_DATA(nid)->node_spanned_pages) +#define node_distance (a, b) (__node_distance(a, b))#else
xen/include/public/xen.h +51 -0
63 lines not on this page · raw message
xen/include/xen/mm.h +3 -0
@@ -46,6 +46,7 @@void init_xenheap_pages (paddr_t ps,paddr_t pe);void *alloc_xenheap_pages (unsigned int order,unsigned int memflags);void free_xenheap_pages (void *v,unsigned int order); +unsigned long avail_node_heap_pages (unsigned int node);#define alloc_xenheap_page () (alloc_xenheap_pages(0,0))#define free_xenheap_page (v) (free_xenheap_pages(v,0))
@@ -78,6 +79,8 @@#define MEMF_populate_on_demand (1U<<_MEMF_populate_on_demand)#define _MEMF_tmem 2#define MEMF_tmem (1U<<_MEMF_tmem) +#define _MEMF_exact_node 3 +#define MEMF_exact_node (1U << _MEMF_exact_node)#define _MEMF_node 8#define MEMF_node (n) ((((n)+1)&0xff)<<_MEMF_node)#define _MEMF_bits 24
xen/include/xen/sched.h +2 -0
@@ -226,6 +226,8 @@bool_t is_paused_by_controller;/* Domain's VCPUs are pinned 1:1 to physical CPUs? */ bool_t is_pinned; +/* Domain is numa aware */ +bool_t is_numa;/* Are any VCPUs polling event channels (SCHEDOP_poll)? */ #if MAX_VIRT_CPUS <=BITS_PER_LONG
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi Dulloor --
Quoted 2 lines
I am in the process of making other places of dynamic memory mgmt/operations numa-aware - tmem, memory exchange operations, etc.
I'd be interested in your thoughts on numa-aware tmem as well as the other dynamic memory mechanisms in Xen 4.0.
Tmem is special in that it uses primarily full-page copies from/to tmem-space to/from guest-space so, assuming the interconnect can pipeline/stream a memcpy, overhead of off-node memory vs on-node memory should be less noticeable. However tmem uses large data structures (rbtrees and radix-trees) and the lookup process might benefit from being NUMA-aware.
Also, I will be looking into adding some page-sharing techniques into tmem in the near future. This (and the existing page sharing feature just added to 4.0) may create some other interesting challenges for NUMA-awareness.
Dan
Quoted 73 lines
-----Original Message-----
From: Dulloor [mailto:[email protected]]
Sent: Friday, February 12, 2010 11:25 PM
To: Ian Pratt
Cc: Andre Przywara; [email protected]; Nakajima, Jun; Keir Fraser
Subject: [Xen-devel] [RFC] pv guest numa [RE: Host Numa informtion in dom0]I am attaching (RFC) patches for NUMA-aware pv guests.
* The patch adds hypervisor interfaces to export minimal numa-related information about the memory of pv domain, which can then be used to setup the node ranges, virtual cpu<->node maps, and virtual slit tables in the pv domain.
* The guest-domain also maintains a mapping between its vnodes and mnodes(actual machine nodes). These mappings can be used in the memory operations, such as those in ballooning.
* In the patch, dom0 is made numa-aware using these interfaces. Other domains should be simpler. I am in the process of adding python interfaces for this. And, this would work with any node selection policy.
* The patch is tested only for 64-on-64 (onx86_64)* Along with the following other patches, this could provide a good solution for numa-aware guests -
- numa-aware ballooning (previously posted by me on xen-devel)
- Andre's patch for HVM domains (posted by Andre recently)I am in the process of making other places of dynamic memory mgmt/operations numa-aware - tmem, memory exchange operations, etc.
Please let know your comments.
-dulloor
Quoted 1 line · Ian Pratt
Quoted 1 line
Quoted 1 line
If guest NUMA is disabled, we just use a single node mask which is
the
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
union of the per-VCPU node masks.
Where allowed node masks span more than one physical node, we
should
Quoted 1 line
Quoted 1 line
Quoted 1 line
allocate memory to the guest's virtual node by pseudo randomly
striping
Quoted 1 line
Quoted 1 line
Quoted 1 line
memory allocations (in 2MB chunks) from across the specified
physical
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
nodes. [pseudo random is probably better than round robin]
Do we really want to support this? I don't think the allowed node
masks
Quoted 1 line
Quoted 1 line
should span more than one physical NUMA node. We also need to look
at I/O
Quoted 3 lines
Quoted 1 line
devices as well.
Given that we definitely need this striping code in the case where
the guest is non NUMA, I'd be inclined to still allow it to be used even if the guest has multiple NUMA nodes. It could come in handy where there is a hierarchy between physical NUMA nodes, enabling for example striping to be used between a pair of 'close' nodes, while exposing the higher-level topology of sets of the paired nodes to be exposed to the guest.
Quoted 10 lines
Ian
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Run this patch through scripts/checkpatch.pl
arch/x86/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 944
Quoted 11 lines · Dulloor
arch/x86/kernel/setup.c +2
-1@@ -940,7 +940,8 @@ void __init setup_arch(char **cmdline_p)/* * Parse SRAT to discover nodes. */ -acpi_numa_init (); +if (acpi_numa >0 ) +acpi_numa_init ();
Why? Why can't we just try acpi_numa_init()?
Quoted 18 lines
arch/x86/kernel/setup.c +0
-0#endif initmem_init (0 , max_pfn);arch/x86/mm/numa_64.c +2
-0@@ -11,7 +11,9 @@#include <linux/ctype.h> #include <linux/module.h> #include <linux/nodemask.h> +#include <linux/cpumask.h> #include <linux/sched.h> +#include <xen/interface/xen.h> #include <asm/e820.h> #include <asm/proto.h>
arch/x86/mm/numa_64.c line 24
Quoted 4 lines
arch/x86/mm/numa_64.c +1
-0@@ -19,6 +21,7 @@#include <asm/numa.h> #include <asm/acpi.h> #include <asm/k8.h> +#include <asm/xen/hypervisor.h>
If one does not set CONFIG_XEN does this compile?
arch/x86/mm/numa_64.c static int __init numa_emulation(unsigned long start_pfn, unsigned long last_pfn · line 431
Quoted 8 lines
arch/x86/mm/numa_64.c +0
-1struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ;EXPORT_SYMBOL (node_data);@@ -428,7 +431,6 @@ static int __init numa_emulation(unsigned long start_pfn, unsigned long last_pfn*/ if (!strchr (cmdline,'*' ) && !strchr (cmdline,',' )) {long n =simple_strtol (cmdline,NULL ,0 ); -
No need for this.
Quoted 5 lines
arch/x86/mm/numa_64.c +0
-0num_nodes =split_nodes_equally (nodes, &addr, max_addr,0 , n);if (num_nodes <0 )return num_nodes;@@ -522,16 +524,162 @@ out:numa_init_array ();
arch/x86/mm/numa_64.c out: · line 534
Quoted 10 lines
arch/x86/mm/numa_64.c +8
-0return 0 ; } +struct xen_domain_numa_layout pv_numa_layout; + +void dump_numa_layout (struct xen_domain_numa_layout *layout) +{ +unsigned int i, j; +char vcpumask[128 ]; +printk ("NUMA-LAYOUT(Dom0) : vcpus(%u), vnodes(%u)\n" , + layout->max_vcpus, layout->max_vnodes);
Redo the printk's. They need KERN_DEBUG
arch/x86/mm/numa_64.c out: · line 542
Quoted 8 lines
arch/x86/mm/numa_64.c +8
-0+for (i =0 ; i < layout->max_vnodes; i++) + { +struct xen_vnode_data *vnode_data = &layout->vnode_data[i]; +cpumask_scnprintf (vcpumask,sizeof (vcpumask), + ((cpumask_t *)&vnode_data->vcpu_mask)); +printk ("vnode[%u]:mnode(%u), node_nr_pages(%lx), vcpu_mask(%s)\n" , + vnode_data->vnode_id, vnode_data->mnode_id, + (unsigned long )vnode_data->nr_pages, vcpumask);
This one too.
arch/x86/mm/numa_64.c out: · line 545
Quoted 3 lines
arch/x86/mm/numa_64.c +3
-0+ } + +printk ("vnode distances :\n" );
and
arch/x86/mm/numa_64.c out: · line 550
Quoted 5 lines
arch/x86/mm/numa_64.c +5
-0+for (i =0 ; i < layout->max_vnodes; i++) +printk ("\tvnode[%u]" , i); +for (i =0 ; i < layout->max_vnodes; i++) + { +printk ("\nvnode[%u]" , i);
this
arch/x86/mm/numa_64.c out: · line 553
Quoted 3 lines
arch/x86/mm/numa_64.c +3
-0+for (j =0 ; j < layout->max_vnodes; j++) +printk ("\t%u" , layout->vnode_distance[i*layout->max_vnodes + j]); +printk ("\n" );
one to.
Quoted 6 lines
arch/x86/mm/numa_64.c +6
-0+ } +return ; +} + +static void __init xen_init_slit_table (struct xen_domain_numa_layout *layout) +{
arch/x86/mm/numa_64.c out: · line 569
Quoted 10 lines
arch/x86/mm/numa_64.c +10
-0+/* Construct a slit table (using layout->vnode_distance). +* Copy it to acpi_slit. */ +return ; +} +/* Distribute the vcpus over the vnodes according to their affinity */ +static void __init xen_init_numa_array (struct xen_domain_numa_layout *layout) +{ +int vcpu, vnode; + +printk (KERN_INFO "xen_numa_init_array - cpu_to_node initialization\n" );
pr_debug instead?
Quoted 27 lines
arch/x86/mm/numa_64.c +27
-0+ +for (vnode =0 ; vnode < layout->max_vnodes; vnode++) + { +struct xen_vnode_data *vnode_data = &layout->vnode_data[vnode]; +cpumask_t vcpu_mask = *((cpumask_t *)&vnode_data->vcpu_mask); + +for (vcpu =0 ; vcpu < layout->max_vcpus; vcpu++) + { +if (cpu_isset (vcpu, vcpu_mask)) + { +if (early_cpu_to_node (vcpu) !=NUMA_NO_NODE ) + { +printk (KERN_INFO "EARLY vcpu[%d] on vnode[%d]\n" , + vcpu,early_cpu_to_node (vcpu)); +continue ; + } +printk (KERN_INFO "vcpu[%d] on vnode[%d]\n" , vcpu, vnode); +numa_set_node (vcpu, vnode); + } + } + } +return ; +} + +static int __init xen_numa_emulation (struct xen_domain_numa_layout *layout, +unsigned long start_pfn,unsigned long last_pfn) +{
arch/x86/mm/numa_64.c out: · line 606
Quoted 10 lines
arch/x86/mm/numa_64.c +10
-0+int num_vnodes, i; +u64 node_start_addr, node_end_addr, max_addr; + +printk (KERN_INFO "xen_numa_emulation : max_vnodes(%d), max_vcpus(%d)" , + layout->max_vnodes, layout->max_vcpus); +dump_numa_layout (layout); +memset (&nodes,0 ,sizeof (nodes)); + + num_vnodes = layout->max_vnodes; +BUG_ON (num_vnodes >MAX_NUMNODES );
Hmm.. Is that really neccessary? What if we just do WARN("some lengthy explanation"), and bail out and not initialize these structures?
Quoted 23 lines
arch/x86/mm/numa_64.c +23
-0+ + max_addr = last_pfn <<PAGE_SHIFT ; + + node_start_addr = start_pfn <<PAGE_SHIFT ; +for (i =0 ; i < num_vnodes; i++) + { +struct xen_vnode_data *vnode_data = &layout->vnode_data[i]; +u64 node_size = vnode_data->nr_pages <<PAGE_SHIFT ; + + node_size &=FAKE_NODE_MIN_HASH_MASK ;/* 64MB aligned */ + +if (i == (num_vnodes-1 )) + node_end_addr = max_addr; +else + { + node_end_addr = node_start_addr + node_size; +while ((node_end_addr - node_start_addr - +e820_hole_size (node_start_addr, node_end_addr)) < node_size) + { + node_end_addr +=FAKE_NODE_MIN_SIZE ; +if (node_end_addr > max_addr) { + node_end_addr = max_addr; +break ;
arch/x86/mm/numa_64.c out: · line 639
Quoted 10 lines
arch/x86/mm/numa_64.c +10
-0+ } + } + } +/* node_start_addr updated inside the function */ +if (setup_node_range (i, nodes, &node_start_addr, + (node_end_addr-node_start_addr), max_addr+1 )) +BUG (); + } + +printk (KERN_INFO "XEN domain numa emulation - setup nodes\n" );
Is this neccessary? Can be it be debug?
arch/x86/mm/numa_64.c out: · line 644
Quoted 5 lines
arch/x86/mm/numa_64.c +5
-0+ + memnode_shift =compute_hash_shift (nodes, num_vnodes,NULL ); +if (memnode_shift <0 ) { +printk (KERN_ERR "No NUMA hash function found.\n" ); +BUG ();
Wow. BUG? What about just bailing out and unset xen_pv_emulation flag?
Quoted 63 lines
arch/x86/mm/numa_64.c +28
-0+ } +/* XXX: Shouldn't be needed because we disabled acpi_numa very early ! */ +/* +* We need to vacate all active ranges that may have been registered by +* SRAT and set acpi_numa to -1 so that srat_disabled() always returns +* true. NUMA emulation has succeeded so we will not scan ACPI nodes. +*/ +remove_all_active_ranges (); + +BUG_ON (acpi_numa >=0 ); +for_each_node_mask (i, node_possible_map) { +e820_register_active_regions (i, nodes[i].start >>PAGE_SHIFT , + nodes[i].end >>PAGE_SHIFT ); +setup_node_bootmem (i, nodes[i].start, nodes[i].end); + } +xen_init_slit_table (layout); +xen_init_numa_array (layout); +return 0 ; +}#endif /* CONFIG_NUMA_EMU */ void __init initmem_init (unsigned long start_pfn,unsigned long last_pfn) {int i; +struct xen_domain_numa_layout *numa_layout = &pv_numa_layout; + +int xen_pv_numa_enabled = numa_layout->max_vnodes;nodes_clear (node_possible_map);nodes_clear (node_online_map);#ifdef CONFIG_NUMA_EMU +if (xen_pv_domain () && xen_pv_numa_enabled) + { +if (!xen_numa_emulation (numa_layout, start_pfn, last_pfn)) +return ; + } +if (cmdline && !numa_emulation (start_pfn, last_pfn))return ;nodes_clear (node_possible_map);arch/x86/xen/enlighten.c +3
-0@@ -83,6 +83,8 @@ void *xen_initial_gdt;*/ struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info; +struct xen_domain_numa_layout *HYPERVISOR_domain_numa_layout; +/* * Flag to determine whether vcpu info placement is available on all * VCPUs. We assume it is to start with, and then set it to zero on @@ -1089,6 +1091,7 @@ static void __init xen_setup_stackprotector(void) pv_cpu_ops.load_gdt = xen_load_gdt; } +extern struct xen_domain_numa_layout pv_numa_layout;/* First C function to be called on Xen boot */ asmlinkage void __init xen_start_kernel(void) {
arch/x86/xen/enlighten.c asmlinkage void __init xen_start_kernel(void) · line 1241
Quoted 9 lines
arch/x86/xen/enlighten.c +6
-0@@ -1230,6 +1233,12 @@ asmlinkage void __init xen_start_kernel(void) xen_start_info->console.domU.evtchn =0 ; } + { +struct xen_domain_numa_layout *layout = + (void *)((char *)xen_start_info + + xen_start_info->numa_layout_info.info_off); +memcpy (&pv_numa_layout, layout,sizeof (*layout)); + }
Shouldn't there be a check to see if the Xen actually exports this structure? Otherwise you might copy garbage in and set pv_numa_layout values to random values.
Quoted 22 lines
arch/x86/xen/enlighten.c +0
-0xen_raw_console_write ("about to get started...\n" );/* Start the world */ arch/x86/xen/setup.c +3
-0@@ -281,6 +281,9 @@ void __init xen_arch_setup(void)printk (KERN_INFO "ACPI in unprivileged domain disabled\n" ); disable_acpi(); } + + acpi_numa =-1 ; + numa_off =1 ;#endif /* include/xen/interface/xen.h +0
-0
include/xen/interface/xen.h struct shared_info { · line 401
Quoted 4 lines
include/xen/interface/xen.h +1
-0@@ -398,6 +398,53 @@ struct shared_info { }; +#define XEN_NR_CPUS 64
No way to share this with some other variable? Like NR_CPUS?
include/xen/interface/xen.h struct shared_info { · line 404
Quoted 3 lines
include/xen/interface/xen.h +3
-0+#if defined(__i386__) +#define XEN_BITS_PER_LONG 32 +#define XEN_BYTES_PER_LONG 4
There gotta be some of these defined in other headers.
include/xen/interface/xen.h struct shared_info { · line 416
Quoted 12 lines
include/xen/interface/xen.h +12
-0+#define XEN_LONG_BYTEORDER 2 +#elif defined(__x86_64__) +#define XEN_BITS_PER_LONG 64 +#define XEN_BYTES_PER_LONG 8 +#define XEN_LONG_BYTEORDER 3 +#endif + +/* same as cpumask_t - in xen and even Linux (for now) */ +#define XEN_BITS_TO_LONGS (bits) \ + (((bits)+XEN_BITS_PER_LONG-1)/XEN_BITS_PER_LONG) +#define XEN_DECLARE_BITMAP (name,bits) \ + unsigned long name[XEN_BITS_TO_LONGS(bits)]
I am pretty sure there are macros for this laready.
include/xen/interface/xen.h struct shared_info { · line 418
Quoted 2 lines
include/xen/interface/xen.h +2
-0+struct xen_cpumask{ XEN_DECLARE_BITMAP(bits, XEN_NR_CPUS); }; +#ifndef __XEN__
Is that neccessary? typedefs are frowned upon in kernel.
include/xen/interface/xen.h struct shared_info { · line 431
Quoted 13 lines
include/xen/interface/xen.h +13
-0+typedef struct xen_cpumask xen_cpumask_t ; +#endif + +#define XEN_MAX_VNODES 8 +struct xen_vnode_data { +uint32_t vnode_id; +uint32_t mnode_id; +uint64_t nr_pages; +/* XXX: Can we use this in xen<->domain interfaces ? */ +struct xen_cpumask vcpu_mask;/* vnode_to_vcpumask */ +}; +#ifndef __XEN__ +typedef struct xen_vnode_data xen_vnode_data_t ;
Ditto.
Quoted 4 lines
include/xen/interface/xen.h +4
-0+#endif + +/* NUMA layout for the domain at the time of startup. +* Structure has to fit within a page. */
include/xen/interface/xen.h struct shared_info { · line 445
Quoted 10 lines
include/xen/interface/xen.h +10
-0+struct xen_domain_numa_layout { +uint32_t max_vcpus; +uint32_t max_vnodes; + +/* Only (max_vnodes*max_vnodes) entries are filled */ +uint32_t vnode_distance[XEN_MAX_VNODES *XEN_MAX_VNODES ]; +struct xen_vnode_data vnode_data[XEN_MAX_VNODES ]; +}; +#ifndef __XEN__ +typedef struct xen_domain_numa_layout xen_domain_numa_layout_t ;
Ditto.
include/xen/interface/xen.h struct start_info { · line 500
Quoted 11 lines
include/xen/interface/xen.h +4
-0+#endif +/* * Start-of-day memory layout for the initial domain (DOM0): * 1. The domain is started within contiguous virtual-memory region. @@ -449,6 +496,13 @@ struct start_info {unsigned long mod_start;/* VIRTUAL address of pre-loaded module. */ unsigned long mod_len;/* Size (bytes) of pre-loaded module. */ int8_t cmd_line[MAX_GUEST_CMDLINE ]; +/* The pfn range here covers both page table and p->m table frames. */ +unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */
Why is this added in this patch? That doesn't look to be used by your patch.
include/xen/interface/xen.h struct start_info { · line 501
Quoted 1 line
include/xen/interface/xen.h +1
-0+unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */
Ditto.
include/xen/interface/xen.h struct start_info { · line 504
Quoted 3 lines
include/xen/interface/xen.h +3
-0+struct { +uint32_t info_off;/* Offset of console_info struct. * +uint32_t info_size; /* Size of console_info struct from start.*/
Wrong comment.
Quoted 5 lines
include/xen/interface/xen.h +1
-0+ } numa_layout_info; };struct
dom0_vga_console_info{
Konrad, Thanks for the comments. I will make the changes and send over the patch.
Any comments on the general approach are welcome too.
-dulloor
Quoted 383 lines · Konrad Rzeszutek Wilk
Run this patch through
scripts/checkpatch.plarch/x86/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 944
Quoted 11 lines · Dulloor
arch/x86/kernel/setup.c +2
-1@@ -940,7 +940,8 @@ void __init setup_arch(char **cmdline_p) /* * Parse SRAT to discover nodes. */ - acpi_numa_init(); + if (acpi_numa > 0) + acpi_numa_init();Why? Why can't we just try acpi_numa_init()?
Quoted 18 lines
arch/x86/kernel/setup.c +0
-0#endif initmem_init(0, max_pfn);arch/x86/mm/numa_64.c +2
-0@@ -11,7 +11,9 @@ #include <linux/ctype.h> #include <linux/module.h> #include <linux/nodemask.h> +#include <linux/cpumask.h> #include <linux/sched.h> +#include <xen/interface/xen.h> #include <asm/e820.h> #include <asm/proto.h>arch/x86/mm/numa_64.c line 24
Quoted 4 lines
arch/x86/mm/numa_64.c +1
-0@@ -19,6 +21,7 @@ #include <asm/numa.h> #include <asm/acpi.h> #include <asm/k8.h> +#include <asm/xen/hypervisor.h> If one does not set
CONFIG_XENdoes this compile?arch/x86/mm/numa_64.c static int __init numa_emulation(unsigned long start_pfn, unsigned long last_pfn · line 431
Quoted 8 lines
arch/x86/mm/numa_64.c +0
-1struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; EXPORT_SYMBOL(node_data);@@ -428,7 +431,6 @@ static int __init numa_emulation(unsigned long start_pfn, unsigned long last_pfn*/ if (!strchr(cmdline, '*') && !strchr(cmdline, ',')) { long n = simple_strtol(cmdline, NULL, 0); -No need for this.
Quoted 5 lines
arch/x86/mm/numa_64.c +0
-0num_nodes = split_nodes_equally(nodes, &addr, max_addr, 0, n); if (num_nodes < 0) return num_nodes;@@ -522,16 +524,162 @@ out: numa_init_array();arch/x86/mm/numa_64.c out: · line 534
Quoted 10 lines
arch/x86/mm/numa_64.c +8
-0return 0; } +struct xen_domain_numa_layout pv_numa_layout; + +void dump_numa_layout (struct xen_domain_numa_layout *layout) +{ + unsigned int i, j; + char vcpumask[128]; + printk("NUMA-LAYOUT(Dom0) : vcpus(%u), vnodes(%u)\n", + layout->max_vcpus, layout->max_vnodes);Redo the printk's. They need
KERN_DEBUGarch/x86/mm/numa_64.c out: · line 542
Quoted 8 lines
arch/x86/mm/numa_64.c +8
-0+ for (i = 0; i < layout->max_vnodes; i++) + { + struct xen_vnode_data *vnode_data = &layout->vnode_data[i]; + cpumask_scnprintf(vcpumask, sizeof(vcpumask), + ((cpumask_t *)&vnode_data->vcpu_mask)); + printk("vnode[%u]:mnode(%u), node_nr_pages(%lx), vcpu_mask(%s)\n", + vnode_data->vnode_id, vnode_data->mnode_id, + (unsigned long)vnode_data->nr_pages, vcpumask);This one too.
arch/x86/mm/numa_64.c out: · line 545
Quoted 3 lines
arch/x86/mm/numa_64.c +3
-0+ } + + printk("vnode distances :\n");and
arch/x86/mm/numa_64.c out: · line 550
Quoted 5 lines
arch/x86/mm/numa_64.c +5
-0+ for (i = 0; i < layout->max_vnodes; i++) + printk("\tvnode[%u]", i); + for (i = 0; i < layout->max_vnodes; i++) + { + printk("\nvnode[%u]", i);this
arch/x86/mm/numa_64.c out: · line 553
Quoted 3 lines
arch/x86/mm/numa_64.c +3
-0+ for (j = 0; j < layout->max_vnodes; j++) + printk("\t%u", layout->vnode_distance[i*layout->max_vnodes + j]); + printk("\n");one to.
Quoted 6 lines
arch/x86/mm/numa_64.c +6
-0+ } + return; +} + +static void __init xen_init_slit_table (struct xen_domain_numa_layout *layout) +{arch/x86/mm/numa_64.c out: · line 569
Quoted 10 lines
arch/x86/mm/numa_64.c +10
-0+ /* Construct a slit table (using layout->vnode_distance). + * Copy it to acpi_slit. */ + return; +} +/* Distribute the vcpus over the vnodes according to their affinity */ +static void __init xen_init_numa_array (struct xen_domain_numa_layout *layout) +{ + int vcpu, vnode; + + printk(KERN_INFO "xen_numa_init_array - cpu_to_node initialization\n");
pr_debuginstead?Quoted 27 lines
arch/x86/mm/numa_64.c +27
-0+ + for (vnode = 0; vnode < layout->max_vnodes; vnode++) + { + struct xen_vnode_data *vnode_data = &layout->vnode_data[vnode]; + cpumask_t vcpu_mask = *((cpumask_t *)&vnode_data->vcpu_mask); + + for (vcpu = 0; vcpu < layout->max_vcpus; vcpu++) + { + if (cpu_isset(vcpu, vcpu_mask)) + { + if (early_cpu_to_node(vcpu) != NUMA_NO_NODE) + { + printk(KERN_INFO "EARLY vcpu[%d] on vnode[%d]\n", + vcpu, early_cpu_to_node(vcpu)); + continue; + } + printk(KERN_INFO "vcpu[%d] on vnode[%d]\n", vcpu, vnode); + numa_set_node(vcpu, vnode); + } + } + } + return; +} + +static int __init xen_numa_emulation (struct xen_domain_numa_layout *layout, + unsigned long start_pfn, unsigned long last_pfn) +{arch/x86/mm/numa_64.c out: · line 606
Quoted 10 lines
arch/x86/mm/numa_64.c +10
-0+ int num_vnodes, i; + u64 node_start_addr, node_end_addr, max_addr; + + printk(KERN_INFO "xen_numa_emulation : max_vnodes(%d), max_vcpus(%d)", + layout->max_vnodes, layout->max_vcpus); + dump_numa_layout(layout); + memset(&nodes, 0, sizeof(nodes)); + + num_vnodes = layout->max_vnodes; + BUG_ON(num_vnodes > MAX_NUMNODES);Hmm.. Is that really neccessary? What if we just do
WARN("some lengthy explanation"), and bail out and not initialize these structures?Quoted 23 lines
arch/x86/mm/numa_64.c +23
-0+ + max_addr = last_pfn << PAGE_SHIFT; + + node_start_addr = start_pfn << PAGE_SHIFT; + for (i = 0; i < num_vnodes; i++) + { + struct xen_vnode_data *vnode_data = &layout->vnode_data[i]; + u64 node_size = vnode_data->nr_pages << PAGE_SHIFT; + + node_size &= FAKE_NODE_MIN_HASH_MASK; /* 64MB aligned */ + + if (i == (num_vnodes-1)) + node_end_addr = max_addr; + else + { + node_end_addr = node_start_addr + node_size; + while ((node_end_addr - node_start_addr - + e820_hole_size(node_start_addr, node_end_addr)) < node_size) + { + node_end_addr += FAKE_NODE_MIN_SIZE; + if (node_end_addr > max_addr) { + node_end_addr = max_addr; + break;arch/x86/mm/numa_64.c out: · line 639
Quoted 10 lines
arch/x86/mm/numa_64.c +10
-0+ } + } + } + /* node_start_addr updated inside the function */ + if (setup_node_range(i, nodes, &node_start_addr, + (node_end_addr-node_start_addr), max_addr+1)) + BUG(); + } + + printk(KERN_INFO "XEN domain numa emulation - setup nodes\n");Is this neccessary? Can be it be debug?
arch/x86/mm/numa_64.c out: · line 644
Quoted 5 lines
arch/x86/mm/numa_64.c +5
-0+ + memnode_shift = compute_hash_shift(nodes, num_vnodes, NULL); + if (memnode_shift < 0) { + printk(KERN_ERR "No NUMA hash function found.\n"); + BUG();Wow. BUG? What about just bailing out and unset
xen_pv_emulationflag?Quoted 63 lines
arch/x86/mm/numa_64.c +28
-0+ } + /* XXX: Shouldn't be needed because we disabled acpi_numa very early ! */ + /* + * We need to vacate all active ranges that may have been registered by + * SRAT and set acpi_numa to -1 so that srat_disabled() always returns + * true. NUMA emulation has succeeded so we will not scan ACPI nodes. + */ + remove_all_active_ranges(); + + BUG_ON(acpi_numa >= 0); + for_each_node_mask(i, node_possible_map) { + e820_register_active_regions(i, nodes[i].start >> PAGE_SHIFT, + nodes[i].end >> PAGE_SHIFT); + setup_node_bootmem(i, nodes[i].start, nodes[i].end); + } + xen_init_slit_table(layout); + xen_init_numa_array(layout); + return 0; +} #endif /* CONFIG_NUMA_EMU */ void __init initmem_init(unsigned long start_pfn, unsigned long last_pfn) { int i; + struct xen_domain_numa_layout *numa_layout = &pv_numa_layout; + + int xen_pv_numa_enabled = numa_layout->max_vnodes; nodes_clear(node_possible_map); nodes_clear(node_online_map); #ifdef CONFIG_NUMA_EMU + if (xen_pv_domain() && xen_pv_numa_enabled) + { + if (!xen_numa_emulation(numa_layout, start_pfn, last_pfn)) + return; + } + if (cmdline && !numa_emulation(start_pfn, last_pfn)) return; nodes_clear(node_possible_map);arch/x86/xen/enlighten.c +3
-0@@ -83,6 +83,8 @@ void *xen_initial_gdt;*/ struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info; +struct xen_domain_numa_layout *HYPERVISOR_domain_numa_layout; + /** Flag to determine whether vcpu info placement is available on all * VCPUs. We assume it is to start with, and then set it to zero on @@ -1089,6 +1091,7 @@ static void __init xen_setup_stackprotector(void) pv_cpu_ops.load_gdt = xen_load_gdt; } +extern struct xen_domain_numa_layout pv_numa_layout; /* First C function to be called on Xen boot */ asmlinkage void __init xen_start_kernel(void) {arch/x86/xen/enlighten.c asmlinkage void __init xen_start_kernel(void) · line 1241
Quoted 9 lines
arch/x86/xen/enlighten.c +6
-0@@ -1230,6 +1233,12 @@ asmlinkage void __init xen_start_kernel(void) xen_start_info->console.domU.evtchn = 0; } + { + struct xen_domain_numa_layout *layout = + (void *)((char *)xen_start_info + + xen_start_info->numa_layout_info.info_off); + memcpy(&pv_numa_layout, layout, sizeof(*layout)); + }Shouldn't there be a check to see if the Xen actually exports this structure? Otherwise you might copy garbage in and set
pv_numa_layoutvalues to random values.Quoted 22 lines
arch/x86/xen/enlighten.c +0
-0xen_raw_console_write("about to get started...\n"); /* Start the world */arch/x86/xen/setup.c +3
-0@@ -281,6 +281,9 @@ void __init xen_arch_setup(void) printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); disable_acpi(); } + + acpi_numa = -1; + numa_off = 1; #endif /*include/xen/interface/xen.h +0
-0include/xen/interface/xen.h struct shared_info { · line 401
Quoted 4 lines
include/xen/interface/xen.h +1
-0@@ -398,6 +398,53 @@ struct shared_info { }; +#define XEN_NR_CPUS 64No way to share this with some other variable? Like
NR_CPUS?include/xen/interface/xen.h struct shared_info { · line 404
Quoted 3 lines
include/xen/interface/xen.h +3
-0+#if defined(__i386__) +#define XEN_BITS_PER_LONG 32 +#define XEN_BYTES_PER_LONG 4There gotta be some of these defined in other headers.
include/xen/interface/xen.h struct shared_info { · line 416
Quoted 12 lines
include/xen/interface/xen.h +12
-0+#define XEN_LONG_BYTEORDER 2 +#elif defined(__x86_64__) +#define XEN_BITS_PER_LONG 64 +#define XEN_BYTES_PER_LONG 8 +#define XEN_LONG_BYTEORDER 3 +#endif + +/* same as cpumask_t - in xen and even Linux (for now) */ +#define XEN_BITS_TO_LONGS (bits) \ + (((bits)+XEN_BITS_PER_LONG-1)/XEN_BITS_PER_LONG) +#define XEN_DECLARE_BITMAP (name,bits) \ + unsigned long name[XEN_BITS_TO_LONGS(bits)]I am pretty sure there are macros for this laready.
include/xen/interface/xen.h struct shared_info { · line 418
Quoted 2 lines
include/xen/interface/xen.h +2
-0+struct xen_cpumask{ XEN_DECLARE_BITMAP(bits, XEN_NR_CPUS); }; +#ifndef __XEN__Is that neccessary? typedefs are frowned upon in kernel.
include/xen/interface/xen.h struct shared_info { · line 431
Quoted 13 lines
include/xen/interface/xen.h +13
-0+typedef struct xen_cpumask xen_cpumask_t ; +#endif + +#define XEN_MAX_VNODES 8 +struct xen_vnode_data { + uint32_t vnode_id; + uint32_t mnode_id; + uint64_t nr_pages; + /* XXX: Can we use this in xen<->domain interfaces ? */ + struct xen_cpumask vcpu_mask; /* vnode_to_vcpumask */ +}; +#ifndef __XEN__ +typedef struct xen_vnode_data xen_vnode_data_t ;Ditto.
Quoted 4 lines
include/xen/interface/xen.h +4
-0+#endif + +/* NUMA layout for the domain at the time of startup. +* Structure has to fit within a page. */ include/xen/interface/xen.h struct shared_info { · line 445
Quoted 10 lines
include/xen/interface/xen.h +10
-0+struct xen_domain_numa_layout { + uint32_t max_vcpus; + uint32_t max_vnodes; + + /* Only (max_vnodes*max_vnodes) entries are filled */ + uint32_t vnode_distance[XEN_MAX_VNODES * XEN_MAX_VNODES]; + struct xen_vnode_data vnode_data[XEN_MAX_VNODES]; +}; +#ifndef __XEN__ +typedef struct xen_domain_numa_layout xen_domain_numa_layout_t ;Ditto.
Quoted 11 lines
include/xen/interface/xen.h +2
-0+#endif + /** Start-of-day memory layout for the initial domain (DOM0): * 1. The domain is started within contiguous virtual-memory region. @@ -449,6 +496,13 @@ struct start_info {unsigned long
mod_start; /* VIRTUAL address of pre-loaded module. */ unsigned longmod_len; /* Size (bytes) of pre-loaded module. */int8_tcmd_line[MAX_GUEST_CMDLINE];
+ /* The pfn range here covers both page table andp->mtable frames. */
+ unsigned long first_p2m_pfn;/* 1st pfn forming initialP->Mtable. */Why is this added in this patch? That doesn't look to be used by your patch.
Quoted 1 line
+ unsigned long nr_p2m_frames;/* # of pfns forming initial
P->Mtable. */Ditto.
Quoted 3 lines
+ struct {
+ uint32_tinfo_off; /* Offset ofconsole_infostruct. *
+ uint32_tinfo_size; /* Size ofconsole_infostruct from start.*/Wrong comment.
Quoted 5 lines
+ }
numa_layout_info;};
struct
dom0_vga_console_info{