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>,
JBeulich@suse.com, chaowang@wustl.edu, lichong659@gmail.com,
dgolomb@seas.upenn.edu
Subject: [PATCH v1 3/4] libxl: add rt scheduler
Date: Sun, 24 Aug 2014 18:58:44 -0400 [thread overview]
Message-ID: <1408921125-21470-4-git-send-email-mengxu@cis.upenn.edu> (raw)
In-Reply-To: <1408921125-21470-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 | 139 +++++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl.h | 7 +++
tools/libxl/libxl_types.idl | 15 +++++
3 files changed, 161 insertions(+)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 3526539..440e8df31 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -5154,6 +5154,139 @@ 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;
+ uint16_t num_vcpus;
+ int rc, i;
+
+ rc = xc_sched_rt_domain_get_num_vcpus(CTX->xch, domid, &num_vcpus);
+ if (rc != 0) {
+ LOGE(ERROR, "getting num_vcpus of domain sched rt");
+ return ERROR_FAIL;
+ }
+
+ /* FIXME: can malloc be used in libxl? seems it was used in the file */
+ sdom = (struct xen_domctl_sched_rt_params *)
+ malloc( sizeof(struct xen_domctl_sched_rt_params) * num_vcpus );
+ if ( !sdom ){
+ LOGE(ERROR, "Allocate sdom array fails\n");
+ return ERROR_INVAL;
+ }
+
+ rc = xc_sched_rt_domain_get(CTX->xch, domid, sdom, num_vcpus);
+ if (rc != 0) {
+ LOGE(ERROR, "getting domain sched rt");
+ return ERROR_FAIL;
+ }
+
+ /* FIXME: how to guarantee libxl_*_dispose be called exactly once? */
+ libxl_domain_sched_params_init(scinfo);
+
+ scinfo->rt.num_vcpus = num_vcpus;
+ scinfo->sched = LIBXL_SCHEDULER_RT;
+ /* FIXME: can malloc be used in libxl? seems it was used in the file */
+ scinfo->rt.vcpus = (libxl_vcpu *)
+ malloc( sizeof(libxl_vcpu) * scinfo->rt.num_vcpus );
+ if ( !scinfo->rt.vcpus ){
+ LOGE(ERROR, "Allocate lib_vcpu array fails\n");
+ return ERROR_INVAL;
+ }
+ for( i = 0; i < num_vcpus; ++i)
+ {
+ scinfo->rt.vcpus[i].period = sdom[i].period;
+ scinfo->rt.vcpus[i].budget = sdom[i].budget;
+ scinfo->rt.vcpus[i].index = sdom[i].index;
+ }
+
+ free(sdom);
+ return 0;
+}
+
+#define SCHED_RT_VCPU_PERIOD_MAX 31536000000000 /* one year in microsecond*/
+#define SCHED_RT_VCPU_BUDGET_MAX SCHED_RT_VCPU_PERIOD_MAX
+
+/*
+ * 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,
+ const uint16_t num_vcpus)
+{
+ int vcpu_index = scinfo->rt.vcpu_index;
+
+ if (vcpu_index == LIBXL_DOMAIN_SCHED_PARAM_VCPU_DEFAULT ||
+ scinfo->rt.period == LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT ||
+ scinfo->rt.budget == LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT)
+ {
+ return 1;
+ }
+
+ if (vcpu_index < 0 || vcpu_index > num_vcpus)
+ {
+ LOG(ERROR, "VCPU index is not set or out of range, "
+ "valid values are within range from 0 to %d", num_vcpus);
+ return 2;
+ }
+
+ if (scinfo->rt.period < 1 ||
+ scinfo->rt.period > SCHED_RT_VCPU_PERIOD_MAX)
+ {
+ LOG(ERROR, "VCPU period is not set or out of range, "
+ "valid values are within range from 0 to %lu", SCHED_RT_VCPU_PERIOD_MAX);
+ return 2;
+ }
+
+ if (scinfo->rt.budget < 1 ||
+ scinfo->rt.budget > SCHED_RT_VCPU_BUDGET_MAX)
+ {
+ LOG(ERROR, "VCPU budget is not set or out of range, "
+ "valid values are within range from 0 to %lu", SCHED_RT_VCPU_BUDGET_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;
+ uint16_t num_vcpus;
+ int rc;
+
+ rc = xc_sched_rt_domain_get_num_vcpus(CTX->xch, domid, &num_vcpus);
+ if (rc != 0) {
+ LOGE(ERROR, "getting domain sched rt");
+ return ERROR_FAIL;
+ }
+
+ rc = sched_rt_domain_set_validate_params(gc, scinfo, num_vcpus);
+ if (rc == 2)
+ return ERROR_INVAL;
+ if (rc == 1)
+ return 0;
+ if (rc == 0)
+ {
+ sdom.index = scinfo->rt.vcpu_index;
+ sdom.period = scinfo->rt.period;
+ sdom.budget = scinfo->rt.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)
{
@@ -5177,6 +5310,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;
@@ -5207,6 +5343,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 bfeb3bc..4657056 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1240,6 +1240,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 0b3496f..c33a776 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -153,6 +153,7 @@ libxl_scheduler = Enumeration("scheduler", [
(5, "credit"),
(6, "credit2"),
(7, "arinc653"),
+ (8, "rt"),
])
# Consistent with SHUTDOWN_* in sched.h (apart from UNKNOWN)
@@ -303,6 +304,19 @@ libxl_domain_restore_params = Struct("domain_restore_params", [
("checkpointed_stream", integer),
])
+libxl_rt_vcpu = Struct("vcpu",[
+ ("period", uint64, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT'}),
+ ("budget", uint64, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT'}),
+ ("index", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_VCPU_INDEX_DEFAULT'}),
+ ])
+
+libxl_domain_sched_rt_params = Struct("domain_sched_rt_params",[
+ ("vcpus", Array(libxl_rt_vcpu, "num_vcpus")),
+ ("period", uint64, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT'}),
+ ("budget", uint64, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_BUDGET_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'}),
@@ -311,6 +325,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-08-24 22:58 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-24 22:58 Introduce rt real-time scheduler for Xen Meng Xu
2014-08-24 22:58 ` [PATCH v1 1/4] xen: add real time scheduler rt Meng Xu
2014-08-26 14:27 ` Jan Beulich
2014-08-27 2:07 ` Meng Xu
2014-08-27 6:26 ` Jan Beulich
2014-08-27 14:28 ` Meng Xu
2014-08-27 15:04 ` Jan Beulich
2014-08-28 16:06 ` Meng Xu
2014-08-29 9:05 ` Jan Beulich
2014-08-29 19:35 ` Meng Xu
2014-09-03 14:08 ` George Dunlap
2014-09-03 14:24 ` Meng Xu
2014-09-03 14:35 ` Dario Faggioli
2014-09-03 13:40 ` George Dunlap
2014-09-03 14:11 ` Meng Xu
2014-09-03 14:15 ` George Dunlap
2014-09-03 14:35 ` Meng Xu
2014-09-05 9:46 ` Dario Faggioli
2014-09-03 14:20 ` George Dunlap
2014-09-03 14:45 ` Jan Beulich
2014-09-03 14:59 ` Dario Faggioli
2014-09-03 15:27 ` Meng Xu
2014-09-03 15:46 ` Dario Faggioli
2014-09-03 17:13 ` George Dunlap
2014-09-03 15:13 ` Meng Xu
2014-09-03 16:06 ` George Dunlap
2014-09-03 16:57 ` Dario Faggioli
2014-09-03 17:18 ` George Dunlap
2014-09-04 2:15 ` Meng Xu
2014-09-04 14:27 ` Dario Faggioli
2014-09-04 15:30 ` Meng Xu
2014-09-05 9:36 ` Dario Faggioli
2014-09-05 15:06 ` Meng Xu
2014-09-05 15:09 ` Dario Faggioli
2014-09-04 2:11 ` Meng Xu
2014-09-04 11:00 ` Dario Faggioli
2014-09-04 13:03 ` George Dunlap
2014-09-04 14:00 ` Meng Xu
2014-09-05 17:17 ` Dario Faggioli
2014-09-07 3:56 ` Meng Xu
2014-09-08 10:33 ` Dario Faggioli
2014-09-09 13:43 ` Meng Xu
2014-08-24 22:58 ` [PATCH v1 2/4] libxc: add rt scheduler Meng Xu
2014-09-05 10:34 ` Dario Faggioli
2014-09-05 17:17 ` Meng Xu
2014-09-05 17:50 ` Dario Faggioli
2014-08-24 22:58 ` Meng Xu [this message]
2014-08-25 13:17 ` [PATCH v1 3/4] libxl: " Wei Liu
2014-08-25 15:55 ` Meng Xu
2014-08-26 9:51 ` Wei Liu
2014-09-03 15:33 ` George Dunlap
2014-09-03 20:52 ` Meng Xu
2014-09-04 14:27 ` George Dunlap
2014-09-04 14:45 ` Dario Faggioli
2014-09-04 14:47 ` Meng Xu
2014-09-04 14:51 ` George Dunlap
2014-09-04 15:07 ` Meng Xu
2014-09-04 15:44 ` Dario Faggioli
2014-09-04 15:55 ` George Dunlap
2014-09-04 16:12 ` Meng Xu
2014-09-05 9:19 ` Dario Faggioli
2014-09-04 15:25 ` Dario Faggioli
2014-09-05 10:21 ` Dario Faggioli
2014-09-05 15:45 ` Meng Xu
2014-09-05 17:41 ` Dario Faggioli
2014-08-24 22:58 ` [PATCH v1 4/4] xl: introduce " Meng Xu
2014-08-25 13:31 ` Wei Liu
2014-08-25 16:12 ` Meng Xu
2014-09-03 15:52 ` George Dunlap
2014-09-03 22:28 ` Meng Xu
2014-09-05 9:40 ` Dario Faggioli
2014-09-05 14:43 ` Meng Xu
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=1408921125-21470-4-git-send-email-mengxu@cis.upenn.edu \
--to=mengxu@cis.upenn.edu \
--cc=JBeulich@suse.com \
--cc=chaowang@wustl.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).