debuggers.hg
changeset 22650:e115ee319a64
Extend cpupools to support numa
The user interfaces for cpupools are extended to support numa machines:
- xl cpupool-create supports now specifying a node list instead of a cpu list.
The new cpupool will be created with all free cpus of the specified numa
nodes.
- xl cpupool-cpu-remove and xl cpupool-cpu-add can take a node number instead
of a cpu number. Using 'node:1' for the cpu parameter will, depending on
the operation, either remove all cpus of node 1 in the specified cpupool,
or add all free cpus of node 1 to the cpupool.
libxl is extended with the following functions to support this feature:
int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus)
int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus)
Signed-off-by: juergen.gross@ts.fujitsu.com
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
The user interfaces for cpupools are extended to support numa machines:
- xl cpupool-create supports now specifying a node list instead of a cpu list.
The new cpupool will be created with all free cpus of the specified numa
nodes.
- xl cpupool-cpu-remove and xl cpupool-cpu-add can take a node number instead
of a cpu number. Using 'node:1' for the cpu parameter will, depending on
the operation, either remove all cpus of node 1 in the specified cpupool,
or add all free cpus of node 1 to the cpupool.
libxl is extended with the following functions to support this feature:
int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus)
int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus)
Signed-off-by: juergen.gross@ts.fujitsu.com
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
author | Juergen Gross <juergen.gross@ts.fujitsu.com> |
---|---|
date | Thu Dec 09 11:26:37 2010 +0100 (2010-12-09) |
parents | 8ecbcb19911f |
children | 6b0620970c73 |
files | tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/xl_cmdimpl.c tools/libxl/xl_cmdtable.c |
line diff
1.1 --- a/tools/libxl/libxl.c Thu Dec 09 11:23:20 2010 +0100 1.2 +++ b/tools/libxl/libxl.c Thu Dec 09 11:26:37 2010 +0100 1.3 @@ -3898,6 +3898,38 @@ int libxl_cpupool_cpuadd(libxl_ctx *ctx, 1.4 return 0; 1.5 } 1.6 1.7 +int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus) 1.8 +{ 1.9 + int rc = 0; 1.10 + int cpu; 1.11 + libxl_cpumap freemap; 1.12 + libxl_topologyinfo topology; 1.13 + 1.14 + if (libxl_get_freecpus(ctx, &freemap)) { 1.15 + return ERROR_FAIL; 1.16 + } 1.17 + 1.18 + if (libxl_get_topologyinfo(ctx, &topology)) { 1.19 + rc = ERROR_FAIL; 1.20 + goto out; 1.21 + } 1.22 + 1.23 + *cpus = 0; 1.24 + for (cpu = 0; cpu < topology.nodemap.entries; cpu++) { 1.25 + if (libxl_cpumap_test(&freemap, cpu) && 1.26 + (topology.nodemap.array[cpu] == node) && 1.27 + !libxl_cpupool_cpuadd(ctx, poolid, cpu)) { 1.28 + (*cpus)++; 1.29 + } 1.30 + } 1.31 + 1.32 + libxl_topologyinfo_destroy(&topology); 1.33 + 1.34 +out: 1.35 + libxl_cpumap_destroy(&freemap); 1.36 + return rc; 1.37 +} 1.38 + 1.39 int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu) 1.40 { 1.41 int rc; 1.42 @@ -3911,6 +3943,48 @@ int libxl_cpupool_cpuremove(libxl_ctx *c 1.43 return 0; 1.44 } 1.45 1.46 +int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus) 1.47 +{ 1.48 + int ret = 0; 1.49 + int n_pools; 1.50 + int p; 1.51 + int cpu; 1.52 + libxl_topologyinfo topology; 1.53 + libxl_cpupoolinfo *poolinfo; 1.54 + 1.55 + poolinfo = libxl_list_cpupool(ctx, &n_pools); 1.56 + if (!poolinfo) { 1.57 + return ERROR_NOMEM; 1.58 + } 1.59 + 1.60 + if (libxl_get_topologyinfo(ctx, &topology)) { 1.61 + ret = ERROR_FAIL; 1.62 + goto out; 1.63 + } 1.64 + 1.65 + *cpus = 0; 1.66 + for (p = 0; p < n_pools; p++) { 1.67 + if (poolinfo[p].poolid == poolid) { 1.68 + for (cpu = 0; cpu < topology.nodemap.entries; cpu++) { 1.69 + if ((topology.nodemap.array[cpu] == node) && 1.70 + libxl_cpumap_test(&poolinfo[p].cpumap, cpu) && 1.71 + !libxl_cpupool_cpuremove(ctx, poolid, cpu)) { 1.72 + (*cpus)++; 1.73 + } 1.74 + } 1.75 + } 1.76 + } 1.77 + 1.78 + libxl_topologyinfo_destroy(&topology); 1.79 + 1.80 +out: 1.81 + for (p = 0; p < n_pools; p++) { 1.82 + libxl_cpupoolinfo_destroy(poolinfo + p); 1.83 + } 1.84 + 1.85 + return ret; 1.86 +} 1.87 + 1.88 int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid) 1.89 { 1.90 libxl__gc gc = LIBXL_INIT_GC(ctx);
2.1 --- a/tools/libxl/libxl.h Thu Dec 09 11:23:20 2010 +0100 2.2 +++ b/tools/libxl/libxl.h Thu Dec 09 11:26:37 2010 +0100 2.3 @@ -529,7 +529,9 @@ int libxl_create_cpupool(libxl_ctx *ctx, 2.4 uint32_t *poolid); 2.5 int libxl_destroy_cpupool(libxl_ctx *ctx, uint32_t poolid); 2.6 int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); 2.7 +int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); 2.8 int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); 2.9 +int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); 2.10 int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); 2.11 2.12 /* common paths */
3.1 --- a/tools/libxl/xl_cmdimpl.c Thu Dec 09 11:23:20 2010 +0100 3.2 +++ b/tools/libxl/xl_cmdimpl.c Thu Dec 09 11:26:37 2010 +0100 3.3 @@ -5412,10 +5412,12 @@ int main_cpupoolcreate(int argc, char ** 3.4 uint32_t poolid; 3.5 int schedid = -1; 3.6 XLU_ConfigList *cpus; 3.7 - int n_cpus, i, n; 3.8 + XLU_ConfigList *nodes; 3.9 + int n_cpus, n_nodes, i, n; 3.10 libxl_cpumap freemap; 3.11 libxl_cpumap cpumap; 3.12 libxl_uuid uuid; 3.13 + libxl_topologyinfo topology; 3.14 3.15 while (1) { 3.16 opt = getopt_long(argc, argv, "hnf:", long_options, &option_index); 3.17 @@ -5524,7 +5526,32 @@ int main_cpupoolcreate(int argc, char ** 3.18 fprintf(stderr, "Failed to allocate cpumap\n"); 3.19 return -ERROR_FAIL; 3.20 } 3.21 - if (!xlu_cfg_get_list(config, "cpus", &cpus, 0, 0)) { 3.22 + if (!xlu_cfg_get_list(config, "nodes", &nodes, 0, 0)) { 3.23 + n_cpus = 0; 3.24 + n_nodes = 0; 3.25 + if (libxl_get_topologyinfo(&ctx, &topology)) { 3.26 + fprintf(stderr, "libxl_get_topologyinfo failed\n"); 3.27 + return -ERROR_FAIL; 3.28 + } 3.29 + while ((buf = xlu_cfg_get_listitem(nodes, n_nodes)) != NULL) { 3.30 + n = atoi(buf); 3.31 + for (i = 0; i < topology.nodemap.entries; i++) { 3.32 + if ((topology.nodemap.array[i] == n) && 3.33 + libxl_cpumap_test(&freemap, i)) { 3.34 + libxl_cpumap_set(&cpumap, i); 3.35 + n_cpus++; 3.36 + } 3.37 + } 3.38 + n_nodes++; 3.39 + } 3.40 + 3.41 + libxl_topologyinfo_destroy(&topology); 3.42 + 3.43 + if (n_cpus == 0) { 3.44 + fprintf(stderr, "no free cpu found\n"); 3.45 + return -ERROR_FAIL; 3.46 + } 3.47 + } else if (!xlu_cfg_get_list(config, "cpus", &cpus, 0, 0)) { 3.48 n_cpus = 0; 3.49 while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) { 3.50 i = atoi(buf); 3.51 @@ -5708,6 +5735,8 @@ int main_cpupoolcpuadd(int argc, char ** 3.52 const char *pool; 3.53 uint32_t poolid; 3.54 int cpu; 3.55 + int node; 3.56 + int n; 3.57 3.58 while ((opt = getopt(argc, argv, "h")) != -1) { 3.59 switch (opt) { 3.60 @@ -5732,7 +5761,13 @@ int main_cpupoolcpuadd(int argc, char ** 3.61 help("cpupool-cpu-add"); 3.62 return -ERROR_FAIL; 3.63 } 3.64 - cpu = atoi(argv[optind]); 3.65 + node = -1; 3.66 + cpu = -1; 3.67 + if (strncmp(argv[optind], "node:", 5) == 0) { 3.68 + node = atoi(argv[optind] + 5); 3.69 + } else { 3.70 + cpu = atoi(argv[optind]); 3.71 + } 3.72 3.73 if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) || 3.74 !libxl_cpupoolid_to_name(&ctx, poolid)) { 3.75 @@ -5740,7 +5775,21 @@ int main_cpupoolcpuadd(int argc, char ** 3.76 return -ERROR_FAIL; 3.77 } 3.78 3.79 - return -libxl_cpupool_cpuadd(&ctx, poolid, cpu); 3.80 + if (cpu >= 0) { 3.81 + return -libxl_cpupool_cpuadd(&ctx, poolid, cpu); 3.82 + } 3.83 + 3.84 + if (libxl_cpupool_cpuadd_node(&ctx, poolid, node, &n)) { 3.85 + fprintf(stderr, "libxl_cpupool_cpuadd_node failed\n"); 3.86 + return -ERROR_FAIL; 3.87 + } 3.88 + 3.89 + if (n > 0) { 3.90 + return 0; 3.91 + } 3.92 + 3.93 + fprintf(stderr, "no free cpu found\n"); 3.94 + return -ERROR_FAIL; 3.95 } 3.96 3.97 int main_cpupoolcpuremove(int argc, char **argv) 3.98 @@ -5749,6 +5798,8 @@ int main_cpupoolcpuremove(int argc, char 3.99 const char *pool; 3.100 uint32_t poolid; 3.101 int cpu; 3.102 + int node; 3.103 + int n; 3.104 3.105 while ((opt = getopt(argc, argv, "h")) != -1) { 3.106 switch (opt) { 3.107 @@ -5773,7 +5824,13 @@ int main_cpupoolcpuremove(int argc, char 3.108 help("cpupool-cpu-remove"); 3.109 return -ERROR_FAIL; 3.110 } 3.111 - cpu = atoi(argv[optind]); 3.112 + node = -1; 3.113 + cpu = -1; 3.114 + if (strncmp(argv[optind], "node:", 5) == 0) { 3.115 + node = atoi(argv[optind] + 5); 3.116 + } else { 3.117 + cpu = atoi(argv[optind]); 3.118 + } 3.119 3.120 if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) || 3.121 !libxl_cpupoolid_to_name(&ctx, poolid)) { 3.122 @@ -5781,7 +5838,21 @@ int main_cpupoolcpuremove(int argc, char 3.123 return -ERROR_FAIL; 3.124 } 3.125 3.126 - return -libxl_cpupool_cpuremove(&ctx, poolid, cpu); 3.127 + if (cpu >= 0) { 3.128 + return -libxl_cpupool_cpuremove(&ctx, poolid, cpu); 3.129 + } 3.130 + 3.131 + if (libxl_cpupool_cpuremove_node(&ctx, poolid, node, &n)) { 3.132 + fprintf(stderr, "libxl_cpupool_cpuremove_node failed\n"); 3.133 + return -ERROR_FAIL; 3.134 + } 3.135 + 3.136 + if (n == 0) { 3.137 + fprintf(stderr, "no cpu of node found in cpupool\n"); 3.138 + return -ERROR_FAIL; 3.139 + } 3.140 + 3.141 + return 0; 3.142 } 3.143 3.144 int main_cpupoolmigrate(int argc, char **argv)
4.1 --- a/tools/libxl/xl_cmdtable.c Thu Dec 09 11:23:20 2010 +0100 4.2 +++ b/tools/libxl/xl_cmdtable.c Thu Dec 09 11:26:37 2010 +0100 4.3 @@ -361,12 +361,12 @@ struct cmd_spec cmd_table[] = { 4.4 { "cpupool-cpu-add", 4.5 &main_cpupoolcpuadd, 4.6 "Adds a CPU to a CPU pool", 4.7 - "<CPU Pool> <CPU nr>", 4.8 + "<CPU Pool> <CPU nr>|node:<node nr>", 4.9 }, 4.10 { "cpupool-cpu-remove", 4.11 &main_cpupoolcpuremove, 4.12 "Removes a CPU from a CPU pool", 4.13 - "<CPU Pool> <CPU nr>", 4.14 + "<CPU Pool> <CPU nr>|node:<node nr>", 4.15 }, 4.16 { "cpupool-migrate", 4.17 &main_cpupoolmigrate,