From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Yang, Sheng" Subject: Re: [patch 1/2] KVM: hlt emulation should take in-kernel APIC/PIT timers into account Date: Fri, 9 May 2008 15:49:20 +0800 Message-ID: <200805091549.20620.sheng.yang@intel.com> References: <20080410201254.316224847@localhost.localdomain> <20080411175326.GA3800@dmt> <4801D236.6000604@qumranet.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_AIAJIzt6dsTOKxQ" Cc: Marcelo Tosatti , Avi Kivity To: kvm-devel@lists.sourceforge.net Return-path: In-Reply-To: <4801D236.6000604@qumranet.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org --Boundary-00=_AIAJIzt6dsTOKxQ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sunday 13 April 2008 17:28:22 Avi Kivity wrote: > Marcelo Tosatti wrote: > > On Fri, Apr 11, 2008 at 03:12:41PM +0300, Avi Kivity wrote: > >> This breaks ia64 (and shouldn't s390 use this too?) > >> > >>> * We will block until either an interrupt or a signal wakes us up > >>> */ > >>> while (!kvm_cpu_has_interrupt(vcpu) > >>> + && !kvm_cpu_has_pending_timer(vcpu) > >> > >> I guess the fix is to stub this out for the other archs. > > > > Agreed. How's this. > > Better :); applied. Hi, Marcelo This patch got into trouble when OS don't use PIT/LAPIC timer and don't=20 disable them. Then the pending counters would keep increasing, but the HLT= =20 emulation can't be executed. And this would resulted in mass a lot (above=20 220,000 per second) halt_exit for the Windows XP that using RTC as the=20 clocksource (and keep PIT enabled after bios did, just mask the pin) idle,= =20 and the cpu utilize would be about 100% of QEmu process.=20 The following patch used another way to fix the issue, though not very form= al. =46rom 4d08ef3173084a6f0b7b76a0727e04ff42b614ba Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Fri, 9 May 2008 15:36:27 +0800 Subject: [PATCH] KVM: Fix CPU utilize hit 100% when emulate HLT in some OS Signed-off-by: Sheng Yang =2D-- arch/x86/kvm/i8254.c | 2 ++ arch/x86/kvm/lapic.c | 2 ++ include/asm-x86/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 2 +- 4 files changed, 7 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index fba0e4e..b2b9eb7 100644 =2D-- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -199,6 +199,7 @@ static int __pit_timer_fn(struct kvm_kpit_state *ps) struct kvm_kpit_timer *pt =3D &ps->pit_timer; atomic_inc(&pt->pending); + vcpu0->arch.timer_pending_updated =3D 1; smp_mb__after_atomic_inc(); /* FIXME: handle case where the guest is in guest mode */ if (vcpu0 && waitqueue_active(&vcpu0->wq)) { @@ -577,6 +578,7 @@ void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu) struct kvm *kvm =3D vcpu->kvm; struct kvm_kpit_state *ps; + kvm->vcpus[0]->arch.timer_pending_updated =3D 0; if (vcpu && pit) { ps =3D &pit->pit_state; diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 7652f88..b919f3f 100644 =2D-- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -944,6 +944,7 @@ static int __apic_timer_fn(struct kvm_lapic *apic) wait_queue_head_t *q =3D &apic->vcpu->wq; atomic_inc(&apic->timer.pending); + apic->vcpu->arch.timer_pending_updated =3D 1; if (waitqueue_active(q)) { apic->vcpu->arch.mp_state =3D KVM_MP_STATE_RUNNABLE; wake_up_interruptible(q); @@ -1067,6 +1068,7 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic =3D vcpu->arch.apic; + vcpu->arch.timer_pending_updated =3D 0; if (apic && apic_lvt_enabled(apic, APIC_LVTT) && atomic_read(&apic->timer.pending) > 0) { if (__inject_apic_timer_irq(apic)) diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h index 1d8cd01..5eded7b 100644 =2D-- a/include/asm-x86/kvm_host.h +++ b/include/asm-x86/kvm_host.h @@ -285,6 +285,8 @@ struct kvm_vcpu_arch { struct kvm_vcpu_time_info hv_clock; unsigned int time_offset; struct page *time_page; + + bool timer_check_pending; }; struct kvm_mem_alias { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0846d3d..ff635e3 100644 =2D-- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -791,7 +791,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) * We will block until either an interrupt or a signal wakes us up */ while (!kvm_cpu_has_interrupt(vcpu) =2D && !kvm_cpu_has_pending_timer(vcpu) + && !vcpu->arch.timer_pending_updated && !signal_pending(current) && !kvm_arch_vcpu_runnable(vcpu)) { set_current_state(TASK_INTERRUPTIBLE); =2D- 1.5.5 --Boundary-00=_AIAJIzt6dsTOKxQ Content-Type: text/x-diff; charset="iso-8859-1"; name="0001-KVM-Fix-CPU-utilize-hit-100-when-emulate-HLT-in-so.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-KVM-Fix-CPU-utilize-hit-100-when-emulate-HLT-in-so.patch" =46rom 4d08ef3173084a6f0b7b76a0727e04ff42b614ba Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Fri, 9 May 2008 15:36:27 +0800 Subject: [PATCH] KVM: Fix CPU utilize hit 100% when emulate HLT in some OS Signed-off-by: Sheng Yang =2D-- arch/x86/kvm/i8254.c | 2 ++ arch/x86/kvm/lapic.c | 2 ++ include/asm-x86/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 2 +- 4 files changed, 7 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index fba0e4e..b2b9eb7 100644 =2D-- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -199,6 +199,7 @@ static int __pit_timer_fn(struct kvm_kpit_state *ps) struct kvm_kpit_timer *pt =3D &ps->pit_timer; =20 atomic_inc(&pt->pending); + vcpu0->arch.timer_pending_updated =3D 1; smp_mb__after_atomic_inc(); /* FIXME: handle case where the guest is in guest mode */ if (vcpu0 && waitqueue_active(&vcpu0->wq)) { @@ -577,6 +578,7 @@ void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu) struct kvm *kvm =3D vcpu->kvm; struct kvm_kpit_state *ps; =20 + kvm->vcpus[0]->arch.timer_pending_updated =3D 0; if (vcpu && pit) { ps =3D &pit->pit_state; =20 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 7652f88..b919f3f 100644 =2D-- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -944,6 +944,7 @@ static int __apic_timer_fn(struct kvm_lapic *apic) wait_queue_head_t *q =3D &apic->vcpu->wq; =20 atomic_inc(&apic->timer.pending); + apic->vcpu->arch.timer_pending_updated =3D 1; if (waitqueue_active(q)) { apic->vcpu->arch.mp_state =3D KVM_MP_STATE_RUNNABLE; wake_up_interruptible(q); @@ -1067,6 +1068,7 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic =3D vcpu->arch.apic; =20 + vcpu->arch.timer_pending_updated =3D 0; if (apic && apic_lvt_enabled(apic, APIC_LVTT) && atomic_read(&apic->timer.pending) > 0) { if (__inject_apic_timer_irq(apic)) diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h index 1d8cd01..5eded7b 100644 =2D-- a/include/asm-x86/kvm_host.h +++ b/include/asm-x86/kvm_host.h @@ -285,6 +285,8 @@ struct kvm_vcpu_arch { struct kvm_vcpu_time_info hv_clock; unsigned int time_offset; struct page *time_page; + + bool timer_check_pending; }; =20 struct kvm_mem_alias { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0846d3d..ff635e3 100644 =2D-- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -791,7 +791,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) * We will block until either an interrupt or a signal wakes us up */ while (!kvm_cpu_has_interrupt(vcpu) =2D && !kvm_cpu_has_pending_timer(vcpu) + && !vcpu->arch.timer_pending_updated && !signal_pending(current) && !kvm_arch_vcpu_runnable(vcpu)) { set_current_state(TASK_INTERRUPTIBLE); =2D-=20 1.5.5 --Boundary-00=_AIAJIzt6dsTOKxQ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone --Boundary-00=_AIAJIzt6dsTOKxQ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel --Boundary-00=_AIAJIzt6dsTOKxQ--