From: Dulloor Subject: Re: [RFC] pv guest numa [RE: Host Numa informtion in dom0] Date: Thu, 18 Feb 2010 11:24:19 -0500 Message-ID: <940bcfd21002180824x40201ae2tc07d248bcde9cc5b@mail.gmail.com> References: <940bcfd21002122225i2c79aad2q91ff6432faef3192@mail.gmail.com> <20100216174900.GB21067@phenom.dumpdata.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20100216174900.GB21067@phenom.dumpdata.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Konrad Rzeszutek Wilk Cc: Andre Przywara , Ian Pratt , "xen-devel@lists.xensource.com" , Keir Fraser , "Nakajima, Jun" List-Id: xen-devel@lists.xenproject.org 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 On Tue, Feb 16, 2010 at 12:49 PM, Konrad Rzeszutek Wilk wrote: > Run this patch through scripts/checkpatch.pl > > On Sat, Feb 13, 2010 at 01:25:22AM -0500, Dulloor wrote: >> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c >> index 86bef0f..7a24070 100644 >> --- a/arch/x86/kernel/setup.c >> +++ b/arch/x86/kernel/setup.c >> @@ -940,7 +940,8 @@ void __init setup_arch(char **cmdline_p) >> =A0 =A0 =A0 /* >> =A0 =A0 =A0 =A0* Parse SRAT to discover nodes. >> =A0 =A0 =A0 =A0*/ >> - =A0 =A0 acpi_numa_init(); >> + =A0 =A0if (acpi_numa > 0) >> + =A0 =A0 =A0 =A0 acpi_numa_init(); > > Why? Why can't we just try =A0acpi_numa_init()? > >> =A0#endif >> >> =A0 =A0 =A0 initmem_init(0, max_pfn); >> diff --git a/arch/x86/mm/numa_64.c b/arch/x86/mm/numa_64.c >> index 459913b..14fa654 100644 >> --- a/arch/x86/mm/numa_64.c >> +++ b/arch/x86/mm/numa_64.c >> @@ -11,7 +11,9 @@ >> =A0#include >> =A0#include >> =A0#include >> +#include >> =A0#include >> +#include >> >> =A0#include >> =A0#include >> @@ -19,6 +21,7 @@ >> =A0#include >> =A0#include >> =A0#include >> +#include > > If one does not set CONFIG_XEN does this compile? >> >> =A0struct pglist_data *node_data[MAX_NUMNODES] __read_mostly; >> =A0EXPORT_SYMBOL(node_data); >> @@ -428,7 +431,6 @@ static int __init numa_emulation(unsigned long start= _pfn, unsigned long last_pfn >> =A0 =A0 =A0 =A0*/ >> =A0 =A0 =A0 if (!strchr(cmdline, '*') && !strchr(cmdline, ',')) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 long n =3D simple_strtol(cmdline, NULL, 0); >> - > > No need for this. >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 num_nodes =3D split_nodes_equally(nodes, &ad= dr, max_addr, 0, n); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (num_nodes < 0) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return num_nodes; >> @@ -522,16 +524,162 @@ out: >> =A0 =A0 =A0 numa_init_array(); >> =A0 =A0 =A0 return 0; >> =A0} >> +struct xen_domain_numa_layout pv_numa_layout; >> + >> +void dump_numa_layout(struct xen_domain_numa_layout *layout) >> +{ >> + =A0 =A0unsigned int i, j; >> + =A0 =A0char vcpumask[128]; >> + =A0 =A0printk("NUMA-LAYOUT(Dom0) : vcpus(%u), vnodes(%u)\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0layout->max_vcp= us, layout->max_vnodes); > > Redo the printk's. They need KERN_DEBUG >> + =A0 =A0for (i =3D 0; i < layout->max_vnodes; i++) >> + =A0 =A0{ >> + =A0 =A0 =A0 =A0struct xen_vnode_data *vnode_data =3D &layout->vnode_da= ta[i]; >> + =A0 =A0 =A0 =A0cpumask_scnprintf(vcpumask, sizeof(vcpumask), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0((cpuma= sk_t *)&vnode_data->vcpu_mask)); >> + =A0 =A0 =A0 =A0printk("vnode[%u]:mnode(%u), node_nr_pages(%lx), vcpu_m= ask(%s)\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vnode_data->vnode_id, vnode_data->mnode= _id, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(unsigned long)vnode_data->nr_pages, vc= pumask); > > This one too. >> + =A0 =A0} >> + >> + =A0 =A0printk("vnode distances :\n"); > > and >> + =A0 =A0for (i =3D 0; i < layout->max_vnodes; i++) >> + =A0 =A0 =A0 =A0printk("\tvnode[%u]", i); >> + =A0 =A0for (i =3D 0; i < layout->max_vnodes; i++) >> + =A0 =A0{ >> + =A0 =A0 =A0 =A0printk("\nvnode[%u]", i); > > this >> + =A0 =A0 =A0 =A0for (j =3D 0; j < layout->max_vnodes; j++) >> + =A0 =A0 =A0 =A0 =A0 =A0printk("\t%u", layout->vnode_distance[i*layout-= >max_vnodes + j]); >> + =A0 =A0 =A0 =A0printk("\n"); > one to. >> + =A0 =A0} >> + =A0 =A0return; >> +} >> + >> +static void __init xen_init_slit_table(struct xen_domain_numa_layout *l= ayout) >> +{ >> + =A0 =A0/* Construct a slit table (using layout->vnode_distance). >> + =A0 =A0 * Copy it to acpi_slit. */ >> + =A0 =A0return; >> +} >> +/* Distribute the vcpus over the vnodes according to their affinity */ >> +static void __init xen_init_numa_array(struct xen_domain_numa_layout *l= ayout) >> +{ >> + =A0 =A0 int vcpu, vnode; >> + >> + =A0 =A0 printk(KERN_INFO "xen_numa_init_array - cpu_to_node initializa= tion\n"); > > pr_debug instead? >> + >> + =A0 =A0for (vnode =3D 0; vnode < layout->max_vnodes; vnode++) >> + =A0 =A0{ >> + =A0 =A0 =A0 =A0struct xen_vnode_data *vnode_data =3D &layout->vnode_da= ta[vnode]; >> + =A0 =A0 =A0 =A0cpumask_t vcpu_mask =3D *((cpumask_t *)&vnode_data->vcp= u_mask); >> + >> + =A0 =A0 =A0 =A0for (vcpu =3D 0; vcpu < layout->max_vcpus; vcpu++) >> + =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0if (cpu_isset(vcpu, vcpu_mask)) >> + =A0 =A0 =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (early_cpu_to_node(vcpu) !=3D NUMA_N= O_NODE) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(KERN_INFO "EARLY vcpu[%d= ] on vnode[%d]\n", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0vcpu, early_cpu_to_node(vcpu)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(KERN_INFO "vcpu[%d] on vnode[%d]= \n", vcpu, vnode); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 numa_set_node(vcpu, vnode); >> + =A0 =A0 =A0 =A0 =A0 =A0} >> + =A0 =A0 =A0 =A0} >> + =A0 =A0} >> + =A0 =A0return; >> +} >> + >> +static int __init xen_numa_emulation(struct xen_domain_numa_layout *lay= out, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned long s= tart_pfn, unsigned long last_pfn) >> +{ >> + =A0 =A0 int num_vnodes, i; >> + =A0 =A0u64 node_start_addr, node_end_addr, max_addr; >> + >> + =A0 =A0printk(KERN_INFO "xen_numa_emulation : max_vnodes(%d), max_vcpu= s(%d)", >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0layout->max_vnodes, layout->max_vcpus); >> + =A0 =A0dump_numa_layout(layout); >> + =A0 =A0 memset(&nodes, 0, sizeof(nodes)); >> + >> + =A0 =A0num_vnodes =3D layout->max_vnodes; >> + =A0 =A0BUG_ON(num_vnodes > MAX_NUMNODES); > > Hmm.. Is that really neccessary? What if we just do WARN("some lengthy ex= planation"), > and bail out and not initialize these structures? >> + >> + =A0 =A0max_addr =3D last_pfn << PAGE_SHIFT; >> + >> + =A0 =A0node_start_addr =3D start_pfn << PAGE_SHIFT; >> + =A0 =A0for (i =3D 0; i < num_vnodes; i++) >> + =A0 =A0{ >> + =A0 =A0 =A0 =A0struct xen_vnode_data *vnode_data =3D &layout->vnode_da= ta[i]; >> + =A0 =A0 =A0 =A0u64 node_size =3D vnode_data->nr_pages << PAGE_SHIFT; >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 node_size &=3D FAKE_NODE_MIN_HASH_MASK; /* 64M= B aligned */ >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D (num_vnodes-1)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 node_end_addr =3D max_addr; >> + =A0 =A0 =A0 =A0 =A0 =A0 else >> + =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0node_end_addr =3D node_start_addr + node_size; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 while ((node_end_addr - node_s= tart_addr - >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0e820_hole_size(node_start_addr, node_en= d_addr)) < node_size) >> + =A0 =A0 =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0node_end_addr +=3D FAKE_NODE_MIN_SIZE; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (node_end_a= ddr > max_addr) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 node_end_addr =3D max_addr; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 break; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0} >> + =A0 =A0 =A0 =A0/* node_start_addr updated inside the function */ >> + =A0 =A0 =A0 =A0if (setup_node_range(i, nodes, &node_start_addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(node_end_addr-node_start_addr)= , max_addr+1)) >> + =A0 =A0 =A0 =A0 =A0 =A0BUG(); >> + =A0 =A0} >> + >> + =A0 =A0 printk(KERN_INFO "XEN domain numa emulation - setup nodes\n"); > > Is this neccessary? Can be it be debug? >> + >> + =A0 =A0memnode_shift =3D compute_hash_shift(nodes, num_vnodes, NULL); >> + =A0 =A0if (memnode_shift < 0) { >> + =A0 =A0 =A0 =A0 printk(KERN_ERR "No NUMA hash function found.\n"); >> + =A0 =A0 =A0 =A0BUG(); > > Wow. BUG? What about just bailing out and unset xen_pv_emulation flag? > >> + =A0 =A0} >> + =A0 =A0/* XXX: Shouldn't be needed because we disabled acpi_numa very = early ! */ >> + =A0 =A0 /* >> + =A0 =A0 =A0* We need to vacate all active ranges that may have been re= gistered by >> + =A0 =A0 =A0* SRAT and set acpi_numa to -1 so that srat_disabled() alwa= ys returns >> + =A0 =A0 =A0* true. =A0NUMA emulation has succeeded so we will not scan= ACPI nodes. >> + =A0 =A0 =A0*/ >> + =A0 =A0 remove_all_active_ranges(); >> + >> + =A0 =A0BUG_ON(acpi_numa >=3D 0); >> + =A0 =A0 for_each_node_mask(i, node_possible_map) { >> + =A0 =A0 =A0 =A0 =A0 =A0 e820_register_active_regions(i, nodes[i].start= >> PAGE_SHIFT, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 nodes[i].end >> PAGE_SHIFT); >> + =A0 =A0 =A0 =A0 =A0 =A0 setup_node_bootmem(i, nodes[i].start, nodes[i]= .end); >> + =A0 =A0 } >> + =A0 =A0xen_init_slit_table(layout); >> + =A0 =A0 xen_init_numa_array(layout); >> + =A0 =A0 return 0; >> +} >> =A0#endif /* CONFIG_NUMA_EMU */ >> >> =A0void __init initmem_init(unsigned long start_pfn, unsigned long last_= pfn) >> =A0{ >> =A0 =A0 =A0 int i; >> + =A0 =A0struct xen_domain_numa_layout *numa_layout =3D &pv_numa_layout; >> + >> + =A0 =A0int xen_pv_numa_enabled =3D numa_layout->max_vnodes; >> >> =A0 =A0 =A0 nodes_clear(node_possible_map); >> =A0 =A0 =A0 nodes_clear(node_online_map); >> >> =A0#ifdef CONFIG_NUMA_EMU >> + =A0 =A0if (xen_pv_domain() && xen_pv_numa_enabled) >> + =A0 =A0{ >> + =A0 =A0 =A0 =A0if (!xen_numa_emulation(numa_layout, start_pfn, last_pf= n)) >> + =A0 =A0 =A0 =A0 =A0 =A0return; >> + =A0 =A0} >> + >> =A0 =A0 =A0 if (cmdline && !numa_emulation(start_pfn, last_pfn)) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 return; >> =A0 =A0 =A0 nodes_clear(node_possible_map); >> diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c >> index ecb9b0d..b020555 100644 >> --- a/arch/x86/xen/enlighten.c >> +++ b/arch/x86/xen/enlighten.c >> @@ -83,6 +83,8 @@ void *xen_initial_gdt; >> =A0 */ >> =A0struct shared_info *HYPERVISOR_shared_info =3D (void *)&xen_dummy_sha= red_info; >> >> +struct xen_domain_numa_layout *HYPERVISOR_domain_numa_layout; >> + >> =A0/* >> =A0 * Flag to determine whether vcpu info placement is available on all >> =A0 * VCPUs. =A0We assume it is to start with, and then set it to zero o= n >> @@ -1089,6 +1091,7 @@ static void __init xen_setup_stackprotector(void) >> =A0 =A0 =A0 pv_cpu_ops.load_gdt =3D xen_load_gdt; >> =A0} >> >> +extern struct xen_domain_numa_layout pv_numa_layout; >> =A0/* First C function to be called on Xen boot */ >> =A0asmlinkage void __init xen_start_kernel(void) >> =A0{ >> @@ -1230,6 +1233,12 @@ asmlinkage void __init xen_start_kernel(void) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 xen_start_info->console.domU.evtchn =3D 0; >> =A0 =A0 =A0 } >> >> + =A0 =A0{ >> + =A0 =A0 =A0 =A0struct xen_domain_numa_layout *layout =3D >> + =A0 =A0 =A0 =A0 =A0 =A0(void *)((char *)xen_start_info + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0xen_start_info->numa_la= yout_info.info_off); >> + =A0 =A0 =A0 =A0memcpy(&pv_numa_layout, layout, sizeof(*layout)); >> + =A0 =A0} > > 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. > >> =A0 =A0 =A0 xen_raw_console_write("about to get started...\n"); >> >> =A0 =A0 =A0 /* Start the world */ >> diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c >> index 612f2c9..cb944a2 100644 >> --- a/arch/x86/xen/setup.c >> +++ b/arch/x86/xen/setup.c >> @@ -281,6 +281,9 @@ void __init xen_arch_setup(void) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "ACPI in unprivileged domai= n disabled\n"); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 disable_acpi(); >> =A0 =A0 =A0 } >> + >> + =A0 =A0acpi_numa =3D -1; >> + =A0 =A0numa_off =3D 1; >> =A0#endif >> >> =A0 =A0 =A0 /* >> diff --git a/include/xen/interface/xen.h b/include/xen/interface/xen.h >> index 812ffd5..d4588fa 100644 >> --- a/include/xen/interface/xen.h >> +++ b/include/xen/interface/xen.h >> @@ -398,6 +398,53 @@ struct shared_info { >> >> =A0}; >> >> +#define XEN_NR_CPUS 64 > No way to share this with some other variable? Like NR_CPUS? > >> +#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. >> +#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) \ >> + =A0 =A0(((bits)+XEN_BITS_PER_LONG-1)/XEN_BITS_PER_LONG) >> +#define XEN_DECLARE_BITMAP(name,bits) \ >> + =A0 =A0unsigned long name[XEN_BITS_TO_LONGS(bits)] > > I am pretty sure there are macros for this laready. >> +struct xen_cpumask{ XEN_DECLARE_BITMAP(bits, XEN_NR_CPUS); }; >> +#ifndef __XEN__ > > Is that neccessary? typedefs are frowned upon in kernel. >> +typedef struct xen_cpumask xen_cpumask_t; >> +#endif >> + >> +#define XEN_MAX_VNODES 8 >> +struct xen_vnode_data { >> + =A0 =A0uint32_t vnode_id; >> + =A0 =A0uint32_t mnode_id; >> + =A0 =A0uint64_t nr_pages; >> + =A0 =A0/* XXX: Can we use this in xen<->domain interfaces ? */ >> + =A0 =A0struct xen_cpumask vcpu_mask; /* vnode_to_vcpumask */ >> +}; >> +#ifndef __XEN__ >> +typedef struct xen_vnode_data xen_vnode_data_t; > > Ditto. >> +#endif >> + >> +/* NUMA layout for the domain at the time of startup. >> + * Structure has to fit within a page. */ >> +struct xen_domain_numa_layout { >> + =A0 =A0uint32_t max_vcpus; >> + =A0 =A0uint32_t max_vnodes; >> + >> + =A0 =A0/* Only (max_vnodes*max_vnodes) entries are filled */ >> + =A0 =A0uint32_t vnode_distance[XEN_MAX_VNODES * XEN_MAX_VNODES]; >> + =A0 =A0struct xen_vnode_data vnode_data[XEN_MAX_VNODES]; >> +}; >> +#ifndef __XEN__ >> +typedef struct xen_domain_numa_layout xen_domain_numa_layout_t; > > Ditto. >> +#endif >> + >> =A0/* >> =A0 * Start-of-day memory layout for the initial domain (DOM0): >> =A0 * =A01. The domain is started within contiguous virtual-memory regio= n. >> @@ -449,6 +496,13 @@ struct start_info { >> =A0 =A0 =A0 unsigned long mod_start; =A0 =A0/* VIRTUAL address of pre-lo= aded module. =A0*/ >> =A0 =A0 =A0 unsigned long mod_len; =A0 =A0 =A0/* Size (bytes) of pre-loa= ded module. =A0 =A0 */ >> =A0 =A0 =A0 int8_t cmd_line[MAX_GUEST_CMDLINE]; >> + =A0 =A0/* The pfn range here covers both page table and p->m table fra= mes. =A0 */ >> + =A0 =A0unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M tab= le. =A0 =A0*/ > > Why is this added in this patch? That doesn't look to be used by your > patch. >> + =A0 =A0unsigned long nr_p2m_frames;/* # of pfns forming initial P->M t= able. =A0*/ > > Ditto. >> + =A0 =A0struct { >> + =A0 =A0 =A0 =A0uint32_t info_off; =A0/* Offset of console_info struct.= =A0 =A0 =A0 =A0 * >> + =A0 =A0 =A0 =A0uint32_t info_size; /* Size of console_info struct from= start.*/ > > Wrong comment. >> + =A0 =A0} numa_layout_info; > >> =A0}; >> >> =A0struct dom0_vga_console_info { > >