libxc/libxl: allow to retrieve the number of online pCPUs
authorDario Faggioli <dario.faggioli@citrix.com>
Sat, 7 Dec 2013 00:05:11 +0000 (01:05 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 9 Dec 2013 15:20:12 +0000 (15:20 +0000)
by introducing introduce xc_get_online_cpus() and
libxl_get_online_cpus().

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxc/xc_misc.c
tools/libxc/xenctrl.h
tools/libxl/libxl.h
tools/libxl/libxl_utils.c

index c7714699e54c2d5360bcd7fd8438cae7ee961095..00cd0d865073391a15c8d9f369b47fc9fb4cb45d 100644 (file)
@@ -38,6 +38,16 @@ int xc_get_max_cpus(xc_interface *xch)
     return -1;
 }
 
+int xc_get_online_cpus(xc_interface *xch)
+{
+    xc_physinfo_t physinfo;
+
+    if ( !xc_physinfo(xch, &physinfo) )
+        return physinfo.nr_cpus;
+
+    return -1;
+}
+
 int xc_get_max_nodes(xc_interface *xch)
 {
     static int max_nodes = 0;
index cced208097c2dd9df214c252599ff0dce6d6a5d2..6e58ebeb5e783946b03a42d400a2ff3efa268d60 100644 (file)
@@ -356,6 +356,9 @@ typedef uint8_t *xc_cpumap_t;
 /* return maximum number of cpus the hypervisor supports */
 int xc_get_max_cpus(xc_interface *xch);
 
+/* return the number of online cpus */
+int xc_get_online_cpus(xc_interface *xch);
+
 /* return array size for cpumap */
 int xc_get_cpumap_size(xc_interface *xch);
 
index 75b64ea5c8cd0f3a1ccded4f5702b50924a73f50..12d6c311a2682a9fd39c8e9ab254285aa333fd6b 100644 (file)
@@ -677,6 +677,14 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_in
 /* get max. number of cpus supported by hypervisor */
 int libxl_get_max_cpus(libxl_ctx *ctx);
 
+/* get the actual number of currently online cpus on the host */
+int libxl_get_online_cpus(libxl_ctx *ctx);
+  /* Beware that no locking or serialization is provided by libxl,
+   * so the information can be outdated as far as the function
+   * returns. If there are other entities in the system capable
+   * of onlining/offlining CPUs, it is up to the application
+   * to guarantee consistency, if that is important. */
+
 /* get max. number of NUMA nodes supported by hypervisor */
 int libxl_get_max_nodes(libxl_ctx *ctx);
 
index 0833de2cc30ac9079fe95ae04512e7cdf11123ef..c9cef66578f0b3475e7e207365556e7b4f0dde18 100644 (file)
@@ -776,6 +776,13 @@ int libxl_get_max_cpus(libxl_ctx *ctx)
     return max_cpus < 0 ? ERROR_FAIL : max_cpus;
 }
 
+int libxl_get_online_cpus(libxl_ctx *ctx)
+{
+    int online_cpus = xc_get_online_cpus(ctx->xch);
+
+    return online_cpus < 0 ? ERROR_FAIL : online_cpus;
+}
+
 int libxl_get_max_nodes(libxl_ctx *ctx)
 {
     int max_nodes = xc_get_max_nodes(ctx->xch);