From patchwork Mon Jul 6 01:55:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 34295 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n66K1WPA005491 for ; Mon, 6 Jul 2009 20:01:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753878AbZGFUB0 (ORCPT ); Mon, 6 Jul 2009 16:01:26 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753847AbZGFUBZ (ORCPT ); Mon, 6 Jul 2009 16:01:25 -0400 Received: from mx2.redhat.com ([66.187.237.31]:39620 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753325AbZGFUBV (ORCPT ); Mon, 6 Jul 2009 16:01:21 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n66K1PRP013637 for ; Mon, 6 Jul 2009 16:01:25 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n66K1OTM028803; Mon, 6 Jul 2009 16:01:24 -0400 Received: from amt.cnet (vpn-51-10.sfbay.redhat.com [10.14.51.10]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n66K1MLh030077; Mon, 6 Jul 2009 16:01:23 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id F38A7274031; Mon, 6 Jul 2009 17:00:51 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n66K0oL0008095; Mon, 6 Jul 2009 17:00:50 -0300 Message-Id: <20090706015813.001127585@localhost.localdomain> References: <20090706015511.923596553@localhost.localdomain> User-Agent: quilt/0.46-1 Date: Sun, 05 Jul 2009 22:55:17 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 6/8] KVM: timer: optimize next_timer_event and vcpu_arm_exit Content-Disposition: inline; filename=kvm-armexit-optimize X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Which reduces the added entry/exit overhead down to ~= 30 cycles. Signed-off-by: Marcelo Tosatti Index: kvm-new/arch/x86/kvm/timer.c =================================================================== --- kvm-new.orig/arch/x86/kvm/timer.c +++ kvm-new/arch/x86/kvm/timer.c @@ -135,14 +135,15 @@ ktime_t kvm_vcpu_next_timer_event(struct void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu) { struct kvm_timer *ktimer, *n; - ktime_t now = ktime_get(); list_for_each_entry_safe(ktimer, n, &vcpu->arch.timers, vcpu_timer) { - ktime_t expire; + ktime_t expire, now; if (!ktimer->can_inject) continue; + now = ktime_get(); + expire = kvm_timer_next_event(ktimer); if (ktime_to_ns(now) < ktime_to_ns(expire)) continue; @@ -173,8 +174,12 @@ void kvm_vcpu_arm_exit(struct kvm_vcpu * { ktime_t expire; ktime_t now; - struct kvm_timer *ktimer = kvm_vcpu_injectable_timer_event(vcpu); + struct kvm_timer *ktimer; + + if (hrtimer_active(&vcpu->arch.exit_timer)) + return; + ktimer = kvm_vcpu_injectable_timer_event(vcpu); if (!ktimer) return; Index: kvm-new/arch/x86/kvm/x86.c =================================================================== --- kvm-new.orig/arch/x86/kvm/x86.c +++ kvm-new/arch/x86/kvm/x86.c @@ -3567,8 +3567,6 @@ static int vcpu_enter_guest(struct kvm_v preempt_enable(); - kvm_vcpu_cleanup_timer(vcpu); - down_read(&vcpu->kvm->slots_lock); /*