change tools cpumaps to uint8_t
PATCH 1/1 change tools cpumaps to uint8_t
Cpumap types in tools (libxc and libxl) are changed to be based on bytes like in the interface to the hypervisor.
To make handling easier the size of used cpumaps is always based on the number of physical cpus supported by the hypervisor. This eliminates the need to keep track of the cpumap size in external interfaces.
In libxl a macro for cycling through a cpumap is added (libxl_for_each_cpu).
Interfaces changed:libxl_set_vcpuaffinity()libxl_cpumap_alloc()xc_vcpu_setaffinity()xc_vcpu_getaffinity()xc_cpupool_freeinfo()
10 files changed, 190 insertions(+), 152 deletions(-) tools/libxc/xc_cpupool.c | 50 ++++++++++++++--------------- tools/libxc/xc_domain.c | 26 ++++++++++++--- tools/libxc/xc_misc.c | 15 ++++++++ tools/libxc/xenctrl.h | 40 +++++++++++++++-------- tools/libxl/libxl.c | 63 ++++++++++++++++++++----------------- tools/libxl/libxl.h | 4 +- tools/libxl/libxl_utils.c | 21 +++++++----- tools/libxl/libxl_utils.h | 4 +- tools/libxl/xl_cmdimpl.c | 57 ++++++++++++++------------------- tools/python/xen/lowlevel/xc/xc.c | 62 +++++++++++++++---------------------
# HG changeset patch
# User Juergen Gross <[email protected]> # Date 1288331667 -7200
# Node ID d60c1258c6b75f6de0bb9e09b27ac9e86c974908 # Parent 5611ec8238ec6cee24a1a1712301e7939e489007 change tools cpumaps to uint8_t
Cpumap types in tools (libxc and libxl) are changed to be based on bytes like in the interface to the hypervisor.
To make handling easier the size of used cpumaps is always based on the number of physical cpus supported by the hypervisor. This eliminates the need to keep track of the cpumap size in external interfaces.
In libxl a macro for cycling through a cpumap is added (libxl_for_each_cpu).
Interfaces changed:libxl_set_vcpuaffinity()libxl_cpumap_alloc()xc_vcpu_setaffinity()xc_vcpu_getaffinity()xc_cpupool_freeinfo()
tools/libxc/xc_cpupool.c +24 -26
@@ -32,11 +32,6 @@ }while ( (ret <0 ) && (errno ==EAGAIN ) );return ret; -} - -static int get_cpumap_size (xc_interface *xch) -{ -return (xc_get_max_cpus (xch) +7 ) /8 ; } int xc_cpupool_create(xc_interface *xch,
@@ -75,12 +70,10 @@int err =0 ;xc_cpupoolinfo_t *info =NULL ;int local_size; -int cpumap_size; -int size;DECLARE_SYSCTL ;DECLARE_HYPERCALL_BUFFER (uint8_t, local); - local_size =get_cpumap_size (xch); + local_size =xc_get_cpumap_size (xch);if (!local_size) {PERROR ("Could not get number of cpus" );
@@ -93,9 +86,6 @@return NULL ; } - cpumap_size = (local_size +sizeof (*info->cpumap) -1 ) /sizeof (*info->cpumap); - size =sizeof (xc_cpupoolinfo_t) + cpumap_size *sizeof (*info->cpumap); - sysctl.cmd = XEN_SYSCTL_cpupool_op; sysctl.u.cpupool_op.op =XEN_SYSCTL_CPUPOOL_OP_INFO ; sysctl.u.cpupool_op.cpupool_id = poolid;
@@ -107,23 +97,31 @@if ( err <0 ) goto out; - info =malloc (size); + info =calloc (1 ,sizeof (xc_cpupoolinfo_t));if ( !info ) goto out; -memset (info,0 , size); - info->cpumap_size = local_size *8 ; - info->cpumap = (uint64_t *)(info +1 ); - + info->cpumap =xc_cpumap_alloc (xch); +if (!info->cpumap) { +free (info); + goto out; + } info->cpupool_id = sysctl.u.cpupool_op.cpupool_id; info->sched_id = sysctl.u.cpupool_op.sched_id; info->n_dom = sysctl.u.cpupool_op.n_dom; -bitmap_byte_to_64 (info->cpumap, local, local_size *8 ); +memcpy (info->cpumap, local, local_size); out:xc_hypercall_buffer_free (xch, local);return info; +} + +void xc_cpupool_infofree (xc_interface *xch, +xc_cpupoolinfo_t *info) +{ +free (info->cpumap); +free (info); } int xc_cpupool_addcpu(xc_interface *xch,
@@ -165,19 +163,19 @@return do_sysctl_save (xch, &sysctl); } -uint64_t *xc_cpupool_freeinfo (xc_interface *xch, -int *cpusize) +xc_cpumap_t xc_cpupool_freeinfo (xc_interface *xch) {int err =-1 ; -uint64_t *cpumap =NULL ; +xc_cpumap_t cpumap =NULL ; +int mapsize;DECLARE_SYSCTL ;DECLARE_HYPERCALL_BUFFER (uint8_t, local); - *cpusize =get_cpumap_size (xch); -if (*cpusize ==0 ) + mapsize =xc_get_cpumap_size (xch); +if (mapsize ==0 )return NULL ; - local =xc_hypercall_buffer_alloc (xch, local, *cpusize); + local =xc_hypercall_buffer_alloc (xch, local, mapsize);if ( local ==NULL ) {PERROR ("Could not allocate locked memory for xc_cpupool_freeinfo" );return NULL ;
@@ -186,18 +184,18 @@ sysctl.cmd = XEN_SYSCTL_cpupool_op; sysctl.u.cpupool_op.op =XEN_SYSCTL_CPUPOOL_OP_FREEINFO ;set_xen_guest_handle (sysctl.u.cpupool_op.cpumap.bitmap, local); - sysctl.u.cpupool_op.cpumap.nr_cpus = *cpusize *8 ; + sysctl.u.cpupool_op.cpumap.nr_cpus = mapsize *8 ; err =do_sysctl_save (xch, &sysctl);if ( err <0 ) goto out; - cpumap =calloc ((*cpusize +sizeof (*cpumap) -1 ) /sizeof (*cpumap),sizeof (*cpumap)); + cpumap =xc_cpumap_alloc (xch);if (cpumap ==NULL ) goto out; -bitmap_byte_to_64 (cpumap, local, *cpusize *8 ); +memcpy (cpumap, local, mapsize); out:xc_hypercall_buffer_free (xch, local);
tools/libxc/xc_domain.c +21 -5
@@ -113,11 +113,19 @@int xc_vcpu_setaffinity (xc_interface *xch,uint32_t domid,int vcpu, -uint64_t *cpumap,int cpusize) +xc_cpumap_t cpumap) {DECLARE_DOMCTL ;DECLARE_HYPERCALL_BUFFER (uint8_t, local);int ret =-1 ; +int cpusize; + + cpusize =xc_get_cpumap_size (xch); +if (!cpusize) + { +PERROR ("Could not get number of cpus" ); + goto out; + } local =xc_hypercall_buffer_alloc (xch, local, cpusize);if ( local ==NULL )
@@ -130,7 +138,7 @@ domctl.domain = (domid_t )domid; domctl.u.vcpuaffinity.vcpu = vcpu; -bitmap_64_to_byte (local, cpumap, cpusize *8 ); +memcpy (local, cpumap, cpusize);set_xen_guest_handle (domctl.u.vcpuaffinity.cpumap.bitmap, local);
@@ -148,14 +156,22 @@int xc_vcpu_getaffinity (xc_interface *xch,uint32_t domid,int vcpu, -uint64_t *cpumap,int cpusize) +xc_cpumap_t cpumap) {DECLARE_DOMCTL ;DECLARE_HYPERCALL_BUFFER (uint8_t, local);int ret =-1 ; +int cpusize; + + cpusize =xc_get_cpumap_size (xch); +if (!cpusize) + { +PERROR ("Could not get number of cpus" ); + goto out; + } local =xc_hypercall_buffer_alloc (xch, local, cpusize); -if (local ==NULL ) +if (local ==NULL ) {PERROR ("Could not allocate memory for getvcpuaffinity domctl hypercall" ); goto out;
@@ -170,7 +186,7 @@ ret =do_domctl (xch, &domctl); -bitmap_byte_to_64 (cpumap, local, cpusize *8 ); +memcpy (cpumap, local, cpusize);xc_hypercall_buffer_free (xch, local); out:
tools/libxc/xc_misc.c +15 -0
@@ -33,6 +33,21 @@ max_cpus = physinfo.max_cpu_id +1 ;return max_cpus; +} + +int xc_get_cpumap_size (xc_interface *xch) +{ +return (xc_get_max_cpus (xch) +7 ) /8 ; +} + +xc_cpumap_t xc_cpumap_alloc (xc_interface *xch) +{ +int sz; + + sz =xc_get_cpumap_size (xch); +if (sz ==0 ) +return NULL ; +return calloc (1 , sz); } int xc_readconsolering(xc_interface *xch,
tools/libxc/xenctrl.h +27 -13
@@ -281,6 +281,20 @@#define xc_hypercall_buffer_free_pages (_xch, _name, _nr) xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name), _nr)/* +* CPUMAP handling +*/ +typedef uint8_t *xc_cpumap_t ; + +/* return maximum number of cpus the hypervisor supports */ +int xc_get_max_cpus (xc_interface *xch); + +/* return array size for cpumap */ +int xc_get_cpumap_size (xc_interface *xch); + +/* allocate a cpumap */ +xc_cpumap_t xc_cpumap_alloc (xc_interface *xch); + +/* * DOMAIN DEBUGGING FUNCTIONS */
@@ -347,9 +361,6 @@start_info_t s; } start_info_any_t; - -/* return maximum number of cpus the hypervisor supports */ -int xc_get_max_cpus (xc_interface *xch); int xc_domain_create(xc_interface *xch, uint32_t ssidref,
@@ -462,13 +473,11 @@int xc_vcpu_setaffinity (xc_interface *xch,uint32_t domid,int vcpu, -uint64_t *cpumap, -int cpusize); +xc_cpumap_t cpumap);int xc_vcpu_getaffinity (xc_interface *xch,uint32_t domid,int vcpu, -uint64_t *cpumap, -int cpusize); +xc_cpumap_t cpumap);/** * This function will return information about one or more domains. It is
@@ -670,8 +679,7 @@uint32_t cpupool_id;uint32_t sched_id;uint32_t n_dom; -uint32_t cpumap_size;/* max number of cpus in map */ -uint64_t *cpumap; +xc_cpumap_t cpumap; } xc_cpupoolinfo_t;/**
@@ -701,10 +709,18 @@* starting at the given id. * @parm xc_handle a handle to an open hypervisor interface * @parm poolid lowest id for which info is returned -* return cpupool info ptr (obtained by malloc) +* return cpupool info ptr (to be freed via xc_cpupool_infofree) */ xc_cpupoolinfo_t *xc_cpupool_getinfo (xc_interface *xch,uint32_t poolid); + +/** +* Free cpupool info. Used to free info obtained via xc_cpupool_getinfo. +* @parm xc_handle a handle to an open hypervisor interface +* @parm info area to free +*/ +void xc_cpupool_infofree (xc_interface *xch, +xc_cpupoolinfo_t *info);/** * Add cpu to a cpupool. cpu may be -1 indicating the first unassigned.
@@ -746,11 +762,9 @@* Return map of cpus not in any cpupool. * * @parm xc_handle a handle to an open hypervisor interface -* @parm cpusize where to store array size in bytes * return cpumap array on success, NULL else */ -uint64_t *xc_cpupool_freeinfo (xc_interface *xch, -int *cpusize); +xc_cpumap_t xc_cpupool_freeinfo (xc_interface *xch);/*
tools/libxl/libxl.c +35 -28
151 lines not on this page · raw message
tools/libxl/libxl.h +2 -2
@@ -145,7 +145,7 @@typedef struct {uint32_t size;/* number of bytes in map */ -uint64_t *map; +uint8_t *map; }libxl_cpumap ;void libxl_cpumap_destroy (libxl_cpumap *map);
@@ -464,7 +464,7 @@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, -uint64_t *cpumap,int nrcpus); +libxl_cpumap *cpumap);int libxl_set_vcpuonline (libxl_ctx *ctx,uint32_t domid,uint32_t bitmask);int libxl_get_sched_id (libxl_ctx *ctx);
tools/libxl/libxl_utils.c +13 -8
@@ -708,15 +708,20 @@return rc; } -int libxl_cpumap_alloc (libxl_cpumap *cpumap,int max_cpus) +int libxl_cpumap_alloc (libxl_ctx *ctx,libxl_cpumap *cpumap) { -int elems; +int max_cpus; +int sz; - elems = (max_cpus +63 ) /64 ; - cpumap->map =calloc (elems,sizeof (*cpumap->map)); + 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 = elems *8 ;/* size in bytes */ + cpumap->size = sz;return 0 ; }
@@ -729,21 +734,21 @@ {if (cpu >= cpumap->size *8 )return 0 ; -return (cpumap->map[cpu /64 ] & (1L << (cpu &63 ))) ?1 :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 /64 ] |=1L << (cpu &63 ); + 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 /64 ] &= ~(1L << (cpu &63 )); + cpumap->map[cpu /8 ] &= ~(1 << (cpu &7 )); }int libxl_get_max_cpus (libxl_ctx *ctx)
tools/libxl/libxl_utils.h +3 -1
@@ -76,9 +76,11 @@* return -1 if there are an error */ int libxl_check_device_model_version (libxl_ctx *ctx,char *path); -int libxl_cpumap_alloc (libxl_cpumap *cpumap,int max_cpus); +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); +#define libxl_for_each_cpu (var, map) for (var = 0; var < (map).size * 8; var++) +#endif
tools/libxl/xl_cmdimpl.c +24 -33
156 lines not on this page · raw message
tools/python/xen/lowlevel/xc/xc.c +26 -36
145 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 7 lines · Juergen Gross
Cpumap types in tools (libxc and libxl) are changed to be based on bytes like in the interface to the hypervisor.
To make handling easier the size of used cpumaps is always based on the number of physical cpus supported by the hypervisor. This eliminates the need to keep track of the cpumap size in external interfaces.
In libxl a macro for cycling through a cpumap is added (libxl_for_each_cpu).
Quoted 8 lines
Interfaces changed:
libxl_set_vcpuaffinity()libxl_cpumap_alloc()xc_vcpu_setaffinity()xc_vcpu_getaffinity()xc_cpupool_freeinfo()Signed-off-by [email protected]
Looks good, thanks.
Quoted 15 lines
10 files changed, 190 insertions(+), 152 deletions(-) tools/libxc/xc_cpupool.c | 50 ++++++++++++++--------------- tools/libxc/xc_domain.c | 26 ++++++++++++--- tools/libxc/xc_misc.c | 15 ++++++++ tools/libxc/xenctrl.h | 40 +++++++++++++++-------- tools/libxl/libxl.c | 63 ++++++++++++++++++++----------------- tools/libxl/libxl.h | 4 +- tools/libxl/libxl_utils.c | 21 +++++++----- tools/libxl/libxl_utils.h | 4 +- tools/libxl/xl_cmdimpl.c | 57 ++++++++++++++------------------- tools/python/xen/lowlevel/xc/xc.c | 62 +++++++++++++++---------------------
Ian Jackson
AppliedRe: [PATCH] change tools cpumaps to uint8_t [and 1 more messages]
In reply to Juergen GrossJuergen Gross writes ("[Xen-devel] [PATCH] change tools cpumaps to uint8_t"):
Quoted 6 lines
Cpumap types in tools (libxc and libxl) are changed to be based on bytes like in the interface to the hypervisor.
To make handling easier the size of used cpumaps is always based on the number of physical cpus supported by the hypervisor. This eliminates the need to keep track of the cpumap size in external interfaces.
In libxl a macro for cycling through a cpumap is added (libxl_for_each_cpu).
Applied, thanks.
Ian.