diff mbox

[V2,4/5] kvm/stats: Add provisioning for 64-bit vcpu statistics

Message ID 1468220912-22828-4-git-send-email-sjitindarsingh@gmail.com
State Superseded
Headers show

Commit Message

Suraj Jitindar Singh July 11, 2016, 7:08 a.m. UTC
vcpus have statistics associated with them which can be viewed within the
debugfs. Currently it is assumed within the vcpu_stat_get() and
vcpu_stat_get_per_vm() functions that all of these statistics are
represented as 32-bit numbers. The next patch adds some 64-bit statistics,
so add provisioning for the display of 64-bit vcpu statistics.

---
Change Log:

V1 -> V2:
	- Nothing

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
---
 arch/powerpc/kvm/book3s.c |  1 +
 include/linux/kvm_host.h  |  1 +
 virt/kvm/kvm_main.c       | 60 +++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 58 insertions(+), 4 deletions(-)

Comments

David Matlack July 11, 2016, 4:51 p.m. UTC | #1
On Mon, Jul 11, 2016 at 12:08 AM, Suraj Jitindar Singh
<sjitindarsingh@gmail.com> wrote:
> vcpus have statistics associated with them which can be viewed within the
> debugfs. Currently it is assumed within the vcpu_stat_get() and
> vcpu_stat_get_per_vm() functions that all of these statistics are
> represented as 32-bit numbers. The next patch adds some 64-bit statistics,
> so add provisioning for the display of 64-bit vcpu statistics.

Thanks, we need 64-bit stats in other places as well. Can we use this
opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
of this patch is duplicated code with "u32" swapped with "u64".

