All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter
@ 2010-04-01 16:27 Eric Chanudet
  2010-04-01 16:27 ` [PATCH 1 of 4] xl: vcpu-list command Eric Chanudet
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Chanudet @ 2010-04-01 16:27 UTC (permalink / raw)
  To: xen-devel

This patch series provides the following vcpu control commands to xl:
- vcpu-list: list the VCPUs for all/some domains.
- vcpu-pin: Set which CPUs a VCPU can use.
- vcpu-set: Set the number of active VCPUs allowed for the domain.

Also provides tsc_mode parameter handling from guest configuration file.

-- 
Eric Chanudet

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1 of 4] xl: vcpu-list command
  2010-04-01 16:27 [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter Eric Chanudet
@ 2010-04-01 16:27 ` Eric Chanudet
  2010-04-01 16:27 ` [PATCH 2 of 4] xl: vcpu-pin command Eric Chanudet
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Chanudet @ 2010-04-01 16:27 UTC (permalink / raw)
  To: xen-devel

This patch add vcpu-list command to xl.

Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2221,3 +2221,64 @@ int libxl_button_press(struct libxl_ctx 
 
     return rc;
 }
+
+int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo)
+{
+    xc_physinfo_t xcphysinfo = { 0 };
+    int rc;
+
+    rc = xc_physinfo(ctx->xch, &xcphysinfo);
+    if (rc != 0) {
+        return rc;
+    }
+    physinfo->threads_per_core = xcphysinfo.threads_per_core;
+    physinfo->cores_per_socket = xcphysinfo.cores_per_socket;
+    physinfo->nr_cpus = xcphysinfo.nr_cpus;
+    physinfo->cpu_khz = xcphysinfo.cpu_khz;
+    physinfo->total_pages = xcphysinfo.total_pages;
+    physinfo->free_pages = xcphysinfo.free_pages;
+    physinfo->scrub_pages = xcphysinfo.scrub_pages;
+    return 0;
+}
+
+struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid,
+                                       int *nb_vcpu, int *cpusize)
+{
+    struct libxl_vcpuinfo *ptr, *ret;
+    xc_domaininfo_t domaininfo;
+    xc_vcpuinfo_t vcpuinfo;
+    xc_physinfo_t physinfo = { 0 };
+
+    if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
+        return NULL;
+    }
+    if (xc_physinfo(ctx->xch, &physinfo) == -1) {
+        return NULL;
+    }
+    *cpusize = physinfo.max_cpu_id + 1;
+    ptr = libxl_calloc(ctx, domaininfo.max_vcpu_id + 1, sizeof (struct libxl_vcpuinfo));
+    if (!ptr) {
+        return NULL;
+    }
+
+    ret = ptr;
+    for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
+        ptr->cpumap = libxl_calloc(ctx, (*cpusize + 63) / 64, sizeof (uint64_t));
+        if (!ptr->cpumap) {
+            return NULL;
+        }
+        if (xc_vcpu_getinfo(ctx->xch, domid, *nb_vcpu, &vcpuinfo) == -1) {
+            return NULL;
+        }
+        if (xc_vcpu_getaffinity(ctx->xch, domid, *nb_vcpu, ptr->cpumap, *cpusize) == -1) {
+            return NULL;
+        }
+        ptr->vcpuid = *nb_vcpu;
+        ptr->cpu = vcpuinfo.cpu;
+        ptr->online = !!vcpuinfo.online;
+        ptr->blocked = !!vcpuinfo.blocked;
+        ptr->running = !!vcpuinfo.running;
+        ptr->vcpu_time = vcpuinfo.cpu_time;
+    }
+    return ret;
+}
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -360,5 +360,31 @@ typedef enum {
 
 int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button);
 
+struct libxl_vcpuinfo {
+    uint32_t vcpuid; /* vcpu's id */
+    uint32_t cpu; /* current mapping */
+    uint8_t online:1; /* currently online (not hotplugged)? */
+    uint8_t blocked:1; /* blocked waiting for an event? */
+    uint8_t running:1; /* currently scheduled on its CPU? */
+    uint64_t vcpu_time; /* total vcpu time ran (ns) */
+    uint64_t *cpumap; /* current cpu's affinities */
+};
+
+struct libxl_physinfo {
+    uint32_t threads_per_core;
+    uint32_t cores_per_socket;
+
+    uint32_t nr_cpus;
+    uint32_t cpu_khz;
+
+    uint64_t total_pages;
+    uint64_t free_pages;
+    uint64_t scrub_pages;
+};
+
+int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo);
+struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid,
+                                       int *nb_vcpu, int *cpusize);
+
 #endif /* LIBXL_H */
 
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -876,6 +876,7 @@ static void help(char *command)
         printf(" cd-eject                      eject a cdrom from a guest's cd drive\n\n");
         printf(" mem-set                       set the current memory usage for a domain\n\n");
         printf(" button-press                  indicate an ACPI button press to the domain\n\n");
+        printf(" vcpu-list                     list the VCPUs for all/some domains.\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");
@@ -933,6 +934,9 @@ static void help(char *command)
         printf("Usage: xl button-press <Domain> <Button>\n\n");
         printf("Indicate <Button> press to a domain.\n");
         printf("<Button> may be 'power' or 'sleep'.\n\n");
+    } else if (!strcmp(command, "vcpu-list")) {
+        printf("Usage: xl vcpu-list [Domain, ...]\n\n");
+        printf("List the VCPUs for all/some domains.\n\n");
     }
 }
 
@@ -1721,6 +1725,144 @@ int main_button_press(int argc, char **a
     exit(0);
 }
 
+static void print_vcpuinfo(struct libxl_ctx *ctx, uint32_t domid,
+                           const struct libxl_vcpuinfo *vcpuinfo,
+                           uint32_t nr_cpus)
+{
+    int i, l;
+    uint64_t *cpumap;
+    uint64_t pcpumap;
+
+    /*      NAME  ID  VCPU */
+    printf("%-32s %5u %5u",
+           libxl_domid_to_name(ctx, domid), domid, vcpuinfo->vcpuid);
+    if (!vcpuinfo->online) {
+        /*      CPU STA */
+        printf("%5c %3c%cp ", '-', '-', '-');
+    } else {
+        /*      CPU STA */
+        printf("%5u %3c%c- ", vcpuinfo->cpu,
+               vcpuinfo->running ? 'r' : '-',
+               vcpuinfo->blocked ? 'b' : '-');
+    }
+    /*      TIM */
+    printf("%9.1f  ", ((float)vcpuinfo->vcpu_time / 1e9));
+    /* CPU AFFINITY */
+    pcpumap = nr_cpus > 64 ? -1 : ((1 << nr_cpus) - 1);
+    for (cpumap = vcpuinfo->cpumap; nr_cpus; ++cpumap) {
+        if (*cpumap < pcpumap) {
+            break;
+        }
+        if (nr_cpus > 64) {
+            pcpumap = -1;
+            nr_cpus -= 64;
+        } else {
+            pcpumap = ((1 << nr_cpus) - 1);
+            nr_cpus = 0;
+        }
+    }
+    if (!nr_cpus) {
+        printf("any cpu\n");
+    } else {
+        for (cpumap = vcpuinfo->cpumap; nr_cpus; ++cpumap) {
+            pcpumap = *cpumap;
+            for (i = 0; !(pcpumap & 1); ++i, pcpumap >>= 1)
+                ;
+            printf("%u", i);
+            for (l = i, pcpumap = (pcpumap >> 1); (pcpumap & 1); ++i, pcpumap >>= 1)
+                ;
+            if (l < i) {
+                printf("-%u", i);
+            }
+            for (++i; pcpumap; ++i, pcpumap >>= 1) {
+                if (pcpumap & 1) {
+                    printf(",%u", i);
+                    for (l = i, pcpumap = (pcpumap >> 1); (pcpumap & 1); ++i, pcpumap >>= 1)
+                        ;
+                    if (l < i) {
+                        printf("-%u", i);
+                    }
+                    ++i;
+                }
+            }
+            printf("\n");
+            nr_cpus = nr_cpus > 64 ? nr_cpus - 64 : 0;
+        }
+    }
+}
+
+void vcpulist(int argc, char **argv)
+{
+    struct libxl_ctx ctx;
+    struct libxl_dominfo *dominfo;
+    uint32_t domid;
+    struct libxl_vcpuinfo *vcpuinfo;
+    struct libxl_physinfo physinfo;
+    int nb_vcpu, nb_domain, cpusize;
+
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (libxl_get_physinfo(&ctx, &physinfo) != 0) {
+        fprintf(stderr, "libxl_physinfo failed.\n");
+        goto vcpulist_out;
+    }
+    printf("%-32s %5s %5s %5s %5s %9s %s\n",
+           "Name", "ID", "VCPU", "CPU", "State", "Time(s)", "CPU Affinity");
+    if (!argc) {
+        if (!(dominfo = libxl_list_domain(&ctx, &nb_domain))) {
+            fprintf(stderr, "libxl_list_domain failed.\n");
+            goto vcpulist_out;
+        }
+        for (; nb_domain > 0; --nb_domain, ++dominfo) {
+            if (!(vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu, &cpusize))) {
+                fprintf(stderr, "libxl_list_vcpu failed.\n");
+                goto vcpulist_out;
+            }
+            for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
+                print_vcpuinfo(&ctx, dominfo->domid, vcpuinfo, physinfo.nr_cpus);
+            }
+        }
+    } else {
+        for (; argc > 0; ++argv, --argc) {
+            if (domain_qualifier_to_domid(&ctx, *argv, &domid) < 0) {
+                fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
+            }
+            if (!(vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &cpusize))) {
+                fprintf(stderr, "libxl_list_vcpu failed.\n");
+                goto vcpulist_out;
+            }
+            for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
+                print_vcpuinfo(&ctx, domid, vcpuinfo, physinfo.nr_cpus);
+            }
+        }
+    }
+  vcpulist_out:
+    libxl_ctx_free(&ctx);
+}
+
+void main_vcpulist(int argc, char **argv)
+{
+    int opt;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("vcpu-list");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    vcpulist(argc - 1, argv + 1);
+    exit(0);
+}
+
 int main(int argc, char **argv)
 {
     if (argc < 2) {
@@ -1762,6 +1904,8 @@ int main(int argc, char **argv)
         main_memset(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "button-press")) {
         main_button_press(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "vcpu-list")) {
+        main_vcpulist(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "help")) {
         if (argc > 2)
             help(argv[2]);
@@ -1773,4 +1917,3 @@ int main(int argc, char **argv)
         exit(1);
     }
 }
-

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2 of 4] xl: vcpu-pin command
  2010-04-01 16:27 [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter Eric Chanudet
  2010-04-01 16:27 ` [PATCH 1 of 4] xl: vcpu-list command Eric Chanudet
