aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/lapic.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2012-07-26 11:01:50 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2012-07-31 23:21:06 -0400
commite9d90d472da97e1b1560bffb89578ba082c88a69 (patch)
treea44f4b5d0d74f88b6dc886a6ee024ae7dd25a5c5 /arch/x86/kvm/lapic.c
parent4a4541a40e1fe145c72c4b959fac524a5600d9fb (diff)
KVM: Remove internal timer abstraction
kvm_timer_fn(), the sole inhabitant of timer.c, is only used by lapic.c. Move it there to make it easier to hack on it. struct kvm_timer is a thin wrapper around hrtimer, and only adds obfuscation. Move near its two users (with different names) to prepare for simplification. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/lapic.c')
-rw-r--r--arch/x86/kvm/lapic.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index ad7fff7ad13..61ed32cd17c 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1262,6 +1262,34 @@ static const struct kvm_io_device_ops apic_mmio_ops = {
1262 .write = apic_mmio_write, 1262 .write = apic_mmio_write,
1263}; 1263};
1264 1264
1265static enum hrtimer_restart apic_timer_fn(struct hrtimer *data)
1266{
1267 struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
1268 struct kvm_vcpu *vcpu = ktimer->vcpu;
1269 wait_queue_head_t *q = &vcpu->wq;
1270
1271 /*
1272 * There is a race window between reading and incrementing, but we do
1273 * not care about potentially losing timer events in the !reinject
1274 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
1275 * in vcpu_enter_guest.
1276 */
1277 if (ktimer->reinject || !atomic_read(&ktimer->pending)) {
1278 atomic_inc(&ktimer->pending);
1279 /* FIXME: this code should not know anything about vcpus */
1280 kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
1281 }
1282
1283 if (waitqueue_active(q))
1284 wake_up_interruptible(q);
1285
1286 if (ktimer->t_ops->is_periodic(ktimer)) {
1287 hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
1288 return HRTIMER_RESTART;
1289 } else
1290 return HRTIMER_NORESTART;
1291}
1292
1265int kvm_create_lapic(struct kvm_vcpu *vcpu) 1293int kvm_create_lapic(struct kvm_vcpu *vcpu)
1266{ 1294{
1267 struct kvm_lapic *apic; 1295 struct kvm_lapic *apic;
@@ -1285,7 +1313,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
1285 1313
1286 hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC, 1314 hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
1287 HRTIMER_MODE_ABS); 1315 HRTIMER_MODE_ABS);
1288 apic->lapic_timer.timer.function = kvm_timer_fn; 1316 apic->lapic_timer.timer.function = apic_timer_fn;
1289 apic->lapic_timer.t_ops = &lapic_timer_ops; 1317 apic->lapic_timer.t_ops = &lapic_timer_ops;
1290 apic->lapic_timer.kvm = vcpu->kvm; 1318 apic->lapic_timer.kvm = vcpu->kvm;
1291 apic->lapic_timer.vcpu = vcpu; 1319 apic->lapic_timer.vcpu = vcpu;