From: Alexander Graf <agraf@suse.de>
To: kvm-ppc <kvm-ppc@vger.kernel.org>
Cc: kvm list <kvm@vger.kernel.org>, Avi Kivity <avi@redhat.com>,
Bharat Bhushan <r65777@freescale.com>,
Bharat Bhushan <bharat.bhushan@freescale.com>
Subject: [PATCH 02/16] KVM: PPC: Use clockevent multiplier and shifter for decrementer
Date: Sun, 06 May 2012 14:20:46 +0000 [thread overview]
Message-ID: <1336314060-32640-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1336314060-32640-1-git-send-email-agraf@suse.de>
From: Bharat Bhushan <r65777@freescale.com>
Time for which the hrtimer is started for decrementer emulation is calculated
using tb_ticks_per_usec. While hrtimer uses the clockevent for DEC
reprogramming (if needed) and which calculate timebase ticks using the
multiplier and shifter mechanism implemented within clockevent layer.
It was observed that this conversion (timebase->time->timebase) are not
correct because the mechanism are not consistent.
In our setup it adds 2% jitter.
With this patch clockevent multiplier and shifter mechanism are used when
starting hrtimer for decrementer emulation. Now the jitter is < 0.5%.
Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/powerpc/include/asm/time.h | 1 +
arch/powerpc/kernel/time.c | 3 ++-
arch/powerpc/kvm/emulate.c | 9 +++++++--
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
index 2136f58..3b4b4a8 100644
--- a/arch/powerpc/include/asm/time.h
+++ b/arch/powerpc/include/asm/time.h
@@ -23,6 +23,7 @@
extern unsigned long tb_ticks_per_jiffy;
extern unsigned long tb_ticks_per_usec;
extern unsigned long tb_ticks_per_sec;
+extern struct clock_event_device decrementer_clockevent;
struct rtc_time;
extern void to_tm(int tim, struct rtc_time * tm);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 2c42cd7..99a995c 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -100,7 +100,7 @@ static int decrementer_set_next_event(unsigned long evt,
static void decrementer_set_mode(enum clock_event_mode mode,
struct clock_event_device *dev);
-static struct clock_event_device decrementer_clockevent = {
+struct clock_event_device decrementer_clockevent = {
.name = "decrementer",
.rating = 200,
.irq = 0,
@@ -108,6 +108,7 @@ static struct clock_event_device decrementer_clockevent = {
.set_mode = decrementer_set_mode,
.features = CLOCK_EVT_FEAT_ONESHOT,
};
+EXPORT_SYMBOL(decrementer_clockevent);
DEFINE_PER_CPU(u64, decrementers_next_tb);
static DEFINE_PER_CPU(struct clock_event_device, decrementers);
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index afc9154..b5872f6 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -23,6 +23,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kvm_host.h>
+#include <linux/clockchips.h>
#include <asm/reg.h>
#include <asm/time.h>
@@ -104,8 +105,12 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
*/
dec_time = vcpu->arch.dec;
- dec_time *= 1000;
- do_div(dec_time, tb_ticks_per_usec);
+ /*
+ * Guest timebase ticks at the same frequency as host decrementer.
+ * So use the host decrementer calculations for decrementer emulation.
+ */
+ dec_time = dec_time << decrementer_clockevent.shift;
+ do_div(dec_time, decrementer_clockevent.mult);
dec_nsec = do_div(dec_time, NSEC_PER_SEC);
hrtimer_start(&vcpu->arch.dec_timer,
ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL);
--
1.6.0.2
next prev parent reply other threads:[~2012-05-06 14:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-06 14:20 [PULL 00/16] ppc patch queue 2012-05-06 Alexander Graf
2012-05-06 14:20 ` [PATCH 01/16] KVM: Use minimum and maximum address mapped by TLB1 Alexander Graf
2012-05-06 14:20 ` Alexander Graf [this message]
2012-05-06 14:20 ` [PATCH 03/16] KVM: PPC: bookehv: Use a Macro for saving/restoring guest registers to/from their 64 b Alexander Graf
2012-05-06 14:20 ` [PATCH 04/16] KVM: PPC: Restrict PPC_[L|ST]D macro to asm code Alexander Graf
2012-05-06 14:20 ` [PATCH 05/16] KVM: PPC: booke(hv): Fix save/restore of guest accessible SPRGs Alexander Graf
2012-05-06 14:20 ` [PATCH 06/16] KVM: PPC: Book3S: PR: Optimize entry path Alexander Graf
2012-05-06 14:20 ` [PATCH 07/16] KVM: PPC: Book3S: PR: No isync in slbie path Alexander Graf
2012-05-06 14:20 ` [PATCH 08/16] KVM: PPC: bookehv: Use lwz/stw instead of PPC_LL/PPC_STL for 32-bit fields Alexander Graf
2012-05-06 14:20 ` [PATCH 09/16] KVM: PPC: Fix stbux emulation Alexander Graf
2012-05-06 14:20 ` [PATCH 10/16] KVM: PPC: Fix PR KVM on POWER7 bare metal Alexander Graf
2012-05-06 14:20 ` [PATCH 11/16] KVM: PPC: Book3S: Enable IRQs during exit handling Alexander Graf
2012-05-06 14:20 ` [PATCH 12/16] KVM: PPC: bookehv: Fix r8/r13 storing in level exception handler Alexander Graf
2012-05-06 14:20 ` [PATCH 13/16] kvm/book3s: Make kernel emulated H_PUT_TCE available for "PR" KVM Alexander Graf
2012-05-06 14:20 ` [PATCH 14/16] kvm/powerpc: Add new ioctl to retreive server MMU infos Alexander Graf
2012-05-06 14:20 ` [PATCH 15/16] KVM: PPC: Emulator: clean up instruction parsing Alexander Graf
2012-05-06 14:21 ` [PATCH 16/16] KVM: PPC: Emulator: clean up SPR reads and writes Alexander Graf
2012-05-08 14:01 ` [PULL 00/16] ppc patch queue 2012-05-06 Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336314060-32640-3-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=avi@redhat.com \
--cc=bharat.bhushan@freescale.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=r65777@freescale.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox