credit2: Add toolstack options to control credit2 scheduler parameters

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
This commit is contained in:
Keir Fraser committed 2010-04-14 12:10:19 +01:00
1 parent 0dd76d3d20
commit 3ac51fc221
11 files changed
+277 -2

No files matched your search

+58
View File
@@ -1558,6 +1558,45 @@ static PyObject *pyxc_sched_credit_domain_get(XcObject *self, PyObject *args)
"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;
@@ -2113,6 +2152,24 @@ static PyMethodDef pyxc_methods[] = {
"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"
@@ -2495,6 +2552,7 @@ PyMODINIT_FUNC initxc(void)
/* 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);
}
+1 -2
View File
@@ -1626,8 +1626,7 @@ class XendAPI(object):
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)
+54
View File
@@ -1757,6 +1757,60 @@ class XendDomain:
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.
+4
View File
@@ -2811,6 +2811,10 @@ class XendDomainInfo:
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',
+4
View File
@@ -779,6 +779,8 @@ class XendNode:
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'
@@ -988,6 +990,8 @@ class XendNode:
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'
+1
View File
@@ -129,6 +129,7 @@ class XendVMMetrics(XendBase):
params_live['cpumap%i' % i] = \
",".join(map(str, info['cpumap']))
# FIXME: credit2??
params_live.update(xc.sched_credit_domain_get(domid))
return params_live
+14
View File
@@ -163,6 +163,20 @@ class SrvDomain(SrvDir):
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']],
+82
View File
@@ -151,6 +151,8 @@ SUBCOMMAND_HELP = {
'sched-sedf' : ('<Domain> [options]', 'Get/set EDF parameters.'),
'sched-credit': ('[-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]',
'Get/set credit scheduler parameters.'),
'sched-credit2': ('[-d <Domain> [-w[=WEIGHT]]',
'Get/set credit2 scheduler parameters.'),
'sysrq' : ('<Domain> <letter>', 'Send a sysrq to a domain.'),
'debug-keys' : ('<Keys>', 'Send debug keys to Xen.'),
'trigger' : ('<Domain> <nmi|reset|init|s3resume|power> [<VCPU>]',
@@ -277,6 +279,10 @@ SUBCOMMAND_OPTIONS = {
('-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'),
@@ -418,6 +424,7 @@ host_commands = [
]
scheduler_commands = [
"sched-credit2",
"sched-credit",
"sched-sedf",
]
@@ -1740,6 +1747,80 @@ def xm_sched_credit(args):
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)
@@ -3490,6 +3571,7 @@ commands = {
# 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,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.