On Fri, Apr 15, 2011 at 04:43:03PM +0900, KAMEZAWA Hiroyuki wrote: > On Fri, 15 Apr 2011 09:43:15 +0200 > Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx> wrote: > > > 2011/4/15 KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>: > > > Per (host) cpu activity of VMs are very insterested numbers > > > when running VMs on large SMPs. virt-top -1 mode tries to > > > provide the information. (But it's not implemented.) > > > > > > This patch adds a libvirt interface to get per cpu statistics > > > of each nodes. This patch just adds an interface and driver > > > entry points. So, > > > Â- doesn't include patches for python. > > > Â- doesn't include any driver. > > > > > > Following patches will add some drivers and codes for python. > > > > > > Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx> > > > --- > > > Âinclude/libvirt/libvirt.h.in |  13 ++++++++++ > > > Âsrc/driver.h         |  Â6 ++++ > > > Âsrc/esx/esx_driver.c     |  Â1 + > > > Âsrc/libvirt.c        Â|  55 ++++++++++++++++++++++++++++++++++++++++++ > > > Âsrc/libvirt_public.syms   Â|  Â4 +++ > > > Âsrc/libxl/libxl_driver.c   |  Â1 + > > > Âsrc/lxc/lxc_driver.c     |  Â1 + > > > Âsrc/openvz/openvz_driver.c  |  Â1 + > > > Âsrc/phyp/phyp_driver.c    |  Â1 + > > > Âsrc/qemu/qemu_driver.c    |  Â1 + > > > Âsrc/remote/remote_driver.c  |  Â1 + > > > Âsrc/test/test_driver.c    |  Â1 + > > > Âsrc/uml/uml_driver.c     |  Â1 + > > > Âsrc/vbox/vbox_tmpl.c     |  Â1 + > > > Âsrc/vmware/vmware_driver.c  |  Â1 + > > > Âsrc/xen/xen_driver.c     |  Â1 + > > > Âsrc/xenapi/xenapi_driver.c  |  Â1 + > > > Â17 files changed, 91 insertions(+), 0 deletions(-) > > > > > > diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in > > > index 5783303..6b9292c 100644 > > > --- a/include/libvirt/libvirt.h.in > > > +++ b/include/libvirt/libvirt.h.in > > > @@ -400,6 +400,13 @@ struct _virDomainMemoryStat { > > > > > > Âtypedef virDomainMemoryStatStruct *virDomainMemoryStatPtr; > > > > > > +typedef struct _virDomainPcpuStat virDomainPcpuStatStruct; > > > + > > > +struct _virDomainPcpuStat { > > > +  Âunsigned long long cpuTime; > > > +}; > > > + > > > > NACK to adding another public struct to the API. > > Oh, yes. I searched a sutiable existing API but cannot found. > > Maybe adding new enum to Usui's work will be good but I need an array. > Hmm, returning an array of unsigned long long is ok ? > > > It's not expendable. > > As a stylistic nit pleas don't use the term PCPU as this looks like > > "Physical CPU". Just call it virDomainPerVcpuStat at least. > > > Ah, no, this is PerPhysicalStat > > > > Also do you really need the absolute CPU time? > yes, for virt-top -1. I don't think that is correct. What virt-top ultimately displays to the end user is a % utilization. So it would be happy to get data in either % util & display that directly, or get absolute CPU time and calculate deltas to display % util. I wonder if we could provide an API that could be used to provide either per-VCPU or per-PCPU statistics in one go, so that we can finally have an API for cpu time that works well for VMWare. eg typedef struct _virDomainCPUTime virDomainCPUTime; typedef virDomainCPUTime *virDomainCPUTimePtr; #define VIR_DOMAIN_CPUTIME_ABS "abs" #define VIR_DOMAIN_CPUTIME_UTIL "util" ...define more stats later if desired... struct _virDomainCPUTime { char field[VIR_DOMAIN_CPU_TIME_FIELD_LENGTH]; unsigned long long value; }; typedef enum { VIR_DOMAIN_CPU_TIME_VIRTUAL = 0, VIR_DOMAIN_CPU_TIME_PHYSICAL = 1, } virDomainCPUTimeFlags; int virDomainGetCPUTime(virDomainPtr dom, virDomainCPUTimePtr stats, int *nstats, unsigned int flags); When querying per-virtual CPU time, nstats would be the number of virtual CPUs in the guest. eg virDomainInfo info; virDomainGetInfo(dom, &info); virDomainCPUTimePtr stats; stats = malloc(sizeof(*stats)*info.nrVirtCPU); virDomainGetCPUTime(dom, stats, info.nrVirtCPU, VIR_DOMAIN_CPU_TIME_VIRTUAL); Or to get the break down per physical CPU, use the VIR_NODEINFO_MAX_CPUS macro virNodeInfo info; virNodeGetInfo(conn, &info); virDomainCPUTimePtr stats; stats = malloc(sizeof(*stats)*VIR_NODEINFO_MAX_CPUS(info)) virDomainGetCPUTime(dom, stats, VIR_NODEINFO_MAX_CPUS(info), VIR_DOMAIN_CPU_TIME_PHYSICAL); We could also allow 'nstats' to be 0, in which case the API would simply populate 'nstats' with the required number and return. The caller can then re-invoke with correct nstats and allocated memory. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list