diff -r 56032cbaf1e8 tools/python/xen/lowlevel/xc/xc.c --- a/tools/python/xen/lowlevel/xc/xc.c Thu Jan 22 10:43:50 2009 +0900 +++ b/tools/python/xen/lowlevel/xc/xc.c Thu Jan 22 12:31:18 2009 +0900 @@ -1285,18 +1285,21 @@ static PyObject *pyxc_sched_credit_domai uint32_t domid; uint16_t weight; uint16_t cap; - static char *kwd_list[] = { "domid", "weight", "cap", NULL }; - static char kwd_type[] = "I|HH"; + uint16_t percent; + static char *kwd_list[] = { "domid", "weight", "cap", "percent", NULL }; + static char kwd_type[] = "I|HHh"; struct xen_domctl_sched_credit sdom; weight = 0; cap = (uint16_t)~0U; + percent = (uint16_t)~0U; if( !PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list, - &domid, &weight, &cap) ) + &domid, &weight, &cap, &percent) ) return NULL; sdom.weight = weight; sdom.cap = cap; + sdom.percent = percent; if ( xc_sched_credit_domain_set(self->xc_handle, domid, &sdom) != 0 ) return pyxc_error_to_exception(); @@ -1316,9 +1319,10 @@ static PyObject *pyxc_sched_credit_domai if ( xc_sched_credit_domain_get(self->xc_handle, domid, &sdom) != 0 ) return pyxc_error_to_exception(); - return Py_BuildValue("{s:H,s:H}", + return Py_BuildValue("{s:H,s:H,s:i}", "weight", sdom.weight, - "cap", sdom.cap); + "cap", sdom.cap, + "percent", sdom.percent); } static PyObject *pyxc_domain_setmaxmem(XcObject *self, PyObject *args) @@ -1744,6 +1748,8 @@ static PyMethodDef pyxc_methods[] = { "SMP credit scheduler.\n" " domid [int]: domain id to set\n" " weight [short]: domain's scheduling weight\n" + " cap [short]: cap\n" + " percent [short]; domain's scheduling percentage per a cpu\n" "Returns: [int] 0 on success; -1 on error.\n" }, { "sched_credit_domain_get", @@ -1753,7 +1759,9 @@ static PyMethodDef pyxc_methods[] = { "SMP credit scheduler.\n" " domid [int]: domain id to get\n" "Returns: [dict]\n" - " weight [short]: domain's scheduling weight\n"}, + " weight [short]: domain's scheduling weight\n" + " cap [short]: cap\n" + " percent [short]: domain's scheduling percentage per a cpu\n"}, { "evtchn_alloc_unbound", (PyCFunction)pyxc_evtchn_alloc_unbound, diff -r 56032cbaf1e8 tools/python/xen/xend/XendAPI.py --- a/tools/python/xen/xend/XendAPI.py Thu Jan 22 10:43:50 2009 +0900 +++ b/tools/python/xen/xend/XendAPI.py Thu Jan 22 12:31:18 2009 +0900 @@ -1505,10 +1505,12 @@ class XendAPI(object): #need to update sched params aswell if 'weight' in xeninfo.info['vcpus_params'] \ - and 'cap' in xeninfo.info['vcpus_params']: + and 'cap' in xeninfo.info['vcpus_params'] \ + and 'percent' 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) + percent = xeninfo.info['vcpus_params']['percent'] + xendom.domain_sched_credit_set(xeninfo.getDomid(), weight, cap, percent) def VM_set_VCPUs_number_live(self, _, vm_ref, num): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) diff -r 56032cbaf1e8 tools/python/xen/xend/XendConfig.py --- a/tools/python/xen/xend/XendConfig.py Thu Jan 22 10:43:50 2009 +0900 +++ b/tools/python/xen/xend/XendConfig.py Thu Jan 22 12:31:18 2009 +0900 @@ -591,6 +591,8 @@ class XendConfig(dict): int(sxp.child_value(sxp_cfg, "cpu_weight", 256)) cfg["vcpus_params"]["cap"] = \ int(sxp.child_value(sxp_cfg, "cpu_cap", 0)) + cfg["vcpus_params"]["percent"] = \ + int(sxp.child_value(sxp_cfg, "cpu_percent", 0)) # Only extract options we know about. extract_keys = LEGACY_UNSUPPORTED_BY_XENAPI_CFG + \ diff -r 56032cbaf1e8 tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Thu Jan 22 10:43:50 2009 +0900 +++ b/tools/python/xen/xend/XendDomain.py Thu Jan 22 12:31:18 2009 +0900 @@ -1536,7 +1536,7 @@ class XendDomain: @param domid: Domain ID or Name @type domid: int or string. - @rtype: dict with keys 'weight' and 'cap' + @rtype: dict with keys 'weight' and 'cap' and 'percent' @return: credit scheduler parameters """ dominfo = self.domain_lookup_nr(domid) @@ -1550,19 +1550,22 @@ class XendDomain: raise XendError(str(ex)) else: return {'weight' : dominfo.getWeight(), - 'cap' : dominfo.getCap()} + 'cap' : dominfo.getCap(), + 'percent': dominfo.getPercent()} - def domain_sched_credit_set(self, domid, weight = None, cap = None): + def domain_sched_credit_set(self, domid, weight = None, cap = None, percent = None): """Set credit scheduler parameters for a domain. @param domid: Domain ID or Name @type domid: int or string. @type weight: int @type cap: int + @type percent: int @rtype: 0 """ set_weight = False set_cap = False + set_percent = False dominfo = self.domain_lookup_nr(domid) if not dominfo: raise XendInvalidDomain(str(domid)) @@ -1581,17 +1584,27 @@ class XendDomain: else: set_cap = True + if percent is None: + percent = int(~0) + elif percent < 0: + raise XendError("percent is out of range") + else: + set_percent = True + assert type(weight) == int assert type(cap) == int + assert type(percent) == int rc = 0 if dominfo._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED): - rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap) + rc = xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap, percent) if rc == 0: if set_weight: dominfo.setWeight(weight) if set_cap: dominfo.setCap(cap) + if set_percent: + dominfo.setPercent(percent) self.managed_config_save(dominfo) return rc except Exception, ex: diff -r 56032cbaf1e8 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Thu Jan 22 10:43:50 2009 +0900 +++ b/tools/python/xen/xend/XendDomainInfo.py Thu Jan 22 12:31:18 2009 +0900 @@ -467,7 +467,8 @@ class XendDomainInfo: if xennode.xenschedinfo() == 'credit': xendomains.domain_sched_credit_set(self.getDomid(), self.getWeight(), - self.getCap()) + self.getCap(), + self.getPercent()) except: log.exception('VM start failed') self.destroy() @@ -1705,6 +1706,12 @@ class XendDomainInfo: def setWeight(self, cpu_weight): self.info['vcpus_params']['weight'] = cpu_weight + def getPercent(self): + return self.info['vcpus_params']['percent'] + + def setPercent(self, cpu_percent): + self.info['vcpus_params']['percent'] = cpu_percent + def getRestartCount(self): return self._readVm('xend/restart_count') diff -r 56032cbaf1e8 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Thu Jan 22 10:43:50 2009 +0900 +++ b/tools/python/xen/xm/main.py Thu Jan 22 12:31:18 2009 +0900 @@ -150,7 +150,7 @@ SUBCOMMAND_HELP = { 'log' : ('', 'Print Xend log'), 'rename' : (' ', 'Rename a domain.'), 'sched-sedf' : (' [options]', 'Get/set EDF parameters.'), - 'sched-credit': ('[-d [-w[=WEIGHT]|-c[=CAP]]]', + 'sched-credit': ('[-d [-w[=WEIGHT]|-c[=CAP]|-p[=PERCENT]]]', 'Get/set credit scheduler parameters.'), 'sysrq' : (' ', 'Send a sysrq to a domain.'), 'debug-keys' : ('', 'Send debug keys to Xen.'), @@ -240,6 +240,7 @@ SUBCOMMAND_OPTIONS = { ('-d DOMAIN', '--domain=DOMAIN', 'Domain to modify'), ('-w WEIGHT', '--weight=WEIGHT', 'Weight (int)'), ('-c CAP', '--cap=CAP', 'Cap (int)'), + ('-p PERCENT', '--percent=PERCENT', 'Percent per a cpu (int)'), ), 'list': ( ('-l', '--long', 'Output all VM details in SXP'), @@ -1578,8 +1579,8 @@ def xm_sched_credit(args): check_sched_type('credit') try: - opts, params = getopt.getopt(args, "d:w:c:", - ["domain=", "weight=", "cap="]) + opts, params = getopt.getopt(args, "d:w:c:p:", + ["domain=", "weight=", "cap=", "percent="]) except getopt.GetoptError, opterr: err(opterr) usage('sched-credit') @@ -1587,6 +1588,7 @@ def xm_sched_credit(args): domid = None weight = None cap = None + percent = None for o, a in opts: if o in ["-d", "--domain"]: @@ -1594,18 +1596,20 @@ def xm_sched_credit(args): elif o in ["-w", "--weight"]: weight = int(a) elif o in ["-c", "--cap"]: - cap = int(a); + cap = int(a) + elif o in ["-p", "--percent"]: + percent = int(a); doms = filter(lambda x : domid_match(domid, x), [parse_doms_info(dom) for dom in getDomains(None, 'all')]) - if weight is None and cap is None: + if weight is None and cap is None and percent is None: if domid is not None and doms == []: err("Domain '%s' does not exist." % domid) usage('sched-credit') # print header if we aren't setting any parameters - print '%-33s %4s %6s %4s' % ('Name','ID','Weight','Cap') + print '%-33s %4s %6s %4s %7s' % ('Name','ID','Weight','Cap','Percent') for d in doms: try: @@ -1618,16 +1622,17 @@ def xm_sched_credit(args): except xmlrpclib.Fault: pass - if 'weight' not in info or 'cap' not in info: + if 'weight' not in info or 'cap' not in info or 'percent' not in info: # domain does not support sched-credit? - info = {'weight': -1, 'cap': -1} + info = {'weight': -1, 'cap': -1, 'percent':-1} info['weight'] = int(info['weight']) info['cap'] = int(info['cap']) + info['percent'] = int(info['percent']) info['name'] = d['name'] info['domid'] = str(d['domid']) - print( ("%(name)-32s %(domid)5s %(weight)6d %(cap)4d") % info) + print( ("%(name)-32s %(domid)5s %(weight)6d %(cap)4d %(percent)6d") % info) else: if domid is None: # place holder for system-wide scheduler parameters @@ -1644,6 +1649,10 @@ def xm_sched_credit(args): get_single_vm(domid), "cap", cap) + server.xenapi.VM.add_to_VCPUs_params_live( + get_single_vm(domid), + "percent", + percent) else: server.xenapi.VM.add_to_VCPUs_params( get_single_vm(domid), @@ -1653,8 +1662,12 @@ def xm_sched_credit(args): get_single_vm(domid), "cap", cap) + server.xenapi.VM.add_to_VCPUs_params( + get_single_vm(domid), + "percent", + percent) else: - result = server.xend.domain.sched_credit_set(domid, weight, cap) + result = server.xend.domain.sched_credit_set(domid, weight, cap, percent) if result != 0: err(str(result))