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: 10650333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01D6313A4 for ; Sat, 20 Oct 2018 09:55:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3B3B28536 for ; Sat, 20 Oct 2018 09:55:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4767285C9; Sat, 20 Oct 2018 09:55:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 280F628536 for ; Sat, 20 Oct 2018 09:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727285AbeJTSE4 (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-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);