debuggers.hg

changeset 21218:3cdd4cf2c20e

credit2: Add toolstack options to control credit2 scheduler parameters

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 14 12:10:19 2010 +0100 (2010-04-14)
parents 9b91a253528b
children ecdc14634425
files tools/libxc/Makefile tools/libxc/xc_csched2.c tools/libxc/xenctrl.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendVMMetrics.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/libxc/Makefile	Wed Apr 14 12:07:21 2010 +0100
     1.2 +++ b/tools/libxc/Makefile	Wed Apr 14 12:10:19 2010 +0100
     1.3 @@ -17,6 +17,7 @@ CTRL_SRCS-y       += xc_physdev.c
     1.4  CTRL_SRCS-y       += xc_private.c
     1.5  CTRL_SRCS-y       += xc_sedf.c
     1.6  CTRL_SRCS-y       += xc_csched.c
     1.7 +CTRL_SRCS-y       += xc_csched2.c
     1.8  CTRL_SRCS-y       += xc_tbuf.c
     1.9  CTRL_SRCS-y       += xc_pm.c
    1.10  CTRL_SRCS-y       += xc_cpu_hotplug.c
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/libxc/xc_csched2.c	Wed Apr 14 12:10:19 2010 +0100
     2.3 @@ -0,0 +1,50 @@
     2.4 +/****************************************************************************
     2.5 + * (C) 2006 - Emmanuel Ackaouy - XenSource Inc.
     2.6 + ****************************************************************************
     2.7 + *
     2.8 + *        File: xc_csched.c
     2.9 + *      Author: Emmanuel Ackaouy
    2.10 + *
    2.11 + * Description: XC Interface to the credit scheduler
    2.12 + *
    2.13 + */
    2.14 +#include "xc_private.h"
    2.15 +
    2.16 +
    2.17 +int
    2.18 +xc_sched_credit2_domain_set(
    2.19 +    int xc_handle,
    2.20 +    uint32_t domid,
    2.21 +    struct xen_domctl_sched_credit2 *sdom)
    2.22 +{
    2.23 +    DECLARE_DOMCTL;
    2.24 +
    2.25 +    domctl.cmd = XEN_DOMCTL_scheduler_op;
    2.26 +    domctl.domain = (domid_t) domid;
    2.27 +    domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT2;
    2.28 +    domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
    2.29 +    domctl.u.scheduler_op.u.credit2 = *sdom;
    2.30 +
    2.31 +    return do_domctl(xc_handle, &domctl);
    2.32 +}
    2.33 +
    2.34 +int
    2.35 +xc_sched_credit2_domain_get(
    2.36 +    int xc_handle,
    2.37 +    uint32_t domid,
    2.38 +    struct xen_domctl_sched_credit2 *sdom)
    2.39 +{
    2.40 +    DECLARE_DOMCTL;
    2.41 +    int err;
    2.42 +
    2.43 +    domctl.cmd = XEN_DOMCTL_scheduler_op;
    2.44 +    domctl.domain = (domid_t) domid;
    2.45 +    domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT2;
    2.46 +    domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
    2.47 +
    2.48 +    err = do_domctl(xc_handle, &domctl);
    2.49 +    if ( err == 0 )
    2.50 +        *sdom = domctl.u.scheduler_op.u.credit2;
    2.51 +
    2.52 +    return err;
    2.53 +}
     3.1 --- a/tools/libxc/xenctrl.h	Wed Apr 14 12:07:21 2010 +0100
     3.2 +++ b/tools/libxc/xenctrl.h	Wed Apr 14 12:10:19 2010 +0100
     3.3 @@ -475,6 +475,14 @@ int xc_sched_credit_domain_get(int xc_ha
     3.4                                 uint32_t domid,
     3.5                                 struct xen_domctl_sched_credit *sdom);
     3.6  
     3.7 +int xc_sched_credit2_domain_set(int xc_handle,
     3.8 +                               uint32_t domid,
     3.9 +                               struct xen_domctl_sched_credit2 *sdom);
    3.10 +
    3.11 +int xc_sched_credit2_domain_get(int xc_handle,
    3.12 +                               uint32_t domid,
    3.13 +                               struct xen_domctl_sched_credit2 *sdom);
    3.14 +
    3.15  /**
    3.16   * This function sends a trigger to a domain.
    3.17   *
     4.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed Apr 14 12:07:21 2010 +0100
     4.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Wed Apr 14 12:10:19 2010 +0100
     4.3 @@ -1558,6 +1558,45 @@ static PyObject *pyxc_sched_credit_domai
     4.4                           "cap",     sdom.cap);
     4.5  }
     4.6  
     4.7 +static PyObject *pyxc_sched_credit2_domain_set(XcObject *self,
     4.8 +                                              PyObject *args,
     4.9 +                                              PyObject *kwds)
    4.10 +{
    4.11 +    uint32_t domid;
    4.12 +    uint16_t weight;
    4.13 +    static char *kwd_list[] = { "domid", "weight", NULL };
    4.14 +    static char kwd_type[] = "I|H";
    4.15 +    struct xen_domctl_sched_credit2 sdom;
    4.16 +
    4.17 +    weight = 0;
    4.18 +    if( !PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list,
    4.19 +                                     &domid, &weight) )
    4.20 +        return NULL;
    4.21 +
    4.22 +    sdom.weight = weight;
    4.23 +
    4.24 +    if ( xc_sched_credit2_domain_set(self->xc_handle, domid, &sdom) != 0 )
    4.25 +        return pyxc_error_to_exception();
    4.26 +
    4.27 +    Py_INCREF(zero);
    4.28 +    return zero;
    4.29 +}
    4.30 +
    4.31 +static PyObject *pyxc_sched_credit2_domain_get(XcObject *self, PyObject *args)
    4.32 +{
    4.33 +    uint32_t domid;
    4.34 +    struct xen_domctl_sched_credit2 sdom;
    4.35 +
    4.36 +    if( !PyArg_ParseTuple(args, "I", &domid) )
    4.37 +        return NULL;
    4.38 +
    4.39 +    if ( xc_sched_credit2_domain_get(self->xc_handle, domid, &sdom) != 0 )
    4.40 +        return pyxc_error_to_exception();
    4.41 +
    4.42 +    return Py_BuildValue("{s:H}",
    4.43 +                         "weight",  sdom.weight);
    4.44 +}
    4.45 +
    4.46  static PyObject *pyxc_domain_setmaxmem(XcObject *self, PyObject *args)
    4.47  {
    4.48      uint32_t dom;
    4.49 @@ -2113,6 +2152,24 @@ static PyMethodDef pyxc_methods[] = {
    4.50        "Returns:   [dict]\n"
    4.51        " weight    [short]: domain's scheduling weight\n"},
    4.52  
    4.53 +    { "sched_credit2_domain_set",
    4.54 +      (PyCFunction)pyxc_sched_credit2_domain_set,
    4.55 +      METH_KEYWORDS, "\n"
    4.56 +      "Set the scheduling parameters for a domain when running with the\n"
    4.57 +      "SMP credit2 scheduler.\n"
    4.58 +      " domid     [int]:   domain id to set\n"
    4.59 +      " weight    [short]: domain's scheduling weight\n"
    4.60 +      "Returns: [int] 0 on success; -1 on error.\n" },
    4.61 +
    4.62 +    { "sched_credit2_domain_get",
    4.63 +      (PyCFunction)pyxc_sched_credit2_domain_get,
    4.64 +      METH_VARARGS, "\n"
    4.65 +      "Get the scheduling parameters for a domain when running with the\n"
    4.66 +      "SMP credit2 scheduler.\n"
    4.67 +      " domid     [int]:   domain id to get\n"
    4.68 +      "Returns:   [dict]\n"
    4.69 +      " weight    [short]: domain's scheduling weight\n"},
    4.70 +
    4.71      { "evtchn_alloc_unbound", 
    4.72        (PyCFunction)pyxc_evtchn_alloc_unbound,
    4.73        METH_VARARGS | METH_KEYWORDS, "\n"
    4.74 @@ -2495,6 +2552,7 @@ PyMODINIT_FUNC initxc(void)
    4.75      /* Expose some libxc constants to Python */
    4.76      PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF);
    4.77      PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
    4.78 +    PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT2", XEN_SCHEDULER_CREDIT2);
    4.79  
    4.80  }
    4.81  
     5.1 --- a/tools/python/xen/xend/XendAPI.py	Wed Apr 14 12:07:21 2010 +0100
     5.2 +++ b/tools/python/xen/xend/XendAPI.py	Wed Apr 14 12:10:19 2010 +0100
     5.3 @@ -1626,8 +1626,7 @@ class XendAPI(object):
     5.4          if 'weight' in xeninfo.info['vcpus_params'] \
     5.5             and 'cap' in xeninfo.info['vcpus_params']:
     5.6              weight = xeninfo.info['vcpus_params']['weight']
     5.7 -            cap = xeninfo.info['vcpus_params']['cap']
     5.8 -            xendom.domain_sched_credit_set(xeninfo.getDomid(), weight, cap)
     5.9 +            xendom.domain_sched_credit2_set(xeninfo.getDomid(), weight)
    5.10  
    5.11      def VM_set_VCPUs_number_live(self, _, vm_ref, num):
    5.12          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
     6.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Apr 14 12:07:21 2010 +0100
     6.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Apr 14 12:10:19 2010 +0100
     6.3 @@ -1757,6 +1757,60 @@ class XendDomain:
     6.4              log.exception(ex)
     6.5              raise XendError(str(ex))
     6.6  
     6.7 +    def domain_sched_credit2_get(self, domid):
     6.8 +        """Get credit2 scheduler parameters for a domain.
     6.9 +
    6.10 +        @param domid: Domain ID or Name
    6.11 +        @type domid: int or string.
    6.12 +        @rtype: dict with keys 'weight'
    6.13 +        @return: credit2 scheduler parameters
    6.14 +        """
    6.15 +        dominfo = self.domain_lookup_nr(domid)
    6.16 +        if not dominfo:
    6.17 +            raise XendInvalidDomain(str(domid))
    6.18 +
    6.19 +        if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
    6.20 +            try:
    6.21 +                return xc.sched_credit2_domain_get(dominfo.getDomid())
    6.22 +            except Exception, ex:
    6.23 +                raise XendError(str(ex))
    6.24 +        else:
    6.25 +            return {'weight' : dominfo.getWeight()}
    6.26 +
    6.27 +    def domain_sched_credit2_set(self, domid, weight = None):
    6.28 +        """Set credit2 scheduler parameters for a domain.
    6.29 +
    6.30 +        @param domid: Domain ID or Name
    6.31 +        @type domid: int or string.
    6.32 +        @type weight: int
    6.33 +        @rtype: 0
    6.34 +        """
    6.35 +        set_weight = False
    6.36 +        dominfo = self.domain_lookup_nr(domid)
    6.37 +        if not dominfo:
    6.38 +            raise XendInvalidDomain(str(domid))
    6.39 +        try:
    6.40 +            if weight is None:
    6.41 +                weight = int(0)
    6.42 +            elif weight < 1 or weight > 65535:
    6.43 +                raise XendError("weight is out of range")
    6.44 +            else:
    6.45 +                set_weight = True
    6.46 +
    6.47 +            assert type(weight) == int
    6.48 +
    6.49 +            rc = 0
    6.50 +            if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
    6.51 +                rc = xc.sched_credit2_domain_set(dominfo.getDomid(), weight)
    6.52 +            if rc == 0:
    6.53 +                if set_weight:
    6.54 +                    dominfo.setWeight(weight)
    6.55 +                self.managed_config_save(dominfo)
    6.56 +            return rc
    6.57 +        except Exception, ex:
    6.58 +            log.exception(ex)
    6.59 +            raise XendError(str(ex))
    6.60 +
    6.61      def domain_maxmem_set(self, domid, mem):
    6.62          """Set the memory limit for a domain.
    6.63  
     7.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Apr 14 12:07:21 2010 +0100
     7.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Apr 14 12:10:19 2010 +0100
     7.3 @@ -2811,6 +2811,10 @@ class XendDomainInfo:
     7.4              XendDomain.instance().domain_sched_credit_set(self.getDomid(),
     7.5                                                            self.getWeight(),
     7.6                                                            self.getCap())
     7.7 +        elif XendNode.instance().xenschedinfo() == 'credit2':
     7.8 +            from xen.xend import XendDomain
     7.9 +            XendDomain.instance().domain_sched_credit2_set(self.getDomid(),
    7.10 +                                                           self.getWeight())
    7.11  
    7.12      def _initDomain(self):
    7.13          log.debug('XendDomainInfo.initDomain: %s %s',
     8.1 --- a/tools/python/xen/xend/XendNode.py	Wed Apr 14 12:07:21 2010 +0100
     8.2 +++ b/tools/python/xen/xend/XendNode.py	Wed Apr 14 12:10:19 2010 +0100
     8.3 @@ -779,6 +779,8 @@ class XendNode:
     8.4              return 'sedf'
     8.5          elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
     8.6              return 'credit'
     8.7 +        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT2:
     8.8 +            return 'credit2'
     8.9          else:
    8.10              return 'unknown'
    8.11  
    8.12 @@ -988,6 +990,8 @@ class XendNode:
    8.13              return 'sedf'
    8.14          elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
    8.15              return 'credit'
    8.16 +        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT2:
    8.17 +            return 'credit2'
    8.18          else:
    8.19              return 'unknown'
    8.20  
     9.1 --- a/tools/python/xen/xend/XendVMMetrics.py	Wed Apr 14 12:07:21 2010 +0100
     9.2 +++ b/tools/python/xen/xend/XendVMMetrics.py	Wed Apr 14 12:10:19 2010 +0100
     9.3 @@ -129,6 +129,7 @@ class XendVMMetrics(XendBase):
     9.4                  params_live['cpumap%i' % i] = \
     9.5                      ",".join(map(str, info['cpumap']))
     9.6  
     9.7 +                # FIXME: credit2??
     9.8              params_live.update(xc.sched_credit_domain_get(domid))
     9.9              
    9.10              return params_live
    10.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Wed Apr 14 12:07:21 2010 +0100
    10.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Wed Apr 14 12:10:19 2010 +0100
    10.3 @@ -163,6 +163,20 @@ class SrvDomain(SrvDir):
    10.4          val = fn(req.args, {'dom': self.dom.getName()})
    10.5          return val
    10.6  
    10.7 +    def op_domain_sched_credit2_get(self, _, req):
    10.8 +        fn = FormFn(self.xd.domain_sched_credit2_get,
    10.9 +                    [['dom', 'str']])
   10.10 +        val = fn(req.args, {'dom': self.dom.getName()})
   10.11 +        return val
   10.12 +
   10.13 +
   10.14 +    def op_domain_sched_credit2_set(self, _, req):
   10.15 +        fn = FormFn(self.xd.domain_sched_credit2_set,
   10.16 +                    [['dom', 'str'],
   10.17 +                     ['weight', 'int']])
   10.18 +        val = fn(req.args, {'dom': self.dom.getName()})
   10.19 +        return val
   10.20 +
   10.21      def op_maxmem_set(self, _, req):
   10.22          return self.call(self.dom.setMemoryMaximum,
   10.23                           [['memory', 'int']],
    11.1 --- a/tools/python/xen/xm/main.py	Wed Apr 14 12:07:21 2010 +0100
    11.2 +++ b/tools/python/xen/xm/main.py	Wed Apr 14 12:10:19 2010 +0100
    11.3 @@ -151,6 +151,8 @@ SUBCOMMAND_HELP = {
    11.4      'sched-sedf'  : ('<Domain> [options]', 'Get/set EDF parameters.'),
    11.5      'sched-credit': ('[-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]',
    11.6                       'Get/set credit scheduler parameters.'),
    11.7 +    'sched-credit2': ('[-d <Domain> [-w[=WEIGHT]]',
    11.8 +                     'Get/set credit2 scheduler parameters.'),
    11.9      'sysrq'       : ('<Domain> <letter>', 'Send a sysrq to a domain.'),
   11.10      'debug-keys'  : ('<Keys>', 'Send debug keys to Xen.'),
   11.11      'trigger'     : ('<Domain> <nmi|reset|init|s3resume|power> [<VCPU>]',
   11.12 @@ -277,6 +279,10 @@ SUBCOMMAND_OPTIONS = {
   11.13         ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'),
   11.14         ('-c CAP',    '--cap=CAP',       'Cap (int)'),
   11.15      ),
   11.16 +    'sched-credit2': (
   11.17 +       ('-d DOMAIN', '--domain=DOMAIN', 'Domain to modify'),
   11.18 +       ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'),
   11.19 +    ),
   11.20      'list': (
   11.21         ('-l', '--long',         'Output all VM details in SXP'),
   11.22         ('', '--label',          'Include security labels'),
   11.23 @@ -418,6 +424,7 @@ host_commands = [
   11.24      ]
   11.25  
   11.26  scheduler_commands = [
   11.27 +    "sched-credit2",
   11.28      "sched-credit",
   11.29      "sched-sedf",
   11.30      ]
   11.31 @@ -1740,6 +1747,80 @@ def xm_sched_credit(args):
   11.32              if result != 0:
   11.33                  err(str(result))
   11.34  
   11.35 +def xm_sched_credit2(args):
   11.36 +    """Get/Set options for Credit2 Scheduler."""
   11.37 +
   11.38 +    check_sched_type('credit2')
   11.39 +
   11.40 +    try:
   11.41 +        opts, params = getopt.getopt(args, "d:w:",
   11.42 +            ["domain=", "weight="])
   11.43 +    except getopt.GetoptError, opterr:
   11.44 +        err(opterr)
   11.45 +        usage('sched-credit2')
   11.46 +
   11.47 +    domid = None
   11.48 +    weight = None
   11.49 +
   11.50 +    for o, a in opts:
   11.51 +        if o in ["-d", "--domain"]:
   11.52 +            domid = a
   11.53 +        elif o in ["-w", "--weight"]:
   11.54 +            weight = int(a)
   11.55 +
   11.56 +    doms = filter(lambda x : domid_match(domid, x),
   11.57 +                  [parse_doms_info(dom)
   11.58 +                  for dom in getDomains(None, 'all')])
   11.59 +
   11.60 +    if weight is None:
   11.61 +        if domid is not None and doms == []:
   11.62 +            err("Domain '%s' does not exist." % domid)
   11.63 +            usage('sched-credit2')
   11.64 +        # print header if we aren't setting any parameters
   11.65 +        print '%-33s %4s %6s' % ('Name','ID','Weight')
   11.66 +
   11.67 +        for d in doms:
   11.68 +            try:
   11.69 +                if serverType == SERVER_XEN_API:
   11.70 +                    info = server.xenapi.VM_metrics.get_VCPUs_params(
   11.71 +                        server.xenapi.VM.get_metrics(
   11.72 +                            get_single_vm(d['name'])))
   11.73 +                else:
   11.74 +                    info = server.xend.domain.sched_credit2_get(d['name'])
   11.75 +            except xmlrpclib.Fault:
   11.76 +                pass
   11.77 +
   11.78 +            if 'weight' not in info:
   11.79 +                # domain does not support sched-credit2?
   11.80 +                info = {'weight': -1}
   11.81 +
   11.82 +            info['weight'] = int(info['weight'])
   11.83 +
   11.84 +            info['name']  = d['name']
   11.85 +            info['domid'] = str(d['domid'])
   11.86 +            print( ("%(name)-32s %(domid)5s %(weight)6d") % info)
   11.87 +    else:
   11.88 +        if domid is None:
   11.89 +            # place holder for system-wide scheduler parameters
   11.90 +            err("No domain given.")
   11.91 +            usage('sched-credit2')
   11.92 +
   11.93 +        if serverType == SERVER_XEN_API:
   11.94 +            if doms[0]['domid']:
   11.95 +                server.xenapi.VM.add_to_VCPUs_params_live(
   11.96 +                    get_single_vm(domid),
   11.97 +                    "weight",
   11.98 +                    weight)
   11.99 +            else:
  11.100 +                server.xenapi.VM.add_to_VCPUs_params(
  11.101 +                    get_single_vm(domid),
  11.102 +                    "weight",
  11.103 +                    weight)
  11.104 +        else:
  11.105 +            result = server.xend.domain.sched_credit2_set(domid, weight)
  11.106 +            if result != 0:
  11.107 +                err(str(result))
  11.108 +
  11.109  def xm_info(args):
  11.110      arg_check(args, "info", 0, 1)
  11.111      
  11.112 @@ -3490,6 +3571,7 @@ commands = {
  11.113      # scheduler
  11.114      "sched-sedf": xm_sched_sedf,
  11.115      "sched-credit": xm_sched_credit,
  11.116 +    "sched-credit2": xm_sched_credit2,
  11.117      # block
  11.118      "block-attach": xm_block_attach,
  11.119      "block-detach": xm_block_detach,