[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 02 of 11] libxl: abstract libxl_cpumap to just libxl_map
More specifically: 1. introduces struct libxl_map; 2. re-implement libxl_cpumap_* on top of struct libxl_map_*; No functional nor interface changes at all. This is in preparation of the introduction of NUMA nodes maps. Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxxxxx> diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -282,11 +282,17 @@ typedef uint32_t libxl_hwcap[8]; typedef uint64_t libxl_ev_user; -typedef struct { +struct libxl_map { uint32_t size; /* number of bytes in map */ uint8_t *map; -} libxl_cpumap; -void libxl_cpumap_dispose(libxl_cpumap *map); +}; +void libxl_map_dispose(struct libxl_map *map); + +typedef struct libxl_map libxl_cpumap; +static inline void libxl_cpumap_dispose(libxl_cpumap *cpumap) +{ + return libxl_map_dispose(cpumap); +} typedef struct { /* diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -488,47 +488,53 @@ int libxl_mac_to_device_nic(libxl_ctx *c return rc; } +void libxl_map_dispose(struct libxl_map *map) +{ + free(map->map); +} + +static int libxl_map_alloc(libxl_ctx *ctx, struct libxl_map *map, int n_elems) +{ + int sz; + + sz = (n_elems + 7) / 8; + map->map = calloc(sz, sizeof(*map->map)); + if (!map->map) + return ERROR_NOMEM; + map->size = sz; + return 0; +} + +int libxl_map_test(struct libxl_map *map, int elem) +{ + if (elem >= map->size * 8) + return 0; + return (map->map[elem / 8] & (1 << (elem & 7))) ? 1 : 0; +} + +void libxl_map_set(struct libxl_map *map, int elem) +{ + if (elem >= map->size * 8) + return; + map->map[elem / 8] |= 1 << (elem & 7); +} + +void libxl_map_reset(struct libxl_map *map, int elem) +{ + if (elem >= map->size * 8) + return; + map->map[elem / 8] &= ~(1 << (elem & 7)); +} + int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap) { int max_cpus; - int sz; max_cpus = libxl_get_max_cpus(ctx); if (max_cpus == 0) return ERROR_FAIL; - sz = (max_cpus + 7) / 8; - cpumap->map = calloc(sz, sizeof(*cpumap->map)); - if (!cpumap->map) - return ERROR_NOMEM; - cpumap->size = sz; - return 0; -} - -void libxl_cpumap_dispose(libxl_cpumap *map) -{ - free(map->map); -} - -int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu) -{ - if (cpu >= cpumap->size * 8) - return 0; - return (cpumap->map[cpu / 8] & (1 << (cpu & 7))) ? 1 : 0; -} - -void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu) -{ - if (cpu >= cpumap->size * 8) - return; - cpumap->map[cpu / 8] |= 1 << (cpu & 7); -} - -void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu) -{ - if (cpu >= cpumap->size * 8) - return; - cpumap->map[cpu / 8] &= ~(1 << (cpu & 7)); + return libxl_map_alloc(ctx, cpumap, max_cpus); } int libxl_get_max_cpus(libxl_ctx *ctx) diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -63,21 +63,46 @@ int libxl_devid_to_device_nic(libxl_ctx int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid, const char *vdev, libxl_device_disk *disk); +int libxl_map_test(struct libxl_map *map, int elem); +void libxl_map_set(struct libxl_map *map, int elem); +void libxl_map_reset(struct libxl_map *map, int elem); +static inline void libxl_map_set_any(struct libxl_map *map) +{ + memset(map->map, -1, map->size); +} +static inline void libxl_map_set_none(struct libxl_map *map) +{ + memset(map->map, 0, map->size); +} +static inline int libxl_map_elem_valid(struct libxl_map *map, int elem) +{ + return elem >= 0 && elem < (map->size * 8); +} + int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap); -int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu); -void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu); -void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu); +static inline int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu) +{ + return libxl_map_test(cpumap, cpu); +} +static inline void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu) +{ + libxl_map_set(cpumap, cpu); +} +static inline void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu) +{ + libxl_map_reset(cpumap, cpu); +} static inline void libxl_cpumap_set_any(libxl_cpumap *cpumap) { - memset(cpumap->map, -1, cpumap->size); + libxl_map_set_any(cpumap); } static inline void libxl_cpumap_set_none(libxl_cpumap *cpumap) { - memset(cpumap->map, 0, cpumap->size); + libxl_map_set_none(cpumap); } static inline int libxl_cpumap_cpu_valid(libxl_cpumap *cpumap, int cpu) { - return cpu >= 0 && cpu < (cpumap->size * 8); + return libxl_map_elem_valid(cpumap, cpu); } #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++) #define libxl_for_each_set_cpu(v, m) for (v = 0; v < (m).size * 8; v++) \ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |