aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl_utils.c
diff options
context:
space:
mode:
authorDario Faggioli <raistlin@linux.it>2012-07-06 13:17:42 +0100
committerDario Faggioli <raistlin@linux.it>2012-07-06 13:17:42 +0100
commitea12318767e45d96d929827068ee410eaf09e711 (patch)
tree50290d598e00be3e41bc27f86335145bb1e91b36 /tools/libxl/libxl_utils.c
parentb13da96bb67a6392c94556991d222fcdd8af9257 (diff)
downloadxen-ea12318767e45d96d929827068ee410eaf09e711.tar.gz
xen-ea12318767e45d96d929827068ee410eaf09e711.tar.bz2
xen-ea12318767e45d96d929827068ee410eaf09e711.zip
libxl: rename libxl_cpumap to libxl_bitmap
And leave to the caller the burden of knowing and remembering what kind of bitmap each instance of libxl_bitmap is. This is basically just some s/libxl_cpumap/libxl_bitmap/ (and some other related interface name substitution, e.g., libxl_for_each_cpu) in a bunch of files, with no real functional change involved. A specific allocation helper is introduced, besides libxl_bitmap_alloc(). It is called libxl_cpu_bitmap_alloc() and is meant at substituting the old libxl_cpumap_alloc(). It is just something easier to use in cases where one wants to allocate a libxl_bitmap that is going to serve as a cpu map. This is because we want to be able to deal with both cpu and NUMA node maps, but we don't want to duplicate all the various helpers and wrappers. While at it, add the usual initialization function, common to all libxl data structures. Signed-off-by: Dario Faggioli <dario.faggioli@citrix.eu.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxl/libxl_utils.c')
-rw-r--r--tools/libxl/libxl_utils.c67
1 files changed, 29 insertions, 38 deletions
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 29f430d977..0301bd00a3 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -487,79 +487,70 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
return rc;
}
-int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap, int max_cpus)
+int libxl_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *bitmap, int n_bits)
{
GC_INIT(ctx);
int sz;
- int rc;
- if (max_cpus < 0) {
- rc = ERROR_INVAL;
- goto out;
- }
- if (max_cpus == 0)
- max_cpus = libxl_get_max_cpus(ctx);
- if (max_cpus == 0) {
- rc = ERROR_FAIL;
- goto out;
- }
-
- sz = (max_cpus + 7) / 8;
- cpumap->map = libxl__calloc(NOGC, sizeof(*cpumap->map), sz);
- cpumap->size = sz;
+ sz = (n_bits + 7) / 8;
+ bitmap->map = libxl__calloc(NOGC, sizeof(*bitmap->map), sz);
+ bitmap->size = sz;
- rc = 0;
- out:
GC_FREE;
- return rc;
+ return 0;
+}
+
+void libxl_bitmap_init(libxl_bitmap *map)
+{
+ memset(map, '\0', sizeof(*map));
}
-void libxl_cpumap_dispose(libxl_cpumap *map)
+void libxl_bitmap_dispose(libxl_bitmap *map)
{
free(map->map);
}
-int libxl_cpumap_test(const libxl_cpumap *cpumap, int cpu)
+int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit)
{
- if (cpu >= cpumap->size * 8)
+ if (bit >= bitmap->size * 8)
return 0;
- return (cpumap->map[cpu / 8] & (1 << (cpu & 7))) ? 1 : 0;
+ return (bitmap->map[bit / 8] & (1 << (bit & 7))) ? 1 : 0;
}
-void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu)
+void libxl_bitmap_set(libxl_bitmap *bitmap, int bit)
{
- if (cpu >= cpumap->size * 8)
+ if (bit >= bitmap->size * 8)
return;
- cpumap->map[cpu / 8] |= 1 << (cpu & 7);
+ bitmap->map[bit / 8] |= 1 << (bit & 7);
}
-void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu)
+void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
{
- if (cpu >= cpumap->size * 8)
+ if (bit >= bitmap->size * 8)
return;
- cpumap->map[cpu / 8] &= ~(1 << (cpu & 7));
+ bitmap->map[bit / 8] &= ~(1 << (bit & 7));
}
-int libxl_cpumap_count_set(const libxl_cpumap *cpumap)
+int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
{
- int i, nr_set_cpus = 0;
- libxl_for_each_set_cpu(i, *cpumap)
- nr_set_cpus++;
+ int i, nr_set_bits = 0;
+ libxl_for_each_set_bit(i, *bitmap)
+ nr_set_bits++;
- return nr_set_cpus;
+ return nr_set_bits;
}
/* NB. caller is responsible for freeing the memory */
-char *libxl_cpumap_to_hex_string(libxl_ctx *ctx, const libxl_cpumap *cpumap)
+char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap)
{
GC_INIT(ctx);
- int i = cpumap->size;
- char *p = libxl__zalloc(NOGC, cpumap->size * 2 + 3);
+ int i = bitmap->size;
+ char *p = libxl__zalloc(NOGC, bitmap->size * 2 + 3);
char *q = p;
strncpy(p, "0x", 2);
p += 2;
while(--i >= 0) {
- sprintf(p, "%02x", cpumap->map[i]);
+ sprintf(p, "%02x", bitmap->map[i]);
p += 2;
}
*p = '\0';