[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] xl: Add subcommand "xl sched-credit"
Hi Stefano, Stefano Stabellini wrote: > Hi all, > this is a non comprehensive list of missing features in libxenlight > and\or xl: ...snip... > > - sched-* commands; I add subcommand 'sched-credit', please refer to the following patch. This patch bases changeset 21236:9a1d7caa2024. If it is difficult for you to resolve the conflict, I'll make it against the latest xen-unstable.hg after May Day. ###did some test### # xl list Name ID Mem VCPUs State Time(s) Domain-0 0 1024 2 r-- 34.4 pvguest1 2 256 2 r-- 0.2 # xl sched-credit Name ID Weight Cap Domain-0 0 256 0 pvguest1 2 256 0 # xl sched-credit -d pvguest1 -w 512 -c 100 # xl sched-credit Name ID Weight Cap Domain-0 0 256 0 pvguest1 2 512 100 ###### Regards Yu Zhiguo ----------------------- Subcommand 'sched-credit' is missing now. So add it by this fix. Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx> diff -r 9a1d7caa2024 -r 23a572bb547c tools/libxl/libxl.c --- a/tools/libxl/libxl.c Mon Apr 26 12:13:23 2010 +0100 +++ b/tools/libxl/libxl.c Sat May 01 00:14:09 2010 +0800 @@ -2481,3 +2481,53 @@ 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 9a1d7caa2024 -r 23a572bb547c tools/libxl/libxl.h --- a/tools/libxl/libxl.h Mon Apr 26 12:13:23 2010 +0100 +++ b/tools/libxl/libxl.h Sat May 01 00:14:09 2010 +0800 @@ -459,5 +459,16 @@ 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 9a1d7caa2024 -r 23a572bb547c tools/libxl/xl.c --- a/tools/libxl/xl.c Mon Apr 26 12:13:23 2010 +0100 +++ b/tools/libxl/xl.c Sat May 01 00:14:09 2010 +0800 @@ -1107,6 +1107,7 @@ 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 @@ } 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"); } } @@ -2757,6 +2764,111 @@ 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); +} + int main(int argc, char **argv) { if (argc < 2) { @@ -2819,6 +2931,8 @@ 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-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |