kvm_stat update
v2 cover kvm_stat update
This is the second 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
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
PATCH v2 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
@@ -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
PATCH v2 2/4 kvm_stat: Print errno when syscall to perf_event_open() fails
In reply to Wei Huangkvm_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
@@ -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
PATCH v2 3/4 kvm_stat: Add aarch64 support
In reply to Wei HuangThis 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
@@ -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
PATCH v2 4/4 kvm_stat: Add RESET support for perf event ioctl
In reply to Wei HuangWhile 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 0kvm_userspace_exit(S390_TSCH) 339 0
==== after patch ====kvm_userspace_exit(S390_SIEIC) 0 0kvm_userspace_exit(S390_TSCH) 0 0
--- scripts/kvm/kvm_stat | 5 +++++ 1 file changed, 5 insertions(+)
scripts/kvm/kvm_stat +5 -0
@@ -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,6 +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
Sorry, please ignore this version.
-Wei
Quoted 28 lines · Wei Huang
This is the second version of
kvm_statpatches. Please review.NOTE: I have tested these patches on ARM64 and
x86_64machines. For PPC, the only area been affected is ioctl RESET number (patch 4). Unfortunately I don't have PPC hardware to test them.Thanks,
-WeiV2:
- fix a typo in VMX exit reason (pointed out by Paolo)
- add ioctl RESET function to initialize counters
- re-arrange the order of patchesV1:
- support for ARM aarch64
- update to the latest exit reasons (vmx, svm and userspace)
- print errno when syscall failsWei Huang (4):
kvm_stat: Update exit reasons to the latest defintion
kvm_stat: Print errno when syscall toperf_event_open()fails
kvm_stat: Add aarch64 support
kvm_stat: Add RESET support for perf event ioctlscripts/kvm/kvm_stat | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)