Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-07-16 Thread Ren, Qiaowei

> -Original Message-
> From: John Ferlan [mailto:jfer...@redhat.com]
> Sent: Wednesday, July 13, 2016 4:02 AM
> To: Ren, Qiaowei <qiaowei@intel.com>; libvir-list@redhat.com
> Cc: Peter Krempa <pkre...@redhat.com>
> Subject: Re: [libvirt] [PATCH 1/1] perf: add more perf events support
> 
> 
> 
> On 06/29/2016 08:10 PM, Qiaowei Ren wrote:
> > With current perf framework, this patch adds support to more perf
>^^^ for more perf
> 
> > events, including cache missing, cache peference, cpu cycles,
> 
> A quick google search turns up "cache references" - there's just too many
> peference or peferences references to comment on them all, but they all need
> to be "references"
> 

John, according perf code from linux kernel, 'cache peference' is from linux 
kernel code. Certainly 'perf list' command show the 'references', and I will 
change it to this.

> > instrction, etc..
> 
> instructions
> 
> >
> > Signed-off-by: Qiaowei Ren <qiaowei@intel.com>
> > ---
> >  docs/formatdomain.html.in   | 24 +++
> >  docs/schemas/domaincommon.rng   |  4 ++
> >  include/libvirt/libvirt-domain.h| 39 +
> >  src/libvirt-domain.c|  8 
> >  src/qemu/qemu_driver.c  | 23 +-
> >  src/util/virperf.c  | 65 
> > -
> >  src/util/virperf.h  |  4 ++
> >  tests/genericxml2xmlindata/generic-perf.xml |  4 ++
> >  8 files changed, 158 insertions(+), 13 deletions(-)
> >
> 
> I see no changes for virsh.pod, see commit id '3110363d' for a recent change
> Peter made in this space...
> 
> I think perhaps it may also be worthwhile to "in a separate patch" alter the
> 'domstats --perf' description to simply reference the 'perf'
> description where each of the collect perf.* events can be listed and 
> described.
> 
> Each of the collectible events could have some sort of tabular output - see 
> how
> 'vol-wipe' describes the various supported algorithms.  So much easier to read
> than one long sentence.
> 
Sure. I will add one patch about this.

> 
> > diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> > index f660aa6..7999e43 100644
> > --- a/docs/formatdomain.html.in
> > +++ b/docs/formatdomain.html.in
> > @@ -1839,6 +1839,10 @@
> >  event name='cmt' enabled='yes'/
> >  event name='mbmt' enabled='no'/
> >  event name='mbml' enabled='yes'/
> > +event name='cache_misses' enabled='no'/
> > +event name='cache_peferences' enabled='no'/
> > +event name='instructions' enabled='no'/
> > +event name='cpu_cycles' enabled='no'/
> >/perf
> >...
> >  
> > @@ -1864,6 +1868,26 @@
> >bandwidth of memory traffic for a memory controller
> >perf.mbml
> >  
> > +
> > +  cache_misses
> > +  the amount of cache missing by applications running on the
> > + platform
> 
> is this the count of caches misses?  amount implies perhaps other things.
> 
Yes. I will change it.

> > +  perf.cache_misses
> > +
> > +
> > +  cache_peferences
> > +  the amount of cache hit by applications running on the 
> > platform
> > +  perf.cache_peferences
> 
> similar is this the count of cache hits, right?
> 
Yes.

> > +
> > +
> > +  instructions
> > +  the amount of instructions by applications running on the
> > + platform
> 
> the count of instructions executed...
> 
> > +  perf.instructions
> > +
> > +
> > +  cpu_cycles
> > +  the amount of cycles one instruction needs
> 
> the number/count of cpu cycles
> 
> > +  perf.cpu_cycles
> > +
> >
> >
> >  Devices
> > diff --git a/docs/schemas/domaincommon.rng
> > b/docs/schemas/domaincommon.rng index 563cb3c..e41dc3a 100644
> > --- a/docs/schemas/domaincommon.rng
> > +++ b/docs/schemas/domaincommon.rng
> > @@ -414,6 +414,10 @@
> >cmt
> >mbmt
> >mbml
> > +  cache_misses
> > +  cache_peferences
> > +  instructions
> > +  cpu_cycles
> >  
> >
> >
> > diff --git a/include/libvirt/libvirt-domain.h
> > b/include/libvirt/libvirt-domain.h
> &g

[libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-29 Thread Qiaowei Ren
With current perf framework, this patch adds support to more perf
events, including cache missing, cache peference, cpu cycles,
instrction, etc..

Signed-off-by: Qiaowei Ren 
---
 docs/formatdomain.html.in   | 24 +++
 docs/schemas/domaincommon.rng   |  4 ++
 include/libvirt/libvirt-domain.h| 39 +
 src/libvirt-domain.c|  8 
 src/qemu/qemu_driver.c  | 23 +-
 src/util/virperf.c  | 65 -
 src/util/virperf.h  |  4 ++
 tests/genericxml2xmlindata/generic-perf.xml |  4 ++
 8 files changed, 158 insertions(+), 13 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f660aa6..7999e43 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1839,6 +1839,10 @@
 event name='cmt' enabled='yes'/
 event name='mbmt' enabled='no'/
 event name='mbml' enabled='yes'/
+event name='cache_misses' enabled='no'/
+event name='cache_peferences' enabled='no'/
+event name='instructions' enabled='no'/
+event name='cpu_cycles' enabled='no'/
   /perf
   ...
 
@@ -1864,6 +1868,26 @@
   bandwidth of memory traffic for a memory controller
   perf.mbml
 
+
+  cache_misses
+  the amount of cache missing by applications running on the 
platform
+  perf.cache_misses
+
+
+  cache_peferences
+  the amount of cache hit by applications running on the platform
+  perf.cache_peferences
+
+
+  instructions
+  the amount of instructions by applications running on the 
platform
+  perf.instructions
+
+
+  cpu_cycles
+  the amount of cycles one instruction needs
+  perf.cpu_cycles
+
   
 
 Devices
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 563cb3c..e41dc3a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -414,6 +414,10 @@
   cmt
   mbmt
   mbml
+  cache_misses
+  cache_peferences
+  instructions
+  cpu_cycles
 
   
   
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 7ea93aa..b79cdb0 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1947,6 +1947,45 @@ void 
virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
  */
 # define VIR_PERF_PARAM_MBML "mbml"
 
+/**
+ * VIR_PERF_PARAM_CACHE_MISSES:
+ *
+ * Macro for typed parameter name that represents cache_misses perf
+ * event which can be used to measure the amount of cache missing by
+ * applications running on the platform. It corresponds to the
+ * "perf.cache_misses" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_CACHE_MISSES "cache_misses"
+
+/**
+ * VIR_PERF_PARAM_CACHE_REFERENCES:
+ *
+ * Macro for typed parameter name that represents cache_peferences
+ * perf event which can be used to measure the amount of cache hit
+ * by applications running on the platform. It corresponds to the
+ * "perf.cache_peferences" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_CACHE_REFERENCES "cache_peferences"
+
+/**
+ * VIR_PERF_PARAM_INSTRUCTIONS:
+ *
+ * Macro for typed parameter name that represents instructions perf
+ * event which can be used to measure the amount of instructions
+ * by applications running on the platform. It corresponds to the
+ * "perf.instructions" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
+
+/**
+ * VIR_PERF_PARAM_CPU_CYCLES:
+ *
+ * Macro for typed parameter name that represents cpu_cycles perf event
+ * which can be used to measure how many cycles one instruction needs.
+ * It corresponds to the "perf.cpu_cycles" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_CPU_CYCLES "cpu_cycles"
+
 int virDomainGetPerfEvents(virDomainPtr dom,
virTypedParameterPtr *params,
int *nparams,
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 4e71a94..b817e4b 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11452,6 +11452,14 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  * "perf.mbml" - the amount of data (bytes/s) sent through the memory 
controller
  *   on the socket as unsigned long long. It is produced by mbml
  *   perf event.
+ * "perf.cache_misses" - the amount of cache missing as unsigned long long.
+ * It is produced by cache_misses perf event.
+ * "perf.cache_peferences" - the amount of cache hit as unsigned long long.
+ * It is produced by cache_peferences perf event.
+ * "perf.instructions" - the amount of instructions as unsigned long long.
+ * It is produced by instructions perf event.
+ * "perf.cpu_cycles" - the amount of cycles one instruction needs as unsigned

Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-21 Thread Ren, Qiaowei

> -Original Message-
> From: Peter Krempa [mailto:pkre...@redhat.com]
> Sent: Tuesday, June 21, 2016 3:03 PM
> To: Ren, Qiaowei <qiaowei@intel.com>
> Cc: libvir-list@redhat.com
> Subject: Re: [libvirt] [PATCH 1/1] perf: add more perf events support
> 
> On Tue, Jun 21, 2016 at 01:43:30 +, Ren, Qiaowei wrote:
> >
> > > -Original Message-
> > > From: libvir-list-boun...@redhat.com
> > > [mailto:libvir-list-boun...@redhat.com]
> > > On Behalf Of Ren, Qiaowei
> > > Sent: Sunday, June 12, 2016 10:14 AM
> > > To: Peter Krempa <pkre...@redhat.com>
> > > Cc: libvir-list@redhat.com
> > > Subject: Re: [libvirt] [PATCH 1/1] perf: add more perf events
> > > support
> 
> [...]
> 
> > Peter, do you have any other comments about this patch?
> 
> Please see my recent patch:
> https://www.redhat.com/archives/libvir-list/2016-June/msg00995.html
> 
> where I've added some documentation of the XML and fixed the schema and
> added a test that actually is used with the parser since the parser was 
> broken.
> You'll need to add the relevant bits to the files added by those commits.
> 
> Additionally I'd be glad if you could improve the documentation in the XML.
> 

Ok. I will update the XML documentation in next version.

Thanks,
Qiaowei

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-21 Thread Peter Krempa
On Tue, Jun 21, 2016 at 01:43:30 +, Ren, Qiaowei wrote:
> 
> > -Original Message-
> > From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
> > On Behalf Of Ren, Qiaowei
> > Sent: Sunday, June 12, 2016 10:14 AM
> > To: Peter Krempa <pkre...@redhat.com>
> > Cc: libvir-list@redhat.com
> > Subject: Re: [libvirt] [PATCH 1/1] perf: add more perf events support

[...]

> Peter, do you have any other comments about this patch?

Please see my recent patch:
https://www.redhat.com/archives/libvir-list/2016-June/msg00995.html

where I've added some documentation of the XML and fixed the schema and
added a test that actually is used with the parser since the parser was
broken. You'll need to add the relevant bits to the files added by those
commits.

Additionally I'd be glad if you could improve the documentation in the
XML.

Peter

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-20 Thread Ren, Qiaowei

> -Original Message-
> From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
> On Behalf Of Ren, Qiaowei
> Sent: Sunday, June 12, 2016 10:14 AM
> To: Peter Krempa <pkre...@redhat.com>
> Cc: libvir-list@redhat.com
> Subject: Re: [libvirt] [PATCH 1/1] perf: add more perf events support
> 
> > > diff --git a/include/libvirt/libvirt-domain.h
> > > b/include/libvirt/libvirt-domain.h
> > > index cba4fa5..99c4c48 100644
> > > --- a/include/libvirt/libvirt-domain.h
> > > +++ b/include/libvirt/libvirt-domain.h
> > > @@ -1928,6 +1928,45 @@ void
> > virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
> > >   */
> > >  # define VIR_PERF_PARAM_MBML "mbml"
> >
> > [...]
> >
> > > +/**
> > > + * VIR_PERF_PARAM_INSTRUCTIONS:
> > > + *
> > > + * Macro for typed parameter name that represents instructions perf
> > > + * event which can be used to measure the amount of instructions
> > > + * by applications running on the platform. It corresponds to the
> > > + * "perf.instructions" field in the *Stats APIs.
> >
> > I'm not sure if I understand the implications and usability of this stat 
> > parameter.
> > Could you elaborate on how this can be used?
> >
> > > + */
> > > +# define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
> > > +
> > > +/**
> > > + * VIR_PERF_PARAM_CPU_CYCLES:
> > > + *
> > > + * Macro for typed parameter name that represents cpu_cycles perf
> > > +event
> > > + * which can be used to measure how many cycles one instruction needs.
> > > + * It corresponds to the "perf.cpu_cycles" field in the *Stats APIs.
> >
> > And same for this. I don't really see how this can be used.
> >
> 
> Peter, thanks for your feedback!
> 
> Instructions and cycles can be used to gain IPC (Instructions Per Clock, =
> Instructions/Cycles), and a low IPC ratio indicates the code of the process 
> makes
> poor use of the CPU.
> 

Peter, do you have any other comments about this patch?

Thanks,
Qiaowei

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-11 Thread Ren, Qiaowei

> -Original Message-
> From: Peter Krempa [mailto:pkre...@redhat.com]
> Sent: Thursday, June 9, 2016 7:50 PM
> To: Ren, Qiaowei <qiaowei@intel.com>
> Cc: libvir-list@redhat.com
> Subject: Re: [libvirt] [PATCH 1/1] perf: add more perf events support
> 
> On Tue, May 31, 2016 at 10:48:15 +0800, Qiaowei Ren wrote:
> > With current perf framework, this patch adds support to more perf
> > events, including cache missing, cache peference, cpu cycles,
> > instrction, etc..
> >
> > Signed-off-by: Qiaowei Ren <qiaowei@intel.com>
> > ---
> >  include/libvirt/libvirt-domain.h | 39 
> >  src/libvirt-domain.c |  8 +
> >  src/qemu/qemu_driver.c   | 23 +++---
> >  src/util/virperf.c   | 65 
> > +++-
> >  src/util/virperf.h   |  4 +++
> >  5 files changed, 126 insertions(+), 13 deletions(-)
> >
> > diff --git a/include/libvirt/libvirt-domain.h
> > b/include/libvirt/libvirt-domain.h
> > index cba4fa5..99c4c48 100644
> > --- a/include/libvirt/libvirt-domain.h
> > +++ b/include/libvirt/libvirt-domain.h
> > @@ -1928,6 +1928,45 @@ void
> virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
> >   */
> >  # define VIR_PERF_PARAM_MBML "mbml"
> 
> [...]
> 
> > +/**
> > + * VIR_PERF_PARAM_INSTRUCTIONS:
> > + *
> > + * Macro for typed parameter name that represents instructions perf
> > + * event which can be used to measure the amount of instructions
> > + * by applications running on the platform. It corresponds to the
> > + * "perf.instructions" field in the *Stats APIs.
> 
> I'm not sure if I understand the implications and usability of this stat 
> parameter.
> Could you elaborate on how this can be used?
> 
> > + */
> > +# define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
> > +
> > +/**
> > + * VIR_PERF_PARAM_CPU_CYCLES:
> > + *
> > + * Macro for typed parameter name that represents cpu_cycles perf
> > +event
> > + * which can be used to measure how many cycles one instruction needs.
> > + * It corresponds to the "perf.cpu_cycles" field in the *Stats APIs.
> 
> And same for this. I don't really see how this can be used.
> 

Peter, thanks for your feedback!

Instructions and cycles can be used to gain IPC (Instructions Per Clock, = 
Instructions/Cycles), and a low IPC ratio indicates the code of the process 
makes poor use of the CPU.

Thanks,
Qiaowei

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-09 Thread Peter Krempa
On Tue, May 31, 2016 at 10:48:15 +0800, Qiaowei Ren wrote:
> With current perf framework, this patch adds support to more perf
> events, including cache missing, cache peference, cpu cycles,
> instrction, etc..
> 
> Signed-off-by: Qiaowei Ren 
> ---
>  include/libvirt/libvirt-domain.h | 39 
>  src/libvirt-domain.c |  8 +
>  src/qemu/qemu_driver.c   | 23 +++---
>  src/util/virperf.c   | 65 
> +++-
>  src/util/virperf.h   |  4 +++
>  5 files changed, 126 insertions(+), 13 deletions(-)
> 
> diff --git a/include/libvirt/libvirt-domain.h 
> b/include/libvirt/libvirt-domain.h
> index cba4fa5..99c4c48 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -1928,6 +1928,45 @@ void 
> virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
>   */
>  # define VIR_PERF_PARAM_MBML "mbml"

[...]

> +/**
> + * VIR_PERF_PARAM_INSTRUCTIONS:
> + *
> + * Macro for typed parameter name that represents instructions perf
> + * event which can be used to measure the amount of instructions
> + * by applications running on the platform. It corresponds to the
> + * "perf.instructions" field in the *Stats APIs.

I'm not sure if I understand the implications and usability of this stat
parameter. Could you elaborate on how this can be used?

> + */
> +# define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
> +
> +/**
> + * VIR_PERF_PARAM_CPU_CYCLES:
> + *
> + * Macro for typed parameter name that represents cpu_cycles perf event
> + * which can be used to measure how many cycles one instruction needs.
> + * It corresponds to the "perf.cpu_cycles" field in the *Stats APIs.

And same for this. I don't really see how this can be used.

> + */
> +# define VIR_PERF_PARAM_CPU_CYCLES "cpu_cycles"
> +

The rest of this patch looks good and applies cleanly.

Peter

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-07 Thread Peter Krempa
On Mon, Jun 06, 2016 at 08:29:41 +, Ren, Qiaowei wrote:
> Hi Peter,
> 
> Do you have any comments on this patch?

Sorry for the delay. I'll review it eventually, but I was stuck with
other work.

Peter

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] perf: add more perf events support

