[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v6 12/14] tools/libxl: introduce some socket helpers
Add libxl_socket_bitmap_alloc() to allow allocating a socket specific libxl_bitmap (as it is for cpu/node bitmap). Internal function libxl__count_physical_sockets() is introduced together to get the socket count when the size of bitmap is not specified. Signed-off-by: Chao Peng <chao.p.peng@xxxxxxxxxxxxxxx> --- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_utils.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 9c22309..32cc725 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3684,6 +3684,8 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc, */ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr, const libxl_bitmap *sptr); + +int libxl__count_physical_sockets(libxl__gc *gc, int *sockets); #endif /* diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 9053b27..5fbace8 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -770,6 +770,52 @@ int libxl_node_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *nodemap, return rc; } +int libxl__count_physical_sockets(libxl__gc *gc, int *sockets) +{ + int rc; + libxl_physinfo info; + + libxl_physinfo_init(&info); + + rc = libxl_get_physinfo(CTX, &info); + if (rc) + return rc; + + *sockets = info.nr_cpus / info.threads_per_core + / info.cores_per_socket; + + libxl_physinfo_dispose(&info); + return 0; +} + +int libxl_socket_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *socketmap, + int max_sockets) +{ + GC_INIT(ctx); + int rc = 0; + + if (max_sockets < 0) { + rc = ERROR_INVAL; + LOG(ERROR, "invalid number of sockets provided"); + goto out; + } + + if (max_sockets == 0) { + rc = libxl__count_physical_sockets(gc, &max_sockets); + if (rc) { + LOGE(ERROR, "failed to get system socket count"); + goto out; + } + } + /* This can't fail: no need to check and log */ + libxl_bitmap_alloc(ctx, socketmap, max_sockets); + + out: + GC_FREE; + return rc; + +} + int libxl_nodemap_to_cpumap(libxl_ctx *ctx, const libxl_bitmap *nodemap, libxl_bitmap *cpumap) diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 68b5580..36ef67d 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -135,6 +135,8 @@ static inline int libxl_bitmap_equal(const libxl_bitmap *ba, int libxl_cpu_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *cpumap, int max_cpus); int libxl_node_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *nodemap, int max_nodes); +int libxl_socket_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *socketmap, + int max_sockets); /* Populate cpumap with the cpus spanned by the nodes in nodemap */ int libxl_nodemap_to_cpumap(libxl_ctx *ctx, -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |