qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus
@ 2014-06-17  7:54 Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons Michael Ellerman
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Michael Ellerman @ 2014-06-17  7:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs, pbonzini

In kvm_stat we grovel through /sys to find out how many cpus are in the
system. However if a cpu is offline it will still be present in /sys,
and the perf_event_open() will fail.

Modify the logic to only return online cpus. We need to be careful on
systems which don't support cpu hotplug, the online file will not be
present at all.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 scripts/kvm/kvm_stat | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index d7e97e7..2a788bc 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -311,18 +311,30 @@ class TracepointProvider(object):
         self.select(fields)
     def fields(self):
         return self._fields
+
+    def _online_cpus(self):
+        l = []
+        pattern = r'cpu([0-9]+)'
+        basedir = '/sys/devices/system/cpu'
+        for entry in os.listdir(basedir):
+            match = re.match(pattern, entry)
+            if not match:
+                continue
+            path = os.path.join(basedir, entry, 'online')
+            if os.path.exists(path) and open(path).read().strip() != '1':
+                continue
+            l.append(int(match.group(1)))
+        return l
+
     def _setup(self, _fields):
         self._fields = _fields
-        cpure = r'cpu([0-9]+)'
-        self.cpus = [int(re.match(cpure, x).group(1))
-                     for x in os.listdir('/sys/devices/system/cpu')
-                     if re.match(cpure, x)]
+        cpus = self._online_cpus()
         import resource
-        nfiles = len(self.cpus) * 1000
+        nfiles = len(cpus) * 1000
         resource.setrlimit(resource.RLIMIT_NOFILE, (nfiles, nfiles))
         events = []
         self.group_leaders = []
-        for cpu in self.cpus:
+        for cpu in cpus:
             group = Group(cpu)
             for name in _fields:
                 tracepoint = name
-- 
1.9.1

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

* [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons
  2014-06-17  7:54 [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus Michael Ellerman
@ 2014-06-17  7:54 ` Michael Ellerman
  2014-10-31 15:49   ` Paolo Bonzini
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 3/6] kvm_stat: Rework platform detection Michael Ellerman
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Michael Ellerman @ 2014-06-17  7:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs, pbonzini

In kvm_stat we have a dictionary of exit reasons for s390. Firstly these
are not s390 specific, they are the generic exit reasons. So rename the
dictionary to reflect that.

Secondly, the values are defined using hex, but in the kernel header
they are decimal. That means values above 9 in kvm_stat are incorrect.

As far as I can tell this does not matter in practice because s390 does
not define a kvm_exit trace point.

While we're there, fix the whitespace to match the rest of the file.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 scripts/kvm/kvm_stat | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 2a788bc..fe2eae3 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -141,33 +141,38 @@ svm_exit_reasons = {
     0x400: 'NPF',
 }
 
