Marcelo Tosatti | d3c7b77 | 2009-02-23 10:57:41 -0300 | [diff] [blame] | 1 | #include <linux/kvm_host.h> |
| 2 | #include <linux/kvm.h> |
| 3 | #include <linux/hrtimer.h> |
| 4 | #include <asm/atomic.h> |
| 5 | #include "kvm_timer.h" |
| 6 | |
| 7 | static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer) |
| 8 | { |
| 9 | int restart_timer = 0; |
| 10 | wait_queue_head_t *q = &vcpu->wq; |
| 11 | |
| 12 | /* FIXME: this code should not know anything about vcpus */ |
| 13 | if (!atomic_inc_and_test(&ktimer->pending)) |
| 14 | set_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests); |
| 15 | |
| 16 | if (!ktimer->reinject) |
| 17 | atomic_set(&ktimer->pending, 1); |
| 18 | |
| 19 | if (waitqueue_active(q)) |
| 20 | wake_up_interruptible(q); |
| 21 | |
| 22 | if (ktimer->t_ops->is_periodic(ktimer)) { |
| 23 | hrtimer_add_expires_ns(&ktimer->timer, ktimer->period); |
| 24 | restart_timer = 1; |
| 25 | } |
| 26 | |
| 27 | return restart_timer; |
| 28 | } |
| 29 | |
| 30 | enum hrtimer_restart kvm_timer_fn(struct hrtimer *data) |
| 31 | { |
| 32 | int restart_timer; |
| 33 | struct kvm_vcpu *vcpu; |
| 34 | struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer); |
| 35 | |
Gleb Natapov | 1ed0ce0 | 2009-06-09 15:56:27 +0300 | [diff] [blame^] | 36 | vcpu = ktimer->vcpu; |
Marcelo Tosatti | d3c7b77 | 2009-02-23 10:57:41 -0300 | [diff] [blame] | 37 | if (!vcpu) |
| 38 | return HRTIMER_NORESTART; |
| 39 | |
| 40 | restart_timer = __kvm_timer_fn(vcpu, ktimer); |
| 41 | if (restart_timer) |
| 42 | return HRTIMER_RESTART; |
| 43 | else |
| 44 | return HRTIMER_NORESTART; |
| 45 | } |
| 46 | |