# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1272967772 -3600
# Node ID 3e5383b537c5d05634cabca0026a46037cd54067
# Parent 80aef59e8c8e86082e85338eea081d7deb112df7
xl: Add subcommand "xl sched-credit"
Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>
Acked-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
tools/libxl/libxl.c | 50 ++++++++++++++++++++++
tools/libxl/libxl.h | 11 +++++
tools/libxl/xl.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 175 insertions(+)
diff -r 80aef59e8c8e -r 3e5383b537c5 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue May 04 11:07:06 2010 +0100
+++ b/tools/libxl/libxl.c Tue May 04 11:09:32 2010 +0100
@@ -2474,3 +2474,53 @@ int libxl_get_sched_id(struct libxl_ctx
return ret;
return sched;
}
+
+int libxl_sched_credit_domain_get(struct libxl_ctx *ctx, uint32_t domid,
struct libxl_sched_credit *scinfo)
+{
+ struct xen_domctl_sched_credit sdom;
+ int rc;
+
+ rc = xc_sched_credit_domain_get(ctx->xch, domid, &sdom);
+ if (rc != 0)
+ return rc;
+
+ scinfo->weight = sdom.weight;
+ scinfo->cap = sdom.cap;
+
+ return 0;
+}
+
+int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid,
struct libxl_sched_credit *scinfo)
+{
+ struct xen_domctl_sched_credit sdom;
+ xc_domaininfo_t domaininfo;
+ int rc;
+
+ rc = xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo);
+ if (rc != 1 || domaininfo.domain != domid)
+ return rc;
+
+
+ if (scinfo->weight < 1 || scinfo->weight > 65535) {
+ XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc,
+ "Cpu weight out of range, valid values are within range from 1 to
65535");
+ return -1;
+ }
+
+ if (scinfo->cap < 0 || scinfo->cap > (domaininfo.max_vcpu_id + 1) * 100) {
+ XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc,
+ "Cpu cap out of range, valid range is from 0 to %d for specified
number of vcpus",
+ ((domaininfo.max_vcpu_id + 1) * 100));
+ return -1;
+ }
+
+ sdom.weight = scinfo->weight;
+ sdom.cap = scinfo->cap;
+
+ rc = xc_sched_credit_domain_set(ctx->xch, domid, &sdom);
+ if (rc != 0)
+ return rc;
+
+ return 0;
+}
+
diff -r 80aef59e8c8e -r 3e5383b537c5 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Tue May 04 11:07:06 2010 +0100
+++ b/tools/libxl/libxl.h Tue May 04 11:09:32 2010 +0100
@@ -459,5 +459,16 @@ int libxl_set_vcpucount(struct libxl_ctx
int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count);
int libxl_get_sched_id(struct libxl_ctx *ctx);
+
+
+struct libxl_sched_credit {
+ int weight;
+ int cap;
+};
+
+int libxl_sched_credit_domain_get(struct libxl_ctx *ctx, uint32_t domid,
+ struct libxl_sched_credit *scinfo);
+int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid,
+ struct libxl_sched_credit *scinfo);
#endif /* LIBXL_H */
diff -r 80aef59e8c8e -r 3e5383b537c5 tools/libxl/xl.c
--- a/tools/libxl/xl.c Tue May 04 11:07:06 2010 +0100
+++ b/tools/libxl/xl.c Tue May 04 11:09:32 2010 +0100
@@ -1107,6 +1107,7 @@ static void help(char *command)
printf(" vcpu-list list the VCPUs for all/some
domains.\n\n");
printf(" vcpu-pin Set which CPUs a VCPU can
use.\n\n");
printf(" vcpu-set Set the number of active VCPUs
allowed for the domain.\n\n");
+ printf(" sched-credit Get/set credit scheduler
parameters.\n\n");
} else if(!strcmp(command, "create")) {
printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
printf("Create a domain based on <ConfigFile>.\n\n");
@@ -1193,6 +1194,12 @@ static void help(char *command)
} else if (!strcmp(command, "vcpu-set")) {
printf("Usage: xl vcpu-set <Domain> <vCPUs>\n\n");
printf("Set the number of active VCPUs for allowed for the
domain.\n\n");
+ } else if (!strcmp(command, "sched-credit")) {
+ printf("Usage: xl sched-credit [-d <Domain>
[-w[=WEIGHT]|-c[=CAP]]]\n\n");
+ printf("Get/set credit scheduler parameters.\n");
+ printf(" -d DOMAIN, --domain=DOMAIN Domain to modify\n");
+ printf(" -w WEIGHT, --weight=WEIGHT Weight (int)\n");
+ printf(" -c CAP, --cap=CAP Cap (int)\n");
}
}
@@ -2754,6 +2761,111 @@ void main_info(int argc, char **argv)
}
info(verbose);
+ exit(0);
+}
+
+int sched_credit_domain_get(int domid, struct libxl_sched_credit *scinfo)
+{
+ int rc;
+
+ rc = libxl_sched_credit_domain_get(&ctx, domid, scinfo);
+ if (rc)
+ fprintf(stderr, "libxl_sched_credit_domain_get failed.\n");
+
+ return rc;
+}
+
+int sched_credit_domain_set(int domid, struct libxl_sched_credit *scinfo)
+{
+ int rc;
+
+ rc = libxl_sched_credit_domain_set(&ctx, domid, scinfo);
+ if (rc)
+ fprintf(stderr, "libxl_sched_credit_domain_set failed.\n");
+
+ return rc;
+}
+
+void sched_credit_domain_output(int domid, struct libxl_sched_credit *scinfo)
+{
+ printf("%-33s %4d %6d %4d\n",
+ libxl_domid_to_name(&ctx, domid),
+ domid,
+ scinfo->weight,
+ scinfo->cap);
+}
+
+void main_sched_credit(int argc, char **argv)
+{
+ struct libxl_dominfo *info;
+ struct libxl_sched_credit scinfo;
+ int nb_domain, i;
+ char *dom = NULL;
+ int weight = 256, cap = 0, opt_w = 0, opt_c = 0;
+ int opt, rc;
+
+ while ((opt = getopt(argc, argv, "hd:w:c:")) != -1) {
+ switch (opt) {
+ case 'd':
+ dom = optarg;
+ break;
+ case 'w':
+ weight = strtol(optarg, NULL, 10);
+ opt_w = 1;
+ break;
+ case 'c':
+ cap = strtol(optarg, NULL, 10);
+ opt_c = 1;
+ break;
+ case 'h':
+ help("sched-credit");
+ exit(0);
+ default:
+ fprintf(stderr, "option `%c' not supported.\n", opt);
+ break;
+ }
+ }
+
+ if (!dom && (opt_w || opt_c)) {
+ fprintf(stderr, "Must specify a domain.\n");
+ exit(1);
+ }
+
+ if (!dom) { /* list all domain's credit scheduler info */
+ info = libxl_list_domain(&ctx, &nb_domain);
+ if (!info) {
+ fprintf(stderr, "libxl_domain_infolist failed.\n");
+ exit(1);
+ }
+
+ printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
+ for (i = 0; i < nb_domain; i++) {
+ rc = sched_credit_domain_get(info[i].domid, &scinfo);
+ if (rc)
+ exit(-rc);
+ sched_credit_domain_output(info[i].domid, &scinfo);
+ }
+ } else {
+ find_domain(dom);
+
+ rc = sched_credit_domain_get(domid, &scinfo);
+ if (rc)
+ exit(-rc);
+
+ if (!opt_w && !opt_c) { /* output credit scheduler info */
+ printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
+ sched_credit_domain_output(domid, &scinfo);
+ } else { /* set credit scheduler paramaters */
+ if (opt_w)
+ scinfo.weight = weight;
+ if (opt_c)
+ scinfo.cap = cap;
+ rc = sched_credit_domain_set(domid, &scinfo);
+ if (rc)
+ exit(-rc);
+ }
+ }
+
exit(0);
}
@@ -2819,6 +2931,8 @@ int main(int argc, char **argv)
main_vcpuset(argc - 1, argv + 1);
} else if (!strcmp(argv[1], "info")) {
main_info(argc - 1, argv + 1);
+ } else if (!strcmp(argv[1], "sched-credit")) {
+ main_sched_credit(argc - 1, argv + 1);
} else if (!strcmp(argv[1], "help")) {
if (argc > 2)
help(argv[2]);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|