diff -r d2f0843a38e4 tools/libxc/Makefile --- a/tools/libxc/Makefile Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/libxc/Makefile Wed Oct 28 14:42:17 2009 +0000 @@ -17,6 +17,7 @@ CTRL_SRCS-y += xc_private.c CTRL_SRCS-y += xc_sedf.c CTRL_SRCS-y += xc_csched.c +CTRL_SRCS-y += xc_csched2.c CTRL_SRCS-y += xc_tbuf.c CTRL_SRCS-y += xc_pm.c CTRL_SRCS-y += xc_cpu_hotplug.c diff -r d2f0843a38e4 tools/libxc/xc_csched2.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxc/xc_csched2.c Wed Oct 28 14:42:17 2009 +0000 @@ -0,0 +1,50 @@ +/**************************************************************************** + * (C) 2006 - Emmanuel Ackaouy - XenSource Inc. + **************************************************************************** + * + * File: xc_csched.c + * Author: Emmanuel Ackaouy + * + * Description: XC Interface to the credit scheduler + * + */ +#include "xc_private.h" + + +int +xc_sched_credit2_domain_set( + int xc_handle, + uint32_t domid, + struct xen_domctl_sched_credit2 *sdom) +{ + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_scheduler_op; + domctl.domain = (domid_t) domid; + domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT2; + domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo; + domctl.u.scheduler_op.u.credit2 = *sdom; + + return do_domctl(xc_handle, &domctl); +} + +int +xc_sched_credit2_domain_get( + int xc_handle, + uint32_t domid, + struct xen_domctl_sched_credit2 *sdom) +{ + DECLARE_DOMCTL; + int err; + + domctl.cmd = XEN_DOMCTL_scheduler_op; + domctl.domain = (domid_t) domid; + domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT2; + domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo; + + err = do_domctl(xc_handle, &domctl); + if ( err == 0 ) + *sdom = domctl.u.scheduler_op.u.credit2; + + return err; +} diff -r d2f0843a38e4 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/libxc/xenctrl.h Wed Oct 28 14:42:17 2009 +0000 @@ -468,6 +468,14 @@ uint32_t domid, struct xen_domctl_sched_credit *sdom); +int xc_sched_credit2_domain_set(int xc_handle, + uint32_t domid, + struct xen_domctl_sched_credit2 *sdom); + +int xc_sched_credit2_domain_get(int xc_handle, + uint32_t domid, + struct xen_domctl_sched_credit2 *sdom); + /** * This function sends a trigger to a domain. * diff -r d2f0843a38e4 tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/lowlevel/xc/xc.c Wed Oct 28 14:42:17 2009 +0000 @@ -1340,6 +1340,45 @@ "cap", sdom.cap); } +static PyObject *pyxc_sched_credit2_domain_set(XcObject *self, + PyObject *args, + PyObject *kwds) +{ + uint32_t domid; + uint16_t weight; + static char *kwd_list[] = { "domid", "weight", NULL }; + static char kwd_type[] = "I|H"; + struct xen_domctl_sched_credit2 sdom; + + weight = 0; + if( !PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list, + &domid, &weight) ) + return NULL; + + sdom.weight = weight; + + if ( xc_sched_credit2_domain_set(self->xc_handle, domid, &sdom) != 0 ) + return pyxc_error_to_exception(); + + Py_INCREF(zero); + return zero; +} + +static PyObject *pyxc_sched_credit2_domain_get(XcObject *self, PyObject *args) +{ + uint32_t domid; + struct xen_domctl_sched_credit2 sdom; + + if( !PyArg_ParseTuple(args, "I", &domid) ) + return NULL; + + if ( xc_sched_credit2_domain_get(self->xc_handle, domid, &sdom) != 0 ) + return pyxc_error_to_exception(); + + return Py_BuildValue("{s:H}", + "weight", sdom.weight); +} + static PyObject *pyxc_domain_setmaxmem(XcObject *self, PyObject *args) { uint32_t dom; @@ -1871,6 +1910,24 @@ "Returns: [dict]\n" " weight [short]: domain's scheduling weight\n"}, + { "sched_credit2_domain_set", + (PyCFunction)pyxc_sched_credit2_domain_set, + METH_KEYWORDS, "\n" + "Set the scheduling parameters for a domain when running with the\n" + "SMP credit2 scheduler.\n" + " domid [int]: domain id to set\n" + " weight [short]: domain's scheduling weight\n" + "Returns: [int] 0 on success; -1 on error.\n" }, + + { "sched_credit2_domain_get", + (PyCFunction)pyxc_sched_credit2_domain_get, + METH_VARARGS, "\n" + "Get the scheduling parameters for a domain when running with the\n" + "SMP credit2 scheduler.\n" + " domid [int]: domain id to get\n" + "Returns: [dict]\n" + " weight [short]: domain's scheduling weight\n"}, + { "evtchn_alloc_unbound", (PyCFunction)pyxc_evtchn_alloc_unbound, METH_VARARGS | METH_KEYWORDS, "\n" @@ -2230,6 +2287,7 @@ /* Expose some libxc constants to Python */ PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF); PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT); + PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT2", XEN_SCHEDULER_CREDIT2); } diff -r d2f0843a38e4 tools/python/xen/xend/XendAPI.py --- a/tools/python/xen/xend/XendAPI.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xend/XendAPI.py Wed Oct 28 14:42:17 2009 +0000 @@ -1613,8 +1613,7 @@ if 'weight' in xeninfo.info['vcpus_params'] \ and 'cap' in xeninfo.info['vcpus_params']: weight = xeninfo.info['vcpus_params']['weight'] - cap = xeninfo.info['vcpus_params']['cap'] - xendom.domain_sched_credit_set(xeninfo.getDomid(), weight, cap) + xendom.domain_sched_credit2_set(xeninfo.getDomid(), weight) def VM_set_VCPUs_number_live(self, _, vm_ref, num): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) diff -r d2f0843a38e4 tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xend/XendDomain.py Wed Oct 28 14:42:17 2009 +0000 @@ -1757,6 +1757,60 @@ log.exception(ex) raise XendError(str(ex)) + def domain_sched_credit2_get(self, domid): + """Get credit2 scheduler parameters for a domain. + + @param domid: Domain ID or Name + @type domid: int or string. + @rtype: dict with keys 'weight' + @return: credit2 scheduler parameters + """ + dominfo = self.domain_lookup_nr(domid) + if not dominfo: + raise XendInvalidDomain(str(domid)) + + if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED): + try: + return xc.sched_credit2_domain_get(dominfo.getDomid()) + except Exception, ex: + raise XendError(str(ex)) + else: + return {'weight' : dominfo.getWeight()} + + def domain_sched_credit2_set(self, domid, weight = None): + """Set credit2 scheduler parameters for a domain. + + @param domid: Domain ID or Name + @type domid: int or string. + @type weight: int + @rtype: 0 + """ + set_weight = False + dominfo = self.domain_lookup_nr(domid) + if not dominfo: + raise XendInvalidDomain(str(domid)) + try: + if weight is None: + weight = int(0) + elif weight < 1 or weight > 65535: + raise XendError("weight is out of range") + else: + set_weight = True + + assert type(weight) == int + + rc = 0 + if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED): + rc = xc.sched_credit2_domain_set(dominfo.getDomid(), weight) + if rc == 0: + if set_weight: + dominfo.setWeight(weight) + self.managed_config_save(dominfo) + return rc + except Exception, ex: + log.exception(ex) + raise XendError(str(ex)) + def domain_maxmem_set(self, domid, mem): """Set the memory limit for a domain. diff -r d2f0843a38e4 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Oct 28 14:42:17 2009 +0000 @@ -2640,6 +2640,10 @@ XendDomain.instance().domain_sched_credit_set(self.getDomid(), self.getWeight(), self.getCap()) + elif XendNode.instance().xenschedinfo() == 'credit2': + from xen.xend import XendDomain + XendDomain.instance().domain_sched_credit2_set(self.getDomid(), + self.getWeight()) def _initDomain(self): log.debug('XendDomainInfo.initDomain: %s %s', diff -r d2f0843a38e4 tools/python/xen/xend/XendNode.py --- a/tools/python/xen/xend/XendNode.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xend/XendNode.py Wed Oct 28 14:42:17 2009 +0000 @@ -679,6 +679,8 @@ return 'sedf' elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT: return 'credit' + elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT2: + return 'credit2' else: return 'unknown' @@ -874,6 +876,8 @@ return 'sedf' elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT: return 'credit' + elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT2: + return 'credit2' else: return 'unknown' diff -r d2f0843a38e4 tools/python/xen/xend/XendVMMetrics.py --- a/tools/python/xen/xend/XendVMMetrics.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xend/XendVMMetrics.py Wed Oct 28 14:42:17 2009 +0000 @@ -129,6 +129,7 @@ params_live['cpumap%i' % i] = \ ",".join(map(str, info['cpumap'])) + # FIXME: credit2?? params_live.update(xc.sched_credit_domain_get(domid)) return params_live diff -r d2f0843a38e4 tools/python/xen/xend/server/SrvDomain.py --- a/tools/python/xen/xend/server/SrvDomain.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xend/server/SrvDomain.py Wed Oct 28 14:42:17 2009 +0000 @@ -163,6 +163,20 @@ val = fn(req.args, {'dom': self.dom.getName()}) return val + def op_domain_sched_credit2_get(self, _, req): + fn = FormFn(self.xd.domain_sched_credit2_get, + [['dom', 'str']]) + val = fn(req.args, {'dom': self.dom.getName()}) + return val + + + def op_domain_sched_credit2_set(self, _, req): + fn = FormFn(self.xd.domain_sched_credit2_set, + [['dom', 'str'], + ['weight', 'int']]) + val = fn(req.args, {'dom': self.dom.getName()}) + return val + def op_maxmem_set(self, _, req): return self.call(self.dom.setMemoryMaximum, [['memory', 'int']], diff -r d2f0843a38e4 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Wed Oct 28 14:21:37 2009 +0000 +++ b/tools/python/xen/xm/main.py Wed Oct 28 14:42:17 2009 +0000 @@ -150,6 +150,8 @@ 'sched-sedf' : (' [options]', 'Get/set EDF parameters.'), 'sched-credit': ('[-d [-w[=WEIGHT]|-c[=CAP]]]', 'Get/set credit scheduler parameters.'), + 'sched-credit2': ('[-d [-w[=WEIGHT]]', + 'Get/set credit2 scheduler parameters.'), 'sysrq' : (' ', 'Send a sysrq to a domain.'), 'debug-keys' : ('', 'Send debug keys to Xen.'), 'trigger' : (' []', @@ -265,6 +267,10 @@ ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'), ('-c CAP', '--cap=CAP', 'Cap (int)'), ), + 'sched-credit2': ( + ('-d DOMAIN', '--domain=DOMAIN', 'Domain to modify'), + ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'), + ), 'list': ( ('-l', '--long', 'Output all VM details in SXP'), ('', '--label', 'Include security labels'), @@ -406,6 +412,7 @@ ] scheduler_commands = [ + "sched-credit2", "sched-credit", "sched-sedf", ] @@ -1720,6 +1727,80 @@ if result != 0: err(str(result)) +def xm_sched_credit2(args): + """Get/Set options for Credit2 Scheduler.""" + + check_sched_type('credit2') + + try: + opts, params = getopt.getopt(args, "d:w:", + ["domain=", "weight="]) + except getopt.GetoptError, opterr: + err(opterr) + usage('sched-credit2') + + domid = None + weight = None + + for o, a in opts: + if o in ["-d", "--domain"]: + domid = a + elif o in ["-w", "--weight"]: + weight = int(a) + + doms = filter(lambda x : domid_match(domid, x), + [parse_doms_info(dom) + for dom in getDomains(None, 'all')]) + + if weight is None: + if domid is not None and doms == []: + err("Domain '%s' does not exist." % domid) + usage('sched-credit2') + # print header if we aren't setting any parameters + print '%-33s %4s %6s' % ('Name','ID','Weight') + + for d in doms: + try: + if serverType == SERVER_XEN_API: + info = server.xenapi.VM_metrics.get_VCPUs_params( + server.xenapi.VM.get_metrics( + get_single_vm(d['name']))) + else: + info = server.xend.domain.sched_credit2_get(d['name']) + except xmlrpclib.Fault: + pass + + if 'weight' not in info: + # domain does not support sched-credit2? + info = {'weight': -1} + + info['weight'] = int(info['weight']) + + info['name'] = d['name'] + info['domid'] = str(d['domid']) + print( ("%(name)-32s %(domid)5s %(weight)6d") % info) + else: + if domid is None: + # place holder for system-wide scheduler parameters + err("No domain given.") + usage('sched-credit2') + + if serverType == SERVER_XEN_API: + if doms[0]['domid']: + server.xenapi.VM.add_to_VCPUs_params_live( + get_single_vm(domid), + "weight", + weight) + else: + server.xenapi.VM.add_to_VCPUs_params( + get_single_vm(domid), + "weight", + weight) + else: + result = server.xend.domain.sched_credit2_set(domid, weight) + if result != 0: + err(str(result)) + def xm_info(args): arg_check(args, "info", 0, 1) @@ -3298,6 +3379,7 @@ # scheduler "sched-sedf": xm_sched_sedf, "sched-credit": xm_sched_credit, + "sched-credit2": xm_sched_credit2, # block "block-attach": xm_block_attach, "block-detach": xm_block_detach,