aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2012-07-26 11:01:51 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2012-07-31 23:21:06 -0400
commit2a6eac9638a92b61de04bac4233d8ca665ae96af (patch)
tree8fb4be2b613c09e48ece185a87566bb5d87f9e17 /arch
parente9d90d472da97e1b1560bffb89578ba082c88a69 (diff)
KVM: Simplify kvm_timer
'reinject' is never initialized 't_ops' only serves as indirection to lapic_is_periodic; call that directly instead 'kvm' is never used 'vcpu' can be derived via container_of Remove these fields. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kvm/lapic.c18
-rw-r--r--arch/x86/kvm/lapic.h8
2 files changed, 5 insertions, 21 deletions
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 61ed32cd17c..0cd431c85d3 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1214,10 +1214,8 @@ int kvm_lapic_enabled(struct kvm_vcpu *vcpu)
1214 *---------------------------------------------------------------------- 1214 *----------------------------------------------------------------------
1215 */ 1215 */
1216 1216
1217static bool lapic_is_periodic(struct kvm_timer *ktimer) 1217static bool lapic_is_periodic(struct kvm_lapic *apic)
1218{ 1218{
1219 struct kvm_lapic *apic = container_of(ktimer, struct kvm_lapic,
1220 lapic_timer);
1221 return apic_lvtt_period(apic); 1219 return apic_lvtt_period(apic);
1222} 1220}
1223 1221
@@ -1253,10 +1251,6 @@ void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu)
1253 kvm_apic_local_deliver(apic, APIC_LVT0); 1251 kvm_apic_local_deliver(apic, APIC_LVT0);
1254} 1252}
1255 1253
1256static struct kvm_timer_ops lapic_timer_ops = {
1257 .is_periodic = lapic_is_periodic,
1258};
1259
1260static const struct kvm_io_device_ops apic_mmio_ops = { 1254static const struct kvm_io_device_ops apic_mmio_ops = {
1261 .read = apic_mmio_read, 1255 .read = apic_mmio_read,
1262 .write = apic_mmio_write, 1256 .write = apic_mmio_write,
@@ -1265,7 +1259,8 @@ static const struct kvm_io_device_ops apic_mmio_ops = {
1265static enum hrtimer_restart apic_timer_fn(struct hrtimer *data) 1259static enum hrtimer_restart apic_timer_fn(struct hrtimer *data)
1266{ 1260{
1267 struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer); 1261 struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
1268 struct kvm_vcpu *vcpu = ktimer->vcpu; 1262 struct kvm_lapic *apic = container_of(ktimer, struct kvm_lapic, lapic_timer);
1263 struct kvm_vcpu *vcpu = apic->vcpu;
1269 wait_queue_head_t *q = &vcpu->wq; 1264 wait_queue_head_t *q = &vcpu->wq;
1270 1265
1271 /* 1266 /*
@@ -1274,7 +1269,7 @@ static enum hrtimer_restart apic_timer_fn(struct hrtimer *data)
1274 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked 1269 * case anyway. Note: KVM_REQ_PENDING_TIMER is implicitly checked
1275 * in vcpu_enter_guest. 1270 * in vcpu_enter_guest.
1276 */ 1271 */
1277 if (ktimer->reinject || !atomic_read(&ktimer->pending)) { 1272 if (!atomic_read(&ktimer->pending)) {
1278 atomic_inc(&ktimer->pending); 1273 atomic_inc(&ktimer->pending);
1279 /* FIXME: this code should not know anything about vcpus */ 1274 /* FIXME: this code should not know anything about vcpus */
1280 kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu); 1275 kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
@@ -1283,7 +1278,7 @@ static enum hrtimer_restart apic_timer_fn(struct hrtimer *data)
1283 if (waitqueue_active(q)) 1278 if (waitqueue_active(q))
1284 wake_up_interruptible(q); 1279 wake_up_interruptible(q);
1285 1280
1286 if (ktimer->t_ops->is_periodic(ktimer)) { 1281 if (lapic_is_periodic(apic)) {
1287 hrtimer_add_expires_ns(&ktimer->timer, ktimer->period); 1282 hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
1288 return HRTIMER_RESTART; 1283 return HRTIMER_RESTART;
1289 } else 1284 } else
@@ -1314,9 +1309,6 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
1314 hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC, 1309 hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
1315 HRTIMER_MODE_ABS); 1310 HRTIMER_MODE_ABS);
1316 apic->lapic_timer.timer.function = apic_timer_fn; 1311 apic->lapic_timer.timer.function = apic_timer_fn;
1317 apic->lapic_timer.t_ops = &lapic_timer_ops;
1318 apic->lapic_timer.kvm = vcpu->kvm;
1319 apic->lapic_timer.vcpu = vcpu;
1320 1312
1321 apic->base_address = APIC_DEFAULT_PHYS_BASE; 1313 apic->base_address = APIC_DEFAULT_PHYS_BASE;
1322 vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE; 1314 vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE;
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index d7251c92ed4..166766fffd9 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -11,14 +11,6 @@ struct kvm_timer {
11 u32 timer_mode_mask; 11 u32 timer_mode_mask;
12 u64 tscdeadline; 12 u64 tscdeadline;
13 atomic_t pending; /* accumulated triggered timers */ 13 atomic_t pending; /* accumulated triggered timers */
14 bool reinject;
15 struct kvm_timer_ops *t_ops;
16 struct kvm *kvm;
17 struct kvm_vcpu *vcpu;
18};
19
20struct kvm_timer_ops {
21 bool (*is_periodic)(struct kvm_timer *);
22}; 14};
23 15
24struct kvm_lapic { 16struct kvm_lapic {