qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V2 0/4] kvm_stat update
@ 2015-01-23 20:44 Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 1/4] kvm_stat: Update exit reasons to the latest defintion Wei Huang
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Wei Huang @ 2015-01-23 20:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peter.maydell

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(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH V2 1/4] kvm_stat: Update exit reasons to the latest defintion
  2015-01-23 20:44 [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
@ 2015-01-23 20:44 ` Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 2/4] kvm_stat: Print errno when syscall to perf_event_open() fails Wei Huang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Huang @ 2015-01-23 20:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peter.maydell

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

Signed-off-by: Wei Huang <wei@redhat.com>
---
 scripts/kvm/kvm_stat | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 7b1437c..7ec84c0 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 = {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH V2 2/4] kvm_stat: Print errno when syscall to perf_event_open() fails
  2015-01-23 20:44 [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 1/4] kvm_stat: Update exit reasons to the latest defintion Wei Huang
@ 2015-01-23 20:44 ` Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 3/4] kvm_stat: Add aarch64 support Wei Huang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Huang @ 2015-01-23 20:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peter.maydell

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".

Signed-off-by: Wei Huang <wei@redhat.com>
---
 scripts/kvm/kvm_stat | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 7ec84c0..cb23877 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):
@@ -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)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH V2 3/4] kvm_stat: Add aarch64 support
  2015-01-23 20:44 [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 1/4] kvm_stat: Update exit reasons to the latest defintion Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 2/4] kvm_stat: Print errno when syscall to perf_event_open() fails Wei Huang
@ 2015-01-23 20:44 ` Wei Huang
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 4/4] kvm_stat: Add RESET support for perf event ioctl Wei Huang
  2015-01-23 20:59 ` [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Huang @ 2015-01-23 20:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peter.maydell

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

Signed-off-by: Wei Huang <wei@redhat.com>
---
 scripts/kvm/kvm_stat | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index cb23877..8f6f007 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -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'):
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH V2 4/4] kvm_stat: Add RESET support for perf event ioctl
  2015-01-23 20:44 [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
                   ` (2 preceding siblings ...)
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 3/4] kvm_stat: Add aarch64 support Wei Huang
@ 2015-01-23 20:44 ` Wei Huang
  2015-01-23 20:59 ` [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Huang @ 2015-01-23 20:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peter.maydell

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 <wei@redhat.com>
---
 scripts/kvm/kvm_stat | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 8f6f007..f927e97 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()
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH V2 0/4] kvm_stat update
  2015-01-23 20:44 [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
                   ` (3 preceding siblings ...)
  2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 4/4] kvm_stat: Add RESET support for perf event ioctl Wei Huang
@ 2015-01-23 20:59 ` Wei Huang
  4 siblings, 0 replies; 6+ messages in thread
From: Wei Huang @ 2015-01-23 20:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peter.maydell

Sorry, please ignore this version.

-Wei

On 01/23/2015 02:44 PM, Wei Huang wrote:
> 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(-)
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-23 20:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-23 20:44 [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang
2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 1/4] kvm_stat: Update exit reasons to the latest defintion Wei Huang
2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 2/4] kvm_stat: Print errno when syscall to perf_event_open() fails Wei Huang
2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 3/4] kvm_stat: Add aarch64 support Wei Huang
2015-01-23 20:44 ` [Qemu-devel] [PATCH V2 4/4] kvm_stat: Add RESET support for perf event ioctl Wei Huang
2015-01-23 20:59 ` [Qemu-devel] [PATCH V2 0/4] kvm_stat update Wei Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).