* [PATCH v2] KVM: arm/arm64: Count guest exit due to various reasons
@ 2015-11-26 10:09 Amit Singh Tomar
2015-12-02 18:12 ` Christoffer Dall
0 siblings, 1 reply; 3+ messages in thread
From: Amit Singh Tomar @ 2015-11-26 10:09 UTC (permalink / raw)
To: kvmarm; +Cc: marc.zyngier, andre.przywara
From: Amit Tomar <amittomer25@gmail.com>
It would add guest exit statistics to debugfs, This can be helpful
while measuring KVM performance.
Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
---
Changes since v1:
* Defined equal number of stats for ARM and ARM64
* Differentiated MMIO_EXIT handled between Userspace and Kernel
* Distinguished between wfi and wfe stat counters
---
arch/arm/include/asm/kvm_host.h | 6 ++++++
arch/arm/kvm/arm.c | 1 +
arch/arm/kvm/guest.c | 6 ++++++
arch/arm/kvm/handle_exit.c | 3 +++
arch/arm/kvm/mmio.c | 3 +++
arch/arm64/include/asm/kvm_host.h | 6 ++++++
arch/arm64/kvm/guest.c | 9 +++++++++
arch/arm64/kvm/handle_exit.c | 3 +++
8 files changed, 37 insertions(+)
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 6692982..872640e 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -150,6 +150,12 @@ struct kvm_vcpu_stat {
u32 halt_successful_poll;
u32 halt_attempted_poll;
u32 halt_wakeup;
+ u32 hvc_exit_stat;
+ u64 wfe_exit_stat;
+ u64 wfi_exit_stat;
+ u64 mmio_exit_handled_in_userspace_stat;
+ u64 mmio_exit_handled_in_kernel_stat;
+ u64 exits;
};
int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index e06fd29..8a79a57 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -603,6 +603,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
ret = kvm_call_hyp(__kvm_vcpu_run, vcpu);
vcpu->mode = OUTSIDE_GUEST_MODE;
+ vcpu->stat.exits++;
/*
* Back from guest
*************************************************************/
diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
index 96e935b..8323241 100644
--- a/arch/arm/kvm/guest.c
+++ b/arch/arm/kvm/guest.c
@@ -33,6 +33,12 @@
#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
struct kvm_stats_debugfs_item debugfs_entries[] = {
+ VCPU_STAT(hvc_exit_stat),
+ VCPU_STAT(wfe_exit_stat),
+ VCPU_STAT(wfi_exit_stat),
+ VCPU_STAT(mmio_exit_handled_in_userspace_stat),
+ VCPU_STAT(mmio_exit_handled_in_kernel_stat),
+ VCPU_STAT(exits),
{ NULL }
};
diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c
index 95f12b2..3ede90d 100644
--- a/arch/arm/kvm/handle_exit.c
+++ b/arch/arm/kvm/handle_exit.c
@@ -42,6 +42,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
trace_kvm_hvc(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
kvm_vcpu_hvc_get_imm(vcpu));
+ vcpu->stat.hvc_exit_stat++;
ret = kvm_psci_call(vcpu);
if (ret < 0) {
@@ -89,9 +90,11 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)
{
if (kvm_vcpu_get_hsr(vcpu) & HSR_WFI_IS_WFE) {
trace_kvm_wfx(*vcpu_pc(vcpu), true);
+ vcpu->stat.wfe_exit_stat++;
kvm_vcpu_on_spin(vcpu);
} else {
trace_kvm_wfx(*vcpu_pc(vcpu), false);
+ vcpu->stat.wfi_exit_stat++;
kvm_vcpu_block(vcpu);
}
diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
index 974b1c6..b66c3a3 100644
--- a/arch/arm/kvm/mmio.c
+++ b/arch/arm/kvm/mmio.c
@@ -209,8 +209,11 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
if (!ret) {
/* We handled the access successfully in the kernel. */
+ vcpu->stat.mmio_exit_handled_in_kernel_stat++;
kvm_handle_mmio_return(vcpu, run);
return 1;
+ } else {
+ vcpu->stat.mmio_exit_handled_in_userspace_stat++;
}
run->exit_reason = KVM_EXIT_MMIO;
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index a35ce72..ad29508 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -197,6 +197,12 @@ struct kvm_vcpu_stat {
u32 halt_successful_poll;
u32 halt_attempted_poll;
u32 halt_wakeup;
+ u32 hvc_exit_stat;
+ u64 wfe_exit_stat;
+ u64 wfi_exit_stat;
+ u64 mmio_exit_handled_in_userspace_stat;
+ u64 mmio_exit_handled_in_kernel_stat;
+ u64 exits;
};
int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index d250160..ad9ea95 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -34,7 +34,16 @@
#include "trace.h"
+#define VM_STAT(x) { #x, offsetof(struct kvm, stat.x), KVM_STAT_VM }
+#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
+
struct kvm_stats_debugfs_item debugfs_entries[] = {
+ VCPU_STAT(hvc_exit_stat),
+ VCPU_STAT(wfe_exit_stat),
+ VCPU_STAT(wfi_exit_stat),
+ VCPU_STAT(mmio_exit_handled_in_userspace_stat),
+ VCPU_STAT(mmio_exit_handled_in_kernel_stat),
+ VCPU_STAT(exits),
{ NULL }
};
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index 68a0759..2894649 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -39,6 +39,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
trace_kvm_hvc_arm64(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
kvm_vcpu_hvc_get_imm(vcpu));
+ vcpu->stat.hvc_exit_stat++;
ret = kvm_psci_call(vcpu);
if (ret < 0) {
@@ -71,9 +72,11 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)
{
if (kvm_vcpu_get_hsr(vcpu) & ESR_ELx_WFx_ISS_WFE) {
trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true);
+ vcpu->stat.wfe_exit_stat++;
kvm_vcpu_on_spin(vcpu);
} else {
trace_kvm_wfx_arm64(*vcpu_pc(vcpu), false);
+ vcpu->stat.wfi_exit_stat++;
kvm_vcpu_block(vcpu);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: arm/arm64: Count guest exit due to various reasons
2015-11-26 10:09 [PATCH v2] KVM: arm/arm64: Count guest exit due to various reasons Amit Singh Tomar
@ 2015-12-02 18:12 ` Christoffer Dall
2015-12-02 19:36 ` Amit Tomer
0 siblings, 1 reply; 3+ messages in thread
From: Christoffer Dall @ 2015-12-02 18:12 UTC (permalink / raw)
To: Amit Singh Tomar; +Cc: marc.zyngier, andre.przywara, kvmarm
On Thu, Nov 26, 2015 at 10:09:43AM +0000, Amit Singh Tomar wrote:
> From: Amit Tomar <amittomer25@gmail.com>
>
> It would add guest exit statistics to debugfs, This can be helpful
> while measuring KVM performance.
>
> Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
> ---
> Changes since v1:
> * Defined equal number of stats for ARM and ARM64
> * Differentiated MMIO_EXIT handled between Userspace and Kernel
> * Distinguished between wfi and wfe stat counters
> ---
> arch/arm/include/asm/kvm_host.h | 6 ++++++
> arch/arm/kvm/arm.c | 1 +
> arch/arm/kvm/guest.c | 6 ++++++
> arch/arm/kvm/handle_exit.c | 3 +++
> arch/arm/kvm/mmio.c | 3 +++
> arch/arm64/include/asm/kvm_host.h | 6 ++++++
> arch/arm64/kvm/guest.c | 9 +++++++++
> arch/arm64/kvm/handle_exit.c | 3 +++
> 8 files changed, 37 insertions(+)
>
> diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
> index 6692982..872640e 100644
> --- a/arch/arm/include/asm/kvm_host.h
> +++ b/arch/arm/include/asm/kvm_host.h
> @@ -150,6 +150,12 @@ struct kvm_vcpu_stat {
> u32 halt_successful_poll;
> u32 halt_attempted_poll;
> u32 halt_wakeup;
> + u32 hvc_exit_stat;
> + u64 wfe_exit_stat;
> + u64 wfi_exit_stat;
> + u64 mmio_exit_handled_in_userspace_stat;
> + u64 mmio_exit_handled_in_kernel_stat;
eh, I think these should just be called mmio_exit_user and
mmio_exit_kernel
> + u64 exits;
> };
>
> int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
> index e06fd29..8a79a57 100644
> --- a/arch/arm/kvm/arm.c
> +++ b/arch/arm/kvm/arm.c
> @@ -603,6 +603,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
> ret = kvm_call_hyp(__kvm_vcpu_run, vcpu);
>
> vcpu->mode = OUTSIDE_GUEST_MODE;
> + vcpu->stat.exits++;
> /*
> * Back from guest
> *************************************************************/
> diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
> index 96e935b..8323241 100644
> --- a/arch/arm/kvm/guest.c
> +++ b/arch/arm/kvm/guest.c
> @@ -33,6 +33,12 @@
> #define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
>
> struct kvm_stats_debugfs_item debugfs_entries[] = {
> + VCPU_STAT(hvc_exit_stat),
> + VCPU_STAT(wfe_exit_stat),
> + VCPU_STAT(wfi_exit_stat),
> + VCPU_STAT(mmio_exit_handled_in_userspace_stat),
> + VCPU_STAT(mmio_exit_handled_in_kernel_stat),
> + VCPU_STAT(exits),
> { NULL }
> };
>
> diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c
> index 95f12b2..3ede90d 100644
> --- a/arch/arm/kvm/handle_exit.c
> +++ b/arch/arm/kvm/handle_exit.c
> @@ -42,6 +42,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
>
> trace_kvm_hvc(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
> kvm_vcpu_hvc_get_imm(vcpu));
> + vcpu->stat.hvc_exit_stat++;
>
> ret = kvm_psci_call(vcpu);
> if (ret < 0) {
> @@ -89,9 +90,11 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)
> {
> if (kvm_vcpu_get_hsr(vcpu) & HSR_WFI_IS_WFE) {
> trace_kvm_wfx(*vcpu_pc(vcpu), true);
> + vcpu->stat.wfe_exit_stat++;
> kvm_vcpu_on_spin(vcpu);
> } else {
> trace_kvm_wfx(*vcpu_pc(vcpu), false);
> + vcpu->stat.wfi_exit_stat++;
> kvm_vcpu_block(vcpu);
> }
>
> diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
> index 974b1c6..b66c3a3 100644
> --- a/arch/arm/kvm/mmio.c
> +++ b/arch/arm/kvm/mmio.c
> @@ -209,8 +209,11 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
>
> if (!ret) {
> /* We handled the access successfully in the kernel. */
> + vcpu->stat.mmio_exit_handled_in_kernel_stat++;
> kvm_handle_mmio_return(vcpu, run);
> return 1;
> + } else {
> + vcpu->stat.mmio_exit_handled_in_userspace_stat++;
> }
>
> run->exit_reason = KVM_EXIT_MMIO;
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index a35ce72..ad29508 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -197,6 +197,12 @@ struct kvm_vcpu_stat {
> u32 halt_successful_poll;
> u32 halt_attempted_poll;
> u32 halt_wakeup;
> + u32 hvc_exit_stat;
> + u64 wfe_exit_stat;
> + u64 wfi_exit_stat;
> + u64 mmio_exit_handled_in_userspace_stat;
> + u64 mmio_exit_handled_in_kernel_stat;
same problem with naming
> + u64 exits;
> };
>
> int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
> diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
> index d250160..ad9ea95 100644
> --- a/arch/arm64/kvm/guest.c
> +++ b/arch/arm64/kvm/guest.c
> @@ -34,7 +34,16 @@
>
> #include "trace.h"
>
> +#define VM_STAT(x) { #x, offsetof(struct kvm, stat.x), KVM_STAT_VM }
> +#define VCPU_STAT(x) { #x, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU }
> +
> struct kvm_stats_debugfs_item debugfs_entries[] = {
> + VCPU_STAT(hvc_exit_stat),
> + VCPU_STAT(wfe_exit_stat),
> + VCPU_STAT(wfi_exit_stat),
> + VCPU_STAT(mmio_exit_handled_in_userspace_stat),
> + VCPU_STAT(mmio_exit_handled_in_kernel_stat),
> + VCPU_STAT(exits),
> { NULL }
> };
>
> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
> index 68a0759..2894649 100644
> --- a/arch/arm64/kvm/handle_exit.c
> +++ b/arch/arm64/kvm/handle_exit.c
> @@ -39,6 +39,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
>
> trace_kvm_hvc_arm64(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
> kvm_vcpu_hvc_get_imm(vcpu));
> + vcpu->stat.hvc_exit_stat++;
>
> ret = kvm_psci_call(vcpu);
> if (ret < 0) {
> @@ -71,9 +72,11 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)
> {
> if (kvm_vcpu_get_hsr(vcpu) & ESR_ELx_WFx_ISS_WFE) {
> trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true);
> + vcpu->stat.wfe_exit_stat++;
> kvm_vcpu_on_spin(vcpu);
> } else {
> trace_kvm_wfx_arm64(*vcpu_pc(vcpu), false);
> + vcpu->stat.wfi_exit_stat++;
> kvm_vcpu_block(vcpu);
> }
>
> --
> 2.1.4
>
I've applied this patch to queue with the naming changed.
Thanks,
-Christoffer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: arm/arm64: Count guest exit due to various reasons
2015-12-02 18:12 ` Christoffer Dall
@ 2015-12-02 19:36 ` Amit Tomer
0 siblings, 0 replies; 3+ messages in thread
From: Amit Tomer @ 2015-12-02 19:36 UTC (permalink / raw)
To: Christoffer Dall; +Cc: Marc Zyngier, Andre Przywara, kvmarm
> I've applied this patch to queue with the naming changed.
>
Ok, Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-12-02 19:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 10:09 [PATCH v2] KVM: arm/arm64: Count guest exit due to various reasons Amit Singh Tomar
2015-12-02 18:12 ` Christoffer Dall
2015-12-02 19:36 ` Amit Tomer
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.