Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751565AbbLUBvA (ORCPT ); Sun, 20 Dec 2015 20:51:00 -0500 Received: from mga03.intel.com ([134.134.136.65]:53500 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751499AbbLUBu6 convert rfc822-to-8bit (ORCPT ); Sun, 20 Dec 2015 20:50:58 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,457,1444719600"; d="scan'208";a="845455444" From: "Wu, Feng" To: Yang Zhang , "pbonzini@redhat.com" , "rkrcmar@redhat.com" CC: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Wu, Feng" Subject: RE: [PATCH v2 1/2] KVM: x86: Use vector-hashing to deliver lowest-priority interrupts Thread-Topic: [PATCH v2 1/2] KVM: x86: Use vector-hashing to deliver lowest-priority interrupts Thread-Index: AQHRO5FzVNvWlqsXtkO3uwvyjy20qJ7UrBtA Date: Mon, 21 Dec 2015 01:50:54 +0000 Message-ID: References: <1450229853-3886-1-git-send-email-feng.wu@intel.com> <1450229853-3886-2-git-send-email-feng.wu@intel.com> <567759F2.5080809@gmail.com> In-Reply-To: <567759F2.5080809@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5304 Lines: 166 > -----Original Message----- > From: Yang Zhang [mailto:yang.zhang.wz@gmail.com] > Sent: Monday, December 21, 2015 9:46 AM > To: Wu, Feng ; pbonzini@redhat.com; > rkrcmar@redhat.com > Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH v2 1/2] KVM: x86: Use vector-hashing to deliver lowest- > priority interrupts > > On 2015/12/16 9:37, Feng Wu wrote: > > Use vector-hashing to deliver lowest-priority interrupts, As an > > example, modern Intel CPUs in server platform use this method to > > handle lowest-priority interrupts. > > > > Signed-off-by: Feng Wu > > --- > > arch/x86/kvm/irq_comm.c | 27 ++++++++++++++++++----- > > arch/x86/kvm/lapic.c | 57 > ++++++++++++++++++++++++++++++++++++++++--------- > > arch/x86/kvm/lapic.h | 2 ++ > > arch/x86/kvm/x86.c | 9 ++++++++ > > arch/x86/kvm/x86.h | 1 + > > 5 files changed, 81 insertions(+), 15 deletions(-) > > > > diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c > > index 84b96d3..c8c5f61 100644 > > --- a/arch/x86/kvm/irq_comm.c > > +++ b/arch/x86/kvm/irq_comm.c > > @@ -32,6 +32,7 @@ > > #include "ioapic.h" > > > > #include "lapic.h" > > +#include "x86.h" > > > > static int kvm_set_pic_irq(struct kvm_kernel_irq_routing_entry *e, > > struct kvm *kvm, int irq_source_id, int level, > > @@ -53,8 +54,10 @@ static int kvm_set_ioapic_irq(struct > kvm_kernel_irq_routing_entry *e, > > int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, > > struct kvm_lapic_irq *irq, unsigned long *dest_map) > > { > > - int i, r = -1; > > + int i, r = -1, idx = 0; > > struct kvm_vcpu *vcpu, *lowest = NULL; > > + unsigned long dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)]; > > + unsigned int dest_vcpus = 0; > > > > if (irq->dest_mode == 0 && irq->dest_id == 0xff && > > kvm_lowest_prio_delivery(irq)) { > > @@ -65,6 +68,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct > kvm_lapic *src, > > if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map)) > > return r; > > > > + memset(dest_vcpu_bitmap, 0, sizeof(dest_vcpu_bitmap)); > > + > > kvm_for_each_vcpu(i, vcpu, kvm) { > > if (!kvm_apic_present(vcpu)) > > continue; > > @@ -78,13 +83,25 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct > kvm_lapic *src, > > r = 0; > > r += kvm_apic_set_irq(vcpu, irq, dest_map); > > } else if (kvm_lapic_enabled(vcpu)) { > > - if (!lowest) > > - lowest = vcpu; > > - else if (kvm_apic_compare_prio(vcpu, lowest) < 0) > > - lowest = vcpu; > > + if (!kvm_vector_hashing_enabled()) { > > + if (!lowest) > > + lowest = vcpu; > > + else if (kvm_apic_compare_prio(vcpu, lowest) < > 0) > > + lowest = vcpu; > > + } else { > > + __set_bit(vcpu->vcpu_id, dest_vcpu_bitmap); > > + dest_vcpus++; > > + } > > } > > } > > > > + if (dest_vcpus != 0) { > > + idx = kvm_vector_2_index(irq->vector, dest_vcpus, > > + dest_vcpu_bitmap, KVM_MAX_VCPUS); > > + > > + lowest = kvm_get_vcpu(kvm, idx - 1); > > + } > > + > > if (lowest) > > r = kvm_apic_set_irq(lowest, irq, dest_map); > > > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > > index ecd4ea1..e29001f 100644 > > --- a/arch/x86/kvm/lapic.c > > +++ b/arch/x86/kvm/lapic.c > > @@ -678,6 +678,22 @@ bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, > struct kvm_lapic *source, > > } > > } > > > > +int kvm_vector_2_index(u32 vector, u32 dest_vcpus, > > + const unsigned long *bitmap, u32 bitmap_size) > > +{ > > + u32 mod; > > + int i, idx = 0; > > + > > + mod = vector % dest_vcpus; > > + > > + for (i = 0; i <= mod; i++) { > > + idx = find_next_bit(bitmap, bitmap_size, idx) + 1; > > + BUG_ON(idx > bitmap_size); > > + } > > + > > + return idx; > > +} > > + > > bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, > > struct kvm_lapic_irq *irq, int *r, unsigned long *dest_map) > > { > > @@ -731,17 +747,38 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm > *kvm, struct kvm_lapic *src, > > dst = map->logical_map[cid]; > > > > if (kvm_lowest_prio_delivery(irq)) { > > - int l = -1; > > - for_each_set_bit(i, &bitmap, 16) { > > - if (!dst[i]) > > - continue; > > - if (l < 0) > > - l = i; > > - else if (kvm_apic_compare_prio(dst[i]->vcpu, > dst[l]->vcpu) < 0) > > - l = i; > > + if (!kvm_vector_hashing_enabled()) { > > + int l = -1; > > + for_each_set_bit(i, &bitmap, 16) { > > + if (!dst[i]) > > + continue; > > + if (l < 0) > > + l = i; > > + else if (kvm_apic_compare_prio(dst[i]- > >vcpu, dst[l]->vcpu) < 0) > > + l = i; > > + } > > + bitmap = (l >= 0) ? 1 << l : 0; > > + } else { > > + int idx = 0; > > + unsigned int dest_vcpus = 0; > > + > > + for_each_set_bit(i, &bitmap, 16) { > > + if (!dst[i] > && !kvm_lapic_enabled(dst[i]->vcpu)) { > > It should be or(||) not and (&&). Oh, you are right! My negligence! Thanks for pointing this out, Yang! Thanks, Feng -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/