From patchwork Wed Apr 4 06:51:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 150604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 8D300B6FE2 for ; Wed, 4 Apr 2012 16:37:36 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751239Ab2DDGhf (ORCPT ); Wed, 4 Apr 2012 02:37:35 -0400 Received: from am1ehsobe006.messaging.microsoft.com ([213.199.154.209]:44178 "EHLO am1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750918Ab2DDGhe (ORCPT ); Wed, 4 Apr 2012 02:37:34 -0400 Received: from mail83-am1-R.bigfish.com (10.3.201.249) by AM1EHSOBE002.bigfish.com (10.3.204.22) with Microsoft SMTP Server id 14.1.225.23; Wed, 4 Apr 2012 06:37:33 +0000 Received: from mail83-am1 (localhost [127.0.0.1]) by mail83-am1-R.bigfish.com (Postfix) with ESMTP id 3B0A7601FA; Wed, 4 Apr 2012 06:37:33 +0000 (UTC) X-SpamScore: 3 X-BigFish: VS3(zzzz1202h1082kzz8275bhz2dh2a8h668h839hd24h) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail83-am1 (localhost.localdomain [127.0.0.1]) by mail83-am1 (MessageSwitch) id 133352145263018_17938; Wed, 4 Apr 2012 06:37:32 +0000 (UTC) Received: from AM1EHSMHS020.bigfish.com (unknown [10.3.201.242]) by mail83-am1.bigfish.com (Postfix) with ESMTP id 00EED20126; Wed, 4 Apr 2012 06:37:32 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by AM1EHSMHS020.bigfish.com (10.3.206.23) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 4 Apr 2012 06:37:31 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.1.355.3; Wed, 4 Apr 2012 01:37:29 -0500 Received: from freescale.com ([10.232.15.72]) by az84smr01.freescale.net (8.14.3/8.14.0) with SMTP id q346bQ8u010770; Tue, 3 Apr 2012 23:37:27 -0700 Received: by freescale.com (sSMTP sendmail emulation); Wed, 04 Apr 2012 12:21:53 +0530 From: Bharat Bhushan To: , CC: Bharat Bhushan Subject: [PATCH] Use clockevent multiplier and shifter for decrementer Date: Wed, 4 Apr 2012 12:21:51 +0530 Message-ID: <1333522311-1390-1-git-send-email-bharat.bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org 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 --- arch/powerpc/include/asm/time.h | 2 ++ arch/powerpc/kernel/time.c | 6 ++++++ arch/powerpc/kvm/emulate.c | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h index 7eb10fb..6d631b2 100644 --- a/arch/powerpc/include/asm/time.h +++ b/arch/powerpc/include/asm/time.h @@ -202,6 +202,8 @@ extern u64 mulhdu(u64, u64); extern void div128_by_32(u64 dividend_high, u64 dividend_low, unsigned divisor, struct div_result *dr); +extern void get_clockevent_mult(u64 *multi, u64 *shift); + /* Used to store Processor Utilization register (purr) values */ struct cpu_usage { diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index 567dd7c..d229edd 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -910,6 +910,12 @@ static void __init init_decrementer_clockevent(void) register_decrementer_clockevent(cpu); } +void get_clockevent_mult(u64 *multi, u64 *shift) +{ + *multi = decrementer_clockevent.mult; + *shift = decrementer_clockevent.shift; +} + void secondary_cpu_time_init(void) { /* Start the decrementer on CPUs that have manual control diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index afc9154..4bfcaa1 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -76,6 +76,7 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) { unsigned long dec_nsec; unsigned long long dec_time; + u64 mult, shift; pr_debug("mtDEC: %x\n", vcpu->arch.dec); hrtimer_try_to_cancel(&vcpu->arch.dec_timer); @@ -103,9 +104,9 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) * host ticks. */ + get_clockevent_mult(&mult, &shift); dec_time = vcpu->arch.dec; - dec_time *= 1000; - do_div(dec_time, tb_ticks_per_usec); + dec_time = (dec_time << shift) / 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);