WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xm, xend: Make cpus parameter available

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xm, xend: Make cpus parameter available
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Sep 2009 07:40:12 -0700
Delivery-date: Wed, 09 Sep 2009 07:40:26 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1252506810 -3600
# Node ID 71c7c3994b19d5fb38371c25d299f1ac37841430
# Parent  67201ec9ed798037a3c06195a0fe241652694362
xm,xend: Make cpus parameter available

When I started a VM by using xm create command, cpus parameter in VM
configuration files was ignored.  The problem occurred only when I
used XenAPI. This patch makes the parameter available.

Signed-off-by: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendConfig.py     |   56 +++++++++++++++++---------------
 tools/python/xen/xend/XendDomainInfo.py |   14 +++++++-
 tools/python/xen/xm/xenapi_create.py    |   17 +++++++++
 3 files changed, 61 insertions(+), 26 deletions(-)

diff -r 67201ec9ed79 -r 71c7c3994b19 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Wed Sep 09 15:32:30 2009 +0100
+++ b/tools/python/xen/xend/XendConfig.py       Wed Sep 09 15:33:30 2009 +0100
@@ -547,7 +547,28 @@ class XendConfig(dict):
 
         if 'handle' in dominfo:
             self['uuid'] = uuid.toString(dominfo['handle'])
-            
+
+    def _convert_cpus_to_list(self, s):
+        # Convert the following string to list of ints.
+        # The string supports a list of ranges (0-3),
+        # seperated by commas, and negation (^1).  
+        # Precedence is settled by order of the string:
+        #    "0-3,^1"   -> [0,2,3]
+        #    "0-3,^1,1" -> [0,1,2,3]
+        l = []
+        for c in s.split(','):
+            if c.find('-') != -1:
+                (x, y) = c.split('-')
+                for i in range(int(x), int(y)+1):
+                    l.append(int(i))
+            else:
+                # remove this element from the list 
+                if c[0] == '^':
+                    l = [x for x in l if x != int(c[1:])]
+                else:
+                    l.append(int(c))
+        return l
+
     def parse_cpuid(self, cfg, field):
        def int2bin(n, count=32):
            return "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)])
@@ -692,27 +713,6 @@ class XendConfig(dict):
         # Convert 'cpus' to list of list of ints
         cpus_list = []
         if 'cpus' in cfg:
-            # Convert the following string to list of ints.
-            # The string supports a list of ranges (0-3),
-            # seperated by commas, and negation (^1).  
-            # Precedence is settled by order of the string:
-            #    "0-3,^1"      -> [0,2,3]
-            #    "0-3,^1,1"    -> [0,1,2,3]
-            def cnv(s):
-                l = []
-                for c in s.split(','):
-                    if c.find('-') != -1:
-                        (x, y) = c.split('-')
-                        for i in range(int(x), int(y)+1):
-                            l.append(int(i))
-                    else:
-                        # remove this element from the list 
-                        if c[0] == '^':
-                            l = [x for x in l if x != int(c[1:])]
-                        else:
-                            l.append(int(c))
-                return l
-            
             if type(cfg['cpus']) == list:
                 if len(cfg['cpus']) > 0 and type(cfg['cpus'][0]) == list:
                     # If sxp_cfg was created from config.sxp,
@@ -736,7 +736,7 @@ class XendConfig(dict):
                     #    ["0-3,^1","1-4,^2"] -> [[0,2,3],[1,3,4]]
                     try:
                         for c in cfg['cpus']:
-                            cpus = cnv(c)
+                            cpus = self._convert_cpus_to_list(c)
                             cpus_list.append(cpus)
                     except ValueError, e:
                         raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], 
e))
@@ -752,7 +752,7 @@ class XendConfig(dict):
                 #    "1"      -> [[1],[1]]
                 #    "0-3,^1" -> [[0,2,3],[0,2,3]]
                 try:
-                    cpus = cnv(cfg['cpus'])
+                    cpus = self._convert_cpus_to_list(cfg['cpus'])
                     for v in range(0, cfg['vcpus']):
                         cpus_list.append(cpus)
                 except ValueError, e:
@@ -1020,7 +1020,13 @@ class XendConfig(dict):
                 
         self['vcpus_params']['weight'] = \
             int(self['vcpus_params'].get('weight', 256))
-        self['vcpus_params']['cap'] = int(self['vcpus_params'].get('cap', 0))
+        self['vcpus_params']['cap'] = \
+            int(self['vcpus_params'].get('cap', 0))
+
+        for key, val in self['vcpus_params'].items():
+            if key.startswith('cpumap'):
+                self['vcpus_params'][key] = \
+                    ','.join(map(str, self._convert_cpus_to_list(val)))
 
     def cpuid_to_sxp(self, sxpr, field):
         regs_list = []
diff -r 67201ec9ed79 -r 71c7c3994b19 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Wed Sep 09 15:32:30 2009 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py   Wed Sep 09 15:33:30 2009 +0100
@@ -2538,7 +2538,19 @@ class XendDomainInfo:
                         return True
             return False
 
-        if has_cpus():
+        def has_cpumap():
+            if self.info.has_key('vcpus_params'):
+                for k, v in self.info['vcpus_params'].items():
+                    if k.startswith('cpumap'):
+                        return True
+            return False
+
+        if has_cpumap():
+            for v in range(0, self.info['VCPUs_max']):
+                if self.info['vcpus_params'].has_key('cpumap%i' % v):
+                    cpumask = map(int, self.info['vcpus_params']['cpumap%i' % 
v].split(','))
+                    xc.vcpu_setaffinity(self.domid, v, cpumask)
+        elif has_cpus():
             for v in range(0, self.info['VCPUs_max']):
                 if self.info['cpus'][v]:
                     xc.vcpu_setaffinity(self.domid, v, self.info['cpus'][v])
diff -r 67201ec9ed79 -r 71c7c3994b19 tools/python/xen/xm/xenapi_create.py
--- a/tools/python/xen/xm/xenapi_create.py      Wed Sep 09 15:32:30 2009 +0100
+++ b/tools/python/xen/xm/xenapi_create.py      Wed Sep 09 15:33:30 2009 +0100
@@ -1094,6 +1094,23 @@ class sxp2xml:
             = str(get_child_by_name(config, "cpu_cap", 0))
         vcpu_params.append(vcpu_param)
 
+        cpus = get_child_by_name(config, "cpus", [])
+        if type(cpus) == list:
+            vcpu = 0
+            for cpu in cpus:
+                if cpu:
+                    vcpu_param = document.createElement("vcpu_param")
+                    vcpu_param.attributes["key"] = "cpumap%i" % vcpu
+                    vcpu_param.attributes["value"] = str(cpu)
+                    vcpu_params.append(vcpu_param)
+                vcpu = vcpu + 1
+        else:
+            for vcpu in range(0, int(get_child_by_name(config, "vcpus", 1))):
+                vcpu_param = document.createElement("vcpu_param")
+                vcpu_param.attributes["key"] = "cpumap%i" % vcpu
+                vcpu_param.attributes["value"] = str(cpus)
+                vcpu_params.append(vcpu_param)
+
         return vcpu_params
     
     _eths = -1

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xm, xend: Make cpus parameter available, Xen patchbot-unstable <=