ia64/xen-unstable

changeset 17155:5f7bfdeb8748

NUMA node migration

Adds NUMA node migration based on live migration to
xend. By adding another parameter to "xm migrate" the target NUMA node
number gets propagated to the target host (can be both localhost or a
remote host). The restore function then sets the VCPU affinity
accordingly. Only changes Python code in xend. I hope that the patch
doesn't break XenAPI compatibility (adding a parameter seems fine?).

# xm migrate --live --node=<nodenr> <domid> localhost
<nodenr> is the number as shown with 'xm info' under node_to_cpu

I am aware that using live migration isn't the best approach (takes
twice the memory and quite some time), but it's less intrusive and
works fine (given localhost migration stability...)

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 28 13:44:28 2008 +0000 (2008-02-28)
parents 15c3c136206d
children bf63d055d30c
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendDomain.py tools/python/xen/xm/migrate.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Feb 28 13:40:30 2008 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Feb 28 13:44:28 2008 +0000
     1.3 @@ -1761,9 +1761,10 @@ class XendAPI(object):
     1.4  
     1.5          resource = other_config.get("resource", 0)
     1.6          port = other_config.get("port", 0)
     1.7 +        node = other_config.get("node", 0)
     1.8          
     1.9          xendom.domain_migrate(xeninfo.getDomid(), destination_url,
    1.10 -                              bool(live), resource, port)
    1.11 +                              bool(live), resource, port, node)
    1.12          return xen_api_success_void()
    1.13  
    1.14      def VM_save(self, _, vm_ref, dest, checkpoint):
     2.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Thu Feb 28 13:40:30 2008 +0000
     2.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Thu Feb 28 13:44:28 2008 +0000
     2.3 @@ -22,6 +22,7 @@ from xen.xend.XendError import XendError
     2.4  from xen.xend.XendLogging import log
     2.5  from xen.xend.XendConfig import XendConfig
     2.6  from xen.xend.XendConstants import *
     2.7 +from xen.xend import XendNode
     2.8  
     2.9  SIGNATURE = "LinuxGuestRecord"
    2.10  QEMU_SIGNATURE = "QemuDeviceModelRecord"
    2.11 @@ -56,10 +57,23 @@ def read_exact(fd, size, errmsg):
    2.12      return buf
    2.13  
    2.14  
    2.15 -def save(fd, dominfo, network, live, dst, checkpoint=False):
    2.16 +def insert_after(list, pred, value):
    2.17 +    for i,k in enumerate(list):
    2.18 +        if type(k) == type([]):
    2.19 +           if k[0] == pred:
    2.20 +              list.insert (i+1, value)
    2.21 +    return
    2.22 +
    2.23 +
    2.24 +def save(fd, dominfo, network, live, dst, checkpoint=False, node=-1):
    2.25      write_exact(fd, SIGNATURE, "could not write guest state file: signature")
    2.26  
    2.27 -    config = sxp.to_string(dominfo.sxpr())
    2.28 +    sxprep = dominfo.sxpr()
    2.29 +
    2.30 +    if node > -1:
    2.31 +        insert_after(sxprep,'vcpus',['node', str(node)])
    2.32 +
    2.33 +    config = sxp.to_string(sxprep)
    2.34  
    2.35      domain_name = dominfo.getName()
    2.36      # Rename the domain temporarily, so that we don't get a name clash if this
    2.37 @@ -192,6 +206,21 @@ def restore(xd, fd, dominfo = None, paus
    2.38      else:
    2.39          dominfo = xd.restore_(vmconfig)
    2.40  
    2.41 +    # repin domain vcpus if a target node number was specified 
    2.42 +    # this is done prior to memory allocation to aide in memory
    2.43 +    # distribution for NUMA systems.
    2.44 +    nodenr = -1
    2.45 +    for i,l in enumerate(vmconfig):
    2.46 +        if type(l) == type([]):
    2.47 +            if l[0] == 'node':
    2.48 +                nodenr = int(l[1])
    2.49 +
    2.50 +    if nodenr >= 0:
    2.51 +        node_to_cpu = XendNode.instance().xc.physinfo()['node_to_cpu']
    2.52 +        if nodenr < len(node_to_cpu):
    2.53 +            for v in range(0, dominfo.info['VCPUs_max']):
    2.54 +                 xc.vcpu_setaffinity(dominfo.domid, v, node_to_cpu[nodenr])
    2.55 +
    2.56      store_port   = dominfo.getStorePort()
    2.57      console_port = dominfo.getConsolePort()
    2.58  
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Thu Feb 28 13:40:30 2008 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Feb 28 13:44:28 2008 +0000
     3.3 @@ -1258,7 +1258,7 @@ class XendDomain:
     3.4  
     3.5          return val       
     3.6  
     3.7 -    def domain_migrate(self, domid, dst, live=False, resource=0, port=0):
     3.8 +    def domain_migrate(self, domid, dst, live=False, resource=0, port=0, node=-1):
     3.9          """Start domain migration.
    3.10          
    3.11          @param domid: Domain ID or Name
    3.12 @@ -1271,6 +1271,8 @@ class XendDomain:
    3.13          @type live: bool
    3.14          @keyword resource: not used??
    3.15          @rtype: None
    3.16 +        @keyword node: use node number for target
    3.17 +        @rtype: int 
    3.18          @raise XendError: Failed to migrate
    3.19          @raise XendInvalidDomain: Domain is not valid        
    3.20          """
    3.21 @@ -1299,7 +1301,7 @@ class XendDomain:
    3.22  
    3.23          sock.send("receive\n")
    3.24          sock.recv(80)
    3.25 -        XendCheckpoint.save(sock.fileno(), dominfo, True, live, dst)
    3.26 +        XendCheckpoint.save(sock.fileno(), dominfo, True, live, dst, node=node)
    3.27          sock.close()
    3.28  
    3.29      def domain_save(self, domid, dst, checkpoint=False):
     4.1 --- a/tools/python/xen/xm/migrate.py	Thu Feb 28 13:40:30 2008 +0000
     4.2 +++ b/tools/python/xen/xm/migrate.py	Thu Feb 28 13:44:28 2008 +0000
     4.3 @@ -43,6 +43,10 @@ gopts.opt('port', short='p', val='portnu
     4.4            fn=set_int, default=0,
     4.5            use="Use specified port for migration.")
     4.6  
     4.7 +gopts.opt('node', short='n', val='nodenum',
     4.8 +          fn=set_int, default=-1,
     4.9 +          use="Use specified NUMA node on target.")
    4.10 +
    4.11  gopts.opt('resource', short='r', val='MBIT',
    4.12            fn=set_int, default=0,
    4.13            use="Set level of resource usage for migration.")
    4.14 @@ -65,11 +69,13 @@ def main(argv):
    4.15          vm_ref = get_single_vm(dom)
    4.16          other_config = {
    4.17              "port":     opts.vals.port,
    4.18 -            "resource": opts.vals.resource
    4.19 +            "resource": opts.vals.resource,
    4.20 +            "node":     opts.vals.node
    4.21              }
    4.22          server.xenapi.VM.migrate(vm_ref, dst, bool(opts.vals.live),
    4.23                                   other_config)
    4.24      else:
    4.25          server.xend.domain.migrate(dom, dst, opts.vals.live,
    4.26                                     opts.vals.resource,
    4.27 -                                   opts.vals.port)
    4.28 +                                   opts.vals.port,
    4.29 +                                   opts.vals.node)