From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Yang, Sheng" Subject: [RFC][PATCH 1/4] KVM: LAPIC: Unified the duplicate calling of setting IRR Date: Thu, 8 May 2008 16:55:36 +0800 Message-ID: <200805081655.36530.sheng.yang@intel.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_IAsIIf+X4/zBokp" To: " kvm-devel" Return-path: 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=_IAsIIf+X4/zBokp Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =46rom 650cad44069541fcd9fea8be6a78837e812b3dfd Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Thu, 8 May 2008 09:58:50 +0800 Subject: [PATCH 1/4] KVM: LAPIC: Unified the duplicate calling of setting I= RR It's strange got two callings of setting IRR seperately for IOAPIC and IPI = in lapic. The patch unified them into __apic_set_irq(). Signed-off-by: Sheng Yang =2D-- arch/x86/kvm/lapic.c | 69 +++++++++++++++++++++++-----------------------= =2D-- 1 files changed, 32 insertions(+), 37 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 7652f88..6226fe0 100644 =2D-- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -184,20 +184,40 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr); =2Dint kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig) +static int __apic_set_irq(struct kvm_vcpu *vcpu, u8 vector, u8 trig_mode) { struct kvm_lapic *apic =3D vcpu->arch.apic; =2D if (!apic_test_and_set_irr(vec, apic)) { =2D /* a new pending irq is set in IRR */ =2D if (trig) =2D apic_set_vector(vec, apic->regs + APIC_TMR); =2D else =2D apic_clear_vector(vec, apic->regs + APIC_TMR); =2D kvm_vcpu_kick(apic->vcpu); =2D return 1; + /* FIXME add logic for vcpu on reset */ + if (unlikely(!apic_enabled(apic))) + return 0; + + if (apic_test_and_set_irr(vector, apic)) { + if (trig_mode) + apic_debug("level trig mode repeatedly for vector %d\n", + vector); + return 0; } =2D return 0; + + if (trig_mode) { + apic_debug("level trig mode for vector %d\n", vector); + apic_set_vector(vector, apic->regs + APIC_TMR); + } else + apic_clear_vector(vector, apic->regs + APIC_TMR); + + if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_RUNNABLE) + kvm_vcpu_kick(vcpu); + else if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_HALTED) { + vcpu->arch.mp_state =3D KVM_MP_STATE_RUNNABLE; + if (waitqueue_active(&vcpu->wq)) + wake_up_interruptible(&vcpu->wq); + } + return 1; +} + +int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig) +{ + return __apic_set_irq(vcpu, vec, trig); } static inline int apic_find_highest_isr(struct kvm_lapic *apic) @@ -315,38 +335,13 @@ static int apic_match_dest(struct kvm_vcpu *vcpu, str= uct=20 kvm_lapic *source, static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, int vector, int level, int trig_mode) { =2D int orig_irr, result =3D 0; + int result =3D 0; struct kvm_vcpu *vcpu =3D apic->vcpu; switch (delivery_mode) { case APIC_DM_FIXED: case APIC_DM_LOWEST: =2D /* FIXME add logic for vcpu on reset */ =2D if (unlikely(!apic_enabled(apic))) =2D break; =2D =2D orig_irr =3D apic_test_and_set_irr(vector, apic); =2D if (orig_irr && trig_mode) { =2D apic_debug("level trig mode repeatedly for vector %d", =2D vector); =2D break; =2D } =2D =2D if (trig_mode) { =2D apic_debug("level trig mode for vector %d", vector); =2D apic_set_vector(vector, apic->regs + APIC_TMR); =2D } else =2D apic_clear_vector(vector, apic->regs + APIC_TMR); =2D =2D if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_RUNNABLE) =2D kvm_vcpu_kick(vcpu); =2D else if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_HALTED) { =2D vcpu->arch.mp_state =3D KVM_MP_STATE_RUNNABLE; =2D if (waitqueue_active(&vcpu->wq)) =2D wake_up_interruptible(&vcpu->wq); =2D } =2D =2D result =3D (orig_irr =3D=3D 0); + result =3D __apic_set_irq(vcpu, vector, trig_mode); break; case APIC_DM_REMRD: =2D- 1.5.5 --Boundary-00=_IAsIIf+X4/zBokp Content-Type: text/x-diff; charset="utf-8"; name="0001-KVM-LAPIC-Unified-the-duplicate-calling-of-setting.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-KVM-LAPIC-Unified-the-duplicate-calling-of-setting.patch" =46rom 650cad44069541fcd9fea8be6a78837e812b3dfd Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Thu, 8 May 2008 09:58:50 +0800 Subject: [PATCH 1/4] KVM: LAPIC: Unified the duplicate calling of setting I= RR It's strange got two callings of setting IRR seperately for IOAPIC and IPI = in lapic. The patch unified them into __apic_set_irq(). Signed-off-by: Sheng Yang =2D-- arch/x86/kvm/lapic.c | 69 +++++++++++++++++++++++-----------------------= =2D-- 1 files changed, 32 insertions(+), 37 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 7652f88..6226fe0 100644 =2D-- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -184,20 +184,40 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr); =20 =2Dint kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig) +static int __apic_set_irq(struct kvm_vcpu *vcpu, u8 vector, u8 trig_mode) { struct kvm_lapic *apic =3D vcpu->arch.apic; =20 =2D if (!apic_test_and_set_irr(vec, apic)) { =2D /* a new pending irq is set in IRR */ =2D if (trig) =2D apic_set_vector(vec, apic->regs + APIC_TMR); =2D else =2D apic_clear_vector(vec, apic->regs + APIC_TMR); =2D kvm_vcpu_kick(apic->vcpu); =2D return 1; + /* FIXME add logic for vcpu on reset */ + if (unlikely(!apic_enabled(apic))) + return 0; + + if (apic_test_and_set_irr(vector, apic)) { + if (trig_mode) + apic_debug("level trig mode repeatedly for vector %d\n", + vector); + return 0; } =2D return 0; + + if (trig_mode) { + apic_debug("level trig mode for vector %d\n", vector); + apic_set_vector(vector, apic->regs + APIC_TMR); + } else + apic_clear_vector(vector, apic->regs + APIC_TMR); + + if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_RUNNABLE) + kvm_vcpu_kick(vcpu); + else if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_HALTED) { + vcpu->arch.mp_state =3D KVM_MP_STATE_RUNNABLE; + if (waitqueue_active(&vcpu->wq)) + wake_up_interruptible(&vcpu->wq); + } + return 1; +} + +int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig) +{ + return __apic_set_irq(vcpu, vec, trig); } =20 static inline int apic_find_highest_isr(struct kvm_lapic *apic) @@ -315,38 +335,13 @@ static int apic_match_dest(struct kvm_vcpu *vcpu, str= uct kvm_lapic *source, static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, int vector, int level, int trig_mode) { =2D int orig_irr, result =3D 0; + int result =3D 0; struct kvm_vcpu *vcpu =3D apic->vcpu; =20 switch (delivery_mode) { case APIC_DM_FIXED: case APIC_DM_LOWEST: =2D /* FIXME add logic for vcpu on reset */ =2D if (unlikely(!apic_enabled(apic))) =2D break; =2D =2D orig_irr =3D apic_test_and_set_irr(vector, apic); =2D if (orig_irr && trig_mode) { =2D apic_debug("level trig mode repeatedly for vector %d", =2D vector); =2D break; =2D } =2D =2D if (trig_mode) { =2D apic_debug("level trig mode for vector %d", vector); =2D apic_set_vector(vector, apic->regs + APIC_TMR); =2D } else =2D apic_clear_vector(vector, apic->regs + APIC_TMR); =2D =2D if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_RUNNABLE) =2D kvm_vcpu_kick(vcpu); =2D else if (vcpu->arch.mp_state =3D=3D KVM_MP_STATE_HALTED) { =2D vcpu->arch.mp_state =3D KVM_MP_STATE_RUNNABLE; =2D if (waitqueue_active(&vcpu->wq)) =2D wake_up_interruptible(&vcpu->wq); =2D } =2D =2D result =3D (orig_irr =3D=3D 0); + result =3D __apic_set_irq(vcpu, vector, trig_mode); break; =20 case APIC_DM_REMRD: =2D-=20 1.5.5 --Boundary-00=_IAsIIf+X4/zBokp 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=_IAsIIf+X4/zBokp 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=_IAsIIf+X4/zBokp--