-s390_exit_reasons = {
-	0x000: 'UNKNOWN',
-	0x001: 'EXCEPTION',
-	0x002: 'IO',
-	0x003: 'HYPERCALL',
-	0x004: 'DEBUG',
-	0x005: 'HLT',
-	0x006: 'MMIO',
-	0x007: 'IRQ_WINDOW_OPEN',
-	0x008: 'SHUTDOWN',
-	0x009: 'FAIL_ENTRY',
-	0x010: 'INTR',
-	0x011: 'SET_TPR',
-	0x012: 'TPR_ACCESS',
-	0x013: 'S390_SIEIC',
-	0x014: 'S390_RESET',
-	0x015: 'DCR',
-	0x016: 'NMI',
-	0x017: 'INTERNAL_ERROR',
-	0x018: 'OSI',
-	0x019: 'PAPR_HCALL',
+# From include/uapi/linux/kvm.h, KVM_EXIT_xxx
+generic_exit_reasons = {
+     0: 'UNKNOWN',
+     1: 'EXCEPTION',
+     2: 'IO',
+     3: 'HYPERCALL',
+     4: 'DEBUG',
+     5: 'HLT',
+     6: 'MMIO',
+     7: 'IRQ_WINDOW_OPEN',
+     8: 'SHUTDOWN',
+     9: 'FAIL_ENTRY',
+    10: 'INTR',
+    11: 'SET_TPR',
+    12: 'TPR_ACCESS',
+    13: 'S390_SIEIC',
+    14: 'S390_RESET',
+    15: 'DCR',
+    16: 'NMI',
+    17: 'INTERNAL_ERROR',
+    18: 'OSI',
+    19: 'PAPR_HCALL',
+    20: 'S390_UCONTROL',
+    21: 'WATCHDOG',
+    22: 'S390_TSCH',
+    23: 'EPR',
 }
 
 vendor_exit_reasons = {
     'vmx': vmx_exit_reasons,
     'svm': svm_exit_reasons,
-    'IBM/S390': s390_exit_reasons,
+    'IBM/S390': generic_exit_reasons,
 }
 
 syscall_numbers = {
-- 
1.9.1

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

* [Qemu-devel] [PATCH 3/6] kvm_stat: Rework platform detection
  2014-06-17  7:54 [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons Michael Ellerman
@ 2014-06-17  7:54 ` Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 4/6] kvm_stat: Fix tracepoint filter definition for s390 Michael Ellerman
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2014-06-17  7:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs, pbonzini

The current platform detection is a little bit messy. We look for lines
in /proc/cpuinfo starting with 'flags' OR 'vendor-id', and scan both
for values we know will only occur in one or the other. We also keep
scanning once we've found a value, which could be a feature, but isn't
in this case.

We'd also like to add another platform, powerpc, which will just make it
worse. So clean it up in preparation.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 scripts/kvm/kvm_stat | 44 +++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index fe2eae3..98c81a8 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -169,27 +169,41 @@ generic_exit_reasons = {
     23: 'EPR',
 }
 
-vendor_exit_reasons = {
+x86_exit_reasons = {
     'vmx': vmx_exit_reasons,
     'svm': svm_exit_reasons,
-    'IBM/S390': generic_exit_reasons,
 }
 
-syscall_numbers = {
-    'IBM/S390': 331,
-}
-
-sc_perf_evt_open = 298
-
+sc_perf_evt_open = None
 exit_reasons = None
 
-for line in file('/proc/cpuinfo').readlines():
-    if line.startswith('flags') or line.startswith('vendor_id'):
-        for flag in line.split():
-            if flag in vendor_exit_reasons:
-                exit_reasons = vendor_exit_reasons[flag]
-            if flag in syscall_numbers:
-                sc_perf_evt_open = syscall_numbers[flag]
+def x86_init(flag):
+    globals().update({
+        'sc_perf_evt_open' : 298,
+        'exit_reasons' : x86_exit_reasons[flag],
+    })
+
+def s390_init():
+    globals().update({
+        'sc_perf_evt_open' : 331,
+        'exit_reasons' : generic_exit_reasons,
+    })
+
+def detect_platform():
+    for line in file('/proc/cpuinfo').readlines():
+        if line.startswith('flags'):
+            for flag in line.split():
+                if flag in x86_exit_reasons:
+                    x86_init(flag)
+                    return
+        elif line.startswith('vendor_id'):
+            for flag in line.split():
+                if flag == 'IBM/S390':
+                    s390_init()
+                    return
+
+detect_platform()
+
 filters = {
     'kvm_exit': ('exit_reason', exit_reasons)
 }
-- 
1.9.1

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

* [Qemu-devel] [PATCH 4/6] kvm_stat: Fix tracepoint filter definition for s390
  2014-06-17  7:54 [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 3/6] kvm_stat: Rework platform detection Michael Ellerman
@ 2014-06-17  7:54 ` Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 5/6] kvm_stat: Abstract ioctl numbers Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support Michael Ellerman
  4 siblings, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2014-06-17  7:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs, pbonzini

Although we have the exit_reasons defined for s390, as far as I can tell
they never take effect. That is because there is no 'kvm_exit'
tracepoint defined for s390.

What is defined, for all platforms, is 'kvm_userspace_exit'. That
tracepoint uses the generic_exit_reason, but the filter parameter is
'reason'.

So invert the way we setup filters, define it by default for the generic
tracepoint 'kvm_userspace_exit', and let x86 override it. Doing it this
way will also work for powerpc when we add it.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 scripts/kvm/kvm_stat | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 98c81a8..2468a22 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -175,18 +175,22 @@ x86_exit_reasons = {
 }
 
 sc_perf_evt_open = None
-exit_reasons = None
+
+filters = {
+    'kvm_userspace_exit': ('reason', generic_exit_reasons)
+}
 
 def x86_init(flag):
     globals().update({
         'sc_perf_evt_open' : 298,
-        'exit_reasons' : x86_exit_reasons[flag],
+        'filters' : {
+            'kvm_exit': ('exit_reason', x86_exit_reasons[flag])
+        },
     })
 
 def s390_init():
     globals().update({
         'sc_perf_evt_open' : 331,
-        'exit_reasons' : generic_exit_reasons,
     })
 
 def detect_platform():
@@ -204,10 +208,6 @@ def detect_platform():
 
 detect_platform()
 
-filters = {
-    'kvm_exit': ('exit_reason', exit_reasons)
-}
-
 def invert(d):
     return dict((x[1], x[0]) for x in d.iteritems())
 
-- 
1.9.1

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

* [Qemu-devel] [PATCH 5/6] kvm_stat: Abstract ioctl numbers
  2014-06-17  7:54 [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus Michael Ellerman
                   ` (2 preceding siblings ...)
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 4/6] kvm_stat: Fix tracepoint filter definition for s390 Michael Ellerman
@ 2014-06-17  7:54 ` Michael Ellerman
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support Michael Ellerman
  4 siblings, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2014-06-17  7:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs, pbonzini

Unfortunately ioctl numbers are platform specific, so abstract them out
of the code so they can be overridden. As it happens x86 and s390 share
the same values, so nothing needs to change yet.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 scripts/kvm/kvm_stat | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 2468a22..2e0f5ed 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -180,6 +180,12 @@ filters = {
     'kvm_userspace_exit': ('reason', generic_exit_reasons)
 }
 
+ioctl_numbers = {
+    'SET_FILTER' : 0x40082406,
+    'ENABLE'     : 0x00002400,
+    'DISABLE'    : 0x00002401,
+}
+
 def x86_init(flag):
     globals().update({
         'sc_perf_evt_open' : 298,
@@ -304,14 +310,14 @@ class Event(object):
             raise Exception('perf_event_open failed')
         if filter:
             import fcntl
-            fcntl.ioctl(fd, 0x40082406, filter)
+            fcntl.ioctl(fd, ioctl_numbers['SET_FILTER'], filter)
         self.fd = fd
     def enable(self):
         import fcntl
-        fcntl.ioctl(self.fd, 0x00002400, 0)
+        fcntl.ioctl(self.fd, ioctl_numbers['ENABLE'], 0)
     def disable(self):
         import fcntl
-        fcntl.ioctl(self.fd, 0x00002401, 0)
+        fcntl.ioctl(self.fd, ioctl_numbers['DISABLE'], 0)
 
 class TracepointProvider(object):
     def __init__(self):
-- 
1.9.1

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

* [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-17  7:54 [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus Michael Ellerman
                   ` (3 preceding siblings ...)
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 5/6] kvm_stat: Abstract ioctl numbers Michael Ellerman
@ 2014-06-17  7:54 ` Michael Ellerman
  2014-06-17  8:27   ` Alexander Graf
  2014-10-31 15:36   ` Paolo Bonzini
  4 siblings, 2 replies; 14+ messages in thread
From: Michael Ellerman @ 2014-06-17  7:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs, pbonzini

Add support for powerpc platforms. We use uname -m, which allows us to
detect ppc, ppc64 and ppc64le/el.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 scripts/kvm/kvm_stat | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 2e0f5ed..db867fe 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -12,7 +12,7 @@
 # the COPYING file in the top-level directory.
 
 import curses
-import sys, os, time, optparse
+import sys, os, time, optparse, ctypes
 
 class DebugfsProvider(object):
     def __init__(self):
@@ -199,7 +199,21 @@ def s390_init():
         'sc_perf_evt_open' : 331,
     })
 
+def ppc_init():
+    globals().update({
+        'sc_perf_evt_open' : 319,
+        'ioctl_numbers' : {
+            'SET_FILTER' : 0x80002406 | (ctypes.sizeof(ctypes.c_char_p) << 16),
+            'ENABLE'     : 0x20002400,
+            'DISABLE'    : 0x20002401,
+        }
+    })
+
 def detect_platform():
+    if os.uname()[4].startswith('ppc'):
+        ppc_init()
+        return
+
     for line in file('/proc/cpuinfo').readlines():
         if line.startswith('flags'):
             for flag in line.split():
@@ -220,7 +234,7 @@ def invert(d):
 for f in filters:
     filters[f] = (filters[f][0], invert(filters[f][1]))
 
-import ctypes, struct, array
+import struct, array
 
 libc = ctypes.CDLL('libc.so.6')
 syscall = libc.syscall
-- 
1.9.1

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support Michael Ellerman
@ 2014-06-17  8:27   ` Alexander Graf
  2014-06-18  0:50     ` Michael Ellerman
  2014-10-31 15:36   ` Paolo Bonzini
  1 sibling, 1 reply; 14+ messages in thread
From: Alexander Graf @ 2014-06-17  8:27 UTC (permalink / raw)
  To: Michael Ellerman, qemu-devel; +Cc: kvm, aik, jan.kiszka, jfrei, alfs, pbonzini


On 17.06.14 09:54, Michael Ellerman wrote:
> Add support for powerpc platforms. We use uname -m, which allows us to
> detect ppc, ppc64 and ppc64le/el.
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Could you please add support for PR KVM tracepoints along the way? There 
we do know the exit reason for every single guest <-> host transition. I 
would like to move to a similar model with HV in the future, so we can 
hopefully just reuse this by then.


Alex

> ---
>   scripts/kvm/kvm_stat | 18 ++++++++++++++++--
>   1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
> index 2e0f5ed..db867fe 100755
> --- a/scripts/kvm/kvm_stat
> +++ b/scripts/kvm/kvm_stat
> @@ -12,7 +12,7 @@
>   # the COPYING file in the top-level directory.
>   
>   import curses
> -import sys, os, time, optparse
> +import sys, os, time, optparse, ctypes
>   
>   class DebugfsProvider(object):
>       def __init__(self):
> @@ -199,7 +199,21 @@ def s390_init():
>           'sc_perf_evt_open' : 331,
>       })
>   
> +def ppc_init():
> +    globals().update({
> +        'sc_perf_evt_open' : 319,
> +        'ioctl_numbers' : {
> +            'SET_FILTER' : 0x80002406 | (ctypes.sizeof(ctypes.c_char_p) << 16),
> +            'ENABLE'     : 0x20002400,
> +            'DISABLE'    : 0x20002401,
> +        }
> +    })
> +
>   def detect_platform():
> +    if os.uname()[4].startswith('ppc'):
> +        ppc_init()
> +        return
> +
>       for line in file('/proc/cpuinfo').readlines():
>           if line.startswith('flags'):
>               for flag in line.split():
> @@ -220,7 +234,7 @@ def invert(d):
>   for f in filters:
>       filters[f] = (filters[f][0], invert(filters[f][1]))
>   
> -import ctypes, struct, array
> +import struct, array
>   
>   libc = ctypes.CDLL('libc.so.6')
>   syscall = libc.syscall

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-17  8:27   ` Alexander Graf
@ 2014-06-18  0:50     ` Michael Ellerman
  2014-06-18  0:59       ` Alexander Graf
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Ellerman @ 2014-06-18  0:50 UTC (permalink / raw)
  To: Alexander Graf; +Cc: graalfs, kvm, aik, jan.kiszka, qemu-devel, jfrei, pbonzini

On Tue, 2014-06-17 at 10:27 +0200, Alexander Graf wrote:
> On 17.06.14 09:54, Michael Ellerman wrote:
> > Add support for powerpc platforms. We use uname -m, which allows us to
> > detect ppc, ppc64 and ppc64le/el.
> >
> > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> 
> Could you please add support for PR KVM tracepoints along the way? There 
> we do know the exit reason for every single guest <-> host transition. I 
> would like to move to a similar model with HV in the future, so we can 
> hopefully just reuse this by then.

So I think what you're saying is you want it to somehow support using
'kvm_exit' for PR and 'kvm_userspace_exit' for HV?

Or actually use 'kvm_exit' if it exists and fall back to 'kvm_userspace_exit',
so that if HV starts providing 'kvm_exit' the script will pick that up without
further changes.

cheers

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-18  0:50     ` Michael Ellerman
@ 2014-06-18  0:59       ` Alexander Graf
  2014-06-18  1:37         ` Michael Ellerman
  0 siblings, 1 reply; 14+ messages in thread
From: Alexander Graf @ 2014-06-18  0:59 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: graalfs, kvm, aik, jan.kiszka, qemu-devel, jfrei, pbonzini


On 18.06.14 02:50, Michael Ellerman wrote:
> On Tue, 2014-06-17 at 10:27 +0200, Alexander Graf wrote:
>> On 17.06.14 09:54, Michael Ellerman wrote:
>>> Add support for powerpc platforms. We use uname -m, which allows us to
>>> detect ppc, ppc64 and ppc64le/el.
>>>
>>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>> Could you please add support for PR KVM tracepoints along the way? There
>> we do know the exit reason for every single guest <-> host transition. I
>> would like to move to a similar model with HV in the future, so we can
>> hopefully just reuse this by then.
> So I think what you're saying is you want it to somehow support using
> 'kvm_exit' for PR and 'kvm_userspace_exit' for HV?

"kvm_userspace_exit" is implemented on both HV and PR. "kvm_exit" is PR 
only, but I'm hoping we can get it working in HV as well.

> Or actually use 'kvm_exit' if it exists and fall back to 'kvm_userspace_exit',
> so that if HV starts providing 'kvm_exit' the script will pick that up without
> further changes.

They are completely different things. "kvm_userspace_exit" tells us 
which exits we take from KVM -> QEMU. "kvm_exit" tells us which exits we 
take from guest -> KVM.

In fact, IIRC x86 also implements kvm_userspace_exit - or at least 
something very similar to it. It's a completely separate category. Maybe 
it should be a command line switch to distinguish between the count types?

Paolo, do you have any strong opinion here?


Alex

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-18  0:59       ` Alexander Graf
@ 2014-06-18  1:37         ` Michael Ellerman
  2014-06-18  1:54           ` Alexander Graf
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Ellerman @ 2014-06-18  1:37 UTC (permalink / raw)
  To: Alexander Graf; +Cc: graalfs, kvm, aik, jan.kiszka, qemu-devel, jfrei, pbonzini

On Wed, 2014-06-18 at 02:59 +0200, Alexander Graf wrote:
> On 18.06.14 02:50, Michael Ellerman wrote:
> > On Tue, 2014-06-17 at 10:27 +0200, Alexander Graf wrote:
> >> On 17.06.14 09:54, Michael Ellerman wrote:
> >>> Add support for powerpc platforms. We use uname -m, which allows us to
> >>> detect ppc, ppc64 and ppc64le/el.
> >>>
> >>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> >> Could you please add support for PR KVM tracepoints along the way? There
> >> we do know the exit reason for every single guest <-> host transition. I
> >> would like to move to a similar model with HV in the future, so we can
> >> hopefully just reuse this by then.
> > So I think what you're saying is you want it to somehow support using
> > 'kvm_exit' for PR and 'kvm_userspace_exit' for HV?
> 
> "kvm_userspace_exit" is implemented on both HV and PR. "kvm_exit" is PR 
> only, but I'm hoping we can get it working in HV as well.
> 
> > Or actually use 'kvm_exit' if it exists and fall back to 'kvm_userspace_exit',
> > so that if HV starts providing 'kvm_exit' the script will pick that up without
> > further changes.
> 
> They are completely different things. "kvm_userspace_exit" tells us 
> which exits we take from KVM -> QEMU. "kvm_exit" tells us which exits we 
> take from guest -> KVM.
>
> In fact, IIRC x86 also implements kvm_userspace_exit - or at least 
> something very similar to it. It's a completely separate category. 

Right. Everyone implements kvm_userspace_exit, it's in virt/kvm/kvm_main.c

> Maybe it should be a command line switch to distinguish between the count types?

Or just we always read the kvm_userspace_exit counts, and if we find kvm_exit
we expose that as well - with an arch specific set of reasons.

cheers

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-18  1:37         ` Michael Ellerman
@ 2014-06-18  1:54           ` Alexander Graf
  0 siblings, 0 replies; 14+ messages in thread
From: Alexander Graf @ 2014-06-18  1:54 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: graalfs, kvm, aik, jan.kiszka, qemu-devel, jfrei, pbonzini


On 18.06.14 03:37, Michael Ellerman wrote:
> On Wed, 2014-06-18 at 02:59 +0200, Alexander Graf wrote:
>> On 18.06.14 02:50, Michael Ellerman wrote:
>>> On Tue, 2014-06-17 at 10:27 +0200, Alexander Graf wrote:
>>>> On 17.06.14 09:54, Michael Ellerman wrote:
>>>>> Add support for powerpc platforms. We use uname -m, which allows us to
>>>>> detect ppc, ppc64 and ppc64le/el.
>>>>>
>>>>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>>>> Could you please add support for PR KVM tracepoints along the way? There
>>>> we do know the exit reason for every single guest <-> host transition. I
>>>> would like to move to a similar model with HV in the future, so we can
>>>> hopefully just reuse this by then.
>>> So I think what you're saying is you want it to somehow support using
>>> 'kvm_exit' for PR and 'kvm_userspace_exit' for HV?
>> "kvm_userspace_exit" is implemented on both HV and PR. "kvm_exit" is PR
>> only, but I'm hoping we can get it working in HV as well.
>>
>>> Or actually use 'kvm_exit' if it exists and fall back to 'kvm_userspace_exit',
>>> so that if HV starts providing 'kvm_exit' the script will pick that up without
>>> further changes.
>> They are completely different things. "kvm_userspace_exit" tells us
>> which exits we take from KVM -> QEMU. "kvm_exit" tells us which exits we
>> take from guest -> KVM.
>>
>> In fact, IIRC x86 also implements kvm_userspace_exit - or at least
>> something very similar to it. It's a completely separate category.
> Right. Everyone implements kvm_userspace_exit, it's in virt/kvm/kvm_main.c
>
>> Maybe it should be a command line switch to distinguish between the count types?
> Or just we always read the kvm_userspace_exit counts, and if we find kvm_exit
> we expose that as well - with an arch specific set of reasons.

That would work too. I'm not sure how interesting the exit count of 
kvm_userspace_exit really is, but it certainly works for me to have it 
available as well.


Alex

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support Michael Ellerman
  2014-06-17  8:27   ` Alexander Graf
@ 2014-10-31 15:36   ` Paolo Bonzini
  2014-11-03  0:40     ` Michael Ellerman
  1 sibling, 1 reply; 14+ messages in thread
From: Paolo Bonzini @ 2014-10-31 15:36 UTC (permalink / raw)
  To: Michael Ellerman, qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs

Thanks, applied the series at last.

Paolo

On 17/06/2014 09:54, Michael Ellerman wrote:
> Add support for powerpc platforms. We use uname -m, which allows us to
> detect ppc, ppc64 and ppc64le/el.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  scripts/kvm/kvm_stat | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
> index 2e0f5ed..db867fe 100755
> --- a/scripts/kvm/kvm_stat
> +++ b/scripts/kvm/kvm_stat
> @@ -12,7 +12,7 @@
>  # the COPYING file in the top-level directory.
>  
>  import curses
> -import sys, os, time, optparse
> +import sys, os, time, optparse, ctypes
>  
>  class DebugfsProvider(object):
>      def __init__(self):
> @@ -199,7 +199,21 @@ def s390_init():
>          'sc_perf_evt_open' : 331,
>      })
>  
> +def ppc_init():
> +    globals().update({
> +        'sc_perf_evt_open' : 319,
> +        'ioctl_numbers' : {
> +            'SET_FILTER' : 0x80002406 | (ctypes.sizeof(ctypes.c_char_p) << 16),
> +            'ENABLE'     : 0x20002400,
> +            'DISABLE'    : 0x20002401,
> +        }
> +    })
> +
>  def detect_platform():
> +    if os.uname()[4].startswith('ppc'):
> +        ppc_init()
> +        return
> +
>      for line in file('/proc/cpuinfo').readlines():
>          if line.startswith('flags'):
>              for flag in line.split():
> @@ -220,7 +234,7 @@ def invert(d):
>  for f in filters:
>      filters[f] = (filters[f][0], invert(filters[f][1]))
>  
> -import ctypes, struct, array
> +import struct, array
>  
>  libc = ctypes.CDLL('libc.so.6')
>  syscall = libc.syscall
> 

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

* Re: [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons
  2014-06-17  7:54 ` [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons Michael Ellerman
@ 2014-10-31 15:49   ` Paolo Bonzini
  0 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2014-10-31 15:49 UTC (permalink / raw)
  To: Michael Ellerman, qemu-devel; +Cc: kvm, aik, jan.kiszka, agraf, jfrei, alfs



On 17/06/2014 09:54, Michael Ellerman wrote:
> In kvm_stat we have a dictionary of exit reasons for s390. Firstly these
> are not s390 specific, they are the generic exit reasons. So rename the
> dictionary to reflect that.
> 
> Secondly, the values are defined using hex, but in the kernel header
> they are decimal. That means values above 9 in kvm_stat are incorrect.
> 
> As far as I can tell this does not matter in practice because s390 does
> not define a kvm_exit trace point.

Right, this should be for kvm_userspace_exit.  If we do this instead of
your patch 4, we should get kvm_userspace_exit on x86 too:

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index fe2eae3..5cd2758 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -142,7 +142,7 @@ svm_exit_reasons = {
 }

 # From include/uapi/linux/kvm.h, KVM_EXIT_xxx
-generic_exit_reasons = {
+userspace_exit_reasons = {
      0: 'UNKNOWN',
      1: 'EXCEPTION',
      2: 'IO',
@@ -172,7 +172,6 @@ generic_exit_reasons = {
 vendor_exit_reasons = {
     'vmx': vmx_exit_reasons,
     'svm': svm_exit_reasons,
-    'IBM/S390': generic_exit_reasons,
 }

 syscall_numbers = {
@@ -190,9 +189,11 @@ for line in file('/proc/cpuinfo').readlines():
                 exit_reasons = vendor_exit_reasons[flag]
             if flag in syscall_numbers:
                 sc_perf_evt_open = syscall_numbers[flag]
-filters = {
-    'kvm_exit': ('exit_reason', exit_reasons)
-}
+
+filters = {}
+filters['kvm_userspace_exit'] = ('reason', userspace_exit_reasons)
+if exit_reasons:
+    filters['kvm_exit'] = ('exit_reason', exit_reasons)

 def invert(d):
     return dict((x[1], x[0]) for x in d.iteritems())

> 
> While we're there, fix the whitespace to match the rest of the file.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  scripts/kvm/kvm_stat | 49 +++++++++++++++++++++++++++----------------------
>  1 file changed, 27 insertions(+), 22 deletions(-)
> 
> diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
> index 2a788bc..fe2eae3 100755
> --- a/scripts/kvm/kvm_stat
> +++ b/scripts/kvm/kvm_stat
> @@ -141,33 +141,38 @@ svm_exit_reasons = {
>      0x400: 'NPF',
>  }
>  
> -s390_exit_reasons = {
> -	0x000: 'UNKNOWN',
> -	0x001: 'EXCEPTION',
> -	0x002: 'IO',
> -	0x003: 'HYPERCALL',
> -	0x004: 'DEBUG',
> -	0x005: 'HLT',
> -	0x006: 'MMIO',
> -	0x007: 'IRQ_WINDOW_OPEN',
> -	0x008: 'SHUTDOWN',
> -	0x009: 'FAIL_ENTRY',
> -	0x010: 'INTR',
> -	0x011: 'SET_TPR',
> -	0x012: 'TPR_ACCESS',
> -	0x013: 'S390_SIEIC',
> -	0x014: 'S390_RESET',
> -	0x015: 'DCR',
> -	0x016: 'NMI',
> -	0x017: 'INTERNAL_ERROR',
> -	0x018: 'OSI',
> -	0x019: 'PAPR_HCALL',
> +# From include/uapi/linux/kvm.h, KVM_EXIT_xxx
> +generic_exit_reasons = {
> +     0: 'UNKNOWN',
> +     1: 'EXCEPTION',
> +     2: 'IO',
> +     3: 'HYPERCALL',
> +     4: 'DEBUG',
> +     5: 'HLT',
> +     6: 'MMIO',
> +     7: 'IRQ_WINDOW_OPEN',
> +     8: 'SHUTDOWN',
> +     9: 'FAIL_ENTRY',
> +    10: 'INTR',
> +    11: 'SET_TPR',
> +    12: 'TPR_ACCESS',
> +    13: 'S390_SIEIC',
> +    14: 'S390_RESET',
> +    15: 'DCR',
> +    16: 'NMI',
> +    17: 'INTERNAL_ERROR',
> +    18: 'OSI',
> +    19: 'PAPR_HCALL',
> +    20: 'S390_UCONTROL',
> +    21: 'WATCHDOG',
> +    22: 'S390_TSCH',
> +    23: 'EPR',
>  }
>  
>  vendor_exit_reasons = {
>      'vmx': vmx_exit_reasons,
>      'svm': svm_exit_reasons,
> -    'IBM/S390': s390_exit_reasons,
> +    'IBM/S390': generic_exit_reasons,
>  }
>  
>  syscall_numbers = {
> 

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

* Re: [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support
  2014-10-31 15:36   ` Paolo Bonzini
@ 2014-11-03  0:40     ` Michael Ellerman
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2014-11-03  0:40 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, aik, jan.kiszka, qemu-devel, agraf, jfrei, alfs

On Fri, 2014-10-31 at 16:36 +0100, Paolo Bonzini wrote:
> Thanks, applied the series at last.

Thanks.

cheers

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

end of thread, other threads:[~2014-11-03  0:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17  7:54 [Qemu-devel] [PATCH 1/6] kvm_stat: Only consider online cpus Michael Ellerman
2014-06-17  7:54 ` [Qemu-devel] [PATCH 2/6] kvm_stat: Fix the non-x86 exit reasons Michael Ellerman
2014-10-31 15:49   ` Paolo Bonzini
2014-06-17  7:54 ` [Qemu-devel] [PATCH 3/6] kvm_stat: Rework platform detection Michael Ellerman
2014-06-17  7:54 ` [Qemu-devel] [PATCH 4/6] kvm_stat: Fix tracepoint filter definition for s390 Michael Ellerman
2014-06-17  7:54 ` [Qemu-devel] [PATCH 5/6] kvm_stat: Abstract ioctl numbers Michael Ellerman
2014-06-17  7:54 ` [Qemu-devel] [PATCH 6/6] kvm_stat: Add powerpc support Michael Ellerman
2014-06-17  8:27   ` Alexander Graf
2014-06-18  0:50     ` Michael Ellerman
2014-06-18  0:59       ` Alexander Graf
2014-06-18  1:37         ` Michael Ellerman
2014-06-18  1:54           ` Alexander Graf
2014-10-31 15:36   ` Paolo Bonzini
2014-11-03  0:40     ` Michael Ellerman

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