1 #include <linux/kvm_host.h>
3 #include <linux/hrtimer.h>
4 #include <asm/atomic.h>
7 static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
10 wait_queue_head_t *q = &vcpu->wq;
13 * There is a race window between reading and incrementing, but we do
14 * not care about potentially loosing timer events in the !reinject
15 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
16 * in vcpu_enter_guest.
18 if (ktimer->reinject || !atomic_read(&ktimer->pending)) {
19 atomic_inc(&ktimer->pending);
20 /* FIXME: this code should not know anything about vcpus */
21 set_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
24 if (waitqueue_active(q))
25 wake_up_interruptible(q);
27 if (ktimer->t_ops->is_periodic(ktimer)) {
28 hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
35 enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
38 struct kvm_vcpu *vcpu;
39 struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
43 return HRTIMER_NORESTART;
45 restart_timer = __kvm_timer_fn(vcpu, ktimer);
47 return HRTIMER_RESTART;
49 return HRTIMER_NORESTART;