From patchwork Wed Oct 21 15:03:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 55110 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9LF4PWp020996 for ; Wed, 21 Oct 2009 15:04:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753977AbZJUPDp (ORCPT ); Wed, 21 Oct 2009 11:03:45 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753993AbZJUPDp (ORCPT ); Wed, 21 Oct 2009 11:03:45 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53840 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753977AbZJUPDk (ORCPT ); Wed, 21 Oct 2009 11:03:40 -0400 Received: from relay2.suse.de (mail2.suse.de [195.135.221.8]) by mx2.suse.de (Postfix) with ESMTP id 71D978AD27; Wed, 21 Oct 2009 17:03:40 +0200 (CEST) From: Alexander Graf To: kvm@vger.kernel.org Cc: Avi Kivity , kvm-ppc , Hollis Blanchard , Arnd Bergmann , Benjamin Herrenschmidt , Kevin Wolf , bphilips@suse.de, Marcelo Tosatti Subject: [PATCH 27/27] Use hrtimers for the decrementer Date: Wed, 21 Oct 2009 17:03:33 +0200 Message-Id: <1256137413-15256-28-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1256137413-15256-27-git-send-email-agraf@suse.de> References: <1256137413-15256-1-git-send-email-agraf@suse.de> <1256137413-15256-2-git-send-email-agraf@suse.de> <1256137413-15256-3-git-send-email-agraf@suse.de> <1256137413-15256-4-git-send-email-agraf@suse.de> <1256137413-15256-5-git-send-email-agraf@suse.de> <1256137413-15256-6-git-send-email-agraf@suse.de> <1256137413-15256-7-git-send-email-agraf@suse.de> <1256137413-15256-8-git-send-email-agraf@suse.de> <1256137413-15256-9-git-send-email-agraf@suse.de> <1256137413-15256-10-git-send-email-agraf@suse.de> <1256137413-15256-11-git-send-email-agraf@suse.de> <1256137413-15256-12-git-send-email-agraf@suse.de> <1256137413-15256-13-git-send-email-agraf@suse.de> <1256137413-15256-14-git-send-email-agraf@suse.de> <1256137413-15256-15-git-send-email-agraf@suse.de> <1256137413-15256-16-git-send-email-agraf@suse.de> <1256137413-15256-17-git-send-email-agraf@suse.de> <1256137413-15256-18-git-send-email-agraf@suse.de> <1256137413-15256-19-git-send-email-agraf@suse.de> <1256137413-15256-20-git-send-email-agraf@suse.de> <1256137413-15256-21-git-send-email-agraf@suse.de> <1256137413-15256-22-git-send-email-agraf@suse.de> <1256137413-15256-23-git-send-email-agraf@suse.de> <1256137413-15256-24-git-send-email-agraf@suse.de> <1256137413-15256-25-git-send-email-agraf@suse.de> <1256137413-15256-26-git-send-email-agraf@suse.de> <1256137413-15256-27-git-send-email-agraf@suse.de> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 2cff5fe..1201f62 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -21,7 +21,8 @@ #define __POWERPC_KVM_HOST_H__ #include -#include +#include +#include #include #include #include @@ -250,7 +251,8 @@ struct kvm_vcpu_arch { u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */ - struct timer_list dec_timer; + struct hrtimer dec_timer; + struct tasklet_struct tasklet; u64 dec_jiffies; unsigned long pending_exceptions; diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index 1ec5e07..4a9ac66 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include #include @@ -79,12 +79,13 @@ static int kvmppc_dec_enabled(struct kvm_vcpu *vcpu) void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) { - unsigned long nr_jiffies; + unsigned long dec_nsec; + pr_debug("mtDEC: %x\n", vcpu->arch.dec); #ifdef CONFIG_PPC64 /* POWER4+ triggers a dec interrupt if the value is < 0 */ if (vcpu->arch.dec & 0x80000000) { - del_timer(&vcpu->arch.dec_timer); + hrtimer_try_to_cancel(&vcpu->arch.dec_timer); kvmppc_core_queue_dec(vcpu); return; } @@ -94,12 +95,15 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) * that's how we convert the guest DEC value to the number of * host ticks. */ + hrtimer_try_to_cancel(&vcpu->arch.dec_timer); + dec_nsec = vcpu->arch.dec; + dec_nsec *= 1000; + dec_nsec /= tb_ticks_per_usec; + hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec), + HRTIMER_MODE_REL); vcpu->arch.dec_jiffies = get_tb(); - nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy; - mod_timer(&vcpu->arch.dec_timer, - get_jiffies_64() + nr_jiffies); } else { - del_timer(&vcpu->arch.dec_timer); + hrtimer_try_to_cancel(&vcpu->arch.dec_timer); } } diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 4ae3490..4c582ed 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -209,10 +210,25 @@ static void kvmppc_decrementer_func(unsigned long data) } } +/* + * low level hrtimer wake routine. Because this runs in hardirq context + * we schedule a tasklet to do the real work. + */ +enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer) +{ + struct kvm_vcpu *vcpu; + + vcpu = container_of(timer, struct kvm_vcpu, arch.dec_timer); + tasklet_schedule(&vcpu->arch.tasklet); + + return HRTIMER_NORESTART; +} + int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) { - setup_timer(&vcpu->arch.dec_timer, kvmppc_decrementer_func, - (unsigned long)vcpu); + hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); + tasklet_init(&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu); + vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup; return 0; }