All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH][RESEND] qemu/kvm_stat: Fix I/O error from kvm_stat
@ 2015-08-31  3:42 Hemant Kumar
  2015-08-31 20:22 ` Wei Huang
  0 siblings, 1 reply; 3+ messages in thread
From: Hemant Kumar @ 2015-08-31  3:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: wei, Hemant Kumar, qemu-ppc, agraf

Running kvm_stat on a powerpc macine where the kernel is compiled with
KVM_BOOK3S_HV_EXIT_TIMING config option, generates the following error :

 # kvm_stat

Traceback (most recent call last):
  File "/usr/bin/kvm_stat", line 644, in <module>
    curses.wrapper(tui, stats)
  File "/usr/lib64/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/bin/kvm_stat", line 550, in tui
    refresh(sleeptime)
  File "/usr/bin/kvm_stat", line 526, in refresh
    s = stats.get()
  File "/usr/bin/kvm_stat", line 486, in get
    new = d.read()
  File "/usr/bin/kvm_stat", line 29, in read
    return dict([(key, val(key)) for key in self._fields])
  File "/usr/bin/kvm_stat", line 28, in val
    return int(file(self.base + '/' + key).read())
IOError: [Errno 21] Is a directory: '/sys/kernel/debug/kvm/vm12840'

The error says that its trying to read the contents of a directory as if
it were a file. The kernel here creates directories inside
"/sys/kernel/debug/kvm/" for the individual VMs running on the
machine. These directories contain timing information (for rm_entry,
rm_intr, rm_exit, guest, cede) related to each vcpu of each VM. All of
this is enabled with KVM_BOOK3S_HV_EXIT_TIMING config option for the
kernel.

kvm_stat script isn't supposed to parse/read these directories and isn't
even expecting any directories inside "/sys/kernel/debug/kvm/". This
patch fixes the problem by avoiding lookup for these directories.

Reported-by: Krishnaja Balachandran <kribalac@in.ibm.com>
Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com>
---
 scripts/kvm/kvm_stat | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 7e5d256..1da7a53 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -18,7 +18,11 @@ from ctypes import *
 class DebugfsProvider(object):
     def __init__(self):
         self.base = '/sys/kernel/debug/kvm'
-        self._fields = os.listdir(self.base)
+        files = os.listdir(self.base)
+        self._fields = []
+        for f in files:
+            if os.path.isfile(self.base + '/' + f):
+                self._fields.append(f)
     def fields(self):
         return self._fields
     def select(self, fields):
-- 
1.9.3

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

* Re: [Qemu-devel] [PATCH][RESEND] qemu/kvm_stat: Fix I/O error from kvm_stat
  2015-08-31  3:42 [Qemu-devel] [PATCH][RESEND] qemu/kvm_stat: Fix I/O error from kvm_stat Hemant Kumar
@ 2015-08-31 20:22 ` Wei Huang
  2015-09-01  6:50   ` Hemant Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Huang @ 2015-08-31 20:22 UTC (permalink / raw)
  To: Hemant Kumar, qemu-devel; +Cc: qemu-ppc, agraf

On 08/30/2015 10:42 PM, Hemant Kumar wrote:
> Running kvm_stat on a powerpc macine where the kernel is compiled with
> KVM_BOOK3S_HV_EXIT_TIMING config option, generates the following error :
> 
>  # kvm_stat
> 
> Traceback (most recent call last):
>   File "/usr/bin/kvm_stat", line 644, in <module>
>     curses.wrapper(tui, stats)
>   File "/usr/lib64/python2.7/curses/wrapper.py", line 43, in wrapper
>     return func(stdscr, *args, **kwds)
>   File "/usr/bin/kvm_stat", line 550, in tui
>     refresh(sleeptime)
>   File "/usr/bin/kvm_stat", line 526, in refresh
>     s = stats.get()
>   File "/usr/bin/kvm_stat", line 486, in get
>     new = d.read()
>   File "/usr/bin/kvm_stat", line 29, in read
>     return dict([(key, val(key)) for key in self._fields])
>   File "/usr/bin/kvm_stat", line 28, in val
>     return int(file(self.base + '/' + key).read())
> IOError: [Errno 21] Is a directory: '/sys/kernel/debug/kvm/vm12840'
> 
> The error says that its trying to read the contents of a directory as if
> it were a file. The kernel here creates directories inside
> "/sys/kernel/debug/kvm/" for the individual VMs running on the
> machine. These directories contain timing information (for rm_entry,
> rm_intr, rm_exit, guest, cede) related to each vcpu of each VM. All of
> this is enabled with KVM_BOOK3S_HV_EXIT_TIMING config option for the
> kernel.

A suggestion: would it be useful to display these statistics in
perf_stat? I understand that these counters are per-vm-based; but they
might provide useful insights to end-users.

> 
> kvm_stat script isn't supposed to parse/read these directories and isn't
> even expecting any directories inside "/sys/kernel/debug/kvm/". This
> patch fixes the problem by avoiding lookup for these directories.
> 
> Reported-by: Krishnaja Balachandran <kribalac@in.ibm.com>
> Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com>
> ---
>  scripts/kvm/kvm_stat | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
> index 7e5d256..1da7a53 100755
> --- a/scripts/kvm/kvm_stat
> +++ b/scripts/kvm/kvm_stat
> @@ -18,7 +18,11 @@ from ctypes import *
>  class DebugfsProvider(object):
>      def __init__(self):
>          self.base = '/sys/kernel/debug/kvm'
> -        self._fields = os.listdir(self.base)
> +        files = os.listdir(self.base)
> +        self._fields = []
> +        for f in files:
> +            if os.path.isfile(self.base + '/' + f):
> +                self._fields.append(f)
>      def fields(self):
>          return self._fields
>      def select(self, fields):
> 

I tested this patch on x86 box and didn't see any problem. So:

Reviewed-by: Wei Huang <wei@redhat.com>

-Wei

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

* Re: [Qemu-devel] [PATCH][RESEND] qemu/kvm_stat: Fix I/O error from kvm_stat
  2015-08-31 20:22 ` Wei Huang
