|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 4/4] libxl: Switch to using new topology interface
Make current users of libxl_get_cpu_topology() call
libxl_get_topology() instead.
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
---
tools/libxl/libxl.c | 25 ++++++++++++-------------
tools/libxl/libxl_numa.c | 14 +++++++-------
tools/libxl/libxl_utils.c | 24 ++++++++++++------------
tools/libxl/xl_cmdimpl.c | 44 +++++++++++++++++++++-----------------------
4 files changed, 52 insertions(+), 55 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index ee103ac..5398e41 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -6410,30 +6410,29 @@ 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, nr;
+ int cpu;
libxl_bitmap freemap;
- libxl_cputopology *topology;
+ libxl_topology *topology;
if (libxl_get_freecpus(ctx, &freemap)) {
return ERROR_FAIL;
}
- topology = libxl_get_cpu_topology(ctx, &nr);
+ topology = libxl_get_topology(ctx);
if (!topology) {
rc = ERROR_FAIL;
goto out;
}
*cpus = 0;
- for (cpu = 0; cpu < nr; cpu++) {
- if (libxl_bitmap_test(&freemap, cpu) && (topology[cpu].node == node) &&
+ for (cpu = 0; cpu < topology->cpu_num; cpu++) {
+ if (libxl_bitmap_test(&freemap, cpu) && (topology->cpu[cpu].node ==
node) &&
!libxl_cpupool_cpuadd(ctx, poolid, cpu)) {
(*cpus)++;
}
- libxl_cputopology_dispose(&topology[cpu]);
}
- free(topology);
+ libxl_topology_free(topology);
out:
libxl_bitmap_dispose(&freemap);
return rc;
@@ -6457,8 +6456,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, nr_cpus;
- libxl_cputopology *topology;
+ int cpu;
+ libxl_topology *topology;
libxl_cpupoolinfo *poolinfo;
poolinfo = libxl_list_cpupool(ctx, &n_pools);
@@ -6466,7 +6465,7 @@ int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t
poolid, int node, int
return ERROR_NOMEM;
}
- topology = libxl_get_cpu_topology(ctx, &nr_cpus);
+ topology = libxl_get_topology(ctx);
if (!topology) {
ret = ERROR_FAIL;
goto out;
@@ -6475,8 +6474,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 < nr_cpus; cpu++) {
- if ((topology[cpu].node == node) &&
+ for (cpu = 0; cpu < topology->cpu_num; cpu++) {
+ if ((topology->cpu[cpu].node == node) &&
libxl_bitmap_test(&poolinfo[p].cpumap, cpu) &&
!libxl_cpupool_cpuremove(ctx, poolid, cpu)) {
(*cpus)++;
@@ -6485,7 +6484,7 @@ int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t
poolid, int node, int
}
}
- libxl_cputopology_list_free(topology, nr_cpus);
+ libxl_topology_free(topology);
out:
libxl_cpupoolinfo_list_free(poolinfo, n_pools);
diff --git a/tools/libxl/libxl_numa.c b/tools/libxl/libxl_numa.c
index 94ca4fe..c809dc0 100644
--- a/tools/libxl/libxl_numa.c
+++ b/tools/libxl/libxl_numa.c
@@ -293,9 +293,9 @@ int libxl__get_numa_candidate(libxl__gc *gc,
int *cndt_found)
{
libxl__numa_candidate new_cndt;
- libxl_cputopology *tinfo = NULL;
+ libxl_topology *tinfo = NULL;
libxl_numainfo *ninfo = NULL;
- int nr_nodes = 0, nr_suit_nodes, nr_cpus = 0;
+ int nr_nodes = 0, nr_suit_nodes;
libxl_bitmap suitable_nodemap, nodemap;
int *vcpus_on_node, rc = 0;
@@ -341,7 +341,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,
goto out;
}
- tinfo = libxl_get_cpu_topology(CTX, &nr_cpus);
+ tinfo = libxl_get_topology(CTX);
if (tinfo == NULL) {
rc = ERROR_FAIL;
goto out;
@@ -372,7 +372,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,
* all we have to do later is summing up the right elements of the
* vcpus_on_node array.
*/
- rc = nr_vcpus_on_nodes(gc, tinfo, nr_cpus, suitable_cpumap, vcpus_on_node);
+ rc = nr_vcpus_on_nodes(gc, tinfo->cpu, tinfo->cpu_num, suitable_cpumap,
vcpus_on_node);
if (rc)
goto out;
@@ -387,7 +387,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,
if (!min_nodes) {
int cpus_per_node;
- cpus_per_node = count_cpus_per_node(tinfo, nr_cpus, nr_nodes);
+ cpus_per_node = count_cpus_per_node(tinfo->cpu, tinfo->cpu_num,
nr_nodes);
if (cpus_per_node == 0)
min_nodes = 1;
else
@@ -451,7 +451,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,
continue;
/* And the same applies if this combination is short in cpus */
- nodes_cpus = nodemap_to_nr_cpus(tinfo, nr_cpus, suitable_cpumap,
+ nodes_cpus = nodemap_to_nr_cpus(tinfo->cpu, tinfo->cpu_num,
suitable_cpumap,
&nodemap);
if (min_cpus && nodes_cpus < min_cpus)
continue;
@@ -503,7 +503,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,
libxl_bitmap_dispose(&suitable_nodemap);
libxl__numa_candidate_dispose(&new_cndt);
libxl_numainfo_list_free(ninfo, nr_nodes);
- libxl_cputopology_list_free(tinfo, nr_cpus);
+ libxl_topology_free(tinfo);
return rc;
}
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 70c21a2..3eb8684 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -751,22 +751,22 @@ int libxl_nodemap_to_cpumap(libxl_ctx *ctx,
const libxl_bitmap *nodemap,
libxl_bitmap *cpumap)
{
- libxl_cputopology *tinfo = NULL;
- int nr_cpus = 0, i, rc = 0;
+ libxl_topology *tinfo = NULL;
+ int i, rc = 0;
- tinfo = libxl_get_cpu_topology(ctx, &nr_cpus);
+ tinfo = libxl_get_topology(ctx);
if (tinfo == NULL) {
rc = ERROR_FAIL;
goto out;
}
libxl_bitmap_set_none(cpumap);
- for (i = 0; i < nr_cpus; i++) {
- if (libxl_bitmap_test(nodemap, tinfo[i].node))
+ for (i = 0; i < tinfo->cpu_num; i++) {
+ if (libxl_bitmap_test(nodemap, tinfo->cpu[i].node))
libxl_bitmap_set(cpumap, i);
}
out:
- libxl_cputopology_list_free(tinfo, nr_cpus);
+ libxl_topology_free(tinfo);
return rc;
}
@@ -796,10 +796,10 @@ int libxl_cpumap_to_nodemap(libxl_ctx *ctx,
const libxl_bitmap *cpumap,
libxl_bitmap *nodemap)
{
- libxl_cputopology *tinfo = NULL;
- int nr_cpus = 0, i, rc = 0;
+ libxl_topology *tinfo = NULL;
+ int i, rc = 0;
- tinfo = libxl_get_cpu_topology(ctx, &nr_cpus);
+ tinfo = libxl_get_topology(ctx);
if (tinfo == NULL) {
rc = ERROR_FAIL;
goto out;
@@ -807,12 +807,12 @@ int libxl_cpumap_to_nodemap(libxl_ctx *ctx,
libxl_bitmap_set_none(nodemap);
libxl_for_each_set_bit(i, *cpumap) {
- if (i >= nr_cpus)
+ if (i >= tinfo->cpu_num)
break;
- libxl_bitmap_set(nodemap, tinfo[i].node);
+ libxl_bitmap_set(nodemap, tinfo->cpu[i].node);
}
out:
- libxl_cputopology_list_free(tinfo, nr_cpus);
+ libxl_topology_free(tinfo);
return rc;
}
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index fd9beb3..824f980 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -7045,7 +7045,7 @@ int main_cpupoolcreate(int argc, char **argv)
libxl_bitmap freemap;
libxl_bitmap cpumap;
libxl_uuid uuid;
- libxl_cputopology *topology;
+ libxl_topology *topology;
int rc = -ERROR_FAIL;
SWITCH_FOREACH_OPT(opt, "hnf:", opts, "cpupool-create", 0) {
@@ -7149,18 +7149,17 @@ int main_cpupoolcreate(int argc, char **argv)
goto out_cfg;
}
if (!xlu_cfg_get_list(config, "nodes", &nodes, 0, 0)) {
- int nr;
n_cpus = 0;
n_nodes = 0;
- topology = libxl_get_cpu_topology(ctx, &nr);
+ topology = libxl_get_topology(ctx);
if (topology == NULL) {
- fprintf(stderr, "libxl_get_topologyinfo failed\n");
+ fprintf(stderr, "libxl_get_topology failed\n");
goto out_cfg;
}
while ((buf = xlu_cfg_get_listitem(nodes, n_nodes)) != NULL) {
n = atoi(buf);
- for (i = 0; i < nr; i++) {
- if ((topology[i].node == n) &&
+ for (i = 0; i < topology->cpu_num; i++) {
+ if ((topology->cpu[i].node == n) &&
libxl_bitmap_test(&freemap, i)) {
libxl_bitmap_set(&cpumap, i);
n_cpus++;
@@ -7169,7 +7168,7 @@ int main_cpupoolcreate(int argc, char **argv)
n_nodes++;
}
- libxl_cputopology_list_free(topology, nr);
+ libxl_topology_free(topology);
if (n_cpus == 0) {
fprintf(stderr, "no free cpu found\n");
@@ -7462,12 +7461,11 @@ int main_cpupoolnumasplit(int argc, char **argv)
libxl_scheduler sched;
int n_pools;
int node;
- int n_cpus;
char name[16];
libxl_uuid uuid;
libxl_bitmap cpumap;
libxl_cpupoolinfo *poolinfo;
- libxl_cputopology *topology;
+ libxl_topology *topology;
libxl_dominfo info;
SWITCH_FOREACH_OPT(opt, "", NULL, "cpupool-numa-split", 0) {
@@ -7491,22 +7489,22 @@ int main_cpupoolnumasplit(int argc, char **argv)
return -ERROR_FAIL;
}
- topology = libxl_get_cpu_topology(ctx, &n_cpus);
+ topology = libxl_get_topology(ctx);
if (topology == NULL) {
- fprintf(stderr, "libxl_get_topologyinfo failed\n");
+ fprintf(stderr, "libxl_get_topology failed\n");
return -ERROR_FAIL;
}
if (libxl_cpu_bitmap_alloc(ctx, &cpumap, 0)) {
fprintf(stderr, "Failed to allocate cpumap\n");
- libxl_cputopology_list_free(topology, n_cpus);
+ libxl_topology_free(topology);
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[0].node;
+ node = topology->cpu[0].node;
if (libxl_cpupool_cpuadd_node(ctx, 0, node, &n)) {
fprintf(stderr, "error on adding cpu to Pool 0\n");
return -ERROR_FAIL;
@@ -7520,9 +7518,9 @@ int main_cpupoolnumasplit(int argc, char **argv)
}
n = 0;
- for (c = 0; c < n_cpus; c++) {
- if (topology[c].node == node) {
- topology[c].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY;
+ for (c = 0; c < topology->cpu_num; c++) {
+ if (topology->cpu[c].node == node) {
+ topology->cpu[c].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY;
libxl_bitmap_set(&cpumap, n);
n++;
}
@@ -7547,12 +7545,12 @@ int main_cpupoolnumasplit(int argc, char **argv)
}
libxl_bitmap_set_none(&cpumap);
- for (c = 0; c < n_cpus; c++) {
- if (topology[c].node == LIBXL_CPUTOPOLOGY_INVALID_ENTRY) {
+ for (c = 0; c < topology->cpu_num; c++) {
+ if (topology->cpu[c].node == LIBXL_CPUTOPOLOGY_INVALID_ENTRY) {
continue;
}
- node = topology[c].node;
+ node = topology->cpu[c].node;
ret = -libxl_cpupool_cpuremove_node(ctx, 0, node, &n);
if (ret) {
fprintf(stderr, "error on removing cpu from Pool 0\n");
@@ -7574,15 +7572,15 @@ int main_cpupoolnumasplit(int argc, char **argv)
goto out;
}
- for (p = c; p < n_cpus; p++) {
- if (topology[p].node == node) {
- topology[p].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY;
+ for (p = c; p < topology->cpu_num; p++) {
+ if (topology->cpu[p].node == node) {
+ topology->cpu[p].node = LIBXL_CPUTOPOLOGY_INVALID_ENTRY;
}
}
}
out:
- libxl_cputopology_list_free(topology, n_cpus);
+ libxl_topology_free(topology);
libxl_bitmap_dispose(&cpumap);
return ret;
--
1.8.4.2
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |