aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/gentest.py2
-rw-r--r--tools/libxl/libxl.c100
-rw-r--r--tools/libxl/libxl.h4
-rw-r--r--tools/libxl/libxl_types.idl8
-rw-r--r--tools/libxl/libxl_utils.c8
-rw-r--r--tools/libxl/xl_cmdimpl.c61
6 files changed, 107 insertions, 76 deletions
diff --git a/tools/libxl/gentest.py b/tools/libxl/gentest.py
index 06d35369cf..be05bfb49d 100644
--- a/tools/libxl/gentest.py
+++ b/tools/libxl/gentest.py
@@ -195,6 +195,7 @@ static void libxl_string_list_rand_init(libxl_string_list *p)
*p = l;
}
+#if 0 /* To be remove in a subsequent patch */
static void libxl_cpuarray_rand_init(libxl_cpuarray *p)
{
int i;
@@ -209,6 +210,7 @@ static void libxl_cpuarray_rand_init(libxl_cpuarray *p)
p->array[i] = r;
}
}
+#endif
""")
for ty in builtins + types:
if ty.typename not in handcoded:
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index a5d87c7cc3..6fcd319b58 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2755,57 +2755,68 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
return 0;
}
-int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info)
+libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nr)
{
xc_topologyinfo_t tinfo;
DECLARE_HYPERCALL_BUFFER(xc_cpu_to_core_t, coremap);
DECLARE_HYPERCALL_BUFFER(xc_cpu_to_socket_t, socketmap);
DECLARE_HYPERCALL_BUFFER(xc_cpu_to_node_t, nodemap);
+ libxl_cputopology *ret = NULL;
int i;
- int rc = 0;
+ int max_cpus;
- rc += libxl_cpuarray_alloc(ctx, &info->coremap);
- rc += libxl_cpuarray_alloc(ctx, &info->socketmap);
- rc += libxl_cpuarray_alloc(ctx, &info->nodemap);
- if (rc)
- goto fail;
+ max_cpus = libxl_get_max_cpus(ctx);
+ if (max_cpus == 0)
+ {
+ LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS");
+ return NULL;
+ }
- coremap = xc_hypercall_buffer_alloc(ctx->xch, coremap, sizeof(*coremap) * info->coremap.entries);
- socketmap = xc_hypercall_buffer_alloc(ctx->xch, socketmap, sizeof(*socketmap) * info->socketmap.entries);
- nodemap = xc_hypercall_buffer_alloc(ctx->xch, nodemap, sizeof(*nodemap) * info->nodemap.entries);
- if ((coremap == NULL) || (socketmap == NULL) || (nodemap == NULL))
+ coremap = xc_hypercall_buffer_alloc
+ (ctx->xch, coremap, sizeof(*coremap) * max_cpus);
+ socketmap = xc_hypercall_buffer_alloc
+ (ctx->xch, socketmap, sizeof(*socketmap) * max_cpus);
+ nodemap = xc_hypercall_buffer_alloc
+ (ctx->xch, nodemap, sizeof(*nodemap) * max_cpus);
+ if ((coremap == NULL) || (socketmap == NULL) || (nodemap == NULL)) {
+ LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
+ "Unable to allocate hypercall arguments");
goto fail;
+ }
set_xen_guest_handle(tinfo.cpu_to_core, coremap);
set_xen_guest_handle(tinfo.cpu_to_socket, socketmap);
set_xen_guest_handle(tinfo.cpu_to_node, nodemap);
- tinfo.max_cpu_index = info->coremap.entries - 1;
- if (xc_topologyinfo(ctx->xch, &tinfo) != 0)
+ tinfo.max_cpu_index = max_cpus - 1;
+ if (xc_topologyinfo(ctx->xch, &tinfo) != 0) {
+ LIBXL__LOG_ERRNO(ctx, XTL_ERROR, "Topology info hypercall failed");
goto fail;
+ }
- for (i = 0; i <= tinfo.max_cpu_index; i++) {
- if (i < info->coremap.entries)
- info->coremap.array[i] = (coremap[i] == INVALID_TOPOLOGY_ID) ?
- LIBXL_CPUARRAY_INVALID_ENTRY : coremap[i];
- if (i < info->socketmap.entries)
- info->socketmap.array[i] = (socketmap[i] == INVALID_TOPOLOGY_ID) ?
- LIBXL_CPUARRAY_INVALID_ENTRY : socketmap[i];
- if (i < info->nodemap.entries)
- info->nodemap.array[i] = (nodemap[i] == INVALID_TOPOLOGY_ID) ?
- LIBXL_CPUARRAY_INVALID_ENTRY : nodemap[i];
+ ret = malloc(sizeof(libxl_cputopology) * max_cpus);
+ if (ret == NULL) {
+ LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
+ "Unable to allocate return value");
+ goto fail;
}
- xc_hypercall_buffer_free(ctx->xch, coremap);
- xc_hypercall_buffer_free(ctx->xch, socketmap);
- xc_hypercall_buffer_free(ctx->xch, nodemap);
- return 0;
+ for (i = 0; i <= max_cpus; i++) {
+#define V(map, i) (map[i] == INVALID_TOPOLOGY_ID) ? \
+ LIBXL_CPUTOPOLOGY_INVALID_ENTRY : map[i]
+ ret[i].core = V(coremap, i);
+ ret[i].socket = V(socketmap, i);
+ ret[i].node = V(nodemap, i);
+#undef V
+ }
fail:
xc_hypercall_buffer_free(ctx->xch, coremap);
xc_hypercall_buffer_free(ctx->xch, socketmap);
xc_hypercall_buffer_free(ctx->xch, nodemap);
- libxl_topologyinfo_dispose(info);
- return ERROR_FAIL;
+
+ if (ret)
+ *nr = max_cpus;
+ return ret;
}
const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)
@@ -3604,30 +3615,30 @@ 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 rc = 0;
- int cpu;
+ int cpu, nr;
libxl_cpumap freemap;
- libxl_topologyinfo topology;
+ libxl_cputopology *topology;
if (libxl_get_freecpus(ctx, &freemap)) {
return ERROR_FAIL;
}
- if (libxl_get_topologyinfo(ctx, &topology)) {
+ topology = libxl_get_cpu_topology(ctx, &nr);
+ if (!topology) {
rc = ERROR_FAIL;
goto out;
}
*cpus = 0;
- for (cpu = 0; cpu < topology.nodemap.entries; cpu++) {
- if (libxl_cpumap_test(&freemap, cpu) &&
- (topology.nodemap.array[cpu] == node) &&
+ for (cpu = 0; cpu < nr; cpu++) {
+ if (libxl_cpumap_test(&freemap, cpu) && (topology[cpu].node == node) &&
!libxl_cpupool_cpuadd(ctx, poolid, cpu)) {
(*cpus)++;
}
+ libxl_cputopology_dispose(&topology[cpu]);
}
- libxl_topologyinfo_dispose(&topology);
-
+ free(topology);
out:
libxl_cpumap_dispose(&freemap);
return rc;
@@ -3651,8 +3662,8 @@ int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int
int ret = 0;
int n_pools;
int p;
- int cpu;
- libxl_topologyinfo topology;
+ int cpu, nr_cpus;
+ libxl_cputopology *topology;
libxl_cpupoolinfo *poolinfo;
poolinfo = libxl_list_cpupool(ctx, &n_pools);
@@ -3660,7 +3671,8 @@ int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int
return ERROR_NOMEM;
}
- if (libxl_get_topologyinfo(ctx, &topology)) {
+ topology = libxl_get_cpu_topology(ctx, &nr_cpus);
+ if (!topology) {
ret = ERROR_FAIL;
goto out;
}
@@ -3668,8 +3680,8 @@ int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int
*cpus = 0;
for (p = 0; p < n_pools; p++) {
if (poolinfo[p].poolid == poolid) {
- for (cpu = 0; cpu < topology.nodemap.entries; cpu++) {
- if ((topology.nodemap.array[cpu] == node) &&
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
+ if ((topology[cpu].node == node) &&
libxl_cpumap_test(&poolinfo[p].cpumap, cpu) &&
!libxl_cpupool_cpuremove(ctx, poolid, cpu)) {
(*cpus)++;
@@ -3678,7 +3690,9 @@ int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int
}
}
- libxl_topologyinfo_dispose(&topology);
+ for (cpu = 0; cpu < nr_cpus; cpu++)
+ libxl_cputopology_dispose(&topology[cpu]);
+ free(topology);
out:
for (p = 0; p < n_pools; p++) {
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index ea5997be04..fd1a8048b3 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -576,7 +576,9 @@ int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,
*/
int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
-int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info);
+#define LIBXL_CPUTOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
+libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nr);
+void libxl_cputopology_list_free(libxl_cputopology *, int nr);
libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
int *nb_vcpu, int *nrcpus);
int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 617dad6374..0cd6678a0b 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -376,10 +376,10 @@ libxl_physinfo = Struct("physinfo", [
("phys_cap", uint32),
], dispose_fn=None, dir=DIR_OUT)
-libxl_topologyinfo = Struct("topologyinfo", [
- ("coremap", libxl_cpuarray), # cpu to core map
- ("socketmap", libxl_cpuarray), # cpu to socket map
- ("nodemap", libxl_cpuarray), # cpu to node map
+libxl_cputopology = Struct("cputopology", [
+ ("core", uint32),
+ ("socket", uint32),
+ ("node", uint32),
])
libxl_sched_credit = Struct("sched_credit", [
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index dbe8891ee9..c92151abc1 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -557,6 +557,14 @@ int libxl__enum_from_string(const libxl_enum_string_table *t,
return ERROR_FAIL;
}
+void libxl_cputopology_list_free(libxl_cputopology *list, int nr)
+{
+ int i;
+ for (i = 0; i < nr; i++)
+ libxl_cputopology_dispose(&list[i]);
+ free(list);
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index faa69f2da1..7ea31635a1 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3833,10 +3833,11 @@ static void output_physinfo(void)
static void output_topologyinfo(void)
{
- libxl_topologyinfo info;
- int i;
+ libxl_cputopology *info;
+ int i, nr;
- if (libxl_get_topologyinfo(ctx, &info)) {
+ info = libxl_get_cpu_topology(ctx, &nr);
+ if (info == NULL) {
fprintf(stderr, "libxl_get_topologyinfo failed.\n");
return;
}
@@ -3844,15 +3845,15 @@ static void output_topologyinfo(void)
printf("cpu_topology :\n");
printf("cpu: core socket node\n");
- for (i = 0; i < info.coremap.entries; i++) {
- if (info.coremap.array[i] != LIBXL_CPUARRAY_INVALID_ENTRY)
- printf("%3d: %4d %4d %4d\n", i, info.coremap.array[i],
- info.socketmap.array[i], info.nodemap.array[i]);
+ for (i = 0; i < nr; i++) {
+ if (info[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY)
+ printf("%3d: %4d %4d %4d\n", i,
+ info[i].core, info[i].socket, info[i].node);
}
- printf("numa_info : none\n");
+ libxl_cputopology_list_free(info, nr);
- libxl_topologyinfo_dispose(&info);
+ printf("numa_info : none\n");
return;
}
@@ -5350,7 +5351,7 @@ int main_cpupoolcreate(int argc, char **argv)
libxl_cpumap freemap;
libxl_cpumap cpumap;
libxl_uuid uuid;
- libxl_topologyinfo topology;
+ libxl_cputopology *topology;
while (1) {
opt = getopt_long(argc, argv, "hnf:", long_options, &option_index);
@@ -5459,16 +5460,18 @@ int main_cpupoolcreate(int argc, char **argv)
return -ERROR_FAIL;
}
if (!xlu_cfg_get_list(config, "nodes", &nodes, 0, 0)) {
+ int nr;
n_cpus = 0;
n_nodes = 0;
- if (libxl_get_topologyinfo(ctx, &topology)) {
+ topology = libxl_get_cpu_topology(ctx, &nr);
+ if (topology == NULL) {
fprintf(stderr, "libxl_get_topologyinfo failed\n");
return -ERROR_FAIL;
}
while ((buf = xlu_cfg_get_listitem(nodes, n_nodes)) != NULL) {
n = atoi(buf);
- for (i = 0; i < topology.nodemap.entries; i++) {
- if ((topology.nodemap.array[i] == n) &&
+ for (i = 0; i < nr; i++) {
+ if ((topology[i].node == n) &&
libxl_cpumap_test(&freemap, i)) {
libxl_cpumap_set(&cpumap, i);
n_cpus++;
@@ -5477,7 +5480,7 @@ int main_cpupoolcreate(int argc, char **argv)
n_nodes++;
}
- libxl_topologyinfo_dispose(&topology);
+ libxl_cputopology_list_free(topology, nr);
if (n_cpus == 0) {
fprintf(stderr, "no free cpu found\n");
@@ -5799,11 +5802,12 @@ int main_cpupoolnumasplit(int argc, char **argv)
int schedid;
int n_pools;
int node;
+ int n_cpus;
char name[16];
libxl_uuid uuid;
libxl_cpumap cpumap;
libxl_cpupoolinfo *poolinfo;
- libxl_topologyinfo topology;
+ libxl_cputopology *topology;
libxl_dominfo info;
if ((opt = def_getopt(argc, argv, "", "cpupool-numa-split", 0)) != -1)
@@ -5825,21 +5829,22 @@ int main_cpupoolnumasplit(int argc, char **argv)
return -ERROR_FAIL;
}
- if (libxl_get_topologyinfo(ctx, &topology)) {
+ topology = libxl_get_cpu_topology(ctx, &n_cpus);
+ if (topology == NULL) {
fprintf(stderr, "libxl_get_topologyinfo failed\n");
return -ERROR_FAIL;
}
if (libxl_cpumap_alloc(ctx, &cpumap)) {
fprintf(stderr, "Failed to allocate cpumap\n");
- libxl_topologyinfo_dispose(&topology);
+ libxl_cputopology_list_free(topology, n_cpus);
return -ERROR_FAIL;
}
/* Reset Pool-0 to 1st node: first add cpus, then remove cpus to avoid
a cpupool without cpus in between */
- node = topology.nodemap.array[0];
+ node = topology[0].node;
if (libxl_cpupool_cpuadd_node(ctx, 0, node, &n)) {
fprintf(stderr, "error on adding cpu to Pool 0\n");
return -ERROR_FAIL;
@@ -5853,9 +5858,9 @@ int main_cpupoolnumasplit(int argc, char **argv)
}
n = 0;
- for (c = 0; c < topology.nodemap.entries; c++) {
- if (topology.nodemap.array[c] == node) {
- topology.nodemap.array[c] = LIBXL_CPUARRAY_INVALID_ENTRY;
+ for (c = 0; c < n_cpus; c++) {
+ if (topology[c].node == node) {
+ topology[c].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY;
libxl_cpumap_set(&cpumap, n);
n++;
}
@@ -5880,12 +5885,12 @@ int main_cpupoolnumasplit(int argc, char **argv)
}
memset(cpumap.map, 0, cpumap.size);
- for (c = 0; c < topology.nodemap.entries; c++) {
- if (topology.nodemap.array[c] == LIBXL_CPUARRAY_INVALID_ENTRY) {
+ for (c = 0; c < n_cpus; c++) {
+ if (topology[c].node == LIBXL_CPUTOPOLOGY_INVALID_ENTRY) {
continue;
}
- node = topology.nodemap.array[c];
+ node = topology[c].node;
ret = -libxl_cpupool_cpuremove_node(ctx, 0, node, &n);
if (ret) {
fprintf(stderr, "error on removing cpu from Pool 0\n");
@@ -5907,15 +5912,15 @@ int main_cpupoolnumasplit(int argc, char **argv)
goto out;
}
- for (p = c; p < topology.nodemap.entries; p++) {
- if (topology.nodemap.array[p] == node) {
- topology.nodemap.array[p] = LIBXL_CPUARRAY_INVALID_ENTRY;
+ for (p = c; p < n_cpus; p++) {
+ if (topology[p].node == node) {
+ topology[p].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY;
}
}
}
out:
- libxl_topologyinfo_dispose(&topology);
+ libxl_cputopology_list_free(topology, n_cpus);
libxl_cpumap_dispose(&cpumap);
return ret;