>
> ---
> Change Log:
>
> V1 -> V2:
>         - Nothing
>
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
> ---
>  arch/powerpc/kvm/book3s.c |  1 +
>  include/linux/kvm_host.h  |  1 +
>  virt/kvm/kvm_main.c       | 60 +++++++++++++++++++++++++++++++++++++++++++----
>  3 files changed, 58 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
> index 47018fc..ed9132b 100644
> --- a/arch/powerpc/kvm/book3s.c
> +++ b/arch/powerpc/kvm/book3s.c
> @@ -40,6 +40,7 @@
>  #include "trace.h"
>
>  #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
> +#define VCPU_STAT_U64(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU_U64
>
>  /* #define EXIT_DEBUG */
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 1c9c973..667b30e 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -991,6 +991,7 @@ static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa)
>  enum kvm_stat_kind {
>         KVM_STAT_VM,
>         KVM_STAT_VCPU,
> +       KVM_STAT_VCPU_U64,
>  };
>
>  struct kvm_stat_data {
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 48bd520..7ab5901 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -3566,6 +3566,20 @@ static int vcpu_stat_get_per_vm(void *data, u64 *val)
>         return 0;
>  }
>
> +static int vcpu_stat_u64_get_per_vm(void *data, u64 *val)
> +{
> +       int i;
> +       struct kvm_stat_data *stat_data = (struct kvm_stat_data *)data;
> +       struct kvm_vcpu *vcpu;
> +
> +       *val = 0;
> +
> +       kvm_for_each_vcpu(i, vcpu, stat_data->kvm)
> +               *val += *(u64 *)((void *)vcpu + stat_data->offset);
> +
> +       return 0;
> +}
> +
>  static int vcpu_stat_get_per_vm_open(struct inode *inode, struct file *file)
>  {
>         __simple_attr_check_format("%llu\n", 0ull);
> @@ -3573,6 +3587,13 @@ static int vcpu_stat_get_per_vm_open(struct inode *inode, struct file *file)
>                                  NULL, "%llu\n");
>  }
>
> +static int vcpu_stat_u64_get_per_vm_open(struct inode *inode, struct file *file)
> +{
> +       __simple_attr_check_format("%llu\n", 0ull);
> +       return kvm_debugfs_open(inode, file, vcpu_stat_u64_get_per_vm,
> +                                NULL, "%llu\n");
> +}
> +
>  static const struct file_operations vcpu_stat_get_per_vm_fops = {
>         .owner   = THIS_MODULE,
>         .open    = vcpu_stat_get_per_vm_open,
> @@ -3582,9 +3603,19 @@ static const struct file_operations vcpu_stat_get_per_vm_fops = {
>         .llseek  = generic_file_llseek,
>  };
>
> +static const struct file_operations vcpu_stat_u64_get_per_vm_fops = {
> +       .owner   = THIS_MODULE,
> +       .open    = vcpu_stat_u64_get_per_vm_open,
> +       .release = kvm_debugfs_release,
> +       .read    = simple_attr_read,
> +       .write   = simple_attr_write,
> +       .llseek  = generic_file_llseek,
> +};
> +
>  static const struct file_operations *stat_fops_per_vm[] = {
> -       [KVM_STAT_VCPU] = &vcpu_stat_get_per_vm_fops,
> -       [KVM_STAT_VM]   = &vm_stat_get_per_vm_fops,
> +       [KVM_STAT_VCPU]         = &vcpu_stat_get_per_vm_fops,
> +       [KVM_STAT_VCPU_U64]     = &vcpu_stat_u64_get_per_vm_fops,
> +       [KVM_STAT_VM]           = &vm_stat_get_per_vm_fops,
>  };
>
>  static int vm_stat_get(void *_offset, u64 *val)
> @@ -3627,9 +3658,30 @@ static int vcpu_stat_get(void *_offset, u64 *val)
>
>  DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");
>
> +static int vcpu_stat_u64_get(void *_offset, u64 *val)
> +{
> +       unsigned offset = (long)_offset;
> +       struct kvm *kvm;
> +       struct kvm_stat_data stat_tmp = {.offset = offset};
> +       u64 tmp_val;
> +
> +       *val = 0;
> +       spin_lock(&kvm_lock);
> +       list_for_each_entry(kvm, &vm_list, vm_list) {
> +               stat_tmp.kvm = kvm;
> +               vcpu_stat_u64_get_per_vm((void *)&stat_tmp, &tmp_val);
> +               *val += tmp_val;
> +       }
> +       spin_unlock(&kvm_lock);
> +       return 0;
> +}
> +
> +DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_u64_fops, vcpu_stat_u64_get, NULL, "%llu\n");
> +
>  static const struct file_operations *stat_fops[] = {
> -       [KVM_STAT_VCPU] = &vcpu_stat_fops,
> -       [KVM_STAT_VM]   = &vm_stat_fops,
> +       [KVM_STAT_VCPU]         = &vcpu_stat_fops,
> +       [KVM_STAT_VCPU_U64]     = &vcpu_stat_u64_fops,
> +       [KVM_STAT_VM]           = &vm_stat_fops,
>  };
>
>  static int kvm_init_debug(void)
> --
> 2.5.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini July 11, 2016, 5:05 p.m. UTC | #2
On 11/07/2016 18:51, David Matlack wrote:
>> > vcpus have statistics associated with them which can be viewed within the
>> > debugfs. Currently it is assumed within the vcpu_stat_get() and
>> > vcpu_stat_get_per_vm() functions that all of these statistics are
>> > represented as 32-bit numbers. The next patch adds some 64-bit statistics,
>> > so add provisioning for the display of 64-bit vcpu statistics.
> Thanks, we need 64-bit stats in other places as well. Can we use this
> opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
> of this patch is duplicated code with "u32" swapped with "u64".
> 

I'm not sure of what 32-bit architectures would do, but perhaps we could
upgrade them to unsigned long at least.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Matlack July 11, 2016, 5:30 p.m. UTC | #3
On Mon, Jul 11, 2016 at 10:05 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 11/07/2016 18:51, David Matlack wrote:
>>> > vcpus have statistics associated with them which can be viewed within the
>>> > debugfs. Currently it is assumed within the vcpu_stat_get() and
>>> > vcpu_stat_get_per_vm() functions that all of these statistics are
>>> > represented as 32-bit numbers. The next patch adds some 64-bit statistics,
>>> > so add provisioning for the display of 64-bit vcpu statistics.
>> Thanks, we need 64-bit stats in other places as well. Can we use this
>> opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
>> of this patch is duplicated code with "u32" swapped with "u64".
>>
>
> I'm not sure of what 32-bit architectures would do, but perhaps we could
> upgrade them to unsigned long at least.

