From patchwork Sat Oct 20 09:54:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 987179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="moN6I8qN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42cdSB5vyMz9sDX for ; Sat, 20 Oct 2018 20:55:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726929AbeJTSE4 (ORCPT ); Sat, 20 Oct 2018 14:04:56 -0400 Received: from ozlabs.org ([203.11.71.1]:45417 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbeJTSE4 (ORCPT ); Sat, 20 Oct 2018 14:04:56 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 42cdS64BR6z9sCt; Sat, 20 Oct 2018 20:55:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1540029302; bh=oqhZiYBBct14AT27BQObH6fHkGa9lEW36BuSNpIydWA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=moN6I8qNuTtvKrjG2Wf3qGNbq2ysw2pDQcsYj4bnO9ViULRdeVkBNWMV/bFrLB82p s6cQ6LSHRwstHjLWInwQFsl7KI3OhHtWVrq9/IE7EuF2LM7RAN6KjQzIP/ksGmwBH3 mnV909ZB5WMXLFj20Y6Ea3pZsDB6XX8fY8ZbpmQybXJ2oV3ib9LpIzHrQS3ak56g+H IoCDQEoJNU40BeqtxnJTYm/x25QzfdPLIBiLaC2sdnxIwPEKpb09z80vW9Qt1b0SYe J0qJXHaTpz1WHVKyVzwXTg7aIyFPhRsM4CKi+nqeLZsE50UrvAno/H4YS0hoTldpf4 x/+Fde4Hwdt5g== Date: Sat, 20 Oct 2018 20:54:55 +1100 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: linuxppc-dev@ozlabs.org, Michael Ellerman Subject: [PATCH v2] KVM: PPC: Use exported tb_to_ns() function in decrementer emulation Message-ID: <20181020095455.GA12489@blackberry> References: <20181019100722.GB6230@blackberry> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181019100722.GB6230@blackberry> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org This changes the KVM code that emulates the decrementer function to do the conversion of decrementer values to time intervals in nanoseconds by calling the tb_to_ns() function exported by the powerpc timer code, in preference to open-coded arithmetic using values from the decrementer_clockevent struct. Similarly, the HV-KVM code that did the same conversion using arithmetic on tb_ticks_per_sec also now uses tb_to_ns(). Signed-off-by: Paul Mackerras --- v2: don't delete the second do_div in kvmppc_emulate_dec(), we need it. arch/powerpc/kvm/book3s_hv.c | 3 +-- arch/powerpc/kvm/emulate.c | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index bf8def2..d65b961 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -2337,8 +2337,7 @@ static void kvmppc_set_timer(struct kvm_vcpu *vcpu) kvmppc_core_prepare_to_enter(vcpu); return; } - dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC - / tb_ticks_per_sec; + dec_nsec = tb_to_ns(vcpu->arch.dec_expires - now); hrtimer_start(&vcpu->arch.dec_timer, dec_nsec, HRTIMER_MODE_REL); vcpu->arch.timer_running = 1; } diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index fa888bf..9f5b8c0 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -61,11 +61,10 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) dec_time = vcpu->arch.dec; /* - * Guest timebase ticks at the same frequency as host decrementer. - * So use the host decrementer calculations for decrementer emulation. + * Guest timebase ticks at the same frequency as host timebase. + * So use the host timebase calculations for decrementer emulation. */ - dec_time = dec_time << decrementer_clockevent.shift; - do_div(dec_time, decrementer_clockevent.mult); + dec_time = tb_to_ns(dec_time); dec_nsec = do_div(dec_time, NSEC_PER_SEC); hrtimer_start(&vcpu->arch.dec_timer, ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL);