From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 5/8] KVM: timer: honor noreinject tunable Date: Sun, 05 Jul 2009 22:55:16 -0300 Message-ID: <20090706015812.896284450@localhost.localdomain> References: <20090706015511.923596553@localhost.localdomain> Cc: Marcelo Tosatti To: kvm@vger.kernel.org Return-path: 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 Content-Disposition: inline; filename=handle-no-reinject Sender: kvm-owner@vger.kernel.org List-ID: 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); } } --