@ 2010-04-01 16:27 ` Eric Chanudet
  2010-04-01 16:27 ` [PATCH 3 of 4] xl: vcpu-set command Eric Chanudet
  2010-04-01 16:27 ` [PATCH 4 of 4] xl: tsc_mode parameter in guest configuration file Eric Chanudet
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Chanudet @ 2010-04-01 16:27 UTC (permalink / raw)
  To: xen-devel

This patch add vcpu-pin command to xl.

Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2233,6 +2233,7 @@ int libxl_get_physinfo(struct libxl_ctx 
     }
     physinfo->threads_per_core = xcphysinfo.threads_per_core;
     physinfo->cores_per_socket = xcphysinfo.cores_per_socket;
+    physinfo->max_cpu_id = xcphysinfo.max_cpu_id;
     physinfo->nr_cpus = xcphysinfo.nr_cpus;
     physinfo->cpu_khz = xcphysinfo.cpu_khz;
     physinfo->total_pages = xcphysinfo.total_pages;
@@ -2282,3 +2283,9 @@ struct libxl_vcpuinfo *libxl_list_vcpu(s
     }
     return ret;
 }
+
+int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
+                           uint64_t *cpumap, int cpusize)
+{
+    return (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize));
+}
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -374,6 +374,7 @@ struct libxl_physinfo {
     uint32_t threads_per_core;
     uint32_t cores_per_socket;
 
+    uint32_t max_cpu_id;
     uint32_t nr_cpus;
     uint32_t cpu_khz;
 
@@ -385,6 +386,7 @@ struct libxl_physinfo {
 int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo);
 struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid,
                                        int *nb_vcpu, int *cpusize);
-
+int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
+                           uint64_t *cpumap, int cpusize);
 #endif /* LIBXL_H */
 
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -877,6 +877,7 @@ static void help(char *command)
         printf(" mem-set                       set the current memory usage for a domain\n\n");
         printf(" button-press                  indicate an ACPI button press to the domain\n\n");
         printf(" vcpu-list                     list the VCPUs for all/some domains.\n\n");
+        printf(" vcpu-pin                      Set which CPUs a VCPU can use.\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");
@@ -937,6 +938,9 @@ static void help(char *command)
     } else if (!strcmp(command, "vcpu-list")) {
         printf("Usage: xl vcpu-list [Domain, ...]\n\n");
         printf("List the VCPUs for all/some domains.\n\n");
+    } else if (!strcmp(command, "vcpu-pin")) {
+        printf("Usage: xl vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n\n");
+        printf("Set which CPUs a VCPU can use.\n\n");
     }
 }
 
@@ -1863,6 +1867,119 @@ void main_vcpulist(int argc, char **argv
     exit(0);
 }
 
+void vcpupin(char *d, const char *vcpu, char *cpu)
+{
+    struct libxl_ctx ctx;
+    struct libxl_vcpuinfo *vcpuinfo;
+    struct libxl_physinfo physinfo;
+    uint64_t *cpumap = NULL;
+
+    uint32_t domid, vcpuid, cpuida, cpuidb;
+    char *endptr, *toka, *tokb;
+    int i, nb_vcpu, cpusize;
+
+    vcpuid = strtoul(vcpu, &endptr, 10);
+    if (vcpu == endptr) {
+        if (strcmp(vcpu, "all")) {
+            fprintf(stderr, "Error: Invalid argument.\n");
+            return;
+        }
+        vcpuid = -1;
+    }
+
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (domain_qualifier_to_domid(&ctx, d, &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", d);
+        goto vcpupin_out1;
+    }
+    if (libxl_get_physinfo(&ctx, &physinfo) != 0) {
+        fprintf(stderr, "libxl_get_physinfo failed.\n");
+        goto vcpupin_out1;
+    }
+
+    cpumap = calloc(physinfo.max_cpu_id + 1, sizeof (uint64_t));
+    if (!cpumap) {
+        goto vcpupin_out1;
+    }
+    if (strcmp(cpu, "all")) {
+        for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) {
+            cpuida = strtoul(toka, &endptr, 10);
+            if (toka == endptr) {
+                fprintf(stderr, "Error: Invalid argument.\n");
+                goto vcpupin_out;
+            }
+            if (*endptr == '-') {
+                tokb = endptr + 1;
+                cpuidb = strtoul(tokb, &endptr, 10);
+                if ((tokb == endptr) || (cpuida > cpuidb)) {
+                    fprintf(stderr, "Error: Invalid argument.\n");
+                    goto vcpupin_out;
+                }
+                while (cpuida <= cpuidb) {
+                    cpumap[cpuida / 64] |= (1 << (cpuida % 64));
+                    ++cpuida;
+                }
+            } else {
+                cpumap[cpuida / 64] |= (1 << (cpuida % 64));
+            }
+        }
+    }
+    else {
+        memset(cpumap, -1, sizeof (uint64_t) * (physinfo.max_cpu_id + 1));
+    }
+
+    if (vcpuid != -1) {
+        if (libxl_set_vcpuaffinity(&ctx, domid, vcpuid,
+                                   cpumap, physinfo.max_cpu_id + 1) == -1) {
+            fprintf(stderr, "Could not set affinity for vcpu `%u'.\n", vcpuid);
+        }
+    }
+    else {
+        if (!(vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &cpusize))) {
+            fprintf(stderr, "libxl_list_vcpu failed.\n");
+            goto vcpupin_out;
+        }
+        for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
+            if (libxl_set_vcpuaffinity(&ctx, domid, vcpuinfo->vcpuid,
+                                       cpumap, physinfo.max_cpu_id + 1) == -1) {
+                fprintf(stderr, "libxl_list_vcpu failed on vcpu `%u'.\n", vcpuinfo->vcpuid);
+            }
+        }
+    }
+  vcpupin_out1:
+    free(cpumap);
+  vcpupin_out:
+    libxl_ctx_free(&ctx);
+}
+
+int main_vcpupin(int argc, char **argv)
+{
+    int opt;
+
+    if (argc != 4) {
+        help("vcpu-pin");
+        exit(0);
+    }
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("vcpu-pin");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    vcpupin(argv[1], argv[2] , argv[3]);
+    exit(0);
+}
+
 int main(int argc, char **argv)
 {
     if (argc < 2) {
@@ -1906,6 +2023,8 @@ int main(int argc, char **argv)
         main_button_press(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "vcpu-list")) {
         main_vcpulist(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "vcpu-pin")) {
+        main_vcpupin(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "help")) {
         if (argc > 2)
             help(argv[2]);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3 of 4] xl: vcpu-set command
  2010-04-01 16:27 [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter Eric Chanudet
  2010-04-01 16:27 ` [PATCH 1 of 4] xl: vcpu-list command Eric Chanudet
  2010-04-01 16:27 ` [PATCH 2 of 4] xl: vcpu-pin command Eric Chanudet
@ 2010-04-01 16:27 ` Eric Chanudet
  2010-04-01 16:27 ` [PATCH 4 of 4] xl: tsc_mode parameter in guest configuration file Eric Chanudet
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Chanudet @ 2010-04-01 16:27 UTC (permalink / raw)
  To: xen-devel

This patch add vcpu-set command to xl.

Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2289,3 +2289,26 @@ int libxl_set_vcpuaffinity(struct libxl_
 {
     return (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize));
 }
+
+int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count)
+{
+    xc_domaininfo_t domaininfo;
+    char *dompath;
+    int i;
+
+    if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
+        return ERROR_FAIL;
+    }
+    if (!count || ((domaininfo.max_vcpu_id + 1) < count)) {
+        return ERROR_INVAL;
+    }
+    if (!(dompath = libxl_xs_get_dompath(ctx, domid)))
+        return ERROR_FAIL;
+
+    for (i = 0; i <= domaininfo.max_vcpu_id; ++i) {
+        libxl_xs_write(ctx, XBT_NULL,
+                       libxl_sprintf(ctx, "%s/cpu/%u/availability", dompath, i),
+                       "%s", ((1 << i) & ((1 << count) - 1)) ? "online" : "offline");
+    }
+    return 0;
+}
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -388,5 +388,6 @@ struct libxl_vcpuinfo *libxl_list_vcpu(s
                                        int *nb_vcpu, int *cpusize);
 int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
                            uint64_t *cpumap, int cpusize);
