Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: add halt_attempted_poll to VCPU stats

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
+1
arch/arm/include/asm/kvm_host.h
··· 148 148 149 149 struct kvm_vcpu_stat { 150 150 u32 halt_successful_poll; 151 + u32 halt_attempted_poll; 151 152 u32 halt_wakeup; 152 153 }; 153 154
+1
arch/arm64/include/asm/kvm_host.h
··· 195 195 196 196 struct kvm_vcpu_stat { 197 197 u32 halt_successful_poll; 198 + u32 halt_attempted_poll; 198 199 u32 halt_wakeup; 199 200 }; 200 201
+1
arch/mips/include/asm/kvm_host.h
··· 128 128 u32 msa_disabled_exits; 129 129 u32 flush_dcache_exits; 130 130 u32 halt_successful_poll; 131 + u32 halt_attempted_poll; 131 132 u32 halt_wakeup; 132 133 }; 133 134
+1
arch/mips/kvm/mips.c
··· 55 55 { "msa_disabled", VCPU_STAT(msa_disabled_exits), KVM_STAT_VCPU }, 56 56 { "flush_dcache", VCPU_STAT(flush_dcache_exits), KVM_STAT_VCPU }, 57 57 { "halt_successful_poll", VCPU_STAT(halt_successful_poll), KVM_STAT_VCPU }, 58 + { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll), KVM_STAT_VCPU }, 58 59 { "halt_wakeup", VCPU_STAT(halt_wakeup), KVM_STAT_VCPU }, 59 60 {NULL} 60 61 };
+1
arch/powerpc/include/asm/kvm_host.h
··· 108 108 u32 dec_exits; 109 109 u32 ext_intr_exits; 110 110 u32 halt_successful_poll; 111 + u32 halt_attempted_poll; 111 112 u32 halt_wakeup; 112 113 u32 dbell_exits; 113 114 u32 gdbell_exits;
+1
arch/powerpc/kvm/book3s.c
··· 53 53 { "ext_intr", VCPU_STAT(ext_intr_exits) }, 54 54 { "queue_intr", VCPU_STAT(queue_intr) }, 55 55 { "halt_successful_poll", VCPU_STAT(halt_successful_poll), }, 56 + { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll), }, 56 57 { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 57 58 { "pf_storage", VCPU_STAT(pf_storage) }, 58 59 { "sp_storage", VCPU_STAT(sp_storage) },
+1
arch/powerpc/kvm/booke.c
··· 63 63 { "dec", VCPU_STAT(dec_exits) }, 64 64 { "ext_intr", VCPU_STAT(ext_intr_exits) }, 65 65 { "halt_successful_poll", VCPU_STAT(halt_successful_poll) }, 66 + { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) }, 66 67 { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 67 68 { "doorbell", VCPU_STAT(dbell_exits) }, 68 69 { "guest doorbell", VCPU_STAT(gdbell_exits) },
+1
arch/s390/include/asm/kvm_host.h
··· 210 210 u32 exit_validity; 211 211 u32 exit_instruction; 212 212 u32 halt_successful_poll; 213 + u32 halt_attempted_poll; 213 214 u32 halt_wakeup; 214 215 u32 instruction_lctl; 215 216 u32 instruction_lctlg;
+1
arch/s390/kvm/kvm-s390.c
··· 63 63 { "exit_program_interruption", VCPU_STAT(exit_program_interruption) }, 64 64 { "exit_instr_and_program_int", VCPU_STAT(exit_instr_and_program) }, 65 65 { "halt_successful_poll", VCPU_STAT(halt_successful_poll) }, 66 + { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) }, 66 67 { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 67 68 { "instruction_lctlg", VCPU_STAT(instruction_lctlg) }, 68 69 { "instruction_lctl", VCPU_STAT(instruction_lctl) },
+1
arch/x86/include/asm/kvm_host.h
··· 711 711 u32 nmi_window_exits; 712 712 u32 halt_exits; 713 713 u32 halt_successful_poll; 714 + u32 halt_attempted_poll; 714 715 u32 halt_wakeup; 715 716 u32 request_irq_exits; 716 717 u32 irq_exits;
+1
arch/x86/kvm/x86.c
··· 149 149 { "nmi_window", VCPU_STAT(nmi_window_exits) }, 150 150 { "halt_exits", VCPU_STAT(halt_exits) }, 151 151 { "halt_successful_poll", VCPU_STAT(halt_successful_poll) }, 152 + { "halt_attempted_poll", VCPU_STAT(halt_attempted_poll) }, 152 153 { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 153 154 { "hypercalls", VCPU_STAT(hypercalls) }, 154 155 { "request_irq", VCPU_STAT(request_irq_exits) },
+1
virt/kvm/kvm_main.c
··· 2004 2004 if (vcpu->halt_poll_ns) { 2005 2005 ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); 2006 2006 2007 + ++vcpu->stat.halt_attempted_poll; 2007 2008 do { 2008 2009 /* 2009 2010 * This sets KVM_REQ_UNHALT if an interrupt