From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juergen Gross Subject: [Patch] use full-size cpumask for vcpu-pin Date: Mon, 02 Aug 2010 08:40:04 +0200 Message-ID: <4C566844.2070408@ts.fujitsu.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040903030809080903060005" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------040903030809080903060005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, attached patch solves a problem with vcpu-pinning and hot-plug of cpus: If a vcpu is unpinned via xl vcpu-pin all on a system with 64 cpus and later other cpus are plugged in, this vcpu will be restricted to the first 64 cpus of the system. The reason is the allocation of the cpumap for pinning: the size is only for the ACTUAL number of physical cpus in the system, not the possible number. The solution is to allocate a cpumap for up to NR_CPUS. Repairing xm vcpu-pin is much harder and not covered by this patch, but the problem can be avoided by calling xm vcpu-pin 0-255 instead (all is hard-wired to 0-63 now). Juergen -- Juergen Gross Principal Developer Operating Systems TSP ES&S SWE OS6 Telephone: +49 (0) 89 3222 2967 Fujitsu Technology Solutions e-mail: juergen.gross@ts.fujitsu.com Domagkstr. 28 Internet: ts.fujitsu.com D-80807 Muenchen Company details: ts.fujitsu.com/imprint.html --------------040903030809080903060005 Content-Type: text/x-patch; name="cpumask.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cpumask.patch" Signed-off-by: juergen.gross@ts.fujitsu.com diff -r 3263d0ff9476 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Jul 29 16:53:40 2010 +0100 +++ b/tools/libxl/libxl.c Mon Aug 02 08:27:03 2010 +0200 @@ -2479,6 +2479,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, l physinfo->max_cpu_id = xcphysinfo.max_cpu_id; physinfo->nr_cpus = xcphysinfo.nr_cpus; physinfo->cpu_khz = xcphysinfo.cpu_khz; + physinfo->max_phys_cpus = xcphysinfo.max_phys_cpus; physinfo->total_pages = xcphysinfo.total_pages; physinfo->free_pages = xcphysinfo.free_pages; physinfo->scrub_pages = xcphysinfo.scrub_pages; @@ -2550,7 +2551,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "getting physinfo"); return NULL; } - *cpusize = physinfo.max_cpu_id + 1; + *cpusize = physinfo.max_phys_cpus + 1; ptr = libxl_calloc(ctx, domaininfo.max_vcpu_id + 1, sizeof (libxl_vcpuinfo)); if (!ptr) { return NULL; diff -r 3263d0ff9476 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Jul 29 16:53:40 2010 +0100 +++ b/tools/libxl/libxl.h Mon Aug 02 08:27:03 2010 +0200 @@ -581,6 +581,7 @@ typedef struct { uint32_t max_cpu_id; uint32_t nr_cpus; uint32_t cpu_khz; + uint32_t max_phys_cpus; uint64_t total_pages; uint64_t free_pages; diff -r 3263d0ff9476 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Jul 29 16:53:40 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Mon Aug 02 08:27:03 2010 +0200 @@ -3297,7 +3297,7 @@ void vcpupin(char *d, const char *vcpu, goto vcpupin_out1; } - cpumap = calloc(physinfo.max_cpu_id + 1, sizeof (uint64_t)); + cpumap = calloc(physinfo.max_phys_cpus + 1, sizeof (uint64_t)); if (!cpumap) { goto vcpupin_out1; } @@ -3325,12 +3325,12 @@ void vcpupin(char *d, const char *vcpu, } } else { - memset(cpumap, -1, sizeof (uint64_t) * (physinfo.max_cpu_id + 1)); + memset(cpumap, -1, sizeof (uint64_t) * (physinfo.max_phys_cpus + 1)); } if (vcpuid != -1) { if (libxl_set_vcpuaffinity(&ctx, domid, vcpuid, - cpumap, physinfo.max_cpu_id + 1) == -1) { + cpumap, physinfo.max_phys_cpus + 1) == -1) { fprintf(stderr, "Could not set affinity for vcpu `%u'.\n", vcpuid); } } @@ -3341,7 +3341,7 @@ void vcpupin(char *d, const char *vcpu, } for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) { if (libxl_set_vcpuaffinity(&ctx, domid, vcpuinfo->vcpuid, - cpumap, physinfo.max_cpu_id + 1) == -1) { + cpumap, physinfo.max_phys_cpus + 1) == -1) { fprintf(stderr, "libxl_list_vcpu failed on vcpu `%u'.\n", vcpuinfo->vcpuid); } } diff -r 3263d0ff9476 tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Thu Jul 29 16:53:40 2010 +0100 +++ b/tools/python/xen/lowlevel/xc/xc.c Mon Aug 02 08:27:03 2010 +0200 @@ -241,7 +241,7 @@ static PyObject *pyxc_vcpu_setaffinity(X if ( xc_physinfo(self->xc_handle, &info) != 0 ) return pyxc_error_to_exception(self->xc_handle); - nr_cpus = info.nr_cpus; + nr_cpus = info.max_phys_cpus; size = (nr_cpus + cpumap_size * 8 - 1)/ (cpumap_size * 8); cpumap = malloc(cpumap_size * size); @@ -400,7 +400,7 @@ static PyObject *pyxc_vcpu_getinfo(XcObj if ( xc_physinfo(self->xc_handle, &pinfo) != 0 ) return pyxc_error_to_exception(self->xc_handle); - nr_cpus = pinfo.nr_cpus; + nr_cpus = pinfo.max_phys_cpus; rc = xc_vcpu_getinfo(self->xc_handle, dom, vcpu, &info); if ( rc < 0 ) diff -r 3263d0ff9476 xen/arch/x86/sysctl.c --- a/xen/arch/x86/sysctl.c Thu Jul 29 16:53:40 2010 +0100 +++ b/xen/arch/x86/sysctl.c Mon Aug 02 08:27:03 2010 +0200 @@ -68,6 +68,7 @@ long arch_do_sysctl( pi->free_pages = avail_domheap_pages(); pi->scrub_pages = 0; pi->cpu_khz = cpu_khz; + pi->max_phys_cpus = NR_CPUS; memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4); if ( hvm_enabled ) pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm; diff -r 3263d0ff9476 xen/include/public/sysctl.h --- a/xen/include/public/sysctl.h Thu Jul 29 16:53:40 2010 +0100 +++ b/xen/include/public/sysctl.h Mon Aug 02 08:27:03 2010 +0200 @@ -96,6 +96,7 @@ struct xen_sysctl_physinfo { uint32_t nr_cpus, max_cpu_id; uint32_t nr_nodes, max_node_id; uint32_t cpu_khz; + uint32_t max_phys_cpus; uint64_aligned_t total_pages; uint64_aligned_t free_pages; uint64_aligned_t scrub_pages; --------------040903030809080903060005 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------040903030809080903060005--