xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <juergen.gross@ts.fujitsu.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [Patch] use full-size cpumask for vcpu-pin
Date: Mon, 02 Aug 2010 08:40:04 +0200	[thread overview]
Message-ID: <4C566844.2070408@ts.fujitsu.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]

Hi,

attached patch solves a problem with vcpu-pinning and hot-plug of cpus:

If a vcpu is unpinned via

xl vcpu-pin <domain> <vcpu> 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 <domain> <vcpu> 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

[-- Attachment #2: cpumask.patch --]
[-- Type: text/x-patch, Size: 4701 bytes --]

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;

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2010-08-02  6:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-02  6:40 Juergen Gross [this message]
2010-08-10 14:11 ` [Patch] use full-size cpumask for vcpu-pin Ian Jackson
2010-08-10 14:27   ` Keir Fraser
2010-08-11  4:32   ` Juergen Gross
2010-08-13 12:31 ` Ian Jackson
2010-08-13 12:58   ` Keir Fraser
2010-08-13 13:11     ` Ian Jackson
2010-08-13 13:15       ` Keir Fraser
2010-08-13 13:21         ` Keir Fraser
2010-08-13 13:25           ` Keir Fraser
2010-08-13 13:29             ` Ian Jackson
2010-08-13 13:30             ` Keir Fraser
2010-08-13 14:09               ` Keir Fraser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C566844.2070408@ts.fujitsu.com \
    --to=juergen.gross@ts.fujitsu.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).