debuggers.hg
changeset 21142:98e7aff6ee19
xl: vcpu-pin command
Signed-off-by: Eric Chanudet <eric.chanudet@citrix.com>
Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Eric Chanudet <eric.chanudet@citrix.com>
Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Apr 06 06:54:51 2010 +0100 (2010-04-06) |
parents | fe30bd463e84 |
children | 29f271d3ceec |
files | tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/xl.c |
line diff
1.1 --- a/tools/libxl/libxl.c Tue Apr 06 06:54:08 2010 +0100 1.2 +++ b/tools/libxl/libxl.c Tue Apr 06 06:54:51 2010 +0100 1.3 @@ -2233,6 +2233,7 @@ int libxl_get_physinfo(struct libxl_ctx 1.4 } 1.5 physinfo->threads_per_core = xcphysinfo.threads_per_core; 1.6 physinfo->cores_per_socket = xcphysinfo.cores_per_socket; 1.7 + physinfo->max_cpu_id = xcphysinfo.max_cpu_id; 1.8 physinfo->nr_cpus = xcphysinfo.nr_cpus; 1.9 physinfo->cpu_khz = xcphysinfo.cpu_khz; 1.10 physinfo->total_pages = xcphysinfo.total_pages; 1.11 @@ -2282,3 +2283,9 @@ struct libxl_vcpuinfo *libxl_list_vcpu(s 1.12 } 1.13 return ret; 1.14 } 1.15 + 1.16 +int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, 1.17 + uint64_t *cpumap, int cpusize) 1.18 +{ 1.19 + return (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize)); 1.20 +}
2.1 --- a/tools/libxl/libxl.h Tue Apr 06 06:54:08 2010 +0100 2.2 +++ b/tools/libxl/libxl.h Tue Apr 06 06:54:51 2010 +0100 2.3 @@ -374,6 +374,7 @@ struct libxl_physinfo { 2.4 uint32_t threads_per_core; 2.5 uint32_t cores_per_socket; 2.6 2.7 + uint32_t max_cpu_id; 2.8 uint32_t nr_cpus; 2.9 uint32_t cpu_khz; 2.10 2.11 @@ -385,6 +386,7 @@ struct libxl_physinfo { 2.12 int libxl_get_physinfo(struct libxl_ctx *ctx, struct libxl_physinfo *physinfo); 2.13 struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid, 2.14 int *nb_vcpu, int *cpusize); 2.15 - 2.16 +int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, 2.17 + uint64_t *cpumap, int cpusize); 2.18 #endif /* LIBXL_H */ 2.19
3.1 --- a/tools/libxl/xl.c Tue Apr 06 06:54:08 2010 +0100 3.2 +++ b/tools/libxl/xl.c Tue Apr 06 06:54:51 2010 +0100 3.3 @@ -877,6 +877,7 @@ static void help(char *command) 3.4 printf(" mem-set set the current memory usage for a domain\n\n"); 3.5 printf(" button-press indicate an ACPI button press to the domain\n\n"); 3.6 printf(" vcpu-list list the VCPUs for all/some domains.\n\n"); 3.7 + printf(" vcpu-pin Set which CPUs a VCPU can use.\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 @@ -937,6 +938,9 @@ static void help(char *command) 3.12 } else if (!strcmp(command, "vcpu-list")) { 3.13 printf("Usage: xl vcpu-list [Domain, ...]\n\n"); 3.14 printf("List the VCPUs for all/some domains.\n\n"); 3.15 + } else if (!strcmp(command, "vcpu-pin")) { 3.16 + printf("Usage: xl vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n\n"); 3.17 + printf("Set which CPUs a VCPU can use.\n\n"); 3.18 } 3.19 } 3.20 3.21 @@ -1863,6 +1867,119 @@ void main_vcpulist(int argc, char **argv 3.22 exit(0); 3.23 } 3.24 3.25 +void vcpupin(char *d, const char *vcpu, char *cpu) 3.26 +{ 3.27 + struct libxl_ctx ctx; 3.28 + struct libxl_vcpuinfo *vcpuinfo; 3.29 + struct libxl_physinfo physinfo; 3.30 + uint64_t *cpumap = NULL; 3.31 + 3.32 + uint32_t domid, vcpuid, cpuida, cpuidb; 3.33 + char *endptr, *toka, *tokb; 3.34 + int i, nb_vcpu, cpusize; 3.35 + 3.36 + vcpuid = strtoul(vcpu, &endptr, 10); 3.37 + if (vcpu == endptr) { 3.38 + if (strcmp(vcpu, "all")) { 3.39 + fprintf(stderr, "Error: Invalid argument.\n"); 3.40 + return; 3.41 + } 3.42 + vcpuid = -1; 3.43 + } 3.44 + 3.45 + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { 3.46 + fprintf(stderr, "cannot init xl context\n"); 3.47 + return; 3.48 + } 3.49 + libxl_ctx_set_log(&ctx, log_callback, NULL); 3.50 + 3.51 + if (domain_qualifier_to_domid(&ctx, d, &domid) < 0) { 3.52 + fprintf(stderr, "%s is an invalid domain identifier\n", d); 3.53 + goto vcpupin_out1; 3.54 + } 3.55 + if (libxl_get_physinfo(&ctx, &physinfo) != 0) { 3.56 + fprintf(stderr, "libxl_get_physinfo failed.\n"); 3.57 + goto vcpupin_out1; 3.58 + } 3.59 + 3.60 + cpumap = calloc(physinfo.max_cpu_id + 1, sizeof (uint64_t)); 3.61 + if (!cpumap) { 3.62 + goto vcpupin_out1; 3.63 + } 3.64 + if (strcmp(cpu, "all")) { 3.65 + for (toka = strtok(cpu, ","), i = 0; toka; toka = strtok(NULL, ","), ++i) { 3.66 + cpuida = strtoul(toka, &endptr, 10); 3.67 + if (toka == endptr) { 3.68 + fprintf(stderr, "Error: Invalid argument.\n"); 3.69 + goto vcpupin_out; 3.70 + } 3.71 + if (*endptr == '-') { 3.72 + tokb = endptr + 1; 3.73 + cpuidb = strtoul(tokb, &endptr, 10); 3.74 + if ((tokb == endptr) || (cpuida > cpuidb)) { 3.75 + fprintf(stderr, "Error: Invalid argument.\n"); 3.76 + goto vcpupin_out; 3.77 + } 3.78 + while (cpuida <= cpuidb) { 3.79 + cpumap[cpuida / 64] |= (1 << (cpuida % 64)); 3.80 + ++cpuida; 3.81 + } 3.82 + } else { 3.83 + cpumap[cpuida / 64] |= (1 << (cpuida % 64)); 3.84 + } 3.85 + } 3.86 + } 3.87 + else { 3.88 + memset(cpumap, -1, sizeof (uint64_t) * (physinfo.max_cpu_id + 1)); 3.89 + } 3.90 + 3.91 + if (vcpuid != -1) { 3.92 + if (libxl_set_vcpuaffinity(&ctx, domid, vcpuid, 3.93 + cpumap, physinfo.max_cpu_id + 1) == -1) { 3.94 + fprintf(stderr, "Could not set affinity for vcpu `%u'.\n", vcpuid); 3.95 + } 3.96 + } 3.97 + else { 3.98 + if (!(vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &cpusize))) { 3.99 + fprintf(stderr, "libxl_list_vcpu failed.\n"); 3.100 + goto vcpupin_out; 3.101 + } 3.102 + for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) { 3.103 + if (libxl_set_vcpuaffinity(&ctx, domid, vcpuinfo->vcpuid, 3.104 + cpumap, physinfo.max_cpu_id + 1) == -1) { 3.105 + fprintf(stderr, "libxl_list_vcpu failed on vcpu `%u'.\n", vcpuinfo->vcpuid); 3.106 + } 3.107 + } 3.108 + } 3.109 + vcpupin_out1: 3.110 + free(cpumap); 3.111 + vcpupin_out: 3.112 + libxl_ctx_free(&ctx); 3.113 +} 3.114 + 3.115 +int main_vcpupin(int argc, char **argv) 3.116 +{ 3.117 + int opt; 3.118 + 3.119 + if (argc != 4) { 3.120 + help("vcpu-pin"); 3.121 + exit(0); 3.122 + } 3.123 + while ((opt = getopt(argc, argv, "h")) != -1) { 3.124 + switch (opt) { 3.125 + case 'h': 3.126 + help("vcpu-pin"); 3.127 + exit(0); 3.128 + default: 3.129 + fprintf(stderr, "option `%c' not supported.\n", opt); 3.130 + break; 3.131 + } 3.132 + } 3.133 + 3.134 + vcpupin(argv[1], argv[2] , argv[3]); 3.135 + exit(0); 3.136 +} 3.137 + 3.138 int main(int argc, char **argv) 3.139 { 3.140 if (argc < 2) { 3.141 @@ -1906,6 +2023,8 @@ int main(int argc, char **argv) 3.142 main_button_press(argc - 1, argv + 1); 3.143 } else if (!strcmp(argv[1], "vcpu-list")) { 3.144 main_vcpulist(argc - 1, argv + 1); 3.145 + } else if (!strcmp(argv[1], "vcpu-pin")) { 3.146 + main_vcpupin(argc - 1, argv + 1); 3.147 } else if (!strcmp(argv[1], "help")) { 3.148 if (argc > 2) 3.149 help(argv[2]);