Re: [libvirt] [PATCH v3 1/1] perf: add support to perf event for MBM

2016-05-19 Thread Ren, Qiaowei

> -Original Message-
> From: Peter Krempa [mailto:pkre...@redhat.com]
> Sent: Thursday, May 19, 2016 9:46 PM
> To: Ren, Qiaowei <qiaowei@intel.com>
> Cc: libvir-list@redhat.com
> Subject: Re: [libvirt] [PATCH v3 1/1] perf: add support to perf event for MBM
> 
> On Fri, May 13, 2016 at 12:26:07 +0800, Qiaowei Ren wrote:
> > Some Intel processor families (e.g. the Intel Xeon processor E5 v3
> > family) introduced some RDT (Resource Director Technology) features to
> > monitor or control shared resource. Among these features, MBM (Memory
> > Bandwidth Monitoring), which is build on the CMT (Cache Monitoring
> > Technology) infrastructure, provides OS/VMM a way to monitor bandwidth
> > from one level of cache to another.
> >
> > With current perf framework, this patch adds support to perf event for
> > MBM.
> >
> > Signed-off-by: Qiaowei Ren <qiaowei@intel.com>
> > ---
> >  include/libvirt/libvirt-domain.h | 26 -
> >  src/libvirt-domain.c | 12 
> >  src/qemu/qemu_driver.c   | 41 +++---
> >  src/util/virperf.c   | 63 
> > 
> >  src/util/virperf.h   |  2 ++
> >  5 files changed, 108 insertions(+), 36 deletions(-)
> 
> [...]
> 
> > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index
> > c4c4968..670f620 100644
> > --- a/src/qemu/qemu_driver.c
> > +++ b/src/qemu/qemu_driver.c
> 
> [...]
> 
> > @@ -19494,24 +19496,38 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr
> > driver,
> >
> >  #undef QEMU_ADD_COUNT_PARAM
> >
> > +#define QEMU_ADD_PERF_PARAM_ULL(record, maxparams, name, value) \
> do
> > +{ \
> > +char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \
> > +snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \
> > + "perf.%s", name); \
> > +if (virTypedParamsAddULLong(&(record)->params, \
> > +&(record)->nparams, \
> > +maxparams, \
> > +param_name, \
> > +value) < 0) \
> > +goto cleanup; \
> > +} while (0)
> 
> This macro is used once so it's not really necessary.
> 
> > +
> >  static int
> > -qemuDomainGetStatsPerfCmt(virPerfPtr perf,
> > +qemuDomainGetStatsPerfRdt(virPerfPtr perf,
> > +  virPerfEventType type,
> >virDomainStatsRecordPtr record,
> >int *maxparams)  {
> > -uint64_t cache = 0;
> > +uint64_t value = 0;
> >
> > -if (virPerfReadEvent(perf, VIR_PERF_EVENT_CMT, ) < 0)
> > +if (virPerfReadEvent(perf, type, ) < 0)
> >  return -1;
> >
> > -if (virTypedParamsAddULLong(>params,
> > ->nparams,
> > -maxparams,
> > -"perf.cache",
> > -cache) < 0)
> > -return -1;
> > +QEMU_ADD_PERF_PARAM_ULL(record, maxparams,
> > +virPerfEventTypeToString(type),
> > +value);
> 
> Otherwise looks good. Thanks for tweaking the documentation.
> 
> I'll push this with the macro dropped in a while.
> 

Peter, thanks very much!

Thanks,
Qiaowei

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


Re: [libvirt] [PATCH v3 1/1] perf: add support to perf event for MBM

2016-05-19 Thread Peter Krempa
On Fri, May 13, 2016 at 12:26:07 +0800, Qiaowei Ren wrote:
> Some Intel processor families (e.g. the Intel Xeon processor E5 v3
> family) introduced some RDT (Resource Director Technology) features
> to monitor or control shared resource. Among these features, MBM
> (Memory Bandwidth Monitoring), which is build on the CMT (Cache
> Monitoring Technology) infrastructure, provides OS/VMM a way to
> monitor bandwidth from one level of cache to another.
> 
> With current perf framework, this patch adds support to perf event
> for MBM.
> 
> Signed-off-by: Qiaowei Ren 
> ---
>  include/libvirt/libvirt-domain.h | 26 -
>  src/libvirt-domain.c | 12 
>  src/qemu/qemu_driver.c   | 41 +++---
>  src/util/virperf.c   | 63 
> 
>  src/util/virperf.h   |  2 ++
>  5 files changed, 108 insertions(+), 36 deletions(-)

[...]

> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index c4c4968..670f620 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c

[...]

> @@ -19494,24 +19496,38 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
>  
>  #undef QEMU_ADD_COUNT_PARAM
>  
> +#define QEMU_ADD_PERF_PARAM_ULL(record, maxparams, name, value) \
> +do { \
> +char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \
> +snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \
> + "perf.%s", name); \
> +if (virTypedParamsAddULLong(&(record)->params, \
> +&(record)->nparams, \
> +maxparams, \
> +param_name, \
> +value) < 0) \
> +goto cleanup; \
> +} while (0)

This macro is used once so it's not really necessary.

> +
>  static int
> -qemuDomainGetStatsPerfCmt(virPerfPtr perf,
> +qemuDomainGetStatsPerfRdt(virPerfPtr perf,
> +  virPerfEventType type,
>virDomainStatsRecordPtr record,
>int *maxparams)
>  {
> -uint64_t cache = 0;
> +uint64_t value = 0;
>  
> -if (virPerfReadEvent(perf, VIR_PERF_EVENT_CMT, ) < 0)
> +if (virPerfReadEvent(perf, type, ) < 0)
>  return -1;
>  
> -if (virTypedParamsAddULLong(>params,
> ->nparams,
> -maxparams,
> -"perf.cache",
> -cache) < 0)
> -return -1;
> +QEMU_ADD_PERF_PARAM_ULL(record, maxparams,
> +virPerfEventTypeToString(type),
> +value);

Otherwise looks good. Thanks for tweaking the documentation.

I'll push this with the macro dropped in a while.

Peter


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v3 1/1] perf: add support to perf event for MBM

2016-05-12 Thread Qiaowei Ren
Some Intel processor families (e.g. the Intel Xeon processor E5 v3
family) introduced some RDT (Resource Director Technology) features
to monitor or control shared resource. Among these features, MBM
(Memory Bandwidth Monitoring), which is build on the CMT (Cache
Monitoring Technology) infrastructure, provides OS/VMM a way to
monitor bandwidth from one level of cache to another.

With current perf framework, this patch adds support to perf event
for MBM.

Signed-off-by: Qiaowei Ren 
---
 include/libvirt/libvirt-domain.h | 26 -
 src/libvirt-domain.c | 12 
 src/qemu/qemu_driver.c   | 41 +++---
 src/util/virperf.c   | 63 
 src/util/virperf.h   |  2 ++
 5 files changed, 108 insertions(+), 36 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 160f20f..27ed29a 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1900,10 +1900,34 @@ void 
virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
 /**
  * VIR_PERF_PARAM_CMT:
  *
- * Macro for typed parameter name that represents CMT perf event.
+ * Macro for typed parameter name that represents CMT perf event
+ * which can be used to measure the usage of cache (bytes) by
+ * applications running on the platform. It corresponds to the
+ * "perf.cmt" field in the *Stats APIs.
  */
 # define VIR_PERF_PARAM_CMT "cmt"
 
+/**
+ * VIR_PERF_PARAM_MBMT:
+ *
+ * Macro for typed parameter name that represents MBMT perf event
+ * which can be used to monitor total system bandwidth (bytes/s)
+ * from one level of cache to another. It corresponds to the
+ * "perf.mbmt" field in the *Stats APIs.
+
+ */
+# define VIR_PERF_PARAM_MBMT "mbmt"
+
+/**
+ * VIR_PERF_PARAM_MBML:
+ *
+ * Macro for typed parameter name that represents MBML perf event
+ * which can be used to monitor the amount of data (bytes/s) sent
+ * through the memory controller on the socket. It corresponds to
+ * the "perf.mbml" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_MBML "mbml"
+
 int virDomainGetPerfEvents(virDomainPtr dom,
virTypedParameterPtr *params,
int *nparams,
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 4f473c9..73ae369 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11441,6 +11441,18 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  * "block..physical" - physical size in bytes of the container of the
  *  backing image as unsigned long long.
  *
+ * VIR_DOMAIN_STATS_PERF: Return perf event statistics.
+ * The typed parameter keys are in this format:
+ * "perf.cmt" - the usage of l3 cache (bytes) by applications running on the
+ *  platform as unsigned long long. It is produced by cmt perf
+ *  event.
+ * "perf.mbmt" - the total system bandwidth (bytes/s) from one level of cache
+ *   to another as unsigned long long. It is produced by mbmt perf
+ *   event.
+ * "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.
+ *
  * 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
  * applicable for the current state of the guest domain, or their retrieval
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c4c4968..670f620 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10051,6 +10051,8 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
 
 if (virTypedParamsValidate(params, nparams,
VIR_PERF_PARAM_CMT, VIR_TYPED_PARAM_BOOLEAN,
+   VIR_PERF_PARAM_MBMT, VIR_TYPED_PARAM_BOOLEAN,
+   VIR_PERF_PARAM_MBML, VIR_TYPED_PARAM_BOOLEAN,
NULL) < 0)
 return -1;
 
@@ -19494,24 +19496,38 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 
 #undef QEMU_ADD_COUNT_PARAM
 
+#define QEMU_ADD_PERF_PARAM_ULL(record, maxparams, name, value) \
+do { \
+char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \
+snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \
+ "perf.%s", name); \
+if (virTypedParamsAddULLong(&(record)->params, \
+&(record)->nparams, \
+maxparams, \
+param_name, \
+value) < 0) \
+goto cleanup; \
+} while (0)
+
 static int
-qemuDomainGetStatsPerfCmt(virPerfPtr perf,
+qemuDomainGetStatsPerfRdt(virPerfPtr perf,
+  virPerfEventType type,
   virDomainStatsRecordPtr record,
   int *maxparams)