debuggers.hg

changeset 21292:3e5383b537c5

xl: Add subcommand "xl sched-credit"

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 04 11:09:32 2010 +0100 (2010-05-04)
parents 80aef59e8c8e
children 742311878ae5
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Tue May 04 11:07:06 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Tue May 04 11:09:32 2010 +0100
     1.3 @@ -2474,3 +2474,53 @@ int libxl_get_sched_id(struct libxl_ctx 
     1.4          return ret;
     1.5      return sched;
     1.6  }
     1.7 +
     1.8 +int libxl_sched_credit_domain_get(struct libxl_ctx *ctx, uint32_t domid, struct libxl_sched_credit *scinfo)
     1.9 +{
    1.10 +    struct xen_domctl_sched_credit sdom;
    1.11 +    int rc;
    1.12 +
    1.13 +    rc = xc_sched_credit_domain_get(ctx->xch, domid, &sdom);
    1.14 +    if (rc != 0)
    1.15 +        return rc;
    1.16 +
    1.17 +    scinfo->weight = sdom.weight;
    1.18 +    scinfo->cap = sdom.cap;
    1.19 +
    1.20 +    return 0;
    1.21 +}
    1.22 +
    1.23 +int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid, struct libxl_sched_credit *scinfo)
    1.24 +{
    1.25 +    struct xen_domctl_sched_credit sdom;
    1.26 +    xc_domaininfo_t domaininfo;
    1.27 +    int rc;
    1.28 +
    1.29 +    rc = xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo);
    1.30 +    if (rc != 1 || domaininfo.domain != domid)
    1.31 +        return rc;
    1.32 +
    1.33 +
    1.34 +    if (scinfo->weight < 1 || scinfo->weight > 65535) {
    1.35 +        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc,
    1.36 +            "Cpu weight out of range, valid values are within range from 1 to 65535");
    1.37 +        return -1;
    1.38 +    }
    1.39 +
    1.40 +    if (scinfo->cap < 0 || scinfo->cap > (domaininfo.max_vcpu_id + 1) * 100) {
    1.41 +        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc,
    1.42 +            "Cpu cap out of range, valid range is from 0 to %d for specified number of vcpus",
    1.43 +            ((domaininfo.max_vcpu_id + 1) * 100));
    1.44 +        return -1;
    1.45 +    }
    1.46 +
    1.47 +    sdom.weight = scinfo->weight;
    1.48 +    sdom.cap = scinfo->cap;
    1.49 +
    1.50 +    rc = xc_sched_credit_domain_set(ctx->xch, domid, &sdom);
    1.51 +    if (rc != 0)
    1.52 +        return rc;
    1.53 +
    1.54 +    return 0;
    1.55 +}
    1.56 +
     2.1 --- a/tools/libxl/libxl.h	Tue May 04 11:07:06 2010 +0100
     2.2 +++ b/tools/libxl/libxl.h	Tue May 04 11:09:32 2010 +0100
     2.3 @@ -459,5 +459,16 @@ int libxl_set_vcpuaffinity(struct libxl_
     2.4  int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count);
     2.5  
     2.6  int libxl_get_sched_id(struct libxl_ctx *ctx);
     2.7 +
     2.8 +
     2.9 +struct libxl_sched_credit {
    2.10 +    int weight;
    2.11 +    int cap;
    2.12 +};
    2.13 +
    2.14 +int libxl_sched_credit_domain_get(struct libxl_ctx *ctx, uint32_t domid,
    2.15 +                                  struct libxl_sched_credit *scinfo);
    2.16 +int libxl_sched_credit_domain_set(struct libxl_ctx *ctx, uint32_t domid,
    2.17 +                                  struct libxl_sched_credit *scinfo);
    2.18  #endif /* LIBXL_H */
    2.19  
     3.1 --- a/tools/libxl/xl.c	Tue May 04 11:07:06 2010 +0100
     3.2 +++ b/tools/libxl/xl.c	Tue May 04 11:09:32 2010 +0100
     3.3 @@ -1107,6 +1107,7 @@ static void help(char *command)
     3.4          printf(" vcpu-list                     list the VCPUs for all/some domains.\n\n");
     3.5          printf(" vcpu-pin                      Set which CPUs a VCPU can use.\n\n");
     3.6          printf(" vcpu-set                      Set the number of active VCPUs allowed for the domain.\n\n");
     3.7 +        printf(" sched-credit                  Get/set credit scheduler parameters.\n\n");
     3.8      } else if(!strcmp(command, "create")) {
     3.9          printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
    3.10          printf("Create a domain based on <ConfigFile>.\n\n");
    3.11 @@ -1193,6 +1194,12 @@ static void help(char *command)
    3.12      } else if (!strcmp(command, "vcpu-set")) {
    3.13          printf("Usage: xl vcpu-set <Domain> <vCPUs>\n\n");
    3.14          printf("Set the number of active VCPUs for allowed for the domain.\n\n");
    3.15 +    } else if (!strcmp(command, "sched-credit")) {
    3.16 +        printf("Usage: xl sched-credit [-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]\n\n");
    3.17 +        printf("Get/set credit scheduler parameters.\n");
    3.18 +        printf("  -d DOMAIN, --domain=DOMAIN     Domain to modify\n");
    3.19 +        printf("  -w WEIGHT, --weight=WEIGHT     Weight (int)\n");
    3.20 +        printf("  -c CAP, --cap=CAP              Cap (int)\n");
    3.21      }
    3.22  }
    3.23  
    3.24 @@ -2757,6 +2764,111 @@ void main_info(int argc, char **argv)
    3.25      exit(0);
    3.26  }
    3.27  
    3.28 +int sched_credit_domain_get(int domid, struct libxl_sched_credit *scinfo)
    3.29 +{
    3.30 +    int rc;
    3.31 +
    3.32 +    rc = libxl_sched_credit_domain_get(&ctx, domid, scinfo);
    3.33 +    if (rc)
    3.34 +        fprintf(stderr, "libxl_sched_credit_domain_get failed.\n");
    3.35 +    
    3.36 +    return rc;
    3.37 +}
    3.38 +
    3.39 +int sched_credit_domain_set(int domid, struct libxl_sched_credit *scinfo)
    3.40 +{
    3.41 +    int rc;
    3.42 +
    3.43 +    rc = libxl_sched_credit_domain_set(&ctx, domid, scinfo);
    3.44 +    if (rc)
    3.45 +        fprintf(stderr, "libxl_sched_credit_domain_set failed.\n");
    3.46 +
    3.47 +    return rc;
    3.48 +}
    3.49 +
    3.50 +void sched_credit_domain_output(int domid, struct libxl_sched_credit *scinfo)
    3.51 +{
    3.52 +    printf("%-33s %4d %6d %4d\n",
    3.53 +        libxl_domid_to_name(&ctx, domid),
    3.54 +        domid,
    3.55 +        scinfo->weight,
    3.56 +        scinfo->cap);
    3.57 +}
    3.58 +
    3.59 +void main_sched_credit(int argc, char **argv)
    3.60 +{
    3.61 +    struct libxl_dominfo *info;
    3.62 +    struct libxl_sched_credit scinfo;
    3.63 +    int nb_domain, i;
    3.64 +    char *dom = NULL;
    3.65 +    int weight = 256, cap = 0, opt_w = 0, opt_c = 0;
    3.66 +    int opt, rc;
    3.67 +
    3.68 +    while ((opt = getopt(argc, argv, "hd:w:c:")) != -1) {
    3.69 +        switch (opt) {
    3.70 +        case 'd':
    3.71 +            dom = optarg;
    3.72 +            break;
    3.73 +        case 'w':
    3.74 +            weight = strtol(optarg, NULL, 10);
    3.75 +            opt_w = 1;
    3.76 +            break;
    3.77 +        case 'c':
    3.78 +            cap = strtol(optarg, NULL, 10);
    3.79 +            opt_c = 1;
    3.80 +            break;
    3.81 +        case 'h':
    3.82 +            help("sched-credit");
    3.83 +            exit(0);
    3.84 +        default:
    3.85 +            fprintf(stderr, "option `%c' not supported.\n", opt);
    3.86 +            break;
    3.87 +        }
    3.88 +    }
    3.89 +
    3.90 +    if (!dom && (opt_w || opt_c)) {
    3.91 +        fprintf(stderr, "Must specify a domain.\n");
    3.92 +        exit(1);
    3.93 +    }
    3.94 +
    3.95 +    if (!dom) { /* list all domain's credit scheduler info */
    3.96 +        info = libxl_list_domain(&ctx, &nb_domain);
    3.97 +        if (!info) {
    3.98 +            fprintf(stderr, "libxl_domain_infolist failed.\n");
    3.99 +            exit(1);
   3.100 +        }
   3.101 +
   3.102 +        printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
   3.103 +        for (i = 0; i < nb_domain; i++) {
   3.104 +            rc = sched_credit_domain_get(info[i].domid, &scinfo);
   3.105 +            if (rc)
   3.106 +                exit(-rc);
   3.107 +            sched_credit_domain_output(info[i].domid, &scinfo);
   3.108 +        }
   3.109 +    } else {
   3.110 +        find_domain(dom);
   3.111 +
   3.112 +        rc = sched_credit_domain_get(domid, &scinfo);
   3.113 +        if (rc)
   3.114 +            exit(-rc);
   3.115 +
   3.116 +        if (!opt_w && !opt_c) { /* output credit scheduler info */
   3.117 +            printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
   3.118 +            sched_credit_domain_output(domid, &scinfo);
   3.119 +        } else { /* set credit scheduler paramaters */
   3.120 +            if (opt_w)
   3.121 +                scinfo.weight = weight;
   3.122 +            if (opt_c)
   3.123 +                scinfo.cap = cap;
   3.124 +            rc = sched_credit_domain_set(domid, &scinfo);
   3.125 +            if (rc)
   3.126 +                exit(-rc);
   3.127 +        }
   3.128 +    }
   3.129 +
   3.130 +    exit(0);
   3.131 +}
   3.132 +
   3.133  int main(int argc, char **argv)
   3.134  {
   3.135      if (argc < 2) {
   3.136 @@ -2819,6 +2931,8 @@ int main(int argc, char **argv)
   3.137          main_vcpuset(argc - 1, argv + 1);
   3.138      } else if (!strcmp(argv[1], "info")) {
   3.139          main_info(argc - 1, argv + 1);
   3.140 +    } else if (!strcmp(argv[1], "sched-credit")) {
   3.141 +        main_sched_credit(argc - 1, argv + 1);
   3.142      } else if (!strcmp(argv[1], "help")) {
   3.143          if (argc > 2)
   3.144              help(argv[2]);