I thought u64 still existed on 32-bit architectures. unsigned long
would be fine but with the caveat that certain stats would overflow on
32-bit architectures.

>
> Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini July 11, 2016, 7:31 p.m. UTC | #4
On 11/07/2016 19:30, David Matlack wrote:
> On Mon, Jul 11, 2016 at 10:05 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>>
>> On 11/07/2016 18:51, David Matlack wrote:
>>>>> vcpus have statistics associated with them which can be viewed within the
>>>>> debugfs. Currently it is assumed within the vcpu_stat_get() and
>>>>> vcpu_stat_get_per_vm() functions that all of these statistics are
>>>>> represented as 32-bit numbers. The next patch adds some 64-bit statistics,
>>>>> so add provisioning for the display of 64-bit vcpu statistics.
>>> Thanks, we need 64-bit stats in other places as well. Can we use this
>>> opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
>>> of this patch is duplicated code with "u32" swapped with "u64".
>>>
>>
>> I'm not sure of what 32-bit architectures would do, but perhaps we could
>> upgrade them to unsigned long at least.
> 
> I thought u64 still existed on 32-bit architectures. unsigned long
> would be fine but with the caveat that certain stats would overflow on
> 32-bit architectures.

Yes, but not all 32-bit architectures can do atomic read-modify-write
(e.g. add) operations on 64-bit values.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Matlack July 11, 2016, 7:45 p.m. UTC | #5
On Mon, Jul 11, 2016 at 12:31 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 11/07/2016 19:30, David Matlack wrote:
>> On Mon, Jul 11, 2016 at 10:05 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>
>>>
>>> On 11/07/2016 18:51, David Matlack wrote:
>>>>>> vcpus have statistics associated with them which can be viewed within the
>>>>>> debugfs. Currently it is assumed within the vcpu_stat_get() and
>>>>>> vcpu_stat_get_per_vm() functions that all of these statistics are
>>>>>> represented as 32-bit numbers. The next patch adds some 64-bit statistics,
>>>>>> so add provisioning for the display of 64-bit vcpu statistics.
>>>> Thanks, we need 64-bit stats in other places as well. Can we use this
>>>> opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
>>>> of this patch is duplicated code with "u32" swapped with "u64".
>>>>
>>>
>>> I'm not sure of what 32-bit architectures would do, but perhaps we could
>>> upgrade them to unsigned long at least.
>>
>> I thought u64 still existed on 32-bit architectures. unsigned long
>> would be fine but with the caveat that certain stats would overflow on
>> 32-bit architectures.
>
> Yes, but not all 32-bit architectures can do atomic read-modify-write
> (e.g. add) operations on 64-bit values.

I think that's ok, none of the stats currently use atomic operations.

>
> Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Suraj Jitindar Singh July 12, 2016, 6:24 a.m. UTC | #6
On 12/07/16 05:45, David Matlack wrote:
> On Mon, Jul 11, 2016 at 12:31 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On 11/07/2016 19:30, David Matlack wrote:
>>> On Mon, Jul 11, 2016 at 10:05 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>>
>>>> On 11/07/2016 18:51, David Matlack wrote:
>>>>>>> vcpus have statistics associated with them which can be viewed within the
>>>>>>> debugfs. Currently it is assumed within the vcpu_stat_get() and
>>>>>>> vcpu_stat_get_per_vm() functions that all of these statistics are
>>>>>>> represented as 32-bit numbers. The next patch adds some 64-bit statistics,
>>>>>>> so add provisioning for the display of 64-bit vcpu statistics.
>>>>> Thanks, we need 64-bit stats in other places as well. Can we use this
>>>>> opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
>>>>> of this patch is duplicated code with "u32" swapped with "u64".
>>>>>
>>>> I'm not sure of what 32-bit architectures would do, but perhaps we could
>>>> upgrade them to unsigned long at least.
>>> I thought u64 still existed on 32-bit architectures. unsigned long
>>> would be fine but with the caveat that certain stats would overflow on
>>> 32-bit architectures.
>> Yes, but not all 32-bit architectures can do atomic read-modify-write
>> (e.g. add) operations on 64-bit values.
> I think that's ok, none of the stats currently use atomic operations.

Yeah so this patch pretty much duplicates the 32-bit code.

