KVM: add halt_attempted_poll to VCPU stats
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 15 Sep 2015 16:27:57 +0000 (18:27 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 16 Sep 2015 10:17:00 +0000 (12:17 +0200)
This new statistic can help diagnosing VCPUs that, for any reason,
trigger bad behavior of halt_poll_ns autotuning.

For example, say halt_poll_ns = 480000, and wakeups are spaced exactly
like 479us, 481us, 479us, 481us. Then KVM always fails polling and wastes
10+20+40+80+160+320+480 = 1110 microseconds out of every
479+481+479+481+479+481+479 = 3359 microseconds. The VCPU then
is consuming about 30% more CPU than it would use without
polling.  This would show as an abnormally high number of
attempted polling compared to the successful polls.

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com<
Reviewed-by: David Matlack <dmatlack@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12 files changed:
arch/arm/include/asm/kvm_host.h
arch/arm64/include/asm/kvm_host.h
arch/mips/include/asm/kvm_host.h
arch/mips/kvm/mips.c
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kvm/book3s.c
arch/powerpc/kvm/booke.c
arch/s390/include/asm/kvm_host.h
arch/s390/kvm/kvm-s390.c
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/x86.c
virt/kvm/kvm_main.c

index dcba0fa5176e990f8a23333f08e34e192351b407..687ddeba36117ac26ec2e8d5368daaed8b0158e2 100644 (file)
@@ -148,6 +148,7 @@ struct kvm_vm_stat {
 
 struct kvm_vcpu_stat {
        u32 halt_successful_poll;
+       u32 halt_attempted_poll;
        u32 halt_wakeup;
 };
 
index 415938dc45cff94600625963b71011882f3a3ae4..486594583cc62c7b739f87cb7feba915e2ca53f0 100644 (file)
@@ -195,6 +195,7 @@ struct kvm_vm_stat {
 
 struct kvm_vcpu_stat {
        u32 halt_successful_poll;
+       u32 halt_attempted_poll;
        u32 halt_wakeup;
 };
 
index e8c8d9d0c45fe7c3600ba39a44e7090ba0827a04..3a54dbca9f7e0b9d0ab11d0a65aad59ddb9bc29b 100644 (file)
@@ -128,6 +128,7 @@ struct kvm_vcpu_stat {
        u32 msa_disabled_exits;
        u32 flush_dcache_exits;
        u32 halt_successful_poll;
+       u32 halt_attempted_poll;
        u32 halt_wakeup;
 };
 
index cd4c129ce7434d60fc6af74bb6b764b536de4dda..49ff3bfc007e534529d0f61d21b6fddd6578d145 100644 (file)
@@ -55,6 +55,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "msa_disabled", VCPU_STAT(msa_disabled_exits), KVM_STAT_VCPU },
        { "flush_dcache", VCPU_STAT(flush_dcache_exits), KVM_STAT_VCPU },
        { "halt_successful_poll", VCPU_STAT(halt_successful_poll), KVM_STAT_VCPU },
+       { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll), KVM_STAT_VCPU },
        { "halt_wakeup",  VCPU_STAT(halt_wakeup),        KVM_STAT_VCPU },
        {NULL}
 };
index 98eebbf663405c59ebcc3174d8619773f9813ac1..195886a583bab5c3d4dbc88782785cff95d309a9 100644 (file)
@@ -108,6 +108,7 @@ struct kvm_vcpu_stat {
        u32 dec_exits;
        u32 ext_intr_exits;
        u32 halt_successful_poll;
+       u32 halt_attempted_poll;
        u32 halt_wakeup;
        u32 dbell_exits;
        u32 gdbell_exits;
index d75bf325f54a17ebf4e19dda7a85eed271e4f3ed..cf009167d208db3ebf3d74a2e1f29b3bfb091d26 100644 (file)
@@ -53,6 +53,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "ext_intr",    VCPU_STAT(ext_intr_exits) },
        { "queue_intr",  VCPU_STAT(queue_intr) },
        { "halt_successful_poll", VCPU_STAT(halt_successful_poll), },
+       { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll), },
        { "halt_wakeup", VCPU_STAT(halt_wakeup) },
        { "pf_storage",  VCPU_STAT(pf_storage) },
        { "sp_storage",  VCPU_STAT(sp_storage) },
index ae458f0fd061efea7cdd569c1bdb32970503659c..fd5875179e5c0e6738a1e7867a75f05cbe1fa0c8 100644 (file)
@@ -63,6 +63,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "dec",        VCPU_STAT(dec_exits) },
        { "ext_intr",   VCPU_STAT(ext_intr_exits) },
        { "halt_successful_poll", VCPU_STAT(halt_successful_poll) },
+       { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) },
        { "halt_wakeup", VCPU_STAT(halt_wakeup) },
        { "doorbell", VCPU_STAT(dbell_exits) },
        { "guest doorbell", VCPU_STAT(gdbell_exits) },
index 3d012e071647970ce14ee2eb566649ada4b000e6..6ce4a0b7e8dafb7bed2fec0a824e0aeb886e6066 100644 (file)
@@ -210,6 +210,7 @@ struct kvm_vcpu_stat {
        u32 exit_validity;
        u32 exit_instruction;
        u32 halt_successful_poll;
+       u32 halt_attempted_poll;
        u32 halt_wakeup;
        u32 instruction_lctl;
        u32 instruction_lctlg;
index c91eb941b444ee7cad8c5a9ea2523495e71e8f2d..2f807ab1725ed64164380eee7016315a1499ae49 100644 (file)
@@ -63,6 +63,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "exit_program_interruption", VCPU_STAT(exit_program_interruption) },
        { "exit_instr_and_program_int", VCPU_STAT(exit_instr_and_program) },
        { "halt_successful_poll", VCPU_STAT(halt_successful_poll) },
+       { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) },
        { "halt_wakeup", VCPU_STAT(halt_wakeup) },
        { "instruction_lctlg", VCPU_STAT(instruction_lctlg) },
        { "instruction_lctl", VCPU_STAT(instruction_lctl) },
index c12e845f59e6b40c5afb62d8ecf1e08f22dce4db..349f80a82b8207411f3e377f8fa924bb19d060f0 100644 (file)
@@ -711,6 +711,7 @@ struct kvm_vcpu_stat {
        u32 nmi_window_exits;
        u32 halt_exits;
        u32 halt_successful_poll;
+       u32 halt_attempted_poll;
        u32 halt_wakeup;
        u32 request_irq_exits;
        u32 irq_exits;
index a60bdbccff5189b5a98b9a7fcc6a3b9f7ff5eeec..6bbb0dfb99d0a5e222131c9b2f8e0fb38e990cb3 100644 (file)
@@ -149,6 +149,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "nmi_window", VCPU_STAT(nmi_window_exits) },
        { "halt_exits", VCPU_STAT(halt_exits) },
        { "halt_successful_poll", VCPU_STAT(halt_successful_poll) },
+       { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) },
        { "halt_wakeup", VCPU_STAT(halt_wakeup) },
        { "hypercalls", VCPU_STAT(hypercalls) },
        { "request_irq", VCPU_STAT(request_irq_exits) },
index 9af68db73c6aabc7314adb7e4633a1fb1c968d7c..04146a2e1d8191e3e152954824594555884f5f6d 100644 (file)
@@ -2004,6 +2004,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
        if (vcpu->halt_poll_ns) {
                ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns);
 
+               ++vcpu->stat.halt_attempted_poll;
                do {
                        /*
                         * This sets KVM_REQ_UNHALT if an interrupt