From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] KVM: Get rid of KVM_REQ_KICK Date: Tue, 04 May 2010 19:42:45 +0300 Message-ID: <4BE04E85.8020608@redhat.com> References: <1272896348-13514-1-git-send-email-avi@redhat.com> <20100504163150.GC20497@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:24888 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759856Ab0EDQmq (ORCPT ); Tue, 4 May 2010 12:42:46 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o44GgkhM008390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 May 2010 12:42:46 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o44GgjLe013081 for ; Tue, 4 May 2010 12:42:46 -0400 In-Reply-To: <20100504163150.GC20497@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 05/04/2010 07:31 PM, Marcelo Tosatti wrote: > On Mon, May 03, 2010 at 05:19:08PM +0300, Avi Kivity wrote: > >> KVM_REQ_KICK poisons vcpu->requests by having a bit set during normal >> operation. This causes the fast path check for a clear vcpu->requests >> to fail all the time, triggering tons of atomic operations. >> > Avi, > > Do you have numbers? > Forgot to post, was about 100 cycles (I expected more, all those atomics really show up in the profile). >> Fix by replacing KVM_REQ_KICK with a vcpu->guest_mode atomic. >> >> Signed-off-by: Avi Kivity >> --- >> arch/x86/kvm/x86.c | 17 ++++++++++------- >> include/linux/kvm_host.h | 1 + >> 2 files changed, 11 insertions(+), 7 deletions(-) >> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 6b2ce1d..307094a 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -4499,13 +4499,15 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) >> if (vcpu->fpu_active) >> kvm_load_guest_fpu(vcpu); >> >> - local_irq_disable(); >> + atomic_set(&vcpu->guest_mode, 1); >> + smp_wmb(); >> > IPI can trigger here? > It can... > >> - clear_bit(KVM_REQ_KICK,&vcpu->requests); >> - smp_mb__after_clear_bit(); >> + local_irq_disable(); >> >> - if (vcpu->requests || need_resched() || signal_pending(current)) { >> - set_bit(KVM_REQ_KICK,&vcpu->requests); >> + if (!atomic_read(&vcpu->guest_mode) || vcpu->requests >> + || need_resched() || signal_pending(current)) { >> ... and we'll detect that guest_mode was cleared and go back. >> + atomic_set(&vcpu->guest_mode, 0); >> + smp_wmb(); >> local_irq_enable(); >> preempt_enable(); >> r = 1; >> @@ -4550,7 +4552,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) >> if (hw_breakpoint_active()) >> hw_breakpoint_restore(); >> >> - set_bit(KVM_REQ_KICK,&vcpu->requests); >> + atomic_set(&vcpu->guest_mode, 0); >> + smp_wmb(); >> local_irq_enable(); >> >> ++vcpu->stat.exits; >> @@ -5470,7 +5473,7 @@ void kvm_vcpu_kick(struct kvm_vcpu *vcpu) >> >> me = get_cpu(); >> if (cpu != me&& (unsigned)cpu< nr_cpu_ids&& cpu_online(cpu)) >> - if (!test_and_set_bit(KVM_REQ_KICK,&vcpu->requests)) >> + if (atomic_xchg(&vcpu->guest_mode, 0)) >> smp_send_reschedule(cpu); >> put_cpu(); >> The atomic_xchg() does the trick. -- error compiling committee.c: too many arguments to function