So what you're saying is just replace all of the 32-bit statistics with
longs, that way we get 32-bit on 32-bit machines and 64-bit on 64-bit
machines? Then we just accept that on 32-bit machines we will get overflow
on some stats.

Or do you think u64s would be better and we accept that on 32-bit machines
we might get update conflicts from non-atomic concurrent accesses? Which
honestly I don't see being a huge issue in this use case.

>
>> Paolo

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christian Borntraeger July 13, 2016, 6 p.m. UTC | #7
On 07/11/2016 09:31 PM, Paolo Bonzini wrote:
> 
> 
> On 11/07/2016 19:30, David Matlack wrote:
>> On Mon, Jul 11, 2016 at 10:05 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>>
>>>
>>> On 11/07/2016 18:51, David Matlack wrote:
>>>>>> vcpus have statistics associated with them which can be viewed within the
>>>>>> debugfs. Currently it is assumed within the vcpu_stat_get() and
>>>>>> vcpu_stat_get_per_vm() functions that all of these statistics are
>>>>>> represented as 32-bit numbers. The next patch adds some 64-bit statistics,
>>>>>> so add provisioning for the display of 64-bit vcpu statistics.
>>>> Thanks, we need 64-bit stats in other places as well. Can we use this
>>>> opportunity to wholesale upgrade all KVM stats from u32 to u64? Most
>>>> of this patch is duplicated code with "u32" swapped with "u64".
>>>>
>>>
>>> I'm not sure of what 32-bit architectures would do, but perhaps we could
>>> upgrade them to unsigned long at least.
>>
>> I thought u64 still existed on 32-bit architectures. unsigned long
>> would be fine but with the caveat that certain stats would overflow on
>> 32-bit architectures.
> 
> Yes, but not all 32-bit architectures can do atomic read-modify-write
> (e.g. add) operations on 64-bit values.

So what about only doing it for the VCPU events? Those should be only
modified by one CPU. We would have some odd values on 32bit overflow, but
this will be certainly better than just start with 0


--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini July 14, 2016, 9:42 a.m. UTC | #8
On 13/07/2016 20:00, Christian Borntraeger wrote:
>>> >> I thought u64 still existed on 32-bit architectures. unsigned long
>>> >> would be fine but with the caveat that certain stats would overflow on
>>> >> 32-bit architectures.
>> > 
>> > Yes, but not all 32-bit architectures can do atomic read-modify-write
>> > (e.g. add) operations on 64-bit values.
> So what about only doing it for the VCPU events? Those should be only
> modified by one CPU. We would have some odd values on 32bit overflow, but
> this will be certainly better than just start with 0

If that's good enough for PPC, that's fine.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Suraj Jitindar Singh July 15, 2016, 7:52 a.m. UTC | #9
On 14/07/16 19:42, Paolo Bonzini wrote:
>
> On 13/07/2016 20:00, Christian Borntraeger wrote:
>>>>>> I thought u64 still existed on 32-bit architectures. unsigned long
>>>>>> would be fine but with the caveat that certain stats would overflow on
>>>>>> 32-bit architectures.
>>>> Yes, but not all 32-bit architectures can do atomic read-modify-write
>>>> (e.g. add) operations on 64-bit values.
>> So what about only doing it for the VCPU events? Those should be only
>> modified by one CPU. We would have some odd values on 32bit overflow, but
>> this will be certainly better than just start with 0
> If that's good enough for PPC, that's fine.
>
> Paolo

I'm don't feel great about having vcpu_stats as u64 and vm_stats still as u32
it's just a bit inconsistent.

That being said, it's only the vcpu_stats which I require to be u64 at this
stage so it's possible to just upgrade those.

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christian Borntraeger July 18, 2016, 7:17 a.m. UTC | #10
On 07/15/2016 09:52 AM, Suraj Jitindar Singh wrote:
> 
> 
> On 14/07/16 19:42, Paolo Bonzini wrote:
>>
>> On 13/07/2016 20:00, Christian Borntraeger wrote:
>>>>>>> I thought u64 still existed on 32-bit architectures. unsigned long
>>>>>>> would be fine but with the caveat that certain stats would overflow on
>>>>>>> 32-bit architectures.
>>>>> Yes, but not all 32-bit architectures can do atomic read-modify-write
>>>>> (e.g. add) operations on 64-bit values.
>>> So what about only doing it for the VCPU events? Those should be only
>>> modified by one CPU. We would have some odd values on 32bit overflow, but
>>> this will be certainly better than just start with 0
>> If that's good enough for PPC, that's fine.
>>
>> Paolo
> 
> I'm don't feel great about having vcpu_stats as u64 and vm_stats still as u32
> it's just a bit inconsistent.
> 
> That being said, it's only the vcpu_stats which I require to be u64 at this
> stage so it's possible to just upgrade those.

