aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2012-07-26 11:01:53 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2012-07-31 23:21:07 -0400
commit26ef19242f6e4d747a61b5fd8da72343838864e4 (patch)
treef2eedd1c60bbd34f72c6a1546958cb8bec0c573d /arch
parent9d9d2239bdecd525ce3eb6cbfe4abb925c98208c (diff)
KVM: fold kvm_pit_timer into kvm_kpit_state
One structure nests inside the other, providing no value at all. 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/i8254.c52
-rw-r--r--arch/x86/kvm/i8254.h14
-rw-r--r--arch/x86/kvm/x86.c2
3 files changed, 31 insertions, 37 deletions
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index a9e187a5b19..11300d2fa71 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -108,7 +108,7 @@ static s64 __kpit_elapsed(struct kvm *kvm)
108 ktime_t remaining; 108 ktime_t remaining;
109 struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state; 109 struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;
110 110
111 if (!ps->pit_timer.period) 111 if (!ps->period)
112 return 0; 112 return 0;
113 113
114 /* 114 /*
@@ -120,9 +120,9 @@ static s64 __kpit_elapsed(struct kvm *kvm)
120 * itself with the initial count and continues counting 120 * itself with the initial count and continues counting
121 * from there. 121 * from there.
122 */ 122 */
123 remaining = hrtimer_get_remaining(&ps->pit_timer.timer); 123 remaining = hrtimer_get_remaining(&ps->timer);
124 elapsed = ps->pit_timer.period - ktime_to_ns(remaining); 124 elapsed = ps->period - ktime_to_ns(remaining);
125 elapsed = mod_64(elapsed, ps->pit_timer.period); 125 elapsed = mod_64(elapsed, ps->period);
126 126
127 return elapsed; 127 return elapsed;
128} 128}
@@ -238,12 +238,12 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
238 int value; 238 int value;
239 239
240 spin_lock(&ps->inject_lock); 240 spin_lock(&ps->inject_lock);
241 value = atomic_dec_return(&ps->pit_timer.pending); 241 value = atomic_dec_return(&ps->pending);
242 if (value < 0) 242 if (value < 0)
243 /* spurious acks can be generated if, for example, the 243 /* spurious acks can be generated if, for example, the
244 * PIC is being reset. Handle it gracefully here 244 * PIC is being reset. Handle it gracefully here
245 */ 245 */
246 atomic_inc(&ps->pit_timer.pending); 246 atomic_inc(&ps->pending);
247 else if (value > 0) 247 else if (value > 0)
248 /* in this case, we had multiple outstanding pit interrupts 248 /* in this case, we had multiple outstanding pit interrupts
249 * that we needed to inject. Reinject 249 * that we needed to inject. Reinject
@@ -261,14 +261,14 @@ void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
261 if (!kvm_vcpu_is_bsp(vcpu) || !pit) 261 if (!kvm_vcpu_is_bsp(vcpu) || !pit)
262 return; 262 return;
263 263
264 timer = &pit->pit_state.pit_timer.timer; 264 timer = &pit->pit_state.timer;
265 if (hrtimer_cancel(timer)) 265 if (hrtimer_cancel(timer))
266 hrtimer_start_expires(timer, HRTIMER_MODE_ABS); 266 hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
267} 267}
268 268
269static void destroy_pit_timer(struct kvm_pit *pit) 269static void destroy_pit_timer(struct kvm_pit *pit)
270{ 270{
271 hrtimer_cancel(&pit->pit_state.pit_timer.timer); 271 hrtimer_cancel(&pit->pit_state.timer);
272 flush_kthread_work(&pit->expired); 272 flush_kthread_work(&pit->expired);
273} 273}
274 274
@@ -311,16 +311,16 @@ static void pit_do_work(struct kthread_work *work)
311 311
312static enum hrtimer_restart pit_timer_fn(struct hrtimer *data) 312static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
313{ 313{
314 struct kvm_pit_timer *ktimer = container_of(data, struct kvm_pit_timer, timer); 314 struct kvm_kpit_state *ps = container_of(data, struct kvm_kpit_state, timer);
315 struct kvm_pit *pt = ktimer->kvm->arch.vpit; 315 struct kvm_pit *pt = ps->kvm->arch.vpit;
316 316
317 if (ktimer->reinject || !atomic_read(&ktimer->pending)) { 317 if (ps->reinject || !atomic_read(&ps->pending)) {
318 atomic_inc(&ktimer->pending); 318 atomic_inc(&ps->pending);
319 queue_kthread_work(&pt->worker, &pt->expired); 319 queue_kthread_work(&pt->worker, &pt->expired);
320 } 320 }
321 321
322 if (pt->pit_state.is_periodic) { 322 if (ps->is_periodic) {
323 hrtimer_add_expires_ns(&ktimer->timer, ktimer->period); 323 hrtimer_add_expires_ns(&ps->timer, ps->period);
324 return HRTIMER_RESTART; 324 return HRTIMER_RESTART;
325 } else 325 } else
326 return HRTIMER_NORESTART; 326 return HRTIMER_NORESTART;
@@ -329,7 +329,6 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
329static void create_pit_timer(struct kvm *kvm, u32 val, int is_period) 329static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
330{ 330{
331 struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state; 331 struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;
332 struct kvm_pit_timer *pt = &ps->pit_timer;
333 s64 interval; 332 s64 interval;
334 333
335 if (!irqchip_in_kernel(kvm) || ps->flags & KVM_PIT_FLAGS_HPET_LEGACY) 334 if (!irqchip_in_kernel(kvm) || ps->flags & KVM_PIT_FLAGS_HPET_LEGACY)
@@ -340,18 +339,18 @@ static void create_pit_timer(struct kvm *kvm, u32 val, int is_period)
340 pr_debug("create pit timer, interval is %llu nsec\n", interval); 339 pr_debug("create pit timer, interval is %llu nsec\n", interval);
341 340
342 /* TODO The new value only affected after the retriggered */ 341 /* TODO The new value only affected after the retriggered */
343 hrtimer_cancel(&pt->timer); 342 hrtimer_cancel(&ps->timer);
344 flush_kthread_work(&ps->pit->expired); 343 flush_kthread_work(&ps->pit->expired);
345 pt->period = interval; 344 ps->period = interval;
346 ps->is_periodic = is_period; 345 ps->is_periodic = is_period;
347 346
348 pt->timer.function = pit_timer_fn; 347 ps->timer.function = pit_timer_fn;
349 pt->kvm = ps->pit->kvm; 348 ps->kvm = ps->pit->kvm;
350 349
351 atomic_set(&pt->pending, 0); 350 atomic_set(&ps->pending, 0);
352 ps->irq_ack = 1; 351 ps->irq_ack = 1;
353 352
354 hrtimer_start(&pt->timer, ktime_add_ns(ktime_get(), interval), 353 hrtimer_start(&ps->timer, ktime_add_ns(ktime_get(), interval),
355 HRTIMER_MODE_ABS); 354 HRTIMER_MODE_ABS);
356} 355}
357 356
@@ -627,7 +626,7 @@ void kvm_pit_reset(struct kvm_pit *pit)
627 } 626 }
628 mutex_unlock(&pit->pit_state.lock); 627 mutex_unlock(&pit->pit_state.lock);
629 628
630 atomic_set(&pit->pit_state.pit_timer.pending, 0); 629 atomic_set(&pit->pit_state.pending, 0);
631 pit->pit_state.irq_ack = 1; 630 pit->pit_state.irq_ack = 1;
632} 631}
633 632
@@ -636,7 +635,7 @@ static void pit_mask_notifer(struct kvm_irq_mask_notifier *kimn, bool mask)
636 struct kvm_pit *pit = container_of(kimn, struct kvm_pit, mask_notifier); 635 struct kvm_pit *pit = container_of(kimn, struct kvm_pit, mask_notifier);
637 636
638 if (!mask) { 637 if (!mask) {
639 atomic_set(&pit->pit_state.pit_timer.pending, 0); 638 atomic_set(&pit->pit_state.pending, 0);
640 pit->pit_state.irq_ack = 1; 639 pit->pit_state.irq_ack = 1;
641 } 640 }
642} 641}
@@ -694,12 +693,11 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
694 693
695 pit_state = &pit->pit_state; 694 pit_state = &pit->pit_state;
696 pit_state->pit = pit; 695 pit_state->pit = pit;
697 hrtimer_init(&pit_state->pit_timer.timer, 696 hrtimer_init(&pit_state->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
698 CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
699 pit_state->irq_ack_notifier.gsi = 0; 697 pit_state->irq_ack_notifier.gsi = 0;
700 pit_state->irq_ack_notifier.irq_acked = kvm_pit_ack_irq; 698 pit_state->irq_ack_notifier.irq_acked = kvm_pit_ack_irq;
701 kvm_register_irq_ack_notifier(kvm, &pit_state->irq_ack_notifier); 699 kvm_register_irq_ack_notifier(kvm, &pit_state->irq_ack_notifier);
702 pit_state->pit_timer.reinject = true; 700 pit_state->reinject = true;
703 mutex_unlock(&pit->pit_state.lock); 701 mutex_unlock(&pit->pit_state.lock);
704 702
705 kvm_pit_reset(pit); 703 kvm_pit_reset(pit);
@@ -749,7 +747,7 @@ void kvm_free_pit(struct kvm *kvm)
749 kvm_unregister_irq_ack_notifier(kvm, 747 kvm_unregister_irq_ack_notifier(kvm,
750 &kvm->arch.vpit->pit_state.irq_ack_notifier); 748 &kvm->arch.vpit->pit_state.irq_ack_notifier);
751 mutex_lock(&kvm->arch.vpit->pit_state.lock); 749 mutex_lock(&kvm->arch.vpit->pit_state.lock);
752 timer = &kvm->arch.vpit->pit_state.pit_timer.timer; 750 timer = &kvm->arch.vpit->pit_state.timer;
753 hrtimer_cancel(timer); 751 hrtimer_cancel(timer);
754 flush_kthread_work(&kvm->arch.vpit->expired); 752 flush_kthread_work(&kvm->arch.vpit->expired);
755 kthread_stop(kvm->arch.vpit->worker_task); 753 kthread_stop(kvm->arch.vpit->worker_task);
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h
index c9bbcb889c4..dd1b16b611b 100644
--- a/arch/x86/kvm/i8254.h
+++ b/arch/x86/kvm/i8254.h
@@ -21,19 +21,15 @@ struct kvm_kpit_channel_state {
21 ktime_t count_load_time; 21 ktime_t count_load_time;
22}; 22};
23 23
24struct kvm_pit_timer {
25 struct hrtimer timer;
26 s64 period; /* unit: ns */
27 atomic_t pending; /* accumulated triggered timers */
28 bool reinject;
29 struct kvm *kvm;
30};
31
32struct kvm_kpit_state { 24struct kvm_kpit_state {
33 struct kvm_kpit_channel_state channels[3]; 25 struct kvm_kpit_channel_state channels[3];
34 u32 flags; 26 u32 flags;
35 struct kvm_pit_timer pit_timer;
36 bool is_periodic; 27 bool is_periodic;
28 s64 period; /* unit: ns */
29 struct hrtimer timer;
30 atomic_t pending; /* accumulated triggered timers */
31 bool reinject;
32 struct kvm *kvm;
37 u32 speaker_data_on; 33 u32 speaker_data_on;
38 struct mutex lock; 34 struct mutex lock;
39 struct kvm_pit *pit; 35 struct kvm_pit *pit;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b6379e55ee2..3a53bcc24f2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3082,7 +3082,7 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm,
3082 if (!kvm->arch.vpit) 3082 if (!kvm->arch.vpit)
3083 return -ENXIO; 3083 return -ENXIO;
3084 mutex_lock(&kvm->arch.vpit->pit_state.lock); 3084 mutex_lock(&kvm->arch.vpit->pit_state.lock);
3085 kvm->arch.vpit->pit_state.pit_timer.reinject = control->pit_reinject; 3085 kvm->arch.vpit->pit_state.reinject = control->pit_reinject;
3086 mutex_unlock(&kvm->arch.vpit->pit_state.lock); 3086 mutex_unlock(&kvm->arch.vpit->pit_state.lock);
3087 return 0; 3087 return 0;
3088} 3088}