Skip to contentSkip to conversation

kvm_stat update

PATCH New Wei Huang 1 participant 5 messages Jan 23, 2015

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

v3 cover kvm_stat update

This is the third version of kvm_stat patches. Please review.

NOTE: I have tested these patches on ARM64 and x86_64 machines. For PPC, the only area been affected is ioctl RESET number (patch 4). Unfortunately I don't have PPC hardware to test them.

Thanks,
-Wei
V3:
- fix a comment in patch #4

V2:
- fix a typo in VMX exit reason (pointed out by Paolo)
- add ioctl RESET function to initialize counters
- re-arrange the order of patches

V1:
- support for ARM aarch64
- update to the latest exit reasons (vmx, svm and userspace)
- print errno when syscall fails

Wei Huang (4):
kvm_stat: Update exit reasons to the latest defintion
kvm_stat: Print errno when syscall to perf_event_open() fails
kvm_stat: Add aarch64 support
kvm_stat: Add RESET support for perf event ioctl

 scripts/kvm/kvm_stat | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v3 1/4 kvm_stat: Update exit reasons to the latest defintion

This patch updates the exit reasons for x86_vmx, x86_svm, and userspace to the latest definition.

---
 scripts/kvm/kvm_stat | 4 ++++
 1 file changed, 4 insertions(+)
scripts/kvm/kvm_stat +4 -0
index 7b1437c..7ec84c0 100755
@@ -65,6 +65,8 @@ vmx_exit_reasons = {
     49: 'EPT_MISCONFIG',
     54: 'WBINVD',
     55: 'XSETBV',
+    56: 'APIC_WRITE',
+    58: 'INVPCID',
 }
 
 svm_exit_reasons = {
@@ -138,6 +140,7 @@ svm_exit_reasons = {
     0x08a: 'MONITOR',
     0x08b: 'MWAIT',
     0x08c: 'MWAIT_COND',
+    0x08d: 'XSETBV',
     0x400: 'NPF',
 }
 
@@ -167,6 +170,7 @@ userspace_exit_reasons = {
     21: 'WATCHDOG',
     22: 'S390_TSCH',
     23: 'EPR',
+    24: 'SYSTEM_EVENT',
 }
 
 x86_exit_reasons = {
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v3 2/4 kvm_stat: Print errno when syscall to perf_event_open() fails

In reply to Wei Huang

kvm_stat uses syscall() to call perf_event_open(). If this function call fails, the returned value is -1, which doesn't tell the details of the failure (i.e. ENOSYS or EINVAL). This patch retrieves errno and prints it when syscall() fails. The error message will look like "Exception: perf_event_open failed, errno = 38".

---
 scripts/kvm/kvm_stat | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/kvm/kvm_stat +6 -1
index 7ec84c0..cb23877 100755
@@ -13,6 +13,7 @@
 
 import curses
 import sys, os, time, optparse, ctypes
+from ctypes import *
 
 class DebugfsProvider(object):
     def __init__(self):
@@ -239,6 +240,9 @@ import struct, array
 
 libc = ctypes.CDLL('libc.so.6')
 syscall = libc.syscall
+get_errno = libc.__errno_location
+get_errno.restype = POINTER(c_int)
+
 class perf_event_attr(ctypes.Structure):
     _fields_ = [('type', ctypes.c_uint32),
                 ('size', ctypes.c_uint32),
@@ -322,7 +326,8 @@ class Event(object):
             group_leader = group.events[0].fd
         fd = _perf_event_open(attr, -1, group.cpu, group_leader, 0)
         if fd == -1:
-            raise Exception('perf_event_open failed')
+            err = get_errno()[0]
+            raise Exception('perf_event_open failed, errno = ' + err.__str__())
         if filter:
             import fcntl
             fcntl.ioctl(fd, ioctl_numbers['SET_FILTER'], filter)
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH v3 3/4 kvm_stat: Add aarch64 support

In reply to Wei Huang

This patch enables aarch64 support for kvm_stat. The platform detection is based on OS uname.

---
 scripts/kvm/kvm_stat | 8 ++++++++
 1 file changed, 8 insertions(+)
scripts/kvm/kvm_stat +8 -0
index cb23877..8f6f007 100755
@@ -209,10 +209,18 @@ def ppc_init():
         }
     })
 
+def aarch64_init():
+    globals().update({
+        'sc_perf_evt_open' : 241
+    })
+
 def detect_platform():
     if os.uname()[4].startswith('ppc'):
         ppc_init()
         return
+    elif os.uname()[4].startswith('aarch64'):
+        aarch64_init()
+        return
 
     for line in file('/proc/cpuinfo').readlines():
         if line.startswith('flags'):
Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH v3 4/4 kvm_stat: Add RESET support for perf event ioctl

In reply to Wei Huang

While running kvm_stat using tracepoint on ARM64 hardware (e.g. "kvm_stat -1 -t"), the initial values of some kvm_userspace_exit counters were found to be very suspecious. For instance the tracing tool showed that S390_TSCH was called many times on ARM64 machine, which apparently was wrong.

This patch adds RESET ioctl support for perf monitoring. Before calling ioctl to enable a perf event, this patch resets the counter first. With this patch, the init counter values become correct on ARM64 hardware.

Example:

==== before patch ====
kvm_userspace_exit(S390_SIEIC) 1426 0
kvm_userspace_exit(S390_TSCH) 339 0

==== after patch ====
kvm_userspace_exit(S390_SIEIC) 0 0
kvm_userspace_exit(S390_TSCH) 0 0

---
 scripts/kvm/kvm_stat | 5 +++++
 1 file changed, 5 insertions(+)
scripts/kvm/kvm_stat +5 -0
index 8f6f007..f927e97 100755
@@ -186,6 +186,7 @@ ioctl_numbers = {
     'SET_FILTER' : 0x40082406,
     'ENABLE'     : 0x00002400,
     'DISABLE'    : 0x00002401,
+    'RESET'      : 0x00002403,
 }
 
 def x86_init(flag):
@@ -346,6 +347,9 @@ class Event(object):
     def disable(self):
         import fcntl
         fcntl.ioctl(self.fd, ioctl_numbers['DISABLE'], 0)
+    def reset(self):
+        import fcntl
+        fcntl.ioctl(self.fd, ioctl_numbers['RESET'], 0)
 
 class TracepointProvider(object):
     def __init__(self):
@@ -405,7 +409,7 @@ class TracepointProvider(object):
         for group in self.group_leaders:
             for event in group.events:
                 if event.name in fields:
+                    event.reset()
                     event.enable()
                 else:
                     event.disable()
Signature · 1 line
1.8.3.1