KVM: SVM: count all irq windows exit
[linux-3.10.git] / arch / x86 / kvm / timer.c
index eea4043..6b85cc6 100644 (file)
@@ -1,23 +1,39 @@
+/*
+ * Kernel-based Virtual Machine driver for Linux
+ *
+ * This module enables machines with Intel VT-x extensions to run virtual
+ * machines without emulation or binary translation.
+ *
+ * timer support
+ *
+ * Copyright 2010 Red Hat, Inc. and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
 #include <linux/kvm_host.h>
 #include <linux/kvm.h>
 #include <linux/hrtimer.h>
-#include <asm/atomic.h>
+#include <linux/atomic.h>
 #include "kvm_timer.h"
 
-static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
+enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
 {
-       int restart_timer = 0;
+       struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
+       struct kvm_vcpu *vcpu = ktimer->vcpu;
        wait_queue_head_t *q = &vcpu->wq;
 
        /*
         * There is a race window between reading and incrementing, but we do
-        * not care about potentially loosing timer events in the !reinject
-        * case anyway.
+        * not care about potentially losing timer events in the !reinject
+        * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
+        * in vcpu_enter_guest.
         */
        if (ktimer->reinject || !atomic_read(&ktimer->pending)) {
                atomic_inc(&ktimer->pending);
                /* FIXME: this code should not know anything about vcpus */
-               set_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
+               kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
        }
 
        if (waitqueue_active(q))
@@ -25,26 +41,7 @@ static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
 
        if (ktimer->t_ops->is_periodic(ktimer)) {
                hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
-               restart_timer = 1;
-       }
-
-       return restart_timer;
-}
-
-enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
-{
-       int restart_timer;
-       struct kvm_vcpu *vcpu;
-       struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
-
-       vcpu = ktimer->vcpu;
-       if (!vcpu)
-               return HRTIMER_NORESTART;
-
-       restart_timer = __kvm_timer_fn(vcpu, ktimer);
-       if (restart_timer)
                return HRTIMER_RESTART;
-       else
+       } else
                return HRTIMER_NORESTART;
 }
-