support of cpu pools in xl
PATCH 1/1 support of cpu pools in xl
Hi,
attached patch adds support of cpu pools in xl/libxl.
Ian, I didn't split up this patch, because the updated libxl_cpumask structure requires changes to xl in any case.
BTW: I realized that libxlu_cfg_l.c seems to be in the repository. Isn't this
file generated by make? I think it should be removed there.
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
Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migrate
tools/libxl/libxl.c +206 -16
@@ -609,9 +609,17 @@ libxl_poolinfo * libxl_list_pool(libxl_clibxl_poolinfo *libxl_list_pool (libxl_ctx *ctx,int *nb_pool) {libxl_poolinfo *ptr; -int i, ret; -xc_cpupoolinfo_t info[256 ]; -int size =256 ; +int i, m; +xc_cpupoolinfo_t *info; +int size; +uint32_t poolid; +libxl_physinfo physinfo; + +if (libxl_get_physinfo (ctx, &physinfo) !=0 ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting phys info" ); +return NULL ; + } + size = physinfo.max_cpu_id +32 ; ptr =calloc (size,sizeof (libxl_poolinfo));if (!ptr) {
@@ -619,16 +627,23 @@ libxl_poolinfo * libxl_list_pool(libxl_creturn NULL ; } - ret =xc_cpupool_getinfo (ctx->xch,0 ,256 , info); -if (ret<0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting cpupool info" ); -return NULL ; + poolid =0 ; +for (i =0 ; i < size; i++) { + info =xc_cpupool_getinfo (ctx->xch, poolid); +if (info ==NULL ) +break ; + ptr[i].poolid = info->cpupool_id; + ptr[i].sched_id = info->sched_id; + ptr[i].n_dom = info->n_dom; +if (libxl_cpumap_alloc (&ptr[i].cpumap, physinfo.max_cpu_id +1 )) +break ; +for (m =0 ; m < ptr[i].cpumap.size /sizeof (*ptr[i].cpumap.map); m++) + ptr[i].cpumap.map[m] = info->cpumap[m]; + poolid = info->cpupool_id +1 ; +free (info); } -for (i =0 ; i < ret; i++) { - ptr[i].poolid = info[i].cpupool_id; - } - *nb_pool = ret; + *nb_pool = i;return ptr; }
@@ -2928,7 +2943,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctxc_domaininfo_t domaininfo;xc_vcpuinfo_t vcpuinfo;xc_physinfo_t physinfo = {0 }; -unsigned num_cpuwords;if (xc_domain_getinfolist (ctx->xch, domid,1 , &domaininfo) !=1 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting infolist" );
@@ -2944,10 +2958,9 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctreturn NULL ; } - num_cpuwords = ((physinfo.max_cpu_id +64 ) /64 );for (*nb_vcpu =0 ; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) { - ptr->cpumap =malloc (num_cpuwords *sizeof (*ptr->cpumap)); -if (!ptr->cpumap) { +if (libxl_cpumap_alloc (&ptr->cpumap, *nrcpus)) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"allocating cpumap" );return NULL ; }if (xc_vcpu_getinfo (ctx->xch, domid, *nb_vcpu, &vcpuinfo) ==-1 ) {
@@ -2955,7 +2968,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctreturn NULL ; }if (xc_vcpu_getaffinity (ctx->xch, domid, *nb_vcpu, - ptr->cpumap, ((*nrcpus) +7 ) /8 ) ==-1 ) { + ptr->cpumap.map, ((*nrcpus) +7 ) /8 ) ==-1 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting vcpu affinity" );return NULL ; }
@@ -3359,3 +3372,180 @@ void libxl_file_reference_destroy(libxl_libxl__file_reference_unmap (f);free (f->path); } + +int libxl_get_freecpus (libxl_ctx *ctx,libxl_cpumap *cpumap) +{ +libxl_physinfo info; +int ret; + +if (libxl_get_physinfo (ctx, &info) !=0 ) +return ERROR_FAIL ; + + ret =libxl_cpumap_alloc (cpumap, info.max_cpu_id +1 ); +if (ret) +return ret; + +if (xc_cpupool_freeinfo (ctx->xch, cpumap->map, cpumap->size)) { +free (cpumap->map); + cpumap->map =NULL ; +return ERROR_FAIL ; + } + +return 0 ; +} + +int libxl_create_cpupool (libxl_ctx *ctx,char *name,int schedid, +libxl_cpumap cpumap,libxl_uuid *uuid, +uint32_t *poolid) +{ +libxl__gc gc =LIBXL_INIT_GC (ctx); +int rc; +int i; +xs_transaction_t t; +char *uuid_string; + + uuid_string =libxl__uuid2string (&gc, *uuid); +if (!uuid_string) +return ERROR_NOMEM ; + + rc =xc_cpupool_create (ctx->xch, poolid, schedid); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"Could not create cpupool" ); +return ERROR_FAIL ; + } + +for (i =0 ; i < cpumap.size *8 ; i++) +if (cpumap.map[i /64 ] & (1L << (i %64 ))) { + rc =xc_cpupool_addcpu (ctx->xch, *poolid, i); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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 (&gc,"/local/pool/%d" , *poolid)); +libxl__xs_write (&gc, t,libxl__sprintf (&gc,"/local/pool/%d/uuid" , *poolid), + uuid_string); +libxl__xs_write (&gc, t,libxl__sprintf (&gc,"/local/pool/%d/name" , *poolid), + name); + +if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) +return 0 ; + } +} + +int libxl_destroy_cpupool (libxl_ctx *ctx,uint32_t poolid) +{ +libxl__gc gc =LIBXL_INIT_GC (ctx); +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) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"Error removing cpu from cpupool" ); + rc =ERROR_FAIL ; + goto out; + } + } + + rc =xc_cpupool_destroy (ctx->xch, poolid); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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 (&gc,"/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) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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) +{ +libxl__gc gc =LIBXL_INIT_GC (ctx); +int rc; +char *dom_path; +char *vm_path; +char *poolname; +xs_transaction_t t; + + dom_path =libxl__xs_get_dompath (&gc, domid); +if (!dom_path) { +return ERROR_FAIL ; + } + + rc =xc_cpupool_movedomain (ctx->xch, poolid, domid); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"Error moving domain to cpupool" ); +return ERROR_FAIL ; + } + + poolname =libxl__poolid_to_name (&gc, poolid); + vm_path =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/vm" , dom_path)); +for (; vm_path;) { + t =xs_transaction_start (ctx->xsh); + +libxl__xs_write (&gc, t,libxl__sprintf (&gc,"%s/pool_name" , vm_path), poolname); + +if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) +break ; + } + +return 0 ; +}
tools/libxl/libxl.h +9 -2
@@ -140,8 +140,6 @@ void libxl_string_list_destroy(libxl_strtypedef char **libxl_key_value_list ;void libxl_key_value_list_destroy (libxl_key_value_list *kvl); - -typedef uint64_t *libxl_cpumap ;typedef uint32_t libxl_hwcap [8 ];
@@ -488,6 +486,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,libxl_cpumap *cpumap); +int libxl_create_cpupool (libxl_ctx *ctx,char *name,int schedid, +libxl_cpumap cpumap,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.idl +10 -4
@@ -16,8 +16,6 @@ libxl_string_list = Builtin("string_list libxl_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy", passby=PASS_BY_REFERENCE) libxl_key_value_list = Builtin("key_value_list", destructor_fn="libxl_key_value_list_destroy", passby=PASS_BY_REFERENCE) libxl_file_reference = Builtin("file_reference", destructor_fn="libxl_file_reference_destroy", passby=PASS_BY_REFERENCE) - -libxl_cpumap = Builtin("cpumap", destructor_fn="free") libxl_hwcap = Builtin("hwcap")
@@ -44,9 +42,17 @@ SHUTDOWN_* constant."""), ("vcpu_online", uint32), ], destructor_fn=None) +libxl_cpumap = Struct("cpumap", [ + ("size", uint32, False, "number of bytes in map"), + ("map", Reference(uint64)), + ]) + libxl_poolinfo = Struct("poolinfo", [ - ("poolid", uint32) - ], destructor_fn=None) + ("poolid", uint32), + ("sched_id", uint32), + ("n_dom", uint32), + ("cpumap", libxl_cpumap) + ], destructor_fn="libxl_poolinfo_destroy") libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid),
tools/libxl/libxl_utils.c +74 -8
102 lines not on this page · raw message
tools/libxl/libxl_utils.h +6 -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);
@@ -74,5 +76,9 @@ int libxl_devid_to_device_net2(libxl_ctx* 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_test (libxl_cpumap *cpumap,int cpu); +void libxl_cpumap_set (libxl_cpumap *cpumap,int cpu); +void libxl_cpumap_reset (libxl_cpumap *cpumap,int cpu);#endif
tools/libxl/libxltypes.py +4 -1
@@ -131,7 +131,10 @@ class Reference(Type): kwargs.setdefault('passby', PASS_BY_VALUE) kwargs.setdefault('namespace', ty.namespace) - typename = ty.typename[len(kwargs['namespace']):] + + typename = ty.typename + if ty.namespace: + typename = typename[len(kwargs['namespace']):] Type.__init__(self, typename + " *", **kwargs) #
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 +454 -7
500 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +35 -0
@@ -338,6 +338,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
Quoted 6 lines · Juergen Gross
attached patch adds support of cpu pools in xl/libxl. Ian, I didn't split up this patch, because the updated
libxl_cpumaskstructure requires changes to xl in any case.
That's fine.
Quoted 2 lines
BTW: I realized that
libxlu_cfg_l.cseems to be in the repository. Isn't this file generated by make? I think it should be removed there.
In an ideal world, yes. I think this was a workaround for buggy versions of flex observed in the field or something.
Quoted 22 lines
Signed-off-by [email protected]Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migratediff -r
d978675f3d53tools/libxl/libxl.ctools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +1
-3@@ -609,9 +609,17 @@ libxl_poolinfo * libxl_list_pool(libxl_c libxl_poolinfo * libxl_list_pool(libxl_ctx *ctx, int *nb_pool) { libxl_poolinfo *ptr; - int i, ret; - xc_cpupoolinfo_t info[256]; - int size = 256; + int i, m;
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 libxl_poolinfo * libxl_list_pool(libxl_c · line 622
Quoted 10 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +10
-0+ xc_cpupoolinfo_t *info; + int size; + uint32_t poolid; + libxl_physinfo physinfo; + + if (libxl_get_physinfo(ctx, &physinfo) != 0) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting phys info"); + return NULL; + } + size = physinfo.max_cpu_id + 32;
Where does the number 32 come from?
Quoted 13 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +2
-4ptr = calloc(size, sizeof(libxl_poolinfo)); if (!ptr) {@@ -619,16 +627,23 @@ libxl_poolinfo * libxl_list_pool(libxl_c return NULL; } - ret = xc_cpupool_getinfo(ctx->xch, 0, 256, info); - if (ret<0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting cpupool info"); - return NULL; + poolid = 0; + for (i = 0; i < size; i++) {
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 libxl_poolinfo * libxl_list_pool(libxl_c · line 641
Quoted 10 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +10
-0+ info = xc_cpupool_getinfo(ctx->xch, poolid); + if (info == NULL) + break; + ptr[i].poolid = info->cpupool_id; + ptr[i].sched_id = info->sched_id; + ptr[i].n_dom = info->n_dom; + if (libxl_cpumap_alloc(&ptr[i].cpumap, physinfo.max_cpu_id + 1)) + break; + for (m = 0; m < ptr[i].cpumap.size / sizeof(*ptr[i].cpumap.map); m++) + ptr[i].cpumap.map[m] = info->cpumap[m];
I guess if "physinfo.max_cpu_id + 1" does not correspond to info->cpumap_size then that is a serious error but if it does happen then you may run over the end of either ptr[i].cpumap.map or info->cpumap.
Ian.
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Juergen Gross
attached patch adds support of cpu pools in xl/libxl. Ian, I didn't split up this patch, because the updated
libxl_cpumaskstructure requires changes to xl in any case.
Quoted 7 lines
That's fine.
Quoted 2 lines
BTW: I realized that
libxlu_cfg_l.cseems to be in the repository. Isn't this file generated by make? I think it should be removed there.In an ideal world, yes. I think this was a workaround for buggy versions of flex observed in the field or something.
How nice ;-)
Quoted 27 lines
Quoted 27 lines
Signed-off-by [email protected]Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migratediff -r
d978675f3d53tools/libxl/libxl.ctools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +5
-3@@ -609,9 +609,17 @@ libxl_poolinfo * libxl_list_pool(libxl_c libxl_poolinfo * libxl_list_pool(libxl_ctx *ctx, int *nb_pool) { libxl_poolinfo *ptr; - int i, ret; - xc_cpupoolinfo_t info[256]; - int size = 256; + int i, m; + xc_cpupoolinfo_t *info; + int size; + uint32_t poolid; + libxl_physinfo physinfo;
Quoted 8 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 libxl_poolinfo * libxl_list_pool(libxl_c · line 622
Quoted 6 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +6
-0+ + if (libxl_get_physinfo(ctx,&physinfo) != 0) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting phys info"); + return NULL; + } + size = physinfo.max_cpu_id + 32;Where does the number 32 come from?
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
Quoted 21 lines
Quoted 21 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +9
-4ptr = calloc(size, sizeof(libxl_poolinfo)); if (!ptr) {@@ -619,16 +627,23 @@ libxl_poolinfo * libxl_list_pool(libxl_c return NULL; } - ret = xc_cpupool_getinfo(ctx->xch, 0, 256, info); - if (ret<0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting cpupool info"); - return NULL; + poolid = 0; + for (i = 0; i< size; i++) { + info = xc_cpupool_getinfo(ctx->xch, poolid); + if (info == NULL) + break; + ptr[i].poolid = info->cpupool_id; + ptr[i].sched_id = info->sched_id; + ptr[i].n_dom = info->n_dom; + if (libxl_cpumap_alloc(&ptr[i].cpumap, physinfo.max_cpu_id + 1))
Quoted 8 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 libxl_poolinfo * libxl_list_pool(libxl_c · line 641
Quoted 3 lines
tools/libxl/libxl.c Fri Sep 17 07:42:30 2010 +0200 renamed from tools/libxl/libxl.c Thu Sep 16 18:29:26 2010 +0100 +3
-0+ break; + for (m = 0; m< ptr[i].cpumap.size / sizeof(*ptr[i].cpumap.map); m++) + ptr[i].cpumap.map[m] = info->cpumap[m];I guess if "physinfo.max_cpu_id + 1" does not correspond to
info->cpumap_sizethen that is a serious error but if it does happen then you may run over the end of either ptr[i].cpumap.map orinfo->cpumap.
Changed (introducing '0' when info->cpumap_size is too small).
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
Support of cpu pools in xl:
library functions
xl pool-create
xl pool-list
xl pool-destroy
xl pool-cpu-add
xl pool-cpu-remove
xl pool-migrate
tools/libxl/libxl.c +207 -16
@@ -609,9 +609,17 @@ libxl_poolinfo * libxl_list_pool(libxl_clibxl_poolinfo *libxl_list_pool (libxl_ctx *ctx,int *nb_pool) {libxl_poolinfo *ptr; -int i, ret; -xc_cpupoolinfo_t info[256 ]; -int size =256 ; +int i, m; +xc_cpupoolinfo_t *info; +int size; +uint32_t poolid; +libxl_physinfo physinfo; + +if (libxl_get_physinfo (ctx, &physinfo) !=0 ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting phys info" ); +return NULL ; + } + size = physinfo.max_cpu_id +32 ;/* allow some inactive cpu pools */ ptr =calloc (size,sizeof (libxl_poolinfo));if (!ptr) {
@@ -619,16 +627,24 @@ libxl_poolinfo * libxl_list_pool(libxl_creturn NULL ; } - ret =xc_cpupool_getinfo (ctx->xch,0 ,256 , info); -if (ret<0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting cpupool info" ); -return NULL ; + poolid =0 ; +for (i =0 ; i < size; i++) { + info =xc_cpupool_getinfo (ctx->xch, poolid); +if (info ==NULL ) +break ; + ptr[i].poolid = info->cpupool_id; + ptr[i].sched_id = info->sched_id; + ptr[i].n_dom = info->n_dom; +if (libxl_cpumap_alloc (&ptr[i].cpumap, physinfo.max_cpu_id +1 )) +break ; +for (m =0 ; m < ptr[i].cpumap.size /sizeof (*ptr[i].cpumap.map); m++) + ptr[i].cpumap.map[m] = (info->cpumap_size > (m *sizeof (*ptr[i].cpumap.map))) ? + info->cpumap[m] :0 ; + poolid = info->cpupool_id +1 ; +free (info); } -for (i =0 ; i < ret; i++) { - ptr[i].poolid = info[i].cpupool_id; - } - *nb_pool = ret; + *nb_pool = i;return ptr; }
@@ -2928,7 +2944,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctxc_domaininfo_t domaininfo;xc_vcpuinfo_t vcpuinfo;xc_physinfo_t physinfo = {0 }; -unsigned num_cpuwords;if (xc_domain_getinfolist (ctx->xch, domid,1 , &domaininfo) !=1 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting infolist" );
@@ -2944,10 +2959,9 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctreturn NULL ; } - num_cpuwords = ((physinfo.max_cpu_id +64 ) /64 );for (*nb_vcpu =0 ; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) { - ptr->cpumap =malloc (num_cpuwords *sizeof (*ptr->cpumap)); -if (!ptr->cpumap) { +if (libxl_cpumap_alloc (&ptr->cpumap, *nrcpus)) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"allocating cpumap" );return NULL ; }if (xc_vcpu_getinfo (ctx->xch, domid, *nb_vcpu, &vcpuinfo) ==-1 ) {
@@ -2955,7 +2969,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctreturn NULL ; }if (xc_vcpu_getaffinity (ctx->xch, domid, *nb_vcpu, - ptr->cpumap, ((*nrcpus) +7 ) /8 ) ==-1 ) { + ptr->cpumap.map, ((*nrcpus) +7 ) /8 ) ==-1 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting vcpu affinity" );return NULL ; }
@@ -3359,3 +3373,180 @@ void libxl_file_reference_destroy(libxl_libxl__file_reference_unmap (f);free (f->path); } + +int libxl_get_freecpus (libxl_ctx *ctx,libxl_cpumap *cpumap) +{ +libxl_physinfo info; +int ret; + +if (libxl_get_physinfo (ctx, &info) !=0 ) +return ERROR_FAIL ; + + ret =libxl_cpumap_alloc (cpumap, info.max_cpu_id +1 ); +if (ret) +return ret; + +if (xc_cpupool_freeinfo (ctx->xch, cpumap->map, cpumap->size)) { +free (cpumap->map); + cpumap->map =NULL ; +return ERROR_FAIL ; + } + +return 0 ; +} + +int libxl_create_cpupool (libxl_ctx *ctx,char *name,int schedid, +libxl_cpumap cpumap,libxl_uuid *uuid, +uint32_t *poolid) +{ +libxl__gc gc =LIBXL_INIT_GC (ctx); +int rc; +int i; +xs_transaction_t t; +char *uuid_string; + + uuid_string =libxl__uuid2string (&gc, *uuid); +if (!uuid_string) +return ERROR_NOMEM ; + + rc =xc_cpupool_create (ctx->xch, poolid, schedid); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"Could not create cpupool" ); +return ERROR_FAIL ; + } + +for (i =0 ; i < cpumap.size *8 ; i++) +if (cpumap.map[i /64 ] & (1L << (i %64 ))) { + rc =xc_cpupool_addcpu (ctx->xch, *poolid, i); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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 (&gc,"/local/pool/%d" , *poolid)); +libxl__xs_write (&gc, t,libxl__sprintf (&gc,"/local/pool/%d/uuid" , *poolid), + uuid_string); +libxl__xs_write (&gc, t,libxl__sprintf (&gc,"/local/pool/%d/name" , *poolid), + name); + +if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) +return 0 ; + } +} + +int libxl_destroy_cpupool (libxl_ctx *ctx,uint32_t poolid) +{ +libxl__gc gc =LIBXL_INIT_GC (ctx); +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) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"Error removing cpu from cpupool" ); + rc =ERROR_FAIL ; + goto out; + } + } + + rc =xc_cpupool_destroy (ctx->xch, poolid); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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 (&gc,"/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) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__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) +{ +libxl__gc gc =LIBXL_INIT_GC (ctx); +int rc; +char *dom_path; +char *vm_path; +char *poolname; +xs_transaction_t t; + + dom_path =libxl__xs_get_dompath (&gc, domid); +if (!dom_path) { +return ERROR_FAIL ; + } + + rc =xc_cpupool_movedomain (ctx->xch, poolid, domid); +if (rc) { +LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc, +"Error moving domain to cpupool" ); +return ERROR_FAIL ; + } + + poolname =libxl__poolid_to_name (&gc, poolid); + vm_path =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/vm" , dom_path)); +for (; vm_path;) { + t =xs_transaction_start (ctx->xsh); + +libxl__xs_write (&gc, t,libxl__sprintf (&gc,"%s/pool_name" , vm_path), poolname); + +if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) +break ; + } + +return 0 ; +}
tools/libxl/libxl.h +9 -2
@@ -140,8 +140,6 @@ void libxl_string_list_destroy(libxl_strtypedef char **libxl_key_value_list ;void libxl_key_value_list_destroy (libxl_key_value_list *kvl); - -typedef uint64_t *libxl_cpumap ;typedef uint32_t libxl_hwcap [8 ];
@@ -488,6 +486,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,libxl_cpumap *cpumap); +int libxl_create_cpupool (libxl_ctx *ctx,char *name,int schedid, +libxl_cpumap cpumap,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.idl +10 -4
@@ -16,8 +16,6 @@ libxl_string_list = Builtin("string_list libxl_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy", passby=PASS_BY_REFERENCE) libxl_key_value_list = Builtin("key_value_list", destructor_fn="libxl_key_value_list_destroy", passby=PASS_BY_REFERENCE) libxl_file_reference = Builtin("file_reference", destructor_fn="libxl_file_reference_destroy", passby=PASS_BY_REFERENCE) - -libxl_cpumap = Builtin("cpumap", destructor_fn="free") libxl_hwcap = Builtin("hwcap")
@@ -44,9 +42,17 @@ SHUTDOWN_* constant."""), ("vcpu_online", uint32), ], destructor_fn=None) +libxl_cpumap = Struct("cpumap", [ + ("size", uint32, False, "number of bytes in map"), + ("map", Reference(uint64)), + ]) + libxl_poolinfo = Struct("poolinfo", [ - ("poolid", uint32) - ], destructor_fn=None) + ("poolid", uint32), + ("sched_id", uint32), + ("n_dom", uint32), + ("cpumap", libxl_cpumap) + ], destructor_fn="libxl_poolinfo_destroy") libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid),
tools/libxl/libxl_utils.c +74 -8
102 lines not on this page · raw message
tools/libxl/libxl_utils.h +6 -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);
@@ -74,5 +76,9 @@ int libxl_devid_to_device_net2(libxl_ctx* 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_test (libxl_cpumap *cpumap,int cpu); +void libxl_cpumap_set (libxl_cpumap *cpumap,int cpu); +void libxl_cpumap_reset (libxl_cpumap *cpumap,int cpu);#endif
tools/libxl/libxltypes.py +4 -1
@@ -131,7 +131,10 @@ class Reference(Type): kwargs.setdefault('passby', PASS_BY_VALUE) kwargs.setdefault('namespace', ty.namespace) - typename = ty.typename[len(kwargs['namespace']):] + + typename = ty.typename + if ty.namespace: + typename = typename[len(kwargs['namespace']):] Type.__init__(self, typename + " *", **kwargs) #
tools/libxl/libxlu_cfg_l.c +8 -22
@@ -54,6 +54,7 @@ typedef unsigned char flex_uint8_t;typedef unsigned char flex_uint8_t ;typedef unsigned short int flex_uint16_t ;typedef unsigned int flex_uint32_t ; +#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN
@@ -83,8 +84,6 @@ typedef unsigned int flex_uint32_t;#ifndef UINT32_MAX #define UINT32_MAX (4294967295U)#endif - -#endif /* ! C99 */ #endif /* ! FLEXINT_H */
@@ -159,15 +158,7 @@ typedef void* yyscan_t;/* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. -* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. -* Ditto for the __ia64__ case accordingly. -*/ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -496,7 +487,7 @@ void xlu__cfg_yyset_column(int column_nvoid xlu__cfg_yyset_column (int column_no,yyscan_t yyscanner); -#line 500 "libxlu_cfg_l.c" +#line 491 "libxlu_cfg_l.c"#define INITIAL 0#define lexerr 1
@@ -632,12 +623,7 @@ static int input (yyscan_t yyscanner );/* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */
@@ -645,7 +631,7 @@ static int input (yyscan_t yyscanner );/* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO fwrite( yytext, yyleng, 1, yyout )#endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@@ -656,7 +642,7 @@ static int input (yyscan_t yyscanner );if (YY_CURRENT_BUFFER_LVALUE ->yy_is_interactive ) \ { \int c ='*' ; \ -size_t n; \ +int n; \for ( n =0 ; n < max_size && \ (c =getc ( yyin )) !=EOF && c !='\n' ; ++n ) \ buf[n] = (char ) c; \
@@ -744,7 +730,7 @@ YY_DECL#line 37 "libxlu_cfg_l.l" -#line 748 "libxlu_cfg_l.c" +#line 734 "libxlu_cfg_l.c" yylval = yylval_param;
@@ -944,7 +930,7 @@ YY_RULE_SETUP#line 82 "libxlu_cfg_l.l"YY_FATAL_ERROR ("flex scanner jammed" ); YY_BREAK -#line 948 "libxlu_cfg_l.c" +#line 934 "libxlu_cfg_l.c"case YY_STATE_EOF (INITIAL ):case YY_STATE_EOF (lexerr):yyterminate ();
@@ -1687,8 +1673,8 @@ YY_BUFFER_STATE xlu__cfg_yy_scan_string/** Setup the input buffer state to scan the given bytes. The next call to xlu__cfg_yylex() will * scan from a @e copy of @a bytes. -* @param yybytes the byte buffer to scan -* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. +* @param bytes the byte buffer to scan +* @param len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */
tools/libxl/libxlu_cfg_l.h +2 -16
@@ -58,6 +58,7 @@ typedef unsigned char flex_uint8_t;typedef unsigned char flex_uint8_t ;typedef unsigned short int flex_uint16_t ;typedef unsigned int flex_uint32_t ; +#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN
@@ -87,8 +88,6 @@ typedef unsigned int flex_uint32_t;#ifndef UINT32_MAX #define UINT32_MAX (4294967295U)#endif - -#endif /* ! C99 */ #endif /* ! FLEXINT_H */
@@ -132,15 +131,7 @@ typedef void* yyscan_t;/* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. -* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. -* Ditto for the __ia64__ case accordingly. -*/ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif #ifndef YY_TYPEDEF_YY_BUFFER_STATE
@@ -310,12 +301,7 @@ static int yy_flex_strlen (yyconst char/* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Number of entries by which start-condition stack grows. */
@@ -352,6 +338,6 @@ extern int xlu__cfg_yylex \#line 82 "libxlu_cfg_l.l" -#line 356 "libxlu_cfg_l.h" +#line 342 "libxlu_cfg_l.h"#undef xlu__cfg_yyIN_HEADER#endif /* xlu__cfg_yyHEADER_H */
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 +454 -7
500 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +35 -0
@@ -338,6 +338,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
Quoted 9 lines · Juergen Gross
Quoted 5 lines · Ian Campbell
Quoted 3 lines · Juergen Gross
+ size = physinfo.max_cpu_id + 32;
Where does the number 32 come from?
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
What is the purpose of these inactive cpupools?
Ian Campbell writes ("Re: [Xen-devel] Re: [Patch] support of cpu pools in xl"):
Quoted 5 lines · Juergen Gross
Quoted 2 lines
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
What is the purpose of these inactive cpupools?
Amongst other things, I would guess, the creation or removal of cpupools !
I think we should have a #define rather than the magic number 32 though.
Ian.
Quoted 9 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] Re: [Patch] support of cpu pools in xl"):
Quoted 5 lines · Juergen Gross
Quoted 2 lines
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
What is the purpose of these inactive cpupools?
Amongst other things, I would guess, the creation or removal of cpupools !
I don't think so, libxl_create_cpupool returns a new poolid for a newly created pool, so they are not needed for that.
libxl_destroy_cpupool would only be used to delete a real cpupool, you don't need dummy pools to remove pools.
BTW I noticed that we have libxl_list_pool vs libxl_{create,destroy}_cpupool and libxl_cpupool_{cpuadd,cpuremove,movedomain}. I think the interface should use cpupool throughout and not just pool to make it clear what it is a pool of. IOW libxl_list_pool should be libxl_list_cpupool, the type should be called libxl_cpupool and functions such as libxl_name_to_poolid should instead be libxl_name_to_cpupoolid.
Ian.
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] Re: [Patch] support of cpu pools in xl"):
Quoted 5 lines · Juergen Gross
Quoted 2 lines
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
What is the purpose of these inactive cpupools?
Amongst other things, I would guess, the creation or removal of cpupools !
"Inactive cpupools" were meant to be cpupools without any cpus and domains assigned to them.
They can exist for a short time during creation and removal, but due to explicitly removing all cpus, too.
Quoted 2 lines
I don't think so,
libxl_create_cpupoolreturns a new poolid for a newly created pool, so they are not needed for that.
They have a poolid, but there might be more cpupools than cpus in the system. This was the reason for the "+ 32". But I agree, this should be done via a #define.
Quoted 7 lines
BTW I noticed that we have
libxl_list_poolvs libxl_{create,destroy}_cpupool and libxl_cpupool_{cpuadd,cpuremove,movedomain}. I think the interface should use cpupool throughout and not just pool to make it clear what it is a pool of. IOWlibxl_list_poolshould belibxl_list_cpupool, the type should be calledlibxl_cpupooland functions such aslibxl_name_to_poolidshould instead belibxl_name_to_cpupoolid.
Okay, I'll change it.
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
(I'm just back from vacation, sorry for the delay replying)
Quoted 9 lines · Juergen Gross
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] Re: [Patch] support of cpu pools in xl"):
Quoted 5 lines · Juergen Gross
Quoted 2 lines
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
What is the purpose of these inactive cpupools?
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Amongst other things, I would guess, the creation or removal of cpupools !
"Inactive cpupools" were meant to be cpupools without any cpus and domains assigned to them.
They can exist for a short time during creation and removal, but due to explicitly removing all cpus, too.
That makes sense in itself but then why do you need to add a magic number?
I think libxl_list_pool should look more like libxl_list_domain, which implies that the xc_cpupool_getinfo interface should not be changed as in your previous patch since the new interface seems to preclude this usage. You really need retain the first poolid + a max number of entries
+ return the actual number of entries used interface in order to have a usable interface when there is no way to query the maximum pool id.
The problem with the interface you are trying to define is compounded by the fact that the returned array is sparse and so in fact you will run out of space at poolid == nr_cpus+32 rather than at number of pools == nr_cpus+32. (Note that in contrast libxl_list_domain returns a compact array so that you run out of space at 1024 domains total, not domid 1024).
IMHO libxl_list_{pool,domain} should also go realloc the buffer and go around again in the case where the underlying xc call returned the maximum number of entries -- since there may be more to come. Perhaps this is less likely in the domain case (1024 domains is quite a lot, at least today) but it seem more plausible in the pool case? I think this is probably a separate issue though and getting the basic semantics of xc_cpupool_getinfo/libxl_list_pool is more important.
Quoted 6 lines
Quoted 2 lines
I don't think so,
libxl_create_cpupoolreturns a new poolid for a newly created pool, so they are not needed for that.They have a poolid, but there might be more cpupools than cpus in the system. This was the reason for the "+ 32". But I agree, this should be done via a #define.
I think it should be done by defining an interface which doesn't need arbitrary magic numbers in the first place.
Ian.
Quoted 30 lines · Ian Campbell
(I'm just back from vacation, sorry for the delay replying)
Quoted 9 lines · Juergen Gross
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] Re: [Patch] support of cpu pools in xl"):
Quoted 5 lines · Juergen Gross
Quoted 2 lines
I just wanted to be able to support some (inactive) cpupools without any cpu allocated. It's just a number which should normally be large enough.
What is the purpose of these inactive cpupools?
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Amongst other things, I would guess, the creation or removal of cpupools !
"Inactive cpupools" were meant to be cpupools without any cpus and domains assigned to them.
They can exist for a short time during creation and removal, but due to explicitly removing all cpus, too.That makes sense in itself but then why do you need to add a magic number?
I think
libxl_list_poolshould look more likelibxl_list_domain, which implies that thexc_cpupool_getinfointerface should not be changed as in your previous patch since the new interface seems to preclude this usage. You really need retain the first poolid + a max number of entries
+ return the actual number of entries used interface in order to have a usable interface when there is no way to query the maximum pool id.
Quoted 6 lines
The problem with the interface you are trying to define is compounded by the fact that the returned array is sparse and so in fact you will run out of space at poolid == nr_cpus+32 rather than at number of pools == nr_cpus+32. (Note that in contrast
libxl_list_domainreturns a compact array so that you run out of space at 1024 domains total, not domid 1024).
I think you misread the code. The returned array is NOT sparse. Please note that the hypervisor will return the info of the next cpu pool with poolid equal or larger as the requested one (that's the reason why poolid is a vital return info).
Quoted 8 lines
IMHO libxl_list_{pool,domain} should also go realloc the buffer and go around again in the case where the underlying xc call returned the maximum number of entries -- since there may be more to come. Perhaps this is less likely in the domain case (1024 domains is quite a lot, at least today) but it seem more plausible in the pool case? I think this is probably a separate issue though and getting the basic semantics of xc_cpupool_getinfo/libxl_list_pool is more important.
I agree realloc-ing the buffer for the array in libxl_list_pool is a better solution (now easy to do as the cpumasks are allocated separately).
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
I don't think so,
libxl_create_cpupoolreturns a new poolid for a newly created pool, so they are not needed for that.They have a poolid, but there might be more cpupools than cpus in the system. This was the reason for the "+ 32". But I agree, this should be done via a #define.
I think it should be done by defining an interface which doesn't need arbitrary magic numbers in the first place.
I'll resend modified patches.
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
Quoted 8 lines · Juergen Gross
Quoted 2 lines
The problem with the interface you are trying to define is
compounded by
Quoted 1 line
the fact that the returned array is sparse and so in fact you will
run
Quoted 1 line
out of space at poolid == nr_cpus+32 rather than at number of pools
==
Quoted 1 line
nr_cpus+32. (Note that in contrast
libxl_list_domainreturns a
Quoted 8 lines
compact
Quoted 2 lines
array so that you run out of space at 1024 domains total, not domid 1024).
I think you misread the code. The returned array is NOT sparse. Please note that the hypervisor will return the info of the next cpu pool with poolid equal or larger as the requested one (that's the reason why poolid is a vital return info).
Ah, I think that makes sense, thanks for taking the time to explain. I'll take another look at the latest patch set.
Ian.
Juergen Gross writes ("Re: [Xen-devel] Re: [Patch] support of cpu pools in xl"):
Quoted 5 lines · Ian Campbell
Quoted 2 lines
In an ideal world, yes. I think this was a workaround for buggy versions of flex observed in the field or something.
How nice ;-)
I don't think it's really that bad an answer. Doing it this way means you can compile if you don't have flex, and the flex output itself is portable to any compiler/platform and not dependent on any part of the configuration.
If you send patches which touch the .l files my build test will rebuild the .c files so I don't mind if you leave out the changes to the .l in your patch.
Ian.