[libvirt] [RFC][PATCHv1 2/5] libvirt - new API for getting percpu statistics of VM
Daniel P. Berrange
berrange at redhat.com
Tue Apr 19 11:29:05 UTC 2011
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 at googlemail.com> wrote:
>
> > 2011/4/15 KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>:
> > > 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 at jp.fujitsu.com>
> > > ---
> > > 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 :|
More information about the libvir-list
mailing list