From edcbc401f42077f9d62713d439839201a73a5966 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Wed, 21 Jan 2015 16:15:29 -0500 Subject: kvm_stat: Add aarch64 support This patch enables aarch64 support for kvm_stat. The platform detection is based on OS uname. Signed-off-by: Wei Huang Signed-off-by: Paolo Bonzini --- scripts/kvm/kvm_stat | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts') diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 7b1437c..470ca08 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -204,10 +204,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'): -- cgit v1.1 From 2c9d535a2e43699de32987b76cf548a39e4d04d2 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Wed, 21 Jan 2015 16:15:30 -0500 Subject: 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. Signed-off-by: Wei Huang Signed-off-by: Paolo Bonzini --- scripts/kvm/kvm_stat | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'scripts') diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 470ca08..95c650b 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -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 = { -- cgit v1.1 From 874b1cfad51e325d535f99261f91c92df444c18c Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Wed, 21 Jan 2015 16:15:31 -0500 Subject: kvm_stat: Print errno when syscall to perf_event_open() fails 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 such 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". Signed-off-by: Wei Huang Signed-off-by: Paolo Bonzini --- scripts/kvm/kvm_stat | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 95c650b..8f6f007 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -13,6 +13,7 @@ import curses import sys, os, time, optparse, ctypes +from ctypes import * class DebugfsProvider(object): def __init__(self): @@ -247,6 +248,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), @@ -330,7 +334,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) -- cgit v1.1 From fc116efad0aadb2f8a49d51240bddbfe21b631a0 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Fri, 23 Jan 2015 15:56:04 -0500 Subject: kvm_stat: Add RESET support for perf event ioctl 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 Signed-off-by: Wei Huang --- scripts/kvm/kvm_stat | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'scripts') diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 8f6f007..c0c4ff0 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -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() -- cgit v1.1