From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dario Faggioli Subject: [PATCH v4 03/15] libxl: introduce libxl_get_nr_cpus() Date: Fri, 22 Nov 2013 19:56:58 +0100 Message-ID: <20131122185658.11200.13074.stgit@Solace> References: <20131122183332.11200.20231.stgit@Solace> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20131122183332.11200.20231.stgit@Solace> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Marcus Granado , Keir Fraser , Ian Campbell , Li Yechen , George Dunlap , Andrew Cooper , Juergen Gross , Ian Jackson , Jan Beulich , Justin Weaver , Matt Wilson , Elena Ufimtseva List-Id: xen-devel@lists.xenproject.org to retrieve the actual number of pCPUs on the host. Signed-off-by: Dario Faggioli --- tools/libxl/libxl.h | 3 +++ tools/libxl/libxl_utils.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index a9663e4..2fab5ba 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -652,6 +652,9 @@ 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 online cpus on the host */ +int libxl_get_nr_cpus(libxl_ctx *ctx); + /* 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 1815422..8763070 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -774,6 +774,24 @@ int libxl_get_max_cpus(libxl_ctx *ctx) return max_cpus <= 0 ? ERROR_FAIL : max_cpus; } +int libxl_get_nr_cpus(libxl_ctx *ctx) +{ + GC_INIT(ctx); + xc_physinfo_t physinfo = { 0 }; + int rc = 0; + + if (xc_physinfo(ctx->xch, &physinfo)) { + LOGE(ERROR, "xc_physinfo failed."); + rc = ERROR_FAIL; + goto out; + } + rc = physinfo.nr_cpus; + + out: + GC_FREE; + return rc; +} + int libxl_get_max_nodes(libxl_ctx *ctx) { int max_nodes = xc_get_max_nodes(ctx->xch);