Yes, its not nice, but we probably want to avoid the overhead of atomics.
What about using u64 for vcpu_stats and unsigned long for vm_stats. This will be
correct for anyone and on 64bit systems we get 64 bits for everything?



--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini July 18, 2016, 8:24 a.m. UTC | #11
On 18/07/2016 09:17, Christian Borntraeger wrote:
> On 07/15/2016 09:52 AM, Suraj Jitindar Singh wrote:
>>
>>
>> On 14/07/16 19:42, Paolo Bonzini wrote:
>>>
>>> On 13/07/2016 20:00, Christian Borntraeger wrote:
>>>>>>>> I thought u64 still existed on 32-bit architectures. unsigned long
>>>>>>>> would be fine but with the caveat that certain stats would overflow on
>>>>>>>> 32-bit architectures.
>>>>>> Yes, but not all 32-bit architectures can do atomic read-modify-write
>>>>>> (e.g. add) operations on 64-bit values.
>>>> So what about only doing it for the VCPU events? Those should be only
>>>> modified by one CPU. We would have some odd values on 32bit overflow, but
>>>> this will be certainly better than just start with 0
>>> If that's good enough for PPC, that's fine.
>>>
>>> Paolo
>>
>> I'm don't feel great about having vcpu_stats as u64 and vm_stats still as u32
>> it's just a bit inconsistent.
>>
>> That being said, it's only the vcpu_stats which I require to be u64 at this
>> stage so it's possible to just upgrade those.
> 
> Yes, its not nice, but we probably want to avoid the overhead of atomics.
> What about using u64 for vcpu_stats and unsigned long for vm_stats. This will be
> correct for anyone and on 64bit systems we get 64 bits for everything?

That makes sense.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Suraj Jitindar Singh July 19, 2016, 1:31 a.m. UTC | #12
On 18/07/16 18:24, Paolo Bonzini wrote:
>
> On 18/07/2016 09:17, Christian Borntraeger wrote:
>> On 07/15/2016 09:52 AM, Suraj Jitindar Singh wrote:
>>>
>>> On 14/07/16 19:42, Paolo Bonzini wrote:
>>>> On 13/07/2016 20:00, Christian Borntraeger wrote:
>>>>>>>>> I thought u64 still existed on 32-bit architectures. unsigned long
>>>>>>>>> would be fine but with the caveat that certain stats would overflow on
>>>>>>>>> 32-bit architectures.
>>>>>>> Yes, but not all 32-bit architectures can do atomic read-modify-write
>>>>>>> (e.g. add) operations on 64-bit values.
>>>>> So what about only doing it for the VCPU events? Those should be only
>>>>> modified by one CPU. We would have some odd values on 32bit overflow, but
>>>>> this will be certainly better than just start with 0
>>>> If that's good enough for PPC, that's fine.
>>>>
>>>> Paolo
>>> I'm don't feel great about having vcpu_stats as u64 and vm_stats still as u32
>>> it's just a bit inconsistent.
>>>
>>> That being said, it's only the vcpu_stats which I require to be u64 at this
>>> stage so it's possible to just upgrade those.
>> Yes, its not nice, but we probably want to avoid the overhead of atomics.
>> What about using u64 for vcpu_stats and unsigned long for vm_stats. This will be
>> correct for anyone and on 64bit systems we get 64 bits for everything?
> That makes sense.
>
> Paolo

