From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH RFC] KVM: busy-spin detector Date: Wed, 16 Jun 2010 11:22:22 +0300 Message-ID: <4C1889BE.9000600@redhat.com> References: <20100611022551.GA16223@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:25987 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752055Ab0FPIWX (ORCPT ); Wed, 16 Jun 2010 04:22:23 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5G8MN2r030625 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Jun 2010 04:22:23 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5G8MMnt009150 for ; Wed, 16 Jun 2010 04:22:23 -0400 In-Reply-To: <20100611022551.GA16223@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 06/11/2010 05:25 AM, Marcelo Tosatti wrote: > The following patch implements a simple busy-spin detector. It considers > a vcpu as busy-spinning if there are two consecutive exits due to > external interrupt on the same RIP, and sleeps for 100us in that case. > > It is very likely that if the vcpu is making progress it will either > exit for other reasons or change RIP. > > The percentage numbers below represent improvement in kernel build > time in comparison with mainline (RHEL 5.4 guest). > > make -j16, 8 cpu host: > smp 16: 3% > smp 18: 10% > smp 32: 14% > > smp 4, make -j4, pinned to 2 cpus: > 4% > > smp 8, make -j8, pinned to 2 cpus: > 5% > > The big problem here is not in the patch itself, but in kvm_vcpu_on_spin(). An un-overcommitted guest will trigger this on long spinlocks and go to sleep, and if the lock is released while we're still sleeping, we lose performance. > @@ -4654,6 +4665,8 @@ static int vcpu_enter_guest(struct kvm_v > kvm_lapic_sync_from_vapic(vcpu); > > r = kvm_x86_ops->handle_exit(vcpu); > + if (r == 1) > + vcpu->arch.last_rip = ~(0UL); > out: > return r; > } > != 2, no? It's a little ugly to overload the return code like that. Perhaps: + vcpu->arch.save_last_rip = vcpu->arch.last_rip + vcpu->arch.last_rip = ~0UL; r = kvm_x86_ops->handle_exit(vcpu); And kvm_detect_spin() can restore last_rip. -- error compiling committee.c: too many arguments to function