From: Dario Faggioli Date: Fri, 13 Mar 2015 11:09:24 +0000 (+0100) Subject: libxl: introduce libxl_cpupool_cpu{add, remove}_cpumap() X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~3577 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7f586dbb483962835b6cb7d6918dcfca95c5437d;p=xen.git libxl: introduce libxl_cpupool_cpu{add, remove}_cpumap() To add (removes) to (from) a cpupool all the pCPUs corresponding to the bits that are set in the passed bitmap. This is convenient and useful in order to implement, in xl, the possibility of specifying ranges of pCPUs to be added (removed) to (from) a cpupool, in the relevant commands. While there, convert libxl_cpupool_cpu{add,remove} to use the appropriate logging macro (LOGE()). Signed-off-by: Dario Faggioli Cc: Ian Campbell Cc: Ian Jackson Cc: Stefano Stabellini Cc: Wei Liu Cc: Juergen Gross Acked-by: Wei Liu --- diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 94b4d595ec..ad69a8a719 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -6358,15 +6358,33 @@ out: int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu) { - int rc; + GC_INIT(ctx); + int rc = 0; rc = xc_cpupool_addcpu(ctx->xch, poolid, cpu); if (rc) { - LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, - "Error moving cpu to cpupool"); - return ERROR_FAIL; + LOGE(ERROR, "Error moving cpu %d to cpupool", cpu); + rc = ERROR_FAIL; } - return 0; + + GC_FREE; + return rc; +} + +int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, + const libxl_bitmap *cpumap) +{ + int c, ncpus = 0, rc = 0; + + libxl_for_each_set_bit(c, *cpumap) { + if (!libxl_cpupool_cpuadd(ctx, poolid, c)) + ncpus++; + } + + if (ncpus != libxl_bitmap_count_set(cpumap)) + rc = ERROR_FAIL; + + return rc; } int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus) @@ -6403,15 +6421,33 @@ out: int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu) { - int rc; + GC_INIT(ctx); + int rc = 0; rc = xc_cpupool_removecpu(ctx->xch, poolid, cpu); if (rc) { - LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, - "Error removing cpu from cpupool"); - return ERROR_FAIL; + LOGE(ERROR, "Error removing cpu %d from cpupool", cpu); + rc = ERROR_FAIL; } - return 0; + + GC_FREE; + return rc; +} + +int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, + const libxl_bitmap *cpumap) +{ + int c, ncpus = 0, rc = 0; + + libxl_for_each_set_bit(c, *cpumap) { + if (!libxl_cpupool_cpuremove(ctx, poolid, c)) + ncpus++; + } + + if (ncpus != libxl_bitmap_count_set(cpumap)) + rc = ERROR_FAIL; + + return rc; } int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 664b87f5dc..6bc75c5e84 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -90,6 +90,15 @@ */ #define LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID 1 +/* LIBXL_HAVE_CPUPOOL_ADD_REM_CPUMAP + * + * If this is defined, libxl has two library functions called + * libxl_cpupool_cpuadd_cpumap and libxl_cpupool_cpuremove_cpumap, + * which allow to add to or remove from a cpupool all the cpus + * specified in a bitmap. + */ +#define LIBXL_HAVE_CPUPOOL_ADD_REM_CPUMAP 1 + /* * LIBXL_HAVE_FIRMWARE_PASSTHROUGH indicates the feature for * passing in SMBIOS and ACPI firmware to HVM guests is present @@ -1475,8 +1484,12 @@ int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, + const libxl_bitmap *cpumap); int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); +int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, + const libxl_bitmap *cpumap); int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid);