diff mbox

[5/8] KVM: timer: honor noreinject tunable

Message ID 20090706015812.896284450@localhost.localdomain (mailing list archive)
State New, archived
Headers show

Commit Message

Marcelo Tosatti July 6, 2009, 1:55 a.m. UTC
Skip events which have been missed by the guest.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
diff mbox

Patch

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);
 	}
 }