direct-io.hg

changeset 5524:4ef3760d61f0

bitkeeper revision 1.1726 (42b7f1bfzMUFLRiUR9wWkzc2mh-Ing)

Add new control messages for vcpu hotplug events. Via the
xm vcpu-hotplug sub-program, vcpus in domains can be enabled/disabled
when CONFIG_HOTPLUG_CPU is enabled in the target domain's kernel.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Jun 21 10:53:51 2005 +0000 (2005-06-21)
parents 4cadd9fa93d5
children f10eeee5e6e8 1bbb7875ee6a
files linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/messages.py tools/python/xen/xm/main.py xen/include/public/io/domain_controller.h
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c	Tue Jun 21 09:59:24 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c	Tue Jun 21 10:53:51 2005 +0000
     1.3 @@ -1303,6 +1303,14 @@ void __devinit smp_prepare_boot_cpu(void
     1.4  }
     1.5  
     1.6  #ifdef CONFIG_HOTPLUG_CPU
     1.7 +#include <asm-xen/ctrl_if.h>
     1.8 +
     1.9 +/* hotplug down/up funtion pointer and target vcpu */
    1.10 +struct vcpu_hotplug_handler_t {
    1.11 +	void (*fn)();
    1.12 +	u32 vcpu;
    1.13 +};
    1.14 +static struct vcpu_hotplug_handler_t vcpu_hotplug_handler;
    1.15  
    1.16  /* must be called with the cpucontrol mutex held */
    1.17  static int __devinit cpu_enable(unsigned int cpu)
    1.18 @@ -1374,6 +1382,78 @@ void __cpu_die(unsigned int cpu)
    1.19  	}
    1.20   	printk(KERN_ERR "CPU %u didn't die...\n", cpu);
    1.21  }
    1.22 +
    1.23 +static int vcpu_hotplug_cpu_process(void *unused)
    1.24 +{
    1.25 +	struct vcpu_hotplug_handler_t *handler = &vcpu_hotplug_handler;
    1.26 +
    1.27 +	if (handler->fn) {
    1.28 +		(*(handler->fn))(handler->vcpu);
    1.29 +		handler->fn = NULL;
    1.30 +	}
    1.31 +	return 0;
    1.32 +}
    1.33 +
    1.34 +static void __vcpu_hotplug_handler(void *unused)
    1.35 +{
    1.36 +	int err;
    1.37 +
    1.38 +	err = kernel_thread(vcpu_hotplug_cpu_process, 
    1.39 +			    NULL, CLONE_FS | CLONE_FILES);
    1.40 +	if (err < 0)
    1.41 +		printk(KERN_ALERT "Error creating hotplug_cpu process!\n");
    1.42 +
    1.43 +}
    1.44 +
    1.45 +static void vcpu_hotplug_event_handler(ctrl_msg_t *msg, unsigned long id)
    1.46 +{
    1.47 +	static DECLARE_WORK(vcpu_hotplug_work, __vcpu_hotplug_handler, NULL);
    1.48 +	vcpu_hotplug_t *req = (vcpu_hotplug_t *)&msg->msg[0];
    1.49 +	struct vcpu_hotplug_handler_t *handler = &vcpu_hotplug_handler;
    1.50 +	ssize_t ret;
    1.51 +
    1.52 +	if (msg->length != sizeof(vcpu_hotplug_t))
    1.53 +		goto parse_error;
    1.54 +
    1.55 +	/* grab target vcpu from msg */
    1.56 +	handler->vcpu = req->vcpu;
    1.57 +
    1.58 +	/* determine which function to call based on msg subtype */
    1.59 +	switch (msg->subtype) {
    1.60 +        case CMSG_VCPU_HOTPLUG_OFF:
    1.61 +		handler->fn = (void *)&cpu_down;
    1.62 +		ret = schedule_work(&vcpu_hotplug_work);
    1.63 +		req->status = (u32) ret;
    1.64 +		break;
    1.65 +        case CMSG_VCPU_HOTPLUG_ON:
    1.66 +		handler->fn = (void *)&cpu_up;
    1.67 +		ret = schedule_work(&vcpu_hotplug_work);
    1.68 +		req->status = (u32) ret;
    1.69 +		break;
    1.70 +        default:
    1.71 +		goto parse_error;
    1.72 +	}
    1.73 +
    1.74 +	ctrl_if_send_response(msg);
    1.75 +	return;
    1.76 + parse_error:
    1.77 +	msg->length = 0;
    1.78 +	ctrl_if_send_response(msg);
    1.79 +}
    1.80 +
    1.81 +static int __init setup_vcpu_hotplug_event(void)
    1.82 +{
    1.83 +	struct vcpu_hotplug_handler_t *handler = &vcpu_hotplug_handler;
    1.84 +
    1.85 +	handler->fn = NULL;
    1.86 +	ctrl_if_register_receiver(CMSG_VCPU_HOTPLUG,
    1.87 +				  vcpu_hotplug_event_handler, 0);
    1.88 +
    1.89 +	return 0;
    1.90 +}
    1.91 +
    1.92 +__initcall(setup_vcpu_hotplug_event);
    1.93 +
    1.94  #else /* ... !CONFIG_HOTPLUG_CPU */
    1.95  int __cpu_disable(void)
    1.96  {
     2.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Tue Jun 21 09:59:24 2005 +0000
     2.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Tue Jun 21 10:53:51 2005 +0000
     2.3 @@ -744,6 +744,14 @@ static PyObject *xu_message_get_payload(
     2.4          C2P(mem_request_t, target, Int, Long);
     2.5          C2P(mem_request_t, status, Int, Long);
     2.6          return dict;
     2.7 +    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF):
     2.8 +        C2P(vcpu_hotplug_t, vcpu, Int, Long);
     2.9 +        C2P(vcpu_hotplug_t, status, Int, Long);
    2.10 +        return dict;
    2.11 +    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON):
    2.12 +        C2P(vcpu_hotplug_t, vcpu, Int, Long);
    2.13 +        C2P(vcpu_hotplug_t, status, Int, Long);
    2.14 +        return dict;
    2.15      }
    2.16  
    2.17      return PyString_FromStringAndSize((char *)xum->msg.msg, xum->msg.length);
    2.18 @@ -909,6 +917,14 @@ static PyObject *xu_message_new(PyObject
    2.19      case TYPE(CMSG_MEM_REQUEST, CMSG_MEM_REQUEST_SET):
    2.20          P2C(mem_request_t, target, u32);
    2.21          break;
    2.22 +    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF):
    2.23 +        P2C(vcpu_hotplug_t, vcpu, u32);
    2.24 +        P2C(vcpu_hotplug_t, status, u32);
    2.25 +        break;
    2.26 +    case TYPE(CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON):
    2.27 +        P2C(vcpu_hotplug_t, vcpu, u32);
    2.28 +        P2C(vcpu_hotplug_t, status, u32);
    2.29 +        break;
    2.30      case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED):
    2.31          P2C(usbif_fe_interface_status_changed_t, status, u32);
    2.32          P2C(usbif_fe_interface_status_changed_t, evtchn, u16);
     3.1 --- a/tools/python/xen/xend/XendClient.py	Tue Jun 21 09:59:24 2005 +0000
     3.2 +++ b/tools/python/xen/xend/XendClient.py	Tue Jun 21 10:53:51 2005 +0000
     3.3 @@ -271,6 +271,12 @@ class Xend:
     3.4                               'target'    : mem_target })
     3.5          return val
     3.6  
     3.7 +    def xend_domain_vcpu_hotplug(self, id, vcpu, state):
     3.8 +        return self.xendPost(self.domainurl(id),
     3.9 +                            {'op'         : 'vcpu_hotplug',
    3.10 +                             'vcpu'       : vcpu,
    3.11 +                             'state'      : state })
    3.12 +
    3.13      def xend_domain_vif_limit(self, id, vif, credit, period):
    3.14          return self.xendPost(self.domainurl(id),
    3.15                              { 'op'      : 'vif_limit_set',
     4.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Jun 21 09:59:24 2005 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Jun 21 10:53:51 2005 +0000
     4.3 @@ -710,6 +710,18 @@ class XendDomain:
     4.4          dominfo = self.domain_lookup(id)
     4.5          return dominfo.mem_target_set(mem)
     4.6  
     4.7 +    def domain_vcpu_hotplug(self, id, vcpu, state):
     4.8 +        """Enable or disable VCPU vcpu in DOM id
     4.9 +
    4.10 +        @param id: domain
    4.11 +        @param vcpu: target VCPU in domain
    4.12 +        @param state: which state VCPU will become
    4.13 +        @return: 0 on success, -1 on error
    4.14 +        """
    4.15 +
    4.16 +        dominfo = self.domain_lookup(id)
    4.17 +        return dominfo.vcpu_hotplug(vcpu, state)
    4.18 +
    4.19      def domain_dumpcore(self, id):
    4.20          """Save a core dump for a crashed domain.
    4.21  
     5.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Jun 21 09:59:24 2005 +0000
     5.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Jun 21 10:53:51 2005 +0000
     5.3 @@ -956,6 +956,18 @@ class XendDomainInfo:
     5.4              msg = messages.packMsg('mem_request_t', { 'target' : target * (1 << 8)} )
     5.5              self.channel.writeRequest(msg)
     5.6  
     5.7 +    def vcpu_hotplug(self, vcpu, state):
     5.8 +        """Disable or enable VCPU in domain.
     5.9 +        """
    5.10 +        log.error("Holly Shit! %d %d\n" % (vcpu, state))
    5.11 +        if self.channel:
    5.12 +            if int(state) == 0:
    5.13 +                msg = messages.packMsg('vcpu_hotplug_off_t', { 'vcpu' : vcpu} )
    5.14 +            else:
    5.15 +                msg = messages.packMsg('vcpu_hotplug_on_t',  { 'vcpu' : vcpu} )
    5.16 +
    5.17 +            self.channel.writeRequest(msg)
    5.18 +
    5.19      def shutdown(self, reason, key=0):
    5.20          msgtype = shutdown_messages.get(reason)
    5.21          if not msgtype:
     6.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Tue Jun 21 09:59:24 2005 +0000
     6.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Tue Jun 21 10:53:51 2005 +0000
     6.3 @@ -180,6 +180,14 @@ class SrvDomain(SrvDir):
     6.4          val = fn(req.args, {'dom': self.dom.id})
     6.5          return val
     6.6  
     6.7 +    def op_vcpu_hotplug(self, op, req):
     6.8 +        fn = FormFn(self.xd.domain_vcpu_hotplug,
     6.9 +                    [['dom', 'int'],
    6.10 +                     ['vcpu', 'int'],
    6.11 +                     ['state', 'int']])
    6.12 +        val = fn(req.args, {'dom': self.dom.id})
    6.13 +        return val
    6.14 +
    6.15      def render_POST(self, req):
    6.16          return self.perform(req)
    6.17          
     7.1 --- a/tools/python/xen/xend/server/messages.py	Tue Jun 21 09:59:24 2005 +0000
     7.2 +++ b/tools/python/xen/xend/server/messages.py	Tue Jun 21 10:53:51 2005 +0000
     7.3 @@ -309,6 +309,24 @@ mem_request_formats = {
     7.4  msg_formats.update(mem_request_formats)
     7.5  
     7.6  #============================================================================
     7.7 +# Domain vcpu hotplug message.
     7.8 +#============================================================================
     7.9 +
    7.10 +CMSG_VCPU_HOTPLUG     = 10
    7.11 +CMSG_VCPU_HOTPLUG_OFF = 0
    7.12 +CMSG_VCPU_HOTPLUG_ON  = 1
    7.13 +
    7.14 +vcpu_hotplug_formats = {
    7.15 +    'vcpu_hotplug_off_t':
    7.16 +    (CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_OFF),
    7.17 +
    7.18 +    'vcpu_hotplug_on_t':
    7.19 +    (CMSG_VCPU_HOTPLUG, CMSG_VCPU_HOTPLUG_ON)
    7.20 +    }
    7.21 +
    7.22 +msg_formats.update(vcpu_hotplug_formats)
    7.23 +
    7.24 +#============================================================================
    7.25  class Msg:
    7.26      pass
    7.27  
     8.1 --- a/tools/python/xen/xm/main.py	Tue Jun 21 09:59:24 2005 +0000
     8.2 +++ b/tools/python/xen/xm/main.py	Tue Jun 21 10:53:51 2005 +0000
     8.3 @@ -410,7 +410,8 @@ class ProgList(Prog):
     8.4          print 'Name              Id  VCPU  CPU  CPUMAP'
     8.5          for dom in doms:
     8.6              info = server.xend_domain(dom)
     8.7 -            vcpu_to_cpu = sxp.child_value(info, 'vcpu_to_cpu', '?').replace('-','')
     8.8 +            # XXX this is quite broken for cpu's > 9
     8.9 +            vcpu_to_cpu = sxp.child_value(info, 'vcpu_to_cpu', '?').replace('-1','#')
    8.10              cpumap = sxp.child_value(info, 'cpumap', [])
    8.11              mask = ((int(sxp.child_value(info, 'vcpus', '0')))**2) - 1
    8.12              count = 0
    8.13 @@ -419,7 +420,10 @@ class ProgList(Prog):
    8.14                  d['name']   = sxp.child_value(info, 'name', '??')
    8.15                  d['dom']    = int(sxp.child_value(info, 'id', '-1'))
    8.16                  d['vcpu']   = int(count)
    8.17 -                d['cpu']    = int(cpu)
    8.18 +                if cpu == "#":
    8.19 +                    d['cpu']    = int("-1")
    8.20 +                else:
    8.21 +                    d['cpu']    = int(cpu)
    8.22                  d['cpumap'] = int(cpumap[count])&mask
    8.23                  count = count + 1
    8.24                  print ("%(name)-16s %(dom)3d  %(vcpu)4d  %(cpu)3d  0x%(cpumap)x" % d)
    8.25 @@ -572,6 +576,35 @@ MEMORY_TARGET megabytes"""
    8.26  
    8.27  xm.prog(ProgBalloon)
    8.28  
    8.29 +class ProgVcpuhotplug(Prog):
    8.30 +    group = 'domain'
    8.31 +    name  = 'vcpu-hotplug'
    8.32 +    info  = """Enable or disable a VCPU in a domain."""
    8.33 +
    8.34 +    def help(self, args):
    8.35 +        print args[0], "DOM VCPU [0|1]"
    8.36 +        print """\nRequest virtual processor VCPU to be disabled or enabled in
    8.37 +domain DOM"""
    8.38 +
    8.39 +    def main(self, args):
    8.40 +        if len(args) != 4: self.err("%s: Invalid arguments(s)" % args[0])
    8.41 +        name = args[1]
    8.42 +        vcpu = int(args[2])
    8.43 +        state = int(args[3])
    8.44 +        dom = server.xend_domain(name)
    8.45 +        id = sxp.child_value(dom, 'id')
    8.46 +        vcpu_to_cpu = sxp.child_value(dom, 'vcpu_to_cpu', '-1')
    8.47 +        # only send state change if states differ 
    8.48 +        try:
    8.49 +            # (down going up) or (up going down)
    8.50 +            if (vcpu_to_cpu[vcpu] == "-1" and state == 1) or \
    8.51 +               (vcpu_to_cpu[vcpu] != "-1" and state == 0):
    8.52 +                server.xend_domain_vcpu_hotplug(id, vcpu, state)
    8.53 +        except IndexError:
    8.54 +            print "Invalid VCPU(%d)"%(vcpu)
    8.55 +
    8.56 +xm.prog(ProgVcpuhotplug)
    8.57 +
    8.58  class ProgDomid(Prog):
    8.59      group = 'domain'
    8.60      name = 'domid'
     9.1 --- a/xen/include/public/io/domain_controller.h	Tue Jun 21 09:59:24 2005 +0000
     9.2 +++ b/xen/include/public/io/domain_controller.h	Tue Jun 21 10:53:51 2005 +0000
     9.3 @@ -61,6 +61,7 @@ typedef struct {
     9.4  #define CMSG_MEM_REQUEST    7  /* Memory reservation reqs */
     9.5  #define CMSG_USBIF_BE       8  /* USB controller backend  */
     9.6  #define CMSG_USBIF_FE       9  /* USB controller frontend */
     9.7 +#define CMSG_VCPU_HOTPLUG  10  /* Hotplug VCPU messages   */
     9.8  
     9.9  /******************************************************************************
    9.10   * CONSOLE DEFINITIONS
    9.11 @@ -758,6 +759,25 @@ typedef struct {
    9.12  } PACKED shutdown_sysrq_t; /* 4 bytes */
    9.13  
    9.14  /******************************************************************************
    9.15 + * VCPU HOTPLUG CONTROLS
    9.16 + */
    9.17 +
    9.18 +/*
    9.19 + * Subtypes for shutdown messages.
    9.20 + */
    9.21 +#define CMSG_VCPU_HOTPLUG_OFF   0   /* turn vcpu off */
    9.22 +#define CMSG_VCPU_HOTPLUG_ON    1   /* turn vcpu on  */
    9.23 +
    9.24 +/*
    9.25 + * CMSG_VCPU_HOTPLUG:
    9.26 + *  Indicate which vcpu's state should change
    9.27 + */
    9.28 +typedef struct {
    9.29 +    u32 vcpu;         /* 0: VCPU's whose state will change */
    9.30 +    u32 status;       /* 4: Return code indicates success or failure. */
    9.31 +} PACKED vcpu_hotplug_t;
    9.32 +
    9.33 +/******************************************************************************
    9.34   * MEMORY CONTROLS
    9.35   */
    9.36