vnuma hook to debug-keys u
PATCH v9 3/9 vnuma hook to debug-keys u
Add debug-keys hook to display vnuma topology.
--- xen/arch/x86/numa.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
xen/arch/x86/numa.c +30 -1
@@ -347,7 +347,7 @@ EXPORT_SYMBOL(node_data);static void dump_numa (unsigned char key) {s_time_t now =NOW (); -int i; +int i, j, n, err;struct domain *d;struct page_info *page;unsigned int page_num_node[MAX_NUMNODES ];
@@ -389,6 +389,35 @@ static void dump_numa(unsigned char key)for_each_online_node (i)printk (" Node %u: %u\n" , i, page_num_node[i]); + +if (d->vnuma) { +printk (" Domain has %u vnodes, %u vcpus\n" , + d->vnuma->nr_vnodes, d->max_vcpus); +for (i =0 ; i < d->vnuma->nr_vnodes; i++) { + err =snprintf (keyhandler_scratch,12 ,"%u" , + d->vnuma->vnode_to_pnode[i]); +if (err <0 || d->vnuma->vnode_to_pnode[i] ==NUMA_NO_NODE ) +snprintf (keyhandler_scratch,3 ,"???" ); + +printk (" vnode %3u - pnode %s," , i, keyhandler_scratch); +printk (" %" PRIu64" MB, " , (d->vnuma->vmemrange[i].end - + d->vnuma->vmemrange[i].start) >>20 ); + +printk ("vcpu nrs: " ); +for (j =0 , n =0 ; j < d->max_vcpus; j++) { +if (d->vnuma->vcpu_to_vnode[j] == i) { +if ( ((n +1 ) %8 ) ==0 ) +printk ("%d\n" , j); +else if ( !(n %8 ) && n !=0 ) +printk ("%s%d " ," " , j); +else +printk ("%d " , j); + n++; + } + } +printk ("\n" ); + } + } }rcu_read_unlock (&domlist_read_lock);
Signature · 1 line
1.7.10.4
PATCH v9 4/9 libxc: Introduce xc_domain_setvnuma to set vNUMA
With the introduction of the XEN_DOMCTL_setvnumainfo in patch titled: "xen: vnuma topology and subop hypercalls" we put in the plumbing here to use from the toolstack. The user is allowed to call this multiple times if they wish so. It will error out if the nr_vnodes or nr_vcpus is zero.
--- tools/libxc/xc_domain.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ tools/libxc/xenctrl.h | 10 +++++++ 2 files changed, 78 insertions(+)
tools/libxc/xc_domain.c +68 -0
@@ -2124,6 +2124,74 @@ int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,return do_domctl (xch, &domctl); } +/* Plumbing Xen with vNUMA topology */ +int xc_domain_setvnuma (xc_interface *xch, +uint32_t domid, +uint32_t nr_vnodes, +uint32_t nr_vmemranges, +uint32_t nr_vcpus, +vmemrange_t *vmemrange, +unsigned int *vdistance, +unsigned int *vcpu_to_vnode, +unsigned int *vnode_to_pnode) +{ +int rc; +DECLARE_DOMCTL ; +DECLARE_HYPERCALL_BOUNCE (vmemrange,sizeof (*vmemrange) * nr_vmemranges, +XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); +DECLARE_HYPERCALL_BOUNCE (vdistance,sizeof (*vdistance) * + nr_vnodes * nr_vnodes, +XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); +DECLARE_HYPERCALL_BOUNCE (vcpu_to_vnode,sizeof (*vcpu_to_vnode) * nr_vcpus, +XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); +DECLARE_HYPERCALL_BOUNCE (vnode_to_pnode,sizeof (*vnode_to_pnode) * + nr_vnodes, +XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); + errno =EINVAL ; + +if ( nr_vnodes ==0 || nr_vmemranges ==0 || + nr_vmemranges < nr_vnodes || nr_vcpus ==0 ) +return -1 ; + +if ( !vdistance || !vcpu_to_vnode || !vmemrange || !vnode_to_pnode ) + { +PERROR ("%s: Cant set vnuma without initializing topology" , __func__); +return -1 ; + } + +if (xc_hypercall_bounce_pre (xch, vmemrange) || +xc_hypercall_bounce_pre (xch, vdistance) || +xc_hypercall_bounce_pre (xch, vcpu_to_vnode) || +xc_hypercall_bounce_pre (xch, vnode_to_pnode) ) + { + rc =-1 ; + goto vnumaset_fail; + + } + +set_xen_guest_handle (domctl.u.vnuma.vmemrange, vmemrange); +set_xen_guest_handle (domctl.u.vnuma.vdistance, vdistance); +set_xen_guest_handle (domctl.u.vnuma.vcpu_to_vnode, vcpu_to_vnode); +set_xen_guest_handle (domctl.u.vnuma.vnode_to_pnode, vnode_to_pnode); + + domctl.cmd = XEN_DOMCTL_setvnumainfo; + domctl.domain = (domid_t )domid; + domctl.u.vnuma.nr_vnodes = nr_vnodes; + domctl.u.vnuma.nr_vmemranges = nr_vmemranges; + domctl.u.vnuma.nr_vcpus = nr_vcpus; + domctl.u.vnuma.pad =0 ; + + rc =do_domctl (xch, &domctl); + + vnumaset_fail: +xc_hypercall_bounce_post (xch, vmemrange); +xc_hypercall_bounce_post (xch, vdistance); +xc_hypercall_bounce_post (xch, vcpu_to_vnode); +xc_hypercall_bounce_post (xch, vnode_to_pnode); + +return rc; +} +/* * Local variables: * mode: C
tools/libxc/xenctrl.h +10 -0
@@ -1245,6 +1245,16 @@ int xc_domain_set_memmap_limit(xc_interface *xch,uint32_t domid, unsigned long map_limitkb); +int xc_domain_setvnuma (xc_interface *xch, +uint32_t domid, +uint32_t nr_vnodes, +uint32_t nr_regions, +uint32_t nr_vcpus, +vmemrange_t *vmemrange, +unsigned int *vdistance, +unsigned int *vcpu_to_vnode, +unsigned int *vnode_to_pnode); +#if defined(__i386__) || defined(__x86_64__)/* * PC BIOS standard E820 types and structure.
Signature · 1 line
1.7.10.4
PATCH v9 5/9 libxl: vnuma types declararion
In reply to Elena UfimtsevaAdds vnuma topology types declarations to libxl_domain_build_info structure.
--- tools/libxl/libxl_types.idl | 8 +++++++- tools/libxl/libxl_vnuma.h | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_vnuma.h
tools/libxl/libxl_types.idl +7 -1
@@ -333,7 +333,13 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("disable_migrate", libxl_defbool), ("cpuid", libxl_cpuid_policy_list), ("blkdev_start", string), - + ("vnodes", uint32), + ("vmemranges", uint32), + ("vnuma_mem", Array(uint64, "num_vnuma_mem")), + ("vnuma_vcpumap", Array(uint32, "num_vnuma_vcpumap")), + ("vdistance", Array(uint32, "num_vdistance")), + ("vnuma_vnodemap", Array(uint32, "num_vnuma_vnondemap")), + ("vnuma_autoplacement", libxl_defbool), ("device_model_version", libxl_device_model_version), ("device_model_stubdomain", libxl_defbool), # if you set device_model you must set device_model_version too
tools/libxl/libxl_vnuma.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef LIBXL_VNUMA_H +#define LIBXL_VNUMA_H + +#include "libxl_osdeps.h" /* must come before any other headers */ + +#define VNUMA_NO_NODE ~((unsigned int)0) + +/* +* Min vNUMA node size in MBytes from Linux for x86 architecture. +* See linux source code arch/x86/include/asm/numa.h +*/ +#define MIN_VNODE_SIZE (4) + +#define MAX_VNUMA_NODES ((unsigned int)1 << 10) + +#endif
Signature · 1 line
1.7.10.4
PATCH v9 6/9 libxl: build numa nodes memory blocks
In reply to Elena UfimtsevaCreate the vmemrange structure based on the PV guests E820 map. Values are in in Megabytes. Also export the E820 filter code e820_sanitize out to be available internally.
As Xen can support mutiranges vNUMA nodes, for PV guest it is one range per one node. The other domain types should have their building routines implemented.
Changes since v8:
- Added setting of the vnuma memory ranges node ids;
--- tools/libxl/libxl_internal.h | 9 ++ tools/libxl/libxl_numa.c | 201 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_x86.c | 3 +- 3 files changed, 212 insertions(+), 1 deletion(-)
tools/libxl/libxl_internal.h +9 -0
@@ -3088,6 +3088,15 @@ void libxl__numa_candidate_put_nodemap(libxl__gc *gc,libxl_bitmap_copy (CTX , &cndt->nodemap, nodemap); } +bool libxl__vnodemap_is_usable (libxl__gc *gc,libxl_domain_build_info *info); + +int e820_sanitize (libxl_ctx *ctx,struct e820entry src[],uint32_t *nr_entries, +unsigned long map_limitkb,unsigned long balloon_kb); + +int libxl__vnuma_align_mem (libxl__gc *gc,uint32_t domid, +struct libxl_domain_build_info *b_info, +vmemrange_t *memblks); + _hidden int libxl__ms_vm_genid_set(libxl__gc *gc, uint32_t domid,const libxl_ms_vm_genid *id);
tools/libxl/libxl_numa.c +201 -0
213 lines not on this page · raw message
tools/libxl/libxl_x86.c +2 -1
@@ -1,5 +1,6 @@#include "libxl_internal.h" #include "libxl_arch.h" +#include "libxl_vnuma.h" static const char *e820_names (int type) {
@@ -14,7 +15,7 @@ static const char *e820_names(int type)return "Unknown" ; } -static int e820_sanitize (libxl_ctx *ctx,struct e820entry src[], +int e820_sanitize (libxl_ctx *ctx,struct e820entry src[],uint32_t *nr_entries,unsigned long map_limitkb,unsigned long balloon_kb)
Signature · 1 line
1.7.10.4
PATCH v9 7/9 libxc: allocate domain memory for vnuma enabled
In reply to Elena UfimtsevavNUMA-aware domain memory allocation based on provided vnode to pnode map. If this map is not defined, use default allocation. Default allocation will not specify any physical node when allocating memory.
Domain creation will fail if at least one node was not defined.
--- tools/libxc/xc_dom.h | 13 ++++++++ tools/libxc/xc_dom_x86.c | 76 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 12 deletions(-)
tools/libxc/xc_dom.h +13 -0
@@ -164,6 +164,16 @@ struct xc_dom_image {/* kernel loader */ struct xc_dom_arch *arch_hooks; + +/* +* vNUMA topology and memory allocation structure. +* Defines the way to allocate memory on per NUMA +* physical defined by vnode_to_pnode. +*/ +uint32_t vnodes; +uint64_t *numa_memszs; +unsigned int *vnode_to_pnode; +/* allocate up to virt_alloc_end */ int (*allocate) (struct xc_dom_image * dom,xen_vaddr_t up_to); };
@@ -385,6 +395,9 @@ static inline xen_pfn_t xc_dom_p2m_guest(struct xc_dom_image *dom,int arch_setup_meminit (struct xc_dom_image *dom);int arch_setup_bootearly (struct xc_dom_image *dom);int arch_setup_bootlate (struct xc_dom_image *dom); +int arch_boot_alloc (struct xc_dom_image *dom); + +#define LIBXC_VNUMA_NO_NODE ~((unsigned int)0)/* * Local variables:
tools/libxc/xc_dom_x86.c +64 -12
96 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v9 8/9 libxl: vnuma nodes placement bits
In reply to Elena UfimtsevaAutomatic numa placement cancels manual vnode placement mechanism. If numa placement explicitly specified, try to fit vnodes to the physical nodes.
Changes since v8:
- Addded number of ranges vmemranges for future support of multi-range nodes; For PV guest it is set to same value as number of vNUMA nodes.
--- tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_dom.c | 204 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+)
tools/libxl/libxl_create.c +1 -0
@@ -203,6 +203,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, }libxl_defbool_setdefault (&b_info->numa_placement, true); +libxl_defbool_setdefault (&b_info->vnuma_autoplacement, true);if (b_info->max_memkb ==LIBXL_MEMKB_DEFAULT ) b_info->max_memkb =32 *1024 ;
tools/libxl/libxl_dom.c +204 -0
253 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v9 9/9 libxl: vnuma topology configuration parser and doc
In reply to Elena UfimtsevaParses vnuma topoplogy number of nodes and memory ranges. If not defined, initializes vnuma with only one node and default topology. This one node covers all domain memory and all vcpus assigned to it.
--- docs/man/xl.cfg.pod.5 | 77 ++++++++ tools/libxl/xl_cmdimpl.c | 434 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 511 insertions(+)
docs/man/xl.cfg.pod.5 +77 -0
@@ -264,6 +264,83 @@ if the values of B<memory=> and B<maxmem=> differ. A "pre-ballooned" HVM guest needs a balloon driver, without a balloon driver it will crash. +=item B<vnuma_nodes=N> + +Number of vNUMA nodes the guest will be initialized with on boot. +PV guest by default will have one vnuma node. + +=item B<vnuma_mem=[vmem1, vmem2, ...]> + +List of memory sizes for each node, defined in MBytes. Number of items listed must +match nr_vnodes. If the sum of all vnode memories does not match the domain memory +or there are missing nodes, it will fail. +If not specified, memory will be equally split between vnodes. Current minimum +memory size for one node is limited by 32MB. + +Example: vnuma_mem=[1024, 1024, 2048, 2048] +Total amount of memory in guest: 6GB + +=item B<vdistance=[d1, d2]> + +Defines the distance table for vNUMA nodes. NUMA topology distances are +represented by two dimensional square matrix. One element of it [i,j] is +a distance between nodes i and j. Trivial case is where all diagonal elements +are equal and matrix is symmetrical. vdistance configuration option allows +to define two values d1 and d2. d1 will be used for all diagonal elements of +distance matrix. All other values will be equal to d2 value. Usually distances +are multiple of 10 in Linux and same rule used here. +If not specified, the default constants values will be used for distance, +e.g. [10, 20]. For one node default distance is [10]; + +Examples: +vnodes = 3 +vdistance=[10, 20] +will create this distance table (this is default setting as well): +[10, 20, 20] +[20, 10, 20] +[20, 20, 10] + +=item B<vnuma_vcpumap=[node_nr, node_nr, ...]> + +Defines vcpu to vnode mapping as a list of integers. The position in the list +is a vcpu number, and the value is the vnode number to which the vcpu will be +assigned to. +Current limitations: +- vNUMA node must have at least one vcpu, otherwise default vcpu_to_vnode will be used. +- Total number of vnodes cannot be bigger then number of vcpus. + +Example: +Map of 4 vcpus to 2 vnodes: +0,1 vcpu -> vnode0 +2,3 vcpu -> vnode1: + +vnuma_vcpumap = [0, 0, 1, 1] + 4 vcpus here - 0 1 2 3 + +=item B<vnuma_vnodemap=[p1, p2, ..., pn]> + +List of physical node numbers, position in the list represents vnode number. +Used for manual placement of vnuma nodes to physical NUMA nodes. +Will not be used if automatic numa placement is active. + +Example: +assume NUMA machine with 4 physical nodes. Placing vnuma node 0 to pnode 2, +vnuma node 1 to pnode 3: +vnode0 -> pnode2 +vnode1 -> pnode3 + +vnuma_vnodemap=[2, 3] +first vnode will be placed on node 2, second on node 3. + +=item B<vnuma_autoplacement=[0|1]> + +If set to 1 and automatic NUMA placement is enabled, automatically will find the best +physical node to place vnuma nodes on. vnuma_vnodemap will be ignored. Automatic NUMA +placement is enabled if domain has no pinned cpus. +If vnuma_autoplacement is set to 0, then the vnodes will be placed on NUMA nodes set +in vnuma_vnodemap if there is enough memory on physical nodes. If not, then the allocation +will be made on any of the available node and be placed on multiple physical NUMA nodes. + =back =head3 Event Actions
tools/libxl/xl_cmdimpl.c +434 -0
452 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 29.08.14 at 05:06, <[email protected]> wrote:
xen/arch/x86/numa.c +19
-0@@ -389,6 +389,35 @@ static void dump_numa(unsigned char key)for_each_online_node (i)printk (" Node %u: %u\n" , i, page_num_node[i]); + +if (d->vnuma) { +printk (" Domain has %u vnodes, %u vcpus\n" , + d->vnuma->nr_vnodes, d->max_vcpus); +for (i =0 ; i < d->vnuma->nr_vnodes; i++) { + err =snprintf (keyhandler_scratch,12 ,"%u" , + d->vnuma->vnode_to_pnode[i]); +if (err <0 || d->vnuma->vnode_to_pnode[i] ==NUMA_NO_NODE ) +snprintf (keyhandler_scratch,3 ,"???" ); + +printk (" vnode %3u - pnode %s," , i, keyhandler_scratch); +printk (" %" PRIu64" MB, " , (d->vnuma->vmemrange[i].end - + d->vnuma->vmemrange[i].start) >>20 ); + +printk ("vcpu nrs: " ); +for (j =0 , n =0 ; j < d->max_vcpus; j++) { +if (d->vnuma->vcpu_to_vnode[j] == i) { +if ( ((n +1 ) %8 ) ==0 ) +printk ("%d\n" , j);
xen/arch/x86/numa.c static void dump_numa(unsigned char key) · line 420
Quoted 10 lines
xen/arch/x86/numa.c +10
-0+else if ( !(n %8 ) && n !=0 ) +printk ("%s%d " ," " , j); +else +printk ("%d " , j); + n++; + } + } +printk ("\n" ); + } + }
There are still a number of indentation issues here (remember that tabs are worth 8 spaces when checking for proper alignment of multi-line statements), and - once that's fixed - a few overly long lines. It might also help to invert the initial condition (following it by "continue;") and thus decrease indentation of the rest of the code by one level. Similarly maybe for the innermost loop.
Jan