@ 2015-09-01  6:50   ` Hemant Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Hemant Kumar @ 2015-09-01  6:50 UTC (permalink / raw)
  To: Wei Huang, qemu-devel; +Cc: qemu-ppc, agraf

Hi Wei,

Thanks for the review.

On 09/01/2015 01:52 AM, Wei Huang wrote:
> On 08/30/2015 10:42 PM, Hemant Kumar wrote:
>> Running kvm_stat on a powerpc macine where the kernel is compiled with
>> KVM_BOOK3S_HV_EXIT_TIMING config option, generates the following error :
>>
>>   # kvm_stat
>>
>> Traceback (most recent call last):
>>    File "/usr/bin/kvm_stat", line 644, in <module>
>>      curses.wrapper(tui, stats)
>>    File "/usr/lib64/python2.7/curses/wrapper.py", line 43, in wrapper
>>      return func(stdscr, *args, **kwds)
>>    File "/usr/bin/kvm_stat", line 550, in tui
>>      refresh(sleeptime)
>>    File "/usr/bin/kvm_stat", line 526, in refresh
>>      s = stats.get()
>>    File "/usr/bin/kvm_stat", line 486, in get
>>      new = d.read()
>>    File "/usr/bin/kvm_stat", line 29, in read
>>      return dict([(key, val(key)) for key in self._fields])
>>    File "/usr/bin/kvm_stat", line 28, in val
>>      return int(file(self.base + '/' + key).read())
>> IOError: [Errno 21] Is a directory: '/sys/kernel/debug/kvm/vm12840'
>>
>> The error says that its trying to read the contents of a directory as if
>> it were a file. The kernel here creates directories inside
>> "/sys/kernel/debug/kvm/" for the individual VMs running on the
>> machine. These directories contain timing information (for rm_entry,
>> rm_intr, rm_exit, guest, cede) related to each vcpu of each VM. All of
>> this is enabled with KVM_BOOK3S_HV_EXIT_TIMING config option for the
>> kernel.
> A suggestion: would it be useful to display these statistics in
> perf_stat? I understand that these counters are per-vm-based; but they
> might provide useful insights to end-users.

It would be definitely useful to display these statistics, but since this
script doesn't work on powerpc with the config option enabled, this
patch should work as a fix for now.

We can work on enhancing kvm_stat to display these per vm statistics.

>> kvm_stat script isn't supposed to parse/read these directories and isn't
>> even expecting any directories inside "/sys/kernel/debug/kvm/". This
>> patch fixes the problem by avoiding lookup for these directories.
>>
>> Reported-by: Krishnaja Balachandran <kribalac@in.ibm.com>
>> Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com>
>> ---
>>   scripts/kvm/kvm_stat | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
>> index 7e5d256..1da7a53 100755
>> --- a/scripts/kvm/kvm_stat
>> +++ b/scripts/kvm/kvm_stat
>> @@ -18,7 +18,11 @@ from ctypes import *
>>   class DebugfsProvider(object):
>>       def __init__(self):
>>           self.base = '/sys/kernel/debug/kvm'
>> -        self._fields = os.listdir(self.base)
>> +        files = os.listdir(self.base)
>> +        self._fields = []
>> +        for f in files:
>> +            if os.path.isfile(self.base + '/' + f):
>> +                self._fields.append(f)
>>       def fields(self):
>>           return self._fields
>>       def select(self, fields):
>>
> I tested this patch on x86 box and didn't see any problem. So:
>
> Reviewed-by: Wei Huang <wei@redhat.com>

Thanks!

-- 
Hemant Kumar

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

end of thread, other threads:[~2015-09-01  6:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-31  3:42 [Qemu-devel] [PATCH][RESEND] qemu/kvm_stat: Fix I/O error from kvm_stat Hemant Kumar
2015-08-31 20:22 ` Wei Huang
2015-09-01  6:50   ` Hemant Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.