# HG changeset patch # User Juergen Gross # Date 1290692690 -3600 # Node ID f31333fe3b3553c90419428624db0983a58e2c82 # Parent d3880bd8b4674e0ec88dfa380347de9045a4b533 Support new xl command cpupool-numa-split New xl command cpupool-numa-split which will create one cpupool for each numa node of the machine. Can be called only if no other cpupools than Pool-0 are defined. After creation the cpupools can be managed as usual. Signed-off-by: juergen.gross@xxxxxxxxxxxxxx diff -r d3880bd8b467 -r f31333fe3b35 tools/libxl/xl.h --- a/tools/libxl/xl.h Thu Nov 25 12:39:52 2010 +0100 +++ b/tools/libxl/xl.h Thu Nov 25 14:44:50 2010 +0100 @@ -85,6 +85,7 @@ int main_cpupoolcpuadd(int argc, char **argv); int main_cpupoolcpuremove(int argc, char **argv); int main_cpupoolmigrate(int argc, char **argv); +int main_cpupoolnumasplit(int argc, char **argv); void help(const char *command); diff -r d3880bd8b467 -r f31333fe3b35 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Nov 25 12:39:52 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Thu Nov 25 14:44:50 2010 +0100 @@ -5945,3 +5945,122 @@ return -libxl_cpupool_movedomain(&ctx, poolid, domid); } + +int main_cpupoolnumasplit(int argc, char **argv) +{ + int ret; + int opt; + int p; + int c; + uint32_t poolid; + int schedid; + int n_pools; + int node; + char name[16]; + libxl_uuid uuid; + libxl_cpumap cpumap; + libxl_cpumap freemap; + libxl_cpupoolinfo *poolinfo; + libxl_topologyinfo *topology; + + while ((opt = getopt(argc, argv, "h")) != -1) { + switch (opt) { + case 'h': + help("cpupool-numa-split"); + return 0; + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + ret = 0; + + if (libxl_cpumap_alloc(&ctx, &cpumap)) { + fprintf(stderr, "Failed to allocate cpumap\n"); + return -ERROR_FAIL; + } + + poolinfo = libxl_list_cpupool(&ctx, &n_pools); + if (!poolinfo) { + fprintf(stderr, "error getting cpupool info\n"); + return -ERROR_NOMEM; + } + poolid = poolinfo[0].poolid; + schedid = poolinfo[0].sched_id; + libxl_for_each_cpu(c, poolinfo[0].cpumap) + if (libxl_cpumap_test(&poolinfo[0].cpumap, c)) + libxl_cpumap_set(&cpumap, c); + for (p = 0; p < n_pools; p++) { + libxl_cpupoolinfo_destroy(poolinfo + p); + } + if (n_pools > 1) { + fprintf(stderr, "splitting not possible, already cpupools in use\n"); + return -ERROR_FAIL; + } + + if (libxl_get_freecpus(&ctx, &freemap)) { + fprintf(stderr, "libxl_get_freecpus failed\n"); + return -ERROR_FAIL; + } + + topology = libxl_get_topologyinfo(&ctx); + if (topology == NULL) { + fprintf(stderr, "libxl_get_topologyinfo failed\n"); + return -ERROR_FAIL; + } + + /* Reset Pool-0 to 1st node */ + node = topology->nodemap.array[0]; + libxl_for_each_cpu(c, cpumap) { + if (!libxl_cpumap_test(&cpumap, c) && (c < topology->nodemap.entries) && + (topology->nodemap.array[c] == node)) { + ret = -libxl_cpupool_cpuadd(&ctx, poolid, c); + if (ret) { + fprintf(stderr, "error on adding cpu to Pool-0\n"); + goto out; + } + libxl_cpumap_reset(&freemap, c); + } + } + libxl_for_each_cpu(c, cpumap) { + if (libxl_cpumap_test(&cpumap, c) && (c < topology->nodemap.entries) && + (topology->nodemap.array[c] != node)) { + ret = -libxl_cpupool_cpuremove(&ctx, poolid, c); + if (ret) { + fprintf(stderr, "error on removing cpu from Pool-0\n"); + goto out; + } + libxl_cpumap_set(&freemap, c); + } + } + + for (;;) { + node = -1; + libxl_for_each_cpu(c, freemap) { + if (libxl_cpumap_test(&freemap, c) && (node == -1)) { + node = topology->nodemap.array[c]; + } + libxl_cpumap_reset(&cpumap, c); + if ((node >= 0) && libxl_cpumap_test(&freemap, c) && + (c < topology->nodemap.entries) && (topology->nodemap.array[c] == node)) { + libxl_cpumap_reset(&freemap, c); + libxl_cpumap_set(&cpumap, c); + } + } + if (node == -1) + break; + + snprintf(name, 15, "Pool-node%d", node); + libxl_uuid_generate(&uuid); + ret = -libxl_create_cpupool(&ctx, name, schedid, cpumap, &uuid, &poolid); + if (ret) { + fprintf(stderr, "error on creating cpupool\n"); + goto out; + } + } + +out: + libxl_topologyinfo_destroy(topology); + + return ret; +} diff -r d3880bd8b467 -r f31333fe3b35 tools/libxl/xl_cmdtable.c --- a/tools/libxl/xl_cmdtable.c Thu Nov 25 12:39:52 2010 +0100 +++ b/tools/libxl/xl_cmdtable.c Thu Nov 25 14:44:50 2010 +0100 @@ -373,6 +373,11 @@ "Moves a domain into a CPU pool", " ", }, + { "cpupool-numa-split", + &main_cpupoolnumasplit, + "Splits up the machine into one CPU pool per NUMA node", + "", + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);