From patchwork Mon Jul 6 01:55:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 34298 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 n66K1dQI005529 for ; Mon, 6 Jul 2009 20:01:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbZGFUBb (ORCPT ); Mon, 6 Jul 2009 16:01:31 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753952AbZGFUBa (ORCPT ); Mon, 6 Jul 2009 16:01:30 -0400 Received: from mx2.redhat.com ([66.187.237.31]:39623 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753679AbZGFUBY (ORCPT ); Mon, 6 Jul 2009 16:01:24 -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 n66K1SIN013655 for ; Mon, 6 Jul 2009 16:01:28 -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 n66K1RXj028815; Mon, 6 Jul 2009 16:01:27 -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 n66K1Pq5030092; Mon, 6 Jul 2009 16:01:25 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 5F81C274030; Mon, 6 Jul 2009 17:00:50 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n66K0mla008094; Mon, 6 Jul 2009 17:00:48 -0300 Message-Id: <20090706015812.896284450@localhost.localdomain> References: <20090706015511.923596553@localhost.localdomain> User-Agent: quilt/0.46-1 Date: Sun, 05 Jul 2009 22:55:16 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 5/8] KVM: timer: honor noreinject tunable Content-Disposition: inline; filename=handle-no-reinject 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 Skip events which have been missed by the guest. 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 @@ -58,6 +58,21 @@ void kvm_timer_ack(struct kvm_timer *kti ktimer->can_inject = true; } +static void no_reinject_adjust(struct kvm_timer *ktimer, ktime_t expire) +{ + u64 unacked_events, delta; + ktime_t now; + + now = ktime_get(); + delta = ktime_to_ns(ktime_sub(now, expire)); + unacked_events = 0; + + if (now.tv64 > expire.tv64) + unacked_events = div_u64(delta, ktimer->period); + if (unacked_events > 1) + ktimer->acked_events += unacked_events-1; +} + static ktime_t periodic_timer_next_event(struct kvm_timer *ktimer) { ktime_t last_acked_event; @@ -136,6 +151,8 @@ void kvm_inject_pending_timer_irqs(struc ktimer->ops->inject(ktimer); if (!ktimer->periodic) list_del_init(&ktimer->vcpu_timer); + else if (unlikely(!ktimer->reinject)) + no_reinject_adjust(ktimer, expire); } }