From e1e1e98cacd82fa054ac3c6b381d9833236110e0 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Thu, 28 Jun 2012 17:51:56 +0100 Subject: libxl: allow setting more than 31 vcpus In current implementation, it uses integer to record current avail cpus and this only allows user to specify 31 vcpus. In following patch, it uses cpumap instead integer which make more sense than before. Also there is no limit to the max vcpus. Signed-off-by: Yang Zhang Acked-by: Ian Jackson Signed-off-by: Ian Jackson Committed-by: Ian Jackson --- tools/libxl/libxl_utils.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tools/libxl/libxl_utils.c') diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 2acf7d4a43..d07a5a7a58 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -511,7 +511,7 @@ void libxl_cpumap_dispose(libxl_cpumap *map) free(map->map); } -int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu) +int libxl_cpumap_test(const libxl_cpumap *cpumap, int cpu) { if (cpu >= cpumap->size * 8) return 0; @@ -532,6 +532,31 @@ void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu) cpumap->map[cpu / 8] &= ~(1 << (cpu & 7)); } +int libxl_cpumap_count_set(const libxl_cpumap *cpumap) +{ + int i, nr_set_cpus = 0; + libxl_for_each_set_cpu(i, *cpumap) + nr_set_cpus++; + + return nr_set_cpus; +} + +/* NB. caller is responsible for freeing the memory */ +char *libxl_cpumap_to_hex_string(const libxl_cpumap *cpumap) +{ + int i = cpumap->size; + char *p = libxl__zalloc(NULL, cpumap->size * 2 + 3); + char *q = p; + strncpy(p, "0x", 2); + p += 2; + while(--i >= 0) { + sprintf(p, "%02x", cpumap->map[i]); + p += 2; + } + *p = '\0'; + return q; +} + int libxl_get_max_cpus(libxl_ctx *ctx) { return xc_get_max_cpus(ctx->xch); -- cgit v1.2.3