+int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count);
 #endif /* LIBXL_H */
 
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -878,6 +878,7 @@ static void help(char *command)
         printf(" button-press                  indicate an ACPI button press to the domain\n\n");
         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");
     } else if(!strcmp(command, "create")) {
         printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
         printf("Create a domain based on <ConfigFile>.\n\n");
@@ -941,6 +942,9 @@ static void help(char *command)
     } else if (!strcmp(command, "vcpu-pin")) {
         printf("Usage: xl vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n\n");
         printf("Set which CPUs a VCPU can use.\n\n");
+    } 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");
     }
 }
 
@@ -1980,6 +1984,60 @@ int main_vcpupin(int argc, char **argv)
     exit(0);
 }
 
+void vcpuset(char *d, char* nr_vcpus)
+{
+    struct libxl_ctx ctx;
+    char *endptr;
+    uint32_t domid;
+    unsigned int max_vcpus;
+
+    max_vcpus = strtoul(nr_vcpus, &endptr, 10);
+    if (nr_vcpus == endptr) {
+        fprintf(stderr, "Error: Invalid argument.\n");
+        return;
+    }
+
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (domain_qualifier_to_domid(&ctx, d, &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", d);
+        goto vcpuset_out;
+    }
+    if (libxl_set_vcpucount(&ctx, domid, max_vcpus) == ERROR_INVAL) {
+        fprintf(stderr, "Error: Cannot set vcpus greater than max vcpus on running domain or lesser than 1.\n");
+    }
+
+  vcpuset_out:
+    libxl_ctx_free(&ctx);
+}
+
+int main_vcpuset(int argc, char **argv)
+{
+    int opt;
+
+    if (argc != 3) {
+        help("vcpu-set");
+        exit(0);
+    }
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+        help("vcpu-set");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    vcpuset(argv[1], argv[2]);
+    exit(0);
+}
+
 int main(int argc, char **argv)
 {
     if (argc < 2) {
@@ -2025,6 +2083,8 @@ int main(int argc, char **argv)
         main_vcpulist(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "vcpu-pin")) {
         main_vcpupin(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "vcpu-set")) {
+        main_vcpuset(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "help")) {
         if (argc > 2)
             help(argv[2]);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4 of 4] xl: tsc_mode parameter in guest configuration file
  2010-04-01 16:27 [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter Eric Chanudet
                   ` (2 preceding siblings ...)
  2010-04-01 16:27 ` [PATCH 3 of 4] xl: vcpu-set command Eric Chanudet
@ 2010-04-01 16:27 ` Eric Chanudet
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Chanudet @ 2010-04-01 16:27 UTC (permalink / raw)
  To: xen-devel

This patch handle tsc_mode argument in guest configuration file.

Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -74,6 +74,7 @@ typedef struct {
     int vpt_align;
     int max_vcpus;
     int cur_vcpus;
+    int tsc_mode;
     uint32_t max_memkb;
     uint32_t target_memkb;
     uint32_t video_memkb;
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -72,6 +72,7 @@ int build_pre(struct libxl_ctx *ctx, uin
     xc_domain_set_memmap_limit(ctx->xch, domid, 
             (info->hvm) ? info->max_memkb : 
             (info->max_memkb + info->u.pv.slack_memkb));
+    xc_domain_set_tsc_info(ctx->xch, domid, info->tsc_mode, 0, 0, 0);
 
     if (info->hvm) {
         unsigned long shadow;
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -235,6 +235,7 @@ static void printf_info(libxl_domain_cre
     printf("hpet: %d\n", b_info->hpet);
     printf("vpt_align: %d\n", b_info->vpt_align);
     printf("max_vcpus: %d\n", b_info->max_vcpus);
+    printf("tsc_mode: %d\n", b_info->tsc_mode);
     printf("max_memkb: %d\n", b_info->max_memkb);
     printf("target_memkb: %d\n", b_info->target_memkb);
     printf("kernel: %s\n", b_info->kernel);
@@ -382,6 +383,9 @@ static void parse_config_file(const char
         b_info->target_memkb = b_info->max_memkb;
     }
 
+    if (!xlu_cfg_get_long(config, "tsc_mode", &l))
+        b_info->tsc_mode = l;
+
     if (!xlu_cfg_get_long (config, "shadow_memory", &l))
         b_info->shadow_memkb = l * 1024;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-04-01 16:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-01 16:27 [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter Eric Chanudet
2010-04-01 16:27 ` [PATCH 1 of 4] xl: vcpu-list command Eric Chanudet
2010-04-01 16:27 ` [PATCH 2 of 4] xl: vcpu-pin command Eric Chanudet
2010-04-01 16:27 ` [PATCH 3 of 4] xl: vcpu-set command Eric Chanudet
2010-04-01 16:27 ` [PATCH 4 of 4] xl: tsc_mode parameter in guest configuration file Eric Chanudet

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.