2016-06-06 Thread Ren, Qiaowei
Hi Peter,

Do you have any comments on this patch?

Thanks,
Qiaowei

> -Original Message-
> From: Ren, Qiaowei
> Sent: Tuesday, May 31, 2016 10:48 AM
> To: libvir-list@redhat.com
> Cc: Daniel P. Berrange ; Peter Krempa
> ; Ren, Qiaowei 
> Subject: [PATCH 1/1] perf: add more perf events support
> 
> With current perf framework, this patch adds support to more perf events,
> including cache missing, cache peference, cpu cycles, instrction, etc..
> 
> Signed-off-by: Qiaowei Ren 
> ---
>  include/libvirt/libvirt-domain.h | 39 
>  src/libvirt-domain.c |  8 +
>  src/qemu/qemu_driver.c   | 23 +++---
>  src/util/virperf.c   | 65 
> +++-
>  src/util/virperf.h   |  4 +++
>  5 files changed, 126 insertions(+), 13 deletions(-)
> 
> diff --git a/include/libvirt/libvirt-domain.h 
> b/include/libvirt/libvirt-domain.h
> index cba4fa5..99c4c48 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -1928,6 +1928,45 @@ void
> virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
>   */
>  # define VIR_PERF_PARAM_MBML "mbml"
> 
> +/**
> + * VIR_PERF_PARAM_CACHE_MISSES:
> + *
> + * Macro for typed parameter name that represents cache_misses perf
> + * event which can be used to measure the amount of cache missing by
> + * applications running on the platform. It corresponds to the
> + * "perf.cache_misses" field in the *Stats APIs.
> + */
> +# define VIR_PERF_PARAM_CACHE_MISSES "cache_misses"
> +
> +/**
> + * VIR_PERF_PARAM_CACHE_REFERENCES:
> + *
> + * Macro for typed parameter name that represents cache_peferences
> + * perf event which can be used to measure the amount of cache hit
> + * by applications running on the platform. It corresponds to the
> + * "perf.cache_peferences" field in the *Stats APIs.
> + */
> +# define VIR_PERF_PARAM_CACHE_REFERENCES "cache_peferences"
> +
> +/**
> + * VIR_PERF_PARAM_INSTRUCTIONS:
> + *
> + * Macro for typed parameter name that represents instructions perf
> + * event which can be used to measure the amount of instructions
> + * by applications running on the platform. It corresponds to the
> + * "perf.instructions" field in the *Stats APIs.
> + */
> +# define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
> +
> +/**
> + * VIR_PERF_PARAM_CPU_CYCLES:
> + *
> + * Macro for typed parameter name that represents cpu_cycles perf event
> + * which can be used to measure how many cycles one instruction needs.
> + * It corresponds to the "perf.cpu_cycles" field in the *Stats APIs.
> + */
> +# define VIR_PERF_PARAM_CPU_CYCLES "cpu_cycles"
> +
>  int virDomainGetPerfEvents(virDomainPtr dom,
> virTypedParameterPtr *params,
> int *nparams, diff --git a/src/libvirt-domain.c 
> b/src/libvirt-
> domain.c index 73ae369..ef71b31 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -11452,6 +11452,14 @@ virConnectGetDomainCapabilities(virConnectPtr
> conn,
>   * "perf.mbml" - the amount of data (bytes/s) sent through the memory
> controller
>   *   on the socket as unsigned long long. It is produced by mbml
>   *   perf event.
> + * "perf.cache_misses" - the amount of cache missing as unsigned long long.
> + * It is produced by cache_misses perf event.
> + * "perf.cache_peferences" - the amount of cache hit as unsigned long long.
> + * It is produced by cache_peferences perf event.
> + * "perf.instructions" - the amount of instructions as unsigned long long.
> + * It is produced by instructions perf event.
> + * "perf.cpu_cycles" - the amount of cycles one instruction needs as
> + unsigned
> + * long long. It is produced by cpu_cycles perf event.
>   *
>   * Note that entire stats groups or individual stat fields may be missing 
> from
>   * the output in case they are not supported by the given hypervisor, are 
> not diff
> --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index
> 10d3e3d..d465ec5 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -9756,6 +9756,10 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
> VIR_PERF_PARAM_CMT, VIR_TYPED_PARAM_BOOLEAN,
> VIR_PERF_PARAM_MBMT, VIR_TYPED_PARAM_BOOLEAN,
> VIR_PERF_PARAM_MBML, VIR_TYPED_PARAM_BOOLEAN,
> +   VIR_PERF_PARAM_CACHE_MISSES,
> VIR_TYPED_PARAM_BOOLEAN,
> +   VIR_PERF_PARAM_CACHE_REFERENCES,
> VIR_TYPED_PARAM_BOOLEAN,
> +   VIR_PERF_PARAM_INSTRUCTIONS,
> VIR_TYPED_PARAM_BOOLEAN,
> +   VIR_PERF_PARAM_CPU_CYCLES,
> + VIR_TYPED_PARAM_BOOLEAN,
> NULL) < 0)
>  return -1;
> 
> @@ -19071,10 +19075,10 @@ 

[libvirt] [PATCH 1/1] perf: add more perf events support

2016-05-30 Thread Qiaowei Ren
With current perf framework, this patch adds support to more perf
events, including cache missing, cache peference, cpu cycles,
instrction, etc..

Signed-off-by: Qiaowei Ren 
---
 include/libvirt/libvirt-domain.h | 39 
 src/libvirt-domain.c |  8 +
 src/qemu/qemu_driver.c   | 23 +++---
 src/util/virperf.c   | 65 +++-
 src/util/virperf.h   |  4 +++
 5 files changed, 126 insertions(+), 13 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index cba4fa5..99c4c48 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1928,6 +1928,45 @@ void 
virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
  */
 # define VIR_PERF_PARAM_MBML "mbml"
 
+/**
+ * VIR_PERF_PARAM_CACHE_MISSES:
+ *
+ * Macro for typed parameter name that represents cache_misses perf
+ * event which can be used to measure the amount of cache missing by
+ * applications running on the platform. It corresponds to the
+ * "perf.cache_misses" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_CACHE_MISSES "cache_misses"
+
+/**
+ * VIR_PERF_PARAM_CACHE_REFERENCES:
+ *
+ * Macro for typed parameter name that represents cache_peferences
+ * perf event which can be used to measure the amount of cache hit
+ * by applications running on the platform. It corresponds to the
+ * "perf.cache_peferences" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_CACHE_REFERENCES "cache_peferences"
+
+/**
+ * VIR_PERF_PARAM_INSTRUCTIONS:
+ *
+ * Macro for typed parameter name that represents instructions perf
+ * event which can be used to measure the amount of instructions
+ * by applications running on the platform. It corresponds to the
+ * "perf.instructions" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
+
+/**
+ * VIR_PERF_PARAM_CPU_CYCLES:
+ *
+ * Macro for typed parameter name that represents cpu_cycles perf event
+ * which can be used to measure how many cycles one instruction needs.
+ * It corresponds to the "perf.cpu_cycles" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_CPU_CYCLES "cpu_cycles"
+
 int virDomainGetPerfEvents(virDomainPtr dom,
virTypedParameterPtr *params,
int *nparams,
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 73ae369..ef71b31 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11452,6 +11452,14 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  * "perf.mbml" - the amount of data (bytes/s) sent through the memory 
controller
  *   on the socket as unsigned long long. It is produced by mbml
  *   perf event.
+ * "perf.cache_misses" - the amount of cache missing as unsigned long long.
+ * It is produced by cache_misses perf event.
+ * "perf.cache_peferences" - the amount of cache hit as unsigned long long.
+ * It is produced by cache_peferences perf event.
+ * "perf.instructions" - the amount of instructions as unsigned long long.
+ * It is produced by instructions perf event.
+ * "perf.cpu_cycles" - the amount of cycles one instruction needs as unsigned
+ * long long. It is produced by cpu_cycles perf event.
  *
  * Note that entire stats groups or individual stat fields may be missing from
  * the output in case they are not supported by the given hypervisor, are not
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 10d3e3d..d465ec5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9756,6 +9756,10 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
VIR_PERF_PARAM_CMT, VIR_TYPED_PARAM_BOOLEAN,
VIR_PERF_PARAM_MBMT, VIR_TYPED_PARAM_BOOLEAN,
VIR_PERF_PARAM_MBML, VIR_TYPED_PARAM_BOOLEAN,
+   VIR_PERF_PARAM_CACHE_MISSES, 
VIR_TYPED_PARAM_BOOLEAN,
+   VIR_PERF_PARAM_CACHE_REFERENCES, 
VIR_TYPED_PARAM_BOOLEAN,
+   VIR_PERF_PARAM_INSTRUCTIONS, 
VIR_TYPED_PARAM_BOOLEAN,
+   VIR_PERF_PARAM_CPU_CYCLES, 
VIR_TYPED_PARAM_BOOLEAN,
NULL) < 0)
 return -1;
 
@@ -19071,10 +19075,10 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 #undef QEMU_ADD_COUNT_PARAM
 
 static int
-qemuDomainGetStatsPerfRdt(virPerfPtr perf,
-  virPerfEventType type,
-  virDomainStatsRecordPtr record,
-  int *maxparams)
+qemuDomainGetStatsPerfOneEvent(virPerfPtr perf,
+   virPerfEventType type,
+   virDomainStatsRecordPtr record,
+   int *maxparams)
 {
 char param_name[VIR_TYPED_PARAM_FIELD_LENGTH];
 uint64_t value = 0;
@@ -19110,14 +19114,9 @@