]> xenbits.xensource.com Git - people/vhanquez/xen-unstable.git/commitdiff
Support new xl command cpupool-numa-split
authorJuergen Gross <juergen.gross@ts.fujitsu.com>
Thu, 9 Dec 2010 10:50:53 +0000 (11:50 +0100)
committerJuergen Gross <juergen.gross@ts.fujitsu.com>
Thu, 9 Dec 2010 10:50:53 +0000 (11:50 +0100)
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@ts.fujitsu.com
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxl/xl.h
tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdtable.c

index 64133e418712758736149ed99fa407895ab09c5b..bb3aca23ed1f088f42c8f2cde13a54dbc63c24c9 100644 (file)
@@ -86,6 +86,7 @@ int main_cpupoolrename(int argc, char **argv);
 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);
 
index cc5de43773d57a8e6711c198b1caea7c9b209a90..6c9b470f9f9add241591bb0126b0e978ddd21fed 100644 (file)
@@ -5943,3 +5943,120 @@ int main_cpupoolmigrate(int argc, char **argv)
 
     return -libxl_cpupool_movedomain(&ctx, poolid, domid);
 }
+
+int main_cpupoolnumasplit(int argc, char **argv)
+{
+    int ret;
+    int opt;
+    int p;
+    int c;
+    int n;
+    uint32_t poolid;
+    int schedid;
+    int n_pools;
+    int node;
+    char name[16];
+    libxl_uuid uuid;
+    libxl_cpumap cpumap;
+    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;
+
+    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;
+    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_topologyinfo(&ctx, &topology)) {
+        fprintf(stderr, "libxl_get_topologyinfo failed\n");
+        return -ERROR_FAIL;
+    }
+
+    if (libxl_cpumap_alloc(&ctx, &cpumap)) {
+        fprintf(stderr, "Failed to allocate cpumap\n");
+        libxl_topologyinfo_destroy(&topology);
+        return -ERROR_FAIL;
+    }
+
+    /* Reset Pool-0 to 1st node: first add cpus, then remove cpus to avoid
+       a cpupool without cpus in between */
+
+    node = topology.nodemap.array[0];
+    if (libxl_cpupool_cpuadd_node(&ctx, 0, node, &n)) {
+        fprintf(stderr, "error on adding cpu to Pool 0\n");
+        return -ERROR_FAIL;
+    }
+
+    snprintf(name, 15, "Pool-node%d", node);
+    ret = -libxl_cpupool_rename(&ctx, name, 0);
+    if (ret) {
+        fprintf(stderr, "error on renaming Pool 0\n");
+        goto out;
+    }
+
+    for (c = 0; c < topology.nodemap.entries; c++) {
+        if (topology.nodemap.array[c] == node) {
+            topology.nodemap.array[c] = LIBXL_CPUARRAY_INVALID_ENTRY;
+        }
+    }
+
+    for (c = 0; c < topology.nodemap.entries; c++) {
+        if (topology.nodemap.array[c] == LIBXL_CPUARRAY_INVALID_ENTRY) {
+            continue;
+        }
+
+        node = topology.nodemap.array[c];
+        ret = -libxl_cpupool_cpuremove_node(&ctx, 0, node, &n);
+        if (ret) {
+            fprintf(stderr, "error on removing cpu from Pool 0\n");
+            goto out;
+        }
+
+        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;
+        }
+
+        ret = -libxl_cpupool_cpuadd_node(&ctx, 0, node, &n);
+        if (ret) {
+            fprintf(stderr, "error on adding cpus to cpupool\n");
+            goto out;
+        }
+
+        for (p = c; p < topology.nodemap.entries; p++) {
+            if (topology.nodemap.array[p] == node) {
+                topology.nodemap.array[p] = LIBXL_CPUARRAY_INVALID_ENTRY;
+            }
+        }
+    }
+
+out:
+    libxl_topologyinfo_destroy(&topology);
+    libxl_cpumap_destroy(&cpumap);
+
+    return ret;
+}
index 854f7da96a7446e2722e9fe04016cd0b3a1d8789..5e7793d49be963d23e06a0283ca101c78b3eaa3f 100644 (file)
@@ -378,6 +378,11 @@ struct cmd_spec cmd_table[] = {
       "Moves a domain into a CPU pool",
       "<Domain> <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);