All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Zhiguo <yuzg@cn.fujitsu.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	Keir Fraser <keir.fraser@eu.citrix.com>
Subject: [PATCH] xl: Add subcommand "xl sched-credit"
Date: Fri, 30 Apr 2010 16:26:55 +0800	[thread overview]
Message-ID: <4BDA944F.1040000@cn.fujitsu.com> (raw)

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@cn.fujitsu.com>

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]);

             reply	other threads:[~2010-04-30  8:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-30  8:26 Yu Zhiguo [this message]
2010-04-30 16:51 ` [PATCH] xl: Add subcommand "xl sched-credit" Stefano Stabellini

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=4BDA944F.1040000@cn.fujitsu.com \
    --to=yuzg@cn.fujitsu.com \
    --cc=keir.fraser@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.