[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RESEND PATCH v5 6/9] libxc/libxl: allow to retrieve the number of online pCPUs



by introducing introduce xc_get_online_cpus() and
libxl_get_online_cpus().

Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
Changes from v5:
 * add a comment about consistency.

Changes from v4:
 * introduced the xc call and call it from libxl, as
   suggested during review.
---
 tools/libxc/xc_misc.c     |   10 ++++++++++
 tools/libxc/xenctrl.h     |    3 +++
 tools/libxl/libxl.h       |    8 ++++++++
 tools/libxl/libxl_utils.c |    7 +++++++
 4 files changed, 28 insertions(+)

diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index c771469..00cd0d8 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -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;
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index cced208..6e58ebe 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -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);
 
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 75b64ea..12d6c31 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -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);
 
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 0833de2..c9cef66 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -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);


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.