support of cpupools in xl
PATCH 1/1 support of cpupools in xl
Hi,
attached patch adds support of cpupools in xl and libxl. The patch is based on my previous correction of cpumask handling! See
http://lists.xensource.com/archives/html/xen-devel/2010-08/msg00086.html
Juergen
Signature · 5 lines
Juergen Gross Principal Developer Operating Systems TSP ES&S SWE OS6 Telephone: +49 (0) 89 3222 2967 Fujitsu Technology Solutions e-mail: [email protected] Domagkstr. 28 Internet: ts.fujitsu.com D-80807 Muenchen Company details: ts.fujitsu.com/imprint.html
Signed-off-by [email protected]
tools/libxl/libxl.c +176 -3
@@ -526,16 +526,27 @@ libxl_poolinfo * libxl_list_pool(libxl_clibxl_poolinfo *libxl_list_pool (libxl_ctx *ctx,int *nb_pool) {libxl_poolinfo *ptr; -int i; +int i, m;xc_cpupoolinfo_t *info; -int size =256 ; +int size;uint32_t poolid; +libxl_physinfo physinfo; +int mapsize; +uint64_t *cpumap; - ptr =calloc (size,sizeof (libxl_poolinfo)); +if (libxl_get_physinfo (ctx, &physinfo) !=0 ) { +XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"getting phys info" ); +return NULL ; + } + mapsize = (physinfo.max_phys_cpus +63 ) /64 ; + size = physinfo.max_phys_cpus +32 ; + + ptr =calloc (size,sizeof (libxl_poolinfo) + mapsize *sizeof (*cpumap));if (!ptr) {XL_LOG_ERRNO (ctx,XL_LOG_ERROR ,"allocating cpupool info" );return NULL ; } + cpumap = (uint64_t *)(ptr + size); poolid =0 ;for (i =0 ; i < size; i++) {
@@ -543,6 +554,13 @@ libxl_poolinfo * libxl_list_pool(libxl_cif (info ==NULL )break ; ptr[i].poolid = info->cpupool_id; + ptr[i].sched_id = info->sched_id; + ptr[i].n_dom = info->n_dom; + ptr[i].cpumap_size = info->cpumap_size; + ptr[i].cpumap = cpumap; +for (m =0 ; m < mapsize; m++) + cpumap[m] = info->cpumap[m]; + cpumap += mapsize; poolid = info->cpupool_id +1 ;free (info); }
@@ -3000,3 +3018,158 @@ int libxl_file_reference_unmap(libxl_ctxreturn ret ==0 ?0 :ERROR_FAIL ; } + +int libxl_get_freecpus (libxl_ctx *ctx,int *n_cpus,uint64_t **cpumap) +{ +libxl_physinfo info; +int mapsize; + +if (libxl_get_physinfo (ctx, &info) !=0 ) +return ERROR_FAIL ; + + mapsize = (info.max_phys_cpus +63 ) /64 ; + *cpumap =calloc (mapsize,sizeof (**cpumap)); +if (!*cpumap) +return ERROR_NOMEM ; + +if (xc_cpupool_freeinfo (ctx->xch, *cpumap, info.max_phys_cpus)) { +free (*cpumap); + *cpumap =NULL ; +return ERROR_FAIL ; + } + + *n_cpus = info.max_phys_cpus; +return 0 ; +} + +int libxl_create_cpupool (libxl_ctx *ctx,const char *name,int schedid, +uint64_t *cpumap,int n_cpus,libxl_uuid *uuid, +uint32_t *poolid) +{ +int rc; +int i; +xs_transaction_t t; +char *uuid_string; + + uuid_string =libxl_uuid2string (ctx, *uuid); +if (!uuid_string) +return ERROR_NOMEM ; + + rc =xc_cpupool_create (ctx->xch, poolid, schedid); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc, +"Could not create cpupool" ); +return ERROR_FAIL ; + } + +for (i =0 ; i < n_cpus; i++) +if (cpumap[i /64 ] & (1L << (i %64 ))) { + rc =xc_cpupool_addcpu (ctx->xch, *poolid, i); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc, +"Error moving cpu to cpupool" ); +return ERROR_FAIL ; + } + } + +for (;;) { + t =xs_transaction_start (ctx->xsh); + +xs_mkdir (ctx->xsh, t,libxl_sprintf (ctx,"/local/pool/%d" , *poolid)); +xs_write (ctx->xsh, t,libxl_sprintf (ctx,"/local/pool/%d/uuid" , *poolid), + uuid_string,strlen (uuid_string)); +xs_write (ctx->xsh, t,libxl_sprintf (ctx,"/local/pool/%d/name" , *poolid), + name,strlen (name)); + +if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) +return 0 ; + } +} + +int libxl_destroy_cpupool (libxl_ctx *ctx,uint32_t poolid) +{ +int rc, i; +xc_cpupoolinfo_t *info; +xs_transaction_t t; + + info =xc_cpupool_getinfo (ctx->xch, poolid); +if (info ==NULL ) +return ERROR_NOMEM ; + + rc =ERROR_INVAL ; +if ((info->cpupool_id != poolid) || (info->n_dom)) + goto out; + +for (i =0 ; i < info->cpumap_size; i++) +if (info->cpumap[i /64 ] & (1L << (i %64 ))) { + rc =xc_cpupool_removecpu (ctx->xch, poolid, i); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc, +"Error removing cpu from cpupool" ); + rc =ERROR_FAIL ; + goto out; + } + } + + rc =xc_cpupool_destroy (ctx->xch, poolid); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc,"Could not destroy cpupool" ); + rc =ERROR_FAIL ; + goto out; + } + +for (;;) { + t =xs_transaction_start (ctx->xsh); + +xs_rm (ctx->xsh,XBT_NULL ,libxl_sprintf (ctx,"/local/pool/%d" , poolid)); + +if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) +break ; + } + + rc =0 ; + +out: +free (info); + +return rc; +} + +int libxl_cpupool_cpuadd (libxl_ctx *ctx,uint32_t poolid,int cpu) +{ +int rc; + + rc =xc_cpupool_addcpu (ctx->xch, poolid, cpu); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc, +"Error moving cpu to cpupool" ); +return ERROR_FAIL ; + } +return 0 ; +} + +int libxl_cpupool_cpuremove (libxl_ctx *ctx,uint32_t poolid,int cpu) +{ +int rc; + + rc =xc_cpupool_removecpu (ctx->xch, poolid, cpu); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc, +"Error removing cpu from cpupool" ); +return ERROR_FAIL ; + } +return 0 ; +} + +int libxl_cpupool_movedomain (libxl_ctx *ctx,uint32_t poolid,uint32_t domid) +{ +int rc; + + rc =xc_cpupool_movedomain (ctx->xch, poolid, domid); +if (rc) { +XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , rc, +"Error moving domain to cpupool" ); +return ERROR_FAIL ; + } +return 0 ; +}
tools/libxl/libxl.h +13 -0
@@ -51,6 +51,10 @@ typedef struct {typedef struct {uint32_t poolid; +uint32_t sched_id; +uint32_t n_dom; +uint32_t cpumap_size; +uint64_t *cpumap; }libxl_poolinfo ; typedef struct {
@@ -666,6 +670,15 @@ int libxl_device_net2_del(libxl_ctx *ctxint libxl_device_net2_del (libxl_ctx *ctx,libxl_device_net2 *net2,int wait); +int libxl_get_freecpus (libxl_ctx *ctx,int *n_cpus,uint64_t **cpumap); +int libxl_create_cpupool (libxl_ctx *ctx,const char *name,int schedid, +uint64_t *cpumap,int n_cpus,libxl_uuid *uuid, +uint32_t *poolid); +int libxl_destroy_cpupool (libxl_ctx *ctx,uint32_t poolid); +int libxl_cpupool_cpuadd (libxl_ctx *ctx,uint32_t poolid,int cpu); +int libxl_cpupool_cpuremove (libxl_ctx *ctx,uint32_t poolid,int cpu); +int libxl_cpupool_movedomain (libxl_ctx *ctx,uint32_t poolid,uint32_t domid); +/* common paths */ const char *libxl_sbindir_path (void );const char *libxl_bindir_path (void );
tools/libxl/libxl_utils.c +33 -0
@@ -31,6 +31,17 @@#include "libxl_utils.h" #include "libxl_internal.h" +struct schedid_name { +char *name; +int id; +}; + +static struct schedid_name schedid_name[] = { + {"credit" ,XEN_SCHEDULER_CREDIT }, + {"sedf" ,XEN_SCHEDULER_SEDF }, + {"credit2" ,XEN_SCHEDULER_CREDIT2 }, + {NULL ,-1 } +};unsigned long libxl_get_required_shadow_memory (unsigned long maxmem_kb,unsigned int smp_cpus) {
@@ -116,6 +127,28 @@ int libxl_name_to_poolid(libxl_ctx *ctx, } }return -1 ; +} + +int libxl_name_to_schedid (libxl_ctx *ctx,const char *name) +{ +int i; + +for (i =0 ; schedid_name[i].name !=NULL ; i++) +if (strcmp (name, schedid_name[i].name) ==0 ) +return schedid_name[i].id; + +return -1 ; +} + +char *libxl_schedid_to_name (libxl_ctx *ctx,int schedid) +{ +int i; + +for (i =0 ; schedid_name[i].name !=NULL ; i++) +if (schedid_name[i].id == schedid) +return schedid_name[i].name; + +return "unknown" ; }int libxl_get_stubdom_id (libxl_ctx *ctx,int guest_domid)
tools/libxl/libxl_utils.h +2 -0
@@ -23,6 +23,8 @@ char *libxl_domid_to_name(libxl_ctx *ctxchar *libxl_domid_to_name (libxl_ctx *ctx,uint32_t domid);int libxl_name_to_poolid (libxl_ctx *ctx,const char *name,uint32_t *poolid);char *libxl_poolid_to_name (libxl_ctx *ctx,uint32_t poolid); +int libxl_name_to_schedid (libxl_ctx *ctx,const char *name); +char *libxl_schedid_to_name (libxl_ctx *ctx,int schedid);int libxl_get_stubdom_id (libxl_ctx *ctx,int guest_domid);int libxl_is_stubdom (libxl_ctx *ctx,uint32_t domid,uint32_t *target_domid);int libxl_create_logfile (libxl_ctx *ctx,char *name,char **full_name);
tools/libxl/xl.h +6 -0
@@ -79,6 +79,12 @@ int main_network2attach(int argc, char *int main_network2attach (int argc,char **argv);int main_network2list (int argc,char **argv);int main_network2detach (int argc,char **argv); +int main_poolcreate (int argc,char **argv); +int main_poollist (int argc,char **argv); +int main_pooldestroy (int argc,char **argv); +int main_poolcpuadd (int argc,char **argv); +int main_poolcpuremove (int argc,char **argv); +int main_poolmigrate (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdimpl.c +452 -5
484 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +35 -0
@@ -336,6 +336,41 @@ struct cmd_spec cmd_table[] = { "destroy a domain's version 2 virtual network device", "<Domain> <DevId>", }, + {"pool-create" , + &main_poolcreate, +"Create a CPU pool based an ConfigFile" , +"[options] <ConfigFile> [vars]" , +"-h, --help Print this help.\n" +"-f=FILE, --defconfig=FILE Use the given configuration file.\n" +"-n, --dryrun Dry run - prints the resulting configuration." + }, + { "pool-list", + &main_poollist, +"List CPU pools on host" , +"[-l|--long] [-c|--cpus] [<CPU Pool>]" , +"-l, --long Output all CPU pool details.\n" +"-c, --cpus Output list of CPUs used by a pool" + }, + { "pool-destroy", + &main_pooldestroy, +"Deactivates a CPU pool" , +"<CPU Pool>" , + }, + { "pool-cpu-add", + &main_poolcpuadd, +"Adds a CPU to a CPU pool" , +"<CPU Pool> <CPU nr>" , + }, + { "pool-cpu-remove", + &main_poolcpuremove, +"Removes a CPU from a CPU pool" , +"<CPU Pool> <CPU nr>" , + }, + { "pool-migrate", + &main_poolmigrate, +"Moves a domain into a CPU pool" , + "<Domain> <CPU Pool>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Juergen Gross writes ("[Xen-devel] [Patch] support of cpupools in xl"):
Quoted 2 lines
attached patch adds support of cpupools in xl and libxl. The patch is based on my previous correction of cpumask handling! See
Thanks.
The cpumask handling fix was changed - see the discussion. Can you confirm whether your patch needs to be updated ?
Ian.