11 files changed, 277 insertions(+), 2 deletions(-)
tools/libxc/Makefile | 1
tools/libxc/xc_csched2.c | 50 +++++++++++++++++
tools/libxc/xenctrl.h | 8 ++
tools/python/xen/lowlevel/xc/xc.c | 58 ++++++++++++++++++++
tools/python/xen/xend/XendAPI.py | 3 -
tools/python/xen/xend/XendDomain.py | 54 +++++++++++++++++++
tools/python/xen/xend/XendDomainInfo.py | 4 +
tools/python/xen/xend/XendNode.py | 4 +
tools/python/xen/xend/XendVMMetrics.py | 1
tools/python/xen/xend/server/SrvDomain.py | 14 ++++
tools/python/xen/xm/main.py | 82 +++++++++++++++++++++++++++++
Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
diff -r 1cdbec67f224 -r 149e4fb24e95 tools/libxc/Makefile
--- a/tools/libxc/Makefile Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/libxc/Makefile Wed Apr 14 11:25:17 2010 +0100
@@ -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 1cdbec67f224 -r 149e4fb24e95 tools/libxc/xc_csched2.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_csched2.c Wed Apr 14 11:25:17 2010 +0100
@@ -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 1cdbec67f224 -r 149e4fb24e95 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/libxc/xenctrl.h Wed Apr 14 11:25:17 2010 +0100
@@ -475,6 +475,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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/lowlevel/xc/xc.c Wed Apr 14 11:25:17 2010 +0100
@@ -1558,6 +1558,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;
@@ -2113,6 +2152,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"
@@ -2495,6 +2552,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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xend/XendAPI.py Wed Apr 14 11:25:17 2010 +0100
@@ -1626,8 +1626,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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xend/XendDomain.py Wed Apr 14 11:25:17 2010 +0100
@@ -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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py Wed Apr 14 11:25:17 2010 +0100
@@ -2811,6 +2811,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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xend/XendNode.py Wed Apr 14 11:25:17 2010 +0100
@@ -779,6 +779,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'
@@ -988,6 +990,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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xend/XendVMMetrics.py
--- a/tools/python/xen/xend/XendVMMetrics.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xend/XendVMMetrics.py Wed Apr 14 11:25:17 2010 +0100
@@ -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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xend/server/SrvDomain.py
--- a/tools/python/xen/xend/server/SrvDomain.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xend/server/SrvDomain.py Wed Apr 14 11:25:17 2010 +0100
@@ -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 1cdbec67f224 -r 149e4fb24e95 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py Wed Apr 14 11:16:58 2010 +0100
+++ b/tools/python/xen/xm/main.py Wed Apr 14 11:25:17 2010 +0100
@@ -151,6 +151,8 @@
'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 @@
('-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 @@
]
scheduler_commands = [
+ "sched-credit2",
"sched-credit",
"sched-sedf",
]
@@ -1740,6 +1747,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)
@@ -3490,6 +3571,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,
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|