[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2 of 8] xen, libxc: introduce node maps and masks
Following suit from cpumap and cpumask implementations. Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx> diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -54,6 +54,11 @@ int xc_get_cpumap_size(xc_interface *xch return (xc_get_max_cpus(xch) + 7) / 8; } +int xc_get_nodemap_size(xc_interface *xch) +{ + return (xc_get_max_nodes(xch) + 7) / 8; +} + xc_cpumap_t xc_cpumap_alloc(xc_interface *xch) { int sz; @@ -64,6 +69,16 @@ xc_cpumap_t xc_cpumap_alloc(xc_interface return calloc(1, sz); } +xc_nodemap_t xc_nodemap_alloc(xc_interface *xch) +{ + int sz; + + sz = xc_get_nodemap_size(xch); + if (sz == 0) + return NULL; + return calloc(1, sz); +} + int xc_readconsolering(xc_interface *xch, char *buffer, unsigned int *pnr_chars, diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -330,12 +330,20 @@ int xc_get_cpumap_size(xc_interface *xch /* allocate a cpumap */ xc_cpumap_t xc_cpumap_alloc(xc_interface *xch); - /* +/* * NODEMAP handling */ +typedef uint8_t *xc_nodemap_t; + /* return maximum number of NUMA nodes the hypervisor supports */ int xc_get_max_nodes(xc_interface *xch); +/* return array size for nodemap */ +int xc_get_nodemap_size(xc_interface *xch); + +/* allocate a nodemap */ +xc_nodemap_t xc_nodemap_alloc(xc_interface *xch); + /* * DOMAIN DEBUGGING FUNCTIONS */ diff --git a/xen/common/domctl.c b/xen/common/domctl.c --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -118,6 +118,30 @@ int xenctl_bitmap_to_cpumask(cpumask_var return err; } +int nodemask_to_xenctl_bitmap(struct xenctl_bitmap *xenctl_nodemap, + const nodemask_t *nodemask) +{ + return bitmap_to_xenctl_bitmap(xenctl_nodemap, cpumask_bits(nodemask), + MAX_NUMNODES); +} + +int xenctl_bitmap_to_nodemask(nodemask_t *nodemask, + const struct xenctl_bitmap *xenctl_nodemap) +{ + int err = 0; + + if ( alloc_nodemask_var(nodemask) ) { + err = xenctl_bitmap_to_bitmap(nodes_addr(*nodemask), xenctl_nodemap, + MAX_NUMNODES); + if ( err ) + free_nodemask_var(*nodemask); + } + else + err = -ENOMEM; + + return err; +} + static inline int is_free_domid(domid_t dom) { struct domain *d; diff --git a/xen/include/xen/nodemask.h b/xen/include/xen/nodemask.h --- a/xen/include/xen/nodemask.h +++ b/xen/include/xen/nodemask.h @@ -298,6 +298,53 @@ static inline int __nodemask_parse(const } #endif +/* + * nodemask_var_t: struct nodemask for stack usage. + * + * See definition of cpumask_var_t in include/xen//cpumask.h. + */ +#if MAX_NUMNODES > 2 * BITS_PER_LONG +#include <xen/xmalloc.h> + +typedef nodemask_t *nodemask_var_t; + +#define nr_nodemask_bits (BITS_TO_LONGS(MAX_NUMNODES) * BITS_PER_LONG) + +static inline bool_t alloc_nodemask_var(nodemask_var_t *mask) +{ + *(void **)mask = _xmalloc(nr_nodemask_bits / 8, sizeof(long)); + return *mask != NULL; +} + +static inline bool_t zalloc_nodemask_var(nodemask_var_t *mask) +{ + *(void **)mask = _xzalloc(nr_nodemask_bits / 8, sizeof(long)); + return *mask != NULL; +} + +static inline void free_nodemask_var(nodemask_var_t mask) +{ + xfree(mask); +} +#else +typedef nodemask_t nodemask_var_t; + +static inline bool_t alloc_nodemask_var(nodemask_var_t *mask) +{ + return 1; +} + +static inline bool_t zalloc_nodemask_var(nodemask_var_t *mask) +{ + nodes_clear(*mask); + return 1; +} + +static inline void free_nodemask_var(nodemask_var_t mask) +{ +} +#endif + #if MAX_NUMNODES > 1 #define for_each_node_mask(node, mask) \ for ((node) = first_node(mask); \ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |