[libvirt] [PATCH v2 09/10] perf: add emulation_faults software perf event support

Nitesh Konkar niteshkonkar.libvirt at gmail.com
Thu Feb 23 14:55:38 UTC 2017


This patch adds support and documentation
for the emulation_faults perf event.

Signed-off-by: Nitesh Konkar <nitkon12 at linux.vnet.ibm.com>
---
 docs/formatdomain.html.in                   |  9 +++++++++
 docs/schemas/domaincommon.rng               |  1 +
 include/libvirt/libvirt-domain.h            | 10 ++++++++++
 src/libvirt-domain.c                        |  3 +++
 src/qemu/qemu_driver.c                      |  1 +
 src/util/virperf.c                          |  5 ++++-
 src/util/virperf.h                          |  1 +
 tests/genericxml2xmlindata/generic-perf.xml |  1 +
 tools/virsh.pod                             |  3 +++
 9 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 3761a5d..8891ed9 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1944,6 +1944,7 @@
   <event name='page_faults_min' enabled='no'/>
   <event name='page_faults_maj' enabled='no'/>
   <event name='alignment_faults' enabled='no'/>
+  <event name='emulation_faults' enabled='no'/>
 </perf>
 ...
 </pre>
@@ -2079,6 +2080,14 @@
           applications running on the platform</td>
       <td><code>perf.alignment_faults</code></td>
     </tr>
+    <tr>
+      <td><code>emulation_faults</code></td>
+      <td>the count of emulation faults, that is when
+          the kernel traps on unimplemented instrucions
+          and emulates them for user space, by
+          applications running on the platform</td>
+      <td><code>perf.emulation_faults</code></td>
+    </tr>
   </table>
 
     <h3><a name="elementsDevices">Devices</a></h3>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 1f0c729..1860f90 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -441,6 +441,7 @@
               <value>page_faults_min</value>
               <value>page_faults_maj</value>
               <value>alignment_faults</value>
+              <value>emulation_faults</value>
             </choice>
           </attribute>
           <attribute name="enabled">
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 0c0fb18..c490d71 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2270,6 +2270,16 @@ void virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
  */
 # define VIR_PERF_PARAM_ALIGNMENT_FAULTS  "alignment_faults"
 
+/**
+ * VIR_PERF_PARAM_EMULATION_FAULTS:
+ *
+ * Macro for typed parameter name that represents emulation_faults
+ * perf event which can be used to measure the count of emulation
+ * faults by applications running on the platform. It corresponds
+ * to the "perf.emulation_faults" field in the *Stats APIs.
+ */
+# define VIR_PERF_PARAM_EMULATION_FAULTS  "emulation_faults"
+
 int virDomainGetPerfEvents(virDomainPtr dom,
                            virTypedParameterPtr *params,
                            int *nparams,
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 336e172..5088f47 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11272,6 +11272,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  *     "perf.alignment_faults" - The count of alignment faults as unsigned
  *                               long long. It is produced by the
  *                               alignment_faults perf event
+ *     "perf.emulation_faults" - The count of emulation faults as unsigned
+ *                               long long. It is produced by the
+ *                               emulation_faults 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 c58c7b0..51d0b5f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9577,6 +9577,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
                                VIR_PERF_PARAM_PAGE_FAULTS_MIN, VIR_TYPED_PARAM_BOOLEAN,
                                VIR_PERF_PARAM_PAGE_FAULTS_MAJ, VIR_TYPED_PARAM_BOOLEAN,
                                VIR_PERF_PARAM_ALIGNMENT_FAULTS, VIR_TYPED_PARAM_BOOLEAN,
+                               VIR_PERF_PARAM_EMULATION_FAULTS, VIR_TYPED_PARAM_BOOLEAN,
                                NULL) < 0)
         return -1;
 
diff --git a/src/util/virperf.c b/src/util/virperf.c
index 3f01596..e39cebb 100644
--- a/src/util/virperf.c
+++ b/src/util/virperf.c
@@ -47,7 +47,7 @@ VIR_ENUM_IMPL(virPerfEvent, VIR_PERF_EVENT_LAST,
               "cpu_clock", "task_clock", "page_faults",
               "context_switches", "cpu_migrations",
               "page_faults_min", "page_faults_maj",
-              "alignment_faults");
+              "alignment_faults", "emulation_faults");
 
 struct virPerfEvent {
     int type;
@@ -140,6 +140,9 @@ static struct virPerfEventAttr attrs[] = {
     {.type = VIR_PERF_EVENT_ALIGNMENT_FAULTS,
      .attrType = PERF_TYPE_SOFTWARE,
      .attrConfig = PERF_COUNT_SW_ALIGNMENT_FAULTS},
+    {.type = VIR_PERF_EVENT_EMULATION_FAULTS,
+     .attrType = PERF_TYPE_SOFTWARE,
+     .attrConfig = PERF_COUNT_SW_EMULATION_FAULTS},
 };
 typedef struct virPerfEventAttr *virPerfEventAttrPtr;
 
diff --git a/src/util/virperf.h b/src/util/virperf.h
index 4e46460..eee7a03 100644
--- a/src/util/virperf.h
+++ b/src/util/virperf.h
@@ -55,6 +55,7 @@ typedef enum {
     VIR_PERF_EVENT_PAGE_FAULTS_MIN,   /* Count of minor page faults */
     VIR_PERF_EVENT_PAGE_FAULTS_MAJ,   /* Count of major page faults */
     VIR_PERF_EVENT_ALIGNMENT_FAULTS,   /* Count of alignment faults */
+    VIR_PERF_EVENT_EMULATION_FAULTS,   /* Count of emulation faults */
 
     VIR_PERF_EVENT_LAST
 } virPerfEventType;
diff --git a/tests/genericxml2xmlindata/generic-perf.xml b/tests/genericxml2xmlindata/generic-perf.xml
index b48f96c..457aea0 100644
--- a/tests/genericxml2xmlindata/generic-perf.xml
+++ b/tests/genericxml2xmlindata/generic-perf.xml
@@ -34,6 +34,7 @@
     <event name='page_faults_min' enabled='yes'/>
     <event name='page_faults_maj' enabled='yes'/>
     <event name='alignment_faults' enabled='yes'/>
+    <event name='emulation_faults' enabled='yes'/>
   </perf>
   <devices>
   </devices>
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 123b701..270b983 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -972,6 +972,7 @@ I<--perf> returns the statistics of all enabled perf events:
  "perf.page_faults_min" - the count of minor page faults
  "perf.page_faults_maj" - the count of major page faults
  "perf.alignment_faults" - the count of alignment faults
+ "perf.emulation_faults" - the count of emulation faults
 
 See the B<perf> command for more details about each event.
 
@@ -2357,6 +2358,8 @@ B<Valid perf event names>
                     by applications running on the platform
   alignment_faults - Provides the count alignment faults
                      by applications running on the platform
+  emulation_faults - Provides the count emulation faults
+                     by applications running on the platform
 
 B<Note>: The statistics can be retrieved using the B<domstats> command using
 the I<--perf> flag.
-- 
1.9.3




More information about the libvir-list mailing list