diff options
author | Christian Borntraeger <borntraeger@de.ibm.com> | 2009-05-12 11:21:49 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2009-06-10 04:48:55 -0400 |
commit | ca8723023f25c9a70d76cbd6101f8fb4ffec2fa0 (patch) | |
tree | ef753d244a55271279b5b2cf29b28db5b35b454c /arch/s390/kvm/interrupt.c | |
parent | 2668dab794272f0898491acaf1e77e9a005abc0f (diff) |
KVM: s390: use hrtimer for clock wakeup from idle - v2
This patch reworks the s390 clock comparator wakeup to hrtimer. The clock
comparator is a per-cpu value that is compared against the TOD clock. If
ckc <= TOD an external interrupt 1004 is triggered. Since the clock comparator
and the TOD clock have a much higher resolution than jiffies we should use
hrtimers to trigger the wakeup. This speeds up guest nanosleep for small
values.
Since hrtimers callbacks run in hard-irq context, I added a tasklet to do
the actual work with enabled interrupts.
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Christian Ehrhardt <ehrhardt@de.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/s390/kvm/interrupt.c')
-rw-r--r-- | arch/s390/kvm/interrupt.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 4ed4c3a11485..a48830fa9c59 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c | |||
@@ -12,6 +12,8 @@ | |||
12 | 12 | ||
13 | #include <asm/lowcore.h> | 13 | #include <asm/lowcore.h> |
14 | #include <asm/uaccess.h> | 14 | #include <asm/uaccess.h> |
15 | #include <linux/hrtimer.h> | ||
16 | #include <linux/interrupt.h> | ||
15 | #include <linux/kvm_host.h> | 17 | #include <linux/kvm_host.h> |
16 | #include <linux/signal.h> | 18 | #include <linux/signal.h> |
17 | #include "kvm-s390.h" | 19 | #include "kvm-s390.h" |
@@ -361,12 +363,10 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) | |||
361 | return 0; | 363 | return 0; |
362 | } | 364 | } |
363 | 365 | ||
364 | sltime = (vcpu->arch.sie_block->ckc - now) / (0xf4240000ul / HZ) + 1; | 366 | sltime = ((vcpu->arch.sie_block->ckc - now)*125)>>9; |
365 | 367 | ||
366 | vcpu->arch.ckc_timer.expires = jiffies + sltime; | 368 | hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL); |
367 | 369 | VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime); | |
368 | add_timer(&vcpu->arch.ckc_timer); | ||
369 | VCPU_EVENT(vcpu, 5, "enabled wait timer:%llx jiffies", sltime); | ||
370 | no_timer: | 370 | no_timer: |
371 | spin_lock_bh(&vcpu->arch.local_int.float_int->lock); | 371 | spin_lock_bh(&vcpu->arch.local_int.float_int->lock); |
372 | spin_lock_bh(&vcpu->arch.local_int.lock); | 372 | spin_lock_bh(&vcpu->arch.local_int.lock); |
@@ -389,21 +389,34 @@ no_timer: | |||
389 | remove_wait_queue(&vcpu->wq, &wait); | 389 | remove_wait_queue(&vcpu->wq, &wait); |
390 | spin_unlock_bh(&vcpu->arch.local_int.lock); | 390 | spin_unlock_bh(&vcpu->arch.local_int.lock); |
391 | spin_unlock_bh(&vcpu->arch.local_int.float_int->lock); | 391 | spin_unlock_bh(&vcpu->arch.local_int.float_int->lock); |
392 | del_timer(&vcpu->arch.ckc_timer); | 392 | hrtimer_try_to_cancel(&vcpu->arch.ckc_timer); |
393 | return 0; | 393 | return 0; |
394 | } | 394 | } |
395 | 395 | ||
396 | void kvm_s390_idle_wakeup(unsigned long data) | 396 | void kvm_s390_tasklet(unsigned long parm) |
397 | { | 397 | { |
398 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; | 398 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm; |
399 | 399 | ||
400 | spin_lock_bh(&vcpu->arch.local_int.lock); | 400 | spin_lock(&vcpu->arch.local_int.lock); |
401 | vcpu->arch.local_int.timer_due = 1; | 401 | vcpu->arch.local_int.timer_due = 1; |
402 | if (waitqueue_active(&vcpu->arch.local_int.wq)) | 402 | if (waitqueue_active(&vcpu->arch.local_int.wq)) |
403 | wake_up_interruptible(&vcpu->arch.local_int.wq); | 403 | wake_up_interruptible(&vcpu->arch.local_int.wq); |
404 | spin_unlock_bh(&vcpu->arch.local_int.lock); | 404 | spin_unlock(&vcpu->arch.local_int.lock); |
405 | } | 405 | } |
406 | 406 | ||
407 | /* | ||
408 | * low level hrtimer wake routine. Because this runs in hardirq context | ||
409 | * we schedule a tasklet to do the real work. | ||
410 | */ | ||
411 | enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) | ||
412 | { | ||
413 | struct kvm_vcpu *vcpu; | ||
414 | |||
415 | vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer); | ||
416 | tasklet_schedule(&vcpu->arch.tasklet); | ||
417 | |||
418 | return HRTIMER_NORESTART; | ||
419 | } | ||
407 | 420 | ||
408 | void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) | 421 | void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) |
409 | { | 422 | { |