Sound good, I am happy with this.

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 47018fc..ed9132b 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -40,6 +40,7 @@ 
 #include "trace.h"
 
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
+#define VCPU_STAT_U64(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU_U64
 
 /* #define EXIT_DEBUG */
 
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 1c9c973..667b30e 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -991,6 +991,7 @@  static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa)
 enum kvm_stat_kind {
 	KVM_STAT_VM,
 	KVM_STAT_VCPU,
+	KVM_STAT_VCPU_U64,
 };
 
 struct kvm_stat_data {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 48bd520..7ab5901 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3566,6 +3566,20 @@  static int vcpu_stat_get_per_vm(void *data, u64 *val)
 	return 0;
 }
 
+static int vcpu_stat_u64_get_per_vm(void *data, u64 *val)
+{
+	int i;
+	struct kvm_stat_data *stat_data = (struct kvm_stat_data *)data;
+	struct kvm_vcpu *vcpu;
+
+	*val = 0;
+
+	kvm_for_each_vcpu(i, vcpu, stat_data->kvm)
+		*val += *(u64 *)((void *)vcpu + stat_data->offset);
+
+	return 0;
+}
+
 static int vcpu_stat_get_per_vm_open(struct inode *inode, struct file *file)
 {
 	__simple_attr_check_format("%llu\n", 0ull);
@@ -3573,6 +3587,13 @@  static int vcpu_stat_get_per_vm_open(struct inode *inode, struct file *file)
 				 NULL, "%llu\n");
 }
 
+static int vcpu_stat_u64_get_per_vm_open(struct inode *inode, struct file *file)
+{
+	__simple_attr_check_format("%llu\n", 0ull);
+	return kvm_debugfs_open(inode, file, vcpu_stat_u64_get_per_vm,
+				 NULL, "%llu\n");
+}
+
 static const struct file_operations vcpu_stat_get_per_vm_fops = {
 	.owner   = THIS_MODULE,
 	.open    = vcpu_stat_get_per_vm_open,
@@ -3582,9 +3603,19 @@  static const struct file_operations vcpu_stat_get_per_vm_fops = {
 	.llseek  = generic_file_llseek,
 };
 
+static const struct file_operations vcpu_stat_u64_get_per_vm_fops = {
+	.owner   = THIS_MODULE,
+	.open    = vcpu_stat_u64_get_per_vm_open,
+	.release = kvm_debugfs_release,
+	.read    = simple_attr_read,
+	.write   = simple_attr_write,
+	.llseek  = generic_file_llseek,
+};
+
 static const struct file_operations *stat_fops_per_vm[] = {
-	[KVM_STAT_VCPU] = &vcpu_stat_get_per_vm_fops,
-	[KVM_STAT_VM]   = &vm_stat_get_per_vm_fops,
+	[KVM_STAT_VCPU]		= &vcpu_stat_get_per_vm_fops,
+	[KVM_STAT_VCPU_U64]	= &vcpu_stat_u64_get_per_vm_fops,
+	[KVM_STAT_VM]		= &vm_stat_get_per_vm_fops,
 };
 
 static int vm_stat_get(void *_offset, u64 *val)
@@ -3627,9 +3658,30 @@  static int vcpu_stat_get(void *_offset, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");
 
+static int vcpu_stat_u64_get(void *_offset, u64 *val)
+{
+	unsigned offset = (long)_offset;
+	struct kvm *kvm;
+	struct kvm_stat_data stat_tmp = {.offset = offset};
+	u64 tmp_val;
+
+	*val = 0;
+	spin_lock(&kvm_lock);
+	list_for_each_entry(kvm, &vm_list, vm_list) {
+		stat_tmp.kvm = kvm;
+		vcpu_stat_u64_get_per_vm((void *)&stat_tmp, &tmp_val);
+		*val += tmp_val;
+	}
+	spin_unlock(&kvm_lock);
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_u64_fops, vcpu_stat_u64_get, NULL, "%llu\n");
+
 static const struct file_operations *stat_fops[] = {
-	[KVM_STAT_VCPU] = &vcpu_stat_fops,
-	[KVM_STAT_VM]   = &vm_stat_fops,
+	[KVM_STAT_VCPU]		= &vcpu_stat_fops,
+	[KVM_STAT_VCPU_U64]	= &vcpu_stat_u64_fops,
+	[KVM_STAT_VM]		= &vm_stat_fops,
 };
 
 static int kvm_init_debug(void)