From: Meng Xu <mengxu@cis.upenn.edu>
To: xen-devel@lists.xen.org
Cc: ian.campbell@citrix.com, xisisu@gmail.com,
stefano.stabellini@eu.citrix.com, george.dunlap@eu.citrix.com,
dario.faggioli@citrix.com, ian.jackson@eu.citrix.com,
xumengpanda@gmail.com, Meng Xu <mengxu@cis.upenn.edu>,
lichong659@gmail.com, dgolomb@seas.upenn.edu
Subject: [PATCH RFC v1 3/4] libxl for rt scheduler
Date: Fri, 11 Jul 2014 00:49:57 -0400 [thread overview]
Message-ID: <1405054198-29106-4-git-send-email-mengxu@cis.upenn.edu> (raw)
In-Reply-To: <1405054198-29106-1-git-send-email-mengxu@cis.upenn.edu>
Add libxl functions to set/get domain's parameters for rt scheduler
Signed-off-by: Sisu Xi <xisisu@gmail.com>
Signed-off-by: Meng Xu <mengxu@cis.upenn.edu>
---
tools/libxl/libxl.c | 121 +++++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl.h | 7 +++
tools/libxl/libxl_types.idl | 13 +++++
3 files changed, 141 insertions(+)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 39f1c28..670420e 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5100,6 +5100,121 @@ static int sched_sedf_domain_set(libxl__gc *gc, uint32_t domid,
return 0;
}
+static int sched_rt_domain_get(libxl__gc *gc, uint32_t domid,
+ libxl_domain_sched_params *scinfo)
+{
+ struct xen_domctl_sched_rt_params sdom;
+ int rc, i;
+
+ rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);
+ if (rc != 0) {
+ LOGE(ERROR, "getting domain sched rt");
+ return ERROR_FAIL;
+ }
+
+ libxl_domain_sched_params_init(scinfo);
+ scinfo->sched = LIBXL_SCHEDULER_RT;
+ scinfo->rt.max_vcpus = LIBXL_XEN_LEGACY_MAX_VCPUS;
+ /*TODO: alloc array with exact num of dom's vcpus; and use GCNEW_ARRAY()*/
+ scinfo->rt.vcpus = (libxl_vcpu *)
+ malloc( sizeof(libxl_vcpu) * scinfo->rt.max_vcpus );
+ if ( !scinfo->rt.vcpus ){
+ LOGE(ERROR, "Allocate lib_vcpu array fails\n");
+ return ERROR_INVAL;
+ }
+ scinfo->rt.num_vcpus = sdom.num_vcpus;
+ for( i = 0; i < sdom.num_vcpus; ++i)
+ {
+ scinfo->rt.vcpus[i].period = sdom.vcpus[i].period;
+ scinfo->rt.vcpus[i].budget = sdom.vcpus[i].budget;
+ }
+
+ return 0;
+}
+
+#define SCHED_RT_VCPU_PARAMS_MAX 4294967295 /* 2^32-1 */
+
+/*
+ * Sanity check of the scinfo parameters
+ * return 0 if all values are valid
+ * return 1 if one param is default value
+ * return 2 if the target vcpu's index, period or budget is out of range
+ */
+static int sched_rt_domain_set_validate_params(libxl__gc *gc,
+ const libxl_domain_sched_params *scinfo)
+{
+ int vcpu_index = scinfo->rt.vcpu_index;
+
+ if (scinfo->rt.vcpus == NULL ||
+ vcpu_index == LIBXL_DOMAIN_SCHED_PARAM_VCPU_DEFAULT ||
+ scinfo->rt.vcpus[vcpu_index].period == LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT ||
+ scinfo->rt.vcpus[vcpu_index].budget == LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT)
+ {
+ return 1;
+ }
+
+ if (vcpu_index < 0 || vcpu_index > scinfo->rt.num_vcpus)
+ {
+ LOG(ERROR, "VCPU index is not set or out of range, "
+ "valid values are within range from 0 to %d", scinfo->rt.num_vcpus);
+ return 2;
+ }
+
+ if (scinfo->rt.vcpus[vcpu_index].period < 1 ||
+ scinfo->rt.vcpus[vcpu_index].period > SCHED_RT_VCPU_PARAMS_MAX)
+ {
+ LOG(ERROR, "VCPU period is not set or out of range, "
+ "valid values are within range from 0 to %lu", SCHED_RT_VCPU_PARAMS_MAX);
+ return 2;
+ }
+
+ if (scinfo->rt.vcpus[vcpu_index].budget < 1 ||
+ scinfo->rt.vcpus[vcpu_index].budget > SCHED_RT_VCPU_PARAMS_MAX)
+ {
+ LOG(ERROR, "VCPU budget is not set or out of range, "
+ "valid values are within range from 0 to %lu", SCHED_RT_VCPU_PARAMS_MAX);
+ return 2;
+ }
+
+ return 0;
+
+}
+
+static int sched_rt_domain_set(libxl__gc *gc, uint32_t domid,
+ const libxl_domain_sched_params *scinfo)
+{
+ struct xen_domctl_sched_rt_params sdom;
+ int vcpu_index;
+ int rc;
+
+ rc = xc_sched_rt_domain_get(CTX->xch, domid, &sdom);
+ if (rc != 0) {
+ LOGE(ERROR, "getting domain sched rt");
+ return ERROR_FAIL;
+ }
+
+ rc = sched_rt_domain_set_validate_params(gc, scinfo);
+ if (rc == 2)
+ return ERROR_INVAL;
+ if (rc == 1)
+ return 0;
+ if (rc == 0)
+ {
+ vcpu_index = scinfo->rt.vcpu_index;
+ sdom.vcpu_index = scinfo->rt.vcpu_index;
+ sdom.vcpus[vcpu_index].period = scinfo->rt.vcpus[vcpu_index].period;
+ sdom.vcpus[vcpu_index].budget = scinfo->rt.vcpus[vcpu_index].budget;
+ }
+
+ rc = xc_sched_rt_domain_set(CTX->xch, domid, &sdom);
+ if ( rc < 0 ) {
+ LOGE(ERROR, "setting domain sched rt");
+ return ERROR_FAIL;
+ }
+
+ return 0;
+}
+
int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
const libxl_domain_sched_params *scinfo)
{
@@ -5123,6 +5238,9 @@ int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
case LIBXL_SCHEDULER_ARINC653:
ret=sched_arinc653_domain_set(gc, domid, scinfo);
break;
+ case LIBXL_SCHEDULER_RT:
+ ret=sched_rt_domain_set(gc, domid, scinfo);
+ break;
default:
LOG(ERROR, "Unknown scheduler");
ret=ERROR_INVAL;
@@ -5153,6 +5271,9 @@ int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
case LIBXL_SCHEDULER_CREDIT2:
ret=sched_credit2_domain_get(gc, domid, scinfo);
break;
+ case LIBXL_SCHEDULER_RT:
+ ret=sched_rt_domain_get(gc, domid, scinfo);
+ break;
default:
LOG(ERROR, "Unknown scheduler");
ret=ERROR_INVAL;
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 459557d..42c8ede 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1217,6 +1217,13 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
#define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT -1
#define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_VCPU_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_NUM_VCPUS_DEFAULT -1
+#define LIBXL_DOMAIN_SCHED_PARAM_VCPU_INDEX_DEFAULT -1
+/* Consistent with XEN_LEGACY_MAX_VCPUS xen/arch-x86/xen.h*/
+#define LIBXL_XEN_LEGACY_MAX_VCPUS 32
+
int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
libxl_domain_sched_params *params);
int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index de25f42..00e00d8 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -139,6 +139,7 @@ libxl_scheduler = Enumeration("scheduler", [
(5, "credit"),
(6, "credit2"),
(7, "arinc653"),
+ (8, "rt"),
])
# Consistent with SHUTDOWN_* in sched.h (apart from UNKNOWN)
@@ -289,6 +290,17 @@ libxl_domain_restore_params = Struct("domain_restore_params", [
("checkpointed_stream", integer),
])
+libxl_rt_vcpu = Struct("vcpu",[
+ ("period", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT'}),
+ ("budget", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
+ ])
+
+libxl_domain_sched_rt_params = Struct("domain_sched_rt_params",[
+ ("vcpus", Array(libxl_rt_vcpu, "max_vcpus")),
+ ("num_vcpus", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_NUM_VCPUS_DEFAULT'}),
+ ("vcpu_index", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_VCPU_INDEX_DEFAULT'}),
+ ])
+
libxl_domain_sched_params = Struct("domain_sched_params",[
("sched", libxl_scheduler),
("weight", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
@@ -297,6 +309,7 @@ libxl_domain_sched_params = Struct("domain_sched_params",[
("slice", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT'}),
("latency", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT'}),
("extratime", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT'}),
+ ("rt", libxl_domain_sched_rt_params),
])
libxl_domain_build_info = Struct("domain_build_info",[
--
1.7.9.5
next prev parent reply other threads:[~2014-07-11 4:49 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 4:49 Introduce rt real-time scheduler for Xen Meng Xu
2014-07-11 4:49 ` [PATCH RFC v1 1/4] rt: Add rt scheduler to hypervisor Meng Xu
2014-07-11 14:27 ` Dario Faggioli
2014-07-11 14:37 ` Andrew Cooper
2014-07-11 15:21 ` Dario Faggioli
2014-07-11 15:40 ` Andrew Cooper
2014-07-11 15:48 ` Dario Faggioli
2014-07-16 17:05 ` Konrad Rzeszutek Wilk
2014-07-17 10:12 ` Meng Xu
2014-07-17 15:12 ` Dario Faggioli
2014-07-18 5:46 ` Meng Xu
2014-07-18 18:40 ` Konrad Rzeszutek Wilk
2014-07-11 4:49 ` [PATCH RFC v1 2/4] xl for rt scheduler Meng Xu
2014-07-11 11:02 ` Wei Liu
2014-07-11 14:59 ` Meng Xu
2014-07-11 15:07 ` Dario Faggioli
2014-07-11 16:25 ` Meng Xu
2014-07-13 12:58 ` Meng Xu
2014-07-14 7:40 ` Dario Faggioli
2014-07-14 9:31 ` Wei Liu
2014-07-17 15:39 ` Ian Campbell
2014-07-11 4:49 ` Meng Xu [this message]
2014-07-11 11:05 ` [PATCH RFC v1 3/4] libxl " Wei Liu
2014-07-11 15:08 ` Dario Faggioli
2014-07-12 18:16 ` Meng Xu
2014-07-14 10:38 ` Dario Faggioli
2014-07-17 15:34 ` Ian Campbell
2014-07-17 15:36 ` Ian Campbell
2014-07-18 11:05 ` Meng Xu
2014-07-11 4:49 ` [PATCH RFC v1 4/4] libxc " Meng Xu
2014-07-11 14:49 ` Dario Faggioli
2014-07-11 16:23 ` Meng Xu
2014-07-11 16:35 ` Dario Faggioli
2014-07-11 16:49 ` Andrew Cooper
2014-07-12 19:46 ` Meng Xu
2014-07-17 15:29 ` Ian Campbell
2014-07-17 15:34 ` George Dunlap
2014-07-17 22:16 ` Meng Xu
2014-07-18 9:49 ` Dario Faggioli
2014-07-18 9:51 ` Ian Campbell
2014-07-18 12:11 ` Meng Xu
2014-07-18 9:47 ` Ian Campbell
2014-07-18 10:00 ` Dario Faggioli
2014-07-11 10:50 ` Introduce rt real-time scheduler for Xen Wei Liu
2014-07-11 11:06 ` Dario Faggioli
2014-07-11 16:14 ` Meng Xu
2014-07-11 16:19 ` Dario Faggioli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405054198-29106-4-git-send-email-mengxu@cis.upenn.edu \
--to=mengxu@cis.upenn.edu \
--cc=dario.faggioli@citrix.com \
--cc=dgolomb@seas.upenn.edu \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=lichong659@gmail.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
--cc=xisisu@gmail.com \
--cc=xumengpanda@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).